You are not logged in.
Bonjour,
j'essaie de créer un rapport me permettant d'afficher un classement type Top 10 des auteurs des tickets afin de leur montrer qu'il abuse un peu trop de cet outil dans l'entreprise (=surcharge pour l'administrateur réseau).
Pour ceci, j'ai créer 2 nouveaux fichiers: un fichier "d'affichage" et un fichier de langue. J'ai mis ces 2 fichiers dans un dossier du même nom que le fichier "d'affichage" dans le dossier "report" du plugin.
Mon problème : je n'arrive pas à le faire afficher mon rapport dans la liste de : Assistance>Statistiques. J'ai peut être oublié de mettre un élément majeur ...
je vous affiche mes 2 fichiers :
FICHIER D'AFFICHAGE statticketbyautor.php :
define('GLPI_ROOT', '../../../..');
include (GLPI_ROOT . "/inc/includes.php");
include (GLPI_ROOT . "/plugins/reports/report/statticketbyautor/stat.class.php");
commonHeader($LANG['Menu'][13],'',"maintain","stat");
checkRight("statistic","1");
if (empty($_REQUEST["type"])) {
$_REQUEST["type"] = "user";
}
if (empty($_REQUEST["showgraph"])) {
$_REQUEST["showgraph"] = 0;
}
if (empty($_REQUEST["date1"]) && empty($_REQUEST["date2"])) {
$year = date("Y")-1;
$_REQUEST["date1"] = date("Y-m-d",mktime(1,0,0,date("m"),date("d"),$year));
$_REQUEST["date2"] = date("Y-m-d");
}
if (!empty($_REQUEST["date1"])
&& !empty($_REQUEST["date2"])
&& strcmp($_REQUEST["date2"],$_REQUEST["date1"]) < 0) {
$tmp = $_REQUEST["date1"];
$_REQUEST["date1"] = $_REQUEST["date2"];
$_REQUEST["date2"] = $tmp;
}
if (!isset($_REQUEST["start"])) {
$_REQUEST["start"] = 0;
}
$items =
array($LANG['job'][4] => array('user' => array('title' => $LANG['common'][37],
'field' => 'glpi_tickets.users_id'),
'group' => array('title' => $LANG['common'][35],
'field' => 'glpi_tickets.groups_id')));
$INSELECT = "";
foreach ($items as $label => $tab) {
$INSELECT .= "<optgroup label=\"$label\">";
foreach ($tab as $key => $val) {
// Current field
if ($key == $_REQUEST["type"]) {
$field = $val["field"];
}
$INSELECT .= "<option value='$key' ".($key==$_REQUEST["type"]?"selected":"").">".$val['title'].
"</option>";
}
$INSELECT .= "</optgroup>";
}
echo "<div class='center'><form method='get' name='form' action='statticketbyautor.php'>";
echo "<table class='tab_cadre'><tr class='tab_bg_2'>";
echo "<td rowspan='2' class='center'>";
echo "<select name='type'>";
echo $INSELECT;
echo "</select></td>";
echo "<td class='right'>".$LANG['search'][8]." :</td><td>";
showDateFormItem("date1",$_REQUEST["date1"]);
echo "</td>";
echo "<td class='right'>".$LANG['stats'][7]." :</td>";
echo "<td rowspan='2' class='center'>";
echo "<input type='submit' class='button' name='submit' value='". $LANG['buttons'][7] ."'></td></tr>";
echo "<tr class='tab_bg_2'><td class='right'>".$LANG['search'][9]." :</td><td>";
showDateFormItem("date2",$_REQUEST["date2"]);
echo "</td><td class='center'>";
Dropdown::showYesNo('showgraph',$_REQUEST['showgraph']);
echo "</td>";
echo "</tr>";
echo "</table></form></div>";
$val = Stat::getItems($_REQUEST["date1"],$_REQUEST["date2"],$_REQUEST["type"]);
$params = array('type' => $_REQUEST["type"],
'field' => $field,
'date1' => $_REQUEST["date1"],
'date2' => $_REQUEST["date2"],
'start' => $_REQUEST["start"]);
printPager($_REQUEST['start'],count($val),$CFG_GLPI['root_doc'].'/plugins/reports/report/statticketbyautor/statticketbyautor.php',
"date1=".$_REQUEST["date1"]."&date2=".$_REQUEST["date2"].
"&type=".$_REQUEST["type"]."&showgraph=".$_REQUEST["showgraph"],
'Stat',$params);
if (!$_REQUEST['showgraph']) {
Stat::show($_REQUEST["type"],$_REQUEST["date1"],$_REQUEST["date2"],$_REQUEST['start'],$val);
} else {
$data=Stat::getDatas($_REQUEST["type"],$_REQUEST["date1"],$_REQUEST["date2"],$_REQUEST['start'],$val);
if (isset($data['opened']) && is_array($data['opened'])) {
foreach($data['opened'] as $key => $val){
$newkey=html_clean($key);
$cleandata[$newkey]=$val;
}
Stat::showGraph(array($LANG['stats'][5]=>$cleandata)
,array('title'=>$LANG['stats'][5],
'showtotal' => 1,
'unit' => $LANG['stats'][35],
'type' => 'pie'));
}
if (isset($data['solved']) && is_array($data['solved'])) {
foreach($data['solved'] as $key => $val){
$newkey=html_clean($key);
$cleandata[$newkey]=$val;
}
Stat::showGraph(array($LANG['stats'][11]=>$cleandata)
,array('title' => $LANG['stats'][11],
'showtotal' => 1,
'unit' => $LANG['stats'][35],
'type' => 'pie'));
}
}
commonFooter();
________________________________________________________________
FICHIER DE LANGUE statticketbyautor.fr_FR.php :
$LANG['plugin_reports']["statticketbyautor"][1]="Tickets par Auteur/Groupe";
En espérant avoir été clair ...
Offline
Version de GLPI ?
Contenu du fichier stat.class ? (include (GLPI_ROOT . "/plugins/reports/report/statticketbyautor/stat.class.php");)
CentOS 6.5 - CentOS 7.x
PHP 5.6 - PHP 7.x - MySQL 5.6 - MariaDB 10.2 + APC + oOPcache
GLPI from 0.72 to dev version
Certifiée ITIL (ITV2F, ITILF, ITILOSA)
Offline
La version sur laquelle je travaille est la 0.78.
Fichier stat.class.php ( La classe "show" ets encore en cours de dév ) :
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access directly to this file");
}
/**
* Computer class
*/
class Stat {
static function getItems($date1,$date2,$type) {
global $CFG_GLPI,$DB;
$val=array();
switch ($type) {
case "user" :
$val = Ticket::getUsedAuthorBetween($date1,$date2);
break;
case "group" :
$val = Ticket::getUsedGroupBetween($date1,$date2);
break;
}
return $val;
}
static function getDatas($type,$date1,$date2,$start,$value,$value2="") {
$export_data=array();
if (is_array($value)) {
$end_display=$start+$_SESSION['glpilist_limit'];
$numrows=count($value);
for ($i=$start ; $i< $numrows && $i<($end_display) ; $i++) {
//le nombre d'intervention - the number of intervention
$opened=Stat::constructEntryValues("inter_total",$date1,$date2,$type,$value[$i]["id"],$value2);
$nb_opened=array_sum($opened);
$export_data['opened'][$value[$i]['link']]=$nb_opened;
//le nombre d'intervention resolues - the number of resolved intervention
$solved=Stat::constructEntryValues("inter_solved",$date1,$date2,$type,$value[$i]["id"],$value2);
$nb_solved=array_sum($solved);
$export_data['solved'][$value[$i]['link']]=$nb_solved;
}
}
return $export_data;
}
static function show($type,$date1,$date2,$start,$value,$value2="") {
global $LANG,$CFG_GLPI;
// Set display type for export if define
$output_type=HTML_OUTPUT;
if (isset($_GET["display_type"])) {
$output_type=$_GET["display_type"];
}
if ($output_type==HTML_OUTPUT) { // HTML display
echo "<div class ='center'>";
}
if (is_array($value)) {
$end_display=$start+$_SESSION['glpilist_limit'];
$numrows=count($value);
if (isset($_GET['export_all'])) {
$start=0;
$end_display=$numrows;
}
$nbcols=8;
if ($output_type!=HTML_OUTPUT) { // not HTML display
$nbcols--;
}
echo Search::showHeader($output_type,$end_display-$start+1,$nbcols);
echo Search::showNewLine($output_type);
$header_num=1;
echo Search::showHeaderItem($output_type," ",$header_num);
if ($output_type==HTML_OUTPUT) // HTML display
echo Search::showHeaderItem($output_type,"",$header_num);
echo Search::showHeaderItem($output_type,$LANG['stats'][13],$header_num);
echo Search::showHeaderItem($output_type,$LANG['stats'][11],$header_num);
// End Line for column headers
echo Search::showEndLine($output_type);
$row_num=0;
for ($i=$start ; $i< $numrows && $i<($end_display) ; $i++) {
$row_num++;
$item_num=1;
// Record New Line with the name.
$value[$i]['newline'] = Search::showNewLine($output_type,$i%2);
$value[$i]['link'] = Search::showItem($output_type,$value[$i]['link'],$item_num,$row_num);
// Record STAT button in connection.
if ($output_type==HTML_OUTPUT) { // HTML display
$link="";
if ($value[$i]['id']>0) {
$link="<a href='stat.graph.php?id=".$value[$i]['id']."&date1=$date1&date2=".
"$date2&type=$type".(!empty($value2)?"&champ=$value2":"")."'>".
"<img src=\"".$CFG_GLPI["root_doc"]."/pics/stats_item.png\" alt='' title=''>".
"</a>";
//le nombre d'intervention - the number of intervention
$opened=Stat::constructEntryValues("inter_total",$date1,$date2,$type,$value[$i]["id"],$value2);
$nb_opened[$i]=array_sum($opened);
$value_open[$i] = Search::showItem($output_type,$nb_opened[$i],$item_num,$row_num);
$export_data['opened'][$value[$i]['link']]=$nb_opened;
//le nombre d'intervention resolues - the number of resolved intervention
$solved=Stat::constructEntryValues("inter_solved",$date1,$date2,$type,$value[$i]["id"],$value2);
$nb_solved=array_sum($solved);
$value[$i]['solved'] = Search::showItem($output_type,$nb_solved,$item_num,$row_num);
$export_data['solved'][$value[$i]['link']]=$nb_solved;
}
$value[$i]['ID'] = Search::showItem($output_type,$link,$item_num,$row_num);
}
$value[$i]['endline'] = Search::showEndLine($output_type);
$line_tab[$i] = $value[$i]['newline'].$value[$i]['link'].$value[$i]['ID'].$value_open[$i].$value[$i]['solved'].$value[$i]['endline'];
}
natsort( $value_open );
$i=1;
foreach ($value_open as $key => $value) {
$values_open[$i] = $line_tab[$key];
$i++;
}
echo $row_num;
echo $limit = $_SESSION['glpilist_limit'];
switch ($type){
case "user":
for ($i=$end_display; $i>=($row_num-$limit-1); $i--)
echo $values_open[$i];
break;
case "group":
if ( $limit<=5 ) {
for ($i=$end_display; $i>=($end_display-$limit); $i--)
echo $values_open[$i];
} else {
for ($i=$end_display; $i>=($end_display-$limit); $i--)
echo $values_open[$i];
}
break;
}
// Display footer
echo Search::showFooter($output_type);
} else {
echo $LANG['stats'][23];
}
if ($output_type==HTML_OUTPUT) // HTML display
echo "</div>";
}
static function constructEntryValues($type,$begin="",$end="",$param="",$value="",$value2="") {
global $DB;
$query = "";
$WHERE = getEntitiesRestrictRequest("WHERE","glpi_tickets");
$LEFTJOIN = "";
switch ($param) {
case "user" :
$WHERE .= " AND `glpi_tickets`.`users_id` = '$value'";
break;
case "group" :
$WHERE .= " AND `glpi_tickets`.`groups_id` = '$value'";
break;
}
switch($type) {
case "inter_total" :
$WHERE .= " AND ".getDateRequest("`glpi_tickets`.`date`",$begin,$end);
$query = "SELECT FROM_UNIXTIME(UNIX_TIMESTAMP(`glpi_tickets`.`date`),'%Y-%m') AS date_unix,
COUNT(`glpi_tickets`.`id`) AS total_visites
FROM `glpi_tickets`
$LEFTJOIN
$WHERE
GROUP BY date_unix
ORDER BY `glpi_tickets`.`date`";
break;
case "inter_solved" :
$WHERE .= " AND (`glpi_tickets`.`status` = 'closed'
OR `glpi_tickets`.`status` = 'solved')
AND `glpi_tickets`.`solvedate` IS NOT NULL ";
$WHERE .= " AND ".getDateRequest("`glpi_tickets`.`solvedate`",$begin,$end);
$query = "SELECT FROM_UNIXTIME(UNIX_TIMESTAMP(`glpi_tickets`.`solvedate`),'%Y-%m')
AS date_unix,
COUNT(`glpi_tickets`.`id`) AS total_visites
FROM `glpi_tickets`
$LEFTJOIN
$WHERE
GROUP BY date_unix
ORDER BY `glpi_tickets`.`solvedate`";
break;
}
$entrees=array();
$count=array();
if (empty($query)) {
return array();
}
$result=$DB->query($query);
if ($result && $DB->numrows($result)>0) {
while ($row = $DB->fetch_array($result)) {
$date = $row['date_unix'];
if ($type=="inter_avgtakeaccount") {
$min=$row["OPEN"];
if (!empty($row["FIRST"]) && !is_null($row["FIRST"]) && $row["FIRST"]<$min) {
$min=$row["FIRST"];
}
if (!isset($entrees["$date"])) {
$entrees["$date"]=$min;
$count["$date"]=1;
} else {
$entrees["$date"]+=$min;
$count["$date"]++;
}
} else {
$visites = round($row['total_visites']);
$entrees["$date"] = $visites;
}
}
}
if ($type=="inter_avgtakeaccount") {
foreach ($entrees as $key => $val) {
$entrees[$key] = round($entrees[$key] / $count[$key] / HOUR_TIMESTAMP);
}
}
// Remplissage de $entrees pour les mois ou il n'y a rien
$min=-1;
$max=0;
if (count($entrees)==0) {
return $entrees;
}
foreach ($entrees as $key => $val) {
$time=strtotime($key."-01");
if ($min>$time || $min<0) {
$min=$time;
}
if ($max<$time) {
$max=$time;
}
}
$end_time=strtotime(date("Y-m",strtotime($end))."-01");
$begin_time=strtotime(date("Y-m",strtotime($begin))."-01");
if ($max<$end_time) {
$max=$end_time;
}
if ($min>$begin_time) {
$min=$begin_time;
}
$current=$min;
while ($current<=$max) {
$curentry=date("Y-m",$current);
if (!isset($entrees["$curentry"])) {
$entrees["$curentry"]=0;
}
$month=date("m",$current);
$year=date("Y",$current);
$current=mktime(0,0,0,intval($month)+1,1,intval($year));
}
ksort($entrees);
return $entrees;
}
/** Get groups assigned to tickets between 2 dates
* BASED ON SPIP DISPLAY GRAPH : www.spip.net
* @param $type string : "month" or "year"
* @param $entrees array : array containing data to displayed
* @param $titre string : title
* @param $unit string : unit
* @param $showtotal boolean : also show total values ?
* @return array contains the distinct groups assigned to a tickets
*/
static function graphBy($entrees,$titre="",$unit="",$showtotal=1,$type="month") {
global $DB,$CFG_GLPI,$LANG;
$total="";
if ($showtotal==1) {
$total=array_sum($entrees);
}
echo "<p class='center'>";
echo "<font face='verdana,arial,helvetica,sans-serif' size='2'>";
echo "<strong>$titre - $total $unit</strong></font>";
echo "<div class='center'>";
if (count($entrees)>0) {
$max = max($entrees);
$maxgraph = substr(ceil(substr($max,0,2) / 10)."000000000000", 0, strlen($max));
if ($maxgraph < 10) {
$maxgraph = 10;
}
if (1.1 * $maxgraph < $max) {
$maxgraph.="0";
}
if (0.8*$maxgraph > $max) {
$maxgraph = 0.8 * $maxgraph;
}
$rapport = 200 / $maxgraph;
$largeur = floor(420 / (count($entrees)));
if ($largeur < 1) {
$largeur = 1;
}
if ($largeur > 50) {
$largeur = 50;
}
}
echo "<table class='tab_glpi'><tr>";
echo "<td style='background-image:url(".$CFG_GLPI["root_doc"]."/pics/fond-stats.gif)' >";
echo "<table><tr><td bgcolor='black'>";
echo "<img src='".$CFG_GLPI["root_doc"]."/pics/noir.png' width='1' height='200' alt=''></td>";
// Presentation graphique
$n = 0;
$decal = 0;
$tab_moyenne = "";
$total_loc = 0;
while (list($key, $value) = each($entrees)) {
$n++;
if ($decal == 30) {
$decal = 0;
}
$decal ++;
$tab_moyenne[$decal] = $value;
$total_loc = $total_loc + $value;
reset($tab_moyenne);
$moyenne = 0;
while (list(,$val_tab) = each($tab_moyenne)) {
$moyenne += $val_tab;
}
$moyenne = $moyenne / count($tab_moyenne);
$hauteur_moyenne = round($moyenne * $rapport) ;
$hauteur = round($value * $rapport) ;
echo "<td class='bottom' width=".$largeur.">";
if ($hauteur >= 0) {
if ($hauteur_moyenne > $hauteur) {
$difference = ($hauteur_moyenne - $hauteur) -1;
echo "<img alt=\"$key: $value\" title=\"$key: $value\" src='".$CFG_GLPI["root_doc"].
"/pics/moyenne.png' width=".$largeur." height='1' >";
echo "<img alt=\"$key: $value\" title=\"$key: $value\" src='".$CFG_GLPI["root_doc"].
"/pics/rien.gif' width=".$largeur." height=".$difference." >";
echo "<img alt=\"$key: $value\" title=\"$key: $value\" src='".$CFG_GLPI["root_doc"].
"/pics/noir.png' width=".$largeur." height='1' >";
if (strstr($key,"-01")) { // janvier en couleur foncee
echo "<img alt=\"$key: $value\" title=\"$key: $value\" src='".$CFG_GLPI["root_doc"].
"/pics/fondgraph1.png' width=".$largeur." height=".$hauteur." >";
} else {
echo "<img alt=\"$key: $value\" title=\"$key: $value\" src='".$CFG_GLPI["root_doc"].
"/pics/fondgraph2.png' width=".$largeur." height=".$hauteur." >";
}
} else if ($hauteur_moyenne < $hauteur) {
$difference = ($hauteur - $hauteur_moyenne) -1;
echo "<img alt=\"$key: $value\" title=\"$key: $value\" src='".$CFG_GLPI["root_doc"].
"/pics/noir.png' width=".$largeur." height='1'>";
if (strstr($key,"-01")) { // janvier en couleur foncee
$couleur = "1";
$couleur2 = "2";
} else {
$couleur = "2";
$couleur2 = "1";
}
echo "<img alt=\"$key: $value\" title=\"$key: $value\" src='".$CFG_GLPI["root_doc"].
"/pics/fondgraph$couleur.png' width=".$largeur." height=".$difference.">";
echo "<img alt=\"$key: $value\" title=\"$key: $value\" src='".$CFG_GLPI["root_doc"].
"/pics/moyenne.png' width=".$largeur." height='1'>";
echo "<img alt=\"$key: $value\" title=\"$key: $value\" src='".$CFG_GLPI["root_doc"].
"/pics/fondgraph$couleur.png' width=".$largeur." height=".$hauteur_moyenne.">";
} else {
echo "<img alt=\"$key: $value\" title=\"$key: $value\" src='".$CFG_GLPI["root_doc"].
"/pics/noir.png' width=".$largeur." height='1'>";
if (strstr($key,"-01")) { // janvier en couleur foncee
echo "<img alt=\"$key: $val_tab\" title=\"$key: $value\" src='".$CFG_GLPI["root_doc"].
"/pics/fondgraph1.png' width=".$largeur." height=".$hauteur.">";
} else {
echo "<img alt=\"$key: $value\" title=\"$key: $value\" src='".$CFG_GLPI["root_doc"].
"/pics/fondgraph2.png' width=".$largeur." height=".$hauteur.">";
}
}
}
echo "<img alt=\"$value\" title=\"$value\" src='".$CFG_GLPI["root_doc"].
"/pics/rien.gif' width=".$largeur." height='1'>";
echo "</td>\n";
}
echo "<td bgcolor='black'>";
echo "<img src='".$CFG_GLPI["root_doc"]."/pics/noir.png' width='1' height='1' alt=''></td></tr>";
if ($largeur>10) {
echo "<tr><td></td>";
foreach ($entrees as $key => $val) {
if ($type=="month") {
$splitter=explode("-",$key);
echo "<td class='center'>".utf8_substr($LANG['calendarM'][$splitter[1]-1],0,3)."</td>";
} else if ($type=="year") {
echo "<td class='center'>".substr($key,2,2)."</td>";
}
}
echo "</tr>";
}
if ($maxgraph<=10) {
$r=2;
} else if ($maxgraph<=100) {
$r=1;
} else {
$r=0;
}
echo "</table>";
echo "</td>";
echo "<td style='background-image:url(".$CFG_GLPI["root_doc"]."/pics/fond-stats.gif)' class='bottom'>";
echo "<img src='".$CFG_GLPI["root_doc"]."/pics/rien.gif' style='background-color:black;' ".
"width='3' height='1' alt=''></td>";
echo "<td><img src='".$CFG_GLPI["root_doc"]."/pics/rien.gif' width='5' height='1' alt=''></td>";
echo "<td class='top'>";
echo "<table>";
echo "<tr><td height='15' class='top'>";
echo "<font face='arial,helvetica,sans-serif' size='1' class ='b'>".
formatNumber($maxgraph,false,$r)."</font></td></tr>";
echo "<tr><td height='25' class='middle'>";
echo "<font face='arial,helvetica,sans-serif' size='1' color='#999999'>".
formatNumber(7*($maxgraph/8),false,$r)."</font></td></tr>";
echo "<tr><td height='25' class='middle'>";
echo "<font face='arial,helvetica,sans-serif' size='1'>".formatNumber(3*($maxgraph/4),false,$r);
echo "</font></td></tr>";
echo "<tr><td height='25' class='middle'>";
echo "<font face='arial,helvetica,sans-serif' size='1' color='#999999'>".
formatNumber(5*($maxgraph/8),false,$r)."</font></td></tr>";
echo "<tr><td height='25' class='middle'>";
echo "<font face='arial,helvetica,sans-serif' size='1' class ='b'>".
formatNumber($maxgraph/2,false,$r)."</font></td></tr>";
echo "<tr><td height='25' class='middle'>";
echo "<font face='arial,helvetica,sans-serif' size='1' color='#999999'>".
formatNumber(3*($maxgraph/8),false,$r)."</font></td></tr>";
echo "<tr><td height='25' class='middle'>";
echo "<font face='arial,helvetica,sans-serif' size='1'>".formatNumber($maxgraph/4,false,$r);
echo "</font></td></tr>";
echo "<tr><td height='25' class='middle'>";
echo "<font face='arial,helvetica,sans-serif' size='1' color='#999999'>".
formatNumber(1*($maxgraph/8),false,$r)."</font></td></tr>";
echo "<tr><td height='10' class='bottom'>";
echo "<font face='arial,helvetica,sans-serif' size='1' class='b'>0</font></td></tr>";
echo "</table>";
echo "</td></tr></table>";
echo "</div>";
}
/** Get groups assigned to tickets between 2 dates
* @param $entrees array : array containing data to displayed
* @param $options array : options
* - title string title displayed (default empty)
* - showtotal boolean show total in title (default false)
* - width integer width of the graph (default 700)
* - height integer height of the graph (default 300)
* - unit integer height of the graph (default empty)
* - type integer height of the graph (default line) : line bar pie
* - csv boolean export to CSV (default true)
* @return array contains the distinct groups assigned to a tickets
*/
static function showGraph($entrees,$options=array()) {
global $CFG_GLPI,$LANG;
if ($uid=getLoginUserID(false)) {
if (!isset($_SESSION['glpigraphtype'])) {
$_SESSION['glpigraphtype']=$CFG_GLPI['default_graphtype'];
}
$param['showtotal'] = false;
$param['title'] = '';
$param['width'] = 900;
$param['height'] = 300;
$param['unit'] = '';
$param['type'] = 'line';
$param['csv'] = true;
if (is_array($options) && count($options)) {
foreach ($options as $key => $val) {
$param[$key]=$val;
}
}
// Clean data
if (is_array($entrees) && count($entrees)) {
foreach ($entrees as $key => $val) {
if (!is_array($val) || count($val)==0) {
unset($entrees[$key]);
}
}
}
if (!is_array($entrees) || count($entrees) == 0) {
if (!empty($param['title'])) {
echo "<div class='center'>".$param['title']." : ".$LANG['stats'][2]."</div>";
}
return false;
}
echo "<div class='center-h' style='width:".$param['width']."px'>";
echo "<div>";
switch ($param['type']) {
case 'pie':
// Check datas : sum must be > 0
reset($entrees);
$sum=array_sum(current($entrees));
while ($sum==0 && $data=next($entrees)) {
$sum+=array_sum($data);
}
if ($sum==0) {
return false;
}
$graph = new ezcGraphPieChart();
$graph->palette = new GraphPalette();
$graph->options->font->maxFontSize = 15;
$graph->title->background = '#EEEEEC';
$graph->renderer = new ezcGraphRenderer3d();
$graph->renderer->options->pieChartHeight = 20;
$graph->renderer->options->moveOut = .2;
$graph->renderer->options->pieChartOffset = 63;
$graph->renderer->options->pieChartGleam = .3;
$graph->renderer->options->pieChartGleamColor = '#FFFFFF';
$graph->renderer->options->pieChartGleamBorder = 2;
$graph->renderer->options->pieChartShadowSize = 5;
$graph->renderer->options->pieChartShadowColor = '#BABDB6';
break;
case 'bar':
$graph = new ezcGraphBarChart();
$graph->options->fillLines = 210;
$graph->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedLabelRenderer();
$graph->xAxis->axisLabelRenderer->angle = 45;
$graph->xAxis->axisSpace = .2;
$graph->yAxis->min = 0;
$graph->palette = new GraphPalette();
$graph->options->font->maxFontSize = 15;
$graph->title->background = '#EEEEEC';
$graph->renderer = new ezcGraphRenderer3d();
$graph->renderer->options->legendSymbolGleam = .5;
$graph->renderer->options->barChartGleam = .5;
break;
case 'line':
// No break default case
default :
$graph = new ezcGraphLineChart();
$graph->options->fillLines = 210;
$graph->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedLabelRenderer();
$graph->xAxis->axisLabelRenderer->angle = 45;
$graph->xAxis->axisSpace = .2;
$graph->yAxis->min = 0;
$graph->palette = new GraphPalette();
$graph->options->font->maxFontSize = 15;
$graph->title->background = '#EEEEEC';
$graph->renderer = new ezcGraphRenderer3d();
$graph->renderer->options->legendSymbolGleam = .5;
$graph->renderer->options->barChartGleam = .5;
$graph->renderer->options->depth = 0.07;
break;
}
if (!empty($param['title'])) {
$pretoadd="";
$posttoadd="";
if (!empty($param['unit'])) {
$posttoadd = " ".$param['unit'];
$pretoadd = " - ";
}
// Add to title
if (count($entrees)==1) {
$param['title'] .= $pretoadd;
if ($param['showtotal']==1) {
reset($entrees);
$param['title'] .= array_sum(current($entrees));
}
$param['title'] .= $posttoadd;
} else { // add sum to legend and unit to title
$param['title'] .=$pretoadd.$posttoadd;
if ($param['showtotal']==1) {
$entree_tmp=$entrees;
$entrees=array();
foreach ($entree_tmp as $key => $data) {
$entrees[$key." (".array_sum($data).")"]=$data;
}
}
}
$graph->title = $param['title'];
}
if (count($entrees)==1) {
$graph->legend = false;
}
switch ($_SESSION['glpigraphtype']) {
case "png" :
$extension="png";
$graph->driver = new ezcGraphGdDriver();
$graph->options->font = GLPI_FONT_FREESANS;
break;
default:
$extension="svg";
break;
}
$filename=$uid.'_'.mt_rand();
$csvfilename=$filename.'.csv';
$filename.='.'.$extension;
foreach ($entrees as $label => $data) {
$graph->data[$label] = new ezcGraphArrayDataSet( $data );
$graph->data[$label]->symbol = ezcGraph::NO_SYMBOL;
}
switch ($_SESSION['glpigraphtype']) {
case "png" :
$graph->render( $param['width'], $param['height'], GLPI_GRAPH_DIR.'/'.$filename );
echo "<img src='".$CFG_GLPI['root_doc']."/front/graph.send.php?file=$filename'>";
break;
default:
$graph->render( $param['width'], $param['height'], GLPI_GRAPH_DIR.'/'.$filename );
echo "<object data='".$CFG_GLPI['root_doc']."/front/graph.send.php?file=$filename'
type='image/svg+xml' width='".$param['width']."' height='".$param['height']."'>
<param name='src' value='".$CFG_GLPI['root_doc']."/front/graph.send.php?file=$filename'>
You need a browser capeable of SVG to display this image.
</object> ";
break;
}
// Render CSV
if ($param['csv']) {
if ($fp = fopen(GLPI_GRAPH_DIR.'/'.$csvfilename, 'w')) {
// reformat datas
$values=array();
$labels=array();
$row_num=0;
foreach ($entrees as $label => $data) {
$labels[$row_num]=$label;
if (is_array($data) && count($data)) {
foreach ($data as $key => $val) {
if (!isset($values[$key])) {
$values[$key]=array();
}
$values[$key][$row_num]=$val;
}
}
$row_num++;
}
ksort($values);
// Print labels
fwrite($fp,";");
foreach ($labels as $val) {
fwrite($fp,"$val;");
}
fwrite($fp,"\n");
foreach ($values as $key => $data) {
fwrite($fp,"$key;");
foreach ($data as $value) {
fwrite($fp,"$value;");
}
fwrite($fp,"\n");
}
fclose($fp);
}
}
echo "</div>";
echo "<div class='right' style='width:".$param['width']."px'>";
if ($_SESSION['glpigraphtype']!='svg') {
echo " <a href='".$CFG_GLPI['root_doc'].
"/front/graph.send.php?switchto=svg'>SVG</a>";
}
if ($_SESSION['glpigraphtype']!='png') {
echo " <a href='".$CFG_GLPI['root_doc'].
"/front/graph.send.php?switchto=png'>PNG</a>";
}
if ($param['csv']) {
echo " / <a href='".$CFG_GLPI['root_doc'].
"/front/graph.send.php?file=$csvfilename'>CSV</a>";
}
echo "</div>";
echo '</div>';
}
}
static function showItems($target,$date1,$date2,$start) {
global $DB,$CFG_GLPI,$LANG;
$view_entities=isMultiEntitiesMode();
if ($view_entities) {
$entities=getAllDatasFromTable('glpi_entities');
}
$output_type=HTML_OUTPUT;
if (isset($_GET["display_type"])) {
$output_type=$_GET["display_type"];
}
if (empty($date2)) {
$date2=date("Y-m-d");
}
$date2.=" 23:59:59";
// 1 an par defaut
if (empty($date1)) {
$date1 = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")-1));
}
$date1.=" 00:00:00";
$query = "SELECT `itemtype`, `items_id`, COUNT(*) AS NB
FROM `glpi_tickets`
WHERE `date` <= '$date2'
AND `date` >= '$date1' ".
getEntitiesRestrictRequest("AND","glpi_tickets")."
AND `itemtype` <> ''
AND `items_id` > 0
GROUP BY `itemtype`, `items_id`
ORDER BY NB DESC";
$result=$DB->query($query);
$numrows=$DB->numrows($result);
if ($numrows>0) {
if ($output_type==HTML_OUTPUT) {
printPager($start,$numrows,$target,
"date1=".$date1."&date2=".$date2."&type=hardwares&start=$start",
'Stat');
echo "<div class='center'>";
}
$end_display=$start+$_SESSION['glpilist_limit'];
if (isset($_GET['export_all'])) {
$end_display=$numrows;
}
echo Search::showHeader($output_type,$end_display-$start+1,2,1);
$header_num=1;
echo Search::showNewLine($output_type);
echo Search::showHeaderItem($output_type,$LANG['common'][1],$header_num);
if ($view_entities) {
echo Search::showHeaderItem($output_type,$LANG['entity'][0],$header_num);
}
echo Search::showHeaderItem($output_type,$LANG['stats'][13],$header_num);
echo Search::showEndLine($output_type);
$DB->data_seek($result,$start);
$i=$start;
if (isset($_GET['export_all'])) {
$start=0;
}
for ($i = $start ;$i < $numrows && $i<$end_display ;$i++) {
$item_num=1;
// Get data and increment loop variables
$data=$DB->fetch_assoc($result);
if (!class_exists($data["itemtype"])) {
continue;
}
$item = new $data["itemtype"]();
if ($item->getFromDB($data["items_id"])) {
echo Search::showNewLine($output_type,$i%2);
echo Search::showItem($output_type,$item->getTypeName()." - ".$item->getLink(),$item_num,
$i-$start+1,"class='center'"." ".
($item->isDeleted()?" class='deleted' ":""));
if ($view_entities) {
$ent=$item->getEntityID();
if ($ent==0) {
$ent=$LANG['entity'][2];
} else {
$ent=$entities[$ent]['completename'];
}
echo Search::showItem($output_type,$ent,$item_num,$i-$start+1,"class='center'"." ".
($item->isDeleted()?" class='deleted' ":""));
}
echo Search::showItem($output_type,$data["NB"],$item_num,$i-$start+1,
"class='center'"." ".
($item->isDeleted()?" class='deleted' ":""));
}
}
echo Search::showFooter($output_type);
if ($output_type==HTML_OUTPUT) {
echo "</div>";
}
}
}
}
Offline
Il manque l'url dans votre common header.
Essayez commonHeader($LANG['Menu'][29],$_SERVER['PHP_SELF'],"maintain","stat");
CentOS 6.5 - CentOS 7.x
PHP 5.6 - PHP 7.x - MySQL 5.6 - MariaDB 10.2 + APC + oOPcache
GLPI from 0.72 to dev version
Certifiée ITIL (ITV2F, ITILF, ITILOSA)
Offline
désolé cela a rien fait du tout ! C'est assez bizarre car dans le fichier plugins/reports/docs/LISEZMOI, la doc précise :
" Ce plugin fournit des rapports supplémentaires.
- Il permet d’ajouter très facilement de nouveaux rapports
(via l’ajout d’un fichier PHP pour le rapport et un fichier de langue associé).
- Le plugin prend en charge la gestion de droits de tout nouveau rapport ajouté.
- il fournit, pour exemple, quelques rapports
- Des nouveaux rapports peuvent être rapidement ajoutés grâce à la fonction SimpleReport "
En revanche la fonction SimpleReport n'est pas utilisé dans les rapports proposés en exemple
Offline
La fonction SimpleReport est dépréciée (juste conservée pour compatibilité).
Les nouveaux rapports utilisent de préférences la classe AutoReport, plus performante, et permettant la gestion des critères.
+
Dév. Fedora 29 - PHP 5.6/7.0/7.1/7.2/7.3/7.4 - MariaDB 10.3 - GLPI master
Certifié ITILv3 - RPM pour Fedora, RHEL et CentOS sur https://blog.remirepo.net/
Offline
Justement je l'ai observé celle-ci aussi.
Elle se trouve dans le fichier : plugins/reports/inc/autoreport.class.php.
D'ailleurs si l'on s'inspire des rapports d'exemple, ils utilisent la fonction :
$report = new PluginReportsAutoReport("statnightticketsbypriority");
N'est ce pas cela qu'il me manque dans mon fichier statticketbyautor.php ?
Offline
La blague ! Après avoir redémarré 5 fois Wamp Server, mon rapport est enfin apparu dans la liste ! Comment ? pourquoi ? aucune idée !
Je n'ai strictement rien touché dans les codes pourtant ... Enfin merci aux personnes qui m'ont aidés .
JE FERME
Offline