Save new folder
This commit is contained in:
295
front/user.update.php
Normal file
295
front/user.update.php
Normal file
@ -0,0 +1,295 @@
|
||||
<?php
|
||||
|
||||
use Glpi\Event;
|
||||
|
||||
include('../inc/includes.php');
|
||||
|
||||
Session::checkLoginUser();
|
||||
|
||||
$allowed_groups = [38, 2];
|
||||
|
||||
if (empty(array_intersect($allowed_groups, $_SESSION['glpigroups']))) {
|
||||
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 user item
|
||||
$pick = [];
|
||||
if ($id > 0) {
|
||||
global $DB;
|
||||
$stmt = $DB->prepare("SELECT * FROM glpi_users WHERE id = ?");
|
||||
$stmt->bind_param("i", $id);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$pick = $result->fetch_assoc();
|
||||
}
|
||||
|
||||
$responsables = [];
|
||||
$res = $DB->query("SELECT id, CONCAT(realname,' ',firstname) AS fullname
|
||||
FROM glpi_users
|
||||
WHERE is_active = 1
|
||||
ORDER BY realname ASC");
|
||||
while ($row = $res->fetch_assoc()) {
|
||||
$responsables[] = $row;
|
||||
}
|
||||
|
||||
$postes = [];
|
||||
$res = $DB->query("SELECT id, value
|
||||
FROM picklist
|
||||
WHERE name='fonction'
|
||||
ORDER BY value ASC");
|
||||
while ($row = $res->fetch_assoc()) {
|
||||
$postes[] = $row;
|
||||
}
|
||||
|
||||
$structures = [];
|
||||
$res = $DB->query("SELECT id, value
|
||||
FROM picklist
|
||||
WHERE name='structure'
|
||||
ORDER BY value ASC");
|
||||
while ($row = $res->fetch_assoc()) {
|
||||
$structures[] = $row;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (empty($pick)) {
|
||||
Html::redirect($CFG_GLPI["root_doc"] . "/front/user.list.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($user == "helpdesk") {
|
||||
Html::helpHeader("Gestion des employées", '', $_SESSION["glpiname"]);
|
||||
} else {
|
||||
Html::header("Gestion des employées", '', "", "");
|
||||
}
|
||||
?>
|
||||
|
||||
<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;
|
||||
}
|
||||
|
||||
.success-message {
|
||||
margin-top: 20px;
|
||||
padding: 12px;
|
||||
background-color: #d4edda;
|
||||
color: #155724;
|
||||
border: 1px solid #c3e6cb;
|
||||
border-radius: 5px;
|
||||
text-align: center;
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class='form-container'>
|
||||
<h2>Modifier un Employé</h2>
|
||||
<form id='form' name='form' method='post' action='<?php echo $root; ?>/ajax/user.php?action=update' enctype='multipart/form-data'>
|
||||
<input type="hidden" name="id" value="<?php echo $pick['id']; ?>">
|
||||
|
||||
<div class='form-group'>
|
||||
<label for='registration_number'>Matricule <span style='color:red'>*</span></label>
|
||||
<input type='text' id='registration_number' name='registration_number' readonly required value="<?php echo htmlspecialchars($pick['registration_number']); ?>">
|
||||
</div>
|
||||
|
||||
<div class='form-group'>
|
||||
<label for='realname'>Nom de famille <span style='color:red'>*</span></label>
|
||||
<input type='text' id='realname' name='realname' required readonly value="<?php echo htmlspecialchars($pick['realname']); ?>">
|
||||
</div>
|
||||
|
||||
<div class='form-group'>
|
||||
<label for='firstname'>Prénom <span style='color:red'>*</span></label>
|
||||
<input type='text' id='firstname' name='firstname' required readonly value="<?php echo htmlspecialchars($pick['firstname']); ?>">
|
||||
</div>
|
||||
|
||||
<div class='form-group'>
|
||||
<label for='users_id_supervisor'>Responsable</label>
|
||||
<select id='users_id_supervisor' name='users_id_supervisor' class='js-example-basic-single'>
|
||||
<option value=''>-- Aucun --</option>
|
||||
<?php foreach ($responsables as $row): ?>
|
||||
<option value="<?= $row['id'] ?>" <?= ($pick['users_id_supervisor'] == $row['id']) ? 'selected' : '' ?>>
|
||||
<?= htmlspecialchars($row['fullname']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class='form-group'>
|
||||
<label for='id_fonction'>Poste</label>
|
||||
<select id='id_fonction' name='id_fonction' class='js-example-basic-single'>
|
||||
<option value=''>-- Sélectionnez un poste --</option>
|
||||
<?php foreach ($postes as $row): ?>
|
||||
<option value="<?= $row['id'] ?>" <?= ($pick['id_fonction'] == $row['id']) ? 'selected' : '' ?>>
|
||||
<?= htmlspecialchars($row['value']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class='form-group'>
|
||||
<label for='id_structure'>Structure</label>
|
||||
<select id='id_structure' name='id_structure' class='js-example-basic-single'>
|
||||
<option value=''>-- Sélectionnez une structure --</option>
|
||||
<?php foreach ($structures as $row): ?>
|
||||
<option value="<?= $row['id'] ?>" <?= ($pick['id_structure'] == $row['id']) ? 'selected' : '' ?>>
|
||||
<?= htmlspecialchars($row['value']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class='form-actions'>
|
||||
<button name='save' class='vsubmit'>Mettre à jour</button>
|
||||
<a href='<?php echo $root; ?>/front/user.list.php' class='vsubmit cancel'>Annuler</a>
|
||||
</div>
|
||||
|
||||
<div class="error-message" id="message-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/user.php?action=update",
|
||||
data: $('#form').serialize(),
|
||||
dataType: "json"
|
||||
})
|
||||
.done(function(res) {
|
||||
if (res.status === "success") {
|
||||
showMessage("Mise à jour réussie !", "success");
|
||||
setTimeout(function () {
|
||||
location.reload();
|
||||
}, 3000);
|
||||
} else {
|
||||
showMessage(res.message || "Une erreur s'est produite lors de la mise à jour.");
|
||||
$("button[name='save']").removeAttr("disabled");
|
||||
}
|
||||
})
|
||||
.fail(function(xhr, status, error) {
|
||||
console.error("Erreur AJAX :", status, error, xhr.responseText);
|
||||
showMessage("Erreur réseau : " + error);
|
||||
$("button[name='save']").removeAttr("disabled");
|
||||
});
|
||||
} else {
|
||||
$("button[name='save']").removeAttr("disabled");
|
||||
}
|
||||
});
|
||||
|
||||
function showMessage(message, type = "error") {
|
||||
const container = $("#message-container");
|
||||
|
||||
// Remove old classes
|
||||
container.removeClass("error-message success-message");
|
||||
|
||||
// Add new class depending on type
|
||||
if (type === "success") {
|
||||
container.addClass("success-message");
|
||||
} else {
|
||||
container.addClass("error-message");
|
||||
}
|
||||
|
||||
container.text(message).fadeIn();
|
||||
|
||||
setTimeout(function () {
|
||||
container.fadeOut();
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
$(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/user.list.php" class="here" title="Gestion des employées">' +
|
||||
'<i class="far fa-sticky-note"></i> Gestion des employées</a></li>' +
|
||||
'<span class="sr-only">Modifier</span>' +
|
||||
'</ul>');
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user