Example #1
0
 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']);
     }
 }
Example #2
0
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";
if (!isset($_GET["id"])) {
    $_GET["id"] = "";
}
$pref = new PluginMreportingPreference();
if (isset($_POST["update"])) {
    $pref->update($_POST);
    Html::redirect($_SERVER['HTTP_REFERER']);
} else {
    Html::header($LANG['plugin_mreporting']["name"], '', "plugins", "mreporting");
    $pref->showForm("./preference.form.php", $_GET["id"]);
    Html::footer();
}
Example #3
0
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();
}