function plugin_init_mreporting() { global $PLUGIN_HOOKS; $PLUGIN_HOOKS['redirect_page']['mreporting'] = 'front/download.php'; /* CRSF */ $PLUGIN_HOOKS['csrf_compliant']['mreporting'] = true; /* Profile */ $PLUGIN_HOOKS['change_profile']['mreporting'] = array('PluginMreportingProfile', 'changeProfile'); Plugin::registerClass('PluginMreportingNotification', array('notificationtemplates_types' => true)); //Plugin::registerClass('PluginMreportingNotificationTargetNotification'); if (Session::getLoginUserID()) { Plugin::registerClass('PluginMreportingProfile', array('addtabon' => 'Profile')); if ($_SESSION['glpiactiveprofile']['interface'] != "helpdesk") { Plugin::registerClass('PluginMreportingPreference', array('addtabon' => array('Preference'))); } /* Reports Link */ if (plugin_mreporting_haveRight("reports", "r")) { $menu_entry = "front/central.php"; $PLUGIN_HOOKS['menu_entry']['mreporting'] = $menu_entry; $PLUGIN_HOOKS['submenu_entry']['mreporting']['search'] = $menu_entry; } /* Configuration Link */ if (plugin_mreporting_haveRight("config", "w")) { $config_entry = 'front/config.php'; $PLUGIN_HOOKS['config_page']['mreporting'] = $config_entry; $PLUGIN_HOOKS['submenu_entry']['mreporting']['config'] = $config_entry; $PLUGIN_HOOKS['submenu_entry']['mreporting']['options']['config']['links']['config'] = '/plugins/mreporting/' . $config_entry; $PLUGIN_HOOKS['submenu_entry']['mreporting']['options']['config']['links']['add'] = '/plugins/mreporting/front/config.form.php'; } /* Show Reports in standart stats page */ if (class_exists('PluginMreportingCommon')) { $mreporting_common = new PluginMreportingCommon(); $reports = $mreporting_common->getAllReports(); if ($reports !== false) { foreach ($reports as $report) { foreach ($report['functions'] as $func) { $PLUGIN_HOOKS['stats']['mreporting'][$func['min_url_graph']] = $func['title']; } } } } } if (class_exists('PluginMreportingProfile')) { // only if plugin activated $PLUGIN_HOOKS['pre_item_purge']['mreporting'] = array('Profile' => array('PluginMreportingProfile', 'purgeProfiles')); } // Add specific files to add to the header : javascript $PLUGIN_HOOKS['add_javascript']['mreporting'][] = "lib/protovis/protovis.min.js"; $PLUGIN_HOOKS['add_javascript']['mreporting'][] = "lib/protovis-msie/protovis-msie.min.js"; $PLUGIN_HOOKS['add_javascript']['mreporting'][] = "lib/protovis-extjs-tooltips.js"; //Add specific files to add to the header : css $PLUGIN_HOOKS['add_css']['mreporting'] = array("mreporting.css"); }
https://forge.indepnet.net/projects/mreporting ------------------------------------------------------------------------- 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 <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ include "../../../inc/includes.php"; header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); Html::includeHeader(""); echo "<div class='debug_content'>"; $common = new PluginMreportingCommon(); $common->debugGraph(); echo "</div></div></div>"; echo "</body></html>";
* @version $Id: HEADER 15930 2011-10-30 15:47:55Z tsmr $ ------------------------------------------------------------------------- Mreporting plugin for GLPI Copyright (C) 2003-2011 by the mreporting Development Team. https://forge.indepnet.net/projects/mreporting ------------------------------------------------------------------------- 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 <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ include "../../../inc/includes.php"; Html::header($LANG['plugin_mreporting']["name"], '', "plugins", "mreporting"); $common = new PluginMreportingCommon(); $common->showGraph($_REQUEST); Html::footer();
/** * Compile Tree datas * * @param $datas, ex : * array( * 'key1' => array('key1.1' => val, 'key1.2' => val, 'key1.3' => val), * 'key2' => array('key2.1' => val, 'key2.2' => val, 'key2.3' => val) * ) * @param $unit, ex : '%', 'Kg' (optionnal) * @return nothing */ function initDatasTree($datas, $unit = '') { $datas = PluginMreportingCommon::compileDatasForUnit($datas, $unit); echo "var datas = " . json_encode($datas) . ";"; echo "var sum = " . PluginMreportingMisc::getArraySum($datas) . ";"; return $datas; }
function showSunburst($params) { $criterias = PluginMreportingCommon::initGraphParams($params); foreach ($criterias as $key => $val) { ${$key} = $val; } if (self::DEBUG_CSV && isset($raw_datas)) { Toolbox::logdebug($raw_datas); } if (isset($raw_datas['datas'])) { $datas = $raw_datas['datas']; } else { $datas = array(); } if (count($datas) <= 0) { return false; } $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); foreach ($configs as $k => $v) { ${$k} = $v; } if ($unit == '%') { $datas = PluginMreportingCommon::compileDatasForUnit($datas, $unit); } $options = array("title" => $title, "desc" => $desc, "randname" => $randname, "export" => $export); $this->initGraph($options); $out = $title . " - " . $desc . "\r\n"; $out .= $this->sunburstLevel($datas); echo $out; }
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 <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ include "../../../inc/includes.php"; Html::header($LANG['plugin_mreporting']["name"], '', "plugins", "mreporting"); $common = new PluginMreportingCommon(); /*** Regular Tab ***/ $reports = $common->getAllReports(); $tabs = array(); foreach ($reports as $classname => $report) { $tabs[$classname] = array('title' => $report['title'], 'url' => $CFG_GLPI['root_doc'] . "/plugins/mreporting/ajax/common.tabs.php", 'params' => "target=" . $_SERVER['PHP_SELF'] . "&classname={$classname}"); } /*** DEBUG Tab ***/ if (DEBUG_MREPORTING) { $tabs['debug'] = array('title' => "DEBUG", 'url' => $CFG_GLPI['root_doc'] . "/plugins/mreporting/ajax/debug.php"); } if (count($tabs) > 0) { echo "<div id='tabspanel' class='center-h'></div>"; Ajax::createTabs('tabspanel', 'tabcontent', $tabs, 'PluginMreportingCommon'); $common->addDivForTabs(); } else {
------------------------------------------------------------------------- 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 <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ include "../../../inc/includes.php"; Session::checkLoginUser(); if (isset($_GET["classname"])) { $_POST["classname"] = $_GET["classname"]; } Html::popHeader($LANG['plugin_mreporting']["export"][0], $_SERVER['PHP_SELF']); $common = new PluginMreportingCommon(); $common->showExportForm($_POST); echo "<div class='center'><br><a href='javascript:window.close()'>" . __("Close") . "</a>"; echo "</div>"; Html::popFooter();
static function generateOdt($params) { global $LANG; $config = array('PATH_TO_TMP' => GLPI_DOC_DIR . '/_tmp'); if (PluginMreportingPreference::atLeastOneTemplateExists()) { $template = PluginMreportingPreference::checkPreferenceTemplateValue(Session::getLoginUserID()); $withdatas = $params[0]["withdata"]; if ($withdatas == 0) { $odf = new odf("../templates/withoutdata.odt", $config); } else { $odf = new odf("../templates/{$template}", $config); } $titre = ''; $short_classname = str_replace('PluginMreporting', '', $params[0]['class']); if (isset($LANG['plugin_mreporting'][$short_classname]['title'])) { $titre = $LANG['plugin_mreporting'][$short_classname]['title']; } $odf->setVars('titre', $titre, true, 'UTF-8'); $newpage = $odf->setSegment('newpage'); foreach ($params as $result => $page) { // Default values of parameters $title = ""; $f_name = ""; $raw_datas = array(); foreach ($page as $key => $val) { ${$key} = $val; } $datas = $raw_datas['datas']; $labels2 = array(); if (isset($raw_datas['labels2'])) { $labels2 = $raw_datas['labels2']; } $configs = PluginMreportingConfig::initConfigParams($f_name, $class); foreach ($configs as $k => $v) { ${$k} = $v; } if ($unit == '%') { $datas = PluginMreportingCommon::compileDatasForUnit($datas, $unit); } $newpage->setVars('message', $title, true, 'UTF-8'); $path = GLPI_PLUGIN_DOC_DIR . "/mreporting/" . $f_name . ".png"; if ($show_graph) { $newpage->setImage('image', $path); } else { $newpage->setVars('image', "", true, 'UTF-8'); } if ($withdatas > 0) { $simpledatas = false; //simple array if (!$labels2) { $labels2 = array(); $simpledatas = true; } if ($flip_data == true) { $labels2 = array_flip($labels2); } $types = array(); foreach ($datas as $k => $v) { if (is_array($v)) { foreach ($v as $key => $val) { if (isset($labels2[$key])) { $types[$key][$k] = $val; } } } else { $types[$k] = $v; } } if ($flip_data != true) { $tmp = $datas; $datas = $types; $types = $tmp; } //simple array if ($simpledatas) { $label = $LANG['plugin_mreporting']["export"][1]; if ($template == "word.odt") { $newpage->data0->label_0(utf8_decode($label)); $newpage->data0->merge(); } else { $newpage->csvdata->setVars('TitreCategorie', $label, true, 'UTF-8'); } if ($template == "word.odt") { foreach ($types as $label2 => $cols) { $newpage->csvdata->label1->label_1(utf8_decode($label2)); $newpage->csvdata->label1->merge(); if (!empty($unit)) { $cols = $cols . " " . $unit; } $newpage->csvdata->data1->data_1($cols); $newpage->csvdata->merge(); } } else { foreach ($types as $label2 => $cols) { if (!empty($unit)) { $cols = $cols . " " . $unit; } $newpage->csvdata->csvdata2->label_1(utf8_decode($label2)); $newpage->csvdata->csvdata2->data_1($cols); $newpage->csvdata->csvdata2->merge(); } $newpage->csvdata->merge(); } } else { if ($template == "word.odt") { foreach ($datas as $label => $val) { $newpage->data0->label_0(utf8_decode($label)); $newpage->data0->merge(); } foreach ($types as $label2 => $cols) { $newpage->csvdata->label1->label_1(utf8_decode($label2)); $newpage->csvdata->label1->merge(); foreach ($cols as $date => $nb) { if (!empty($unit)) { $nb = $nb . " " . $unit; } if (!is_array($nb)) { $newpage->csvdata->data1->data_1(utf8_decode($nb)); } $newpage->csvdata->data1->merge(); } $newpage->csvdata->merge(); } } else { foreach ($types as $label2 => $cols) { foreach ($cols as $label1 => $nb) { if (!empty($unit)) { $nb = $nb . " " . $unit; } $newpage->csvdata->setVars('TitreCategorie', $label2, true, 'UTF-8'); $newpage->csvdata->csvdata2->setVars('label_1', utf8_decode($label1), true, 'UTF-8'); if (!is_array($nb)) { $newpage->csvdata->csvdata2->setVars('data_1', utf8_decode($nb), true, 'UTF-8'); } $newpage->csvdata->csvdata2->merge(); } $newpage->csvdata->merge(); } } } } $newpage->merge(); } $odf->mergeSegment($newpage); // We export the file $odf->exportAsAttachedFile(); unset($_SESSION['glpi_plugin_mreporting_odtarray']); } }
/** * Show a multi-area chart * * @param $raw_datas : an array with : * - key 'datas', ex : array( 'test1' => 15, 'test2' => 25) * - key 'unit', ex : '%', 'Kg' (optionnal) * - key 'spline', curves line (boolean - optionnal) * @param $title : title of the chart * @param $desc : description of the chart (optionnal) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) * @return nothing */ function showGArea($params) { global $LANG; $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 = array(); } $options = array("title" => $title, "desc" => $desc, "randname" => $randname, "export" => $export, "delay" => $delay, "short_classname" => $opt["short_classname"]); $this->initGraph($options); if (count($datas) <= 0) { if ($export != "odtall") { echo $LANG['plugin_mreporting']["error"][1]; $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']; $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($datas); if ($nb_bar > 1) { $percent = 2 * (450 + 18 * $nb_bar) / (18 * $nb_bar * 100); } else { $percent = 0.2; } $height = $percent * 450 + 18 * $nb_bar; $delta = 450 - $height; $height_tot = 450 + $height; $width_line = ($width - 45) / $nb; $index1 = 0; $index3 = 1; $step = ceil($nb / 20); //create image $image = imagecreatetruecolor($width, $height_tot); if ($show_graph) { //colors $palette = self::getPalette($nb_bar); $alphapalette = self::getPalette($nb_bar, "50"); $darkerpalette = self::getDarkerPalette($nb_bar); //background $bg_color = $this->white; imagefilledrectangle($image, 0, 0, $width - 1, $height_tot - 1, $bg_color); //draw x-axis grey step line and value ticks $xstep = round(($height + $delta + 40) / 13); for ($i = 0; $i < 13; $i++) { $yaxis = $height_tot - 30 - $xstep * $i; //horizontal grey lines imageLine($image, 30, $yaxis, 30 + $width_line * ($nb - 1), $yaxis, $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, $this->darkgrey, $this->font, $val); } //draw y-axis vertical grey step line for ($i = 0; $i < $nb; $i++) { $xaxis = 30 + $width_line * $i; imageLine($image, $xaxis, $height - 40, $xaxis, $height_tot, $this->grey); } //draw y-axis imageLine($image, 30, $height - 40, 30, $height_tot - 25, $this->black); //draw y-axis imageLine($image, 30, $height_tot - 30, $width - 50, $height_tot - 30, $this->black); //create border on export if ($export) { imagerectangle($image, 0, 0, $width - 1, $height_tot - 1, $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, $this->black, $this->font, $title); } //parse datas foreach ($datas as $label => $data) { $aCoords = array(); $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 + 30; $y1 = $height_tot - 30 - $old_data * ($height_tot - $height) / $max; $x2 = $x1 + $width_line; $y2 = $height_tot - 30 - $subdata * ($height_tot - $height) / $max; //in case of area chart fill under point space if ($area > 0) { $points = array($x1, $y1, $x2, $y2, $x2, $height_tot - 30, $x1, $height_tot - 30); imagefilledpolygon($image, $points, 4, $alphapalette[$index1]); } //trace lines between points (if linear) if (!$spline) { $this->imageSmoothAlphaLineLarge($image, $x1, $y1, $x2, $y2, $palette[$index1]); } $aCoords[$x1] = $y1; $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); $index2 = 0; $old_data = 0; $old_label = ""; } //draw labels and dots $index2 = 0; $old_data = 0; foreach ($data as $subdata) { //if first index, continue if ($index2 == 0) { $old_data = $subdata; $old_label = $label; $index2++; continue; } // determine coords $x1 = $index2 * $width_line - $width_line + 30; $y1 = $height_tot - 30 - $old_data * ($height_tot - $height) / $max; $x2 = $x1 + $width_line; $y2 = $height_tot - 30 - $subdata * ($height_tot - $height) / $max; //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, array(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, $darkerpalette[$index1], $this->font, $old_data); } //show x-axis ticks if ($step != 0 && $index3 / $step == round($index3 / $step)) { imageline($image, $x1, $height_tot - 30, $x1, $height_tot - 27, $darkerpalette[$index1]); } $old_data = $subdata; $old_label = $label; $index2++; $index3++; } /*** 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, array(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, $darkerpalette[$index1], $this->font, $old_data); } } /*** end display last value ***/ $index1++; } //display labels2 $index = 0; foreach ($labels2 as $label) { $x = $index * $width_line + 20; if ($step != 0 && $index / $step == round($index / $step)) { imagettftext($image, $this->fontsize - 1, $this->fontangle, $x, $height_tot - 10, $this->black, $this->font, $label); } $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, 35 + $index * 14, $this->black, $this->font, $label); //legend circle $color_rbg = self::colorHexToRGB($palette[$index]); imageSmoothArc($image, 10, 30 + $index * 14, 7, 7, $color_rbg, 0, 2 * M_PI); $index++; } } //generate image $params = array("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 = array("opt" => $opt, "export" => $export, "datas" => $datas, "labels2" => $labels2, "flip_data" => $flip_data, "unit" => $unit); PluginMreportingCommon::endGraph($options); }
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 <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ include "../../../inc/includes.php"; header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); if ($_REQUEST['switchto'] == 'odt' || $_REQUEST['switchto'] == 'odtall') { require_once '../lib/odtphp/odf.php'; } if (PluginMreportingPreference::atLeastOneTemplateExists()) { $template = PluginMreportingPreference::checkPreferenceTemplateValue(Session::getLoginUserID()); if ($template) { $common = new PluginMreportingCommon(); $common->export($_REQUEST); } else { Session::addMessageAfterRedirect($LANG['plugin_mreporting']["parser"][2], false, ERROR); Html::redirect("../../../front/preference.php"); } } else { Session::addMessageAfterRedirect($LANG['plugin_mreporting']["parser"][3], false, ERROR); Html::back(); }
https://forge.indepnet.net/projects/mreporting ------------------------------------------------------------------------- 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 <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ include "../../../inc/includes.php"; header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); $common = new PluginMreportingCommon(); switch ($_POST['classname']) { default: $common->showCentral($_REQUEST); break; } Html::ajaxFooter();
/** * Generate a PDF file with mreporting reports to be send in the notifications * * @return string hash Name of the created file */ private function _buildPDF($user_name = '') { global $CFG_GLPI, $DB, $LANG; $dir = GLPI_PLUGIN_DOC_DIR . '/mreporting/notifications'; $file_name = 'glpi_report_' . $user_name . date('d-m-Y') . '.pdf'; if (!is_dir($dir)) { return false; } require_once GLPI_ROOT . '/plugins/mreporting/lib/tcpdf/tcpdf.php'; $CFG_GLPI['default_graphtype'] = "png"; setlocale(LC_TIME, 'fr_FR.utf8', 'fra'); $graphs = array(); $images = array(); $query = 'SELECT id, name, classname, default_delay FROM glpi_plugin_mreporting_configs WHERE is_notified = 1 AND is_active = 1'; $result = $DB->query($query); while ($graph = $result->fetch_array()) { $type = preg_split('/(?<=\\w)(?=[A-Z])/', $graph['name']); $graphs[] = array('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) { ob_start(); $_REQUEST = array('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']); $common = new PluginMreportingCommon(); $common->showGraph($_REQUEST); $content = ob_get_clean(); preg_match_all('/<img .*?(?=src)src=\'([^\']+)\'/si', $content, $matches); if (empty($matches[1][2])) { continue; } if (strpos($matches[1][2], 'data:image/png;base64,') === false) { continue; } $image_base64 = str_replace('data:image/png;base64,', '', $matches[1][2]); $image = imagecreatefromstring(base64_decode($image_base64)); $image_width = imagesx($image); $image_height = imagesy($image); $image_title = $LANG['plugin_mreporting'][$graph['class']][$graph['method']]['title']; $format = '%e'; if (strftime('%Y', strtotime($graph['start'])) != strftime('%Y', strtotime($graph['end']))) { $format .= ' %B %Y'; } elseif (strftime('%B', strtotime($graph['start'])) != strftime('%B', strtotime($graph['end']))) { $format .= ' %B'; } $image_title .= " du " . strftime($format, strtotime($graph['start'])); $image_title .= " au " . strftime('%e %B %Y', strtotime($graph['end'])); array_push($images, array('title' => $image_title, 'base64' => $image_base64, 'width' => $image_width, 'height' => $image_height)); } $pdf = new PluginMreportingPdf(); $pdf->Init(); $pdf->Content($images); $pdf->Output($dir . '/' . $file_name, 'F'); // Return the generated filename return $file_name; }
function plugin_mreporting_giveItem($type, $ID, $data, $num) { global $LANG; $searchopt =& Search::getOptions($type); $table = $searchopt[$ID]["table"]; $field = $searchopt[$ID]["field"]; $output_type = Search::HTML_OUTPUT; if (isset($_GET['display_type'])) { $output_type = $_GET['display_type']; } switch ($type) { case 'PluginMreportingConfig': switch ($table . '.' . $field) { case "glpi_plugin_mreporting_configs.show_label": $out = ' '; if (!empty($data["ITEM_{$num}"])) { $out = PluginMreportingConfig::getLabelTypeName($data["ITEM_{$num}"]); } return $out; break; case "glpi_plugin_mreporting_configs.name": $out = ' '; if (!empty($data["ITEM_{$num}"])) { $title_func = ''; $short_classname = ''; $f_name = ''; $inc_dir = GLPI_ROOT . "/plugins/mreporting/inc"; //parse inc dir to search report classes $classes = PluginMreportingCommon::parseAllClasses($inc_dir); foreach ($classes as $classname) { $functions = get_class_methods($classname); foreach ($functions as $funct_name) { $ex_func = preg_split('/(?<=\\w)(?=[A-Z])/', $funct_name); if ($ex_func[0] != 'report') { continue; } $gtype = strtolower($ex_func[1]); if ($data["ITEM_{$num}"] == $funct_name) { if (!empty($classname) && !empty($funct_name)) { $short_classname = str_replace('PluginMreporting', '', $classname); if (isset($LANG['plugin_mreporting'][$short_classname][$funct_name]['title'])) { $title_func = $LANG['plugin_mreporting'][$short_classname][$funct_name]['title']; } } } } } $out = "<a href='config.form.php?id=" . $data["id"] . "'>" . $data["ITEM_{$num}"] . "</a> (" . $title_func . ")"; } return $out; break; } return ""; break; } return ""; }
/** * show not used Graphs dropdown * @name name of dropdown * @options array example $value *@return nothing **/ static function dropdownGraph($name, $options = array()) { $self = new self(); $common = new PluginMreportingCommon(); $rand = mt_rand(); $select = "<select name='{$name}' id='dropdown_" . $name . $rand . "'>"; $select .= "<option value='-1' selected>" . Dropdown::EMPTY_VALUE . "</option>"; $i = 0; $reports = $common->getAllReports(); foreach ($reports as $classname => $report) { foreach ($report['functions'] as $function) { if (!$self->getFromDBByFunctionAndClassname($function["function"], $classname)) { $graphs[$classname][$function['category_func']][] = $function; } } if (isset($graphs[$classname])) { $count = count($graphs[$classname]); if ($count > 0) { $select .= "<optgroup label=\"" . $report['title'] . "\">"; $count = count($graphs[$classname]); if ($count > 0) { foreach ($graphs[$classname] as $cat => $graph) { $select .= "<optgroup label=\"" . $cat . "\">"; foreach ($graph as $k => $v) { $comment = ""; if (isset($v["desc"])) { $comment = $v["desc"]; $desc = " (" . $comment . ")"; } $select .= "<option title=\"" . Html::cleanInputText($comment) . "\" \n value='" . $classname . ";" . $v["function"] . "'" . ($options['value'] == $classname . ";" . $v["function"] ? " selected " : "") . ">"; $select .= $v["title"] . $desc; $select .= "</option>"; $i++; } $select .= "</optgroup>"; } } $select .= "</optgroup>"; } } } $select .= "</select>"; echo $select; return $rand; }