Files
MYSOPHAL/front/dsi.demandes.acces.php
2025-08-07 13:15:31 +01:00

438 lines
14 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
use Glpi\Event;
include ('../inc/includes.php');
Session::checkLoginUser();
require_once '../functionsophalglpi.php';
$modele =addslashes($_GET['modele']);
$root = $CFG_GLPI["root_doc"];
//Security - Get Variables
if(isset($modele) ){
if( filter_var($modele, FILTER_VALIDATE_INT)=== 0 || !filter_var($modele, FILTER_VALIDATE_INT)=== FALSE){
if( $modele > 0 or $modele < 0){Html::redirect($CFG_GLPI["root_doc"]."/front/ticket.php");}
}else{
Html::redirect($CFG_GLPI["root_doc"]."/front/ticket.php");
}
}else if (!isset($modele)){
Html::redirect($CFG_GLPI["root_doc"]."/front/ticket.php");
}
if( ($_SESSION['glpiactiveprofile']['name'] == "Self-Service" || $_SESSION['glpiactiveprofile']['name'] == "Utilisateur-standard") && $modele == 7){
Html::redirect($CFG_GLPI["root_doc"]."/front/ticket.php");
}
if (Session::getCurrentInterface() == "helpdesk") {
Html::helpHeader("DSI : Gestion des accès", '', $_SESSION["glpiname"]);
} else {
Html::header("DSI : Gestion des accès", '', "", "");
}
function get_Users(){
global $DB;
$query = "SELECT id,concat(`realname`,' ',`firstname`) AS fullname
FROM `glpi_users`
WHERE is_deleted = 0 AND realname is not null AND firstname is not null order by fullname";
$result = $DB->query($query);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$res[] = $row;
}
return $res;
}
return null;
}
function get_Softwares(){
global $DB;
$query = "SELECT s.name,sv.name as version FROM `glpi_softwares` s
left join `glpi_softwareversions` sv on s.id = sv.softwares_id
where is_deleted = 0";
$result = $DB->query($query);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$res[] = $row;
}
return $res;
}
return null;
}
$title = array("Attribution accès", "Reconfiguration accès", "Retrait accès");
$profile = array("Administrateur", "Utilisateur", "Utilisateur avec approbation");
$type = array("Nouveau", "Reconfiguration", "Retrait");
$famtype = get_Softwares();
$_SESSION['modele'] = $modele ;
$currentuserid = $_SESSION["glpiID"];
echo "<style>
#messageBar {
opacity: 0.5;
background-color: white;
z-index: 100000;
position: fixed;
top: 0px;
width: 100%;
height: 100%;
}
.alert-danger {
color: #842029;
background-color: #f8d7da;
border-color: #f5c2c7;
}
.alert {
position: relative;
padding: 1rem 1rem;
margin-bottom: 1rem;
border: 1px solid transparent;
border-radius: 0.25rem;
}
</style>";
echo "<div id='messageBar' style='display: none;'>
<div style='text-align:center;position:fixed;top:50%;left:40%;'>
<img src='../file_upload/loading.gif'>
</div>
</div>";
echo "<div id='tabs1216654411' class='center vertical ui-tabs ui-corner-all ui-widget ui-widget-content ui-tabs-vertical ui-helper-clearfix ui-corner-left'>
<div id='ui-id-3' style=' margin-left: 0px; ' aria-live='polite' aria-labelledby='ui-id-2' role='tabpanel' class='ui-tabs-panel ui-corner-bottom ui-widget-content' aria-hidden='false'>
<br>
<form id='form' name='form' method='post' action='".$CFG_GLPI["root_doc"]."/front/dsi.demandes.acces.form.php' enctype='multipart/form-data'>
<input type='hidden' name='entities_id' value='0'>
<div class='spaced' id='tabsbody'>";
echo"<table class='tab_cadre_fixe' id='mainformtable'>
<tbody>
<tr class='headerRow'>
<th colspan='2' class=''>Demande et Approbation daccès</th>
<th colspan='2' class=''>".date("Y-m-d")."</th>
</tr>
<tr class=''>
<td width='20%'>Nom & Prénom Employé : </td>
<td width='30%'>
<select class='js-example-basic-single' name='id_user' id='id_user' onchange ='picklist_enchange();' required>
<option value=''>----</option>";
$Users = get_Users();
foreach ($Users as $user) {
echo '<option value="'.$user['id'].'-'.$user['fullname'].'">'.$user['fullname'].'</option>';
}
echo" </select>
</td>
<td width='20%'>Fonction : </td>
<td width='30%'>
<input style='width:80%;' id='fonction' type='text' name='fonction' value=''>
</td>
</tr>
<tr class=''>
<td width='20%'>Matricule : <span style='color:red'>*</span></td>
<td width='30%'>
<input id='matricule' type='text' name='matricule' value='' required>
</td>
<td width='20%'>Structure : </td>
<td width='30%'>
<input style='width:80%;' id='structure' type='text' name='structure' value='' >
</td>
</tr>
<tr class='' id='hardware_holder'>
<td width='20%'>Matériel Associé : <span style='color:red'>*</span></td>
<td colspan='3'>
<table id='hardware_content' style='padding-top: 20px;border: none;'>
<tbody>
</tbody>
</table>
</td>
</tr>
<tr class=''>
<td width='20%'>Profil Accès : <span style='color:red'>*</span></td>
<td width='30%'>
<select class='js-example-basic-single' name='accesprofile' id='accesprofile' required>";
foreach ($profile as $p) {
echo '<option value="'.$p.'">'.$p.'</option>';
}
echo" </select>
</td>
<td width='20%'>Type : </td>
<td width='30%'>
<select class='js-example-basic-single' name='accestype' id='accestype' onchange ='type_change(this);' required>";
foreach ($type as $p) {
echo '<option value="'.$p.'">'.$p.'</option>';
}
echo" </select>
</td>
</tr>
<tr class='' id='reason_holder' style='display: none;'>
<td width='20%'>Raison de la Reconfiguration/Retrait :</td>
<td width='50%' colspan='3'>
<textarea cols='6' rows='6' id='reason_to_reconfig' name='reason_to_reconfig' style='margin: 0px; width: 40%; height: 34px;'></textarea>
</td>
</tr>
<tr class=''>
<td width='20%'>Demandé par : <span style='color:red'>*</span></td>
<td width='30%'>
<input style='width:80%;' id='requested_by_id' type='text' name='requested_by_id' value='' required readonly>
</td>
<td width='20%'></td>
<td width='30%'></td>
</tr>";
modeles($modele);
echo"
<tr class='tab_bg_2'>
<td class='center' colspan='4'>
<div class='center'>
<button name='add' class='vsubmit'><i class='fas fa-plus'></i>&nbsp;Ajouter </button>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</form>
</div>
</div>";
function modeles($modele){
global $famtype;
if(isset($modele)){
switch ($modele) {
case 0:
echo'
<table class="tab_cadre_fixehov" id="dynamique" style="padding-top: 20px;">
<thead>
<tr>
<th></th>
<th>Détail des accès :</th>
<th class="">Remarque</th>
</tr>
</thead>
<tfoot>
<tr>
<th></th>
<th></th>
<th class="">Remarque</th>
</tr>
</tfoot>
<tbody id="result">
<tr class="tab_bg_2">
<td><i class="fa fa-trash deleteRow cursorPointer" onclick="supprimer(this)" title="Supprimer" style="display: inline-block;" ></i></td>
<td>
<select class="js-example-basic-single" name="software[]" required>';
foreach ($famtype as $t) {
echo '<option value="'.$t['name'].' '.$t['version'].'">'.$t['name'].' '.$t['version'].'</option>';
}
echo'
</select>
</td>
<td><textarea cols="6" rows="6" name="remarque[]" style="margin: 0px; width: 429px; height: 57px;"></textarea></td>
</tr>
</tbody>
</table>
<table class="tab_cadre_fixe">
<tr class="tab_bg_2">
<td><i name="add_lign" id="add_lign" class="fas fa-plus"></i>&nbsp;Ajouter</td>
<td></td>
</tr>
</table>';
break;
}
}
}
if (Session::getCurrentInterface() == "helpdesk") {
Html::helpFooter();
} else {
Html::footer();
}
?>
<script>
var root = <?php echo json_encode($root); ?>;
var famtype = <?php echo json_encode($famtype); ?>;
var currentuserid = <?php echo $currentuserid; ?>;
$("button[name='add']").click(function( event ) {
if($("#form")[0].checkValidity()) {
event.preventDefault();
$("button[name='add']").attr("disabled","disabled");
$("#messageBar").css("display","block");
$.ajax({
type: "POST",
url: "dsi.demandes.acces.form.php",
data: $('#form').serialize()
})
.done(function( msg ) {
window.location = root+"/front/ticket.php";
})
.fail(function(msg) {
$("#messageBar").css("display","none");
$("button[name='add']").removeAttr("disabled");
});
}
});
function get_fonction(){
$.ajax({
type: "GET",
url: root+"/ajax/accesmanagment.php?action=get_utilisateur_fonction&userid="+$( "#id_user" ).val().split("-")[0]
})
.done(function( msg ) {
$('#fonction').val(msg);
})
.fail(function(msg) {
console.log(msg);
});
}
function get_matricule(){
$.ajax({
type: "GET",
url: root+"/ajax/accesmanagment.php?action=get_utilisateur_matricule&userid="+$( "#id_user" ).val().split("-")[0]
})
.done(function( msg ) {
$('#matricule').val(msg);
})
.fail(function(msg) {
console.log(msg);
});
}
function get_structure(){
$.ajax({
type: "GET",
url: root+"/ajax/accesmanagment.php?action=get_utilisateur_structure&userid="+$( "#id_user" ).val() .split("-")[0]
})
.done(function( msg ) {
$('#structure').val(msg);
})
.fail(function(msg) {
console.log(msg);
});
}
function get_fullname_requesting(){
$.ajax({
type: "GET",
url: root+"/ajax/accesmanagment.php?action=get_utilisateur_fullname&userid="+currentuserid
})
.done(function( msg ) {
$('#requested_by_id').val(msg);
})
.fail(function(msg) {
console.log(msg);
});
}
function get_user_hardware(){
$.ajax({
type: "GET",
url: root+"/ajax/accesmanagment.php?action=get_utilisateur_hardware&userid="+$( "#id_user" ).val() .split("-")[0]
})
.done(function( msg ) {
//$('#requested_by_id').val(msg);
msg = JSON.parse(msg);
var optionsContent = ""
for(var i = 0; i< msg.length;i++){
optionsContent = optionsContent +
"<tr class=''><td>"+
"<input type='radio' id='materiel"+i+"' name='user_hardware' value='"+msg[i]+"' checked>&nbsp;"+
"<label for='materiel"+i+"'>"+msg[i]+"</label>"+
"</td></tr>";
}
$('#hardware_content tr').remove();
$('#hardware_content').append(
optionsContent
);
})
.fail(function(msg) {
console.log(msg);
});
}
function type_change(e){
if(e.value != "Nouveau"){
$('#reason_holder').show();
}else{
$('#reason_holder').hide();
}
}
$(document).ready(function(){
get_fullname_requesting();
$("#add_lign").click(function(){
var optionsContent = ""
for(var i = 0; i< famtype.length;i++){
optionsContent = optionsContent + "<option value='"+famtype[i]['name'] + ' ' + famtype[i]['version'] +"'>"+famtype[i]['name'] + ' ' + famtype[i]['version']+"</option>";
}
var markup = "<tr class='tab_bg_2'>"
+"<td><i class='fa fa-trash deleteRow cursorPointer' onclick='supprimer(this)' title='Supprimer' style='display: inline-block;' ></i></td>"
+"<td><select class='js-example-basic-single' name='software[]' required>"
+optionsContent
+"</select></td>"
+"<td><textarea cols='6' rows='6' name='remarque[]' style='margin: 0px; width: 429px; height: 57px;'></textarea></td>"
+"</tr>";
$("#dynamique").append(markup);
});
});
function supprimer(e){
$(e).parents("tr").remove();
}
function picklist_enchange(){
get_fonction();
get_matricule();
get_structure();
get_user_hardware();
}
</script>