first commit
This commit is contained in:
218
front/change.responsable.php
Normal file
218
front/change.responsable.php
Normal file
@ -0,0 +1,218 @@
|
||||
<?php
|
||||
ob_Start();
|
||||
|
||||
use Glpi\Event;
|
||||
|
||||
include ('../inc/includes.php');
|
||||
|
||||
Session::checkLoginUser();
|
||||
|
||||
|
||||
if (Session::getCurrentInterface() == "helpdesk") {
|
||||
Html::helpHeader("Modifier Responsable", '', $_SESSION["glpiname"]);
|
||||
} else {
|
||||
Html::header("Modifier Responsable", '', "", "");
|
||||
}
|
||||
|
||||
|
||||
function get_list(){
|
||||
|
||||
global $DB;
|
||||
|
||||
$query = "SELECT U.id, CONCAT(U.realname, ' ', U.firstname) AS fullname, CONCAT(S.realname, ' ', S.firstname) AS supervisor_name,U.users_id_supervisor
|
||||
FROM glpi_users AS U
|
||||
LEFT JOIN glpi_users AS S ON U.users_id_supervisor = S.id
|
||||
WHERE U.is_deleted = 0 AND S.is_deleted = 0 AND U.is_active = 1
|
||||
ORDER BY supervisor_name";
|
||||
|
||||
$result = $DB->query($query);
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
|
||||
while($row = $result->fetch_assoc()) {
|
||||
$res[] = $row;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
$res =get_list() ;
|
||||
|
||||
echo '
|
||||
<div class="center">
|
||||
<table id="tabcenter" border="0" class="tab_cadrehov">
|
||||
<thead>
|
||||
<tr class="tab_bg_2">
|
||||
<th class=""></th>
|
||||
<th>Responsable</th>
|
||||
<th>ID</th>
|
||||
<th>Utilisateur</th>
|
||||
<th>Nouveau Responsable</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
<tr class="tab_bg_2">
|
||||
<th class=""></th>
|
||||
<th>
|
||||
<select class="js-example-basic-single" name="responsable" id="users_id_supervisor" onchange ="filtre();">
|
||||
<option value="0">ALL</option>';
|
||||
foreach ($res as $user) {
|
||||
echo '<option value="'.$user['id'].'">'.$user['fullname'].'</option>';
|
||||
}
|
||||
echo'</select>
|
||||
</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th>
|
||||
<select class="js-example-basic-single" name="new_supervisor_id" id="new_supervisor_id">
|
||||
<option value="0"></option>';
|
||||
foreach ($res as $user) {
|
||||
echo '<option value="'.$user['id'].'">'.$user['fullname'].'</option>';
|
||||
}
|
||||
echo'</select>
|
||||
</th>
|
||||
<th>
|
||||
<button onClick=update_supervisor() class="vsubmit"> Modifier Responsable </button>
|
||||
</th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="data">
|
||||
</tbody>
|
||||
<footer>
|
||||
<tr class="tab_bg_2">
|
||||
<th class=""></th>
|
||||
<th>Responsable</th>
|
||||
<th>ID</th>
|
||||
<th>Utilisateur</th>
|
||||
<th>Nouveau Responsable</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</footer>
|
||||
</table>
|
||||
|
||||
|
||||
</div>';
|
||||
|
||||
if (Session::getCurrentInterface() == "helpdesk") {
|
||||
Html::helpFooter();
|
||||
} else {
|
||||
Html::footer();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$link=$CFG_GLPI["root_doc"]."/front/ticket.php";
|
||||
$root = $CFG_GLPI["root_doc"];
|
||||
$user = Session::getCurrentInterface();
|
||||
?>
|
||||
|
||||
|
||||
<script>
|
||||
var root = <?php echo json_encode($root); ?>;
|
||||
var res = <?php echo json_encode($res); ?>;
|
||||
var user = <?php echo json_encode($user); ?>;
|
||||
|
||||
var userlink;
|
||||
if(user == "helpdesk"){
|
||||
userlink ='<li class="breadcrumb_item"><a href="'+root+'/front/helpdesk.public.php" title="Accueil">Accueil</a></li>';
|
||||
}else{
|
||||
userlink = '<li class="breadcrumb_item"><a href="'+root+'/front/central.php" title="Accueil">Accueil</a></li>';
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
|
||||
$("#c_ssmenu2").html('<ul>'+
|
||||
userlink+
|
||||
'<li class="breadcrumb_item"><a href="" title="">Administration</a></li>'+
|
||||
'<li class="breadcrumb_item"><a href="'+root+'/front/change.responsable.php" class="here" title="ModifierResponsable"><i class="far fa-sticky-note"></i> Modifier Responsable</a></li>'+
|
||||
'</ul>');
|
||||
|
||||
});
|
||||
|
||||
function message() {
|
||||
var r = confirm("Etes-vous sûr de vouloir supprimer ?");
|
||||
if (r == false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function loadTable(data)
|
||||
{
|
||||
$("#tabcenter tr").slice(2).remove();
|
||||
console.log(data);
|
||||
if(data.length > 0 && data != null) {
|
||||
|
||||
for(var i = 0; i < data.length; i++) {
|
||||
var row = data[i];
|
||||
$('#data').append(
|
||||
'<tr class="tab_bg_2">'+
|
||||
'<td width="10" valign="top"></td>'+
|
||||
'<td valign="top">'+row['supervisor_name']+'</td>'+
|
||||
'<td valign="top">'+row['id']+'</td>'+
|
||||
'<td valign="top">'+row['fullname']+'</td>'+
|
||||
'<td valign="top"></td>'+
|
||||
'<td valign="top"></td>'+
|
||||
'</tr>');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function filtre() {
|
||||
|
||||
let selectVal = $("#users_id_supervisor").find(":selected").val();
|
||||
let vals = res.filter((s) => s.users_id_supervisor == selectVal);
|
||||
loadTable(vals);
|
||||
}
|
||||
|
||||
function update_supervisor(){
|
||||
let oldVal = $("#users_id_supervisor").find(":selected").val();
|
||||
let vals = res.filter((s) => s.users_id_supervisor == oldVal);
|
||||
let newVal = $("#new_supervisor_id").find(":selected").val();
|
||||
|
||||
|
||||
if(!(vals.length == 0) && newVal != "0" && oldVal!= "0") {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: root+"/ajax/responsable.php?action=update&oldsupervisor="+oldVal+"&newsupervisor="+newVal,
|
||||
dataType: "json"
|
||||
})
|
||||
.done(function( msg ) {
|
||||
//var data = JSON.parse(msg);
|
||||
var data = msg;
|
||||
if(data !== null) {
|
||||
location.reload();
|
||||
vals.forEach(val => { val.users_id_supervisor = newVal; });
|
||||
loadTable(data);
|
||||
}
|
||||
|
||||
})
|
||||
.fail(function(msg, status, error) {
|
||||
console.log(msg);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
loadTable(res);
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
<!-- script pour liste déroulante -->
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('.js-example-basic-single').select2();
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
</script>
|
||||
Reference in New Issue
Block a user