1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
<?php
error_log("in downtime 1");
require_once 'includes/functions.php';
global $special_cat;
global $graphDirectory;
$displayGraph = 1;
$largeurImage = 500;
$hauteurImage = 400;
$largeurBarre = 15;
$ecartement = 35;
$police = 4;
if($displayGraph == true){
header ("Content-type: image/png");
}
$where='';
$sup = getParameter('sup','');
if($sup != ''){
$where .= ' AND glpi_followups.date > "'.$sup.'" ';
}
$item = getParameter('item','');
$filename = '';
if($item == 'planned'){
$where .= ' AND completecategory = "'.$special_cat['maintenance'].'" ';
}
if($item == 'unplanned'){
$where .= ' AND completecategory = "'.$special_cat['panne'].'" ';
}
$filename = $graphDirectory.'/'.getParameter('name','empty').'.gif';
if($item=='')exit;
$sql = 'SELECT glpi_followups.realtime AS realtime,EXTRACT(YEAR_MONTH FROM glpi_followups.date) AS period
FROM glpi_followups
LEFT JOIN glpi_tracking ON glpi_followups.tracking = glpi_tracking.ID
WHERE glpi_followups.realtime > 0
'.$where.'
ORDER BY period ASC;';
//error_log($sql);
$record = runSQL($sql);
if($sup ==''){
exit('date missing');
}else{
$supA = substr($sup,0,4);
$supM = substr($sup,5,2);
$periods = array();
$barres = array();
}
for($i=0;$i<13;$i++){
if(strlen($supM) == 1)
array_push($periods,$supA.'0'.$supM);
else
array_push($periods,$supA.$supM);
array_push($barres,0);
$supM++;
if($supM==13){
$supA++;
$supM=1;
}
}
foreach($record as $val){
for($i=0;$i<count($periods);$i++){
if($val['period'] == $periods[$i]){
$barres[$i]+=$val['realtime'];
break 1;
}
}
}
$max = 0;
foreach($barres as &$val){
if($val > $max)
$max = $val;
}
$im = imagecreatetruecolor ($largeurImage, $hauteurImage) or error_log("Erreur lors de la creation de l'image");
$blanc = imagecolorallocate ($im, 255, 255, 255);
$noir = imagecolorallocate ($im, 0, 0, 0);
$bleu = imagecolorallocate ($im, 220, 218, 255);
$rouge = imagecolorallocate ($im, 255, 0, 255);
// traces barres vertical
for ($i=0; $i<count($barres); $i++) {
$hmax = 275;
$hauteurImageRectangle = $barres[$i]*$hmax/$max; // $hauteurImageRectangle est la hauteur du rectangle dessiné
imagefilledrectangle ($im, ($i+1)*$ecartement-$largeurBarre/2, $hauteurImage-$hauteurImageRectangle-100, ($i+1)*$ecartement+$largeurBarre/2, $hauteurImage-100, $bleu);
}
if($displayGraph == true){
imagepng($im,$filename); // saves the image on disk
}
imagedestroy($im);
?> |