/** Get groups assigned to tickets between 2 dates * @param $entrees array : array containing data to displayed * @param $options array : options * - title string title displayed (default empty) * - showtotal boolean show total in title (default false) * - width integer width of the graph (default 700) * - height integer height of the graph (default 300) * - unit integer height of the graph (default empty) * - type integer height of the graph (default line) : line bar pie * - csv boolean export to CSV (default true) * @return array contains the distinct groups assigned to a tickets */ static function showGraph(array $entrees, $options = array()) { global $CFG_GLPI, $LANG; //stevenes donato $ScreenWidth = "undefined"; if (!isset($_GET['screen_check']) && !isset($_GET['date1'])) { echo ' <script> document.location="' . $_SERVER["REQUEST_URI"] . '?screen_check=done&Width="+screen.width+"&Height="+screen.height; </script>'; exit; } if (!isset($_GET['screen_check']) && isset($_GET['date1'])) { echo ' <script> document.location="' . $_SERVER["REQUEST_URI"] . '&screen_check=done&Width="+screen.width+"&Height="+screen.height; </script>'; exit; } if (isset($_GET['Width'])) { $ScreenWidth = $_GET['Width']; } else { $ScreenWidth = 400; } //echo "Screen width = $ScreenWidth"; $CFG_GLPI["root_doc"] // stevenes if ($uid = Session::getLoginUserID(false)) { if (!isset($_SESSION['glpigraphtype'])) { $_SESSION['glpigraphtype'] = $CFG_GLPI['default_graphtype']; } $param['showtotal'] = false; $param['title'] = ''; // $param['width'] = $_SESSION['plugin_mobile']['screen_width'] - 50; // $param['width'] = $ScreenWidth - 50; $param['width'] = $ScreenWidth - 50; $param['height'] = 200; $param['unit'] = ''; $param['type'] = 'line'; $param['csv'] = true; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $param[$key] = $val; } } // Clean data if (is_array($entrees) && count($entrees)) { foreach ($entrees as $key => $val) { if (!is_array($val) || count($val) == 0) { unset($entrees[$key]); } } } if (!is_array($entrees) || count($entrees) == 0) { if (!empty($param['title'])) { echo "<h3>" . $param['title'] . " : </h3>" . $LANG['stats'][2] . "<br />"; } return false; } switch ($param['type']) { case 'pie': // Check datas : sum must be > 0 reset($entrees); $sum = array_sum(current($entrees)); while ($sum == 0 && ($data = next($entrees))) { $sum += array_sum($data); } if ($sum == 0) { return false; } $graph = new ezcGraphPieChart(); $graph->palette = new GraphPalette(); $graph->options->font->maxFontSize = 15; $graph->title->background = '#EEEEEC'; $graph->renderer = new ezcGraphRenderer3d(); $graph->renderer->options->pieChartHeight = 20; $graph->renderer->options->moveOut = 0.2; $graph->renderer->options->pieChartOffset = 63; $graph->renderer->options->pieChartGleam = 0.3; $graph->renderer->options->pieChartGleamColor = '#FFFFFF'; $graph->renderer->options->pieChartGleamBorder = 2; $graph->renderer->options->pieChartShadowSize = 5; $graph->renderer->options->pieChartShadowColor = '#BABDB6'; break; case 'bar': $graph = new ezcGraphBarChart(); $graph->options->fillLines = 210; $graph->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedBoxedLabelRenderer(); $graph->xAxis->axisLabelRenderer->angle = 45; $graph->xAxis->axisSpace = 0.2; $graph->yAxis->min = 0; $graph->palette = new GraphPalette(); $graph->options->font->maxFontSize = 15; $graph->title->background = '#EEEEEC'; $graph->renderer = new ezcGraphRenderer3d(); $graph->renderer->options->legendSymbolGleam = 0.5; $graph->renderer->options->barChartGleam = 0.5; $max = 0; foreach ($entrees as $key => $val) { if (count($val) > $max) { $max = count($val); } } $graph->xAxis->labelCount = $max; break; case 'line': // No break default case // No break default case default: $graph = new ezcGraphLineChart(); $graph->options->fillLines = 210; $graph->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedLabelRenderer(); $graph->xAxis->axisLabelRenderer->angle = 45; $graph->xAxis->axisSpace = 0.2; $graph->yAxis->min = 0; $graph->palette = new GraphPalette(); $graph->options->font->maxFontSize = 15; $graph->title->background = '#EEEEEC'; $graph->renderer = new ezcGraphRenderer3d(); $graph->renderer->options->legendSymbolGleam = 0.5; $graph->renderer->options->barChartGleam = 0.5; $graph->renderer->options->depth = 0.07000000000000001; break; } if (!empty($param['title'])) { $pretoadd = ""; $posttoadd = ""; if (!empty($param['unit'])) { $posttoadd = " " . $param['unit']; $pretoadd = " - "; } // Add to title if (count($entrees) == 1) { $param['title'] .= $pretoadd; if ($param['showtotal'] == 1) { reset($entrees); $param['title'] .= array_sum(current($entrees)); } $param['title'] .= $posttoadd; } else { // add sum to legend and unit to title $param['title'] .= $pretoadd . $posttoadd; if ($param['showtotal'] == 1) { $entree_tmp = $entrees; $entrees = array(); foreach ($entree_tmp as $key => $data) { $entrees[$key . " (" . array_sum($data) . ")"] = $data; } } } //$graph->title = $param['title']; echo "<h3>" . $param['title'] . "</h3>"; } if (count($entrees) == 1) { $graph->legend = false; } $graphtype = $_SESSION['glpigraphtype']; if (in_array(navigatorDetect(), array('Android'))) { $graphtype = 'png'; } switch ($graphtype) { case "png": $extension = "png"; $graph->driver = new ezcGraphGdDriver(); $graph->options->font = GLPI_FONT_FREESANS; break; default: $extension = "svg"; break; } $filename = $uid . '_' . mt_rand(); $csvfilename = $filename . '.csv'; $filename .= '.' . $extension; foreach ($entrees as $label => $data) { $graph->data[$label] = new ezcGraphArrayDataSet($data); $graph->data[$label]->symbol = ezcGraph::NO_SYMBOL; } switch ($graphtype) { case "png": $graph->render($param['width'], $param['height'], GLPI_GRAPH_DIR . '/' . $filename); echo "<img src='" . $CFG_GLPI['root_doc'] . "/front/graph.send.php?file={$filename}'>"; break; default: $graph->render($param['width'], $param['height'], GLPI_GRAPH_DIR . '/' . $filename); echo "<object data='" . $CFG_GLPI['root_doc'] . "/front/graph.send.php?file={$filename}'\n type='image/svg+xml' width='" . $param['width'] . "' height='" . $param['height'] . "'>\n <param name='src' value='" . $CFG_GLPI['root_doc'] . "/front/graph.send.php?file={$filename}'>\n You need a browser capeable of SVG to display this image.\n </object> "; break; } // Render CSV if ($param['csv']) { if ($fp = fopen(GLPI_GRAPH_DIR . '/' . $csvfilename, 'w')) { // reformat datas $values = array(); $labels = array(); $row_num = 0; foreach ($entrees as $label => $data) { $labels[$row_num] = $label; if (is_array($data) && count($data)) { foreach ($data as $key => $val) { if (!isset($values[$key])) { $values[$key] = array(); } $values[$key][$row_num] = $val; } } $row_num++; } ksort($values); // Print labels fwrite($fp, $CFG_GLPI["csv_export_delimiter"]); foreach ($labels as $val) { fwrite($fp, $val . $CFG_GLPI["csv_export_delimiter"]); } fwrite($fp, "\n"); foreach ($values as $key => $data) { fwrite($fp, $key . $CFG_GLPI["csv_export_delimiter"]); foreach ($data as $value) { fwrite($fp, $value . $CFG_GLPI["csv_export_delimiter"]); } fwrite($fp, "\n"); } fclose($fp); } } } }
function isNavigatorMobile() { return in_array(navigatorDetect(), array('iPhone', 'iPad', 'Android', 'Fennec')); }
function displayHeader($title = " ", $back = '', $external = false, $title2 = '', $id_attr = '') { global $CFG_GLPI, $LANG; /*if ($external) $external = "rel='external'"; else */ $external = ""; if ($back != '') { $back = $CFG_GLPI["root_doc"] . "/plugins/mobile/front/" . $back; } if (strlen($title2) > 0) { $title2 = " " . $title2; } $this->displayCommonHtmlHeader($title); echo "<div data-role='page' data-theme='c' id='{$id_attr}' "; if (nativeSelect()) { echo "class='native-select'"; } echo ">"; if (!$this->checkDisplayHeaderBar()) { echo "<div data-role='header' data-theme='c'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/mobile/front/central.php' rel='external'>"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/plugins/mobile/pics/logo.png' alt='Logo' width='62' height='30' />"; echo "</a>"; echo "<h1>" . $title . $title2 . "</h1>"; $dataTransition = "data-transition='slide'"; if (navigatorDetect() == 'Android' && getOsVersion() < "3.0") { $dataTransition = ""; } if ($back != '') { echo "<a href='" . $back . "' " . $external . " data-icon='arrow-l' data-back='true' {$dataTransition} class='ui-btn-right' style='margin-top:6px;'>" . $LANG['buttons'][13] . "</a>"; } elseif (strpos($_SERVER['PHP_SELF'], 'central.php') === false) { echo "<a href='#' onclick='history.back();' data-icon='arrow-l' class='ui-btn-right' {$dataTransition} data-back='true' style='margin-top:6px;'>" . $LANG['buttons'][13] . "</a>"; } if (strpos($_SERVER['PHP_SELF'], 'central.php') !== false) { echo "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/mobile/front/option.php' data-icon=\"gear\" class='ui-btn-right' data-rel='dialog' style='margin-top:6px;'>" . $LANG['plugin_mobile']['navigation']['options'] . "</a>"; } echo "</div>"; } }