";
- }
- }
-
-
- function showImage($contents, $export = "png") {
- global $CFG_GLPI;
-
- if ($export!="odt" && $export!="odtall") {
-
- //test browser (if IE < 9, show img from temp dir instead base64 inline)
- if (isset($_SERVER["HTTP_USER_AGENT"])) {
- $ua = trim(strtolower($_SERVER["HTTP_USER_AGENT"]));
- $pattern = "/msie\s(\d+)\.0/";
- if (preg_match($pattern, $ua, $arr)) {
- $ie_version = $arr[1];
- if (version_compare($ie_version, '9') < 0) {
- $rand=mt_rand();
- $filename = "mreporting_img_$rand.png";
- $filedir = GLPI_ROOT."/files/_plugins/mreporting/$filename";
- file_put_contents($filedir, $contents);
-
- echo "
";
- return;
- }
- }
- }
-
- echo "
";
-
- }
- }
-
-
- function generateImage($params) {
-
- // Default values of parameters
- $image = "";
- $export = "png";
- $f_name = "";
- $class = "";
- $title = "";
- $unit = '';
- $raw_datas = [];
- $withdata = 0;
-
- foreach ($params as $key => $val) {
- $$key=$val;
- }
-
- ob_start();
-
- if ($export=="odt") {
- $show_graph = PluginMreportingConfig::showGraphConfigValue($f_name, $class);
- if ($show_graph) {
- $path=GLPI_PLUGIN_DOC_DIR."/mreporting/".$f_name.".png";
- imagepng($image, $path);
- }
- $common = new PluginMreportingCommon();
- $options[] = ["title" => $title,
- "f_name" => $f_name,
- "class" => $class,
- "randname" => $randname,
- "raw_datas" => $raw_datas,
- "withdata" => $withdata];
- $common->generateOdt($options);
- return true;
-
- } else if ($export=="odtall") {
-
- $show_graph = PluginMreportingConfig::showGraphConfigValue($f_name, $class);
- if ($show_graph) {
- $path=GLPI_PLUGIN_DOC_DIR."/mreporting/".$f_name.".png";
- imagepng($image, $path);
- }
- if (isset($raw_datas['datas'])) {
- $_SESSION['glpi_plugin_mreporting_odtarray'][]=["title" => $title,
- "f_name" => $f_name,
- "class" => $class,
- "randname" => $randname,
- "raw_datas" => $raw_datas,
- "withdata" => $withdata];
- }
-
- return true;
-
- } else {
- imagepng($image);
- $contents = ob_get_contents();
- ob_end_clean();
- return $contents;
- }
-
- }
-
-
- static function getColors($index = 20) {
- $colors = PluginMreportingConfig::getColors($index);
- foreach ($colors as &$color) {
- $color = str_replace('#', '', $color);
- }
- return $colors;
- }
+ }
+ if ($options['export'] != "odt" && $options['export'] != "odtall") {
+ echo "
";
+ }
+ }
+
+
+ public function showImage($contents, $export = "png")
+ {
+ global $CFG_GLPI;
+
+ if ($export != "odt" && $export != "odtall") {
+ //test browser (if IE < 9, show img from temp dir instead base64 inline)
+ if (isset($_SERVER["HTTP_USER_AGENT"])) {
+ $ua = trim(strtolower($_SERVER["HTTP_USER_AGENT"]));
+ $pattern = "/msie\s(\d+)\.0/";
+ if (preg_match($pattern, $ua, $arr)) {
+ $ie_version = $arr[1];
+ if (version_compare($ie_version, '9') < 0) {
+ $rand = mt_rand();
+ $filename = "mreporting_img_$rand.png";
+ $filedir = GLPI_ROOT . "/files/_plugins/mreporting/$filename";
+ file_put_contents($filedir, $contents);
+
+ echo "

";
+ return;
+ }
+ }
+ }
+
+ echo "

+ . ")
";
+ }
+ }
+
+
+ public function generateImage($params)
+ {
+
+ // Default values of parameters
+ $image = "";
+ $export = "png";
+ $f_name = "";
+ $class = "";
+ $title = "";
+ $unit = '';
+ $raw_datas = [];
+ $withdata = 0;
+
+ foreach ($params as $key => $val) {
+ $$key = $val;
+ }
+
+ ob_start();
+
+ if ($export == "odt") {
+ $show_graph = PluginMreportingConfig::showGraphConfigValue($f_name, $class);
+ if ($show_graph) {
+ $path = GLPI_PLUGIN_DOC_DIR . "/mreporting/" . $f_name . ".png";
+ imagepng($image, $path);
+ }
+ $common = new PluginMreportingCommon();
+ $options[] = ["title" => $title,
+ "f_name" => $f_name,
+ "class" => $class,
+ "randname" => $randname,
+ "raw_datas" => $raw_datas,
+ "withdata" => $withdata
+ ];
+ $common->generateOdt($options);
+ return true;
+ } else if ($export == "odtall") {
+ $show_graph = PluginMreportingConfig::showGraphConfigValue($f_name, $class);
+ if ($show_graph) {
+ $path = GLPI_PLUGIN_DOC_DIR . "/mreporting/" . $f_name . ".png";
+ imagepng($image, $path);
+ }
+ if (isset($raw_datas['datas'])) {
+ $_SESSION['glpi_plugin_mreporting_odtarray'][] = ["title" => $title,
+ "f_name" => $f_name,
+ "class" => $class,
+ "randname" => $randname,
+ "raw_datas" => $raw_datas,
+ "withdata" => $withdata
+ ];
+ }
+
+ return true;
+ } else {
+ imagepng($image);
+ $contents = ob_get_contents();
+ ob_end_clean();
+ return $contents;
+ }
+ }
+
+
+ public static function getColors($index = 20)
+ {
+ $colors = PluginMreportingConfig::getColors($index);
+ foreach ($colors as &$color) {
+ $color = str_replace('#', '', $color);
+ }
+ return $colors;
+ }
/**
* returns an array with the rgb values
**/
- static function colorHexToRGB($color) {
- $hex = substr($color, 4);
-
- if (strlen($hex) == 3) {
- $r = substr($hex, 0, 1).substr($hex, 0, 1);
- $g = substr($hex, 1, 1).substr($hex, 1, 1);
- $b = substr($hex, 2, 1).substr($hex, 2, 1);
- } else {
- $r = substr($hex, 0, 2);
- $g = substr($hex, 2, 2);
- $b = substr($hex, 4, 2);
- }
-
- $alpha = substr($color, 0, 4);
- return [hexdec($r), hexdec($g), hexdec($b), hexdec($alpha)];
- }
-
-
-
- static function getPalette($nb_index = 20, $alpha = "00") {
- $palette = [];
- foreach (self::getColors($nb_index) as $color) {
- $palette[] = "0x$alpha".substr($color, 0, 6);
- }
-
- if ($nb_index > 20) {
- $nb = ceil($nb_index / 20);
- $tmp = $palette;
- for ($i = 0; $i <= $nb; $i++) {
- $palette = array_merge($palette, $tmp);
- }
- }
- return $palette;
- }
-
-
-
- static function getDarkerPalette($nb_index = 20, $alpha = "00") {
- $palette = [];
- foreach (self::getColors($nb_index) as $color) {
- $palette[] = "0x$alpha".substr(self::darker($color), 0, 6);
- }
- if ($nb_index > 20) {
- $nb = ceil($nb_index / 20);
- $tmp = $palette;
- for ($i = 0; $i <= $nb; $i++) {
- $palette = array_merge($palette, $tmp);
- }
- }
- return $palette;
- }
-
-
- static function getLighterPalette($nb_index = 20, $alpha = "00") {
- $palette = [];
- foreach (self::getColors($nb_index) as $color) {
- $palette[] = "0x$alpha".substr(self::lighter($color), 0, 6);
- }
- if ($nb_index > 20) {
- $nb = ceil($nb_index / 20);
- $tmp = $palette;
- for ($i = 0; $i <= $nb; $i++) {
- $palette = array_merge($palette, $tmp);
- }
- }
- return $palette;
- }
-
- static function darker($color, $factor = 50) {
- if (strlen($color) == 10) {
- $color = substr($color, 4);
- }
-
- $new_hex = '';
-
- $base['R'] = hexdec($color[0].$color[1]);
- $base['G'] = hexdec($color[2].$color[3]);
- $base['B'] = hexdec($color[4].$color[5]);
-
- foreach ($base as $k => $v) {
- $amount = $v / 100;
- $amount = round($amount * $factor);
- $new_decimal = $v - $amount;
-
- $new_hex_component = dechex($new_decimal);
- if (strlen($new_hex_component) < 2) {
- $new_hex_component = "0".$new_hex_component;
- }
- $new_hex .= $new_hex_component;
- }
-
- return $new_hex;
- }
-
-
- static function lighter($color, $factor = 50) {
- if (strlen($color) == 10) {
- $color = substr($color, 4);
- }
-
- $new_hex = '';
-
- $base['R'] = hexdec($color[0].$color[1]);
- $base['G'] = hexdec($color[2].$color[3]);
- $base['B'] = hexdec($color[4].$color[5]);
-
- foreach ($base as $k => $v) {
- $amount = 255 - $v;
- $amount = $amount / 100;
- $amount = round($amount * $factor);
- $new_decimal = $v + $amount;
-
- $new_hex_component = dechex($new_decimal);
- if (strlen($new_hex_component) < 2) {
- $new_hex_component = "0".$new_hex_component;
- }
- $new_hex .= $new_hex_component;
- }
-
- return $new_hex;
- }
+ public static function colorHexToRGB($color)
+ {
+ $hex = substr($color, 4);
+
+ if (strlen($hex) == 3) {
+ $r = substr($hex, 0, 1) . substr($hex, 0, 1);
+ $g = substr($hex, 1, 1) . substr($hex, 1, 1);
+ $b = substr($hex, 2, 1) . substr($hex, 2, 1);
+ } else {
+ $r = substr($hex, 0, 2);
+ $g = substr($hex, 2, 2);
+ $b = substr($hex, 4, 2);
+ }
+
+ $alpha = substr($color, 0, 4);
+ return [hexdec($r), hexdec($g), hexdec($b), hexdec($alpha)];
+ }
+
+
+
+ public static function getPalette($nb_index = 20, $alpha = "00")
+ {
+ $palette = [];
+ foreach (self::getColors($nb_index) as $color) {
+ $palette[] = "0x$alpha" . substr($color, 0, 6);
+ }
+
+ if ($nb_index > 20) {
+ $nb = ceil($nb_index / 20);
+ $tmp = $palette;
+ for ($i = 0; $i <= $nb; $i++) {
+ $palette = array_merge($palette, $tmp);
+ }
+ }
+ return $palette;
+ }
+
+
+
+ public static function getDarkerPalette($nb_index = 20, $alpha = "00")
+ {
+ $palette = [];
+ foreach (self::getColors($nb_index) as $color) {
+ $palette[] = "0x$alpha" . substr(self::darker($color), 0, 6);
+ }
+ if ($nb_index > 20) {
+ $nb = ceil($nb_index / 20);
+ $tmp = $palette;
+ for ($i = 0; $i <= $nb; $i++) {
+ $palette = array_merge($palette, $tmp);
+ }
+ }
+ return $palette;
+ }
+
+
+ public static function getLighterPalette($nb_index = 20, $alpha = "00")
+ {
+ $palette = [];
+ foreach (self::getColors($nb_index) as $color) {
+ $palette[] = "0x$alpha" . substr(self::lighter($color), 0, 6);
+ }
+ if ($nb_index > 20) {
+ $nb = ceil($nb_index / 20);
+ $tmp = $palette;
+ for ($i = 0; $i <= $nb; $i++) {
+ $palette = array_merge($palette, $tmp);
+ }
+ }
+ return $palette;
+ }
+
+ public static function darker($color, $factor = 50)
+ {
+ if (strlen($color) == 10) {
+ $color = substr($color, 4);
+ }
+
+ $new_hex = '';
+
+ $base['R'] = hexdec($color[0] . $color[1]);
+ $base['G'] = hexdec($color[2] . $color[3]);
+ $base['B'] = hexdec($color[4] . $color[5]);
+
+ foreach ($base as $k => $v) {
+ $amount = $v / 100;
+ $amount = round($amount * $factor);
+ $new_decimal = $v - $amount;
+
+ $new_hex_component = dechex($new_decimal);
+ if (strlen($new_hex_component) < 2) {
+ $new_hex_component = "0" . $new_hex_component;
+ }
+ $new_hex .= $new_hex_component;
+ }
+
+ return $new_hex;
+ }
+
+
+ public static function lighter($color, $factor = 50)
+ {
+ if (strlen($color) == 10) {
+ $color = substr($color, 4);
+ }
+
+ $new_hex = '';
+
+ $base['R'] = hexdec($color[0] . $color[1]);
+ $base['G'] = hexdec($color[2] . $color[3]);
+ $base['B'] = hexdec($color[4] . $color[5]);
+
+ foreach ($base as $k => $v) {
+ $amount = 255 - $v;
+ $amount = $amount / 100;
+ $amount = round($amount * $factor);
+ $new_decimal = $v + $amount;
+
+ $new_hex_component = dechex($new_decimal);
+ if (strlen($new_hex_component) < 2) {
+ $new_hex_component = "0" . $new_hex_component;
+ }
+ $new_hex .= $new_hex_component;
+ }
+
+ return $new_hex;
+ }
/**
@@ -356,105 +371,143 @@ static function lighter($color, $factor = 50) {
*
* @author DASPRiD
*/
- function imageSmoothAlphaLine ($image, $x1, $y1, $x2, $y2, $dcol) {
-
- $height = imagesy($image)-1;
- $width = imagesx($image)-1;
-
- $rgba = self::colorHexToRGB($dcol);
- $r = $rgba[0];
- $g = $rgba[1];
- $b = $rgba[2];
- $alpha = $rgba[3];
-
- $icr = $r;
- $icg = $g;
- $icb = $b;
-
- $m = ($y2 - $y1) / ($x2 - $x1);
- $b = $y1 - $m * $x1;
-
- if (abs ($m) <2) {
- $x = min($x1, $x2);
- $endx = max($x1, $x2) + 1;
-
- while ($x < $endx) {
- $y = $m * $x + $b;
- $ya = ($y == floor($y) ? 1: $y - floor($y));
- $yb = ceil($y) - $y;
-
- if ($x > $width) {
- break;
- }
-
- if ($y > $height) {
- $x++;
- continue;
- }
-
- $trgb = ImageColorAt($image, $x, floor($y));
- $tcr = ($trgb >> 16) & 0xFF;
- $tcg = ($trgb >> 8) & 0xFF;
- $tcb = $trgb & 0xFF;
- imagesetpixel($image, $x, floor($y),
- imagecolorallocatealpha($image, round($tcr * $ya + $icr * $yb),
- ($tcg * $ya + $icg * $yb), ($tcb * $ya + $icb * $yb), hexdec($alpha)));
-
- $trgb = ImageColorAt($image, $x, ceil($y));
- $tcr = ($trgb >> 16) & 0xFF;
- $tcg = ($trgb >> 8) & 0xFF;
- $tcb = $trgb & 0xFF;
- imagesetpixel($image, $x, ceil($y),
- imagecolorallocatealpha($image, round($tcr * $yb + $icr * $ya),
- round($tcg * $yb + $icg * $ya), round($tcb * $yb + $icb * $ya), hexdec($alpha)));
-
- $x++;
- }
- } else {
- $y = min($y1, $y2);
- $endy = max($y1, $y2) + 1;
-
- while ($y < $endy) {
- $x = ($y - $b) / $m;
- $xa = ($x == floor($x) ? 1: $x - floor($x));
- $xb = ceil($x) - $x;
-
- if ($x > $width) {
- $y++;
- continue;
- }
-
- $trgb = ImageColorAt($image, floor($x), $y);
- $tcr = ($trgb >> 16) & 0xFF;
- $tcg = ($trgb >> 8) & 0xFF;
- $tcb = $trgb & 0xFF;
- imagesetpixel($image, floor($x), $y,
- imagecolorallocatealpha($image, round($tcr * $xa + $icr * $xb),
- round($tcg * $xa + $icg * $xb), round($tcb * $xa + $icb * $xb), hexdec($alpha)));
-
- $trgb = ImageColorAt($image, ceil($x), $y);
- $tcr = ($trgb >> 16) & 0xFF;
- $tcg = ($trgb >> 8) & 0xFF;
- $tcb = $trgb & 0xFF;
- imagesetpixel ($image, ceil($x), $y,
- imagecolorallocatealpha($image, round($tcr * $xb + $icr * $xa),
- round($tcg * $xb + $icg * $xa), round($tcb * $xb + $icb * $xa), hexdec($alpha)));
-
- $y ++;
- }
- }
- } // end of 'imageSmoothAlphaLine()' function
-
-
- function imageSmoothAlphaLineLarge($image, $x1, $y1, $x2, $y2, $color) {
- imageline($image, $x1, $y1, $x2, $y2, hexdec($color));
- $this->imageSmoothAlphaLine($image, $x1-1, $y1-1, $x2-1, $y2-1, $color);
- $this->imageSmoothAlphaLine($image, $x1+1, $y1+1, $x2+1, $y2+1, $color);
- $this->imageSmoothAlphaLine($image, $x1, $y1+1, $x2, $y2+1, $color);
- $this->imageSmoothAlphaLine($image, $x1, $y1-1, $x2, $y2-1, $color);
- $this->imageSmoothAlphaLine($image, $x1-1, $y1, $x2-1, $y2, $color);
- $this->imageSmoothAlphaLine($image, $x1+1, $y1, $x2+1, $y2, $color);
- }
+ public function imageSmoothAlphaLine($image, $x1, $y1, $x2, $y2, $dcol)
+ {
+
+ $height = imagesy($image) - 1;
+ $width = imagesx($image) - 1;
+
+ $rgba = self::colorHexToRGB($dcol);
+ $r = $rgba[0];
+ $g = $rgba[1];
+ $b = $rgba[2];
+ $alpha = $rgba[3];
+
+ $icr = $r;
+ $icg = $g;
+ $icb = $b;
+
+ $m = ($y2 - $y1) / ($x2 - $x1);
+ $b = $y1 - $m * $x1;
+
+ if (abs($m) < 2) {
+ $x = min($x1, $x2);
+ $endx = max($x1, $x2) + 1;
+
+ while ($x < $endx) {
+ $y = $m * $x + $b;
+ $ya = ($y == floor($y) ? 1 : $y - floor($y));
+ $yb = ceil($y) - $y;
+
+ if ($x > $width) {
+ break;
+ }
+
+ if ($y > $height) {
+ $x++;
+ continue;
+ }
+
+ $trgb = ImageColorAt($image, $x, floor($y));
+ $tcr = ($trgb >> 16) & 0xFF;
+ $tcg = ($trgb >> 8) & 0xFF;
+ $tcb = $trgb & 0xFF;
+ imagesetpixel(
+ $image,
+ $x,
+ floor($y),
+ imagecolorallocatealpha(
+ $image,
+ round($tcr * $ya + $icr * $yb),
+ ($tcg * $ya + $icg * $yb),
+ ($tcb * $ya + $icb * $yb),
+ hexdec($alpha)
+ )
+ );
+
+ $trgb = ImageColorAt($image, $x, ceil($y));
+ $tcr = ($trgb >> 16) & 0xFF;
+ $tcg = ($trgb >> 8) & 0xFF;
+ $tcb = $trgb & 0xFF;
+ imagesetpixel(
+ $image,
+ $x,
+ ceil($y),
+ imagecolorallocatealpha(
+ $image,
+ round($tcr * $yb + $icr * $ya),
+ round($tcg * $yb + $icg * $ya),
+ round($tcb * $yb + $icb * $ya),
+ hexdec($alpha)
+ )
+ );
+
+ $x++;
+ }
+ } else {
+ $y = min($y1, $y2);
+ $endy = max($y1, $y2) + 1;
+
+ while ($y < $endy) {
+ $x = ($y - $b) / $m;
+ $xa = ($x == floor($x) ? 1 : $x - floor($x));
+ $xb = ceil($x) - $x;
+
+ if ($x > $width) {
+ $y++;
+ continue;
+ }
+
+ $trgb = ImageColorAt($image, floor($x), $y);
+ $tcr = ($trgb >> 16) & 0xFF;
+ $tcg = ($trgb >> 8) & 0xFF;
+ $tcb = $trgb & 0xFF;
+ imagesetpixel(
+ $image,
+ floor($x),
+ $y,
+ imagecolorallocatealpha(
+ $image,
+ round($tcr * $xa + $icr * $xb),
+ round($tcg * $xa + $icg * $xb),
+ round($tcb * $xa + $icb * $xb),
+ hexdec($alpha)
+ )
+ );
+
+ $trgb = ImageColorAt($image, ceil($x), $y);
+ $tcr = ($trgb >> 16) & 0xFF;
+ $tcg = ($trgb >> 8) & 0xFF;
+ $tcb = $trgb & 0xFF;
+ imagesetpixel(
+ $image,
+ ceil($x),
+ $y,
+ imagecolorallocatealpha(
+ $image,
+ round($tcr * $xb + $icr * $xa),
+ round($tcg * $xb + $icg * $xa),
+ round($tcb * $xb + $icb * $xa),
+ hexdec($alpha)
+ )
+ );
+
+ $y++;
+ }
+ }
+ }
+
+
+ public function imageSmoothAlphaLineLarge($image, $x1, $y1, $x2, $y2, $color)
+ {
+ imageline($image, $x1, $y1, $x2, $y2, hexdec($color));
+ $this->imageSmoothAlphaLine($image, $x1 - 1, $y1 - 1, $x2 - 1, $y2 - 1, $color);
+ $this->imageSmoothAlphaLine($image, $x1 + 1, $y1 + 1, $x2 + 1, $y2 + 1, $color);
+ $this->imageSmoothAlphaLine($image, $x1, $y1 + 1, $x2, $y2 + 1, $color);
+ $this->imageSmoothAlphaLine($image, $x1, $y1 - 1, $x2, $y2 - 1, $color);
+ $this->imageSmoothAlphaLine($image, $x1 - 1, $y1, $x2 - 1, $y2, $color);
+ $this->imageSmoothAlphaLine($image, $x1 + 1, $y1, $x2 + 1, $y2, $color);
+ }
/**
@@ -466,31 +519,38 @@ function imageSmoothAlphaLineLarge($image, $x1, $y1, $x2, $y2, $color) {
* @param coords array with points coordinates (x1 => y1, x2 => y2, etc)
*
*/
- function imageCubicSmoothLine($image, $color, $coords) {
+ public function imageCubicSmoothLine($image, $color, $coords)
+ {
- $oCurve = new CubicSplines();
- if ($oCurve->setInitCoords($coords, 6) !== false) {
- if (!$r = $oCurve->processCoords()) {
+ $oCurve = new CubicSplines();
+ if ($oCurve->setInitCoords($coords, 6) !== false) {
+ if (!$r = $oCurve->processCoords()) {
+ $r = $coords;
+ }
+ } else {
$r = $coords;
- }
- } else {
- $r = $coords;
- }
-
- $iPrevX = key($r);
- $iPrevY = current($r);
-
- while (false !== next($r)) {
- $x = key($r);
- $y = current($r);
-
- $this->imageSmoothAlphaLineLarge(
- $image, round($iPrevX), round($iPrevY), round($x), round($y), $color);
+ }
+
+ $iPrevX = key($r);
+ $iPrevY = current($r);
+
+ while (false !== next($r)) {
+ $x = key($r);
+ $y = current($r);
+
+ $this->imageSmoothAlphaLineLarge(
+ $image,
+ round($iPrevX),
+ round($iPrevY),
+ round($x),
+ round($y),
+ $color
+ );
- $iPrevX = $x;
- $iPrevY = $y;
- }
- }
+ $iPrevX = $x;
+ $iPrevY = $y;
+ }
+ }
/**
@@ -504,187 +564,190 @@ function imageCubicSmoothLine($image, $color, $coords) {
* @param $show_label : behavior of the graph labels,
* values : 'hover', 'never', 'always' (optionnal)
* @param $export : keep only svg to export (optionnal)
- * @return nothing
+ * @return void
*/
- function showHbar($params, $dashboard = false, $width = false) {
- if ($width !== false) {
- $this->width = $width + 50;
- }
-
- $criterias = PluginMreportingCommon::initGraphParams($params);
-
- foreach ($criterias as $key => $val) {
- $$key=$val;
- }
-
- //$rand = $opt['rand'];
-
- $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']);
-
- foreach ($configs as $k => $v) {
- $$k=$v;
- }
-
- if (self::DEBUG_GRAPH && isset($raw_datas)) {
- Toolbox::logdebug($raw_datas);
- }
-
- if (isset($raw_datas['datas'])) {
- $datas = $raw_datas['datas'];
- } else {
- $datas = [];
- }
-
- $options = ["title" => $title,
- "desc" => $desc,
- "randname" => $randname,
- "export" => $export,
- "delay" => $delay,
- "short_classname" => $opt["short_classname"],
- "showHeader" => $dashboard];
-
- $this->initGraph($options);
-
- if (count($datas) <= 0) {
-
- if ($export!="odtall") {
- echo __("No data for this date range !", 'mreporting');
- $end['opt']["export"] = false;
- $end['opt']["randname"] = false;
- $end['opt']["f_name"] = $opt['f_name'];
- $end['opt']["class"] = $opt['class'];
- PluginMreportingCommon::endGraph($end);
- }
- return false;
- }
-
- if (empty($unit) && !empty($raw_datas['unit'])) {
- $unit = $raw_datas['unit'];
- }
-
- $datas = PluginMreportingCommon::compileDatasForUnit($datas, $unit);
- $raw_datas['datas'] = $datas;
-
- $values = array_values($datas);
- $labels = array_keys($datas);
- $max = max($values);
- if ($max <= 1) {
- $max = 1;
- }
- if ($max == 1 && $unit == '%') {
- $max = 100;
- }
-
- $nb_bar = count($datas);
- $width = $this->width;
- $height = 30 * $nb_bar + 80;
- if ($dashboard) {
- if ($height > 380) {
- $height = 380;
- }
- }
- $height_bar = .7 * $height / ($nb_bar+1);
-
- //create image
- $image = imagecreatetruecolor ($width, $height);
-
- if ($show_graph) {
- //colors
- $palette = self::getPalette($nb_bar);
- $darkerpalette = self::getDarkerPalette($nb_bar);
-
- //background
- $bg_color = hexdec($this->white);
- imagefilledrectangle($image, 0, 0, $width - 1, $height - 1, $bg_color);
-
- //create border on export
- if ($export) {
- $bg_color = hexdec($this->black);
- imagerectangle($image, 0, 0, $width - 1, $height - 1, $bg_color);
- }
-
- //add title on export
- if ($export) {
- imagettftext(
- $image,
- $this->fontsize+2,
- $this->fontangle,
- 10,
- 20,
- hexdec($this->black),
- $this->font,
- $title
- );
- }
-
- //bars
- $index = 0;
- foreach ($datas as $label => $data) {
- $bx1 = 250;
- $by1 = ($index+1) * 1.25 * $height_bar + .05 * $height + 2;
- $bx2 = $bx1 + round(($data*($width -300)) / $max);
- $by2 = $by1 + $height_bar;
-
- //createbar
- ImageFilledRectangle($image, $bx1, $by1, $bx2, $by2, hexdec($palette[$index]));
- imagerectangle($image, $bx1, $by1-1, $bx2+1, $by2+1, hexdec($darkerpalette[$index]));
- imagerectangle($image, $bx1, $by1-2, $bx2+2, $by2+2, hexdec($darkerpalette[$index]));
-
- //create data label
- if ($show_label == "always" || $show_label == "hover") {
- imagettftext(
- $image,
- $this->fontsize,
- $this->fontangle,
- $bx2 + 6,
- $by1 + 14,
- hexdec($darkerpalette[$index]),
- $this->font,
- Html::clean($data.$unit)
- );
- }
- //create axis label (align right)
- $box = @imageTTFBbox($this->fontsize, $this->fontangle, $this->font, $labels[$index]);
- $textwidth = abs($box[4] - $box[0]);
- $textheight = abs($box[5] - $box[1]);
- imagettftext(
- $image,
- $this->fontsize,
- $this->fontangle,
- 245 - $textwidth,
- $by1 + 14,
- hexdec($this->black),
- $this->font,
- Html::clean($labels[$index])
- );
+ public function showHbar($params, $dashboard = false, $width = false)
+ {
+ if ($width !== false) {
+ $this->width = $width + 50;
+ }
+
+ $criterias = PluginMreportingCommon::initGraphParams($params);
+
+ foreach ($criterias as $key => $val) {
+ $$key = $val;
+ }
+
+ //$rand = $opt['rand'];
+
+ $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']);
+
+ foreach ($configs as $k => $v) {
+ $$k = $v;
+ }
+
+ if (self::DEBUG_GRAPH && isset($raw_datas)) {
+ Toolbox::logdebug($raw_datas);
+ }
+
+ if (isset($raw_datas['datas'])) {
+ $datas = $raw_datas['datas'];
+ } else {
+ $datas = [];
+ }
+
+ $options = ["title" => $title,
+ "desc" => $desc,
+ "randname" => $randname,
+ "export" => $export,
+ "delay" => $delay,
+ "short_classname" => $opt["short_classname"],
+ "showHeader" => $dashboard
+ ];
+
+ $this->initGraph($options);
+
+ if (count($datas) <= 0) {
+ if ($export != "odtall") {
+ echo __("No data for this date range !", 'mreporting');
+ $end['opt']["export"] = false;
+ $end['opt']["randname"] = false;
+ $end['opt']["f_name"] = $opt['f_name'];
+ $end['opt']["class"] = $opt['class'];
+ PluginMreportingCommon::endGraph($end);
+ }
+ return false;
+ }
+
+ if (empty($unit) && !empty($raw_datas['unit'])) {
+ $unit = $raw_datas['unit'];
+ }
+
+ $datas = PluginMreportingCommon::compileDatasForUnit($datas, $unit);
+ $raw_datas['datas'] = $datas;
+
+ $values = array_values($datas);
+ $labels = array_keys($datas);
+ $max = max($values);
+ if ($max <= 1) {
+ $max = 1;
+ }
+ if ($max == 1 && $unit == '%') {
+ $max = 100;
+ }
+
+ $nb_bar = count($datas);
+ $width = $this->width;
+ $height = 30 * $nb_bar + 80;
+ if ($dashboard) {
+ if ($height > 380) {
+ $height = 380;
+ }
+ }
+ $height_bar = .7 * $height / ($nb_bar + 1);
- $index++;
- }
-
- //y axis
- imageline($image, 250, 40, 250, $height-20, hexdec($this->black));
- imageline($image, 251, 40, 251, $height-20, hexdec($this->black));
- }
- $params = ["image" => $image,
- "export" => $export,
- "f_name" => $opt['f_name'],
- "class" => $opt['class'],
- "title" => $title,
- "randname" => $randname,
- "raw_datas" => $raw_datas,
- "withdata" => $opt['withdata']];
-
- $contents = $this->generateImage($params);
- if ($show_graph) {
- $this->showImage($contents, $export);
- }
- $opt['randname'] = $randname;
- $options = ["opt" => $opt,
- "export" => $export,
- "datas" => $datas,
- "unit" => $unit];
- PluginMreportingCommon::endGraph($options, $dashboard);
- }
+ //create image
+ $image = imagecreatetruecolor($width, $height);
+
+ if ($show_graph) {
+ //colors
+ $palette = self::getPalette($nb_bar);
+ $darkerpalette = self::getDarkerPalette($nb_bar);
+
+ //background
+ $bg_color = hexdec($this->white);
+ imagefilledrectangle($image, 0, 0, $width - 1, $height - 1, $bg_color);
+
+ //create border on export
+ if ($export) {
+ $bg_color = hexdec($this->black);
+ imagerectangle($image, 0, 0, $width - 1, $height - 1, $bg_color);
+ }
+
+ //add title on export
+ if ($export) {
+ imagettftext(
+ $image,
+ $this->fontsize + 2,
+ $this->fontangle,
+ 10,
+ 20,
+ hexdec($this->black),
+ $this->font,
+ $title
+ );
+ }
+
+ //bars
+ $index = 0;
+ foreach ($datas as $label => $data) {
+ $bx1 = 250;
+ $by1 = ($index + 1) * 1.25 * $height_bar + .05 * $height + 2;
+ $bx2 = $bx1 + round(($data * ($width - 300)) / $max);
+ $by2 = $by1 + $height_bar;
+
+ //createbar
+ ImageFilledRectangle($image, $bx1, $by1, $bx2, $by2, hexdec($palette[$index]));
+ imagerectangle($image, $bx1, $by1 - 1, $bx2 + 1, $by2 + 1, hexdec($darkerpalette[$index]));
+ imagerectangle($image, $bx1, $by1 - 2, $bx2 + 2, $by2 + 2, hexdec($darkerpalette[$index]));
+
+ //create data label
+ if ($show_label == "always" || $show_label == "hover") {
+ imagettftext(
+ $image,
+ $this->fontsize,
+ $this->fontangle,
+ $bx2 + 6,
+ $by1 + 14,
+ hexdec($darkerpalette[$index]),
+ $this->font,
+ Toolbox::stripTags($data . $unit)
+ );
+ }
+ //create axis label (align right)
+ $box = @imageTTFBbox($this->fontsize, $this->fontangle, $this->font, $labels[$index]);
+ $textwidth = abs($box[4] - $box[0]);
+ $textheight = abs($box[5] - $box[1]);
+ imagettftext(
+ $image,
+ $this->fontsize,
+ $this->fontangle,
+ 245 - $textwidth,
+ $by1 + 14,
+ hexdec($this->black),
+ $this->font,
+ Toolbox::stripTags($labels[$index])
+ );
+
+ $index++;
+ }
+
+ //y axis
+ imageline($image, 250, 40, 250, $height - 20, hexdec($this->black));
+ imageline($image, 251, 40, 251, $height - 20, hexdec($this->black));
+ }
+ $params = ["image" => $image,
+ "export" => $export,
+ "f_name" => $opt['f_name'],
+ "class" => $opt['class'],
+ "title" => $title,
+ "randname" => $randname,
+ "raw_datas" => $raw_datas,
+ "withdata" => $opt['withdata']
+ ];
+
+ $contents = $this->generateImage($params);
+ if ($show_graph) {
+ $this->showImage($contents, $export);
+ }
+ $opt['randname'] = $randname;
+ $options = ["opt" => $opt,
+ "export" => $export,
+ "datas" => $datas,
+ "unit" => $unit
+ ];
+ PluginMreportingCommon::endGraph($options, $dashboard);
+ }
/**
@@ -699,195 +762,230 @@ function showHbar($params, $dashboard = false, $width = false) {
* @param $show_label : behavior of the graph labels,
* values : 'hover', 'never', 'always' (optionnal)
* @param $export : keep only svg to export (optionnal)
- * @return nothing
+ * @return void
*/
- function showPie($params, $dashboard = false, $width = false) {
-
- $criterias = PluginMreportingCommon::initGraphParams($params);
-
- foreach ($criterias as $key => $val) {
- $$key=$val;
- }
-
- if ($width !== false) {
- $this->width = $width;
- }
-
- $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']);
-
- foreach ($configs as $k => $v) {
- $$k=$v;
- }
-
- if (self::DEBUG_GRAPH && isset($raw_datas)) {
- Toolbox::logdebug($raw_datas);
- }
-
- if (isset($raw_datas['datas'])) {
- $datas = $raw_datas['datas'];
- } else {
- $datas = [];
- }
-
- $options = ["title" => $title,
- "desc" => $desc,
- "randname" => $randname,
- "export" => $export,
- "delay" => $delay,
- "short_classname" => $opt["short_classname"],
- "showHeader" => $dashboard];
-
- $this->initGraph($options);
-
- if (count($datas) <= 0) {
-
- if ($export!="odtall") {
- echo __("No data for this date range !", 'mreporting');
- $end['opt']["export"] = false;
- $end['opt']["randname"] = false;
- $end['opt']["f_name"] = $opt['f_name'];
- $end['opt']["class"] = $opt['class'];
- PluginMreportingCommon::endGraph($end);
- }
- return false;
- }
-
- if (empty($unit) && !empty($raw_datas['unit'])) {
- $unit = $raw_datas['unit'];
- }
-
- $datas = PluginMreportingCommon::compileDatasForUnit($datas, $unit);
- $raw_datas['datas'] = $datas;
-
- $values = array_values($datas);
-
- $labels = array_keys($datas);
- $max = 0;
- foreach ($values as $value) {
- $max += $value;
- }
- if ($max < 1) {
- $max = 1;
- }
- if ($max == 1 && $unit == '%') {
- $max = 100;
- }
-
- $nb_bar = count($datas);
- $width = $this->width;
-
- $height = 15 * $nb_bar + 50;
- if ($height < 300) {
- $height = 370;
- }
- //create image
- $image = imagecreatetruecolor ($width, $height);
-
- if ($show_graph) {
- //colors
- $palette = self::getPalette($nb_bar);
- $darkerpalette = self::getDarkerPalette($nb_bar);
-
- //background
- $bg_color = hexdec($this->white);
- imagefilledrectangle($image, 0, 0, $width - 1, $height - 1, $bg_color);
-
- //create border on export
- if ($export) {
- imagerectangle($image, 0, 0, $width - 1, $height - 1, hexdec($this->black));
- }
-
- //add title on export
- if ($export) {
- imagettftext($image, $this->fontsize+2, $this->fontangle, 10, 20,
- hexdec($this->black), $this->font, $title);
- }
-
- if ($export && $desc) {
- imagettftext($image, $this->fontsize+2, $this->fontangle, 10, 35,
- hexdec($this->black), $this->font, $desc);
- }
-
- //pie
- $index = 0;
- $x = $width / 4 + .43 * $width;
- $y = $height / 2;
- $radius = $height / 1.5;
- $start_angle = 0;
- foreach ($datas as $label => $data) {
- $angle = $start_angle + (360 * $data) / $max;
-
- //full circle need fix
- if ($angle - $start_angle == 360) {
- $angle = 359.999;
- $start_angle = 0;
- }
-
- if ($data != 0) {
- $color_rbg = self::colorHexToRGB($palette[$index]);
- imageSmoothArc($image, $x, $y, $radius+8, $radius+8, $color_rbg,
- deg2rad($start_angle), deg2rad($angle));
-
- //text associated with pie arc (only for angle > 2°)
- if ($angle > 2 && ($show_label == "always" || $show_label == "hover")) {
- $xtext = $x - 1 + cos(deg2rad(($start_angle + $angle)/2)) * ($radius / 1.7);
- $ytext = $y + 5 - sin(deg2rad(($start_angle + $angle)/2)) * ($radius / 1.7);
- imagettftext(
- $image,
- $this->fontsize,
- $this->fontangle,
- $xtext,
- $ytext,
- hexdec($darkerpalette[$index]),
- $this->font,
- Html::clean($data.$unit)
- );
- }
+ public function showPie($params, $dashboard = false, $width = false)
+ {
+
+ $criterias = PluginMreportingCommon::initGraphParams($params);
+
+ foreach ($criterias as $key => $val) {
+ $$key = $val;
+ }
+
+ if ($width !== false) {
+ $this->width = $width;
+ }
+
+ $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']);
+
+ foreach ($configs as $k => $v) {
+ $$k = $v;
+ }
+
+ if (self::DEBUG_GRAPH && isset($raw_datas)) {
+ Toolbox::logdebug($raw_datas);
+ }
+
+ if (isset($raw_datas['datas'])) {
+ $datas = $raw_datas['datas'];
+ } else {
+ $datas = [];
+ }
+
+ $options = ["title" => $title,
+ "desc" => $desc,
+ "randname" => $randname,
+ "export" => $export,
+ "delay" => $delay,
+ "short_classname" => $opt["short_classname"],
+ "showHeader" => $dashboard
+ ];
+
+ $this->initGraph($options);
+
+ if (count($datas) <= 0) {
+ if ($export != "odtall") {
+ echo __("No data for this date range !", 'mreporting');
+ $end['opt']["export"] = false;
+ $end['opt']["randname"] = false;
+ $end['opt']["f_name"] = $opt['f_name'];
+ $end['opt']["class"] = $opt['class'];
+ PluginMreportingCommon::endGraph($end);
+ }
+ return false;
+ }
+
+ if (empty($unit) && !empty($raw_datas['unit'])) {
+ $unit = $raw_datas['unit'];
+ }
+
+ $datas = PluginMreportingCommon::compileDatasForUnit($datas, $unit);
+ $raw_datas['datas'] = $datas;
+
+ $values = array_values($datas);
+
+ $labels = array_keys($datas);
+ $max = 0;
+ foreach ($values as $value) {
+ $max += $value;
+ }
+ if ($max < 1) {
+ $max = 1;
+ }
+ if ($max == 1 && $unit == '%') {
+ $max = 100;
+ }
+
+ $nb_bar = count($datas);
+ $width = $this->width;
+
+ $height = 15 * $nb_bar + 50;
+ if ($height < 300) {
+ $height = 370;
+ }
+ //create image
+ $image = imagecreatetruecolor($width, $height);
+
+ if ($show_graph) {
+ //colors
+ $palette = self::getPalette($nb_bar);
+ $darkerpalette = self::getDarkerPalette($nb_bar);
+
+ //background
+ $bg_color = hexdec($this->white);
+ imagefilledrectangle($image, 0, 0, $width - 1, $height - 1, $bg_color);
+
+ //create border on export
+ if ($export) {
+ imagerectangle($image, 0, 0, $width - 1, $height - 1, hexdec($this->black));
+ }
- $start_angle = $angle;
+ //add title on export
+ if ($export) {
+ imagettftext(
+ $image,
+ $this->fontsize + 2,
+ $this->fontangle,
+ 10,
+ 20,
+ hexdec($this->black),
+ $this->font,
+ $title
+ );
}
- $index++;
- }
-
- //legend (align left)
- $index = 0;
- foreach ($labels as $label) {
- //legend label
- $box = @imageTTFBbox($this->fontsize, $this->fontangle, $this->font, $label);
- $textwidth = abs($box[4] - $box[0]);
- $textheight = abs($box[5] - $box[1]);
- imagettftext($image, $this->fontsize, $this->fontangle,
- 20, 55 + $index * 14, hexdec($this->black), $this->font, $label);
-
- //legend circle
- $color_rbg = self::colorHexToRGB($palette[$index]);
- imageSmoothArc($image, 10, 50 + $index * 14, 7, 7, $color_rbg, 0, 2 * M_PI);
- $index++;
- }
- }
-
- $params = ["image" => $image,
- "export" => $export,
- "f_name" => $opt['f_name'],
- "class" => $opt['class'],
- "title" => $title,
- "randname" => $randname,
- "raw_datas" => $raw_datas,
- "withdata" => $opt['withdata']];
-
- $contents = $this->generateImage($params);
- if ($show_graph) {
- $this->showImage($contents, $export);
- }
- $opt['randname'] = $randname;
- $options = ["opt" => $opt,
- "export" => $export,
- "datas" => $datas,
- "unit" => $unit];
-
- PluginMreportingCommon::endGraph($options, $dashboard);
- }
+ if ($export && $desc) {
+ imagettftext(
+ $image,
+ $this->fontsize + 2,
+ $this->fontangle,
+ 10,
+ 35,
+ hexdec($this->black),
+ $this->font,
+ $desc
+ );
+ }
+
+ //pie
+ $index = 0;
+ $x = $width / 4 + .43 * $width;
+ $y = $height / 2;
+ $radius = $height / 1.5;
+ $start_angle = 0;
+ foreach ($datas as $label => $data) {
+ $angle = $start_angle + (360 * $data) / $max;
+
+ //full circle need fix
+ if ($angle - $start_angle == 360) {
+ $angle = 359.999;
+ $start_angle = 0;
+ }
+
+ if ($data != 0) {
+ $color_rbg = self::colorHexToRGB($palette[$index]);
+ imageSmoothArc(
+ $image,
+ $x,
+ $y,
+ $radius + 8,
+ $radius + 8,
+ $color_rbg,
+ deg2rad($start_angle),
+ deg2rad($angle)
+ );
+
+ //text associated with pie arc (only for angle > 2°)
+ if ($angle > 2 && ($show_label == "always" || $show_label == "hover")) {
+ $xtext = $x - 1 + cos(deg2rad(($start_angle + $angle) / 2)) * ($radius / 1.7);
+ $ytext = $y + 5 - sin(deg2rad(($start_angle + $angle) / 2)) * ($radius / 1.7);
+ imagettftext(
+ $image,
+ $this->fontsize,
+ $this->fontangle,
+ $xtext,
+ $ytext,
+ hexdec($darkerpalette[$index]),
+ $this->font,
+ Toolbox::stripTags($data . $unit)
+ );
+ }
+
+ $start_angle = $angle;
+ }
+ $index++;
+ }
+
+ //legend (align left)
+ $index = 0;
+ foreach ($labels as $label) {
+ //legend label
+ $box = @imageTTFBbox($this->fontsize, $this->fontangle, $this->font, $label);
+ $textwidth = abs($box[4] - $box[0]);
+ $textheight = abs($box[5] - $box[1]);
+ imagettftext(
+ $image,
+ $this->fontsize,
+ $this->fontangle,
+ 20,
+ 55 + $index * 14,
+ hexdec($this->black),
+ $this->font,
+ $label
+ );
+
+ //legend circle
+ $color_rbg = self::colorHexToRGB($palette[$index]);
+ imageSmoothArc($image, 10, 50 + $index * 14, 7, 7, $color_rbg, 0, 2 * M_PI);
+
+ $index++;
+ }
+ }
+
+ $params = ["image" => $image,
+ "export" => $export,
+ "f_name" => $opt['f_name'],
+ "class" => $opt['class'],
+ "title" => $title,
+ "randname" => $randname,
+ "raw_datas" => $raw_datas,
+ "withdata" => $opt['withdata']
+ ];
+
+ $contents = $this->generateImage($params);
+ if ($show_graph) {
+ $this->showImage($contents, $export);
+ }
+ $opt['randname'] = $randname;
+ $options = ["opt" => $opt,
+ "export" => $export,
+ "datas" => $datas,
+ "unit" => $unit
+ ];
+
+ PluginMreportingCommon::endGraph($options, $dashboard);
+ }
/**
@@ -907,292 +1005,320 @@ function showPie($params, $dashboard = false, $width = false) {
* @param $show_label : behavior of the graph labels,
* values : 'hover', 'never', 'always' (optionnal)
* @param $export : keep only svg to export (optionnal)
- * @return nothing
+ * @return void
*/
- function showSunburst($params, $dashboard = false, $width = false) {
- $criterias = PluginMreportingCommon::initGraphParams($params);
- foreach ($criterias as $key => $val) {
- $$key=$val;
- }
- $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']);
- foreach ($configs as $k => $v) {
- $$k=$v;
- }
-
- if (self::DEBUG_GRAPH && isset($raw_datas)) {
- Toolbox::logdebug($raw_datas);
- }
-
- if (isset($raw_datas['datas'])) {
- $datas = $raw_datas['datas'];
- } else {
- $datas = [];
- }
-
- $options = ["title" => $title,
- "desc" => $desc,
- "randname" => $randname,
- "export" => $export,
- "delay" => $delay,
- "short_classname" => $opt["short_classname"],
- "showHeader" => $dashboard];
-
- $this->initGraph($options);
-
- if (count($datas) <= 0) {
-
- if ($export!="odtall") {
- echo __("No data for this date range !", 'mreporting');
- $end['opt']["export"] = false;
- $end['opt']["randname"] = false;
- $end['opt']["f_name"] = $opt['f_name'];
- $end['opt']["class"] = $opt['class'];
- PluginMreportingCommon::endGraph($end);
- }
- return false;
- }
-
- $labels2 = [];
-
- if (empty($unit) && !empty($raw_datas['unit'])) {
- $unit = $raw_datas['unit'];
- }
-
- if ($unit == '%') {
- $raw_datas['datas'] = PluginMreportingCommon::compileDatasForUnit($datas, $unit);
- }
-
- $values = array_values($datas);
- $labels = array_keys($datas);
-
- $width = $this->width-200;
- $height = 500;
-
- //create image
- $image = imagecreatetruecolor ($width, $height);
-
- if ($show_graph) {
-
- //background
- $bg_color = hexdec($this->white);
- imagefilledrectangle($image, 1, 1, $width - 2, $height-2, $bg_color);
-
- //create border on export
- if ($export) {
- imagerectangle($image, 0, 0, $width - 1, $height, hexdec($this->black));
- }
-
- //add title on export
- if ($export) {
- imagettftext(
- $image,
- $this->fontsize+2,
- $this->fontangle,
- 10,
- 20,
- hexdec($this->black),
- $this->font,
- $title
- );
- }
-
- if ($export && $desc) {
- imagettftext($image, $this->fontsize+2, $this->fontangle, 10, 35,
- hexdec($this->black), $this->font, $desc);
- }
- }
-
- //recursive level draw
- $image = $this->drawSunburstLevel($image, $datas, [
- 'width' => $width,
- 'height' => $height
- ]);
-
- //generate image
- $params = ["image" => $image,
- "export" => $export,
- "f_name" => $opt['f_name'],
- "class" => $opt['class'],
- "title" => $title,
- "randname" => $randname,
- "raw_datas" => $raw_datas,
- "withdata" => $opt['withdata']];
- $contents = $this->generateImage($params);
- $this->showImage($contents, $export);
-
- $opt['randname'] = $randname;
- $options = ["opt" => $opt,
- "export" => $export,
- "datas" => $datas,
- "labels2" => $labels2,
- "flip_data" => $flip_data,
- "unit" => $unit];
- PluginMreportingCommon::endGraph($options, $dashboard);
- }
-
- function drawSunburstLevel($image, $datas, $params = []) {
- $width = $params['width'] - 70;
- $height = $params['height'] - 120;
-
- $gsum = PluginMreportingCommon::getArraySum($datas);
-
- $index = 0;
- $x = $width / 2;
- $y = $height / 2 + 60;
- $params['depth'] = isset($params['depth'])
+ public function showSunburst($params, $dashboard = false, $width = false)
+ {
+ $criterias = PluginMreportingCommon::initGraphParams($params);
+ foreach ($criterias as $key => $val) {
+ $$key = $val;
+ }
+ $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']);
+ foreach ($configs as $k => $v) {
+ $$k = $v;
+ }
+
+ if (self::DEBUG_GRAPH && isset($raw_datas)) {
+ Toolbox::logdebug($raw_datas);
+ }
+
+ if (isset($raw_datas['datas'])) {
+ $datas = $raw_datas['datas'];
+ } else {
+ $datas = [];
+ }
+
+ $options = ["title" => $title,
+ "desc" => $desc,
+ "randname" => $randname,
+ "export" => $export,
+ "delay" => $delay,
+ "short_classname" => $opt["short_classname"],
+ "showHeader" => $dashboard
+ ];
+
+ $this->initGraph($options);
+
+ if (count($datas) <= 0) {
+ if ($export != "odtall") {
+ echo __("No data for this date range !", 'mreporting');
+ $end['opt']["export"] = false;
+ $end['opt']["randname"] = false;
+ $end['opt']["f_name"] = $opt['f_name'];
+ $end['opt']["class"] = $opt['class'];
+ PluginMreportingCommon::endGraph($end);
+ }
+ return false;
+ }
+
+ $labels2 = [];
+
+ if (empty($unit) && !empty($raw_datas['unit'])) {
+ $unit = $raw_datas['unit'];
+ }
+
+ if ($unit == '%') {
+ $raw_datas['datas'] = PluginMreportingCommon::compileDatasForUnit($datas, $unit);
+ }
+
+ $values = array_values($datas);
+ $labels = array_keys($datas);
+
+ $width = $this->width - 200;
+ $height = 500;
+
+ //create image
+ $image = imagecreatetruecolor($width, $height);
+
+ if ($show_graph) {
+ //background
+ $bg_color = hexdec($this->white);
+ imagefilledrectangle($image, 1, 1, $width - 2, $height - 2, $bg_color);
+
+ //create border on export
+ if ($export) {
+ imagerectangle($image, 0, 0, $width - 1, $height, hexdec($this->black));
+ }
+
+ //add title on export
+ if ($export) {
+ imagettftext(
+ $image,
+ $this->fontsize + 2,
+ $this->fontangle,
+ 10,
+ 20,
+ hexdec($this->black),
+ $this->font,
+ $title
+ );
+ }
+
+ if ($export && $desc) {
+ imagettftext(
+ $image,
+ $this->fontsize + 2,
+ $this->fontangle,
+ 10,
+ 35,
+ hexdec($this->black),
+ $this->font,
+ $desc
+ );
+ }
+ }
+
+ //recursive level draw
+ $image = $this->drawSunburstLevel($image, $datas, [
+ 'width' => $width,
+ 'height' => $height
+ ]);
+
+ //generate image
+ $params = ["image" => $image,
+ "export" => $export,
+ "f_name" => $opt['f_name'],
+ "class" => $opt['class'],
+ "title" => $title,
+ "randname" => $randname,
+ "raw_datas" => $raw_datas,
+ "withdata" => $opt['withdata']
+ ];
+ $contents = $this->generateImage($params);
+ $this->showImage($contents, $export);
+
+ $opt['randname'] = $randname;
+ $options = ["opt" => $opt,
+ "export" => $export,
+ "datas" => $datas,
+ "labels2" => $labels2,
+ "flip_data" => $flip_data,
+ "unit" => $unit
+ ];
+ PluginMreportingCommon::endGraph($options, $dashboard);
+ }
+
+ public function drawSunburstLevel($image, $datas, $params = [])
+ {
+ $width = $params['width'] - 70;
+ $height = $params['height'] - 120;
+
+ $gsum = PluginMreportingCommon::getArraySum($datas);
+
+ $index = 0;
+ $x = $width / 2;
+ $y = $height / 2 + 60;
+ $params['depth'] = isset($params['depth'])
? $params['depth']
: PluginMreportingCommon::getArrayDepth($datas);
- $params['start_angle'] = isset($params['start_angle']) ? $params['start_angle'] : 0;
- $params['max_angle'] = isset($params['max_angle']) ? $params['max_angle'] : 360;
- $params['level'] = isset($params['level']) ? $params['level'] : 0;
- $params['current_index'] = isset($params['current_index']) ? $params['current_index'] : false;
- $step = $height / $params['depth'];
- $radius = $step * ($params['level']+1);
-
- $darkerpalette = self::getDarkerPalette(50);
-
- foreach ($datas as $key => $data) {
- if (is_array($data)) {
- arsort($data);
-
- $params2 = [];
- $params2 = $params;
-
- $sum = PluginMreportingCommon::getArraySum($data);
- $angle = ($params['max_angle'] * $sum) / $gsum;
-
- $params2['max_angle'] = $angle;
- $params2['start_angle'] = $params['start_angle'];
- $params2['level'] = $params['level']+1;
- $params2['current_index'] = ($params['current_index'] === false)
- ? $index
- : $params['current_index'];
-
- $this->drawSunburstLevel($image, $data, $params2);
-
- } else {
- $angle = ($params['max_angle'] * $data) / $gsum;
- }
-
- //get colors
- $palette = $this->getPalette(50);
- if ($params['current_index'] === false) {
- $color = $palette[$index];
- } else {
- $color = $palette[$params['current_index']];
- //get lighter color
- $color = "0x00".substr(self::lighter($color, 15 * $params['level'] * $index), 0, 6);
- }
- $darkercolor = "0x00".substr(self::darker($color), 0, 6);
- $color_rbg = self::colorHexToRGB($color);
- $darkercolor_rbg = self::colorHexToRGB($darkercolor);
-
- //show data arc (tow arcs : 1st border color, 2nd content color)
- //(Never use deg2rad() in loops, use $rad = ($deg * M_PI / 180) instead which is faster!)
- imageSmoothArc(
- $image, $x, $y, $radius+1, $radius+1, $darkercolor_rbg,
- $params['start_angle'] * M_PI / 180,
- ($params['start_angle'] + $angle) * M_PI / 180
- );
- imageSmoothArc(
- $image, $x, $y, $radius-1, $radius-1, $color_rbg,
- ($params['start_angle'] + 0.8 / ($params['level']+1)) * M_PI / 180,
- ($params['start_angle'] + $angle - 0.8 / ($params['level']+1)) * M_PI / 180
- );
-
- //text associated with pie arc (only for angle > 2°)
- $am = $params['start_angle'] + $angle / 2; //mediant angle
- $amr = $am * M_PI / 180; //mediant angle in radiant
-
- //adjust label position (in fonction of angle position)
- $dx = $dy = 0;
- if ($amr>=7*M_PI/4 || $amr <= M_PI/4) {
- $dx=0;
- }
- if ($amr>=M_PI/4 && $amr <= 3*M_PI/4) {
- $dx=($amr-M_PI/4)*2/M_PI;
- }
- if ($amr>=3*M_PI/4 && $amr <= 5*M_PI/4) {
- $dx=1;
- }
- if ($amr>=5*M_PI/4 && $amr <= 7*M_PI/4) {
- $dx=(1-($amr-M_PI*5/4)*2/M_PI);
- }
-
- if ($amr>=7*M_PI/4) {
- $dy=(($amr-M_PI)-3*M_PI/4)*2/M_PI;
- }
- if ($amr<=M_PI/4) {
- $dy=(1-$amr*2/M_PI);
- }
- if ($amr>=M_PI/4 && $amr <= 3*M_PI/4) {
- $dy=1;
- }
- if ($amr>=3*M_PI/4 && $amr <= 5*M_PI/4) {
- $dy=(1-($amr-3*M_PI/4)*2/M_PI);
- }
- if ($amr>=5*M_PI/4 && $amr <= 7*M_PI/4) {
- $dy=0;
- }
-
- //get label size
- $box = @imageTTFBbox($this->fontsize, $this->fontangle, $this->font, $key);
- $tw = abs($box[4] - $box[0]);
- $th = abs($box[5] - $box[1]);
-
- //define label position
- if (is_array($data)) {
- //show label inside its arc
- $xtext = $x - $dx * $tw + cos($amr) * (0.5 * $radius - $step/3);
- $ytext = $y + $dy * $th - sin($amr) * (0.5 * $radius - $step/4);
- } else {
- //show label outside of its arc
- $xtext = $x + 3 - $dx * $tw + cos($amr) * (0.5 * $radius + $step/16);
- $ytext = $y + $dy * $th - sin($amr) * (0.5 * $radius + $step/8);
- }
-
- //draw label
- imagettftext(
- $image,
- $this->fontsize, $this->fontangle,
- $xtext, $ytext,
- hexdec($darkercolor),
- $this->font,
- $key
- );
-
- //values labels
- if ($angle > 5) {
- //mediant start angle in radiant (adjusted for left align label to its arc)
- $samr = ($params['start_angle'] + 10/($params['level']+1)) * M_PI / 180;
-
- //get label size
- $box = @imageTTFBbox($this->fontsize, $this->fontangle, $this->font,
- (is_array($data)) ? $gsum : $data);
+ $params['start_angle'] = isset($params['start_angle']) ? $params['start_angle'] : 0;
+ $params['max_angle'] = isset($params['max_angle']) ? $params['max_angle'] : 360;
+ $params['level'] = isset($params['level']) ? $params['level'] : 0;
+ $params['current_index'] = isset($params['current_index']) ? $params['current_index'] : false;
+ $step = $height / $params['depth'];
+ $radius = $step * ($params['level'] + 1);
+
+ $darkerpalette = self::getDarkerPalette(50);
+
+ foreach ($datas as $key => $data) {
+ if (is_array($data)) {
+ arsort($data);
+
+ $params2 = [];
+ $params2 = $params;
+
+ $sum = PluginMreportingCommon::getArraySum($data);
+ $angle = ($params['max_angle'] * $sum) / $gsum;
+
+ $params2['max_angle'] = $angle;
+ $params2['start_angle'] = $params['start_angle'];
+ $params2['level'] = $params['level'] + 1;
+ $params2['current_index'] = ($params['current_index'] === false)
+ ? $index
+ : $params['current_index'];
+
+ $this->drawSunburstLevel($image, $data, $params2);
+ } else {
+ $angle = ($params['max_angle'] * $data) / $gsum;
+ }
+
+ //get colors
+ $palette = $this->getPalette(50);
+ if ($params['current_index'] === false) {
+ $color = $palette[$index];
+ } else {
+ $color = $palette[$params['current_index']];
+ //get lighter color
+ $color = "0x00" . substr(self::lighter($color, 15 * $params['level'] * $index), 0, 6);
+ }
+ $darkercolor = "0x00" . substr(self::darker($color), 0, 6);
+ $color_rbg = self::colorHexToRGB($color);
+ $darkercolor_rbg = self::colorHexToRGB($darkercolor);
+
+ //show data arc (tow arcs : 1st border color, 2nd content color)
+ //(Never use deg2rad() in loops, use $rad = ($deg * M_PI / 180) instead which is faster!)
+ imageSmoothArc(
+ $image,
+ $x,
+ $y,
+ $radius + 1,
+ $radius + 1,
+ $darkercolor_rbg,
+ $params['start_angle'] * M_PI / 180,
+ ($params['start_angle'] + $angle) * M_PI / 180
+ );
+ imageSmoothArc(
+ $image,
+ $x,
+ $y,
+ $radius - 1,
+ $radius - 1,
+ $color_rbg,
+ ($params['start_angle'] + 0.8 / ($params['level'] + 1)) * M_PI / 180,
+ ($params['start_angle'] + $angle - 0.8 / ($params['level'] + 1)) * M_PI / 180
+ );
+
+ //text associated with pie arc (only for angle > 2°)
+ $am = $params['start_angle'] + $angle / 2; //mediant angle
+ $amr = $am * M_PI / 180; //mediant angle in radiant
+
+ //adjust label position (in fonction of angle position)
+ $dx = $dy = 0;
+ if ($amr >= 7 * M_PI / 4 || $amr <= M_PI / 4) {
+ $dx = 0;
+ }
+ if ($amr >= M_PI / 4 && $amr <= 3 * M_PI / 4) {
+ $dx = ($amr - M_PI / 4) * 2 / M_PI;
+ }
+ if ($amr >= 3 * M_PI / 4 && $amr <= 5 * M_PI / 4) {
+ $dx = 1;
+ }
+ if ($amr >= 5 * M_PI / 4 && $amr <= 7 * M_PI / 4) {
+ $dx = (1 - ($amr - M_PI * 5 / 4) * 2 / M_PI);
+ }
+
+ if ($amr >= 7 * M_PI / 4) {
+ $dy = (($amr - M_PI) - 3 * M_PI / 4) * 2 / M_PI;
+ }
+ if ($amr <= M_PI / 4) {
+ $dy = (1 - $amr * 2 / M_PI);
+ }
+ if ($amr >= M_PI / 4 && $amr <= 3 * M_PI / 4) {
+ $dy = 1;
+ }
+ if ($amr >= 3 * M_PI / 4 && $amr <= 5 * M_PI / 4) {
+ $dy = (1 - ($amr - 3 * M_PI / 4) * 2 / M_PI);
+ }
+ if ($amr >= 5 * M_PI / 4 && $amr <= 7 * M_PI / 4) {
+ $dy = 0;
+ }
+
+ //get label size
+ $box = @imageTTFBbox($this->fontsize, $this->fontangle, $this->font, $key);
$tw = abs($box[4] - $box[0]);
$th = abs($box[5] - $box[1]);
- //define label position
- $xtext = $x - $dx * $tw + cos($samr) * (0.5 * $radius - $step/8);
- $ytext = $y + $dy * $th - sin($samr) * (0.5 * $radius - $step/16);
+ //define label position
+ if (is_array($data)) {
+ //show label inside its arc
+ $xtext = $x - $dx * $tw + cos($amr) * (0.5 * $radius - $step / 3);
+ $ytext = $y + $dy * $th - sin($amr) * (0.5 * $radius - $step / 4);
+ } else {
+ //show label outside of its arc
+ $xtext = $x + 3 - $dx * $tw + cos($amr) * (0.5 * $radius + $step / 16);
+ $ytext = $y + $dy * $th - sin($amr) * (0.5 * $radius + $step / 8);
+ }
- //draw label
+ //draw label
imagettftext(
- $image,
- $this->fontsize, $this->fontangle,
- $xtext, $ytext,
- hexdec($this->black),
- $this->font,
- (is_array($data)) ? $sum : $data
+ $image,
+ $this->fontsize,
+ $this->fontangle,
+ $xtext,
+ $ytext,
+ hexdec($darkercolor),
+ $this->font,
+ $key
);
- }
- $params['start_angle']+= $angle;
- $index++;
- }
+ //values labels
+ if ($angle > 5) {
+ //mediant start angle in radiant (adjusted for left align label to its arc)
+ $samr = ($params['start_angle'] + 10 / ($params['level'] + 1)) * M_PI / 180;
+
+ //get label size
+ $box = @imageTTFBbox(
+ $this->fontsize,
+ $this->fontangle,
+ $this->font,
+ (is_array($data)) ? $gsum : $data
+ );
+ $tw = abs($box[4] - $box[0]);
+ $th = abs($box[5] - $box[1]);
+
+ //define label position
+ $xtext = $x - $dx * $tw + cos($samr) * (0.5 * $radius - $step / 8);
+ $ytext = $y + $dy * $th - sin($samr) * (0.5 * $radius - $step / 16);
+
+ //draw label
+ imagettftext(
+ $image,
+ $this->fontsize,
+ $this->fontangle,
+ $xtext,
+ $ytext,
+ hexdec($this->black),
+ $this->font,
+ (is_array($data)) ? $sum : $data
+ );
+ }
+
+ $params['start_angle'] += $angle;
+ $index++;
+ }
- return $image;
- }
+ return $image;
+ }
/**
@@ -1207,229 +1333,240 @@ function drawSunburstLevel($image, $datas, $params = []) {
* @param $show_label : behavior of the graph labels,
* values : 'hover', 'never', 'always' (optionnal)
* @param $export : keep only svg to export (optionnal)
- * @return nothing
+ * @return void
*/
- function showHgbar($params, $dashboard = false, $width = false) {
- if ($width !== false) {
- $this->width = $width;
- }
-
- $criterias = PluginMreportingCommon::initGraphParams($params);
-
- foreach ($criterias as $key => $val) {
- $$key=$val;
- }
-
- //$rand = $opt['rand'];
-
- $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']);
-
- foreach ($configs as $k => $v) {
- $$k=$v;
- }
-
- if (self::DEBUG_GRAPH && isset($raw_datas)) {
- Toolbox::logdebug($raw_datas);
- }
-
- if (isset($raw_datas['datas'])) {
- $datas = $raw_datas['datas'];
- } else {
- $datas = [];
- }
-
- $options = ["title" => $title,
- "desc" => $desc,
- "randname" => $randname,
- "export" => $export,
- "delay" => $delay,
- "short_classname" => $opt["short_classname"],
- "showHeader" => $dashboard];
-
- $this->initGraph($options);
-
- if (count($datas) <= 0) {
-
- if ($export!="odtall") {
- echo __("No data for this date range !", 'mreporting');
- $end['opt']["export"] = false;
- $end['opt']["randname"] = false;
- $end['opt']["f_name"] = $opt['f_name'];
- $end['opt']["class"] = $opt['class'];
- PluginMreportingCommon::endGraph($end);
- }
- return false;
- }
-
- $labels2 = $raw_datas['labels2'];
-
- if (empty($unit) && !empty($raw_datas['unit'])) {
- $unit = $raw_datas['unit'];
- }
-
- $datas = PluginMreportingCommon::compileDatasForUnit($datas, $unit);
- $raw_datas['datas'] = $datas;
-
- $values = array_values($datas);
- $labels = array_keys($datas);
-
- $max = 1;
- foreach ($values as $line) {
- foreach ($line as $label2 => $value) {
- if ($value > $max) {
- $max = $value;
- }
- }
- }
- if ($max == 1 && $unit == '%') {
- $max = 100;
- }
-
- $nb_bar = count($datas) * count($labels2);
- $width = $this->width;
- $height = 28 * $nb_bar + count($labels2) * 24;
-
- //create image
- $image = imagecreatetruecolor ($width, $height);
-
- if ($show_graph) {
- //colors
- $palette = self::getPalette($nb_bar);
- $darkerpalette = self::getDarkerPalette($nb_bar);
-
- //background
- $bg_color = hexdec($this->white);
- imagefilledrectangle($image, 0, 0, $width - 1, $height - 1, $bg_color);
-
- //create border on export
- if ($export) {
- imagerectangle($image, 0, 0, $width - 1, $height - 1, hexdec($this->black));
- }
-
- //add title on export
- if ($export) {
- imagettftext(
- $image,
- $this->fontsize+2,
- $this->fontangle,
- 10,
- 20,
- hexdec($this->black),
- $this->font,
- $title
- );
- }
-
- if ($export && $desc) {
- imagettftext($image, $this->fontsize+2, $this->fontangle, 10, 35,
- hexdec($this->black), $this->font, $desc);
- }
- //bars
- $index1 = 0;
- $index2 = 0;
-
- foreach ($datas as $label => $data) {
- $ly = $index1 * count($labels2) * 28 + count($labels2) *24 / 2 + count($labels2) * 14;
- $step = $index1 * count($labels2) * 28;
-
- //create axis label (align right)
- $box = @imageTTFBbox($this->fontsize, $this->fontangle, $this->font, $labels[$index1]);
- $textwidth = abs($box[4] - $box[0]);
- $textheight = abs($box[5] - $box[1]);
- imagettftext(
- $image,
- $this->fontsize,
- $this->fontangle,
- 245 - $textwidth,
- $ly + 14,
- hexdec($this->black),
- $this->font,
- Html::clean($labels[$index1])
- );
+ public function showHgbar($params, $dashboard = false, $width = false)
+ {
+ if ($width !== false) {
+ $this->width = $width;
+ }
+
+ $criterias = PluginMreportingCommon::initGraphParams($params);
+
+ foreach ($criterias as $key => $val) {
+ $$key = $val;
+ }
+
+ //$rand = $opt['rand'];
+
+ $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']);
+
+ foreach ($configs as $k => $v) {
+ $$k = $v;
+ }
+
+ if (self::DEBUG_GRAPH && isset($raw_datas)) {
+ Toolbox::logdebug($raw_datas);
+ }
+
+ if (isset($raw_datas['datas'])) {
+ $datas = $raw_datas['datas'];
+ } else {
+ $datas = [];
+ }
+
+ $options = ["title" => $title,
+ "desc" => $desc,
+ "randname" => $randname,
+ "export" => $export,
+ "delay" => $delay,
+ "short_classname" => $opt["short_classname"],
+ "showHeader" => $dashboard
+ ];
+
+ $this->initGraph($options);
+
+ if (count($datas) <= 0) {
+ if ($export != "odtall") {
+ echo __("No data for this date range !", 'mreporting');
+ $end['opt']["export"] = false;
+ $end['opt']["randname"] = false;
+ $end['opt']["f_name"] = $opt['f_name'];
+ $end['opt']["class"] = $opt['class'];
+ PluginMreportingCommon::endGraph($end);
+ }
+ return false;
+ }
- foreach ($data as $subdata) {
- $bx1 = 250;
- $by1 = ($index2+1) * 22 + $step + count($labels2) * 14;
- $bx2 = $bx1 + round(($subdata*($width - 300))/$max);
- $by2 = $by1 + 16;
+ $labels2 = $raw_datas['labels2'];
- //createbar
- ImageFilledRectangle($image, $bx1, $by1, $bx2, $by2, hexdec($palette[$index2]));
- imagerectangle($image, $bx1, $by1-1, $bx2+1, $by2+1, hexdec($darkerpalette[$index2]));
- imagerectangle($image, $bx1, $by1-2, $bx2+2, $by2+2, hexdec($darkerpalette[$index2]));
+ if (empty($unit) && !empty($raw_datas['unit'])) {
+ $unit = $raw_datas['unit'];
+ }
- //create data label
- if ($show_label == "always" || $show_label == "hover") {
- imagettftext(
- $image,
- $this->fontsize,
- $this->fontangle,
- $bx2 + 6,
- $by1 + 14,
- hexdec($darkerpalette[$index2]),
- $this->font,
- $subdata.$unit
- );
- }
- $index2++;
- }
- $index1++;
- $index2 = 0;
- }
+ $datas = PluginMreportingCommon::compileDatasForUnit($datas, $unit);
+ $raw_datas['datas'] = $datas;
- //y axis
- imageline($image, 250, 40, 250, $height-6, hexdec($this->black));
- imageline($image, 251, 40, 251, $height-6, hexdec($this->black));
+ $values = array_values($datas);
+ $labels = array_keys($datas);
+
+ $max = 1;
+ foreach ($values as $line) {
+ foreach ($line as $label2 => $value) {
+ if ($value > $max) {
+ $max = $value;
+ }
+ }
+ }
+ if ($max == 1 && $unit == '%') {
+ $max = 100;
+ }
+
+ $nb_bar = count($datas) * count($labels2);
+ $width = $this->width;
+ $height = 28 * $nb_bar + count($labels2) * 24;
+
+ //create image
+ $image = imagecreatetruecolor($width, $height);
+
+ if ($show_graph) {
+ //colors
+ $palette = self::getPalette($nb_bar);
+ $darkerpalette = self::getDarkerPalette($nb_bar);
+
+ //background
+ $bg_color = hexdec($this->white);
+ imagefilledrectangle($image, 0, 0, $width - 1, $height - 1, $bg_color);
+
+ //create border on export
+ if ($export) {
+ imagerectangle($image, 0, 0, $width - 1, $height - 1, hexdec($this->black));
+ }
- //legend (align right)
- $index = 0;
- foreach ($labels2 as $label) {
- $box = @imageTTFBbox($this->fontsize+1, $this->fontangle, $this->font, $label);
- $textwidth = abs($box[4] - $box[0]);
- $textheight = abs($box[5] - $box[1]);
+ //add title on export
+ if ($export) {
+ imagettftext(
+ $image,
+ $this->fontsize + 2,
+ $this->fontangle,
+ 10,
+ 20,
+ hexdec($this->black),
+ $this->font,
+ $title
+ );
+ }
- //legend label
- imagettftext(
- $image,
- $this->fontsize,
- $this->fontangle,
- $width - $textwidth - 18,
- 10 + $index * 15,
- hexdec($this->black),
- $this->font,
- Html::clean($label)
- );
+ if ($export && $desc) {
+ imagettftext(
+ $image,
+ $this->fontsize + 2,
+ $this->fontangle,
+ 10,
+ 35,
+ hexdec($this->black),
+ $this->font,
+ $desc
+ );
+ }
+ //bars
+ $index1 = 0;
+ $index2 = 0;
- //legend circle
- $color_rbg = self::colorHexToRGB($palette[$index]);
- imageSmoothArc($image, $width - 10, 5 + $index * 15, 8, 8, $color_rbg, 0, 2 * M_PI);
+ foreach ($datas as $label => $data) {
+ $ly = $index1 * count($labels2) * 28 + count($labels2) * 24 / 2 + count($labels2) * 14;
+ $step = $index1 * count($labels2) * 28;
+
+ //create axis label (align right)
+ $box = @imageTTFBbox($this->fontsize, $this->fontangle, $this->font, $labels[$index1]);
+ $textwidth = abs($box[4] - $box[0]);
+ $textheight = abs($box[5] - $box[1]);
+ imagettftext(
+ $image,
+ $this->fontsize,
+ $this->fontangle,
+ 245 - $textwidth,
+ $ly + 14,
+ hexdec($this->black),
+ $this->font,
+ Toolbox::stripTags($labels[$index1])
+ );
+
+ foreach ($data as $subdata) {
+ $bx1 = 250;
+ $by1 = ($index2 + 1) * 22 + $step + count($labels2) * 14;
+ $bx2 = $bx1 + round(($subdata * ($width - 300)) / $max);
+ $by2 = $by1 + 16;
+
+ //createbar
+ ImageFilledRectangle($image, $bx1, $by1, $bx2, $by2, hexdec($palette[$index2]));
+ imagerectangle($image, $bx1, $by1 - 1, $bx2 + 1, $by2 + 1, hexdec($darkerpalette[$index2]));
+ imagerectangle($image, $bx1, $by1 - 2, $bx2 + 2, $by2 + 2, hexdec($darkerpalette[$index2]));
+
+ //create data label
+ if ($show_label == "always" || $show_label == "hover") {
+ imagettftext(
+ $image,
+ $this->fontsize,
+ $this->fontangle,
+ $bx2 + 6,
+ $by1 + 14,
+ hexdec($darkerpalette[$index2]),
+ $this->font,
+ $subdata . $unit
+ );
+ }
+ $index2++;
+ }
+ $index1++;
+ $index2 = 0;
+ }
- $index++;
- }
- }
- //generate image
- $params = ["image" => $image,
- "export" => $export,
- "f_name" => $opt['f_name'],
- "class" => $opt['class'],
- "title" => $title,
- "randname" => $randname,
- "raw_datas" => $raw_datas,
- "withdata" => $opt['withdata']];
-
- $contents = $this->generateImage($params);
- if ($show_graph) {
- $this->showImage($contents, $export);
- }
- $opt['randname'] = $randname;
- $options = ["opt" => $opt,
- "export" => $export,
- "datas" => $datas,
- "labels2" => $labels2,
- "flip_data" => $flip_data,
- "unit" => $unit];
- PluginMreportingCommon::endGraph($options, $dashboard);
- }
+ //y axis
+ imageline($image, 250, 40, 250, $height - 6, hexdec($this->black));
+ imageline($image, 251, 40, 251, $height - 6, hexdec($this->black));
+
+ //legend (align right)
+ $index = 0;
+ foreach ($labels2 as $label) {
+ $box = @imageTTFBbox($this->fontsize + 1, $this->fontangle, $this->font, $label);
+ $textwidth = abs($box[4] - $box[0]);
+ $textheight = abs($box[5] - $box[1]);
+
+ //legend label
+ imagettftext(
+ $image,
+ $this->fontsize,
+ $this->fontangle,
+ $width - $textwidth - 18,
+ 10 + $index * 15,
+ hexdec($this->black),
+ $this->font,
+ Toolbox::stripTags($label)
+ );
+
+ //legend circle
+ $color_rbg = self::colorHexToRGB($palette[$index]);
+ imageSmoothArc($image, $width - 10, 5 + $index * 15, 8, 8, $color_rbg, 0, 2 * M_PI);
+
+ $index++;
+ }
+ }
+ //generate image
+ $params = ["image" => $image,
+ "export" => $export,
+ "f_name" => $opt['f_name'],
+ "class" => $opt['class'],
+ "title" => $title,
+ "randname" => $randname,
+ "raw_datas" => $raw_datas,
+ "withdata" => $opt['withdata']
+ ];
+
+ $contents = $this->generateImage($params);
+ if ($show_graph) {
+ $this->showImage($contents, $export);
+ }
+ $opt['randname'] = $randname;
+ $options = ["opt" => $opt,
+ "export" => $export,
+ "datas" => $datas,
+ "labels2" => $labels2,
+ "flip_data" => $flip_data,
+ "unit" => $unit
+ ];
+ PluginMreportingCommon::endGraph($options, $dashboard);
+ }
/**
@@ -1444,296 +1581,329 @@ function showHgbar($params, $dashboard = false, $width = false) {
* @param $show_label : behavior of the graph labels,
* values : 'hover', 'never', 'always' (optionnal)
* @param $export : keep only svg to export (optionnal)
- * @return nothing
+ * @return void
*/
- function showVstackbar($params, $dashboard = false, $width = false) {
- if ($width !== false) {
- $this->width = $width;
- }
-
- $criterias = PluginMreportingCommon::initGraphParams($params);
-
- foreach ($criterias as $key => $val) {
- $$key=$val;
- }
-
- //$rand = $opt['rand'];
-
- $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']);
-
- foreach ($configs as $k => $v) {
- $$k=$v;
- }
-
- if (self::DEBUG_GRAPH && isset($raw_datas)) {
- Toolbox::logdebug($raw_datas);
- }
-
- if (isset($raw_datas['datas'])) {
- $datas = $raw_datas['datas'];
- } else {
- $datas = [];
- }
-
- $options = ["title" => $title,
- "desc" => $desc,
- "randname" => $randname,
- "export" => $export,
- "delay" => $delay,
- "short_classname" => $opt["short_classname"],
- "showHeader" => $dashboard];
-
- $this->initGraph($options);
-
- if (count($datas) <= 0) {
-
- if ($export!="odtall") {
- echo __("No data for this date range !", 'mreporting');
- $end['opt']["export"] = false;
- $end['opt']["randname"] = false;
- $end['opt']["f_name"] = $opt['f_name'];
- $end['opt']["class"] = $opt['class'];
- PluginMreportingCommon::endGraph($end);
- }
- return false;
- }
-
- $labels2 = $raw_datas['labels2'];
-
- if (empty($unit) && !empty($raw_datas['unit'])) {
- $unit = $raw_datas['unit'];
- }
-
- $datas = PluginMreportingCommon::compileDatasForUnit($datas, $unit);
- $raw_datas['datas'] = $datas;
-
- $values = array_values($datas);
-
- $labels = array_keys($datas);
-
- $max = 1;
- foreach ($values as $line) {
- foreach ($line as $label2 => $value) {
- if ($value > $max) {
- $max = $value;
- }
- }
- }
- if ($max == 1 && $unit == '%') {
- $max = 100;
- }
-
- //process datas (reverse keys)
- $new_datas=[];
-
- foreach ($datas as $key1 => $data) {
- foreach ($data as $key2 => $subdata) {
- $new_datas[$key2][$key1] = $subdata;
- }
- }
-
- //calculate max cumul
- $cum = 0;
- foreach ($new_datas as $key1 => $data) {
- $tmp_cum = 0;
- foreach ($data as $key2 => $subdata) {
- $tmp_cum += $subdata;
- }
- if ($tmp_cum > $cum) {
- $cum = $tmp_cum;
- }
- }
-
- $nb_bar = count($labels2);
- $nb_labels2 = count($datas);
- $height = 400;
- if ($dashboard) {
- $height = 350;
- }
- $x_bar = (0.85 * $this->width / $nb_bar);
- $width_bar = $x_bar * .85;
- $y_labels_width = .1 * $this->width;
- $x_labels_height = $height - 0.95 * $height;
- $legend_height = $nb_labels2 * 15 + 10;
-
- //longueur du texte en dessous des barres
- $index = 0;
- foreach ($labels2 as $label) {
- $lx = 55 + $index * $width_bar;
- $box = @imageTTFBbox($this->fontsize-1, $this->fontangle, $this->font, $label);
- $textwidth[$label] = abs($box[4] - $box[0]);
- $index++;
- }
- $maxtextwidth = max($textwidth);
-
- //create image
- $image = imagecreatetruecolor ($this->width, $height + $maxtextwidth);
-
- if ($show_graph) {
- //colors
- $palette = self::getPalette($nb_bar);
- $alphapalette = self::getPalette($nb_bar, 90);
- $darkerpalette = self::getDarkerPalette($nb_bar);
-
- //background
- $bg_color = hexdec($this->white);
- imagefilledrectangle($image, 0, 0, $this->width, $height + $maxtextwidth, $bg_color);
-
- //create border on export
- if ($export) {
- imagerectangle($image, 0, 0, $this->width - 1, $height - 1 + $maxtextwidth, hexdec($this->black));
- }
-
- //draw x-axis grey step line and values ticks
- $xstep = round(($height - $legend_height - $x_labels_height) / 12);
- for ($i = 0; $i <= 12; $i++) {
- $yaxis = $height - $x_labels_height - $xstep * $i;
- imageLine($image, .9 * $y_labels_width, $yaxis, 0.95 * $this->width, $yaxis, hexdec($this->grey));
-
- //value label
- $val = round($i * $cum / 12, 1);
- $box = @imageTTFBbox($this->fontsize, $this->fontangle, $this->font, $val);
- $textwidth = abs($box[4] - $box[0]);
-
- imagettftext($image, $this->fontsize, $this->fontangle,
- $y_labels_width - 2 - $textwidth, $yaxis + 5, hexdec($this->darkgrey), $this->font, $val);
- }
-
- //draw y-axis
- imageLine($image, $y_labels_width, $legend_height, $y_labels_width, $height-28, hexdec($this->black));
-
- //draw x-axis
- imageline($image, .9 * $y_labels_width, $height - $x_labels_height,
- 0.95 * $this->width, $height - $x_labels_height, hexdec($this->black));
-
- //add title on export
- if ($export) {
- imagettftext(
- $image,
- $this->fontsize+2,
- $this->fontangle,
- 10,
- 20,
- hexdec($this->black),
- $this->font,
- $title
- );
- }
+ public function showVstackbar($params, $dashboard = false, $width = false)
+ {
+ if ($width !== false) {
+ $this->width = $width;
+ }
+
+ $criterias = PluginMreportingCommon::initGraphParams($params);
+
+ foreach ($criterias as $key => $val) {
+ $$key = $val;
+ }
+
+ //$rand = $opt['rand'];
+
+ $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']);
+
+ foreach ($configs as $k => $v) {
+ $$k = $v;
+ }
+
+ if (self::DEBUG_GRAPH && isset($raw_datas)) {
+ Toolbox::logdebug($raw_datas);
+ }
+
+ if (isset($raw_datas['datas'])) {
+ $datas = $raw_datas['datas'];
+ } else {
+ $datas = [];
+ }
+
+ $options = ["title" => $title,
+ "desc" => $desc,
+ "randname" => $randname,
+ "export" => $export,
+ "delay" => $delay,
+ "short_classname" => $opt["short_classname"],
+ "showHeader" => $dashboard
+ ];
+
+ $this->initGraph($options);
+
+ if (count($datas) <= 0) {
+ if ($export != "odtall") {
+ echo __("No data for this date range !", 'mreporting');
+ $end['opt']["export"] = false;
+ $end['opt']["randname"] = false;
+ $end['opt']["f_name"] = $opt['f_name'];
+ $end['opt']["class"] = $opt['class'];
+ PluginMreportingCommon::endGraph($end);
+ }
+ return false;
+ }
- if ($export && $desc) {
- imagettftext($image, $this->fontsize+2, $this->fontangle, 10, 35,
- hexdec($this->black), $this->font, $desc);
- }
+ $labels2 = $raw_datas['labels2'];
- $index1 = 0;
- $index2 = 0;
+ if (empty($unit) && !empty($raw_datas['unit'])) {
+ $unit = $raw_datas['unit'];
+ }
- foreach ($new_datas as $label => $data) {
- $by2 = $height - $x_labels_height;
+ $datas = PluginMreportingCommon::compileDatasForUnit($datas, $unit);
+ $raw_datas['datas'] = $datas;
- foreach ($data as $subdata) {
- $by1 = $by2;
- $bx1 = $y_labels_width + $index1 * $x_bar;
- $by2 = $by1 - $subdata * ($height - $legend_height - $x_labels_height) / $cum;
- $bx2 = $bx1 + $width_bar;
+ $values = array_values($datas);
- if ($by1 != $by2) { // no draw for empty datas
- imagefilledrectangle($image, $bx1, $by1, $bx2, $by2, hexdec($alphapalette[$index2]));
- imagerectangle($image, $bx1, $by1, $bx2, $by2, hexdec($darkerpalette[$index2]));
+ $labels = array_keys($datas);
- //create data label // Affichage des données à côté des barres
- if (($show_label == "always" || $show_label == "hover") && $subdata>0) {
- $box = @imageTTFBbox($this->fontsize-1, $this->fontangle, $this->font, $subdata.$unit);
- $textwidth = abs($box[4] - $box[6]);
+ $max = 1;
+ foreach ($values as $line) {
+ foreach ($line as $label2 => $value) {
+ if ($value > $max) {
+ $max = $value;
+ }
+ }
+ }
+ if ($max == 1 && $unit == '%') {
+ $max = 100;
+ }
- imagettftext(
- $image,
- $this->fontsize-1,
- $this->fontangle,
- $bx1 + ($width_bar / 2) - ($textwidth / 2) - 4,
- $by1 - ($by1 - $by2)/2 + 5,
- hexdec($darkerpalette[$index2]),
- $this->font,
- $subdata.$unit
- );
- }
- }
- $tab[$index2]= $by1;
- $index2++;
+ //process datas (reverse keys)
+ $new_datas = [];
+
+ foreach ($datas as $key1 => $data) {
+ foreach ($data as $key2 => $subdata) {
+ $new_datas[$key2][$key1] = $subdata;
+ }
+ }
+
+ //calculate max cumul
+ $cum = 0;
+ foreach ($new_datas as $key1 => $data) {
+ $tmp_cum = 0;
+ foreach ($data as $key2 => $subdata) {
+ $tmp_cum += $subdata;
}
+ if ($tmp_cum > $cum) {
+ $cum = $tmp_cum;
+ }
+ }
+
+ $nb_bar = count($labels2);
+ $nb_labels2 = count($datas);
+ $height = 400;
+ if ($dashboard) {
+ $height = 350;
+ }
+ $x_bar = (0.85 * $this->width / $nb_bar);
+ $width_bar = $x_bar * .85;
+ $y_labels_width = .1 * $this->width;
+ $x_labels_height = $height - 0.95 * $height;
+ $legend_height = $nb_labels2 * 15 + 10;
+
+ //longueur du texte en dessous des barres
+ $index = 0;
+ foreach ($labels2 as $label) {
+ $lx = 55 + $index * $width_bar;
+ $box = @imageTTFBbox($this->fontsize - 1, $this->fontangle, $this->font, $label);
+ $textwidth[$label] = abs($box[4] - $box[0]);
+ $index++;
+ }
+ $maxtextwidth = max($textwidth);
- //create label 2
- $box = @imageTTFBbox($this->fontsize-1, $this->fontangle, $this->font, $labels2[$label]);
- $textwidth = abs($box[4] - $box[6]);
- $textwidth = abs(sqrt((pow($textwidth, 2) / 2)));
+ //create image
+ $image = imagecreatetruecolor($this->width, $height + $maxtextwidth);
- $lx = $y_labels_width + $index1 * $x_bar + ($width_bar / 2.5);
- imagettftext(
- $image,
- $this->fontsize-1,
- -45,
- $lx,
- $height - $x_labels_height + 9,
- hexdec($this->black),
- $this->font,
- Html::clean($labels2[$label])
- );
+ if ($show_graph) {
+ //colors
+ $palette = self::getPalette($nb_bar);
+ $alphapalette = self::getPalette($nb_bar, 90);
+ $darkerpalette = self::getDarkerPalette($nb_bar);
- $index1++;
- $index2 = 0;
- }
+ //background
+ $bg_color = hexdec($this->white);
+ imagefilledrectangle($image, 0, 0, $this->width, $height + $maxtextwidth, $bg_color);
- //legend (align right)
- $index = 0;
- foreach ($datas as $label => $data) {
- $box = @imageTTFBbox($this->fontsize, $this->fontangle, $this->font, $labels[$index]);
- $textwidth = abs($box[4] - $box[0]);
- $textheight = abs($box[5] - $box[1]);
- $y_legend = 5 + ($index + 1) * 15;
+ //create border on export
+ if ($export) {
+ imagerectangle($image, 0, 0, $this->width - 1, $height - 1 + $maxtextwidth, hexdec($this->black));
+ }
- //legend label
- imagettftext(
- $image,
- $this->fontsize-1,
- $this->fontangle,
- $this->width - $textwidth - 18,
- $y_legend,
- hexdec($this->black),
- $this->font,
- Html::clean($labels[$index])
+ //draw x-axis grey step line and values ticks
+ $xstep = round(($height - $legend_height - $x_labels_height) / 12);
+ for ($i = 0; $i <= 12; $i++) {
+ $yaxis = $height - $x_labels_height - $xstep * $i;
+ imageLine($image, .9 * $y_labels_width, $yaxis, 0.95 * $this->width, $yaxis, hexdec($this->grey));
+
+ //value label
+ $val = round($i * $cum / 12, 1);
+ $box = @imageTTFBbox($this->fontsize, $this->fontangle, $this->font, $val);
+ $textwidth = abs($box[4] - $box[0]);
+
+ imagettftext(
+ $image,
+ $this->fontsize,
+ $this->fontangle,
+ $y_labels_width - 2 - $textwidth,
+ $yaxis + 5,
+ hexdec($this->darkgrey),
+ $this->font,
+ $val
+ );
+ }
+
+ //draw y-axis
+ imageLine($image, $y_labels_width, $legend_height, $y_labels_width, $height - 28, hexdec($this->black));
+
+ //draw x-axis
+ imageline(
+ $image,
+ .9 * $y_labels_width,
+ $height - $x_labels_height,
+ 0.95 * $this->width,
+ $height - $x_labels_height,
+ hexdec($this->black)
);
- //legend circle
- $color_rbg = self::colorHexToRGB($palette[$index]);
- imageSmoothArc($image,
- $this->width - 10, $y_legend - 4, 8, 8, $color_rbg, 0, 2 * M_PI);
+ //add title on export
+ if ($export) {
+ imagettftext(
+ $image,
+ $this->fontsize + 2,
+ $this->fontangle,
+ 10,
+ 20,
+ hexdec($this->black),
+ $this->font,
+ $title
+ );
+ }
- $index++;
- }
- }
- //generate image
- $params = ["image" => $image,
- "export" => $export,
- "f_name" => $opt['f_name'],
- "class" => $opt['class'],
- "title" => $title,
- "randname" => $randname,
- "raw_datas" => $raw_datas,
- "withdata" => $opt['withdata']];
-
- $contents = $this->generateImage($params);
- if ($show_graph) {
- $this->showImage($contents, $export);
- }
- $opt['randname'] = $randname;
- $options = ["opt" => $opt,
- "export" => $export,
- "datas" => $datas,
- "labels2" => $labels2,
- "flip_data" => $flip_data,
- "unit" => $unit];
- PluginMreportingCommon::endGraph($options, $dashboard);
- }
+ if ($export && $desc) {
+ imagettftext(
+ $image,
+ $this->fontsize + 2,
+ $this->fontangle,
+ 10,
+ 35,
+ hexdec($this->black),
+ $this->font,
+ $desc
+ );
+ }
+
+ $index1 = 0;
+ $index2 = 0;
+
+ foreach ($new_datas as $label => $data) {
+ $by2 = $height - $x_labels_height;
+
+ foreach ($data as $subdata) {
+ $by1 = $by2;
+ $bx1 = $y_labels_width + $index1 * $x_bar;
+ $by2 = $by1 - $subdata * ($height - $legend_height - $x_labels_height) / $cum;
+ $bx2 = $bx1 + $width_bar;
+
+ if ($by1 != $by2) { // no draw for empty datas
+ imagefilledrectangle($image, $bx1, $by1, $bx2, $by2, hexdec($alphapalette[$index2]));
+ imagerectangle($image, $bx1, $by1, $bx2, $by2, hexdec($darkerpalette[$index2]));
+
+ //create data label // Affichage des données à côté des barres
+ if (($show_label == "always" || $show_label == "hover") && $subdata > 0) {
+ $box = @imageTTFBbox($this->fontsize - 1, $this->fontangle, $this->font, $subdata . $unit);
+ $textwidth = abs($box[4] - $box[6]);
+
+ imagettftext(
+ $image,
+ $this->fontsize - 1,
+ $this->fontangle,
+ $bx1 + ($width_bar / 2) - ($textwidth / 2) - 4,
+ $by1 - ($by1 - $by2) / 2 + 5,
+ hexdec($darkerpalette[$index2]),
+ $this->font,
+ $subdata . $unit
+ );
+ }
+ }
+ $tab[$index2] = $by1;
+ $index2++;
+ }
+
+ //create label 2
+ $box = @imageTTFBbox($this->fontsize - 1, $this->fontangle, $this->font, $labels2[$label]);
+ $textwidth = abs($box[4] - $box[6]);
+ $textwidth = abs(sqrt((pow($textwidth, 2) / 2)));
+
+ $lx = $y_labels_width + $index1 * $x_bar + ($width_bar / 2.5);
+ imagettftext(
+ $image,
+ $this->fontsize - 1,
+ -45,
+ $lx,
+ $height - $x_labels_height + 9,
+ hexdec($this->black),
+ $this->font,
+ Toolbox::stripTags($labels2[$label])
+ );
+
+ $index1++;
+ $index2 = 0;
+ }
+
+ //legend (align right)
+ $index = 0;
+ foreach ($datas as $label => $data) {
+ $box = @imageTTFBbox($this->fontsize, $this->fontangle, $this->font, $labels[$index]);
+ $textwidth = abs($box[4] - $box[0]);
+ $textheight = abs($box[5] - $box[1]);
+ $y_legend = 5 + ($index + 1) * 15;
+
+ //legend label
+ imagettftext(
+ $image,
+ $this->fontsize - 1,
+ $this->fontangle,
+ $this->width - $textwidth - 18,
+ $y_legend,
+ hexdec($this->black),
+ $this->font,
+ Toolbox::stripTags($labels[$index])
+ );
+
+ //legend circle
+ $color_rbg = self::colorHexToRGB($palette[$index]);
+ imageSmoothArc(
+ $image,
+ $this->width - 10,
+ $y_legend - 4,
+ 8,
+ 8,
+ $color_rbg,
+ 0,
+ 2 * M_PI
+ );
+
+ $index++;
+ }
+ }
+ //generate image
+ $params = ["image" => $image,
+ "export" => $export,
+ "f_name" => $opt['f_name'],
+ "class" => $opt['class'],
+ "title" => $title,
+ "randname" => $randname,
+ "raw_datas" => $raw_datas,
+ "withdata" => $opt['withdata']
+ ];
+
+ $contents = $this->generateImage($params);
+ if ($show_graph) {
+ $this->showImage($contents, $export);
+ }
+ $opt['randname'] = $randname;
+ $options = ["opt" => $opt,
+ "export" => $export,
+ "datas" => $datas,
+ "labels2" => $labels2,
+ "flip_data" => $flip_data,
+ "unit" => $unit
+ ];
+ PluginMreportingCommon::endGraph($options, $dashboard);
+ }
/**
@@ -1749,261 +1919,310 @@ function showVstackbar($params, $dashboard = false, $width = false) {
* values : 'hover', 'never', 'always' (optionnal)
* @param $export : keep only svg to export (optionnal)
* @param $area : show plain chart instead only a line (optionnal)
- * @return nothing
+ * @return void
*/
- function showArea($params, $dashboard = false, $width = false) {
- if ($width !== false) {
- $this->width = $width;
- }
-
- $criterias = PluginMreportingCommon::initGraphParams($params);
-
- foreach ($criterias as $key => $val) {
- $$key=$val;
- }
-
- //$rand = $opt['rand'];
-
- $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']);
-
- foreach ($configs as $k => $v) {
- $$k=$v;
- }
-
- if (self::DEBUG_GRAPH && isset($raw_datas)) {
- Toolbox::logdebug($raw_datas);
- }
-
- if (isset($raw_datas['datas'])) {
- $datas = $raw_datas['datas'];
- } else {
- $datas = [];
- }
-
- $options = ["title" => $title,
- "desc" => $desc,
- "randname" => $randname,
- "export" => $export,
- "delay" => $delay,
- "short_classname" => $opt["short_classname"],
- "showHeader" => $dashboard];
-
- $this->initGraph($options);
-
- if (count($datas) <= 0) {
-
- if ($export!="odtall") {
- echo __("No data for this date range !", 'mreporting');
- $end['opt']["export"] = false;
- $end['opt']["randname"] = false;
- $end['opt']["f_name"] = $opt['f_name'];
- $end['opt']["class"] = $opt['class'];
- PluginMreportingCommon::endGraph($end);
- }
- return false;
- }
-
- if (empty($unit) && !empty($raw_datas['unit'])) {
- $unit = $raw_datas['unit'];
- }
-
- $datas = PluginMreportingCommon::compileDatasForUnit($datas, $unit);
- $raw_datas['datas'] = $datas;
-
- $values = array_values($datas);
- $labels = array_keys($datas);
- $max = max($values);
- if ($max <= 1) {
- $max = 1;
- }
- if ($max == 1 && $unit == '%') {
- $max = 100;
- }
-
- $nb = count($datas);
- $width = $this->width;
- $height = 350;
- $width_line = ($width - 45) / $nb;
- $step = ceil($nb / 20);
-
- //create image
- $image = imagecreatetruecolor ($width, $height);
-
- if ($show_graph) {
- //colors
- $palette = self::getPalette($nb);
- $alphapalette = self::getPalette($nb, "50");
- $darkerpalette = self::getDarkerPalette($nb);
-
- //background
- $bg_color = hexdec($this->white);
- imagefilledrectangle($image, 0, 0, $width - 1, $height - 1, $bg_color);
-
- //draw x-axis grey step line and values
- $xstep = round(($height - 60) / 13);
- for ($i = 0; $i< 13; $i++) {
- $yaxis = $height- 30 - $xstep * $i;
-
- //grey lines
- imageLine($image, 30, $yaxis, 30+$width_line*($nb-1), $yaxis, hexdec($this->grey));
-
- //value labels
- $val = round($i * $max / 12);
- $box = @imageTTFBbox($this->fontsize, $this->fontangle, $this->font, $val);
- $textwidth = abs($box[4] - $box[0]);
- imagettftext($image, $this->fontsize, $this->fontangle,
- 28-$textwidth, $yaxis+5, hexdec($this->darkgrey), $this->font, $val);
- }
-
- //draw y-axis grey step line
- for ($i = 0; $i< $nb; $i++) {
- $xaxis = 30 + $width_line * $i;
- imageLine($image, $xaxis, 50, $xaxis, $height-25, hexdec($this->grey));
- }
-
- //draw y-axis
- imageLine($image, 30, 50, 30, $height-25, hexdec($this->black));
-
- //draw x-axis
- imageline($image, 30, $height-30, $width - 60, $height-30, hexdec($this->black));
-
- //create border on export
- if ($export) {
- imagerectangle($image, 0, 0, $width - 1, $height - 1, hexdec($this->black));
- }
-
- //add title on export
- if ($export) {
- imagettftext($image, $this->fontsize+1, $this->fontangle, 10, 20,
- hexdec($this->black), $this->font, $title);
- }
-
- //on png graph, no way to draw curved polygons, force area reports to be linear
- if ($area) {
- $spline = false;
- }
-
- //parse datas
- $index = 0;
- $old_data = 0;
- $aCoords = [];
- foreach ($datas as $label => $data) {
-
- //if first index, continue
- if ($index == 0) {
- $old_data = $data;
- $index++;
- continue;
- }
-
- // determine coords
- $x1 = $index * $width_line - $width_line + 30;
- $y1 = $height - 30 - $old_data * ($height - 85) / $max;
- $x2 = $x1 + $width_line;
- $y2 = $height - 30 - $data * ($height - 85) / $max;
- $aCoords[$x1] = $y1;
-
- //in case of area chart fill under point space
- if ($area > 0) {
- $points = [
- $x1, $y1,
- $x2, $y2,
- $x2, $height - 30,
- $x1, $height - 30
- ];
- imagefilledpolygon($image, $points, 4, hexdec($alphapalette[0]));
- }
-
- //trace lines between points (if linear)
- if (!$spline) {
- $this->imageSmoothAlphaLineLarge ($image, $x1, $y1, $x2, $y2, $palette[0]);
- }
-
- $old_data = $data;
- $index++;
- }
-
- //if curved spline activated, draw cubic spline for the current line
- if ($spline) {
- $aCoords[$x2] = $y2;
- $this->imageCubicSmoothLine($image, $palette[0], $aCoords);
- }
-
- //draw labels and dots
- $index = 0;
- $old_label = "";
- foreach ($datas as $label => $data) {
- //if first index, continue
- if ($index == 0) {
- $old_data = $data;
- $old_label = $label;
- $index++;
- continue;
- }
-
- // determine coords
- $x1 = $index * $width_line - $width_line + 30;
- $y1 = $height - 30 - $old_data * ($height - 85) / $max;
- $x2 = $x1 + $width_line;
- $y2 = $height - 30 - $data * ($height - 85) / $max;
-
- //trace dots
- $color_rbg = self::colorHexToRGB($darkerpalette[0]);
- imageSmoothArc($image, $x1-1, $y1-1, 8, 8, $color_rbg, 0, 2 * M_PI);
- imageSmoothArc($image, $x1-1, $y1-1, 4, 4, [255,255,255,0], 0, 2 * M_PI);
-
- //display values label
- if ($show_label == "always" || $show_label == "hover") {
- imagettftext($image, $this->fontsize-1, $this->fontangle,
- ($index == 1 ? $x1 : $x1 - 6 ), $y1 - 5,
- hexdec($darkerpalette[0]), $this->font, $old_data);
- }
-
- //display y ticks and labels
- if ($step!=0 && ($index / $step) == round($index / $step)) {
- imageline($image, $x1, $height-30, $x1, $height-27, hexdec($darkerpalette[0]));
-
- imagettftext($image, $this->fontsize, $this->fontangle, $x1 - 10, $height-10,
- hexdec($this->black), $this->font, $old_label);
- }
-
- $old_data = $data;
- $old_label = $label;
- $index++;
- }
-
- //display last value, dot and axis label
- if (isset($x2)) {
- imagettftext($image, $this->fontsize-1, $this->fontangle,
- $x2 - 6, $y2 - 5, hexdec($darkerpalette[0]), $this->font, $data);
- $color_rbg = self::colorHexToRGB($darkerpalette[0]);
- imageSmoothArc($image, $x2-1, $y2-1, 8, 8, $color_rbg, 0, 2 * M_PI);
- imageSmoothArc($image, $x2-1, $y2-1, 4, 4, [255,255,255,0], 0, 2 * M_PI);
- imagettftext($image, $this->fontsize, $this->fontangle,
- $x2 - 10, $height-10, hexdec($this->black), $this->font, $label);
- imageline($image, $x2, $height-30, $x2, $height-27, hexdec($darkerpalette[0]));
- }
- }
- //generate image
- $params = ["image" => $image,
- "export" => $export,
- "f_name" => $opt['f_name'],
- "class" => $opt['class'],
- "title" => $title,
- "randname" => $randname,
- "raw_datas" => $raw_datas,
- "withdata" => $opt['withdata']];
- $contents = $this->generateImage($params);
- if ($show_graph) {
- $this->showImage($contents, $export);
- }
- $opt['randname'] = $randname;
- $options = ["opt" => $opt,
- "export" => $export,
- "datas" => $datas,
- "unit" => $unit];
- PluginMreportingCommon::endGraph($options, $dashboard);
- } // end Area
+ public function showArea($params, $dashboard = false, $width = false)
+ {
+ if ($width !== false) {
+ $this->width = $width;
+ }
+
+ $criterias = PluginMreportingCommon::initGraphParams($params);
+
+ foreach ($criterias as $key => $val) {
+ $$key = $val;
+ }
+
+ //$rand = $opt['rand'];
+
+ $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']);
+
+ foreach ($configs as $k => $v) {
+ $$k = $v;
+ }
+
+ if (self::DEBUG_GRAPH && isset($raw_datas)) {
+ Toolbox::logdebug($raw_datas);
+ }
+
+ if (isset($raw_datas['datas'])) {
+ $datas = $raw_datas['datas'];
+ } else {
+ $datas = [];
+ }
+
+ $options = ["title" => $title,
+ "desc" => $desc,
+ "randname" => $randname,
+ "export" => $export,
+ "delay" => $delay,
+ "short_classname" => $opt["short_classname"],
+ "showHeader" => $dashboard
+ ];
+
+ $this->initGraph($options);
+
+ if (count($datas) <= 0) {
+ if ($export != "odtall") {
+ echo __("No data for this date range !", 'mreporting');
+ $end['opt']["export"] = false;
+ $end['opt']["randname"] = false;
+ $end['opt']["f_name"] = $opt['f_name'];
+ $end['opt']["class"] = $opt['class'];
+ PluginMreportingCommon::endGraph($end);
+ }
+ return false;
+ }
+
+ if (empty($unit) && !empty($raw_datas['unit'])) {
+ $unit = $raw_datas['unit'];
+ }
+
+ $datas = PluginMreportingCommon::compileDatasForUnit($datas, $unit);
+ $raw_datas['datas'] = $datas;
+
+ $values = array_values($datas);
+ $labels = array_keys($datas);
+ $max = max($values);
+ if ($max <= 1) {
+ $max = 1;
+ }
+ if ($max == 1 && $unit == '%') {
+ $max = 100;
+ }
+
+ $nb = count($datas);
+ $width = $this->width;
+ $height = 350;
+ $width_line = ($width - 45) / $nb;
+ $step = ceil($nb / 20);
+
+ //create image
+ $image = imagecreatetruecolor($width, $height);
+
+ if ($show_graph) {
+ //colors
+ $palette = self::getPalette($nb);
+ $alphapalette = self::getPalette($nb, "50");
+ $darkerpalette = self::getDarkerPalette($nb);
+
+ //background
+ $bg_color = hexdec($this->white);
+ imagefilledrectangle($image, 0, 0, $width - 1, $height - 1, $bg_color);
+
+ //draw x-axis grey step line and values
+ $xstep = round(($height - 60) / 13);
+ for ($i = 0; $i < 13; $i++) {
+ $yaxis = $height - 30 - $xstep * $i;
+
+ //grey lines
+ imageLine($image, 30, $yaxis, 30 + $width_line * ($nb - 1), $yaxis, hexdec($this->grey));
+
+ //value labels
+ $val = round($i * $max / 12);
+ $box = @imageTTFBbox($this->fontsize, $this->fontangle, $this->font, $val);
+ $textwidth = abs($box[4] - $box[0]);
+ imagettftext(
+ $image,
+ $this->fontsize,
+ $this->fontangle,
+ 28 - $textwidth,
+ $yaxis + 5,
+ hexdec($this->darkgrey),
+ $this->font,
+ $val
+ );
+ }
+
+ //draw y-axis grey step line
+ for ($i = 0; $i < $nb; $i++) {
+ $xaxis = 30 + $width_line * $i;
+ imageLine($image, $xaxis, 50, $xaxis, $height - 25, hexdec($this->grey));
+ }
+
+ //draw y-axis
+ imageLine($image, 30, 50, 30, $height - 25, hexdec($this->black));
+
+ //draw x-axis
+ imageline($image, 30, $height - 30, $width - 60, $height - 30, hexdec($this->black));
+
+ //create border on export
+ if ($export) {
+ imagerectangle($image, 0, 0, $width - 1, $height - 1, hexdec($this->black));
+ }
+
+ //add title on export
+ if ($export) {
+ imagettftext(
+ $image,
+ $this->fontsize + 1,
+ $this->fontangle,
+ 10,
+ 20,
+ hexdec($this->black),
+ $this->font,
+ $title
+ );
+ }
+
+ //on png graph, no way to draw curved polygons, force area reports to be linear
+ if ($area) {
+ $spline = false;
+ }
+
+ //parse datas
+ $index = 0;
+ $old_data = 0;
+ $aCoords = [];
+ foreach ($datas as $label => $data) {
+ //if first index, continue
+ if ($index == 0) {
+ $old_data = $data;
+ $index++;
+ continue;
+ }
+
+ // determine coords
+ $x1 = $index * $width_line - $width_line + 30;
+ $y1 = $height - 30 - $old_data * ($height - 85) / $max;
+ $x2 = $x1 + $width_line;
+ $y2 = $height - 30 - $data * ($height - 85) / $max;
+ $aCoords[$x1] = $y1;
+
+ //in case of area chart fill under point space
+ if ($area > 0) {
+ $points = [
+ $x1, $y1,
+ $x2, $y2,
+ $x2, $height - 30,
+ $x1, $height - 30
+ ];
+ imagefilledpolygon($image, $points, 4, hexdec($alphapalette[0]));
+ }
+
+ //trace lines between points (if linear)
+ if (!$spline) {
+ $this->imageSmoothAlphaLineLarge($image, $x1, $y1, $x2, $y2, $palette[0]);
+ }
+
+ $old_data = $data;
+ $index++;
+ }
+
+ //if curved spline activated, draw cubic spline for the current line
+ if ($spline) {
+ $aCoords[$x2] = $y2;
+ $this->imageCubicSmoothLine($image, $palette[0], $aCoords);
+ }
+
+ //draw labels and dots
+ $index = 0;
+ $old_label = "";
+ foreach ($datas as $label => $data) {
+ //if first index, continue
+ if ($index == 0) {
+ $old_data = $data;
+ $old_label = $label;
+ $index++;
+ continue;
+ }
+
+ // determine coords
+ $x1 = $index * $width_line - $width_line + 30;
+ $y1 = $height - 30 - $old_data * ($height - 85) / $max;
+ $x2 = $x1 + $width_line;
+ $y2 = $height - 30 - $data * ($height - 85) / $max;
+
+ //trace dots
+ $color_rbg = self::colorHexToRGB($darkerpalette[0]);
+ imageSmoothArc($image, $x1 - 1, $y1 - 1, 8, 8, $color_rbg, 0, 2 * M_PI);
+ imageSmoothArc($image, $x1 - 1, $y1 - 1, 4, 4, [255,255,255,0], 0, 2 * M_PI);
+
+ //display values label
+ if ($show_label == "always" || $show_label == "hover") {
+ imagettftext(
+ $image,
+ $this->fontsize - 1,
+ $this->fontangle,
+ ($index == 1 ? $x1 : $x1 - 6 ),
+ $y1 - 5,
+ hexdec($darkerpalette[0]),
+ $this->font,
+ $old_data
+ );
+ }
+
+ //display y ticks and labels
+ if ($step != 0 && ($index / $step) == round($index / $step)) {
+ imageline($image, $x1, $height - 30, $x1, $height - 27, hexdec($darkerpalette[0]));
+
+ imagettftext(
+ $image,
+ $this->fontsize,
+ $this->fontangle,
+ $x1 - 10,
+ $height - 10,
+ hexdec($this->black),
+ $this->font,
+ $old_label
+ );
+ }
+
+ $old_data = $data;
+ $old_label = $label;
+ $index++;
+ }
+
+ //display last value, dot and axis label
+ if (isset($x2)) {
+ imagettftext(
+ $image,
+ $this->fontsize - 1,
+ $this->fontangle,
+ $x2 - 6,
+ $y2 - 5,
+ hexdec($darkerpalette[0]),
+ $this->font,
+ $data
+ );
+ $color_rbg = self::colorHexToRGB($darkerpalette[0]);
+ imageSmoothArc($image, $x2 - 1, $y2 - 1, 8, 8, $color_rbg, 0, 2 * M_PI);
+ imageSmoothArc($image, $x2 - 1, $y2 - 1, 4, 4, [255,255,255,0], 0, 2 * M_PI);
+ imagettftext(
+ $image,
+ $this->fontsize,
+ $this->fontangle,
+ $x2 - 10,
+ $height - 10,
+ hexdec($this->black),
+ $this->font,
+ $label
+ );
+ imageline($image, $x2, $height - 30, $x2, $height - 27, hexdec($darkerpalette[0]));
+ }
+ }
+ //generate image
+ $params = ["image" => $image,
+ "export" => $export,
+ "f_name" => $opt['f_name'],
+ "class" => $opt['class'],
+ "title" => $title,
+ "randname" => $randname,
+ "raw_datas" => $raw_datas,
+ "withdata" => $opt['withdata']
+ ];
+ $contents = $this->generateImage($params);
+ if ($show_graph) {
+ $this->showImage($contents, $export);
+ }
+ $opt['randname'] = $randname;
+ $options = ["opt" => $opt,
+ "export" => $export,
+ "datas" => $datas,
+ "unit" => $unit
+ ];
+ PluginMreportingCommon::endGraph($options, $dashboard);
+ }
/**
@@ -2018,303 +2237,356 @@ function showArea($params, $dashboard = false, $width = false) {
* @param $show_label : behavior of the graph labels,
* values : 'hover', 'never', 'always' (optionnal)
* @param $export : keep only svg to export (optionnal)
- * @return nothing
+ * @return void
*/
- function showGArea($params, $dashboard = false, $width = false) {
- if ($width !== false) {
- $this->width = $width;
- }
-
- $criterias = PluginMreportingCommon::initGraphParams($params);
-
- foreach ($criterias as $key => $val) {
- $$key=$val;
- }
-
- //$rand = $opt['rand'];
-
- $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']);
-
- foreach ($configs as $k => $v) {
- $$k=$v;
- }
-
- if (self::DEBUG_GRAPH && isset($raw_datas)) {
- Toolbox::logdebug($raw_datas);
- }
-
- if (isset($raw_datas['datas'])) {
- $datas = $raw_datas['datas'];
- } else {
- $datas = [];
- }
-
- $options = ["title" => $title,
- "desc" => $desc,
- "randname" => $randname,
- "export" => $export,
- "delay" => $delay,
- "short_classname" => $opt["short_classname"],
- "showHeader" => $dashboard];
-
- $this->initGraph($options);
-
- if (count($datas) <= 0) {
-
- if ($export!="odtall") {
- echo __("No data for this date range !", 'mreporting');
- $end['opt']["export"] = false;
- $end['opt']["randname"] = false;
- $end['opt']["f_name"] = $opt['f_name'];
- $end['opt']["class"] = $opt['class'];
- PluginMreportingCommon::endGraph($end);
- }
- return false;
- }
-
- $labels2 = $raw_datas['labels2'];
-
- if (empty($unit) && !empty($raw_datas['unit'])) {
- $unit = $raw_datas['unit'];
- }
-
- $datas = PluginMreportingCommon::compileDatasForUnit($datas, $unit);
- $raw_datas['datas'] = $datas;
-
- $values = array_values($datas);
- $labels = array_keys($datas);
-
- $max = 1;
- foreach ($values as $line) {
- foreach ($line as $label2 => $value) {
- if ($value > $max) {
- $max = $value;
- }
- }
- }
- if ($max == 1 && $unit == '%') {
- $max = 100;
- }
-
- $nb = count($labels2);
- $width = $this->width;
-
- $nb_bar = count($labels2);
- $nb_labels2 = count($datas);
-
- $width_line = ($this->width - 45) / $nb;
- $index1 = 0;
- $index3 = 1;
- $step = ceil($nb / 21);
- $height = 450;
- if ($dashboard) {
- $height = 350;
- }
- $y_labels_width = .1 * $this->width;
- $x_labels_height = 60;
- $x_bar = 30;
- $legend_height = $nb_labels2 * 15 + 20;
-
- //create image
- $image = imagecreatetruecolor ($width, $height);
-
- if ($show_graph) {
- //colors
- $palette = self::getPalette($nb_bar);
- $alphapalette = self::getPalette($nb_bar, "50");
- $darkerpalette = self::getDarkerPalette($nb_bar);
-
- //background
- $bg_color = hexdec($this->white);
- imagefilledrectangle($image, 0, 0, $width - 1, $height, $bg_color);
-
- //draw x-axis grey step line and value ticks
- $xstep = round(($height - $legend_height - $x_labels_height) / 12);
- for ($i = 0; $i< 12; $i++) {
- $yaxis = $height - $x_labels_height - $xstep * $i;
-
- //horizontal grey lines
- imageLine($image, $x_bar, $yaxis, $x_bar+$width_line*($nb-1), $yaxis, hexdec($this->grey));
-
- //value ticks
- if ($i * $max / 12 < 10) {
- $val = round($i * $max / 12, 1);
- } else {
- $val = round($i * $max / 12);
+ public function showGArea($params, $dashboard = false, $width = false)
+ {
+ if ($width !== false) {
+ $this->width = $width;
+ }
+
+ $criterias = PluginMreportingCommon::initGraphParams($params);
+
+ foreach ($criterias as $key => $val) {
+ $$key = $val;
+ }
+
+ //$rand = $opt['rand'];
+
+ $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']);
+
+ foreach ($configs as $k => $v) {
+ $$k = $v;
+ }
+
+ if (self::DEBUG_GRAPH && isset($raw_datas)) {
+ Toolbox::logdebug($raw_datas);
+ }
+
+ if (isset($raw_datas['datas'])) {
+ $datas = $raw_datas['datas'];
+ } else {
+ $datas = [];
+ }
+
+ $options = ["title" => $title,
+ "desc" => $desc,
+ "randname" => $randname,
+ "export" => $export,
+ "delay" => $delay,
+ "short_classname" => $opt["short_classname"],
+ "showHeader" => $dashboard
+ ];
+
+ $this->initGraph($options);
+
+ if (count($datas) <= 0) {
+ if ($export != "odtall") {
+ echo __("No data for this date range !", 'mreporting');
+ $end['opt']["export"] = false;
+ $end['opt']["randname"] = false;
+ $end['opt']["f_name"] = $opt['f_name'];
+ $end['opt']["class"] = $opt['class'];
+ PluginMreportingCommon::endGraph($end);
}
+ return false;
+ }
- $box = @imageTTFBbox($this->fontsize-1, $this->fontangle, $this->font, $val);
- $textwidth = abs($box[4] - $box[0]);
-
- imagettftext($image, $this->fontsize-1, $this->fontangle,
- 25-$textwidth, $yaxis+5, hexdec($this->darkgrey), $this->font, $val);
- }
-
- //draw y-axis vertical grey step line
- for ($i = 0; $i< $nb; $i++) {
- $xaxis = $x_bar + $width_line * $i;
- imageLine($image, $xaxis, $height-$x_labels_height, $xaxis, $legend_height, hexdec($this->grey));
- }
-
- //draw y-axis
- imageLine($image, $x_bar, $height - $x_labels_height, $x_bar, $legend_height, hexdec($this->black));
+ $labels2 = $raw_datas['labels2'];
- //draw y-axis
- imageLine($image, $x_bar, $height - $x_labels_height, $width - 50, $height - $x_labels_height, hexdec($this->black));
-
- //create border on export
- if ($export) {
- imagerectangle($image, 0, 0, $width - 1, $height - 1, hexdec($this->black));
- }
-
- //on png graph, no way to draw curved polygons, force area reports to be linear
- if ($area) {
- $spline = false;
- }
-
- //add title on export
- if ($export) {
- imagettftext($image, $this->fontsize+1, $this->fontangle, 10, 20,
- hexdec($this->black), $this->font, $title);
- }
-
- //parse datas
- foreach ($datas as $label => $data) {
-
- $aCoords = [];
- $index2 = 0;
- $old_data = 0;
- //parse line
- foreach ($data as $subdata) {
- //if first index, continue
- if ($index2 == 0) {
- $old_data = $subdata;
- $index2++;
- continue;
- }
+ if (empty($unit) && !empty($raw_datas['unit'])) {
+ $unit = $raw_datas['unit'];
+ }
- // determine coords
- $x1 = $index2 * $width_line - $width_line + $x_bar;
- $y1 = $height - $x_labels_height - $old_data * ($height - $legend_height - $x_labels_height) / $max;
- $x2 = $x1 + $width_line;
- $y2 = $height - $x_labels_height - $subdata * ($height - $legend_height - $x_labels_height) / $max;
+ $datas = PluginMreportingCommon::compileDatasForUnit($datas, $unit);
+ $raw_datas['datas'] = $datas;
- //in case of area chart fill under point space
- if ($area > 0) {
- $points = [
- $x1, $y1,
- $x2, $y2,
- $x2, $height - $x_labels_height,
- $x1, $height - $x_labels_height
- ];
- imagefilledpolygon($image, $points, 4, hexdec($alphapalette[$index1]));
- }
+ $values = array_values($datas);
+ $labels = array_keys($datas);
- //trace lines between points (if linear)
- if (!$spline) {
- $this->imageSmoothAlphaLineLarge($image, $x1, $y1, $x2, $y2, $palette[$index1]);
- }
- $aCoords[$x1]=$y1;
+ $max = 1;
+ foreach ($values as $line) {
+ foreach ($line as $label2 => $value) {
+ if ($value > $max) {
+ $max = $value;
+ }
+ }
+ }
+ if ($max == 1 && $unit == '%') {
+ $max = 100;
+ }
+
+ $nb = count($labels2);
+ $width = $this->width;
+
+ $nb_bar = count($labels2);
+ $nb_labels2 = count($datas);
+
+ $width_line = ($this->width - 45) / $nb;
+ $index1 = 0;
+ $index3 = 1;
+ $step = ceil($nb / 21);
+ $height = 450;
+ if ($dashboard) {
+ $height = 350;
+ }
+ $y_labels_width = .1 * $this->width;
+ $x_labels_height = 60;
+ $x_bar = 30;
+ $legend_height = $nb_labels2 * 15 + 20;
+
+ //create image
+ $image = imagecreatetruecolor($width, $height);
+
+ if ($show_graph) {
+ //colors
+ $palette = self::getPalette($nb_bar);
+ $alphapalette = self::getPalette($nb_bar, "50");
+ $darkerpalette = self::getDarkerPalette($nb_bar);
+
+ //background
+ $bg_color = hexdec($this->white);
+ imagefilledrectangle($image, 0, 0, $width - 1, $height, $bg_color);
+
+ //draw x-axis grey step line and value ticks
+ $xstep = round(($height - $legend_height - $x_labels_height) / 12);
+ for ($i = 0; $i < 12; $i++) {
+ $yaxis = $height - $x_labels_height - $xstep * $i;
+
+ //horizontal grey lines
+ imageLine($image, $x_bar, $yaxis, $x_bar + $width_line * ($nb - 1), $yaxis, hexdec($this->grey));
+
+ //value ticks
+ if ($i * $max / 12 < 10) {
+ $val = round($i * $max / 12, 1);
+ } else {
+ $val = round($i * $max / 12);
+ }
+
+ $box = @imageTTFBbox($this->fontsize - 1, $this->fontangle, $this->font, $val);
+ $textwidth = abs($box[4] - $box[0]);
+
+ imagettftext(
+ $image,
+ $this->fontsize - 1,
+ $this->fontangle,
+ 25 - $textwidth,
+ $yaxis + 5,
+ hexdec($this->darkgrey),
+ $this->font,
+ $val
+ );
+ }
- //trace dots
- $color_rbg = self::colorHexToRGB($darkerpalette[$index1]);
- imageSmoothArc($image, $x1-1, $y1-1, 7, 7, $color_rbg, 0, 2 * M_PI);
- imageSmoothArc($image, $x1-1, $y1-1, 4, 4, [255,255,255,0], 0, 2 * M_PI);
+ //draw y-axis vertical grey step line
+ for ($i = 0; $i < $nb; $i++) {
+ $xaxis = $x_bar + $width_line * $i;
+ imageLine($image, $xaxis, $height - $x_labels_height, $xaxis, $legend_height, hexdec($this->grey));
+ }
- //display values label
- if ($show_label == "always" || $show_label == "hover") {
- imagettftext($image, $this->fontsize-2, $this->fontangle,
- ($index2 == 1 ? $x1 : $x1 - 6 ), $y1 - 5,
- hexdec($darkerpalette[$index1]), $this->font, $old_data);
- }
+ //draw y-axis
+ imageLine($image, $x_bar, $height - $x_labels_height, $x_bar, $legend_height, hexdec($this->black));
- //show x-axis ticks
- if ($step!=0 && ($index3 / $step) == round($index3 / $step)) {
- imageline($image, $x1, $height-$x_labels_height, $x1,
- $height-$x_labels_height+3, hexdec($darkerpalette[$index1]));
- }
+ //draw y-axis
+ imageLine($image, $x_bar, $height - $x_labels_height, $width - 50, $height - $x_labels_height, hexdec($this->black));
- $old_data = $subdata;
- $index2++;
- $index3++;
+ //create border on export
+ if ($export) {
+ imagerectangle($image, 0, 0, $width - 1, $height - 1, hexdec($this->black));
}
- //if curved spline activated, draw cubic spline for the current line
- if ($spline) {
- $aCoords[$x2] = $y2;
- $this->imageCubicSmoothLine($image, $palette[$index1], $aCoords);
+ //on png graph, no way to draw curved polygons, force area reports to be linear
+ if ($area) {
+ $spline = false;
}
- // display last value
- if (isset($x2)) {
- //trace dots
- $color_rbg = self::colorHexToRGB($darkerpalette[$index1]);
- imageSmoothArc($image, $x2-1, $y2-1, 7, 7, $color_rbg, 0, 2 * M_PI);
- imageSmoothArc($image, $x2-1, $y2-1, 4, 4, [255,255,255,0], 0, 2 * M_PI);
+ //add title on export
+ if ($export) {
+ imagettftext(
+ $image,
+ $this->fontsize + 1,
+ $this->fontangle,
+ 10,
+ 20,
+ hexdec($this->black),
+ $this->font,
+ $title
+ );
+ }
- //display value label
- if ($show_label == "always" || $show_label == "hover") {
- imagettftext($image, $this->fontsize - 2, $this->fontangle,
- ($index2 == 1 ? $x2 : $x2 - 6), $y2 - 5,
- hexdec($darkerpalette[$index1]), $this->font, $old_data);
- }
+ //parse datas
+ foreach ($datas as $label => $data) {
+ $aCoords = [];
+ $index2 = 0;
+ $old_data = 0;
+ //parse line
+ foreach ($data as $subdata) {
+ //if first index, continue
+ if ($index2 == 0) {
+ $old_data = $subdata;
+ $index2++;
+ continue;
+ }
+
+ // determine coords
+ $x1 = $index2 * $width_line - $width_line + $x_bar;
+ $y1 = $height - $x_labels_height - $old_data * ($height - $legend_height - $x_labels_height) / $max;
+ $x2 = $x1 + $width_line;
+ $y2 = $height - $x_labels_height - $subdata * ($height - $legend_height - $x_labels_height) / $max;
+
+ //in case of area chart fill under point space
+ if ($area > 0) {
+ $points = [
+ $x1, $y1,
+ $x2, $y2,
+ $x2, $height - $x_labels_height,
+ $x1, $height - $x_labels_height
+ ];
+ imagefilledpolygon($image, $points, 4, hexdec($alphapalette[$index1]));
+ }
+
+ //trace lines between points (if linear)
+ if (!$spline) {
+ $this->imageSmoothAlphaLineLarge($image, $x1, $y1, $x2, $y2, $palette[$index1]);
+ }
+ $aCoords[$x1] = $y1;
+
+ //trace dots
+ $color_rbg = self::colorHexToRGB($darkerpalette[$index1]);
+ imageSmoothArc($image, $x1 - 1, $y1 - 1, 7, 7, $color_rbg, 0, 2 * M_PI);
+ imageSmoothArc($image, $x1 - 1, $y1 - 1, 4, 4, [255,255,255,0], 0, 2 * M_PI);
+
+ //display values label
+ if ($show_label == "always" || $show_label == "hover") {
+ imagettftext(
+ $image,
+ $this->fontsize - 2,
+ $this->fontangle,
+ ($index2 == 1 ? $x1 : $x1 - 6 ),
+ $y1 - 5,
+ hexdec($darkerpalette[$index1]),
+ $this->font,
+ $old_data
+ );
+ }
+
+ //show x-axis ticks
+ if ($step != 0 && ($index3 / $step) == round($index3 / $step)) {
+ imageline(
+ $image,
+ $x1,
+ $height - $x_labels_height,
+ $x1,
+ $height - $x_labels_height + 3,
+ hexdec($darkerpalette[$index1])
+ );
+ }
+
+ $old_data = $subdata;
+ $index2++;
+ $index3++;
+ }
+
+ //if curved spline activated, draw cubic spline for the current line
+ if ($spline) {
+ $aCoords[$x2] = $y2;
+ $this->imageCubicSmoothLine($image, $palette[$index1], $aCoords);
+ }
+
+ // display last value
+ if (isset($x2)) {
+ //trace dots
+ $color_rbg = self::colorHexToRGB($darkerpalette[$index1]);
+ imageSmoothArc($image, $x2 - 1, $y2 - 1, 7, 7, $color_rbg, 0, 2 * M_PI);
+ imageSmoothArc($image, $x2 - 1, $y2 - 1, 4, 4, [255,255,255,0], 0, 2 * M_PI);
+
+ //display value label
+ if ($show_label == "always" || $show_label == "hover") {
+ imagettftext(
+ $image,
+ $this->fontsize - 2,
+ $this->fontangle,
+ ($index2 == 1 ? $x2 : $x2 - 6),
+ $y2 - 5,
+ hexdec($darkerpalette[$index1]),
+ $this->font,
+ $old_data
+ );
+ }
+ }
+
+ $index1++;
}
- $index1++;
- }
+ //display labels2
+ $index = 0;
+ foreach ($labels2 as $label) {
+ $x = $x_bar + $index * $width_line - 2;
- //display labels2
- $index = 0;
- foreach ($labels2 as $label) {
- $x = $x_bar + $index * $width_line - 2;
+ if ($step != 0 && ($index / $step) == round($index / $step)) {
+ imagettftext(
+ $image,
+ $this->fontsize - 1,
+ -45,
+ $x,
+ $height - $x_labels_height + 11,
+ hexdec($this->black),
+ $this->font,
+ $label
+ );
+ }
- if ($step!=0 && ($index / $step) == round($index / $step)) {
- imagettftext($image, $this->fontsize-1, -45, $x, $height - $x_labels_height + 11,
- hexdec($this->black), $this->font, $label);
+ $index++;
}
- $index++;
- }
-
- //legend (align left)
- $index = 0;
- foreach ($labels as $label) {
- //legend label
- $box = @imageTTFBbox($this->fontsize, $this->fontangle, $this->font, $label);
- $textwidth = abs($box[4] - $box[0]);
- $textheight = abs($box[5] - $box[1]);
- imagettftext($image, $this->fontsize-1, $this->fontangle,
- 20, 15 + $index * 14, hexdec($this->black), $this->font, $label);
-
- //legend circle
- $color_rbg = self::colorHexToRGB($palette[$index]);
- imageSmoothArc($image, 10, 10 + $index * 14, 7, 7, $color_rbg, 0, 2 * M_PI);
-
- $index++;
- }
- }
- //generate image
- $params = ["image" => $image,
- "export" => $export,
- "f_name" => $opt['f_name'],
- "class" => $opt['class'],
- "title" => $title,
- "randname" => $randname,
- "raw_datas" => $raw_datas,
- "withdata" => $opt['withdata']];
- $contents = $this->generateImage($params);
-
- if ($show_graph) {
- $this->showImage($contents, $export);
- }
- $opt['randname'] = $randname;
- $options = ["opt" => $opt,
- "export" => $export,
- "datas" => $datas,
- "labels2" => $labels2,
- "flip_data" => $flip_data,
- "unit" => $unit];
- PluginMreportingCommon::endGraph($options, $dashboard);
- }// End Garea
-
-}// End Class
+ //legend (align left)
+ $index = 0;
+ foreach ($labels as $label) {
+ //legend label
+ $box = @imageTTFBbox($this->fontsize, $this->fontangle, $this->font, $label);
+ $textwidth = abs($box[4] - $box[0]);
+ $textheight = abs($box[5] - $box[1]);
+ imagettftext(
+ $image,
+ $this->fontsize - 1,
+ $this->fontangle,
+ 20,
+ 15 + $index * 14,
+ hexdec($this->black),
+ $this->font,
+ $label
+ );
+
+ //legend circle
+ $color_rbg = self::colorHexToRGB($palette[$index]);
+ imageSmoothArc($image, 10, 10 + $index * 14, 7, 7, $color_rbg, 0, 2 * M_PI);
+
+ $index++;
+ }
+ }
+ //generate image
+ $params = ["image" => $image,
+ "export" => $export,
+ "f_name" => $opt['f_name'],
+ "class" => $opt['class'],
+ "title" => $title,
+ "randname" => $randname,
+ "raw_datas" => $raw_datas,
+ "withdata" => $opt['withdata']
+ ];
+ $contents = $this->generateImage($params);
+
+ if ($show_graph) {
+ $this->showImage($contents, $export);
+ }
+ $opt['randname'] = $randname;
+ $options = ["opt" => $opt,
+ "export" => $export,
+ "datas" => $datas,
+ "labels2" => $labels2,
+ "flip_data" => $flip_data,
+ "unit" => $unit
+ ];
+ PluginMreportingCommon::endGraph($options, $dashboard);
+ }
+}
diff --git a/inc/helpdesk.class.php b/inc/helpdesk.class.php
index 4b03d327..83980844 100644
--- a/inc/helpdesk.class.php
+++ b/inc/helpdesk.class.php
@@ -1,133 +1,141 @@
.
- --------------------------------------------------------------------------
+/**
+ * -------------------------------------------------------------------------
+ * Mreporting plugin for GLPI
+ * -------------------------------------------------------------------------
+ *
+ * LICENSE
+ *
+ * This file is part of Mreporting.
+ *
+ * Mreporting is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mreporting is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mreporting. If not, see .
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2003-2023 by Mreporting plugin team.
+ * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
+ * @link https://github.com/pluginsGLPI/mreporting
+ * -------------------------------------------------------------------------
*/
-class PluginMreportingHelpdesk Extends PluginMreportingBaseclass {
+class PluginMreportingHelpdesk extends PluginMreportingBaseclass
+{
+ public function reportPieTicketNumberByEntity($config = [])
+ {
+ $_SESSION['mreporting_selector']['reportPieTicketNumberByEntity'] = ['dateinterval'];
- function reportPieTicketNumberByEntity($config = []) {
- $_SESSION['mreporting_selector']['reportPieTicketNumberByEntity'] = ['dateinterval'];
+ return $this->reportHbarTicketNumberByEntity($config);
+ }
- return $this->reportHbarTicketNumberByEntity($config);
- }
+ public function reportHbarTicketNumberByEntity($config = [])
+ {
+ global $DB;
- function reportHbarTicketNumberByEntity($config = []) {
- global $DB;
+ $_SESSION['mreporting_selector']['reportHbarTicketNumberByEntity'] = ['dateinterval',
+ 'limit'
+ ];
- $_SESSION['mreporting_selector']['reportHbarTicketNumberByEntity'] = ['dateinterval',
- 'limit'];
+ //Init delay value
+ $this->sql_date = PluginMreportingCommon::getSQLDate(
+ "`glpi_tickets`.`date`",
+ $config['delay'],
+ $config['randname']
+ );
- //Init delay value
- $this->sql_date = PluginMreportingCommon::getSQLDate("`glpi_tickets`.`date`",
- $config['delay'],
- $config['randname']);
+ $datas = [];
- $datas = [];
-
- $query = "SELECT COUNT(glpi_tickets.id) as count,
+ $query = "SELECT COUNT(glpi_tickets.id) as count,
glpi_entities.name as name
FROM glpi_tickets
LEFT JOIN glpi_entities
ON (glpi_tickets.entities_id = glpi_entities.id)
WHERE {$this->sql_date} ";
- if (Session::isMultiEntitiesMode()) {
- $query.= "AND glpi_entities.id IN (".$this->where_entities.") ";
- }
- $query.= "AND glpi_tickets.is_deleted = '0'
+ if (Session::isMultiEntitiesMode()) {
+ $query .= "AND glpi_entities.id IN (" . $this->where_entities . ") ";
+ }
+ $query .= "AND glpi_tickets.is_deleted = '0'
GROUP BY glpi_entities.name
ORDER BY count DESC
LIMIT 0, ";
- $query .= (isset($_REQUEST['glpilist_limit'])) ? $_REQUEST['glpilist_limit'] : 20;
-
- $result = $DB->query($query);
+ $query .= (isset($_REQUEST['glpilist_limit'])) ? $_REQUEST['glpilist_limit'] : 20;
- while ($ticket = $DB->fetchAssoc($result)) {
- if (empty($ticket['name'])) {
- $label = __("Root entity");
- } else {
- $label = $ticket['name'];
- }
- $datas['datas'][$label] = $ticket['count'];
- }
+ $result = $DB->query($query);
- return $datas;
+ while ($ticket = $DB->fetchAssoc($result)) {
+ if (empty($ticket['name'])) {
+ $label = __("Root entity");
+ } else {
+ $label = $ticket['name'];
+ }
+ $datas['datas'][$label] = $ticket['count'];
+ }
- }
+ return $datas;
+ }
- function reportHgbarTicketNumberByCatAndEntity($config = []) {
- global $DB;
+ public function reportHgbarTicketNumberByCatAndEntity($config = [])
+ {
+ global $DB;
- $_SESSION['mreporting_selector']['reportHgbarTicketNumberByCatAndEntity']
+ $_SESSION['mreporting_selector']['reportHgbarTicketNumberByCatAndEntity']
= ['dateinterval'];
- $datas = [];
- $tmp_datas = [];
+ $datas = [];
+ $tmp_datas = [];
- //Init delay value
- $this->sql_date = PluginMreportingCommon::getSQLDate("glpi_tickets.date",
- $config['delay'],
- $config['randname']);
+ //Init delay value
+ $this->sql_date = PluginMreportingCommon::getSQLDate(
+ "glpi_tickets.date",
+ $config['delay'],
+ $config['randname']
+ );
- //get categories used in this period
- $query_cat = "SELECT DISTINCT(glpi_tickets.itilcategories_id) as itilcategories_id,
+ //get categories used in this period
+ $query_cat = "SELECT DISTINCT(glpi_tickets.itilcategories_id) as itilcategories_id,
glpi_itilcategories.completename as category
FROM glpi_tickets
LEFT JOIN glpi_itilcategories
ON glpi_tickets.itilcategories_id = glpi_itilcategories.id
WHERE {$this->sql_date} ";
- if (Session::isMultiEntitiesMode()) {
- $query_cat.= "AND glpi_tickets.entities_id IN (".$this->where_entities.") ";
- }
+ if (Session::isMultiEntitiesMode()) {
+ $query_cat .= "AND glpi_tickets.entities_id IN (" . $this->where_entities . ") ";
+ }
- $query_cat.= "AND glpi_tickets.is_deleted = '0'
+ $query_cat .= "AND glpi_tickets.is_deleted = '0'
ORDER BY glpi_itilcategories.id ASC";
- $res_cat = $DB->query($query_cat);
+ $res_cat = $DB->query($query_cat);
- $categories = [];
- while ($data = $DB->fetchAssoc($res_cat)) {
- if (empty($data['category'])) {
- $data['category'] = __("None");
- }
- $categories[$data['category']] = $data['itilcategories_id'];
- }
+ $categories = [];
+ while ($data = $DB->fetchAssoc($res_cat)) {
+ if (empty($data['category'])) {
+ $data['category'] = __("None");
+ }
+ $categories[$data['category']] = $data['itilcategories_id'];
+ }
- $labels2 = array_keys($categories);
+ $labels2 = array_keys($categories);
- $tmp_cat = [];
- foreach (array_values($categories) as $id) {
- $tmp_cat[] = "cat_$id";
- }
- $cat_str = "'".implode("', '", array_values($categories))."'";
+ $tmp_cat = [];
+ foreach (array_values($categories) as $id) {
+ $tmp_cat[] = "cat_$id";
+ }
+ $cat_str = "'" . implode("', '", array_values($categories)) . "'";
- //count ticket by entity and categories previously selected
- $query = "SELECT
+ //count ticket by entity and categories previously selected
+ $query = "SELECT
COUNT(glpi_tickets.id) as nb,
glpi_entities.name as entity,
glpi_tickets.itilcategories_id as cat_id
@@ -136,138 +144,148 @@ function reportHgbarTicketNumberByCatAndEntity($config = []) {
ON glpi_tickets.entities_id = glpi_entities.id
WHERE glpi_tickets.itilcategories_id IN ($cat_str) ";
- if (Session::isMultiEntitiesMode()) {
- $query.= "AND glpi_tickets.entities_id IN (".$this->where_entities.")";
- }
+ if (Session::isMultiEntitiesMode()) {
+ $query .= "AND glpi_tickets.entities_id IN (" . $this->where_entities . ")";
+ }
- $query.= "AND ".$this->sql_date."
+ $query .= "AND " . $this->sql_date . "
AND glpi_tickets.is_deleted = '0'
GROUP BY glpi_entities.name, glpi_tickets.itilcategories_id
ORDER BY glpi_entities.name ASC, glpi_tickets.itilcategories_id ASC";
- $res = $DB->query($query);
- while ($data = $DB->fetchAssoc($res)) {
- if (empty($data['entity'])) {
- $data['entity'] = __("Root entity");
- }
- $tmp_datas[$data['entity']]["cat_".$data['cat_id']] = $data['nb'];
- }
-
- //merge missing datas (0 ticket for a category)
- foreach ($tmp_datas as &$data) {
- $data = $data + array_fill_keys($tmp_cat, 0);
- }
-
- //replace cat_id by labels2
- foreach ($tmp_datas as $entity => &$subdata) {
- $tmp = [];
- $i = 0;
- foreach ($subdata as $value) {
- $cat_label = $labels2[$i];
- $tmp[$cat_label] = $value;
- $i++;
- }
- $subdata = $tmp;
- }
-
- $datas['datas'] = $tmp_datas;
-
- foreach ($categories as $key => $value) {
- $datas['labels2'][$key] = $key;
- }
-
- return $datas;
- }
-
- function reportPieTicketOpenedAndClosed($config = []) {
- global $DB;
-
- $_SESSION['mreporting_selector']['reportPieTicketOpenedAndClosed']
- = ['dateinterval'];
+ $res = $DB->query($query);
+ while ($data = $DB->fetchAssoc($res)) {
+ if (empty($data['entity'])) {
+ $data['entity'] = __("Root entity");
+ }
+ $tmp_datas[$data['entity']]["cat_" . $data['cat_id']] = $data['nb'];
+ }
+
+ //merge missing datas (0 ticket for a category)
+ foreach ($tmp_datas as &$data) {
+ $data = $data + array_fill_keys($tmp_cat, 0);
+ }
+
+ //replace cat_id by labels2
+ foreach ($tmp_datas as $entity => &$subdata) {
+ $tmp = [];
+ $i = 0;
+ foreach ($subdata as $value) {
+ $cat_label = $labels2[$i];
+ $tmp[$cat_label] = $value;
+ $i++;
+ }
+ $subdata = $tmp;
+ }
+
+ $datas['datas'] = $tmp_datas;
- //Init delay value
- $this->sql_date = PluginMreportingCommon::getSQLDate("glpi_tickets.date",
- $config['delay'],
- $config['randname']);
+ foreach ($categories as $key => $value) {
+ $datas['labels2'][$key] = $key;
+ }
+
+ return $datas;
+ }
+
+ public function reportPieTicketOpenedAndClosed($config = [])
+ {
+ global $DB;
+
+ $_SESSION['mreporting_selector']['reportPieTicketOpenedAndClosed']
+ = ['dateinterval'];
- $datas = [];
- foreach ($this->filters as $filter) {
+ //Init delay value
+ $this->sql_date = PluginMreportingCommon::getSQLDate(
+ "glpi_tickets.date",
+ $config['delay'],
+ $config['randname']
+ );
- $query = "SELECT COUNT(*)
+ $datas = [];
+ foreach ($this->filters as $filter) {
+ $query = "SELECT COUNT(*)
FROM glpi_tickets
- WHERE ".$this->sql_date." ";
+ WHERE " . $this->sql_date . " ";
- if (Session::isMultiEntitiesMode()) {
- $query.= "AND glpi_tickets.entities_id IN (".$this->where_entities.")";
- }
+ if (Session::isMultiEntitiesMode()) {
+ $query .= "AND glpi_tickets.entities_id IN (" . $this->where_entities . ")";
+ }
- $query.= "AND glpi_tickets.is_deleted = '0'
- AND glpi_tickets.status IN('".implode("', '", array_keys($filter['status']))."')";
- $result = $DB->query($query);
- $datas[$filter['label']] = $DB->result($result, 0, 0);
- }
+ $query .= "AND glpi_tickets.is_deleted = '0'
+ AND glpi_tickets.status IN('" . implode("', '", array_keys($filter['status'])) . "')";
+ $result = $DB->query($query);
+ $datas[$filter['label']] = $DB->result($result, 0, 0);
+ }
- return ['datas' => $datas];
- }
+ return ['datas' => $datas];
+ }
- function reportPieTicketOpenedbyStatus($config = []) {
- global $DB;
+ public function reportPieTicketOpenedbyStatus($config = [])
+ {
+ global $DB;
- $_SESSION['mreporting_selector']['reportPieTicketOpenedbyStatus']
+ $_SESSION['mreporting_selector']['reportPieTicketOpenedbyStatus']
= ['dateinterval', 'allstates'];
- //Init delay value
- $this->sql_date = PluginMreportingCommon::getSQLDate("glpi_tickets.date",
- $config['delay'],
- $config['randname']);
-
- // Get status to show
- if (isset($_POST['status_1'])) {
- foreach ($_POST as $key => $value) {
- if ((substr($key, 0, 7) == 'status_') && ($value == 1)) {
- $status_to_show[] = substr($key, 7, 1);
+ //Init delay value
+ $this->sql_date = PluginMreportingCommon::getSQLDate(
+ "glpi_tickets.date",
+ $config['delay'],
+ $config['randname']
+ );
+
+ // Get status to show
+ if (isset($_POST['status_1'])) {
+ foreach ($_POST as $key => $value) {
+ if ((substr($key, 0, 7) == 'status_') && ($value == 1)) {
+ $status_to_show[] = substr($key, 7, 1);
+ }
}
- }
- } else {
- $status_to_show = ['1', '2', '3', '4'];
- }
-
- $datas = [];
- $status = $this->filters['open']['status'] + $this->filters['close']['status'];
- foreach ($status as $key => $val) {
- if (in_array($key, $status_to_show)) {
- $query = "SELECT COUNT(glpi_tickets.id) as count
+ } else {
+ $status_to_show = ['1', '2', '3', '4'];
+ }
+
+ $datas = [];
+ $status = $this->filters['open']['status'] + $this->filters['close']['status'];
+ foreach ($status as $key => $val) {
+ if (in_array($key, $status_to_show)) {
+ $query = "SELECT COUNT(glpi_tickets.id) as count
FROM glpi_tickets
WHERE {$this->sql_date}
AND glpi_tickets.is_deleted = '0'
AND glpi_tickets.entities_id IN ({$this->where_entities})
AND glpi_tickets.status ='{$key}'";
- $result = $DB->query($query);
+ $result = $DB->query($query);
- while ($ticket = $DB->fetchAssoc($result)) {
- $datas['datas'][$val] = $ticket['count'];
+ while ($ticket = $DB->fetchAssoc($result)) {
+ $datas['datas'][$val] = $ticket['count'];
+ }
}
- }
- }
+ }
- return $datas;
- }
+ return $datas;
+ }
- function reportPieTopTenAuthor($config = []) {
- global $DB;
+ public function reportPieTopTenAuthor($config = [])
+ {
+ global $DB;
- $_SESSION['mreporting_selector']['reportPieTopTenAuthor']
+ $_SESSION['mreporting_selector']['reportPieTopTenAuthor']
= ['dateinterval'];
- //Init delay value
- $this->sql_date = PluginMreportingCommon::getSQLDate("glpi_tickets.date",
- $config['delay'],
- $config['randname']);
- $this->sql_closedate = PluginMreportingCommon::getSQLDate("glpi_tickets.closedate",
- $config['delay'],
- $config['randname']);
-
- $datas = [];
- $query = "SELECT COUNT(glpi_tickets.id) as count, glpi_tickets_users.users_id as users_id
+ //Init delay value
+ $this->sql_date = PluginMreportingCommon::getSQLDate(
+ "glpi_tickets.date",
+ $config['delay'],
+ $config['randname']
+ );
+ $this->sql_closedate = PluginMreportingCommon::getSQLDate(
+ "glpi_tickets.closedate",
+ $config['delay'],
+ $config['randname']
+ );
+
+ $datas = [];
+ $query = "SELECT COUNT(glpi_tickets.id) as count, glpi_tickets_users.users_id as users_id
FROM glpi_tickets
LEFT JOIN glpi_tickets_users
ON (glpi_tickets_users.tickets_id = glpi_tickets.id AND glpi_tickets_users.type =1)
@@ -278,46 +296,51 @@ function reportPieTopTenAuthor($config = []) {
GROUP BY glpi_tickets_users.users_id
ORDER BY count DESC
LIMIT 10";
- $result = $DB->query($query);
- while ($ticket = $DB->fetchAssoc($result)) {
- if ($ticket['users_id']==0) {
- $label = __("Undefined", 'mreporting');
- } else {
- $label = getUserName($ticket['users_id']);
- }
- $datas['datas'][$label] = $ticket['count'];
- }
-
- return $datas;
- }
-
-
- function reportHgbarOpenTicketNumberByCategoryAndByType($config = []) {
- $_SESSION['mreporting_selector']['reportHgbarOpenTicketNumberByCategoryAndByType']
+ $result = $DB->query($query);
+ while ($ticket = $DB->fetchAssoc($result)) {
+ if ($ticket['users_id'] == 0) {
+ $label = __("Undefined", 'mreporting');
+ } else {
+ $label = getUserName($ticket['users_id']);
+ }
+ $datas['datas'][$label] = $ticket['count'];
+ }
+
+ return $datas;
+ }
+
+
+ public function reportHgbarOpenTicketNumberByCategoryAndByType($config = [])
+ {
+ $_SESSION['mreporting_selector']['reportHgbarOpenTicketNumberByCategoryAndByType']
= ['dateinterval'];
- return $this->reportHgbarTicketNumberByCategoryAndByType($config, 'open');
- }
+ return $this->reportHgbarTicketNumberByCategoryAndByType($config, 'open');
+ }
- function reportHgbarCloseTicketNumberByCategoryAndByType($config = []) {
- $_SESSION['mreporting_selector']['reportHgbarCloseTicketNumberByCategoryAndByType']
+ public function reportHgbarCloseTicketNumberByCategoryAndByType($config = [])
+ {
+ $_SESSION['mreporting_selector']['reportHgbarCloseTicketNumberByCategoryAndByType']
= ['dateinterval'];
- return $this->reportHgbarTicketNumberByCategoryAndByType($config, 'close');
- }
+ return $this->reportHgbarTicketNumberByCategoryAndByType($config, 'close');
+ }
- private function reportHgbarTicketNumberByCategoryAndByType(array $config, $filter) {
- global $DB;
+ private function reportHgbarTicketNumberByCategoryAndByType(array $config, $filter)
+ {
+ global $DB;
- $_SESSION['mreporting_selector']['reportHgbarTicketNumberByCategoryAndByType']
+ $_SESSION['mreporting_selector']['reportHgbarTicketNumberByCategoryAndByType']
= ['dateinterval'];
- $datas = [];
+ $datas = [];
- //Init delay value
- $this->sql_date = PluginMreportingCommon::getSQLDate("glpi_tickets.date",
- $config['delay'],
- $config['randname']);
+ //Init delay value
+ $this->sql_date = PluginMreportingCommon::getSQLDate(
+ "glpi_tickets.date",
+ $config['delay'],
+ $config['randname']
+ );
- $query = "SELECT glpi_itilcategories.id as category_id,
+ $query = "SELECT glpi_itilcategories.id as category_id,
glpi_itilcategories.completename as category_name,
glpi_tickets.type as type,
COUNT(glpi_tickets.id) as count
@@ -326,62 +349,63 @@ private function reportHgbarTicketNumberByCategoryAndByType(array $config, $filt
ON glpi_itilcategories.id = glpi_tickets.itilcategories_id
WHERE {$this->sql_date}
AND glpi_tickets.entities_id IN ({$this->where_entities})
- AND glpi_tickets.status IN('".implode(
- "', '", array_keys($this->filters[$filter]['status']))."')
+ AND glpi_tickets.status IN('" . implode("', '", array_keys($this->filters[$filter]['status'])) . "')
AND glpi_tickets.is_deleted = '0'
GROUP BY glpi_itilcategories.id, glpi_tickets.type
ORDER BY glpi_itilcategories.name";
- $result = $DB->query($query);
-
- $datas['datas'] = [];
- while ($ticket = $DB->fetchAssoc($result)) {
- if (is_null($ticket['category_id'])) {
- $ticket['category_id'] = 0;
- $ticket['category_name'] = __("None");
- }
- if ($ticket['type']==0) {
- $type = __("Undefined", 'mreporting');
- } else {
- $type = Ticket::getTicketTypeName($ticket['type']);
- }
- $datas['labels2'][$type] = $type;
- $datas['datas'][$ticket['category_name']][$type] = $ticket['count'];
- }
-
- return $datas;
- }
-
- function reportHgbarTicketNumberByService($config = []) {
- global $DB;
-
- $_SESSION['mreporting_selector']['reportHgbarTicketNumberByService']
- = ['dateinterval'];
+ $result = $DB->query($query);
- $datas = [];
+ $datas['datas'] = [];
+ while ($ticket = $DB->fetchAssoc($result)) {
+ if (is_null($ticket['category_id'])) {
+ $ticket['category_id'] = 0;
+ $ticket['category_name'] = __("None");
+ }
+ if ($ticket['type'] == 0) {
+ $type = __("Undefined", 'mreporting');
+ } else {
+ $type = Ticket::getTicketTypeName($ticket['type']);
+ }
+ $datas['labels2'][$type] = $type;
+ $datas['datas'][$ticket['category_name']][$type] = $ticket['count'];
+ }
+
+ return $datas;
+ }
- //Init delay value
- $this->sql_date = PluginMreportingCommon::getSQLDate("glpi_tickets.date",
- $config['delay'],
- $config['randname']);
+ public function reportHgbarTicketNumberByService($config = [])
+ {
+ global $DB;
+
+ $_SESSION['mreporting_selector']['reportHgbarTicketNumberByService']
+ = ['dateinterval'];
- foreach ($this->filters as $class => $filter) {
+ $datas = [];
- $datas['labels2'][$filter['label']] = $filter['label'];
- $query = "SELECT COUNT(*)
+ //Init delay value
+ $this->sql_date = PluginMreportingCommon::getSQLDate(
+ "glpi_tickets.date",
+ $config['delay'],
+ $config['randname']
+ );
+
+ foreach ($this->filters as $class => $filter) {
+ $datas['labels2'][$filter['label']] = $filter['label'];
+ $query = "SELECT COUNT(*)
FROM glpi_tickets
WHERE id NOT IN (
SELECT tickets_id
FROM glpi_groups_tickets
WHERE glpi_groups_tickets.type = 1
)
- AND glpi_tickets.entities_id IN (".$this->where_entities.")
+ AND glpi_tickets.entities_id IN (" . $this->where_entities . ")
AND {$this->sql_date}
- AND status IN('".implode("', '", array_keys($filter['status']))."')";
- $result = $DB->query($query);
+ AND status IN('" . implode("', '", array_keys($filter['status'])) . "')";
+ $result = $DB->query($query);
- $datas['datas'][__("None")][$filter['label']] = $DB->result($result, 0, 0);
+ $datas['datas'][__("None")][$filter['label']] = $DB->result($result, 0, 0);
- $query = "SELECT glpi_groups.name as group_name,
+ $query = "SELECT glpi_groups.name as group_name,
COUNT(glpi_tickets.id) as count
FROM glpi_tickets, glpi_groups_tickets, glpi_groups
WHERE glpi_tickets.id = glpi_groups_tickets.tickets_id
@@ -390,109 +414,115 @@ function reportHgbarTicketNumberByService($config = []) {
AND glpi_groups_tickets.type = 1
AND glpi_tickets.is_deleted = '0'
AND {$this->sql_date}
- AND glpi_tickets.status IN('".implode("', '", array_keys($filter['status']))."')
+ AND glpi_tickets.status IN('" . implode("', '", array_keys($filter['status'])) . "')
GROUP BY glpi_groups.id
ORDER BY glpi_groups.name";
- $result = $DB->query($query);
-
- while ($ticket = $DB->fetchAssoc($result)) {
- $datas['datas'][$ticket['group_name']][$filter['label']] = $ticket['count'];
- }
+ $result = $DB->query($query);
- }
+ while ($ticket = $DB->fetchAssoc($result)) {
+ $datas['datas'][$ticket['group_name']][$filter['label']] = $ticket['count'];
+ }
+ }
- return $datas;
- }
+ return $datas;
+ }
- function reportHgbarOpenedTicketNumberByCategory($config = []) {
- global $DB;
+ public function reportHgbarOpenedTicketNumberByCategory($config = [])
+ {
+ global $DB;
- $_SESSION['mreporting_selector']['reportHgbarOpenedTicketNumberByCategory']
+ $_SESSION['mreporting_selector']['reportHgbarOpenedTicketNumberByCategory']
= ['dateinterval', 'allstates'];
- $datas = [];
-
- //Init delay value
- $this->sql_date = PluginMreportingCommon::getSQLDate("glpi_tickets.date",
- $config['delay'],
- $config['randname']);
-
- // Get status to show
- if (isset($_POST['status_1'])) {
- foreach ($_POST as $key => $value) {
- if (substr($key, 0, 7) == 'status_' && $value == 1) {
- $status_to_show[] = substr($key, 7, 1);
+ $datas = [];
+
+ //Init delay value
+ $this->sql_date = PluginMreportingCommon::getSQLDate(
+ "glpi_tickets.date",
+ $config['delay'],
+ $config['randname']
+ );
+
+ // Get status to show
+ if (isset($_POST['status_1'])) {
+ foreach ($_POST as $key => $value) {
+ if (substr($key, 0, 7) == 'status_' && $value == 1) {
+ $status_to_show[] = substr($key, 7, 1);
+ }
}
- }
- } else {
- $status_to_show = ['1', '2', '3', '4'];
- }
+ } else {
+ $status_to_show = ['1', '2', '3', '4'];
+ }
- $status = $this->filters['open']['status'] + $this->filters['close']['status'];
- $status_keys = array_keys($status);
+ $status = $this->filters['open']['status'] + $this->filters['close']['status'];
+ $status_keys = array_keys($status);
- $query = "SELECT glpi_tickets.status,
+ $query = "SELECT glpi_tickets.status,
glpi_itilcategories.completename as category_name,
COUNT(glpi_tickets.id) as count
FROM glpi_tickets
LEFT JOIN glpi_itilcategories
ON glpi_itilcategories.id = glpi_tickets.itilcategories_id
WHERE {$this->sql_date}
- AND glpi_tickets.entities_id IN (".$this->where_entities.")
- AND glpi_tickets.status IN('".implode("', '", $status_keys)."')
+ AND glpi_tickets.entities_id IN (" . $this->where_entities . ")
+ AND glpi_tickets.status IN('" . implode("', '", $status_keys) . "')
AND glpi_tickets.is_deleted = '0'
- AND status IN (".implode(',', $status_to_show).")
+ AND status IN (" . implode(',', $status_to_show) . ")
GROUP BY glpi_itilcategories.id, glpi_tickets.status
ORDER BY glpi_itilcategories.name";
- $result = $DB->query($query);
-
- while ($ticket = $DB->fetchAssoc($result)) {
- if (is_null($ticket['category_name'])) {
- $ticket['category_name'] = __("None");
- }
-
- if (!isset($datas['datas'][$ticket['category_name']])) {
- foreach ($status as $statusKey => $statusLabel) {
- if (in_array($statusKey, $status_to_show)) {
- $datas['datas'][$ticket['category_name']][$statusLabel] = 0;
- }
+ $result = $DB->query($query);
+
+ while ($ticket = $DB->fetchAssoc($result)) {
+ if (is_null($ticket['category_name'])) {
+ $ticket['category_name'] = __("None");
}
- }
- $datas['datas'][$ticket['category_name']][$status[$ticket['status']]] = $ticket['count'];
- }
+ if (!isset($datas['datas'][$ticket['category_name']])) {
+ foreach ($status as $statusKey => $statusLabel) {
+ if (in_array($statusKey, $status_to_show)) {
+ $datas['datas'][$ticket['category_name']][$statusLabel] = 0;
+ }
+ }
+ }
+
+ $datas['datas'][$ticket['category_name']][$status[$ticket['status']]] = $ticket['count'];
+ }
- //Define legend for all ticket status available in GLPI
- foreach ($status as $key => $label) {
- if (in_array($key, $status_to_show)) {
- $datas['labels2'][$label] = $label;
- }
- }
+ //Define legend for all ticket status available in GLPI
+ foreach ($status as $key => $label) {
+ if (in_array($key, $status_to_show)) {
+ $datas['labels2'][$label] = $label;
+ }
+ }
- return $datas;
- }
+ return $datas;
+ }
- function reportLineNbTicket($config = []) {
- $_SESSION['mreporting_selector']['reportLineNbTicket'] = ['dateinterval'];
+ public function reportLineNbTicket($config = [])
+ {
+ $_SESSION['mreporting_selector']['reportLineNbTicket'] = ['dateinterval'];
- return $this->reportAreaNbTicket($config, false);
- }
+ return $this->reportAreaNbTicket($config, false);
+ }
- function reportAreaNbTicket($config = [], $area = true) {
- global $DB;
+ public function reportAreaNbTicket($config = [], $area = true)
+ {
+ global $DB;
- $_SESSION['mreporting_selector']['reportAreaNbTicket'] = ['dateinterval', 'period'];
+ $_SESSION['mreporting_selector']['reportAreaNbTicket'] = ['dateinterval', 'period'];
- $datas = [];
+ $datas = [];
- //Init delay value
- $this->sql_date = PluginMreportingCommon::getSQLDate("glpi_tickets.date",
- $config['delay'],
- $config['randname']);
+ //Init delay value
+ $this->sql_date = PluginMreportingCommon::getSQLDate(
+ "glpi_tickets.date",
+ $config['delay'],
+ $config['randname']
+ );
- $query = "SELECT
- DISTINCT DATE_FORMAT(date, '".$this->period_sort."') as period,
- DATE_FORMAT(date, '".$this->period_label."') as period_name,
+ $query = "SELECT
+ DISTINCT DATE_FORMAT(date, '" . $this->period_sort . "') as period,
+ DATE_FORMAT(date, '" . $this->period_label . "') as period_name,
COUNT(id) as nb
FROM glpi_tickets
WHERE {$this->sql_date}
@@ -500,119 +530,127 @@ function reportAreaNbTicket($config = [], $area = true) {
AND glpi_tickets.is_deleted = '0'
GROUP BY period
ORDER BY period";
- $res = $DB->query($query);
- while ($data = $DB->fetchAssoc($res)) {
- $datas['datas'][$data['period_name']] = $data['nb'];
- }
-
- return $datas;
- }
-
- function reportVstackbarNbTicket($config = []) {
- $_SESSION['mreporting_selector']['reportVstackbarNbTicket'] = ['dateinterval'];
- return $this->reportGlineNbTicket($config, false);
- }
-
- function reportGareaNbTicket($config = []) {
- $_SESSION['mreporting_selector']['reportGareaNbTicket'] = ['dateinterval'];
- return $this->reportGlineNbTicket($config, true);
- }
-
- function reportGlineNbTicket($config = [], $area = false) {
- global $DB;
-
- $_SESSION['mreporting_selector']['reportGlineNbTicket']
+ $res = $DB->query($query);
+ while ($data = $DB->fetchAssoc($res)) {
+ $datas['datas'][$data['period_name']] = $data['nb'];
+ }
+
+ return $datas;
+ }
+
+ public function reportVstackbarNbTicket($config = [])
+ {
+ $_SESSION['mreporting_selector']['reportVstackbarNbTicket'] = ['dateinterval'];
+ return $this->reportGlineNbTicket($config, false);
+ }
+
+ public function reportGareaNbTicket($config = [])
+ {
+ $_SESSION['mreporting_selector']['reportGareaNbTicket'] = ['dateinterval'];
+ return $this->reportGlineNbTicket($config, true);
+ }
+
+ public function reportGlineNbTicket($config = [], $area = false)
+ {
+ global $DB;
+
+ $_SESSION['mreporting_selector']['reportGlineNbTicket']
= ['dateinterval', 'period', 'allstates'];
- $datas = [];
- $tmp_datas = [];
-
- //Init delay value
- $this->sql_date = PluginMreportingCommon::getSQLDate("glpi_tickets.date",
- $config['delay'],
- $config['randname']);
-
- // Get status to show
- if (isset($_POST['status_1'])) {
- foreach ($_POST as $key => $value) {
- if ((substr($key, 0, 7) == 'status_') && ($value == 1)) {
- $status_to_show[] = substr($key, 7, 1);
+ $datas = [];
+ $tmp_datas = [];
+
+ //Init delay value
+ $this->sql_date = PluginMreportingCommon::getSQLDate(
+ "glpi_tickets.date",
+ $config['delay'],
+ $config['randname']
+ );
+
+ // Get status to show
+ if (isset($_POST['status_1'])) {
+ foreach ($_POST as $key => $value) {
+ if ((substr($key, 0, 7) == 'status_') && ($value == 1)) {
+ $status_to_show[] = substr($key, 7, 1);
+ }
}
- }
- } else {
- $status_to_show = ['1', '2', '3', '4'];
- }
-
- //get dates used in this period
- $query_date = "SELECT DISTINCT
- DATE_FORMAT(`date`, '".$this->period_sort."') AS period,
- DATE_FORMAT(`date`, '".$this->period_label."') AS period_name
+ } else {
+ $status_to_show = ['1', '2', '3', '4'];
+ }
+
+ //get dates used in this period
+ $query_date = "SELECT DISTINCT
+ DATE_FORMAT(`date`, '" . $this->period_sort . "') AS period,
+ DATE_FORMAT(`date`, '" . $this->period_label . "') AS period_name
FROM `glpi_tickets`
- WHERE ".$this->sql_date."
- AND `glpi_tickets`.`entities_id` IN (".$this->where_entities.")
+ WHERE " . $this->sql_date . "
+ AND `glpi_tickets`.`entities_id` IN (" . $this->where_entities . ")
AND `glpi_tickets`.`is_deleted` = '0'
- AND status IN(".implode(',', $status_to_show).")
+ AND status IN(" . implode(',', $status_to_show) . ")
ORDER BY `date` ASC";
- $res_date = $DB->query($query_date);
- $dates = [];
- while ($data = $DB->fetchAssoc($res_date)) {
- $dates[$data['period']] = $data['period'];
- }
-
- $tmp_date = [];
- foreach (array_values($dates) as $id) {
- $tmp_date[] = $id;
- }
-
- $query = "SELECT DISTINCT
- DATE_FORMAT(date, '".$this->period_sort."') as period,
- DATE_FORMAT(date, '".$this->period_label."') as period_name,
+ $res_date = $DB->query($query_date);
+ $dates = [];
+ while ($data = $DB->fetchAssoc($res_date)) {
+ $dates[$data['period']] = $data['period'];
+ }
+
+ $tmp_date = [];
+ foreach (array_values($dates) as $id) {
+ $tmp_date[] = $id;
+ }
+
+ $query = "SELECT DISTINCT
+ DATE_FORMAT(date, '" . $this->period_sort . "') as period,
+ DATE_FORMAT(date, '" . $this->period_label . "') as period_name,
status,
COUNT(id) as nb
FROM glpi_tickets
- WHERE ".$this->sql_date."
- AND glpi_tickets.entities_id IN (".$this->where_entities.")
+ WHERE " . $this->sql_date . "
+ AND glpi_tickets.entities_id IN (" . $this->where_entities . ")
AND glpi_tickets.is_deleted = '0'
- AND status IN(".implode(',', $status_to_show).")
+ AND status IN(" . implode(',', $status_to_show) . ")
GROUP BY period, status
ORDER BY period, status";
- $res = $DB->query($query);
- while ($data = $DB->fetchAssoc($res)) {
- $status =Ticket::getStatus($data['status']);
- $datas['labels2'][$data['period']] = $data['period_name'];
- $datas['datas'][$status][$data['period']] = $data['nb'];
- }
-
- //merge missing datas (not defined status for a month)
- if (isset($datas['datas'])) {
- foreach ($datas['datas'] as &$data) {
- $data = $data + array_fill_keys($tmp_date, 0);
- }
- }
-
- //fix order of datas
- if (count($datas) > 0) {
- foreach ($datas['datas'] as &$data) {
- ksort($data);
- }
- }
- return $datas;
- }
-
- function reportSunburstTicketByCategories($config = []) {
- global $DB;
-
- $_SESSION['mreporting_selector']['reportSunburstTicketByCategories'] = ['dateinterval'];
-
- //Init delay value
- $this->sql_date = PluginMreportingCommon::getSQLDate("glpi_tickets.date",
- $config['delay'],
- $config['randname']);
-
- $flat_datas = [];
- $datas = [];
-
- $query = "SELECT glpi_tickets.itilcategories_id as id,
+ $res = $DB->query($query);
+ while ($data = $DB->fetchAssoc($res)) {
+ $status = Ticket::getStatus($data['status']);
+ $datas['labels2'][$data['period']] = $data['period_name'];
+ $datas['datas'][$status][$data['period']] = $data['nb'];
+ }
+
+ //merge missing datas (not defined status for a month)
+ if (isset($datas['datas'])) {
+ foreach ($datas['datas'] as &$data) {
+ $data = $data + array_fill_keys($tmp_date, 0);
+ }
+ }
+
+ //fix order of datas
+ if (count($datas) > 0) {
+ foreach ($datas['datas'] as &$data) {
+ ksort($data);
+ }
+ }
+ return $datas;
+ }
+
+ public function reportSunburstTicketByCategories($config = [])
+ {
+ global $DB;
+
+ $_SESSION['mreporting_selector']['reportSunburstTicketByCategories'] = ['dateinterval'];
+
+ //Init delay value
+ $this->sql_date = PluginMreportingCommon::getSQLDate(
+ "glpi_tickets.date",
+ $config['delay'],
+ $config['randname']
+ );
+
+ $flat_datas = [];
+ $datas = [];
+
+ $query = "SELECT glpi_tickets.itilcategories_id as id,
glpi_itilcategories.name as name,
glpi_itilcategories.itilcategories_id as parent,
COUNT(glpi_tickets.id) as count
@@ -624,52 +662,56 @@ function reportSunburstTicketByCategories($config = []) {
AND glpi_tickets.is_deleted = '0'
GROUP BY glpi_itilcategories.id
ORDER BY glpi_itilcategories.name";
- $res = $DB->query($query);
- while ($data = $DB->fetchAssoc($res)) {
- $flat_datas[$data['id']] = $data;
- }
-
- //get full parent list
- krsort($flat_datas);
- $itilcategory = new ITILCategory;
- foreach ($flat_datas as $cat_id => $current_datas) {
- if (!isset($flat_datas[$current_datas['parent']])) {
-
- if ($current_datas['parent'] != 0
- && $itilcategory->getFromDB($current_datas['parent'])) {
- $flat_datas[$current_datas['parent']] = [
- 'id' => $current_datas['parent'],
- 'name' => $itilcategory->fields['name'],
- 'parent' => $itilcategory->fields['itilcategories_id'],
- 'count' => 0
- ];
+ $res = $DB->query($query);
+ while ($data = $DB->fetchAssoc($res)) {
+ $flat_datas[$data['id']] = $data;
+ }
+
+ //get full parent list
+ krsort($flat_datas);
+ $itilcategory = new ITILCategory();
+ foreach ($flat_datas as $cat_id => $current_datas) {
+ if (!isset($flat_datas[$current_datas['parent']])) {
+ if (
+ $current_datas['parent'] != 0
+ && $itilcategory->getFromDB($current_datas['parent'])
+ ) {
+ $flat_datas[$current_datas['parent']] = [
+ 'id' => $current_datas['parent'],
+ 'name' => $itilcategory->fields['name'],
+ 'parent' => $itilcategory->fields['itilcategories_id'],
+ 'count' => 0
+ ];
+ }
}
- }
- }
+ }
- $tree_datas['datas'] = PluginMreportingCommon::buildTree($flat_datas);
+ $tree_datas['datas'] = PluginMreportingCommon::buildTree($flat_datas);
- return $tree_datas;
- }
+ return $tree_datas;
+ }
- function reportVstackbarTicketStatusByTechnician($config = []) {
- global $DB;
+ public function reportVstackbarTicketStatusByTechnician($config = [])
+ {
+ global $DB;
- $_SESSION['mreporting_selector']['reportVstackbarTicketStatusByTechnician'] = ['dateinterval'];
+ $_SESSION['mreporting_selector']['reportVstackbarTicketStatusByTechnician'] = ['dateinterval'];
- $datas = [];
- //Init delay value
- $this->sql_date = PluginMreportingCommon::getSQLDate("glpi_tickets.date",
- $config['delay'],
- $config['randname']);
+ $datas = [];
+ //Init delay value
+ $this->sql_date = PluginMreportingCommon::getSQLDate(
+ "glpi_tickets.date",
+ $config['delay'],
+ $config['randname']
+ );
- $status = $this->filters['open']['status'] + $this->filters['close']['status'];
- $status_keys = array_keys($status);
+ $status = $this->filters['open']['status'] + $this->filters['close']['status'];
+ $status_keys = array_keys($status);
- //get technician list
- $technicians = [];
- $query = "SELECT
+ //get technician list
+ $technicians = [];
+ $query = "SELECT
CONCAT(glpi_users.firstname, ' ', glpi_users.realname) as fullname,
glpi_users.name as username
FROM glpi_tickets
@@ -682,29 +724,29 @@ function reportVstackbarTicketStatusByTechnician($config = []) {
AND glpi_tickets.entities_id IN ({$this->where_entities})
AND glpi_tickets.is_deleted = '0'
ORDER BY fullname, username";
- $result = $DB->query($query);
-
- while ($technician = $DB->fetchAssoc($result)) {
- $technicians[] = ['username' => $technician['username'],
- 'fullname' => $technician['fullname'],
- ];
- }
-
- //prepare empty values with technician list
- foreach ($status as $key_status => $current_status) {
- foreach ($technicians as $technician) {
- $datas['datas'][$current_status][$technician['username']] = 0;
-
- $fullname = trim($technician['fullname']);
- if (!empty($fullname)) {
- $datas['labels2'][$technician['username']] = $fullname;
- } else {
- $datas['labels2'][$technician['username']] = $technician['username'];
+ $result = $DB->query($query);
+
+ while ($technician = $DB->fetchAssoc($result)) {
+ $technicians[] = ['username' => $technician['username'],
+ 'fullname' => $technician['fullname'],
+ ];
+ }
+
+ //prepare empty values with technician list
+ foreach ($status as $key_status => $current_status) {
+ foreach ($technicians as $technician) {
+ $datas['datas'][$current_status][$technician['username']] = 0;
+
+ $fullname = trim($technician['fullname']);
+ if (!empty($fullname)) {
+ $datas['labels2'][$technician['username']] = $fullname;
+ } else {
+ $datas['labels2'][$technician['username']] = $technician['username'];
+ }
}
- }
- }
+ }
- $query = "SELECT glpi_tickets.status,
+ $query = "SELECT glpi_tickets.status,
CONCAT(glpi_users.firstname, ' ', glpi_users.realname) as technician,
glpi_users.name as username,
COUNT(glpi_tickets.id) as count
@@ -719,32 +761,35 @@ function reportVstackbarTicketStatusByTechnician($config = []) {
AND glpi_tickets.is_deleted = '0'
GROUP BY status, technician
ORDER BY technician, username";
- $result = $DB->query($query);
+ $result = $DB->query($query);
- while ($ticket = $DB->fetchAssoc($result)) {
- if (is_null($ticket['technician'])) {
- $ticket['technician'] = __("None");
- }
- $datas['datas'][$status[$ticket['status']]][$ticket['username']] = $ticket['count'];
- }
+ while ($ticket = $DB->fetchAssoc($result)) {
+ if (is_null($ticket['technician'])) {
+ $ticket['technician'] = __("None");
+ }
+ $datas['datas'][$status[$ticket['status']]][$ticket['username']] = $ticket['count'];
+ }
- return $datas;
- }
+ return $datas;
+ }
- function reportHbarTicketNumberByLocation($config = []) {
- global $DB;
+ public function reportHbarTicketNumberByLocation($config = [])
+ {
+ global $DB;
- $_SESSION['mreporting_selector']['reportHbarTicketNumberByLocation']
+ $_SESSION['mreporting_selector']['reportHbarTicketNumberByLocation']
= ['dateinterval', 'limit'];
- //Init delay value
- $this->sql_date = PluginMreportingCommon::getSQLDate("`glpi_tickets`.`date`",
- $config['delay'],
- $config['randname']);
+ //Init delay value
+ $this->sql_date = PluginMreportingCommon::getSQLDate(
+ "`glpi_tickets`.`date`",
+ $config['delay'],
+ $config['randname']
+ );
- $datas = [];
+ $datas = [];
- $query = "SELECT COUNT(glpi_tickets.id) as count,
+ $query = "SELECT COUNT(glpi_tickets.id) as count,
glpi_locations.name as name
FROM glpi_tickets
LEFT JOIN glpi_tickets_users
@@ -759,22 +804,21 @@ function reportHbarTicketNumberByLocation($config = []) {
GROUP BY glpi_locations.name
ORDER BY count DESC
LIMIT 0, ";
- $query .= (isset($_REQUEST['glpilist_limit'])) ? $_REQUEST['glpilist_limit'] : 20;
+ $query .= (isset($_REQUEST['glpilist_limit'])) ? $_REQUEST['glpilist_limit'] : 20;
- $result = $DB->query($query);
+ $result = $DB->query($query);
- while ($ticket = $DB->fetchAssoc($result)) {
- if (empty($ticket['name'])) {
- $label = __("None");
- } else {
- $label = $ticket['name'];
- }
- $datas['datas'][$label] = $ticket['count'];
- }
-
- return $datas;
+ while ($ticket = $DB->fetchAssoc($result)) {
+ if (empty($ticket['name'])) {
+ $label = __("None");
+ } else {
+ $label = $ticket['name'];
+ }
+ $datas['datas'][$label] = $ticket['count'];
+ }
- }
+ return $datas;
+ }
/**
@@ -785,13 +829,14 @@ function reportHbarTicketNumberByLocation($config = []) {
* @param type $functionname
* @return $opt
*/
- function customExportDates(array $opt, $functionname) {
- $config = PluginMreportingConfig::initConfigParams($functionname, __CLASS__);
+ public function customExportDates(array $opt, $functionname)
+ {
+ $config = PluginMreportingConfig::initConfigParams($functionname, __CLASS__);
- $opt['date1'] = date('Y-m-j', strtotime($opt['date2'].' -'.$config['delay'].' days'));
+ $opt['date1'] = date('Y-m-j', strtotime($opt['date2'] . ' -' . $config['delay'] . ' days'));
- return $opt;
- }
+ return $opt;
+ }
/**
* Preconfig datas with your values when init config is done
@@ -801,35 +846,33 @@ function customExportDates(array $opt, $functionname) {
* @param PluginMreportingConfig $config
* @return $config
*/
- function preconfig($funct_name, $classname, PluginMreportingConfig $config) {
-
- if ($funct_name != -1 && $classname) {
-
- $ex_func = preg_split('/(?<=\\w)(?=[A-Z])/', $funct_name);
- if ($ex_func[0] != 'report') {
- return false;
- }
- $gtype = strtolower($ex_func[1]);
-
- switch ($gtype) {
- case 'pie':
- $config->fields["name"]=$funct_name;
- $config->fields["classname"]=$classname;
- $config->fields["is_active"]="1";
- $config->fields["show_label"]="hover";
- $config->fields["spline"]="0";
- $config->fields["show_area"]="0";
- $config->fields["show_graph"]="1";
- $config->fields["default_delay"]="30";
- $config->fields["show_label"]="hover";
- break;
- default :
- $config->preconfig($funct_name, $classname);
- break;
-
- }
-
- }
- return $config->fields;
- }
+ public function preconfig($funct_name, $classname, PluginMreportingConfig $config)
+ {
+
+ if ($funct_name != -1 && $classname) {
+ $ex_func = preg_split('/(?<=\\w)(?=[A-Z])/', $funct_name);
+ if ($ex_func[0] != 'report') {
+ return false;
+ }
+ $gtype = strtolower($ex_func[1]);
+
+ switch ($gtype) {
+ case 'pie':
+ $config->fields["name"] = $funct_name;
+ $config->fields["classname"] = $classname;
+ $config->fields["is_active"] = "1";
+ $config->fields["show_label"] = "hover";
+ $config->fields["spline"] = "0";
+ $config->fields["show_area"] = "0";
+ $config->fields["show_graph"] = "1";
+ $config->fields["default_delay"] = "30";
+ $config->fields["show_label"] = "hover";
+ break;
+ default:
+ $config->preconfig($funct_name, $classname);
+ break;
+ }
+ }
+ return $config->fields;
+ }
}
diff --git a/inc/helpdeskplus.class.php b/inc/helpdeskplus.class.php
index 3436cbd5..f8330895 100644
--- a/inc/helpdeskplus.class.php
+++ b/inc/helpdeskplus.class.php
@@ -1,51 +1,81 @@
.
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2003-2023 by Mreporting plugin team.
+ * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
+ * @link https://github.com/pluginsGLPI/mreporting
+ * -------------------------------------------------------------------------
+ */
+
if (!defined('GLPI_ROOT')) {
- die("Sorry. You can't access directly to this file");
+ die("Sorry. You can't access directly to this file");
}
-class PluginMreportingHelpdeskplus Extends PluginMreportingBaseclass {
-
- protected $sql_group_assign,
- $sql_group_request,
- $sql_user_assign,
- $sql_type,
- $sql_itilcat,
- $sql_join_cat,
- $sql_join_g,
- $sql_join_u,
- $sql_join_tt,
- $sql_join_tu,
- $sql_join_gt,
- $sql_join_gtr,
- $sql_select_sla;
-
-
- function __construct($config = []) {
- global $LANG;
- $this->sql_group_assign = "1=1";
- $this->sql_group_request = "1=1";
- $this->sql_user_assign = "1=1";
- $this->sql_type = "glpi_tickets.type IN (".Ticket::INCIDENT_TYPE.", ".Ticket::DEMAND_TYPE.")";
- $this->sql_itilcat = "1=1";
- $this->sql_join_cat = "LEFT JOIN glpi_itilcategories cat
+class PluginMreportingHelpdeskplus extends PluginMreportingBaseclass
+{
+ protected $sql_group_assign;
+ protected $sql_group_request;
+ protected $sql_user_assign;
+ protected $sql_type;
+ protected $sql_itilcat;
+ protected $sql_join_cat;
+ protected $sql_join_g;
+ protected $sql_join_u;
+ protected $sql_join_tt;
+ protected $sql_join_tu;
+ protected $sql_join_gt;
+ protected $sql_join_gtr;
+ protected $sql_select_sla;
+
+
+ public function __construct($config = [])
+ {
+ /** @var array $LANG */
+ global $LANG;
+ $this->sql_group_assign = "1=1";
+ $this->sql_group_request = "1=1";
+ $this->sql_user_assign = "1=1";
+ $this->sql_type = "glpi_tickets.type IN (" . Ticket::INCIDENT_TYPE . ", " . Ticket::DEMAND_TYPE . ")";
+ $this->sql_itilcat = "1=1";
+ $this->sql_join_cat = "LEFT JOIN glpi_itilcategories cat
ON glpi_tickets.itilcategories_id = cat.id";
- $this->sql_join_g = "LEFT JOIN glpi_groups g
+ $this->sql_join_g = "LEFT JOIN glpi_groups g
ON gt.groups_id = g.id";
- $this->sql_join_u = "LEFT JOIN glpi_users u
+ $this->sql_join_u = "LEFT JOIN glpi_users u
ON tu.users_id = u.id";
- $this->sql_join_tt = "LEFT JOIN glpi_tickettasks tt
+ $this->sql_join_tt = "LEFT JOIN glpi_tickettasks tt
ON tt.tickets_id = glpi_tickets.id";
- $this->sql_join_tu = "LEFT JOIN glpi_tickets_users tu
+ $this->sql_join_tu = "LEFT JOIN glpi_tickets_users tu
ON tu.tickets_id = glpi_tickets.id
- AND tu.type = ".Ticket_User::ASSIGN;
- $this->sql_join_gt = "LEFT JOIN glpi_groups_tickets gt
+ AND tu.type = " . Ticket_User::ASSIGN;
+ $this->sql_join_gt = "LEFT JOIN glpi_groups_tickets gt
ON gt.tickets_id = glpi_tickets.id
- AND gt.type = ".Group_Ticket::ASSIGN;
- $this->sql_join_gtr = "LEFT JOIN glpi_groups_tickets gtr
+ AND gt.type = " . Group_Ticket::ASSIGN;
+ $this->sql_join_gtr = "LEFT JOIN glpi_groups_tickets gtr
ON gtr.tickets_id = glpi_tickets.id
- AND gtr.type = ".Group_Ticket::REQUESTER;
- $this->sql_select_sla = "CASE WHEN glpi_slas.definition_time = 'day'
+ AND gtr.type = " . Group_Ticket::REQUESTER;
+ $this->sql_select_sla = "CASE WHEN glpi_slas.definition_time = 'day'
AND glpi_tickets.solve_delay_stat <= glpi_slas.number_time * 86400
THEN 'ok'
WHEN glpi_slas.definition_time = 'hour'
@@ -57,68 +87,76 @@ function __construct($config = []) {
ELSE 'nok'
END AS respected_sla";
- parent::__construct($config);
-
- $this->lcl_slaok = $LANG['plugin_mreporting']['Helpdeskplus']['slaobserved'];
- $this->lcl_slako = $LANG['plugin_mreporting']['Helpdeskplus']['slanotobserved'];
-
- $mr_values = $_SESSION['mreporting_values'];
-
- if (isset($mr_values['groups_assign_id'])) {
- if (is_array($mr_values['groups_assign_id'])) {
- $this->sql_group_assign = "gt.groups_id IN (".
- implode(',', $mr_values['groups_assign_id']).")";
- } else if ($mr_values['groups_assign_id'] > 0) {
- $this->sql_group_assign = "gt.groups_id = ".$mr_values['groups_assign_id'];
- }
- }
-
- if (isset($mr_values['groups_request_id'])) {
- if (is_array($mr_values['groups_request_id'])) {
- $this->sql_group_request = "gtr.groups_id IN (".
- implode(',', $mr_values['groups_request_id']).")";
- } else if ($mr_values['groups_request_id'] > 0) {
- $this->sql_group_request = "gt.groups_id = ".$mr_values['groups_request_id'];
- }
- }
-
- if (isset($mr_values['users_assign_id'])
- && $mr_values['users_assign_id'] > 0) {
- $this->sql_user_assign = "tu.users_id = ".$mr_values['users_assign_id'];
- }
-
- if (isset($mr_values['type'])
- && $mr_values['type'] > 0) {
- $this->sql_type = "glpi_tickets.type = ".$mr_values['type'];
- }
-
- if (isset($mr_values['itilcategories_id'])
- && $mr_values['itilcategories_id'] > 0) {
- $this->sql_itilcat = "glpi_tickets.itilcategories_id = ".$mr_values['itilcategories_id'];
- }
- }
-
- function reportGlineBacklogs($config = []) {
- global $DB, $LANG;
-
- $_SESSION['mreporting_selector']['reportGlineBacklogs'] =
+ parent::__construct($config);
+
+ $this->lcl_slaok = $LANG['plugin_mreporting']['Helpdeskplus']['slaobserved'];
+ $this->lcl_slako = $LANG['plugin_mreporting']['Helpdeskplus']['slanotobserved'];
+
+ $mr_values = $_SESSION['mreporting_values'];
+
+ if (isset($mr_values['groups_assign_id'])) {
+ if (is_array($mr_values['groups_assign_id'])) {
+ $this->sql_group_assign = "gt.groups_id IN (" .
+ implode(',', $mr_values['groups_assign_id']) . ")";
+ } else if ($mr_values['groups_assign_id'] > 0) {
+ $this->sql_group_assign = "gt.groups_id = " . $mr_values['groups_assign_id'];
+ }
+ }
+
+ if (isset($mr_values['groups_request_id'])) {
+ if (is_array($mr_values['groups_request_id'])) {
+ $this->sql_group_request = "gtr.groups_id IN (" .
+ implode(',', $mr_values['groups_request_id']) . ")";
+ } else if ($mr_values['groups_request_id'] > 0) {
+ $this->sql_group_request = "gt.groups_id = " . $mr_values['groups_request_id'];
+ }
+ }
+
+ if (
+ isset($mr_values['users_assign_id'])
+ && $mr_values['users_assign_id'] > 0
+ ) {
+ $this->sql_user_assign = "tu.users_id = " . $mr_values['users_assign_id'];
+ }
+
+ if (
+ isset($mr_values['type'])
+ && $mr_values['type'] > 0
+ ) {
+ $this->sql_type = "glpi_tickets.type = " . $mr_values['type'];
+ }
+
+ if (
+ isset($mr_values['itilcategories_id'])
+ && $mr_values['itilcategories_id'] > 0
+ ) {
+ $this->sql_itilcat = "glpi_tickets.itilcategories_id = " . $mr_values['itilcategories_id'];
+ }
+ }
+
+ public function reportGlineBacklogs($config = [])
+ {
+ global $DB, $LANG;
+
+ $_SESSION['mreporting_selector']['reportGlineBacklogs'] =
['dateinterval', 'period', 'backlogstates', 'multiplegrouprequest',
- 'userassign', 'category', 'multiplegroupassign'];
-
- $tab = [];
- $datas = [];
-
- $search_new = (!isset($_SESSION['mreporting_values']['show_new'])
- || ($_SESSION['mreporting_values']['show_new'] == '1')) ?true:false;
- $search_solved = (!isset($_SESSION['mreporting_values']['show_solved'])
- || ($_SESSION['mreporting_values']['show_solved'] == '1')) ?true:false;
- $search_backlogs = (!isset($_SESSION['mreporting_values']['show_backlog'])
- || ($_SESSION['mreporting_values']['show_backlog'] == '1')) ?true:false;
- $search_closed = (isset($_SESSION['mreporting_values']['show_closed'])
- && ($_SESSION['mreporting_values']['show_closed'] == '1')) ?true:false;
-
- if ($search_new) {
- $sql_create = "SELECT
+ 'userassign', 'category', 'multiplegroupassign'
+ ];
+
+ $tab = [];
+ $datas = [];
+
+ $search_new = (!isset($_SESSION['mreporting_values']['show_new'])
+ || ($_SESSION['mreporting_values']['show_new'] == '1')) ? true : false;
+ $search_solved = (!isset($_SESSION['mreporting_values']['show_solved'])
+ || ($_SESSION['mreporting_values']['show_solved'] == '1')) ? true : false;
+ $search_backlogs = (!isset($_SESSION['mreporting_values']['show_backlog'])
+ || ($_SESSION['mreporting_values']['show_backlog'] == '1')) ? true : false;
+ $search_closed = (isset($_SESSION['mreporting_values']['show_closed'])
+ && ($_SESSION['mreporting_values']['show_closed'] == '1')) ? true : false;
+
+ if ($search_new) {
+ $sql_create = "SELECT
DISTINCT DATE_FORMAT(date, '{$this->period_sort}') as period,
DATE_FORMAT(date, '{$this->period_label}') as period_name,
COUNT(DISTINCT glpi_tickets.id) as nb
@@ -137,14 +175,14 @@ function reportGlineBacklogs($config = []) {
AND {$this->sql_itilcat}
GROUP BY period
ORDER BY period";
- foreach ($DB->request($sql_create) as $data) {
- $tab[$data['period']]['open'] = $data['nb'];
- $tab[$data['period']]['period_name'] = $data['period_name'];
- }
- }
-
- if ($search_solved) {
- $sql_solved = "SELECT
+ foreach ($DB->request($sql_create) as $data) {
+ $tab[$data['period']]['open'] = $data['nb'];
+ $tab[$data['period']]['period_name'] = $data['period_name'];
+ }
+ }
+
+ if ($search_solved) {
+ $sql_solved = "SELECT
DISTINCT DATE_FORMAT(solvedate, '{$this->period_sort}') as period,
DATE_FORMAT(solvedate, '{$this->period_label}') as period_name,
COUNT(DISTINCT glpi_tickets.id) as nb
@@ -162,42 +200,42 @@ function reportGlineBacklogs($config = []) {
AND {$this->sql_itilcat}
GROUP BY period
ORDER BY period";
- foreach ($DB->request($sql_solved) as $data) {
- $tab[$data['period']]['solved'] = $data['nb'];
- $tab[$data['period']]['period_name'] = $data['period_name'];
- }
- }
+ foreach ($DB->request($sql_solved) as $data) {
+ $tab[$data['period']]['solved'] = $data['nb'];
+ $tab[$data['period']]['period_name'] = $data['period_name'];
+ }
+ }
/**
* Backlog : Tickets Ouverts à la date en cours...
*/
- if ($search_backlogs) {
- $date_array1=explode("-", $_SESSION['mreporting_values']['date1'.$config['randname']]);
- $time1=mktime(0, 0, 0, $date_array1[1], $date_array1[2], $date_array1[0]);
-
- $date_array2=explode("-", $_SESSION['mreporting_values']['date2'.$config['randname']]);
- $time2=mktime(0, 0, 0, $date_array2[1], $date_array2[2], $date_array2[0]);
-
- //if data inverted, reverse it
- if ($time1 > $time2) {
- list($time1, $time2) = [$time2, $time1];
- list($_SESSION['mreporting_values']['date1'.$config['randname']], $_SESSION['mreporting_values']['date2'.$config['randname']]) = [
- $_SESSION['mreporting_values']['date2'.$config['randname']],
- $_SESSION['mreporting_values']['date1'.$config['randname']]
- ];
- }
-
- $sql_itilcat_backlog = isset($_SESSION['mreporting_values']['itilcategories_id'])
+ if ($search_backlogs) {
+ $date_array1 = explode("-", $_SESSION['mreporting_values']['date1' . $config['randname']]);
+ $time1 = mktime(0, 0, 0, $date_array1[1], $date_array1[2], $date_array1[0]);
+
+ $date_array2 = explode("-", $_SESSION['mreporting_values']['date2' . $config['randname']]);
+ $time2 = mktime(0, 0, 0, $date_array2[1], $date_array2[2], $date_array2[0]);
+
+ //if data inverted, reverse it
+ if ($time1 > $time2) {
+ list($time1, $time2) = [$time2, $time1];
+ list($_SESSION['mreporting_values']['date1' . $config['randname']], $_SESSION['mreporting_values']['date2' . $config['randname']]) = [
+ $_SESSION['mreporting_values']['date2' . $config['randname']],
+ $_SESSION['mreporting_values']['date1' . $config['randname']]
+ ];
+ }
+
+ $sql_itilcat_backlog = isset($_SESSION['mreporting_values']['itilcategories_id'])
&& $_SESSION['mreporting_values']['itilcategories_id'] > 0
- ? " AND tic.itilcategories_id = ".$_SESSION['mreporting_values']['itilcategories_id']
+ ? " AND tic.itilcategories_id = " . $_SESSION['mreporting_values']['itilcategories_id']
: "";
- $begin=strftime($this->period_sort_php, $time1);
- $end=strftime($this->period_sort_php, $time2);
- $sql_date_backlog = "DATE_FORMAT(list_date.period_l, '{$this->period_sort}') >= '$begin'
+ $begin = date($this->period_sort_php, $time1);
+ $end = date($this->period_sort_php, $time2);
+ $sql_date_backlog = "DATE_FORMAT(list_date.period_l, '{$this->period_sort}') >= '$begin'
AND DATE_FORMAT(list_date.period_l, '{$this->period_sort}') <= '$end'";
- $sql_list_date2 = str_replace('date', 'solvedate', $this->sql_list_date);
- $sql_backlog = "SELECT
+ $sql_list_date2 = str_replace('date', 'solvedate', $this->sql_list_date);
+ $sql_backlog = "SELECT
DISTINCT(DATE_FORMAT(list_date.period_l, '$this->period_sort')) as period,
DATE_FORMAT(list_date.period_l, '$this->period_label') as period_name,
COUNT(DISTINCT(glpi_tickets.id)) as nb
@@ -228,15 +266,14 @@ function reportGlineBacklogs($config = []) {
AND {$this->sql_itilcat}
AND $sql_date_backlog
GROUP BY period";
- foreach ($DB->request($sql_backlog) as $data) {
- $tab[$data['period']]['backlog'] = $data['nb'];
- $tab[$data['period']]['period_name'] = $data['period_name'];
- }
-
- }
+ foreach ($DB->request($sql_backlog) as $data) {
+ $tab[$data['period']]['backlog'] = $data['nb'];
+ $tab[$data['period']]['period_name'] = $data['period_name'];
+ }
+ }
- if ($search_closed) {
- $sql_closed = "SELECT
+ if ($search_closed) {
+ $sql_closed = "SELECT
DISTINCT DATE_FORMAT(closedate, '{$this->period_sort}') as period,
DATE_FORMAT(closedate, '{$this->period_label}') as period_name,
COUNT(DISTINCT glpi_tickets.id) as nb
@@ -254,51 +291,53 @@ function reportGlineBacklogs($config = []) {
AND {$this->sql_itilcat}
GROUP BY period
ORDER BY period";
- foreach ($DB->request($sql_closed) as $data) {
- $tab[$data['period']]['closed'] = $data['nb'];
- $tab[$data['period']]['period_name'] = $data['period_name'];
- }
- }
-
- ksort($tab);
-
- foreach ($tab as $period => $data) {
- if ($search_new) {
- $datas['datas'][$LANG['plugin_mreporting']['Helpdeskplus']['opened']][] = (isset($data['open'])) ? $data['open'] : 0;
- }
- if ($search_solved) {
- $datas['datas'][_x('status', 'Solved')][] = (isset($data['solved'])) ? $data['solved'] : 0;
- }
- if ($search_closed) {
- $datas['datas'][_x('status', 'Closed')][] = (isset($data['closed'])) ? $data['closed'] : 0;
- }
- if ($search_backlogs) {
- $datas['datas'][$LANG['plugin_mreporting']['Helpdeskplus']['backlogs']][] = (isset($data['backlog'])) ? $data['backlog'] : 0;
- }
- $datas['labels2'][] = $data['period_name'];
- }
-
- return $datas;
- }
-
-
-
- function reportVstackbarLifetime($config = []) {
- global $DB;
-
- $tab = $datas = $labels2 = [];
- $_SESSION['mreporting_selector']['reportVstackbarLifetime']
+ foreach ($DB->request($sql_closed) as $data) {
+ $tab[$data['period']]['closed'] = $data['nb'];
+ $tab[$data['period']]['period_name'] = $data['period_name'];
+ }
+ }
+
+ ksort($tab);
+
+ foreach ($tab as $period => $data) {
+ if ($search_new) {
+ $datas['datas'][$LANG['plugin_mreporting']['Helpdeskplus']['opened']][] = (isset($data['open'])) ? $data['open'] : 0;
+ }
+ if ($search_solved) {
+ $datas['datas'][_x('status', 'Solved')][] = (isset($data['solved'])) ? $data['solved'] : 0;
+ }
+ if ($search_closed) {
+ $datas['datas'][_x('status', 'Closed')][] = (isset($data['closed'])) ? $data['closed'] : 0;
+ }
+ if ($search_backlogs) {
+ $datas['datas'][$LANG['plugin_mreporting']['Helpdeskplus']['backlogs']][] = (isset($data['backlog'])) ? $data['backlog'] : 0;
+ }
+ $datas['labels2'][] = $data['period_name'];
+ }
+
+ return $datas;
+ }
+
+
+
+ public function reportVstackbarLifetime($config = [])
+ {
+ global $DB;
+
+ $tab = $datas = $labels2 = [];
+ $_SESSION['mreporting_selector']['reportVstackbarLifetime']
= ['dateinterval', 'period', 'allstates', 'multiplegrouprequest',
- 'multiplegroupassign', 'userassign', 'category'];
+ 'multiplegroupassign', 'userassign', 'category'
+ ];
- if (!isset($_SESSION['mreporting_values']['date2'.$config['randname']])) {
- $_SESSION['mreporting_values']['date2'.$config['randname']] = strftime("%Y-%m-%d");
- }
+ if (!isset($_SESSION['mreporting_values']['date2' . $config['randname']])) {
+ $_SESSION['mreporting_values']['date2' . $config['randname']] = date("Y-m-d");
+ }
- foreach ($this->status as $current_status) {
- if ($_SESSION['mreporting_values']['status_'.$current_status] == '1') {
- $status_name = Ticket::getStatus($current_status);
- $sql_status = "SELECT
+ foreach ($this->status as $current_status) {
+ if ($_SESSION['mreporting_values']['status_' . $current_status] == '1') {
+ $status_name = Ticket::getStatus($current_status);
+ $sql_status = "SELECT
DISTINCT DATE_FORMAT(date, '{$this->period_sort}') as period,
DATE_FORMAT(date, '{$this->period_label}') as period_name,
COUNT(DISTINCT glpi_tickets.id) as nb
@@ -317,42 +356,43 @@ function reportVstackbarLifetime($config = []) {
AND {$this->sql_user_assign}
GROUP BY period
ORDER BY period";
- $res = $DB->query($sql_status);
- while ($data = $DB->fetchAssoc($res)) {
- $tab[$data['period']][$status_name] = $data['nb'];
- $labels2[$data['period']] = $data['period_name'];
+ $res = $DB->query($sql_status);
+ while ($data = $DB->fetchAssoc($res)) {
+ $tab[$data['period']][$status_name] = $data['nb'];
+ $labels2[$data['period']] = $data['period_name'];
+ }
}
- }
- }
+ }
- //ascending order of datas by date
- ksort($tab);
+ //ascending order of datas by date
+ ksort($tab);
- //fill missing datas with zeros
- $datas = $this->fillStatusMissingValues($tab, $labels2);
+ //fill missing datas with zeros
+ $datas = $this->fillStatusMissingValues($tab, $labels2);
- return $datas;
- }
+ return $datas;
+ }
- function reportVstackbarTicketsgroups($config = []) {
- global $DB;
+ public function reportVstackbarTicketsgroups($config = [])
+ {
+ global $DB;
- $_SESSION['mreporting_selector']['reportVstackbarTicketsgroups'] =
+ $_SESSION['mreporting_selector']['reportVstackbarTicketsgroups'] =
['dateinterval', 'allstates', 'multiplegroupassign', 'category'];
- $tab = [];
- $datas = [];
+ $tab = [];
+ $datas = [];
- if (!isset($_SESSION['mreporting_values']['date2'.$config['randname']])) {
- $_SESSION['mreporting_values']['date2'.$config['randname']] = strftime("%Y-%m-%d");
- }
+ if (!isset($_SESSION['mreporting_values']['date2' . $config['randname']])) {
+ $_SESSION['mreporting_values']['date2' . $config['randname']] = date("Y-m-d");
+ }
- foreach ($this->status as $current_status) {
- if ($_SESSION['mreporting_values']['status_'.$current_status] == '1') {
- $status_name = Ticket::getStatus($current_status);
- $sql_status = "SELECT
+ foreach ($this->status as $current_status) {
+ if ($_SESSION['mreporting_values']['status_' . $current_status] == '1') {
+ $status_name = Ticket::getStatus($current_status);
+ $sql_status = "SELECT
DISTINCT g.completename AS group_name,
COUNT(DISTINCT glpi_tickets.id) AS nb
FROM glpi_tickets
@@ -367,45 +407,46 @@ function reportVstackbarTicketsgroups($config = []) {
AND {$this->sql_group_assign}
GROUP BY group_name
ORDER BY group_name";
- $res = $DB->query($sql_status);
- while ($data = $DB->fetchAssoc($res)) {
- if (empty($data['group_name'])) {
- $data['group_name'] = __("None");
- }
- $tab[$data['group_name']][$status_name] = $data['nb'];
+ $res = $DB->query($sql_status);
+ while ($data = $DB->fetchAssoc($res)) {
+ if (empty($data['group_name'])) {
+ $data['group_name'] = __("None");
+ }
+ $tab[$data['group_name']][$status_name] = $data['nb'];
+ }
}
- }
- }
+ }
- //ascending order of datas by date
- ksort($tab);
+ //ascending order of datas by date
+ ksort($tab);
- //fill missing datas with zeros
- $datas = $this->fillStatusMissingValues($tab);
+ //fill missing datas with zeros
+ $datas = $this->fillStatusMissingValues($tab);
- return $datas;
- }
+ return $datas;
+ }
- function reportVstackbarTicketstech($config = []) {
- global $DB;
+ public function reportVstackbarTicketstech($config = [])
+ {
+ global $DB;
- $_SESSION['mreporting_selector']['reportVstackbarTicketstech']
+ $_SESSION['mreporting_selector']['reportVstackbarTicketstech']
= ['dateinterval', 'multiplegroupassign', 'allstates', 'category'];
- $tab = [];
- $datas = [];
+ $tab = [];
+ $datas = [];
- if (!isset($_SESSION['mreporting_values']['date2'.$config['randname']])) {
- $_SESSION['mreporting_values']['date2'.$config['randname']] = strftime("%Y-%m-%d");
- }
+ if (!isset($_SESSION['mreporting_values']['date2' . $config['randname']])) {
+ $_SESSION['mreporting_values']['date2' . $config['randname']] = date("Y-m-d");
+ }
- foreach ($this->status as $current_status) {
- if ($_SESSION['mreporting_values']['status_'.$current_status] == '1') {
- $status_name = Ticket::getStatus($current_status);
+ foreach ($this->status as $current_status) {
+ if ($_SESSION['mreporting_values']['status_' . $current_status] == '1') {
+ $status_name = Ticket::getStatus($current_status);
- $sql_create = "SELECT
+ $sql_create = "SELECT
DISTINCT CONCAT(u.firstname, ' ', u.realname) AS completename,
u.name as name,
u.id as u_id,
@@ -425,38 +466,39 @@ function reportVstackbarTicketstech($config = []) {
AND {$this->sql_itilcat}
GROUP BY name
ORDER BY name";
- $res = $DB->query($sql_create);
- while ($data = $DB->fetchAssoc($res)) {
- $data['name'] = empty($data['completename']) ? __("None") : $data['completename'];
+ $res = $DB->query($sql_create);
+ while ($data = $DB->fetchAssoc($res)) {
+ $data['name'] = empty($data['completename']) ? __("None") : $data['completename'];
- if (!isset($tab[$data['name']][$status_name])) {
- $tab[$data['name']][$status_name] = 0;
- }
+ if (!isset($tab[$data['name']][$status_name])) {
+ $tab[$data['name']][$status_name] = 0;
+ }
- $tab[$data['name']][$status_name]+= $data['nb'];
+ $tab[$data['name']][$status_name] += $data['nb'];
+ }
}
- }
- }
+ }
- //ascending order of datas by date
- ksort($tab);
+ //ascending order of datas by date
+ ksort($tab);
- //fill missing datas with zeros
- $datas = $this->fillStatusMissingValues($tab);
+ //fill missing datas with zeros
+ $datas = $this->fillStatusMissingValues($tab);
- return $datas;
- }
+ return $datas;
+ }
- function reportHbarTopcategory($config = []) {
- global $DB;
+ public function reportHbarTopcategory($config = [])
+ {
+ global $DB;
- $_SESSION['mreporting_selector']['reportHbarTopcategory']
+ $_SESSION['mreporting_selector']['reportHbarTopcategory']
= ['dateinterval', 'limit', 'userassign', 'multiplegrouprequest', 'multiplegroupassign', 'type'];
- $tab = [];
- $datas = [];
+ $tab = [];
+ $datas = [];
- $sql_create = "SELECT DISTINCT glpi_tickets.itilcategories_id,
+ $sql_create = "SELECT DISTINCT glpi_tickets.itilcategories_id,
COUNT(DISTINCT glpi_tickets.id) as nb,
cat.completename
FROM glpi_tickets
@@ -474,29 +516,30 @@ function reportHbarTopcategory($config = []) {
GROUP BY cat.completename
ORDER BY nb DESC
LIMIT 0, ";
- $sql_create .= (isset($_SESSION['mreporting_values']['glpilist_limit']))
+ $sql_create .= (isset($_SESSION['mreporting_values']['glpilist_limit']))
? $_SESSION['mreporting_values']['glpilist_limit'] : 20;
- $res = $DB->query($sql_create);
- while ($data = $DB->fetchAssoc($res)) {
- if (empty($data['completename'])) {
- $data['completename'] = __("None");
- }
- $datas['datas'][$data['completename']] = $data['nb'];
- }
+ $res = $DB->query($sql_create);
+ while ($data = $DB->fetchAssoc($res)) {
+ if (empty($data['completename'])) {
+ $data['completename'] = __("None");
+ }
+ $datas['datas'][$data['completename']] = $data['nb'];
+ }
- return $datas;
- }
+ return $datas;
+ }
- function reportHbarTopapplicant($config = []) {
- global $DB;
+ public function reportHbarTopapplicant($config = [])
+ {
+ global $DB;
- $_SESSION['mreporting_selector']['reportHbarTopapplicant'] = ['dateinterval', 'limit', 'type'];
+ $_SESSION['mreporting_selector']['reportHbarTopapplicant'] = ['dateinterval', 'limit', 'type'];
- $tab = [];
- $datas = [];
+ $tab = [];
+ $datas = [];
- $sql_create = "SELECT DISTINCT gt.groups_id,
+ $sql_create = "SELECT DISTINCT gt.groups_id,
COUNT(DISTINCT glpi_tickets.id) AS nb,
g.completename
FROM glpi_tickets
@@ -509,30 +552,32 @@ function reportHbarTopapplicant($config = []) {
GROUP BY g.completename
ORDER BY nb DESC
LIMIT 0, ";
- $sql_create .= (isset($_SESSION['mreporting_values']['glpilist_limit']))
+ $sql_create .= (isset($_SESSION['mreporting_values']['glpilist_limit']))
? $_SESSION['mreporting_values']['glpilist_limit'] : 20;
- $res = $DB->query($sql_create);
- while ($data = $DB->fetchAssoc($res)) {
- if (empty($data['completename'])) {
- $data['completename'] = __("None");
- }
- $datas['datas'][$data['completename']] = $data['nb'];
- }
+ $res = $DB->query($sql_create);
+ while ($data = $DB->fetchAssoc($res)) {
+ if (empty($data['completename'])) {
+ $data['completename'] = __("None");
+ }
+ $datas['datas'][$data['completename']] = $data['nb'];
+ }
- return $datas;
- }
+ return $datas;
+ }
- function reportVstackbarGroupChange($config = []) {
- global $DB;
+ public function reportVstackbarGroupChange($config = [])
+ {
+ global $DB;
- $_SESSION['mreporting_selector']['reportVstackbarGroupChange']
+ $_SESSION['mreporting_selector']['reportVstackbarGroupChange']
= ['dateinterval', 'userassign', 'category',
- 'multiplegrouprequest', 'multiplegroupassign'];
+ 'multiplegrouprequest', 'multiplegroupassign'
+ ];
- $datas = [];
+ $datas = [];
- $query = "SELECT COUNT(DISTINCT ticc.id) as nb_ticket,
+ $query = "SELECT COUNT(DISTINCT ticc.id) as nb_ticket,
ticc.nb_add_group - 1 as nb_add_group
FROM (
SELECT
@@ -559,28 +604,30 @@ function reportVstackbarGroupChange($config = []) {
GROUP BY glpi_tickets.id
HAVING nb_add_group > 0
) as ticc
- GROUP BY nb_add_group";
+ GROUP BY ticc.nb_add_group";
- $result = $DB->query($query);
+ $result = $DB->query($query);
- $datas['datas'] = [];
- while ($ticket = $DB->fetchAssoc($result)) {
- $datas['labels2'][$ticket['nb_add_group']] = $ticket['nb_add_group'];
- $datas['datas'][__("Number of tickets")][$ticket['nb_add_group']] = $ticket['nb_ticket'];
- }
+ $datas['datas'] = [];
+ while ($ticket = $DB->fetchAssoc($result)) {
+ $datas['labels2'][$ticket['nb_add_group']] = $ticket['nb_add_group'];
+ $datas['datas'][__("Number of tickets")][$ticket['nb_add_group']] = $ticket['nb_ticket'];
+ }
- return $datas;
- }
+ return $datas;
+ }
- function reportLineActiontimeVsSolvedelay($config = []) {
- global $DB;
+ public function reportLineActiontimeVsSolvedelay($config = [])
+ {
+ global $DB;
- $_SESSION['mreporting_selector']['reportLineActiontimeVsSolvedelay'] =
+ $_SESSION['mreporting_selector']['reportLineActiontimeVsSolvedelay'] =
['dateinterval', 'period', 'multiplegrouprequest',
- 'userassign', 'category', 'multiplegroupassign'];
+ 'userassign', 'category', 'multiplegroupassign'
+ ];
- $query = "SELECT
+ $query = "SELECT
DATE_FORMAT(glpi_tickets.date, '{$this->period_sort}') as period,
DATE_FORMAT(glpi_tickets.date, '{$this->period_label}') as period_name,
ROUND(AVG(actiontime_vs_solvedelay.time_percent), 1) as time_percent
@@ -610,56 +657,55 @@ function reportLineActiontimeVsSolvedelay($config = []) {
WHERE {$this->sql_date_create}
GROUP BY period
ORDER BY period";
- $data = [];
- foreach ($DB->request($query) as $result) {
- $data['datas'][$result['period_name']] = floatval($result['time_percent']);
- $data['labels2'][$result['period_name']] = $result['period_name'];
- }
-
- return $data;
- }
+ $data = [];
+ foreach ($DB->request($query) as $result) {
+ $data['datas'][$result['period_name']] = floatval($result['time_percent']);
+ $data['labels2'][$result['period_name']] = $result['period_name'];
+ }
+ return $data;
+ }
- function reportGlineNbTicketBySla($config = []) {
- global $DB;
+ public function reportGlineNbTicketBySla($config = [])
+ {
+ global $DB;
- $area = false;
- $datas = [];
+ $area = false;
+ $datas = [];
- $_SESSION['mreporting_selector']['reportGlineNbTicketBySla']
+ $_SESSION['mreporting_selector']['reportGlineNbTicketBySla']
= ['dateinterval', 'period', 'allSlasWithTicket'];
- if (isset($_SESSION['mreporting_values']['slas'])
- && !empty($_SESSION['mreporting_values']['slas'])) {
- //get dates used in this period
- $query_date = "SELECT DISTINCT DATE_FORMAT(`glpi_tickets`.`date`, '{$this->period_sort}') AS period,
+ if (
+ isset($_SESSION['mreporting_values']['slas'])
+ && !empty($_SESSION['mreporting_values']['slas'])
+ ) {
+ //get dates used in this period
+ $query_date = "SELECT DISTINCT DATE_FORMAT(`glpi_tickets`.`date`, '{$this->period_sort}') AS period,
DATE_FORMAT(`glpi_tickets`.`date`, '{$this->period_label}') AS period_name
FROM `glpi_tickets`
INNER JOIN `glpi_slas`
ON `glpi_tickets`.slas_id_ttr = `glpi_slas`.id
WHERE {$this->sql_date_create}
- AND `glpi_tickets`.status IN (" . implode(
- ',',
- array_merge(Ticket::getSolvedStatusArray(), Ticket::getClosedStatusArray())
- ) . ")
+ AND `glpi_tickets`.status IN (" . implode(',', array_merge(Ticket::getSolvedStatusArray(), Ticket::getClosedStatusArray())) . ")
AND `glpi_tickets`.`entities_id` IN (" . $this->where_entities . ")
AND `glpi_tickets`.`is_deleted` = '0'
- AND `glpi_slas`.id IN (".implode(',', $_SESSION['mreporting_values']['slas']).")
+ AND `glpi_slas`.id IN (" . implode(',', $_SESSION['mreporting_values']['slas']) . ")
ORDER BY `glpi_tickets`.`date` ASC";
- $res_date = $DB->query($query_date);
+ $res_date = $DB->query($query_date);
- $dates = [];
- while ($data = $DB->fetchAssoc($res_date)) {
- $dates[$data['period']] = $data['period'];
- }
+ $dates = [];
+ while ($data = $DB->fetchAssoc($res_date)) {
+ $dates[$data['period']] = $data['period'];
+ }
- $tmp_date = [];
- foreach (array_values($dates) as $id) {
- $tmp_date[] = $id;
- }
+ $tmp_date = [];
+ foreach (array_values($dates) as $id) {
+ $tmp_date[] = $id;
+ }
- $query = "SELECT DISTINCT
+ $query = "SELECT DISTINCT
DATE_FORMAT(`glpi_tickets`.`date`, '{$this->period_sort}') AS period,
DATE_FORMAT(`glpi_tickets`.`date`, '{$this->period_label}') AS period_name,
count(`glpi_tickets`.id) AS nb,
@@ -669,62 +715,60 @@ function reportGlineNbTicketBySla($config = []) {
INNER JOIN `glpi_slas`
ON `glpi_tickets`.slas_id_ttr = `glpi_slas`.id
WHERE {$this->sql_date_create}
- AND `glpi_tickets`.status IN (" . implode(
- ',',
- array_merge(Ticket::getSolvedStatusArray(), Ticket::getClosedStatusArray())
- ) . ")
+ AND `glpi_tickets`.status IN (" . implode(',', array_merge(Ticket::getSolvedStatusArray(), Ticket::getClosedStatusArray())) . ")
AND `glpi_tickets`.entities_id IN (" . $this->where_entities . ")
AND `glpi_tickets`.is_deleted = '0'";
- if (isset($_SESSION['mreporting_values']['slas'])) {
- $query .= " AND `glpi_slas`.id IN (".implode(',', $_SESSION['mreporting_values']['slas']).") ";
- }
- $query .= "GROUP BY `glpi_slas`.name, period, respected_sla";
-
- $result = $DB->query($query);
- while ($data = $DB->fetchAssoc($result)) {
- $datas['labels2'][$data['period']] = $data['period_name'];
- if ($data['respected_sla'] == 'ok') {
- $value = $this->lcl_slaok;
- } else {
- $value = $this->lcl_slako;
+ if (isset($_SESSION['mreporting_values']['slas'])) {
+ $query .= " AND `glpi_slas`.id IN (" . implode(',', $_SESSION['mreporting_values']['slas']) . ") ";
+ }
+ $query .= "GROUP BY `glpi_slas`.name, period, respected_sla";
+
+ $result = $DB->query($query);
+ while ($data = $DB->fetchAssoc($result)) {
+ $datas['labels2'][$data['period']] = $data['period_name'];
+ if ($data['respected_sla'] == 'ok') {
+ $value = $this->lcl_slaok;
+ } else {
+ $value = $this->lcl_slako;
+ }
+ $datas['datas'][$data['name'] . ' ' . $value][$data['period']] = $data['nb'];
}
- $datas['datas'][$data['name'] . ' ' . $value][$data['period']] = $data['nb'];
- }
- if (isset($datas['datas'])) {
- foreach ($datas['datas'] as &$data) {
- $data = $data + array_fill_keys($tmp_date, 0);
+ if (isset($datas['datas'])) {
+ foreach ($datas['datas'] as &$data) {
+ $data = $data + array_fill_keys($tmp_date, 0);
+ }
}
- }
- }
+ }
- return $datas;
- }
+ return $datas;
+ }
- public function reportHgbarRespectedSlasByTopCategory($config = []) {
- global $DB;
+ public function reportHgbarRespectedSlasByTopCategory($config = [])
+ {
+ global $DB;
- $area = false;
+ $area = false;
- $_SESSION['mreporting_selector']['reportHgbarRespectedSlasByTopCategory']
+ $_SESSION['mreporting_selector']['reportHgbarRespectedSlasByTopCategory']
= ['dateinterval', 'limit', 'categories'];
- $datas = [];
- $categories = [];
+ $datas = [];
+ $categories = [];
- if (isset($_POST['categories']) && $_POST['categories'] > 0) {
- $category = $_POST['categories'];
- } else {
- $category = false;
- }
+ if (isset($_POST['categories']) && $_POST['categories'] > 0) {
+ $category = $_POST['categories'];
+ } else {
+ $category = false;
+ }
- $category_limit = isset($_POST['glpilist_limit']) ? $_POST['glpilist_limit'] : 10;
+ $category_limit = isset($_POST['glpilist_limit']) ? $_POST['glpilist_limit'] : 10;
- $_SESSION['glpilist_limit'] = $category_limit;
+ $_SESSION['glpilist_limit'] = $category_limit;
- if (!$category) {
- $query_categories = "SELECT
+ if (!$category) {
+ $query_categories = "SELECT
count(`glpi_tickets`.id) as nb,
`glpi_itilcategories`.id
FROM `glpi_tickets`
@@ -739,13 +783,13 @@ public function reportHgbarRespectedSlasByTopCategory($config = []) {
ORDER BY nb DESC
LIMIT " . $category_limit;
- $result_categories = $DB->query($query_categories);
- while ($data = $DB->fetchAssoc($result_categories)) {
- $categories[] = $data['id'];
- }
- }
+ $result_categories = $DB->query($query_categories);
+ while ($data = $DB->fetchAssoc($result_categories)) {
+ $categories[] = $data['id'];
+ }
+ }
- $query = "SELECT COUNT(`glpi_tickets`.id) as nb,
+ $query = "SELECT COUNT(`glpi_tickets`.id) as nb,
{$this->sql_select_sla},
`glpi_itilcategories`.id,
`glpi_itilcategories`.name
@@ -757,41 +801,43 @@ public function reportHgbarRespectedSlasByTopCategory($config = []) {
WHERE " . $this->sql_date_create . "
AND `glpi_tickets`.entities_id IN (" . $this->where_entities . ")
AND `glpi_tickets`.is_deleted = '0'";
- if ($category) {
- $query .= " AND `glpi_itilcategories`.id = " . $category;
- } else if (!empty($categories)) {
- $query .= " AND `glpi_itilcategories`.id IN (" . implode(',', $categories) . ")";
- }
+ if ($category) {
+ $query .= " AND `glpi_itilcategories`.id = " . $category;
+ } else if (!empty($categories)) {
+ $query .= " AND `glpi_itilcategories`.id IN (" . implode(',', $categories) . ")";
+ }
$query .= " GROUP BY respected_sla, `glpi_itilcategories`.id
ORDER BY nb DESC";
- $result = $DB->query($query);
- while ($data = $DB->fetchAssoc($result)) {
- $value = ($data['respected_sla'] == 'ok') ? $this->lcl_slaok
+ $result = $DB->query($query);
+ while ($data = $DB->fetchAssoc($result)) {
+ $value = ($data['respected_sla'] == 'ok') ? $this->lcl_slaok
: $this->lcl_slako;
- $datas['datas'][$data['name']][$value] = $data['nb'];
- }
- $datas['labels2'] = [$this->lcl_slaok => $this->lcl_slaok,
- $this->lcl_slako => $this->lcl_slako];
+ $datas['datas'][$data['name']][$value] = $data['nb'];
+ }
+ $datas['labels2'] = [$this->lcl_slaok => $this->lcl_slaok,
+ $this->lcl_slako => $this->lcl_slako
+ ];
- if (isset($datas['datas'])) {
- foreach ($datas['datas'] as &$data) {
- $data = $data + array_fill_keys($datas['labels2'], 0);
- }
- }
+ if (isset($datas['datas'])) {
+ foreach ($datas['datas'] as &$data) {
+ $data = $data + array_fill_keys($datas['labels2'], 0);
+ }
+ }
- return $datas;
- }
+ return $datas;
+ }
- public function reportHgbarRespectedSlasByTechnician($config = []) {
- global $DB;
+ public function reportHgbarRespectedSlasByTechnician($config = [])
+ {
+ global $DB;
- $area = false;
- $datas = [];
+ $area = false;
+ $datas = [];
- $_SESSION['mreporting_selector']['reportHgbarRespectedSlasByTechnician'] = ['dateinterval'];
+ $_SESSION['mreporting_selector']['reportHgbarRespectedSlasByTechnician'] = ['dateinterval'];
- $query = "SELECT
+ $query = "SELECT
CONCAT(`glpi_users`.firstname, ' ', `glpi_users`.realname) as fullname,
`glpi_users`.id,
COUNT(`glpi_tickets`.id) as nb,
@@ -810,258 +856,233 @@ public function reportHgbarRespectedSlasByTechnician($config = []) {
GROUP BY respected_sla, `glpi_users`.id
ORDER BY nb DESC";
- $result = $DB->query($query);
- while ($data = $DB->fetchAssoc($result)) {
- if ($data['respected_sla'] == 'ok') {
- $value = $this->lcl_slaok;
- } else {
- $value = $this->lcl_slako;
- }
- $datas['datas'][$data['fullname']][$value] = $data['nb'];
- }
- $datas['labels2'] = [$this->lcl_slaok => $this->lcl_slaok,
- $this->lcl_slako => $this->lcl_slako];
-
- if (isset($datas['datas'])) {
- foreach ($datas['datas'] as &$data) {
- $data = $data + array_fill_keys($datas['labels2'], 0);
- }
- }
-
- return $datas;
- }
-
- function fillStatusMissingValues($tab, $labels2 = []) {
- $datas = [];
- foreach ($tab as $name => $data) {
- foreach ($this->status as $current_status) {
- if (!isset($_SESSION['mreporting_values']['status_'.$current_status])
- || ($_SESSION['mreporting_values']['status_'.$current_status] == '1')) {
-
- $status_name = Ticket::getStatus($current_status);
- if (isset($data[$status_name])) {
- $datas['datas'][$status_name][] = $data[$status_name];
- } else {
- $datas['datas'][$status_name][] = 0;
- }
+ $result = $DB->query($query);
+ while ($data = $DB->fetchAssoc($result)) {
+ if ($data['respected_sla'] == 'ok') {
+ $value = $this->lcl_slaok;
+ } else {
+ $value = $this->lcl_slako;
+ }
+ $datas['datas'][$data['fullname']][$value] = $data['nb'];
+ }
+ $datas['labels2'] = [$this->lcl_slaok => $this->lcl_slaok,
+ $this->lcl_slako => $this->lcl_slako
+ ];
+
+ if (isset($datas['datas'])) {
+ foreach ($datas['datas'] as &$data) {
+ $data = $data + array_fill_keys($datas['labels2'], 0);
}
- }
- if (empty($labels2)) {
- $datas['labels2'][] = $name;
- } else {
- $datas['labels2'][] = $labels2[$name];
- }
- }
- return $datas;
- }
-
- static function selectorBacklogstates() {
- global $LANG;
-
- echo "
".$LANG['plugin_mreporting']['Helpdeskplus']['backlogstatus']." :
";
-
- // Opened
- echo '';
- echo "
";
+ echo "
";
- // Backlog
- echo '';
- echo ' ';
- echo '';
+ echo ' ';
+ echo ' ';
- echo $LANG['plugin_mreporting']['Helpdeskplus']['backlogs'];
- echo '';
-
- // Closed
- echo '';
- echo ' ';
- echo ' ';
+ echo $LANG['plugin_mreporting']['Helpdeskplus']['backlogs'];
+ echo '';
+
+ // Closed
+ echo '';
+ echo ' ';
+ echo ' ';
- echo _x('status', 'Closed');
- echo '';
- }
+ echo ' /> ';
+ echo _x('status', 'Closed');
+ echo '';
+ }
- function reportVstackbarRespectedSlasByGroup($config = []) {
- global $DB, $LANG;
+ public function reportVstackbarRespectedSlasByGroup($config = [])
+ {
+ global $DB, $LANG;
- $datas = [];
+ $datas = [];
- $_SESSION['mreporting_selector']['reportVstackbarRespectedSlasByGroup']
+ $_SESSION['mreporting_selector']['reportVstackbarRespectedSlasByGroup']
= ['dateinterval', 'allSlasWithTicket'];
- $this->sql_date_create = PluginMreportingCommon::getSQLDate("`glpi_tickets`.date",
- $config['delay'],
- $config['randname']);
-
- if (isset($_SESSION['mreporting_values']['slas'])
- && !empty($_SESSION['mreporting_values']['slas'])) {
-
- $query = "SELECT COUNT(`glpi_tickets`.id) AS nb,
+ $this->sql_date_create = PluginMreportingCommon::getSQLDate(
+ "`glpi_tickets`.date",
+ $config['delay'],
+ $config['randname']
+ );
+
+ if (
+ isset($_SESSION['mreporting_values']['slas'])
+ && !empty($_SESSION['mreporting_values']['slas'])
+ ) {
+ $query = "SELECT COUNT(`glpi_tickets`.id) AS nb,
`glpi_groups_tickets`.groups_id as groups_id,
`glpi_slas`.name,
{$this->sql_select_sla}
FROM `glpi_tickets`
INNER JOIN `glpi_groups_tickets`
ON `glpi_groups_tickets`.tickets_id = `glpi_tickets`.id
- AND `glpi_groups_tickets`.type = ".CommonITILActor::ASSIGN."
+ AND `glpi_groups_tickets`.type = " . CommonITILActor::ASSIGN . "
INNER JOIN `glpi_slas`
ON `glpi_tickets`.slas_id_ttr = `glpi_slas`.id
WHERE {$this->sql_date_create}
- AND `glpi_tickets`.status IN (" . implode(
- ',',
- array_merge(Ticket::getSolvedStatusArray(), Ticket::getClosedStatusArray())
- ) . ")
+ AND `glpi_tickets`.status IN (" . implode(',', array_merge(Ticket::getSolvedStatusArray(), Ticket::getClosedStatusArray())) . ")
AND `glpi_tickets`.entities_id IN ({$this->where_entities})
AND `glpi_tickets`.is_deleted = '0'
- AND `glpi_slas`.id IN (".implode(',', $_SESSION['mreporting_values']['slas']).")
+ AND `glpi_slas`.id IN (" . implode(',', $_SESSION['mreporting_values']['slas']) . ")
GROUP BY `glpi_groups_tickets`.groups_id, respected_sla;";
- $result = $DB->query($query);
+ $result = $DB->query($query);
- while ($data = $DB->fetchAssoc($result)) {
- $gp = new Group();
- $gp->getFromDB($data['groups_id']);
+ while ($data = $DB->fetchAssoc($result)) {
+ $gp = new Group();
+ $gp->getFromDB($data['groups_id']);
- $datas['labels2'][$gp->fields['name']] = $gp->fields['name'];
+ $datas['labels2'][$gp->fields['name']] = $gp->fields['name'];
- if ($data['respected_sla'] == 'ok') {
- $datas['datas'][$LANG['plugin_mreporting']['Helpdeskplus']['slaobserved']][$gp->fields['name']] = $data['nb'];
- } else {
- $datas['datas'][$LANG['plugin_mreporting']['Helpdeskplus']['slanotobserved']][$gp->fields['name']] = $data['nb'];
+ if ($data['respected_sla'] == 'ok') {
+ $datas['datas'][$LANG['plugin_mreporting']['Helpdeskplus']['slaobserved']][$gp->fields['name']] = $data['nb'];
+ } else {
+ $datas['datas'][$LANG['plugin_mreporting']['Helpdeskplus']['slanotobserved']][$gp->fields['name']] = $data['nb'];
+ }
}
- }
-
- // Ajout des '0' manquants :
- $gp = new Group();
- $gp_found = $gp->find([], "name"); //Tri précose qui n'est pas utile
-
- foreach ($gp_found as $group) {
- $group_name = $group['name'];
- if (!isset($datas['datas'][$LANG['plugin_mreporting']['Helpdeskplus']['slaobserved']][$group_name])) {
- $datas['labels2'][$group_name] = $group_name;
- $datas['datas'][$LANG['plugin_mreporting']['Helpdeskplus']['slaobserved']][$group_name] = 0;
- }
- if (!isset($datas['datas'][$LANG['plugin_mreporting']['Helpdeskplus']['slanotobserved']][$group_name])) {
- $datas['datas'][$LANG['plugin_mreporting']['Helpdeskplus']['slanotobserved']][$group_name] = 0;
+ // Ajout des '0' manquants :
+ $gp = new Group();
+ $gp_found = $gp->find([], "name"); //Tri précose qui n'est pas utile
+
+ foreach ($gp_found as $group) {
+ $group_name = $group['name'];
+ if (!isset($datas['datas'][$LANG['plugin_mreporting']['Helpdeskplus']['slaobserved']][$group_name])) {
+ $datas['labels2'][$group_name] = $group_name;
+ $datas['datas'][$LANG['plugin_mreporting']['Helpdeskplus']['slaobserved']][$group_name] = 0;
+ }
+ if (!isset($datas['datas'][$LANG['plugin_mreporting']['Helpdeskplus']['slanotobserved']][$group_name])) {
+ $datas['datas'][$LANG['plugin_mreporting']['Helpdeskplus']['slanotobserved']][$group_name] = 0;
+ }
}
- }
-
- //Flip array to have observed SLA first
- arsort($datas['datas']);
- //Array alphabetic sort
- //For PNG mode, it is important to sort by date on each item
- ksort($datas['datas'][$LANG['plugin_mreporting']['Helpdeskplus']['slaobserved']]);
- ksort($datas['datas'][$LANG['plugin_mreporting']['Helpdeskplus']['slanotobserved']]);
+ //Flip array to have observed SLA first
+ arsort($datas['datas']);
- //For SVG mode, labels2 sort is ok
- asort($datas['labels2']);
+ //Array alphabetic sort
+ //For PNG mode, it is important to sort by date on each item
+ ksort($datas['datas'][$LANG['plugin_mreporting']['Helpdeskplus']['slaobserved']]);
+ ksort($datas['datas'][$LANG['plugin_mreporting']['Helpdeskplus']['slanotobserved']]);
- $datas['unit'] = '%';
- }
+ //For SVG mode, labels2 sort is ok
+ asort($datas['labels2']);
- return $datas;
- }
+ $datas['unit'] = '%';
+ }
- function reportVstackbarNbTicketBySla($config = []) {
- global $DB, $LANG;
+ return $datas;
+ }
- $area = false;
+ public function reportVstackbarNbTicketBySla($config = [])
+ {
+ global $DB, $LANG;
- $_SESSION['mreporting_selector']['reportVstackbarNbTicketBySla'] = ['dateinterval', 'allSlasWithTicket'];
+ $area = false;
- $datas = [];
- $tmp_datas = [];
+ $_SESSION['mreporting_selector']['reportVstackbarNbTicketBySla'] = ['dateinterval', 'allSlasWithTicket'];
- $this->sql_date_create = PluginMreportingCommon::getSQLDate("`glpi_tickets`.date",
- $config['delay'],
- $config['randname']);
+ $datas = [];
+ $tmp_datas = [];
- if (isset($_SESSION['mreporting_values']['slas'])
- && !empty($_SESSION['mreporting_values']['slas'])) {
+ $this->sql_date_create = PluginMreportingCommon::getSQLDate(
+ "`glpi_tickets`.date",
+ $config['delay'],
+ $config['randname']
+ );
- $query = "SELECT count(`glpi_tickets`.id) AS nb, `glpi_slas`.name,
+ if (
+ isset($_SESSION['mreporting_values']['slas'])
+ && !empty($_SESSION['mreporting_values']['slas'])
+ ) {
+ $query = "SELECT count(`glpi_tickets`.id) AS nb, `glpi_slas`.name,
{$this->sql_select_sla}
FROM `glpi_tickets`
INNER JOIN `glpi_slas`
ON `glpi_tickets`.slas_id_ttr = `glpi_slas`.id
WHERE {$this->sql_date_create}
- AND `glpi_tickets`.status IN (" . implode(',',
- array_merge(Ticket::getSolvedStatusArray(), Ticket::getClosedStatusArray())
- ) . ")
+ AND `glpi_tickets`.status IN (" . implode(',', array_merge(Ticket::getSolvedStatusArray(), Ticket::getClosedStatusArray())) . ")
AND `glpi_tickets`.entities_id IN ({$this->where_entities})
AND `glpi_tickets`.is_deleted = '0'
- AND `glpi_slas`.id IN (".implode(',', $_SESSION['mreporting_values']['slas']).")
+ AND `glpi_slas`.id IN (" . implode(',', $_SESSION['mreporting_values']['slas']) . ")
GROUP BY `glpi_slas`.name, respected_sla;";
- $result = $DB->query($query);
- while ($data = $DB->fetchAssoc($result)) {
- $tmp_datas[$data['name']][$data['respected_sla']] = $data['nb'];
- }
-
- foreach ($tmp_datas as $key => $value) {
- $datas['labels2'][$key] = $key;
- $datas['datas'][$LANG['plugin_mreporting']['Helpdeskplus']['slaobserved']][$key]
- = !empty($value['ok']) ? $value['ok'] : 0;
- $datas['datas'][$LANG['plugin_mreporting']['Helpdeskplus']['slanotobserved']][$key]
- = !empty($value['nok']) ? $value['nok'] : 0;
- }
- }
-
- return $datas;
- }
-
-
- private function _getPeriod() {
- if (isset($_REQUEST['period']) && !empty($_REQUEST['period'])) {
- switch ($_REQUEST['period']) {
- case 'day':
- $this->_period_sort = '%y%m%d';
- $this->_period_label = '%d %b %Y';
- break;
- case 'week':
- $this->_period_sort = '%y%u';
- $this->_period_label = 'S-%u %Y';
- break;
- case 'month':
- $this->_period_sort = '%y%m';
- $this->_period_label = '%b %Y';
- break;
- case 'year':
- $this->_period_sort = '%Y';
- $this->_period_label = '%Y';
- break;
- default :
- $this->_period_sort = '%y%m';
- $this->_period_label = '%b %Y';
- break;
- }
- } else {
- $this->_period_sort = '%y%m';
- $this->_period_label = '%b %Y';
- }
- }
+ $result = $DB->query($query);
+ while ($data = $DB->fetchAssoc($result)) {
+ $tmp_datas[$data['name']][$data['respected_sla']] = $data['nb'];
+ }
+
+ foreach ($tmp_datas as $key => $value) {
+ $datas['labels2'][$key] = $key;
+ $datas['datas'][$LANG['plugin_mreporting']['Helpdeskplus']['slaobserved']][$key]
+ = !empty($value['ok']) ? $value['ok'] : 0;
+ $datas['datas'][$LANG['plugin_mreporting']['Helpdeskplus']['slanotobserved']][$key]
+ = !empty($value['nok']) ? $value['nok'] : 0;
+ }
+ }
+
+ return $datas;
+ }
}
diff --git a/inc/inventory.class.php b/inc/inventory.class.php
index 3bdd34d9..1d1e2941 100644
--- a/inc/inventory.class.php
+++ b/inc/inventory.class.php
@@ -1,110 +1,120 @@
.
- --------------------------------------------------------------------------
+/**
+ * -------------------------------------------------------------------------
+ * Mreporting plugin for GLPI
+ * -------------------------------------------------------------------------
+ *
+ * LICENSE
+ *
+ * This file is part of Mreporting.
+ *
+ * Mreporting is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mreporting is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mreporting. If not, see .
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2003-2023 by Mreporting plugin team.
+ * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
+ * @link https://github.com/pluginsGLPI/mreporting
+ * -------------------------------------------------------------------------
*/
-class PluginMreportingInventory Extends PluginMreportingBaseclass {
+class PluginMreportingInventory extends PluginMreportingBaseclass
+{
/* ==== SPECIFIC SELECTORS FOR INVENTORY ==== */
- static function selectorMultipleStates() {
- self::selectorForMultipleStates('states_id', [], _sx("item", "State"));
- }
-
- static function selectorForMultipleStates($field, $condition = [], $label = '') {
- global $DB;
-
- $selected_states = [];
- if (isset($_SESSION['mreporting_values'][$field])) {
- $selected_states = $_SESSION['mreporting_values'][$field];
- } else {
- $selected_states = self::getDefaultState();
- }
- $datas = [];
- foreach (getAllDataFromTable('glpi_states', $condition) as $data) {
- $datas[$data['id']] = $data['completename'];
- }
-
- $param = ['multiple' => true,
- 'display' => true,
- 'size' => count($selected_states),
- 'values' => $selected_states];
-
- echo "
".$label." :
";
- Dropdown::showFromArray($field, $datas, $param);
- }
-
- static function getDefaultState() {
- global $DB;
-
- $states = [];
- $query = "SELECT `id`FROM `glpi_states` WHERE `name` IN ('En service')";
- foreach ($DB->request($query) as $data) {
- $states[] = $data['id'];
- }
- return $states;
- }
-
- static function getStateCondition($field, $as_array = false) {
- $sql_states = ($as_array ? [] : "");
- if (isset($_SESSION['mreporting_values']['states_id'])) {
- if (is_array($_SESSION['mreporting_values']['states_id'])) {
- if ($as_array) {
- $sql_states[$field] = $_SESSION['mreporting_values']['states_id'];
- } else {
- $sql_states = " AND $field IN (".implode(',', $_SESSION['mreporting_values']['states_id']).")";
- }
- } else if ($_SESSION['mreporting_values']['states_id'] > 0) {
- if ($as_array) {
- $sql_states[$field] = $_SESSION['mreporting_values']['states_id'];
- } else {
- $sql_states = " AND $field = ".$_SESSION['mreporting_values']['states_id'];
+ public static function selectorMultipleStates()
+ {
+ self::selectorForMultipleStates('states_id', [], _sx("item", "State"));
+ }
+
+ public static function selectorForMultipleStates($field, $condition = [], $label = '')
+ {
+ global $DB;
+
+ $selected_states = [];
+ if (isset($_SESSION['mreporting_values'][$field])) {
+ $selected_states = $_SESSION['mreporting_values'][$field];
+ } else {
+ $selected_states = self::getDefaultState();
+ }
+ $datas = [];
+ foreach (getAllDataFromTable('glpi_states', $condition) as $data) {
+ $datas[$data['id']] = $data['completename'];
+ }
+
+ $param = ['multiple' => true,
+ 'display' => true,
+ 'size' => count($selected_states),
+ 'values' => $selected_states
+ ];
+
+ echo "
" . $label . " :
";
+ Dropdown::showFromArray($field, $datas, $param);
+ }
+
+ public static function getDefaultState()
+ {
+ global $DB;
+
+ $states = [];
+ $query = "SELECT `id`FROM `glpi_states` WHERE `name` IN ('En service')";
+ foreach ($DB->request($query) as $data) {
+ $states[] = $data['id'];
+ }
+ return $states;
+ }
+
+ public static function getStateCondition($field, $as_array = false)
+ {
+ $sql_states = ($as_array ? [] : "");
+ if (isset($_SESSION['mreporting_values']['states_id'])) {
+ if (is_array($_SESSION['mreporting_values']['states_id'])) {
+ if ($as_array) {
+ $sql_states[$field] = $_SESSION['mreporting_values']['states_id'];
+ } else {
+ $sql_states = " AND $field IN (" . implode(',', $_SESSION['mreporting_values']['states_id']) . ")";
+ }
+ } else if ($_SESSION['mreporting_values']['states_id'] > 0) {
+ if ($as_array) {
+ $sql_states[$field] = $_SESSION['mreporting_values']['states_id'];
+ } else {
+ $sql_states = " AND $field = " . $_SESSION['mreporting_values']['states_id'];
+ }
}
- }
- }
- return $sql_states;
- }
+ }
+ return $sql_states;
+ }
/* ==== MANUFACTURERS REPORTS ==== */
- function reportPieComputersByFabricant($config = []) {
- $_SESSION['mreporting_selector']['reportPieComputersByFabricant'] = ['multiplestates'];
- return $this->computersByFabricant($config);
- }
-
- function reportHbarComputersByFabricant($config = []) {
- $_SESSION['mreporting_selector']['reportHbarComputersByFabricant'] = ['multiplestates'];
- return $this->computersByFabricant($config);
- }
-
- function computersByFabricant($config = []) {
- global $DB;
-
- $sql_entities = " AND c.`entities_id` IN ({$this->where_entities})";
- $sql_states = self::getStateCondition('c.states_id');
-
- $query = "SELECT m.`name` as Manufacturer,
+ public function reportPieComputersByFabricant($config = [])
+ {
+ $_SESSION['mreporting_selector']['reportPieComputersByFabricant'] = ['multiplestates'];
+ return $this->computersByFabricant($config);
+ }
+
+ public function reportHbarComputersByFabricant($config = [])
+ {
+ $_SESSION['mreporting_selector']['reportHbarComputersByFabricant'] = ['multiplestates'];
+ return $this->computersByFabricant($config);
+ }
+
+ public function computersByFabricant($config = [])
+ {
+ global $DB;
+
+ $sql_entities = " AND c.`entities_id` IN ({$this->where_entities})";
+ $sql_states = self::getStateCondition('c.states_id');
+
+ $query = "SELECT m.`name` as Manufacturer,
count(*) as Total,
count(*) * 100 / (SELECT count(*)
FROM glpi_computers as c,
@@ -123,36 +133,39 @@ function computersByFabricant($config = []) {
AND c.`is_template` = 0
GROUP BY m.`name`
ORDER BY Total DESC";
- $result = $DB->query($query);
+ $result = $DB->query($query);
- $datas = [];
- while ($computer = $DB->fetchAssoc($result)) {
- if ($computer['Total']) {
- $percent = round($computer['Percent'], 2);
- $datas['datas'][$computer['Manufacturer']." ($percent %)"] = $computer['Total'];
- }
- }
+ $datas = [];
+ while ($computer = $DB->fetchAssoc($result)) {
+ if ($computer['Total']) {
+ $percent = round($computer['Percent'], 2);
+ $datas['datas'][$computer['Manufacturer'] . " ($percent %)"] = $computer['Total'];
+ }
+ }
- return $datas;
- }
+ return $datas;
+ }
/* ==== COMPUTER'S TYPE REPORTS ==== */
- function reportPieComputersByType($config = []) {
- $_SESSION['mreporting_selector']['reportPieComputersByType'] = ['multiplestates'];
- return $this->computersByType($config);
- }
-
- function reportHbarComputersByType($config = []) {
- $_SESSION['mreporting_selector']['reportHbarComputersByType'] = ['multiplestates'];
- return $this->computersByType($config);
- }
-
- function computersByType($config = []) {
- global $DB;
-
- $sql_entities = " AND c.`entities_id` IN ({$this->where_entities})";
- $sql_states = self::getStateCondition('c.states_id');
- $query = "SELECT t.`name` as Type,
+ public function reportPieComputersByType($config = [])
+ {
+ $_SESSION['mreporting_selector']['reportPieComputersByType'] = ['multiplestates'];
+ return $this->computersByType($config);
+ }
+
+ public function reportHbarComputersByType($config = [])
+ {
+ $_SESSION['mreporting_selector']['reportHbarComputersByType'] = ['multiplestates'];
+ return $this->computersByType($config);
+ }
+
+ public function computersByType($config = [])
+ {
+ global $DB;
+
+ $sql_entities = " AND c.`entities_id` IN ({$this->where_entities})";
+ $sql_states = self::getStateCondition('c.states_id');
+ $query = "SELECT t.`name` as Type,
count(*) as Total,
count(*) * 100 / (SELECT count(*)
FROM glpi_computers as c,
@@ -171,35 +184,38 @@ function computersByType($config = []) {
AND c.`is_template` = 0
GROUP BY t.`name`
ORDER BY Total DESC";
- $result = $DB->query($query);
- $datas = [];
- while ($computer = $DB->fetchAssoc($result)) {
- $percent = round($computer['Percent'], 2);
- $datas['datas'][$computer['Type']." ($percent %)"] = $computer['Total'];
- }
+ $result = $DB->query($query);
+ $datas = [];
+ while ($computer = $DB->fetchAssoc($result)) {
+ $percent = round($computer['Percent'], 2);
+ $datas['datas'][$computer['Type'] . " ($percent %)"] = $computer['Total'];
+ }
- return $datas;
- }
+ return $datas;
+ }
/* ==== COMPUTER'S AGE REPORTS ==== */
- function reportPieComputersByAge($config = []) {
- $_SESSION['mreporting_selector']['reportPieComputersByAge'] = ['multiplestates'];
- return $this->computersByAge($config);
- }
-
- function reportHbarComputersByAge($config = []) {
- $_SESSION['mreporting_selector']['reportHbarComputersByAge'] = ['multiplestates'];
- return $this->computersByAge($config);
- }
-
- function computersByAge($config = []) {
- global $DB;
-
- $sql_entities = " AND c.`entities_id` IN ({$this->where_entities})";
- $sql_states = self::getStateCondition('c.states_id');
- $datas = [];
+ public function reportPieComputersByAge($config = [])
+ {
+ $_SESSION['mreporting_selector']['reportPieComputersByAge'] = ['multiplestates'];
+ return $this->computersByAge($config);
+ }
+
+ public function reportHbarComputersByAge($config = [])
+ {
+ $_SESSION['mreporting_selector']['reportHbarComputersByAge'] = ['multiplestates'];
+ return $this->computersByAge($config);
+ }
+
+ public function computersByAge($config = [])
+ {
+ global $DB;
+
+ $sql_entities = " AND c.`entities_id` IN ({$this->where_entities})";
+ $sql_states = self::getStateCondition('c.states_id');
+ $datas = [];
- $query = "SELECT '< 1 year' Age, count(*) Total, count(*) * 100 / (SELECT count(*)
+ $query = "SELECT '< 1 year' Age, count(*) Total, count(*) * 100 / (SELECT count(*)
FROM glpi_computers as c,
glpi_infocoms as i
WHERE c.`id` = i.`items_id`
@@ -291,50 +307,53 @@ function computersByAge($config = []) {
AND i.`warranty_date` IS NULL
$sql_entities
$sql_states";
- $result = $DB->query($query);
-
- while ($computer = $DB->fetchAssoc($result)) {
- $percent = round($computer['Percent'], 2);
+ $result = $DB->query($query);
- $datas['datas'][__($computer['Age'], 'mreporting')." ($percent %)"] = $computer['Total'];
- }
+ while ($computer = $DB->fetchAssoc($result)) {
+ $percent = round($computer['Percent'], 2);
- return $datas;
+ $datas['datas'][__($computer['Age'], 'mreporting') . " ($percent %)"] = $computer['Total'];
+ }
- }
+ return $datas;
+ }
/* === OS REPORTS === */
- function reportPieComputersByOS($config = []) {
- $_SESSION['mreporting_selector']['reportPieComputersByOS'] = ['multiplestates'];
- return $this->computersByOS($config);
- }
-
- function reportHbarComputersByOS($config = []) {
- $_SESSION['mreporting_selector']['reportHbarComputersByOS'] = ['multiplestates'];
- return $this->computersByOS($config);
- }
-
- function computersByOS($config = []) {
- global $DB;
-
- $sql_entities = " AND c.`entities_id` IN ({$this->where_entities})";
- $sql_states = self::getStateCondition('c.states_id');
- $oses = ['Windows' => 'Windows',
- 'Linux' => 'Linux|Ubuntu|openSUSE',
- 'Solaris' => 'Solaris',
- 'AIX' => 'AIX',
- 'BSD' => 'BSD',
- 'VMWare' => 'VMWare',
- 'MAC' => 'MAC',
- 'Android' => 'Android',
- 'HP-UX' => 'HP-UX'];
- $query = "";
- $first = true;
- $notlike = "";
- foreach ($oses as $os => $search) {
- $query.=(!$first?" UNION ":"")
- ."\n SELECT '$os' AS OS, count(*) AS Total, count(*) * 100 / (SELECT count(*)
+ public function reportPieComputersByOS($config = [])
+ {
+ $_SESSION['mreporting_selector']['reportPieComputersByOS'] = ['multiplestates'];
+ return $this->computersByOS($config);
+ }
+
+ public function reportHbarComputersByOS($config = [])
+ {
+ $_SESSION['mreporting_selector']['reportHbarComputersByOS'] = ['multiplestates'];
+ return $this->computersByOS($config);
+ }
+
+ public function computersByOS($config = [])
+ {
+ global $DB;
+
+ $sql_entities = " AND c.`entities_id` IN ({$this->where_entities})";
+ $sql_states = self::getStateCondition('c.states_id');
+ $oses = ['Windows' => 'Windows',
+ 'Linux' => 'Linux|Ubuntu|openSUSE',
+ 'Solaris' => 'Solaris',
+ 'AIX' => 'AIX',
+ 'BSD' => 'BSD',
+ 'VMWare' => 'VMWare',
+ 'MAC' => 'MAC',
+ 'Android' => 'Android',
+ 'HP-UX' => 'HP-UX'
+ ];
+ $query = "";
+ $first = true;
+ $notlike = "";
+ foreach ($oses as $os => $search) {
+ $query .= (!$first ? " UNION " : "")
+ . "\n SELECT '$os' AS OS, count(*) AS Total, count(*) * 100 / (SELECT count(*)
FROM glpi_computers as c,
glpi_operatingsystems as os,
glpi_items_operatingsystems as ios
@@ -356,11 +375,11 @@ function computersByOS($config = []) {
$sql_entities
$sql_states";
- $notlike.= " AND os.`name` NOT REGEXP '$search'";
- $first = false;
- }
+ $notlike .= " AND os.`name` NOT REGEXP '$search'";
+ $first = false;
+ }
$query .= " UNION
- SELECT '".__("Others")."' AS OS, count(*) Total, count(*) * 100 / (SELECT count(*)
+ SELECT '" . __("Others") . "' AS OS, count(*) Total, count(*) * 100 / (SELECT count(*)
FROM glpi_computers as c,
glpi_operatingsystems as os,
glpi_items_operatingsystems as ios
@@ -382,343 +401,365 @@ function computersByOS($config = []) {
$sql_entities
$sql_states";
- $query.=" ORDER BY Total DESC";
+ $query .= " ORDER BY Total DESC";
$result = $DB->query($query);
$datas = [];
- while ($computer = $DB->fetchAssoc($result)) {
- $percent = round($computer['Percent'], 2);
- if ($computer['Total']) {
- $datas['datas'][$computer['OS']." ($percent %)"] = $computer['Total'];
- }
- }
+ while ($computer = $DB->fetchAssoc($result)) {
+ $percent = round($computer['Percent'], 2);
+ if ($computer['Total']) {
+ $datas['datas'][$computer['OS'] . " ($percent %)"] = $computer['Total'];
+ }
+ }
return $datas;
- }
-
-
- function reportHbarWindows($config = []) {
- global $DB;
-
- $_SESSION['mreporting_selector']['reportHbarWindows'] = ['multiplestates'];
-
- $sql_states = self::getStateCondition('glpi_computers.states_id', true);
- $total_computers = countElementsInTable(
- 'glpi_computers', [
- 'is_deleted' => 0,
- 'is_template' => 0,
- 'entities_id' => $this->where_entities_array
- ]
- );
-
- $list_windows = ['Windows 3.1', 'Windows 95', 'Windows 98', 'Windows 2000 Pro',
- 'Windows XP', 'Windows 7', 'Windows Vista', 'Windows 8', 'Windows 10',
- 'Windows 2000 Server', 'Server 2003', 'Server 2008', 'Server 2012'];
- $data = [];
- foreach ($list_windows as $windows) {
- $oses = [];
- $ositerator = $DB->request('glpi_operatingsystems', ['name' => ['LIKE', "%$windows%"]]);
- while ($os = $ositerator->next()) {
- $oses[] = $os['id'];
- }
- if (!empty($oses)) {
- $number = countElementsInTable(
- 'glpi_computers', [
- 'INNER JOIN' => [
- 'glpi_items_operatingsystems' => [
+ }
+
+
+ public function reportHbarWindows($config = [])
+ {
+ global $DB;
+
+ $_SESSION['mreporting_selector']['reportHbarWindows'] = ['multiplestates'];
+
+ $sql_states = self::getStateCondition('glpi_computers.states_id', true);
+ $total_computers = countElementsInTable(
+ 'glpi_computers',
+ [
+ 'is_deleted' => 0,
+ 'is_template' => 0,
+ 'entities_id' => $this->where_entities_array
+ ]
+ );
+
+ $oses = $DB->request(
+ [
+ 'SELECT' => [
+ 'glpi_operatingsystems' => 'name AS os_name',
+ 'glpi_operatingsystemversions' => 'name AS os_version',
+ ],
+ 'FROM' => 'glpi_items_operatingsystems',
+ 'COUNT' => 'os_qty',
+ 'INNER JOIN' => [
+ 'glpi_computers' => [
+ 'FKEY' => [
+ 'glpi_items_operatingsystems' => 'items_id',
+ 'glpi_computers' => 'id'
+ ]
+ ],
+ 'glpi_operatingsystems' => [
+ 'FKEY' => [
+ 'glpi_operatingsystems' => 'id',
+ 'glpi_items_operatingsystems' => 'operatingsystems_id'
+ ]
+ ]
+ ],
+ 'LEFT JOIN' => [
+ 'glpi_operatingsystemversions' => [
'FKEY' => [
- 'glpi_computers' => 'id',
- 'glpi_items_operatingsystems' => 'items_id'
+ 'glpi_operatingsystemversions' => 'id',
+ 'glpi_items_operatingsystems' => 'operatingsystemversions_id'
+ ]
+ ]
+ ],
+ 'WHERE' => [
+ 'glpi_operatingsystems.name' => ['LIKE', '%windows%'],
+ 'glpi_items_operatingsystems.itemtype' => 'Computer',
+ 'glpi_computers.is_deleted' => 0,
+ 'glpi_computers.is_template' => 0,
+ 'glpi_computers.entities_id' => $this->where_entities_array,
+ ] + $sql_states,
+ 'GROUPBY' => ['os_name', 'os_version'],
+ 'ORDER' => ['os_name', 'os_version']
+ ]
+ );
+ $data = [];
+ foreach ($oses as $version) {
+ $key = $version['os_name'] . ' ' . $version['os_version'] . ' (' . round($version['os_qty'] / $total_computers * 100) . '%)';
+ $data['datas'][$key] = $version['os_qty'];
+ }
+ if (isset($data['datas']) && !empty($data['datas'])) {
+ arsort($data['datas']);
+ }
+ return $data;
+ }
+
+ public function reportHbarLinux($config = [])
+ {
+ global $DB;
+
+ $_SESSION['mreporting_selector']['reportHbarLinux'] = ['multiplestates'];
+ $sql_states = self::getStateCondition('glpi_computers.states_id', true);
+ $sql_states2 = self::getStateCondition('c.states_id', true);
+
+ $data = [];
+ foreach ($DB->request('glpi_operatingsystems', "name LIKE '%Linux%' OR name LIKE '%Ubuntu%' OR name LIKE '%openSUSE%'") as $os) {
+ $iterator = $DB->request(
+ 'glpi_computers',
+ [
+ 'SELECT' => [
+ 'glpi_operatingsystemversions.name'
+ ],
+ 'COUNT' => 'cpt',
+ 'INNER JOIN' => [
+ 'glpi_items_operatingsystems' => [
+ 'FKEY' => [
+ 'glpi_computers' => 'id',
+ 'glpi_items_operatingsystems' => 'items_id'
+ ]
]
- ]
- ],
- 'WHERE' => [
- 'glpi_items_operatingsystems.operatingsystems_id' => $oses,
- 'glpi_items_operatingsystems.itemtype' => 'Computer',
- 'glpi_computers.is_deleted' => 0,
- 'glpi_computers.is_template' => 0,
- 'glpi_computers.entities_id' => $this->where_entities_array
- ] + $sql_states
- ]
+ ],
+ 'LEFT JOIN' => [
+ 'glpi_operatingsystemversions' => [
+ 'FKEY' => [
+ 'glpi_items_operatingsystems' => 'operatingsystemversions_id',
+ 'glpi_operatingsystemversions' => 'id'
+ ]
+ ]
+ ],
+ 'WHERE' => [
+ 'glpi_items_operatingsystems.operatingsystems_id' => $os['id'],
+ 'glpi_items_operatingsystems.itemtype' => 'Computer',
+ 'glpi_computers.is_deleted' => 0,
+ 'glpi_computers.is_template' => 0,
+ 'glpi_computers.entities_id' => $this->where_entities_array,
+ ] + $sql_states + $sql_states2,
+ 'GROUPBY' => ['operatingsystemversions_id'],
+ 'ORDER' => ['glpi_operatingsystemversions.name']
+ ]
);
- $percent = round($number * 100 / $total_computers). " % du parc";
- if ($number) {
- $data['datas'][$windows." ($percent)"] = $number;
+ foreach ($iterator as $version) {
+ if ($version['name'] != '' && $version['cpt']) {
+ $data['datas'][$os['name'] . " " . $version['name']] = $version['cpt'];
+ }
}
- }
- }
- if (isset($data['datas']) && !empty($data['datas'])) {
- arsort($data['datas']);
- }
- return $data;
- }
-
- function reportHbarLinux($config = []) {
- global $DB;
-
- $_SESSION['mreporting_selector']['reportHbarLinux'] = ['multiplestates'];
- $sql_states = self::getStateCondition('glpi_computers.states_id', true);
- $sql_states2 = self::getStateCondition('c.states_id', true);
-
- $data = [];
- foreach ($DB->request('glpi_operatingsystems', "name LIKE '%Linux%' OR name LIKE '%Ubuntu%' OR name LIKE '%openSUSE%'") as $os) {
- $iterator = $DB->request(
- 'glpi_computers', [
- 'SELECT' => [
- 'glpi_operatingsystemversions.name'
- ],
- 'COUNT' => 'cpt',
- 'INNER JOIN' => [
- 'glpi_items_operatingsystems' => [
- 'FKEY' => [
- 'glpi_computers' => 'id',
- 'glpi_items_operatingsystems' => 'items_id'
- ]
- ]
- ],
- 'LEFT JOIN' => [
- 'glpi_operatingsystemversions' => [
- 'FKEY' => [
- 'glpi_items_operatingsystems' => 'operatingsystemversions_id',
- 'glpi_operatingsystemversions' => 'id'
- ]
- ]
- ],
- 'WHERE' => [
- 'glpi_items_operatingsystems.operatingsystems_id' => $os['id'],
- 'glpi_items_operatingsystems.itemtype' => 'Computer',
- 'glpi_computers.is_deleted' => 0,
- 'glpi_computers.is_template' => 0,
- 'glpi_computers.entities_id' => $this->where_entities_array,
- ] + $sql_states + $sql_states2,
- 'GROUPBY' => ['operatingsystemversions_id'],
- 'ORDER' => ['glpi_operatingsystemversions.name']
- ]
- );
+ }
+ if (isset($data['datas']) && !empty($data['datas'])) {
+ arsort($data['datas']);
+ }
+ return $data;
+ }
+
+ public function reportHbarLinuxDistro($config = [])
+ {
+ global $DB;
+
+ $_SESSION['mreporting_selector']['reportHbarLinuxDistro'] = ['multiplestates'];
+ $sql_states = self::getStateCondition('glpi_computers.states_id', true);
+
+ $data = [];
+ foreach ($DB->request('glpi_operatingsystems', "name LIKE '%Linux%' OR name LIKE '%Ubuntu%' OR name LIKE '%openSUSE%'") as $os) {
+ $number = countElementsInTable(
+ 'glpi_computers',
+ [
+ 'INNER JOIN' => [
+ 'glpi_items_operatingsystems' => [
+ 'FKEY' => [
+ 'glpi_computers' => 'id',
+ 'glpi_items_operatingsystems' => 'items_id'
+ ]
+ ]
+ ],
+ 'WHERE' => [
+ 'glpi_items_operatingsystems.operatingsystems_id' => $os['id'],
+ 'glpi_items_operatingsystems.itemtype' => 'Computer',
+ 'glpi_computers.is_deleted' => 0,
+ 'glpi_computers.is_template' => 0,
+ 'glpi_computers.entities_id' => $this->where_entities_array
+ ] + $sql_states
+ ]
+ );
- while ($version = $iterator->next()) {
- if ($version['name'] != '' && $version['cpt']) {
- $data['datas'][$os['name']. " ".$version['name']] = $version['cpt'];
+ if ($number) {
+ $data['datas'][$os['name']] = $number;
}
- }
- }
- if (isset($data['datas']) && !empty($data['datas'])) {
- arsort($data['datas']);
- }
- return $data;
- }
-
- function reportHbarLinuxDistro($config = []) {
- global $DB;
-
- $_SESSION['mreporting_selector']['reportHbarLinuxDistro'] = ['multiplestates'];
- $sql_states = self::getStateCondition('glpi_computers.states_id', true);
-
- $data = [];
- foreach ($DB->request('glpi_operatingsystems', "name LIKE '%Linux%' OR name LIKE '%Ubuntu%' OR name LIKE '%openSUSE%'") as $os) {
- $number = countElementsInTable(
- 'glpi_computers', [
- 'INNER JOIN' => [
- 'glpi_items_operatingsystems' => [
- 'FKEY' => [
- 'glpi_computers' => 'id',
- 'glpi_items_operatingsystems' => 'items_id'
- ]
- ]
- ],
- 'WHERE' => [
- 'glpi_items_operatingsystems.operatingsystems_id' => $os['id'],
- 'glpi_items_operatingsystems.itemtype' => 'Computer',
- 'glpi_computers.is_deleted' => 0,
- 'glpi_computers.is_template' => 0,
- 'glpi_computers.entities_id' => $this->where_entities_array
- ] + $sql_states
- ]
- );
-
- if ($number) {
- $data['datas'][$os['name']] = $number;
- }
- }
- if (isset($data['datas']) && !empty($data['datas'])) {
- arsort($data['datas']);
- }
- return $data;
- }
-
- function reportHbarMac($config = []) {
- global $DB;
-
- $_SESSION['mreporting_selector']['reportHbarMac'] = ['multiplestates'];
- $sql_states = self::getStateCondition('glpi_computers.states_id', true);
- $sql_states2 = self::getStateCondition('c.states_id', true);
-
- $data = [];
- $ositerator = $DB->request('glpi_operatingsystems', ['name' => ['LIKE', '%Mac OS%']]);
- while ($os = $ositerator->next()) {
- $iterator = $DB->request(
- 'glpi_computers', [
- 'SELECT' => [
- 'glpi_operatingsystemversions.name'
- ],
- 'COUNT' => 'cpt',
- 'INNER JOIN' => [
- 'glpi_items_operatingsystems' => [
- 'FKEY' => [
- 'glpi_computers' => 'id',
- 'glpi_items_operatingsystems' => 'items_id'
- ]
- ]
- ],
- 'LEFT JOIN' => [
- 'glpi_operatingsystemversions' => [
- 'FKEY' => [
- 'glpi_items_operatingsystems' => 'operatingsystemversions_id',
- 'glpi_operatingsystemversions' => 'id'
- ]
- ]
- ],
- 'WHERE' => [
- 'glpi_items_operatingsystems.operatingsystems_id' => $os['id'],
- 'glpi_items_operatingsystems.itemtype' => 'Computer',
- 'glpi_computers.is_deleted' => 0,
- 'glpi_computers.is_template' => 0,
- 'glpi_computers.entities_id' => $this->where_entities_array,
- ] + $sql_states + $sql_states2,
- 'GROUPBY' => ['operatingsystemversions_id'],
- 'ORDER' => ['glpi_operatingsystemversions.name']
- ]
- );
+ }
+ if (isset($data['datas']) && !empty($data['datas'])) {
+ arsort($data['datas']);
+ }
+ return $data;
+ }
+
+ public function reportHbarMac($config = [])
+ {
+ global $DB;
+
+ $_SESSION['mreporting_selector']['reportHbarMac'] = ['multiplestates'];
+ $sql_states = self::getStateCondition('glpi_computers.states_id', true);
+ $sql_states2 = self::getStateCondition('c.states_id', true);
+
+ $data = [];
+ $ositerator = $DB->request('glpi_operatingsystems', ['name' => ['LIKE', '%Mac OS%']]);
+ foreach ($ositerator as $os) {
+ $iterator = $DB->request(
+ 'glpi_computers',
+ [
+ 'SELECT' => [
+ 'glpi_operatingsystemversions.name'
+ ],
+ 'COUNT' => 'cpt',
+ 'INNER JOIN' => [
+ 'glpi_items_operatingsystems' => [
+ 'FKEY' => [
+ 'glpi_computers' => 'id',
+ 'glpi_items_operatingsystems' => 'items_id'
+ ]
+ ]
+ ],
+ 'LEFT JOIN' => [
+ 'glpi_operatingsystemversions' => [
+ 'FKEY' => [
+ 'glpi_items_operatingsystems' => 'operatingsystemversions_id',
+ 'glpi_operatingsystemversions' => 'id'
+ ]
+ ]
+ ],
+ 'WHERE' => [
+ 'glpi_items_operatingsystems.operatingsystems_id' => $os['id'],
+ 'glpi_items_operatingsystems.itemtype' => 'Computer',
+ 'glpi_computers.is_deleted' => 0,
+ 'glpi_computers.is_template' => 0,
+ 'glpi_computers.entities_id' => $this->where_entities_array,
+ ] + $sql_states + $sql_states2,
+ 'GROUPBY' => ['operatingsystemversions_id'],
+ 'ORDER' => ['glpi_operatingsystemversions.name']
+ ]
+ );
- while ($version = $iterator->next()) {
- if ($version['name'] != '' && $version['cpt']) {
- $data['datas'][$os['name']. " ".$version['name']] = $version['cpt'];
+ foreach ($iterator as $version) {
+ if ($version['name'] != '' && $version['cpt']) {
+ $data['datas'][$os['name'] . " " . $version['name']] = $version['cpt'];
+ }
}
- }
- }
- return $data;
- }
-
- function reportHbarMacFamily($config = []) {
- global $DB;
-
- $_SESSION['mreporting_selector']['reportHbarMacFamily'] = ['multiplestates'];
- $sql_states = self::getStateCondition('glpi_computers.states_id', true);
- $sql_states2 = self::getStateCondition('c.states_id', true);
-
- $data = [];
- $ositerator = $DB->request('glpi_operatingsystems', ['name' => ['LIKE', '%Mac OS%']]);
- while ($os = $ositerator->next()) {
- $iterator = $DB->request(
- 'glpi_computers', [
- 'SELECT' => [
- 'glpi_operatingsystemversions.name'
- ],
- 'COUNT' => 'cpt',
- 'INNER JOIN' => [
- 'glpi_items_operatingsystems' => [
- 'FKEY' => [
- 'glpi_computers' => 'id',
- 'glpi_items_operatingsystems' => 'items_id'
- ]
- ]
- ],
- 'LEFT JOIN' => [
- 'glpi_operatingsystemversions' => [
- 'FKEY' => [
- 'glpi_items_operatingsystems' => 'operatingsystemversions_id',
- 'glpi_operatingsystemversions' => 'id'
- ]
- ]
- ],
- 'WHERE' => [
- 'glpi_items_operatingsystems.operatingsystems_id' => $os['id'],
- 'glpi_items_operatingsystems.itemtype' => 'Computer',
- 'glpi_computers.is_deleted' => 0,
- 'glpi_computers.is_template' => 0,
- 'glpi_computers.entities_id' => $this->where_entities_array,
- ] + $sql_states + $sql_states2,
- 'GROUPBY' => ['operatingsystemversions_id'],
- 'ORDER' => ['glpi_operatingsystemversions.name']
- ]
- );
-
- while ($version = $iterator->next()) {
- if ($version['name'] != '' && $version['cpt']) {
- if (preg_match("/(10.[0-9]+)/", $version['name'], $results)) {
- if (!isset($data['datas'][$os['name']. " ".$results[1]])) {
- $data['datas'][$os['name']. " ".$results[1]] = $version['cpt'];
- } else {
- $data['datas'][$os['name']. " ".$results[1]] += $version['cpt'];
- }
- }
+ }
+ return $data;
+ }
+
+ public function reportHbarMacFamily($config = [])
+ {
+ global $DB;
+
+ $_SESSION['mreporting_selector']['reportHbarMacFamily'] = ['multiplestates'];
+ $sql_states = self::getStateCondition('glpi_computers.states_id', true);
+ $sql_states2 = self::getStateCondition('c.states_id', true);
+
+ $data = [];
+ $ositerator = $DB->request('glpi_operatingsystems', ['name' => ['LIKE', '%Mac OS%']]);
+ foreach ($ositerator as $os) {
+ $iterator = $DB->request(
+ 'glpi_computers',
+ [
+ 'SELECT' => [
+ 'glpi_operatingsystemversions.name'
+ ],
+ 'COUNT' => 'cpt',
+ 'INNER JOIN' => [
+ 'glpi_items_operatingsystems' => [
+ 'FKEY' => [
+ 'glpi_computers' => 'id',
+ 'glpi_items_operatingsystems' => 'items_id'
+ ]
+ ]
+ ],
+ 'LEFT JOIN' => [
+ 'glpi_operatingsystemversions' => [
+ 'FKEY' => [
+ 'glpi_items_operatingsystems' => 'operatingsystemversions_id',
+ 'glpi_operatingsystemversions' => 'id'
+ ]
+ ]
+ ],
+ 'WHERE' => [
+ 'glpi_items_operatingsystems.operatingsystems_id' => $os['id'],
+ 'glpi_items_operatingsystems.itemtype' => 'Computer',
+ 'glpi_computers.is_deleted' => 0,
+ 'glpi_computers.is_template' => 0,
+ 'glpi_computers.entities_id' => $this->where_entities_array,
+ ] + $sql_states + $sql_states2,
+ 'GROUPBY' => ['operatingsystemversions_id'],
+ 'ORDER' => ['glpi_operatingsystemversions.name']
+ ]
+ );
+
+ foreach ($iterator as $version) {
+ if ($version['name'] != '' && $version['cpt']) {
+ if (preg_match("/(10.[0-9]+)/", $version['name'], $results)) {
+ if (!isset($data['datas'][$os['name'] . " " . $results[1]])) {
+ $data['datas'][$os['name'] . " " . $results[1]] = $version['cpt'];
+ } else {
+ $data['datas'][$os['name'] . " " . $results[1]] += $version['cpt'];
+ }
+ }
+ }
}
- }
- }
- if (isset($data['datas']) && count($data['datas'])) {
- arsort($data['datas']);
- }
- return $data;
- }
+ }
+ if (isset($data['datas']) && count($data['datas'])) {
+ arsort($data['datas']);
+ }
+ return $data;
+ }
/* ==== FUSIONINVENTORY REPORTS ==== */
- function reportPieFusionInventory($config = []) {
- $_SESSION['mreporting_selector']['reportPieFusionInventory'] = ['multiplestates'];
- return $this->fusionInventory($config);
- }
-
- function reportHbarFusionInventory($config = []) {
- $_SESSION['mreporting_selector']['reportHbarFusionInventory'] = ['multiplestates'];
- return $this->fusionInventory($config);
- }
-
- function fusionInventory($config = []) {
- global $DB;
-
- $plugin = new Plugin();
- if (!$plugin->isActivated('fusioninventory')) {
- return [];
- }
- $sql_states = self::getStateCondition('glpi_computers.states_id', true);
- $total_computers = countElementsInTable(
- 'glpi_computers',
- [
- 'is_deleted' => 0,
- 'is_template' => 0,
- 'entities_id' => $this->where_entities_array,
- ] + $sql_states
- );
-
- $query = "SELECT count(*) AS cpt, `useragent`
+ public function reportPieFusionInventory($config = [])
+ {
+ $_SESSION['mreporting_selector']['reportPieFusionInventory'] = ['multiplestates'];
+ return $this->fusionInventory($config);
+ }
+
+ public function reportHbarFusionInventory($config = [])
+ {
+ $_SESSION['mreporting_selector']['reportHbarFusionInventory'] = ['multiplestates'];
+ return $this->fusionInventory($config);
+ }
+
+ public function fusionInventory($config = [])
+ {
+ global $DB;
+
+ $plugin = new Plugin();
+ if (!$plugin->isActivated('fusioninventory')) {
+ return [];
+ }
+ $sql_states = self::getStateCondition('glpi_computers.states_id', true);
+ $total_computers = countElementsInTable(
+ 'glpi_computers',
+ [
+ 'is_deleted' => 0,
+ 'is_template' => 0,
+ 'entities_id' => $this->where_entities_array,
+ ] + $sql_states
+ );
+
+ $query = "SELECT count(*) AS cpt, `useragent`
FROM `glpi_plugin_fusioninventory_agents`
WHERE `computers_id` > 0
GROUP BY `useragent`
ORDER BY cpt DESC";
- $data = [];
- foreach ($DB->request($query) as $agent) {
- $values = [];
- if (preg_match('/FusionInventory-Agent_v(.*)/i', $agent['useragent'], $values)) {
- $useragent = $values['1'];
- } else {
- $useragent = $agent['useragent'];
- }
- $data['datas'][$useragent] = $agent['cpt'];
-
- }
- return $data;
- }
+ $data = [];
+ foreach ($DB->request($query) as $agent) {
+ $values = [];
+ if (preg_match('/FusionInventory-Agent_v(.*)/i', $agent['useragent'], $values)) {
+ $useragent = $values['1'];
+ } else {
+ $useragent = $agent['useragent'];
+ }
+ $data['datas'][$useragent] = $agent['cpt'];
+ }
+ return $data;
+ }
/* ==== MONITOR REPORST ==== */
- function reportHbarMonitors($config = []) {
- global $DB;
+ public function reportHbarMonitors($config = [])
+ {
+ global $DB;
- $_SESSION['mreporting_selector']['reportHbarMonitors'] = ['multiplestates'];
- $sql_states = self::getStateCondition('c.`states_id`');
+ $_SESSION['mreporting_selector']['reportHbarMonitors'] = ['multiplestates'];
+ $sql_states = self::getStateCondition('c.`states_id`');
- $query = "SELECT COUNT(*) AS cpt
+ $query = "SELECT COUNT(*) AS cpt
FROM `glpi_computers_items` AS ci,
`glpi_computers` AS c
WHERE `ci`.`itemtype` = 'Monitor'
@@ -729,23 +770,24 @@ function reportHbarMonitors($config = []) {
$sql_states
GROUP BY `ci`.`computers_id`
ORDER BY `cpt`";
- $data = [];
- foreach ($DB->request($query) as $result) {
- $label = $result['cpt']." "._n('Monitor', 'Monitors', $result['cpt']);
- if (!isset($data['datas'][$label])) {
- $data['datas'][$label] = 0;
- }
- $data['datas'][$label] = $data['datas'][$label]+1;
- }
-
- return $data;
- }
+ $data = [];
+ foreach ($DB->request($query) as $result) {
+ $label = $result['cpt'] . " " . _n('Monitor', 'Monitors', $result['cpt']);
+ if (!isset($data['datas'][$label])) {
+ $data['datas'][$label] = 0;
+ }
+ $data['datas'][$label] = $data['datas'][$label] + 1;
+ }
+
+ return $data;
+ }
/* ==== COMPUTER'S STATE REPORTS ==== */
- function reportHbarComputersByStatus($config = []) {
- global $DB;
+ public function reportHbarComputersByStatus($config = [])
+ {
+ global $DB;
- $query = "SELECT t.`name` status, count(*) Total, count(*) * 100 / (SELECT count(*)
+ $query = "SELECT t.`name` status, count(*) Total, count(*) * 100 / (SELECT count(*)
FROM glpi_computers as c,
glpi_states as t
WHERE c.`states_id` = t.`id`
@@ -759,24 +801,25 @@ function reportHbarComputersByStatus($config = []) {
AND c.`is_deleted` = 0
AND c.`is_template` = 0
GROUP BY t.`name`";
- $result = $DB->query($query);
- $datas = [];
- while ($computer = $DB->fetchAssoc($result)) {
- $percent = round($computer['Percent'], 2);
- $datas['datas'][$computer['status']." ($percent %)"] = $computer['Total'];
- }
+ $result = $DB->query($query);
+ $datas = [];
+ while ($computer = $DB->fetchAssoc($result)) {
+ $percent = round($computer['Percent'], 2);
+ $datas['datas'][$computer['status'] . " ($percent %)"] = $computer['Total'];
+ }
- return $datas;
- }
+ return $datas;
+ }
- function reportHbarPrintersByStatus($config = []) {
- global $DB;
+ public function reportHbarPrintersByStatus($config = [])
+ {
+ global $DB;
- $datas = [];
+ $datas = [];
- $condition = " AND c.entities_id IN (".$this->where_entities.")";
+ $condition = " AND c.entities_id IN (" . $this->where_entities . ")";
- $query = "SELECT t.name status, count(*) Total, count(*)*100/(
+ $query = "SELECT t.name status, count(*) Total, count(*)*100/(
SELECT count(*)
FROM glpi_printers c, glpi_states t
WHERE c.`is_deleted`=0 AND c.`is_template`=0
@@ -784,49 +827,49 @@ function reportHbarPrintersByStatus($config = []) {
FROM glpi_printers c, glpi_states t
WHERE c.states_id = t.id $condition AND c.`is_deleted`=0 AND c.`is_template`=0
GROUP BY t.name";
- $result = $DB->query($query);
-
- while ($printer = $DB->fetchAssoc($result)) {
- $pourcentage = round($printer['Pourcentage'], 2);
- $datas['datas'][$printer['status']." ($pourcentage %)"] = $printer['Total'];
- }
+ $result = $DB->query($query);
- return $datas;
+ while ($printer = $DB->fetchAssoc($result)) {
+ $pourcentage = round($printer['Pourcentage'], 2);
+ $datas['datas'][$printer['status'] . " ($pourcentage %)"] = $printer['Total'];
+ }
- }
+ return $datas;
+ }
/* ==== COMPUTER'S ENTITIES REPORTS ==== */
- function reportHbarComputersByEntity($config = []) {
- global $DB, $CFG_GLPI;
+ public function reportHbarComputersByEntity($config = [])
+ {
+ global $DB, $CFG_GLPI;
- $_SESSION['mreporting_selector']['reportHbarComputersByEntity'] = ['multiplestates',
- 'entityLevel'];
+ $_SESSION['mreporting_selector']['reportHbarComputersByEntity'] = ['multiplestates',
+ 'entityLevel'
+ ];
- $this->where_entities_level = PluginMreportingCommon::getSQLEntityLevel("`glpi_entities`.`level`");
+ $this->where_entities_level = PluginMreportingCommon::getSQLEntityLevel("`glpi_entities`.`level`");
- $datas = [];
+ $datas = [];
- $entity = new Entity();
- $entity->getFromDB($_SESSION['glpiactive_entity']);
- $entities_first_level = [$_SESSION['glpiactive_entity'] => $entity->getName()];
+ $entity = new Entity();
+ $entity->getFromDB($_SESSION['glpiactive_entity']);
+ $entities_first_level = [$_SESSION['glpiactive_entity'] => $entity->getName()];
- $query = "SELECT `id`, `name`
+ $query = "SELECT `id`, `name`
FROM `glpi_entities`
- WHERE `entities_id` = '".$_SESSION['glpiactive_entity']."'
- AND {$this->where_entities_level}
+ WHERE {$this->where_entities_level}
ORDER BY `name`";
- $result = $DB->query($query);
+ $result = $DB->query($query);
- while ($data = $DB->fetchAssoc($result)) {
- $entities_first_level[$data['id']] = $data['name'];
- }
+ while ($data = $DB->fetchAssoc($result)) {
+ $entities_first_level[$data['id']] = $data['name'];
+ }
$entities = [];
- foreach ($entities_first_level as $entities_id=>$entities_name) {
- if ($entities_id == $_SESSION['glpiactive_entity']) {
- $restrict = " = '".$entities_id."'";
- } else {
- $restrict = "IN (".implode(',', getSonsOf('glpi_entities', $entities_id)).")";
- }
+ foreach ($entities_first_level as $entities_id => $entities_name) {
+ if ($entities_id == $_SESSION['glpiactive_entity']) {
+ $restrict = " = '" . $entities_id . "'";
+ } else {
+ $restrict = "IN (" . implode(',', getSonsOf('glpi_entities', $entities_id)) . ")";
+ }
$query = "SELECT count(*) Total
FROM `glpi_computers`
WHERE `entities_id` " . $restrict . "
@@ -834,29 +877,29 @@ function reportHbarComputersByEntity($config = []) {
AND `is_template` = 0";
$result = $DB->query($query);
- while ($computer = $DB->fetchAssoc($result)) {
- $datas['tmp'][$entities_name." (pourcentage %)"] = $computer['Total'];
- $entities[$entities_name." (pourcentage %)"] = $entities_id;
- }
- }
+ while ($computer = $DB->fetchAssoc($result)) {
+ $datas['tmp'][$entities_name . " (pourcentage %)"] = $computer['Total'];
+ $entities[$entities_name . " (pourcentage %)"] = $entities_id;
+ }
+ }
$total = array_sum($datas['tmp']);
- foreach ($datas['tmp'] as $key=>$value) {
- if ($value == 0) {
- $percent = 0;
- } else {
- $percent = round((100 * $value) / $total);
- }
- $ent_id = $entities[$key];
- $key = str_replace('pourcentage', $percent, $key);
- $datas['datas'][$key] = $value;
- $type = 'under';
- if ($ent_id == $_SESSION['glpiactive_entity']) {
- $type = 'equals';
- }
- $datas['links'][$key] = $CFG_GLPI["root_doc"].'/front/computer.php?is_deleted=0&criteria[0][field]=80&criteria[0][searchtype]='.$type.'&criteria[0][value]='.$ent_id.'&itemtype=Computer&start=0';
- }
+ foreach ($datas['tmp'] as $key => $value) {
+ if ($value == 0) {
+ $percent = 0;
+ } else {
+ $percent = round((100 * $value) / $total);
+ }
+ $ent_id = $entities[$key];
+ $key = str_replace('pourcentage', $percent, $key);
+ $datas['datas'][$key] = $value;
+ $type = 'under';
+ if ($ent_id == $_SESSION['glpiactive_entity']) {
+ $type = 'equals';
+ }
+ $datas['links'][$key] = $CFG_GLPI["root_doc"] . '/front/computer.php?is_deleted=0&criteria[0][field]=80&criteria[0][searchtype]=' . $type . '&criteria[0][value]=' . $ent_id . '&itemtype=Computer&start=0';
+ }
unset($datas['tmp']);
return $datas;
- }
+ }
}
diff --git a/inc/notification.class.php b/inc/notification.class.php
index 72d96ef7..b1a198f8 100644
--- a/inc/notification.class.php
+++ b/inc/notification.class.php
@@ -1,11 +1,39 @@
.
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2003-2023 by Mreporting plugin team.
+ * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
+ * @link https://github.com/pluginsGLPI/mreporting
+ * -------------------------------------------------------------------------
+ */
+
+class PluginMreportingNotification extends CommonDBTM
+{
/**
* @var boolean activate the history for the plugin
*/
- public $dohistory = true;
+ public $dohistory = true;
/**
* Return the localized name of the current Type (PluginMreporting)
@@ -14,106 +42,109 @@ class PluginMreportingNotification extends CommonDBTM {
* @param string $nb
* @return string name of the plugin
*/
- static function getTypeName($nb = 0) {
- return __("More Reporting", 'mreporting');
- }
+ public static function getTypeName($nb = 0)
+ {
+ return __("More Reporting", 'mreporting');
+ }
/**
* Install mreporting notifications.
*
* @return array 'success' => true on success
*/
- static function install($migration) {
- global $DB;
-
- // Création du template de la notification
- $template = new NotificationTemplate();
- $found_template = $template->find(['itemtype' => 'PluginMreportingNotification']);
- if (empty($found_template)) {
- $template_id = $template->add([
- 'name' => __('Notification for "More Reporting"', 'mreporting'),
- 'comment' => "",
- 'itemtype' => __CLASS__,
- ]);
-
- $content_html = __("\nHello,
\n\nGLPI reports are available.
\nYou will find attached in this email.
\n\n", 'mreporting');
-
- // Ajout d'une traduction (texte) en Français
- $translation = new NotificationTemplateTranslation();
- $translation->add([
- 'notificationtemplates_id' => $template_id,
- 'language' => '',
- 'subject' => __("GLPI statistics reports", 'mreporting'),
- 'content_text' => __("Hello,\n\nGLPI reports are available.\nYou will find attached in this email.\n\n", 'mreporting'),
- 'content_html' => $content_html]
- );
-
- // Création de la notification
- $notification = new Notification();
- $notification_id = $notification->add(
- [
- 'name' => __('Notification for "More Reporting"', 'mreporting'),
- 'comment' => "",
- 'entities_id' => 0,
- 'is_recursive' => 1,
- 'is_active' => 1,
- 'itemtype' => __CLASS__,
- 'event' => 'sendReporting',
- ]
- );
-
- $n_n_template = new Notification_NotificationTemplate();
- $n_n_template->add(
- [
- 'notifications_id' => $notification_id,
- 'mode' => Notification_NotificationTemplate::MODE_MAIL,
- 'notificationtemplates_id' => $template_id,
- ]
- );
-
- $DB->query('INSERT INTO glpi_notificationtargets (items_id, type, notifications_id)
+ public static function install($migration)
+ {
+ global $DB;
+
+ // Création du template de la notification
+ $template = new NotificationTemplate();
+ $found_template = $template->find(['itemtype' => 'PluginMreportingNotification']);
+ if (empty($found_template)) {
+ $template_id = $template->add([
+ 'name' => __('Notification for "More Reporting"', 'mreporting'),
+ 'comment' => "",
+ 'itemtype' => __CLASS__,
+ ]);
+
+ $content_html = __("\nHello,
\n\nGLPI reports are available.
\nYou will find attached in this email.
\n\n", 'mreporting');
+
+ // Ajout d'une traduction (texte) en Français
+ $translation = new NotificationTemplateTranslation();
+ $translation->add([
+ 'notificationtemplates_id' => $template_id,
+ 'language' => '',
+ 'subject' => __("GLPI statistics reports", 'mreporting'),
+ 'content_text' => __("Hello,\n\nGLPI reports are available.\nYou will find attached in this email.\n\n", 'mreporting'),
+ 'content_html' => $content_html
+ ]);
+
+ // Création de la notification
+ $notification = new Notification();
+ $notification_id = $notification->add(
+ [
+ 'name' => __('Notification for "More Reporting"', 'mreporting'),
+ 'comment' => "",
+ 'entities_id' => 0,
+ 'is_recursive' => 1,
+ 'is_active' => 1,
+ 'itemtype' => __CLASS__,
+ 'event' => 'sendReporting',
+ ]
+ );
+
+ $n_n_template = new Notification_NotificationTemplate();
+ $n_n_template->add(
+ [
+ 'notifications_id' => $notification_id,
+ 'mode' => Notification_NotificationTemplate::MODE_MAIL,
+ 'notificationtemplates_id' => $template_id,
+ ]
+ );
+
+ $DB->query('INSERT INTO glpi_notificationtargets (items_id, type, notifications_id)
VALUES (1, 1, ' . $notification_id . ');');
- }
+ }
- return ['success' => true];
- }
+ return ['success' => true];
+ }
/**
* Remove mreporting notifications from GLPI.
*
* @return array 'success' => true on success
*/
- static function uninstall() {
- global $DB;
-
- $queries = [];
-
- // Remove NotificationTargets and Notifications
- $notification = new Notification();
- $result = $notification->find(['itemtype' => 'PluginMreportingNotification']);
- foreach ($result as $row) {
- $notification_id = $row['id'];
- $queries[] = "DELETE FROM glpi_notificationtargets WHERE notifications_id = " . $notification_id;
- $queries[] = "DELETE FROM glpi_notifications WHERE id = " . $notification_id;
- }
-
- // Remove NotificationTemplateTranslations and NotificationTemplates
- $template = new NotificationTemplate();
- $result = $template->find(['itemtype' => 'PluginMreportingNotification']);
- foreach ($result as $row) {
- $template_id = $row['id'];
- $queries[] = "DELETE FROM glpi_notificationtemplatetranslations
+ public static function uninstall()
+ {
+ global $DB;
+
+ $queries = [];
+
+ // Remove NotificationTargets and Notifications
+ $notification = new Notification();
+ $result = $notification->find(['itemtype' => 'PluginMreportingNotification']);
+ foreach ($result as $row) {
+ $notification_id = $row['id'];
+ $queries[] = "DELETE FROM glpi_notificationtargets WHERE notifications_id = " . $notification_id;
+ $queries[] = "DELETE FROM glpi_notifications WHERE id = " . $notification_id;
+ }
+
+ // Remove NotificationTemplateTranslations and NotificationTemplates
+ $template = new NotificationTemplate();
+ $result = $template->find(['itemtype' => 'PluginMreportingNotification']);
+ foreach ($result as $row) {
+ $template_id = $row['id'];
+ $queries[] = "DELETE FROM glpi_notificationtemplatetranslations
WHERE notificationtemplates_id = " . $template_id;
- $queries[] = "DELETE FROM glpi_notificationtemplates
+ $queries[] = "DELETE FROM glpi_notificationtemplates
WHERE id = " . $template_id;
- }
+ }
- foreach ($queries as $query) {
- $DB->query($query);
- }
+ foreach ($queries as $query) {
+ $DB->query($query);
+ }
- return ['success' => true];
- }
+ return ['success' => true];
+ }
/**
* Give localized information about 1 task
@@ -122,22 +153,24 @@ static function uninstall() {
*
* @return array of strings
*/
- static function cronInfo($name) {
- switch ($name) {
- case 'SendNotifications' :
- return ['description' => __('Notification for "More Reporting"', 'mreporting')];
- }
- return [];
- }
+ public static function cronInfo($name)
+ {
+ switch ($name) {
+ case 'SendNotifications':
+ return ['description' => __('Notification for "More Reporting"', 'mreporting')];
+ }
+ return [];
+ }
/**
* @param $mailing_options
**/
- static function send($mailing_options, $additional_options) {
+ public static function send($mailing_options, $additional_options)
+ {
- $mail = new PluginMreportingNotificationMail();
- $mail->sendNotification(array_merge($mailing_options, $additional_options));
- }
+ $mail = new PluginMreportingNotificationMail();
+ $mail->sendNotification(array_merge($mailing_options, $additional_options));
+ }
/**
* Execute 1 task manage by the plugin
@@ -149,9 +182,10 @@ static function send($mailing_options, $additional_options) {
* <0 : to be run again (not finished)
* 0 : nothing to do
*/
- static function cronSendNotifications($task) {
- $task->log(__("Notification(s) sent !", 'mreporting'));
- PluginMreportingNotificationEvent::raiseEvent('sendReporting', new self(), $task->fields);
- return 1;
- }
+ public static function cronSendNotifications($task)
+ {
+ $task->log(__("Notification(s) sent !", 'mreporting'));
+ PluginMreportingNotificationEvent::raiseEvent('sendReporting', new self(), $task->fields);
+ return 1;
+ }
}
diff --git a/inc/notificationevent.class.php b/inc/notificationevent.class.php
index e337ae0a..d76046ae 100644
--- a/inc/notificationevent.class.php
+++ b/inc/notificationevent.class.php
@@ -1,121 +1,161 @@
.
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2003-2023 by Mreporting plugin team.
+ * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
+ * @link https://github.com/pluginsGLPI/mreporting
+ * -------------------------------------------------------------------------
+ */
+
if (!defined('GLPI_ROOT')) {
- die("Sorry. You can't access directly to this file");
+ die("Sorry. You can't access directly to this file");
}
/**
* Class which manages notification events
**/
-class PluginMreportingNotificationEvent extends NotificationEvent {
-
- /**
- * Raise a notification event event
- *
- * @param $event the event raised for the itemtype
- * @param $item the object which raised the event
- * @param $options array of options used
- * @param $label used for debugEvent() (default '')
- **/
- static function raiseEvent($event, $item, $options = [], $label = '') {
- global $CFG_GLPI;
-
- //If notifications are enabled in GLPI's configuration
- if ($CFG_GLPI["use_notifications"]) {
- $email_processed = [];
- $email_notprocessed = [];
-
- $options['entities_id'] = 0; //New code
- $notificationtarget = NotificationTarget::getInstance($item, $event, $options);
- if (!$notificationtarget) {
- return false;
- }
-
- //Get template's information
- $template = new NotificationTemplate();
-
- $entity = $notificationtarget->getEntity();
- //Foreach notification
- foreach (Notification::getNotificationsByEventAndType($event, $item->getType(), $entity)
- as $data) {
- $targets = getAllDataFromTable(
- 'glpi_notificationtargets',
- ['notifications_id' => $data['id']]
- );
- $eventClass = Notification_NotificationTemplate::getModeClass($data['mode'], 'event');
- $notificationtarget->setMode($data['mode']);
- $notificationtarget->setEvent($eventClass);
- $notificationtarget->clearAddressesList();
-
- //Process more infos (for example for tickets)
- $notificationtarget->addAdditionnalInfosForTarget();
-
- $template->getFromDB($data['notificationtemplates_id']);
- $template->resetComputedTemplates();
-
- //Set notification's signature (the one which corresponds to the entity)
- $template->setSignature(Notification::getMailingSignature($entity));
-
- $notify_me = Session::isCron() ? true : $_SESSION['glpinotification_to_myself'];
-
- //Foreach notification targets
- foreach ($targets as $target) {
- //Get all users affected by this notification
- $notificationtarget->addForTarget($target, $options);
+class PluginMreportingNotificationEvent extends NotificationEvent
+{
+ /**
+ * Raise a notification event event
+ *
+ * @param string $event the event raised for the itemtype
+ * @param CommonDBTM $item the object which raised the event
+ * @param array $options options used
+ * @param string $label used for debugEvent() (default '')
+ **/
+ public static function raiseEvent($event, $item, $options = [], $label = '')
+ {
+ /** @var array $CFG_GLPI */
+ global $CFG_GLPI;
+
+ //If notifications are enabled in GLPI's configuration
+ if ($CFG_GLPI["use_notifications"]) {
+ $email_processed = [];
+ $email_notprocessed = [];
+
+ $options['entities_id'] = 0; //New code
+ $notificationtarget = NotificationTarget::getInstance($item, $event, $options);
+ if (!$notificationtarget) {
+ return false;
+ }
- foreach ($notificationtarget->getTargets() as $user_email => $users_infos) {
- if ($label
- || $notificationtarget->validateSendTo($event, $users_infos, $notify_me)) {
- //If the user have not yet been notified
- if (!isset($email_processed[$users_infos['language']][$users_infos['email']])) {
- //If ther user's language is the same as the template's one
- if (isset($email_notprocessed[$users_infos['language']]
- [$users_infos['email']])) {
- unset($email_notprocessed[$users_infos['language']]
+ //Get template's information
+ $template = new NotificationTemplate();
+
+ $entity = $notificationtarget->getEntity();
+ //Foreach notification
+ $notifications = Notification::getNotificationsByEventAndType($event, $item->getType(), $entity);
+ foreach ($notifications as $data) {
+ $targets = getAllDataFromTable(
+ 'glpi_notificationtargets',
+ ['notifications_id' => $data['id']]
+ );
+ $eventClass = Notification_NotificationTemplate::getModeClass($data['mode'], 'event');
+ $notificationtarget->setMode($data['mode']);
+ $notificationtarget->setEvent($eventClass);
+ $notificationtarget->clearAddressesList();
+
+ //Process more infos (for example for tickets)
+ $notificationtarget->addAdditionnalInfosForTarget();
+
+ $template->getFromDB($data['notificationtemplates_id']);
+ $template->resetComputedTemplates();
+
+ //Set notification's signature (the one which corresponds to the entity)
+ $template->setSignature(Notification::getMailingSignature($entity));
+
+ $notify_me = Session::isCron() ? true : $_SESSION['glpinotification_to_myself'];
+
+ //Foreach notification targets
+ foreach ($targets as $target) {
+ //Get all users affected by this notification
+ $notificationtarget->addForTarget($target, $options);
+
+ foreach ($notificationtarget->getTargets() as $user_email => $users_infos) {
+ if (
+ $label
+ || $notificationtarget->validateSendTo($event, $users_infos, $notify_me)
+ ) {
+ //If the user have not yet been notified
+ if (!isset($email_processed[$users_infos['language']][$users_infos['email']])) {
+ //If ther user's language is the same as the template's one
+ if (
+ isset($email_notprocessed[$users_infos['language']]
+ [$users_infos['email']])
+ ) {
+ unset($email_notprocessed[$users_infos['language']]
[$users_infos['email']]);
- }
- if ($tid = $template->getTemplateByLanguage($notificationtarget, $users_infos,
- $event, $options)) {
- //Send notification to the user
- if ($label == '') {
- PluginMreportingNotification::send(
- $template->getDataToSend(
- $notificationtarget,
- $tid,
- $users_infos[$eventClass::getTargetFieldName()],
- $users_infos,
- $options
- ),
- $notificationtarget->additionalData
- );
- } else {
- $notificationtarget->getFromDB($target['id']);
- echo "";
- echo "| ".$label." | ";
- echo "".$notificationtarget->getNameID()." | ";
- echo "".sprintf(__('%1$s (%2$s)'), $template->getName(),
- $users_infos['language'])." | ";
- echo "".$users_infos['email']." | ";
- echo "
";
- }
- $email_processed[$users_infos['language']][$users_infos['email']]
+ }
+ if (
+ $tid = $template->getTemplateByLanguage(
+ $notificationtarget,
+ $users_infos,
+ $event,
+ $options
+ )
+ ) {
+ //Send notification to the user
+ if ($label == '') {
+ PluginMreportingNotification::send(
+ $template->getDataToSend(
+ $notificationtarget,
+ $tid,
+ $users_infos[$eventClass::getTargetFieldName()],
+ $users_infos,
+ $options
+ ),
+ $notificationtarget->additionalData
+ );
+ } else {
+ $notificationtarget->getFromDB($target['id']);
+ echo "";
+ echo "| " . $label . " | ";
+ echo "" . $notificationtarget->getNameID() . " | ";
+ echo "" . sprintf(
+ __('%1$s (%2$s)'),
+ $template->getName(),
+ $users_infos['language']
+ ) . " | ";
+ echo "" . $users_infos['email'] . " | ";
+ echo "
";
+ }
+ $email_processed[$users_infos['language']][$users_infos['email']]
= $users_infos;
-
- } else {
- $email_notprocessed[$users_infos['language']][$users_infos['email']]
+ } else {
+ $email_notprocessed[$users_infos['language']][$users_infos['email']]
= $users_infos;
+ }
+ }
}
- }
- }
- }
+ }
+ }
}
- }
- }
- unset($email_processed);
- unset($email_notprocessed);
- $template = null;
- return true;
- }
-
+ }
+ unset($email_processed);
+ unset($email_notprocessed);
+ $template = null;
+ return true;
+ }
}
-
diff --git a/inc/notificationmail.class.php b/inc/notificationmail.class.php
index fea8fd29..786f5586 100644
--- a/inc/notificationmail.class.php
+++ b/inc/notificationmail.class.php
@@ -1,64 +1,93 @@
.
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2003-2023 by Mreporting plugin team.
+ * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
+ * @link https://github.com/pluginsGLPI/mreporting
+ * -------------------------------------------------------------------------
+ */
+
if (!defined('GLPI_ROOT')) {
- die("Sorry. You can't access directly to this file");
+ die("Sorry. You can't access directly to this file");
}
/**
* NotificationMailing class extends phpmail and implements the NotificationInterface
**/
-class PluginMreportingNotificationMail extends NotificationMailing {
-
+class PluginMreportingNotificationMail extends NotificationMailing
+{
/**
* @param $options array
**/
- function sendNotification($options = []) {
+ public function sendNotification($options = [])
+ {
- $mmail = new GLPIMailer();
- $mmail->AddCustomHeader("Auto-Submitted: auto-generated");
- // For exchange
- $mmail->AddCustomHeader("X-Auto-Response-Suppress: OOF, DR, NDR, RN, NRN");
+ $mmail = new GLPIMailer();
+ $mmail->AddCustomHeader("Auto-Submitted: auto-generated");
+ // For exchange
+ $mmail->AddCustomHeader("X-Auto-Response-Suppress: OOF, DR, NDR, RN, NRN");
- $mmail->SetFrom($options['from'], $options['fromname'], false);
+ $mmail->SetFrom($options['from'], $options['fromname'], false);
- if ($options['replyto']) {
- $mmail->AddReplyTo($options['replyto'], $options['replytoname']);
- }
- $mmail->Subject = $options['subject'];
+ if ($options['replyto']) {
+ $mmail->AddReplyTo($options['replyto'], $options['replytoname']);
+ }
+ $mmail->Subject = $options['subject'];
- if (empty($options['content_html'])) {
- $mmail->isHTML(false);
- $mmail->Body = $options['content_text'];
- } else {
- $mmail->isHTML(true);
- $mmail->Body = $options['content_html'];
- $mmail->AltBody = $options['content_text'];
- }
+ if (empty($options['content_html'])) {
+ $mmail->isHTML(false);
+ $mmail->Body = $options['content_text'];
+ } else {
+ $mmail->isHTML(true);
+ $mmail->Body = $options['content_html'];
+ $mmail->AltBody = $options['content_text'];
+ }
- $mmail->AddAddress($options['to'], $options['toname']);
+ $mmail->AddAddress($options['to'], $options['toname']);
- if (!empty($options['messageid'])) {
- $mmail->MessageID = "<".$options['messageid'].">";
- }
+ if (!empty($options['messageid'])) {
+ $mmail->MessageID = "<" . $options['messageid'] . ">";
+ }
- // Attach pdf to mail
- $mmail->AddAttachment($options['attachment']['path'], $options['attachment']['name']);
+ // Attach pdf to mail
+ $mmail->AddAttachment($options['attachment']['path'], $options['attachment']['name']);
- $messageerror = __('Error in sending the email');
+ $messageerror = __('Error in sending the email');
- if (!$mmail->Send()) {
- $senderror = true;
- Session::addMessageAfterRedirect($messageerror."
".$mmail->ErrorInfo, true);
- } else {
- //TRANS to be written in logs %1$s is the to email / %2$s is the subject of the mail
- Toolbox::logInFile("mail", sprintf(__('%1$s: %2$s'),
- sprintf(__('An email was sent to %s'), $options['to']),
- $options['subject']."\n"));
- }
-
- $mmail->ClearAddresses();
- return true;
- }
+ if (!$mmail->Send()) {
+ $senderror = true;
+ Session::addMessageAfterRedirect($messageerror . "
" . $mmail->ErrorInfo, true);
+ } else {
+ //TRANS to be written in logs %1$s is the to email / %2$s is the subject of the mail
+ Toolbox::logInFile("mail", sprintf(
+ __('%1$s: %2$s'),
+ sprintf(__('An email was sent to %s'), $options['to']),
+ $options['subject'] . "\n"
+ ));
+ }
+ $mmail->ClearAddresses();
+ return true;
+ }
}
-
diff --git a/inc/notificationtargetnotification.class.php b/inc/notificationtargetnotification.class.php
index 977dbf1a..dd8e5a3f 100644
--- a/inc/notificationtargetnotification.class.php
+++ b/inc/notificationtargetnotification.class.php
@@ -1,33 +1,65 @@
__('More Reporting', 'mreporting')];
- }
-
- function getTags() {
- $this->addTagToList(['tag' => 'mreporting.file_url',
- 'label' => __('Link'),
- 'value' => true]);
-
- asort($this->tag_descriptions);
- }
-
- function addDataForTemplate($event, $options = []) {
- global $CFG_GLPI;
-
- $file_name = $this->_buildPDF(mt_rand().'_');
-
- $this->data['##lang.mreporting.file_url##'] = __('Link');
- $this->data['##mreporting.file_url##'] = $CFG_GLPI['url_base'].
+/**
+ * -------------------------------------------------------------------------
+ * Mreporting plugin for GLPI
+ * -------------------------------------------------------------------------
+ *
+ * LICENSE
+ *
+ * This file is part of Mreporting.
+ *
+ * Mreporting is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mreporting is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mreporting. If not, see .
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2003-2023 by Mreporting plugin team.
+ * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
+ * @link https://github.com/pluginsGLPI/mreporting
+ * -------------------------------------------------------------------------
+ */
+
+class PluginMreportingNotificationTargetNotification extends NotificationTarget
+{
+ public $additionalData;
+
+ public function getEvents()
+ {
+ return ['sendReporting' => __('More Reporting', 'mreporting')];
+ }
+
+ public function getTags()
+ {
+ $this->addTagToList(['tag' => 'mreporting.file_url',
+ 'label' => __('Link'),
+ 'value' => true
+ ]);
+
+ asort($this->tag_descriptions);
+ }
+
+ public function addDataForTemplate($event, $options = [])
+ {
+ global $CFG_GLPI;
+
+ $file_name = $this->buildPDF(mt_rand() . '_');
+
+ $this->data['##lang.mreporting.file_url##'] = __('Link');
+ $this->data['##mreporting.file_url##'] = $CFG_GLPI['url_base'] .
"/index.php?redirect=plugin_mreporting_$file_name";
- $this->additionalData['attachment']['path'] = GLPI_PLUGIN_DOC_DIR."/mreporting/notifications/".$file_name;
- $this->additionalData['attachment']['name'] = $file_name;
- }
+ $this->additionalData['attachment']['path'] = GLPI_PLUGIN_DOC_DIR . "/mreporting/notifications/" . $file_name;
+ $this->additionalData['attachment']['name'] = $file_name;
+ }
/**
@@ -35,104 +67,107 @@ function addDataForTemplate($event, $options = []) {
*
* @return string hash Name of the created file
*/
- private function _buildPDF($user_name = '') {
- global $CFG_GLPI, $DB, $LANG;
+ private function buildPDF($user_name = '')
+ {
+ global $CFG_GLPI, $DB, $LANG;
- $dir = GLPI_PLUGIN_DOC_DIR.'/mreporting/notifications';
+ $dir = GLPI_PLUGIN_DOC_DIR . '/mreporting/notifications';
- if (!is_dir($dir)) {
- return false;
- }
+ if (!is_dir($dir)) {
+ return false;
+ }
- setlocale(LC_TIME, 'fr_FR.utf8', 'fra');
- ini_set('memory_limit', '256M');
- set_time_limit(300);
+ setlocale(LC_TIME, 'fr_FR.utf8', 'fra');
+ ini_set('memory_limit', '256M');
+ set_time_limit(300);
- $images = [];
+ $images = [];
- $result = $DB->query('SELECT id, name, classname, default_delay
+ $result = $DB->query('SELECT id, name, classname, default_delay
FROM glpi_plugin_mreporting_configs
WHERE is_notified = 1
AND is_active = 1');
- $graphs = [];
- while ($graph = $result->fetch_array()) {
- $type = preg_split('/(?<=\\w)(?=[A-Z])/', $graph['name']);
-
- $graphs[] = [
- 'class' => substr($graph['classname'], 16),
- 'classname' => $graph['classname'],
- 'method' => $graph['name'],
- 'type' => $type[1],
- 'start' => date('Y-m-d', strtotime(date('Y-m-d 00:00:00').
- ' -'.$graph['default_delay'].' day')),
- 'end' => date('Y-m-d', strtotime(date('Y-m-d 00:00:00').' -1 day')),
- ];
- }
-
- foreach ($graphs as $graph) {
- $_REQUEST = ['switchto' => 'png',
- 'short_classname' => $graph['class'],
- 'f_name' => $graph['method'],
- 'gtype' => $graph['type'],
- 'date1PluginMreporting'.$graph['class'].$graph['method'] => $graph['start'],
- 'date2PluginMreporting'.$graph['class'].$graph['method'] => $graph['end'],
- 'randname' => 'PluginMreporting'.$graph['class'].$graph['method'],
- 'hide_title' => false]; //New code
-
- ob_start();
- $common = new PluginMreportingCommon();
- $common->showGraph($_REQUEST, false, 'PNG');
- $content = ob_get_clean();
-
- preg_match_all('/
fetch_array()) {
+ $type = preg_split('/(?<=\\w)(?=[A-Z])/', $graph['name']);
+
+ $graphs[] = [
+ 'class' => substr($graph['classname'], 16),
+ 'classname' => $graph['classname'],
+ 'method' => $graph['name'],
+ 'type' => $type[1],
+ 'start' => date('Y-m-d', strtotime(date('Y-m-d 00:00:00') .
+ ' -' . $graph['default_delay'] . ' day')),
+ 'end' => date('Y-m-d', strtotime(date('Y-m-d 00:00:00') . ' -1 day')),
+ ];
+ }
+
+ foreach ($graphs as $graph) {
+ $_REQUEST = ['switchto' => 'png',
+ 'short_classname' => $graph['class'],
+ 'f_name' => $graph['method'],
+ 'gtype' => $graph['type'],
+ 'date1PluginMreporting' . $graph['class'] . $graph['method'] => $graph['start'],
+ 'date2PluginMreporting' . $graph['class'] . $graph['method'] => $graph['end'],
+ 'randname' => 'PluginMreporting' . $graph['class'] . $graph['method'],
+ 'hide_title' => false
+ ]; //New code
+
+ ob_start();
+ $common = new PluginMreportingCommon();
+ $common->showGraph($_REQUEST, false, 'PNG');
+ $content = ob_get_clean();
+
+ preg_match_all('/
$image_title,
- 'base64' => $image_base64,
- 'width' => $image_width,
- 'height' => $image_height]);
- }
-
- $file_name = 'glpi_report_'.$user_name.date('d-m-Y').'.pdf';
-
- $pdf = new PluginMreportingPdf();
- $pdf->Init();
- $pdf->Content($images);
- $pdf->Output($dir.'/'.$file_name, 'F');
-
- // Return the generated filename
- return $file_name;
- }
+
+ $image_title = $LANG['plugin_mreporting'][$graph['class']][$graph['method']]['title'];
+ $image_title .= " du " . strftime($format, strtotime($graph['start']));
+ $image_title .= " au " . strftime('%e %B %Y', strtotime($graph['end']));
+
+ array_push($images, ['title' => $image_title,
+ 'base64' => $image_base64,
+ 'width' => $image_width,
+ 'height' => $image_height
+ ]);
+ }
+
+ $file_name = 'glpi_report_' . $user_name . date('d-m-Y') . '.pdf';
+
+ $pdf = new PluginMreportingPdf();
+ $pdf->Init();
+ $pdf->Content($images);
+ $pdf->Output($dir . '/' . $file_name, 'F');
+
+ // Return the generated filename
+ return $file_name;
+ }
}
diff --git a/inc/other.class.php b/inc/other.class.php
index 9e35a3c5..cb4caef5 100644
--- a/inc/other.class.php
+++ b/inc/other.class.php
@@ -1,124 +1,129 @@
.
- --------------------------------------------------------------------------
+/**
+ * -------------------------------------------------------------------------
+ * Mreporting plugin for GLPI
+ * -------------------------------------------------------------------------
+ *
+ * LICENSE
+ *
+ * This file is part of Mreporting.
+ *
+ * Mreporting is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mreporting is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mreporting. If not, see .
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2003-2023 by Mreporting plugin team.
+ * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
+ * @link https://github.com/pluginsGLPI/mreporting
+ * -------------------------------------------------------------------------
*/
-class PluginMreportingOther Extends PluginMreportingBaseclass {
-
- function reportHbarLogs($configs = []) {
- global $DB;
+class PluginMreportingOther extends PluginMreportingBaseclass
+{
+ public function reportHbarLogs($configs = [])
+ {
+ global $DB;
- //Init delay value
- $this->sql_date = PluginMreportingCommon::getSQLDate("`glpi_tickets`.`date`",
- $configs['delay'], $configs['randname']);
+ //Init delay value
+ $this->sql_date = PluginMreportingCommon::getSQLDate(
+ "`glpi_tickets`.`date`",
+ $configs['delay'],
+ $configs['randname']
+ );
- $prefix = "SELECT count(*) as cpt FROM `glpi_logs` WHERE ";
- //Add/remove a software on a computer
- $query_software = "$prefix `linked_action` IN (4,5)";
+ $prefix = "SELECT count(*) as cpt FROM `glpi_logs` WHERE ";
+ //Add/remove a software on a computer
+ $query_software = "$prefix `linked_action` IN (4,5)";
- //Add/remove a software on a computer
- $query_computer_software = "$prefix `linked_action` IN (4,5)";
+ //Add/remove a software on a computer
+ $query_computer_software = "$prefix `linked_action` IN (4,5)";
- $query_software_version = "$prefix `itemtype`='Software'
+ $query_software_version = "$prefix `itemtype`='Software'
AND `itemtype_link`='SoftwareVersion'
AND `linked_action` IN (17, 18, 19)";
- $query_add_infocom = "$prefix `itemtype`='Software'
+ $query_add_infocom = "$prefix `itemtype`='Software'
AND `itemtype_link`='Infocom'
AND `linked_action` IN (17)";
- $query_user_profiles = "$prefix `itemtype`='User'
+ $query_user_profiles = "$prefix `itemtype`='User'
AND `itemtype_link`='Profile_User'
AND `linked_action` IN (17, 18, 19)";
- $query_user_groups = "$prefix `itemtype`='User'
+ $query_user_groups = "$prefix `itemtype`='User'
AND `itemtype_link`='Group_User'
AND `linked_action` IN (17, 18, 19)";
- $query_user_deleted = "$prefix `itemtype`='User' AND `linked_action` IN (12)";
+ $query_user_deleted = "$prefix `itemtype`='User' AND `linked_action` IN (12)";
- $query_ocs = "$prefix `linked_action` IN (8, 9, 10, 11)";
- $query_device = "$prefix `linked_action` IN (1, 2, 3, 6, 7)";
- $query_relation = "$prefix `linked_action` IN (15, 16)";
- $query_item = "$prefix `linked_action` IN (13, 14, 17, 18, 19, 20)";
- $query_other = "$prefix `id_search_option` IN (16, 19)";
+ $query_ocs = "$prefix `linked_action` IN (8, 9, 10, 11)";
+ $query_device = "$prefix `linked_action` IN (1, 2, 3, 6, 7)";
+ $query_relation = "$prefix `linked_action` IN (15, 16)";
+ $query_item = "$prefix `linked_action` IN (13, 14, 17, 18, 19, 20)";
+ $query_other = "$prefix `id_search_option` IN (16, 19)";
- $datas = [];
+ $datas = [];
- $result = $DB->query($query_computer_software);
- $datas['datas'][__('Add/remove software on a computer', 'mreporting')] = $DB->result($result, 0, 'cpt');
+ $result = $DB->query($query_computer_software);
+ $datas['datas'][__('Add/remove software on a computer', 'mreporting')] = $DB->result($result, 0, 'cpt');
- $result = $DB->query($query_software_version);
- $datas['datas'][__('Add/remove version on a software', 'mreporting')] = $DB->result($result, 0, 'cpt');
+ $result = $DB->query($query_software_version);
+ $datas['datas'][__('Add/remove version on a software', 'mreporting')] = $DB->result($result, 0, 'cpt');
- $result = $DB->query($query_add_infocom);
- $datas['datas'][__('Add infocom', 'mreporting')] = $DB->result($result, 0, 'cpt');
+ $result = $DB->query($query_add_infocom);
+ $datas['datas'][__('Add infocom', 'mreporting')] = $DB->result($result, 0, 'cpt');
- $result = $DB->query($query_user_profiles);
- $datas['datas'][__('Add/remove profile on a user', 'mreporting')] = $DB->result($result, 0, 'cpt');
+ $result = $DB->query($query_user_profiles);
+ $datas['datas'][__('Add/remove profile on a user', 'mreporting')] = $DB->result($result, 0, 'cpt');
- $result = $DB->query($query_user_groups);
- $datas['datas'][__('Add/remove group on a user', 'mreporting')] = $DB->result($result, 0, 'cpt');
+ $result = $DB->query($query_user_groups);
+ $datas['datas'][__('Add/remove group on a user', 'mreporting')] = $DB->result($result, 0, 'cpt');
- $result = $DB->query($query_user_deleted);
- $datas['datas'][__('User deleted from LDAP', 'mreporting')] = $DB->result($result, 0, 'cpt');
+ $result = $DB->query($query_user_deleted);
+ $datas['datas'][__('User deleted from LDAP', 'mreporting')] = $DB->result($result, 0, 'cpt');
- $plugin = new Plugin();
- if ($plugin->isActivated("webservices")) {
- $query_webservice = "$prefix `itemtype`='PluginWebservicesClient'";
+ $plugin = new Plugin();
+ if ($plugin->isActivated("webservices")) {
+ $query_webservice = "$prefix `itemtype`='PluginWebservicesClient'";
- // Display this information is not usefull if webservices is not activated
- $result = $DB->query($query_webservice);
- $datas['datas'][__('Webservice logs', 'mreporting')] = $DB->result($result, 0, 'cpt');
- }
+ // Display this information is not usefull if webservices is not activated
+ $result = $DB->query($query_webservice);
+ $datas['datas'][__('Webservice logs', 'mreporting')] = $DB->result($result, 0, 'cpt');
+ }
- $result = $DB->query($query_ocs);
- $datas['datas'][__('OCS Infos', 'mreporting')] = $DB->result($result, 0, 'cpt');
+ $result = $DB->query($query_ocs);
+ $datas['datas'][__('OCS Infos', 'mreporting')] = $DB->result($result, 0, 'cpt');
- $result = $DB->query($query_device);
- $datas['datas'][__('Add/update/remove device', 'mreporting')] = $DB->result($result, 0, 'cpt');
+ $result = $DB->query($query_device);
+ $datas['datas'][__('Add/update/remove device', 'mreporting')] = $DB->result($result, 0, 'cpt');
- $result = $DB->query($query_relation);
- $datas['datas'][__('Add/remove relation', 'mreporting')] = $DB->result($result, 0, 'cpt');
+ $result = $DB->query($query_relation);
+ $datas['datas'][__('Add/remove relation', 'mreporting')] = $DB->result($result, 0, 'cpt');
- $result = $DB->query($query_item);
- $datas['datas'][__('Add/remove item', 'mreporting')] = $DB->result($result, 0, 'cpt');
+ $result = $DB->query($query_item);
+ $datas['datas'][__('Add/remove item', 'mreporting')] = $DB->result($result, 0, 'cpt');
- $result = $DB->query($query_other);
- $datas['datas'][__('Comments & date_mod changes', 'mreporting')] = $DB->result($result, 0, 'cpt');
+ $result = $DB->query($query_other);
+ $datas['datas'][__('Comments & date_mod changes', 'mreporting')] = $DB->result($result, 0, 'cpt');
- $plugin = new Plugin();
- if ($plugin->isActivated("genericobject")) {
- $query_genericobject = "$prefix `itemtype` LIKE '%PluginGenericobject%'";
+ $plugin = new Plugin();
+ if ($plugin->isActivated("genericobject")) {
+ $query_genericobject = "$prefix `itemtype` LIKE '%PluginGenericobject%'";
- // Display this information is not usefull if genericobject is not activated
- $result = $DB->query($query_genericobject);
- $datas['datas'][__('Genericobject plugin logs', 'mreporting')] = $DB->result($result, 0, 'cpt');
- }
+ // Display this information is not usefull if genericobject is not activated
+ $result = $DB->query($query_genericobject);
+ $datas['datas'][__('Genericobject plugin logs', 'mreporting')] = $DB->result($result, 0, 'cpt');
+ }
- return $datas;
- }
+ return $datas;
+ }
/**
* Preconfig datas with your values when init config is done
@@ -128,36 +133,33 @@ function reportHbarLogs($configs = []) {
* @param PluginMreportingConfig $config
* @return $config
*/
- function preconfig($funct_name, $classname, PluginMreportingConfig $config) {
-
- if ($funct_name != -1 && $classname) {
-
- $ex_func = preg_split('/(?<=\\w)(?=[A-Z])/', $funct_name);
- if ($ex_func[0] != 'report') {
- return false;
- }
- $gtype = strtolower($ex_func[1]);
-
- switch ($gtype) {
- case 'pie':
- $config->fields["name"]=$funct_name;
- $config->fields["classname"]=$classname;
- $config->fields["is_active"]="1";
- $config->fields["show_label"]="hover";
- $config->fields["spline"]="0";
- $config->fields["show_area"]="0";
- $config->fields["show_graph"]="1";
- $config->fields["default_delay"]="30";
- $config->fields["show_label"]="hover";
- break;
- default :
- $config->preconfig($funct_name, $classname);
- break;
-
- }
-
- }
- return $config->fields;
- }
-
+ public function preconfig($funct_name, $classname, PluginMreportingConfig $config)
+ {
+
+ if ($funct_name != -1 && $classname) {
+ $ex_func = preg_split('/(?<=\\w)(?=[A-Z])/', $funct_name);
+ if ($ex_func[0] != 'report') {
+ return false;
+ }
+ $gtype = strtolower($ex_func[1]);
+
+ switch ($gtype) {
+ case 'pie':
+ $config->fields["name"] = $funct_name;
+ $config->fields["classname"] = $classname;
+ $config->fields["is_active"] = "1";
+ $config->fields["show_label"] = "hover";
+ $config->fields["spline"] = "0";
+ $config->fields["show_area"] = "0";
+ $config->fields["show_graph"] = "1";
+ $config->fields["default_delay"] = "30";
+ $config->fields["show_label"] = "hover";
+ break;
+ default:
+ $config->preconfig($funct_name, $classname);
+ break;
+ }
+ }
+ return $config->fields;
+ }
}
diff --git a/inc/pdf.class.php b/inc/pdf.class.php
index 61c24896..0eb7668b 100644
--- a/inc/pdf.class.php
+++ b/inc/pdf.class.php
@@ -1,70 +1,107 @@
.
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2003-2023 by Mreporting plugin team.
+ * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
+ * @link https://github.com/pluginsGLPI/mreporting
+ * -------------------------------------------------------------------------
+ */
+
if (!defined('GLPI_ROOT')) {
- die("Sorry. You can't access directly to this file");
+ die("Sorry. You can't access directly to this file");
}
-class PluginMreportingPdf extends TCPDF {
-
+class PluginMreportingPdf extends TCPDF
+{
/**
* Create PDF header and initialize presentation
*/
- function Init() {
- global $CFG_GLPI;
+ // @codingStandardsIgnoreStart
+ public function Init()
+ {
+ // @codingStandardsIgnoreEnd
+ global $CFG_GLPI;
- $title = __("GLPI statistics reports", 'mreporting');
- $creator = __("Automaticaly generated by GLPI", 'mreporting');
- $version = plugin_version_mreporting();
- $author = $CFG_GLPI["version"].' - ' . $version['name'].' v' . $version['version'];
+ $title = __("GLPI statistics reports", 'mreporting');
+ $creator = __("Automaticaly generated by GLPI", 'mreporting');
+ $version = plugin_version_mreporting();
+ $author = $CFG_GLPI["version"] . ' - ' . $version['name'] . ' v' . $version['version'];
- $this->SetCreator($creator);
- $this->SetAuthor($author);
- $this->SetTitle($title);
+ $this->SetCreator($creator);
+ $this->SetAuthor($author);
+ $this->SetTitle($title);
- $this->SetFontSize(10);
- $this->SetMargins(20, 25);
+ $this->SetFontSize(10);
+ $this->SetMargins(20, 25);
- $this->SetAutoPageBreak(true);
+ $this->SetAutoPageBreak(true);
- $this->setHeaderFont([PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN]);
- $this->SetHeaderMargin(PDF_MARGIN_HEADER);
- $this->AddPage();
- }
+ $this->setHeaderFont([PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN]);
+ $this->SetHeaderMargin(PDF_MARGIN_HEADER);
+ $this->AddPage();
+ }
/**
* Insert content and graphs
*
* @param array $images Array of reports
*/
- function Content($images) {
- $images_lengh = sizeof($images);
- $i = 0;
- foreach ($images as $image) {
- $i++;
- $file = '@' . base64_decode($image['base64']);
- $w = 210 - PDF_MARGIN_LEFT * 2;
+ // @codingStandardsIgnoreStart
+ public function Content($images)
+ {
+ // @codingStandardsIgnoreEnd
+ $images_lengh = sizeof($images);
+ $i = 0;
+ foreach ($images as $image) {
+ $i++;
+ $file = '@' . base64_decode($image['base64']);
+ $w = 210 - PDF_MARGIN_LEFT * 2;
- if ($image['width'] == 0) {
- continue;
- }
+ if ($image['width'] == 0) {
+ continue;
+ }
- $h = floor(($image['height'] * $w) / $image['width']);
- $this->Image($file, '', '', $w, $h);
- $this->Ln($h);
+ $h = floor(($image['height'] * $w) / $image['width']);
+ $this->Image($file, '', '', $w, $h);
+ $this->Ln($h);
- $this->writeHTMLCell('', '', '', '', $image['title'], 0, 1, false, true, 'C');
- if ($i < $images_lengh) {
- $this->AddPage();
- }
- }
- }
+ $this->writeHTMLCell('', '', '', '', $image['title'], 0, 1, false, true, 'C');
+ if ($i < $images_lengh) {
+ $this->AddPage();
+ }
+ }
+ }
/**
* Create the PDF footer
*/
- function Footer() {
- $this->SetY(-15);
- $this->SetFontSize(8);
- $this->writeHTMLCell('', '', '', '', date('Y-m-d H:i:s'), 0, 0, false, true, 'R');
- }
+ // @codingStandardsIgnoreStart
+ public function Footer()
+ {
+
+ $this->SetY(-15);
+ $this->SetFontSize(8);
+ $this->writeHTMLCell('', '', '', '', date('Y-m-d H:i:s'), 0, 0, false, true, 'R');
+ }
}
diff --git a/inc/preference.class.php b/inc/preference.class.php
index ee0168ba..6e6dd546 100644
--- a/inc/preference.class.php
+++ b/inc/preference.class.php
@@ -1,49 +1,52 @@
.
- --------------------------------------------------------------------------
+/**
+ * -------------------------------------------------------------------------
+ * Mreporting plugin for GLPI
+ * -------------------------------------------------------------------------
+ *
+ * LICENSE
+ *
+ * This file is part of Mreporting.
+ *
+ * Mreporting is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mreporting is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mreporting. If not, see .
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2003-2023 by Mreporting plugin team.
+ * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
+ * @link https://github.com/pluginsGLPI/mreporting
+ * -------------------------------------------------------------------------
*/
-class PluginMreportingPreference extends CommonDBTM {
-
- static function checkIfPreferenceExists($users_id) {
- return self::checkPreferenceValue('id', $users_id);
- }
-
- function addDefaultPreference($users_id) {
- $id = self::checkIfPreferenceExists($users_id);
- if (!$id) {
- $input["users_id"] = $users_id;
- $input["template"] = "";
- $input["selectors"] = null;
-
- $id = $this->add($input);
- }
- return $id;
- }
+class PluginMreportingPreference extends CommonDBTM
+{
+ public static function checkIfPreferenceExists($users_id)
+ {
+ return self::checkPreferenceValue('id', $users_id);
+ }
+
+ public function addDefaultPreference($users_id)
+ {
+ $id = self::checkIfPreferenceExists($users_id);
+ if (!$id) {
+ $input["users_id"] = $users_id;
+ $input["template"] = "";
+ $input["selectors"] = null;
+
+ $id = $this->add($input);
+ }
+ return $id;
+ }
/**
*
@@ -52,29 +55,36 @@ function addDefaultPreference($users_id) {
* @param unknown_type user ID
* @return preference value or 0
*/
- static function checkPreferenceValue($field, $users_id = 0) {
- $data = getAllDataFromTable(getTableForItemType(__CLASS__), ['users_id' => $users_id]);
- if (!empty($data)) {
- $first = array_pop($data);
- return $first[$field];
- } else {
- return 0;
- }
- }
-
- static function checkPreferenceTemplateValue($users_id) {
- return self::checkPreferenceValue('template', $users_id);
- }
+ public static function checkPreferenceValue($field, $users_id = 0)
+ {
+ $data = getAllDataFromTable(getTableForItemType(__CLASS__), ['users_id' => $users_id]);
+ if (!empty($data)) {
+ $first = array_pop($data);
+ return $first[$field];
+ } else {
+ return 0;
+ }
+ }
+
+ public static function checkPreferenceTemplateValue($users_id)
+ {
+ return self::checkPreferenceValue('template', $users_id);
+ }
/**
*
* Display a dropdown of all ODT template files available
* @param $value default value
*/
- static function dropdownFileTemplates($value = '') {
- return self::dropdownListFiles('template', PLUGIN_MREPORTING_TEMPLATE_EXTENSION,
- PLUGIN_MREPORTING_TEMPLATE_DIR, $value);
- }
+ public static function dropdownFileTemplates($value = '')
+ {
+ return self::dropdownListFiles(
+ 'template',
+ PLUGIN_MREPORTING_TEMPLATE_EXTENSION,
+ PLUGIN_MREPORTING_TEMPLATE_DIR,
+ $value
+ );
+ }
/**
@@ -85,116 +95,122 @@ static function dropdownFileTemplates($value = '') {
* @param $directory directory in which to look for files
* @param $value default value
*/
- static function dropdownListFiles($name, $extension, $directory, $value = '') {
- $files = self::getFiles($directory, $extension);
- $values = [];
- if (empty($files)) {
- $values[0] = Dropdown::EMPTY_VALUE;
- }
- foreach ($files as $file) {
- $values[$file[0]] = $file[0];
- }
- return Dropdown::showFromArray($name, $values, ['value' => $value]);
- }
+ public static function dropdownListFiles($name, $extension, $directory, $value = '')
+ {
+ $files = self::getFiles($directory, $extension);
+ $values = [];
+ if (empty($files)) {
+ $values[0] = Dropdown::EMPTY_VALUE;
+ }
+ foreach ($files as $file) {
+ $values[$file[0]] = $file[0];
+ }
+ return Dropdown::showFromArray($name, $values, ['value' => $value]);
+ }
/**
*
* Check if at least one template exists
* @return true if at least one template exists, false otherwise
*/
- static function atLeastOneTemplateExists() {
- $files = self::getFiles(PLUGIN_MREPORTING_TEMPLATE_DIR, PLUGIN_MREPORTING_TEMPLATE_EXTENSION);
- return (!empty($files));
- }
-
- function showForm($ID) {
- $this->getFromDB($ID);
-
- $version = plugin_version_mreporting();
-
- echo "