204 lines
6.1 KiB
PHP
204 lines
6.1 KiB
PHP
<?php
|
|
|
|
use Glpi\Event;
|
|
|
|
include('../inc/includes.php');
|
|
|
|
Session::checkLoginUser();
|
|
|
|
if (!in_array($_SESSION['glpiactiveprofile']['name'], ['Super-Admin', 'Admin'])) {
|
|
Html::redirect($CFG_GLPI["root_doc"] . "/front/central.php");
|
|
exit;
|
|
}
|
|
|
|
$root = $CFG_GLPI["root_doc"];
|
|
$user = Session::getCurrentInterface();
|
|
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
|
|
|
|
// Fetch picklist item
|
|
$pick = [];
|
|
if ($id > 0) {
|
|
global $DB;
|
|
$stmt = $DB->prepare("SELECT * FROM picklist WHERE id = ?");
|
|
$stmt->bind_param("i", $id);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
$pick = $result->fetch_assoc();
|
|
}
|
|
|
|
if (empty($pick)) {
|
|
Html::redirect($CFG_GLPI["root_doc"] . "/front/picklist.list.php");
|
|
exit;
|
|
}
|
|
|
|
if ($user == "helpdesk") {
|
|
Html::helpHeader("Fonction et Structure", '', $_SESSION["glpiname"]);
|
|
} else {
|
|
Html::header("Fonction et Structure", '', "", "");
|
|
}
|
|
?>
|
|
|
|
<style>
|
|
.form-container {
|
|
max-width: 600px;
|
|
margin: 30px auto;
|
|
padding: 20px;
|
|
border: 1px solid #dcdcdc;
|
|
border-radius: 10px;
|
|
background-color: #f9f9f9;
|
|
}
|
|
|
|
.form-container h2 {
|
|
text-align: center;
|
|
margin-bottom: 20px;
|
|
color: #333;
|
|
}
|
|
|
|
.form-group {
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
.form-group label {
|
|
display: block;
|
|
margin-bottom: 8px;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.form-group select,
|
|
.form-group input {
|
|
width: 100%;
|
|
padding: 8px;
|
|
border-radius: 5px;
|
|
border: 1px solid #ccc;
|
|
}
|
|
|
|
.form-actions {
|
|
text-align: center;
|
|
margin-top: 25px;
|
|
}
|
|
|
|
.form-actions .vsubmit {
|
|
padding: 10px 20px;
|
|
font-size: 14px;
|
|
margin-right: 10px;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.form-actions .cancel {
|
|
background-color: #eba696;
|
|
color: #000;
|
|
text-decoration: none;
|
|
}
|
|
|
|
.error-message {
|
|
margin-top: 20px;
|
|
padding: 12px;
|
|
background-color: #f8d7da;
|
|
color: #721c24;
|
|
border: 1px solid #f5c6cb;
|
|
border-radius: 5px;
|
|
text-align: center;
|
|
display: none;
|
|
}
|
|
</style>
|
|
|
|
<div class='form-container'>
|
|
<h2>Modifier un élément de la Pick List</h2>
|
|
<form id='form' name='form' method='post' action='<?php echo $root; ?>/ajax/picklist.php?action=update' enctype='multipart/form-data'>
|
|
<input type="hidden" name="id" value="<?php echo $pick['id']; ?>">
|
|
|
|
<div class='form-group'>
|
|
<label for='type'>Type <span style='color:red'>*</span></label>
|
|
<select id='type' name='type' class='js-example-basic-single' required>
|
|
<option value='' disabled>-- Sélectionnez un type --</option>
|
|
<option value='fonction' <?php if ($pick['name'] == 'fonction') echo 'selected'; ?>>Fonction</option>
|
|
<option value='structure' <?php if ($pick['name'] == 'structure') echo 'selected'; ?>>Structure</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class='form-group'>
|
|
<label for='value'>Valeur <span style='color:red'>*</span></label>
|
|
<input type='text' id='value' name='value' required value="<?php echo htmlspecialchars($pick['value']); ?>">
|
|
</div>
|
|
|
|
<div class='form-actions'>
|
|
<button name='save' class='vsubmit'>Mettre à jour</button>
|
|
<a href='<?php echo $root; ?>/front/picklist.list.php' class='vsubmit cancel'>Annuler</a>
|
|
</div>
|
|
|
|
<div class="error-message" id="error-container"></div>
|
|
</form>
|
|
</div>
|
|
|
|
<?php
|
|
if ($user == "helpdesk") {
|
|
Html::helpFooter();
|
|
} else {
|
|
Html::footer();
|
|
}
|
|
?>
|
|
|
|
<script>
|
|
var root = <?php echo json_encode($root); ?>;
|
|
var user = <?php echo json_encode($user); ?>;
|
|
|
|
$("button[name='save']").click(function(event) {
|
|
event.preventDefault();
|
|
|
|
if ($("#form")[0].checkValidity()) {
|
|
$("button[name='save']").attr("disabled", "disabled");
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: root + "/ajax/picklist.php?action=update",
|
|
data: $('#form').serialize()
|
|
})
|
|
.done(function(response) {
|
|
try {
|
|
var res = JSON.parse(response);
|
|
if (res.status === "success") {
|
|
window.location = root + "/front/picklist.list.php";
|
|
} else {
|
|
showErrorMessage(res.message || "Une erreur s'est produite lors de la mise à jour.");
|
|
$("button[name='save']").removeAttr("disabled");
|
|
}
|
|
} catch (e) {
|
|
console.error("Erreur JSON :", e);
|
|
showErrorMessage("Réponse invalide du serveur.");
|
|
$("button[name='save']").removeAttr("disabled");
|
|
}
|
|
})
|
|
.fail(function(xhr, status, error) {
|
|
console.error("Erreur AJAX :", status, error);
|
|
showErrorMessage("Erreur réseau : " + error);
|
|
$("button[name='save']").removeAttr("disabled");
|
|
});
|
|
}
|
|
});
|
|
|
|
function showErrorMessage(message) {
|
|
$("#error-container").text(message).fadeIn();
|
|
|
|
setTimeout(function () {
|
|
$("#error-container").fadeOut();
|
|
}, 4000);
|
|
}
|
|
|
|
$(document).ready(function () {
|
|
$('.js-example-basic-single').select2();
|
|
|
|
var userlink = user === "helpdesk"
|
|
? '<li class="breadcrumb_item"><a href="' + root + '/front/helpdesk.public.php" title="Accueil">Accueil</a></li>'
|
|
: '<li class="breadcrumb_item"><a href="' + root + '/front/central.php" title="Accueil">Accueil</a></li>';
|
|
|
|
$("#c_ssmenu2").html('<ul>' +
|
|
userlink +
|
|
'<li class="breadcrumb_item"><a href="#" title="">Administration</a></li>' +
|
|
'<li class="breadcrumb_item"><a href="' + root + '/front/picklist.list.php" class="here" title="Fonction et Structure">' +
|
|
'<i class="far fa-sticky-note"></i> Fonction et Structure</a></li>' +
|
|
'<span class="sr-only">Modifier</span>' +
|
|
'</ul>');
|
|
});
|
|
</script>
|