first commit

This commit is contained in:
2025-08-07 13:15:31 +01:00
commit d903893b4c
21854 changed files with 4461308 additions and 0 deletions

382
ajax/decharge.php Normal file
View File

@ -0,0 +1,382 @@
<?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 update_sequence($last_seq , $type){
global $DB;
$stmt = $DB->prepare("UPDATE `sequence` SET `last_seq`= ? WHERE type = ? ");
$stmt->bind_param("is", $last_seq , $type);
$stmt->execute();
}
function get_num_refernce($type){
global $DB;
$res = array();
$stmt = $DB->prepare("SELECT * FROM `sequence` where type = ? ");
$stmt->bind_param("s",$type);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
while($row = $result->fetch_array(MYSQLI_ASSOC)) {
$res[] = $row;
}
return $res[0]['last_seq'];
}
return null;
}
function get_Phones($user_id){
global $DB;
$res = array();
$stmt = $DB->prepare(" SELECT DISTINCT glpi_phonemodels.name as modele , glpi_phonetypes.name as types ,glpi_phonepowersupplies.name as alimentation,
glpi_phones.`number_line`,glpi_phones.users_id ,glpi_phones.comment,glpi_phones.brand as marque,
glpi_phones.serial as num_serie
FROM `glpi_phones`
LEFT JOIN `glpi_phonemodels` ON (glpi_phones.phonemodels_id = glpi_phonemodels.id )
LEFT JOIN `glpi_phonetypes` ON (glpi_phones.phonetypes_id = glpi_phonetypes.id )
LEFT JOIN `glpi_phonepowersupplies` ON (glpi_phones.phonepowersupplies_id = glpi_phonepowersupplies.id )
WHERE glpi_phones.users_id = ? AND glpi_phones.is_deleted = 0 AND glpi_phones.is_template = 0");
$stmt->bind_param("i",$user_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
while($row = $result->fetch_array(MYSQLI_ASSOC)) {
$Phones[] = $row;
}
for($ph = 0 ; $ph < count($Phones) ; $ph++){
$data_all = array();
$temp = array();
$temp[0] = !empty($Phones[$ph]['types']) ? 'Type :'.$Phones[$ph]['types'] : null;
$temp[1] = !empty($Phones[$ph]['modele']) ? 'Modèle :'.$Phones[$ph]['modele'] : null;
$temp[2] = !empty($Phones[$ph]['marque']) ? 'Marque :'.$Phones[$ph]['marque'] : null;
$temp[3] = !empty($Phones[$ph]['alimentation']) ? 'Alimentation :'.$Phones[$ph]['alimentation'] : null;
$temp[4] = !empty($Phones[$ph]['num_serie']) ? 'S/N :'.$Phones[$ph]['num_serie'] : null;
$temp[5] = !empty($Phones[$ph]['number_line']) ? 'Nombre de lignes :'.$Phones[$ph]['number_line'] : null;
for($v = 0 ; $v < count($temp) ; $v++) {
if($temp[$v] != null) array_push($data_all ,$temp[$v]);
}
$Phone = ['Téléphone','1',implode(' , ',$data_all),$Phones[$ph]['comment']];
array_push($res,$Phone);
}
return $res;
}
return $res;
}
function get_Ordinateurs($user_id){
global $DB;
$res = array();
$stmt = $DB->prepare("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->bind_param("i",$user_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
while($row = $result->fetch_array(MYSQLI_ASSOC)) {
$Ordinateurs[] = $row;
}
for($i = 0 ; $i < count($Ordinateurs) ; $i++){
$data_all = array();
$temp = array();
$temp[0] = !empty($Ordinateurs[$i]['types']) ? 'Type : '.$Ordinateurs[$i]['types'] : null;
$temp[1] = !empty($Ordinateurs[$i]['modele']) ? 'Modèle : '.$Ordinateurs[$i]['modele'] : null;
$temp[2] = !empty($Ordinateurs[$i]['fabricant']) ? 'Fabricant : '.$Ordinateurs[$i]['fabricant'] : null;
$temp[3] = !empty($Ordinateurs[$i]['num_serie']) ? 'S/N : '.$Ordinateurs[$i]['num_serie'] : null;
$temp[4] = !empty($Ordinateurs[$i]['uuid']) ? $Ordinateurs[$i]['uuid'] : null;
for($k = 0 ; $k < count($temp) ; $k++) {
if($temp[$k] != null) array_push($data_all ,$temp[$k]);
}
$Ordinateur = ['Ordinateur','1',implode(' , ',$data_all),$Ordinateurs[$i]['comment']];
array_push($res,$Ordinateur);
}
return $res;
}
return $res;
}
function add(array $request){
global $DB;
if(isset($request["id_user"])){
$stmt = $DB->prepare("INSERT INTO decharge_entete(id_user , fonction, num, date, type, date_creation ,titre) VALUES ( ?,?,?,?,?, NOW(),?)");
$stmt->bind_param("isssss" ,
$request["id_user"] ,
$request["fonction"] ,
$request["num"] ,
$request["date"] ,
$request["type"] ,
$request["titre"]
);
$stmt->execute();
$lastId = $DB->insert_id();
$nbr = count($request["designation"]);
for($i=0;$i < $nbr ;$i++){
$stmt = $DB->prepare("INSERT INTO decharge_lignes (id_entete ,designation , quantite, fiche, etat) VALUES ( ?,?,?,?,?)");
$stmt->bind_param("issss" ,
$lastId ,
$request["designation"][$i] ,
$request["quantite"][$i] ,
$request["fiche"][$i] ,
$request["etat"][$i]
);
$stmt->execute();
}
update_sequence($request["num"] ,$request["type"]);
}
}
function update(array $request){
global $DB;
if(isset($request["id_entete"])){
//decharge_entete
$stmt = $DB->prepare("UPDATE decharge_entete SET fonction = ?,
num = ?, date = ?, type = ? , date_modification = NOW() ,titre = ?
where id_entete = ?
");
$stmt->bind_param("sssssi" ,
$request["fonction"] ,
$request["num"] ,
$request["date"] ,
$request["type"] ,
$request["titre"] ,
$request["id_entete"]
);
$stmt->execute();
//decharge_lignes
$nbr = count($request["designation"]);
for($i=0;$i < $nbr ;$i++){
//Insert
if($_POST["ids"][$i] == 0){
$stmt = $DB->prepare("INSERT INTO decharge_lignes (id_entete ,designation , quantite, fiche, etat) VALUES ( ?,?,?,?,?)");
$stmt->bind_param("issss" ,
$request["id_entete"] ,
$request["designation"][$i] ,
$request["quantite"][$i] ,
$request["fiche"][$i] ,
$request["etat"][$i]
);
$stmt->execute();
//Update
}elseif($_POST["ids"][$i] != 0){
$stmt = $DB->prepare("UPDATE decharge_lignes SET designation = ? , quantite = ?, fiche = ?, etat = ?
where id = ? ");
$stmt->bind_param("ssssi" ,
$request["designation"][$i] ,
$request["quantite"][$i] ,
$request["fiche"][$i] ,
$request["etat"][$i] ,
$request["ids"][$i]
);
$stmt->execute();
}
}
//Deleted
$idsToDelete = explode(",", $_GET['idsToDelete']);
for ($c = 0; $c< count($idsToDelete); $c++) {
$stmt = $DB->prepare( "DELETE FROM decharge_lignes WHERE id = ?");
$stmt->bind_param("i", $idsToDelete[$c]);
$stmt->execute();
}
}
}
function get_Function($user_id){
global $DB;
$stmt = $DB->prepare("SELECT value as fonction FROM `glpi_users`
LEFT JOIN picklist on glpi_users.id_fonction = picklist.id
WHERE glpi_users.id = ? ");
$stmt->bind_param("i",$user_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
while($row = $result->fetch_array(MYSQLI_ASSOC)) {
$res[] = $row;
}
return null;
}
return null;
}
function filtre($id , $num , $type , $date){
global $DB;
$filtre_values = array();
$id = $id <> 0 ? array_push($filtre_values,"en.id_user =".$id) : "";
$num = $num <> '' ? array_push($filtre_values,"en.num =".$num) : "";
$type = $type <> 'all' ? array_push($filtre_values,"en.type ='".$type."'") : "";
$date = $date <> '' ? array_push($filtre_values,"en.date ='".$date."'") : "";
if(count($filtre_values) > 0){
$sql=" WHERE ".implode(" and ",$filtre_values);
}else{
$sql="";
}
$query = "SELECT en.id_entete,en.fonction ,en.num,en.date,en.type ,
concat(glpi_users.realname,' ',glpi_users.firstname) as fullname
FROM decharge_entete as en
LEFT JOIN glpi_users on en.id_user = glpi_users.id ".$sql." ORDER BY `en`.`id_entete` DESC";
$result = $DB->query($query);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$res[] = $row;
}
return $res;
}
return null;
}
function delete_decharge($id){
global $DB;
//decharge_entete
$stmt = $DB->prepare("DELETE FROM decharge_entete where id_entete = ? ");
$stmt->bind_param("i" , $id);
$stmt->execute();
//decharge_lignes
$stmt = $DB->prepare("DELETE FROM decharge_lignes where id_entete = ? ");
$stmt->bind_param("i" , $id);
$stmt->execute();
}
if(isset($_POST)){
switch ($_GET['action']) {
case "add":
add($_POST);
break;
case "update":
update($_POST);
break;
/*
case "delete":
delete_decharge($_GET['id_entete']);
Html::redirect($CFG_GLPI["root_doc"]."/front/decharge.list.php");
break;
*/
case "get_utilisateur_fonction":
//header('Content-type: application/json');
$function = get_Function($_GET['userid']);
//echo json_encode($function);
echo $function;
break;
case "filtre":
header('Content-type: application/json; charset=utf-8');
$res = filtre($_GET['iduser'],$_GET['num'],$_GET['type'],$_GET['date']);
echo json_encode($res,JSON_UNESCAPED_UNICODE);
break;
case "user_equipments":
if(isset($_GET['userid']) && !empty($_GET['userid'])){
header('Content-type: application/json');
$equipments = array();
$Ordinateurs = get_Ordinateurs($_GET['userid']) ;
$Phones = get_Phones($_GET['userid']);
$equipments['ordinateurs'] = $Ordinateurs;
$equipments['phones'] = $Phones;
echo json_encode($equipments,JSON_UNESCAPED_UNICODE);
}
break;
case "get_refernce":
if(isset($_GET['type']) && !empty($_GET['type'])){
header('Content-type: application/json; charset=utf-8');
$res['last_num'] = get_num_refernce($_GET['type']);
echo json_encode($res);
}
break;
}
}