Files
MYSOPHAL/ajax/accesmanagment.php
2025-08-07 13:15:31 +01:00

209 lines
7.8 KiB
PHP

<?php
if (!defined('GLPI_ROOT')) {
define('GLPI_ROOT', dirname(__DIR__));
}
include_once GLPI_ROOT . '/inc/based_config.php';
// Init Timer to compute time of display
$TIMER_DEBUG = new Timer();
$TIMER_DEBUG->start();
/// TODO try to remove them if possible
include_once (GLPI_ROOT . "/inc/db.function.php");
// Standard includes
include_once (GLPI_ROOT . "/inc/config.php");
//disbled errors =>pour le variable res (Ajax)
ini_set('display_errors', 0);
Session::checkLoginUser();
global $DB;
function get_Function($user_id){
global $DB;
$query = "SELECT value as fonction FROM `glpi_users`
LEFT JOIN picklist on glpi_users.id_fonction = picklist.id
WHERE glpi_users.id = ?";
$stmt = $DB->prepare($query);
$stmt->bind_param("i" , $user_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$res[] = $row;
}
return $res[0]['fonction'];
}
return null;
}
function get_matricule($user_id){
global $DB;
$query = "SELECT registration_number AS mat FROM `glpi_users`
WHERE glpi_users.id = ?";
$stmt = $DB->prepare($query);
$stmt->bind_param("i" , $user_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$res[] = $row;
}
return $res[0]['mat'];
}
return null;
}
function get_structure($user_id){
global $DB;
$query = "SELECT value as structure FROM `glpi_users`
LEFT JOIN picklist on glpi_users.id_structure = picklist.id
WHERE glpi_users.id = ?";
$stmt = $DB->prepare($query);
$stmt->bind_param("i" , $user_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$res[] = $row;
}
return $res[0]['structure'];
}
return null;
}
function get_username($user_id){
global $DB;
$query = "SELECT concat(`realname`,' ',`firstname`) AS fullname
FROM `glpi_users`
WHERE glpi_users.id = ?";
$stmt = $DB->prepare($query);
$stmt->bind_param("i" , $user_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$res[] = $row;
}
return $res[0]['fullname'];
}
return null;
}
function get_Ordinateurs($user_id){
global $DB;
$res = array();
$query = "SELECT DISTINCT
glpi_computers.id AS Computer_id, glpi_manufacturers.name AS fabricant, glpi_computers.serial AS serial,
glpi_computertypes.name AS types, glpi_computermodels.name AS modele, glpi_users.id AS users_id,
glpi_computers.uuid , glpi_computers.comment AS comment , glpi_computers.serial as num_serie
FROM glpi_computers
LEFT JOIN glpi_states ON (glpi_computers.states_id = glpi_states.id )
LEFT JOIN glpi_manufacturers ON (glpi_computers.manufacturers_id = glpi_manufacturers.id )
LEFT JOIN glpi_computertypes ON (glpi_computers.computertypes_id = glpi_computertypes.id )
LEFT JOIN glpi_computermodels ON (glpi_computers.computermodels_id = glpi_computermodels.id )
LEFT JOIN glpi_items_operatingsystems ON (glpi_computers.id = glpi_items_operatingsystems.items_id AND glpi_items_operatingsystems.itemtype = 'Computer' )
LEFT JOIN glpi_operatingsystems AS glpi_operatingsystems_8 ON (glpi_items_operatingsystems.operatingsystems_id = glpi_operatingsystems_8.id )
LEFT JOIN glpi_locations ON (glpi_computers.locations_id = glpi_locations.id )
LEFT JOIN glpi_users ON (glpi_computers.users_id = glpi_users.id )
LEFT JOIN glpi_items_deviceprocessors ON (glpi_computers.id = glpi_items_deviceprocessors.items_id AND glpi_items_deviceprocessors.itemtype = 'Computer' )
LEFT JOIN glpi_deviceprocessors AS glpi_deviceprocessors_7 ON (glpi_items_deviceprocessors.deviceprocessors_id = glpi_deviceprocessors_7.id )
WHERE glpi_computers.is_deleted = 0 AND glpi_computers.is_template = 0 and glpi_users.id = ?
GROUP BY glpi_computers.id";
$stmt = $DB->prepare($query);
$stmt->bind_param("i" , $user_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$Ordinateurs[] = $row;
}
for($i = 0 ; $i < count($Ordinateurs) ; $i++){
$data_all = array();
$temp = array();
$temp[0] = !empty($Ordinateurs[$i]['types']) ? $Ordinateurs[$i]['types'] : null;
$temp[0] = !empty($Ordinateurs[$i]['fabricant']) ? $temp[0].' '.$Ordinateurs[$i]['fabricant'] : $temp[0];
$temp[1] = !empty($Ordinateurs[$i]['modele']) ? 'Modèle : '.$Ordinateurs[$i]['modele'] : null;
$temp[2] = !empty($Ordinateurs[$i]['num_serie']) ? 'S/N : '.$Ordinateurs[$i]['num_serie'] : null;
$temp[3] = !empty($Ordinateurs[$i]['uuid']) ? 'Caracteristiques : '.$Ordinateurs[$i]['uuid'] : null;
for($k = 0 ; $k < count($temp) ; $k++) {
if($temp[$k] != null) array_push($data_all ,$temp[$k]);
}
array_push($res,implode(' - ',$data_all));
}
return $res;
}
return $res;
}
if(isset($_POST)){
switch ($_GET['action']) {
case "get_utilisateur_fonction":
$function = get_Function($_GET['userid']);
echo $function;
break;
case "get_utilisateur_matricule":
$mat = get_matricule($_GET['userid']);
echo $mat;
break;
case "get_utilisateur_structure":
$struct = get_structure($_GET['userid']);
echo $struct;
break;
case "get_utilisateur_fullname":
$name = get_username($_GET['userid']);
echo $name;
break;
case "get_utilisateur_hardware":
$hardware = get_Ordinateurs($_GET['userid']);
echo json_encode($hardware);
break;
}
}