Пример #1
0
* @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();
 /**
  * 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;
 }