/**
  * Main display method for command line interface
  */
 protected function displayCommandLine()
 {
     $this->completeChart();
     if (count($this->request_remainder) > 0) {
         $output_file = array_shift($this->request_remainder);
     } else {
         $output_file = "pChart.out.png";
     }
     $this->chartImage->render($output_file);
 }
Example #2
0
 function renderChart($chartType, $title, $prepData, $legend)
 {
     $width = 800;
     $height = 500;
     $titleHeight = 20;
     /*
      * Create a dataset we can use
      */
     $dataSet = array_values($prepData);
     $imgData = new pData();
     if ($chartType == "bar") {
         $imgData->addPoints($dataSet, "data");
         $imgData->addPoints($legend, "legend");
         $imgData->setAbscissa("legend");
         $imgData->setPalette("data", array("R" => 0, "G" => 108, "B" => 171, "Alpha" => 100));
         $img = new pImage($width, $height, $imgData);
         $img->drawGradientArea(0, $titleHeight, $width, $height, DIRECTION_VERTICAL, array("StartR" => 200, "StartG" => 200, "StartB" => 200, "EndR" => 18, "EndG" => 52, "EndB" => 86, "Alpha" => 100));
         $img->drawGradientArea(0, 0, $width, $titleHeight, DIRECTION_VERTICAL, array("StartR" => 18, "StartG" => 52, "StartB" => 86, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 100));
         $img->setFontProperties(array("FontName" => "images/ttf/liberation-sans/LiberationSans-Bold.ttf", "FontSize" => 10));
         $img->drawText($width / 2, 13, $title, array("Align" => TEXT_ALIGN_MIDDLEMIDDLE, "R" => 255, "G" => 255, "B" => 255));
         $img->setFontProperties(array("R" => 255, "G" => 255, "B" => 255, "FontName" => "images/ttf/liberation-sans/LiberationSans-Regular.ttf", "FontSize" => 9));
         $img->setGraphArea(60, $titleHeight + 20, $width - 50, $height - 30);
         $img->drawScale(array("GridR" => 200, "GridG" => 200, "GridB" => 200, "Mode" => SCALE_MODE_START0));
         $img->drawBarChart(array("Gradient" => TRUE, "GradientMode" => GRADIENT_EFFECT_CAN, "DisplayPos" => LABEL_POS_INSIDE, "DisplayValues" => TRUE, "Surrounding" => 10));
     } elseif ($chartType == "3Dpie") {
         $imgData->addPoints($dataSet, "data");
         $imgData->addPoints($legend, "legend");
         $imgData->setAbscissa("legend");
         $img = new pImage($width, $height, $imgData, TRUE);
         $PieChart = new pPie($img, $imgData);
         $img->drawGradientArea(0, $titleHeight, $width, $height, DIRECTION_VERTICAL, array("StartR" => 200, "StartG" => 200, "StartB" => 200, "EndR" => 18, "EndG" => 52, "EndB" => 86, "Alpha" => 100));
         $img->drawGradientArea(0, 0, $width, $titleHeight, DIRECTION_VERTICAL, array("StartR" => 18, "StartG" => 52, "StartB" => 86, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 100));
         $img->setFontProperties(array("FontName" => "images/ttf/liberation-sans/LiberationSans-Bold.ttf", "FontSize" => 10));
         $img->drawText($width / 2, 13, $title, array("Align" => TEXT_ALIGN_MIDDLEMIDDLE, "R" => 255, "G" => 255, "B" => 255));
         $PieChart->setSliceColor(0, array("R" => 0, "G" => 108, "B" => 171));
         $PieChart->setSliceColor(1, array("R" => 205, "G" => 159, "B" => 0));
         $PieChart->setSliceColor(2, array("R" => 0, "G" => 171, "B" => 0));
         $PieChart->setSliceColor(3, array("R" => 171, "G" => 28, "B" => 0));
         $img->setFontProperties(array("FontName" => "images/ttf/liberation-sans/LiberationSans-Regular.ttf", "FontSize" => 9));
         $PieChart->draw3DPie($width / 2, $height / 2 + $titleHeight, array("Radius" => $width / 2 - 100, "SecondPass" => TRUE, "DrawLabels" => TRUE, "WriteValues" => TRUE, "Precision" => 2, "ValueR" => 0, "ValueG" => 0, "ValueB" => 0, "ValueAlpha" => 100, "SkewFactor" => 0.6, "LabelR" => 255, "LabelG" => 255, "LabelB" => 255, "LabelAlpha" => 100));
     }
     # if
     if (isset($img)) {
         ob_start();
         $img->render(NULL);
         $imageString = ob_get_clean();
         $dimensions = $this->_svcImageUtil->getImageDimensions($imageString);
         return array('metadata' => $dimensions, 'content' => $imageString);
     } else {
         return false;
     }
     # else
 }
 function displayGraph($rrdtool_template, $itemtype, $items_id, $timezone, $time = '1d', $width = '470')
 {
     global $DB, $LANG;
     $timezonefile = str_replace("+", ".", $timezone);
     // Cache 1 minute
     if (file_exists(GLPI_PLUGIN_DOC_DIR . "/monitoring/" . $itemtype . "-" . $items_id . "-" . $time . $timezonefile . ".png")) {
         $time_generate = filectime(GLPI_PLUGIN_DOC_DIR . "/monitoring/" . $itemtype . "-" . $items_id . "-" . $time . $timezonefile . ".png");
         if ($time_generate + 150 > date('U')) {
             return;
         }
     }
     $filename = GLPI_PLUGIN_DOC_DIR . "/monitoring/templates/" . $rrdtool_template . "_graph.json";
     $loadfile = file_get_contents($filename);
     if (!$loadfile) {
         return;
     }
     $a_jsong = json_decode($loadfile);
     // Manage timezones
     $converttimezone = '0';
     if (strstr($timezone, '-')) {
         $timezone_temp = str_replace("-", "", $timezone);
         $converttimezone = $timezone_temp * 3600;
         $timezone = str_replace("-", "+", $timezone);
     } else {
         if (strstr($timezone, '+')) {
             $timezone_temp = str_replace("+", "", $timezone);
             $converttimezone = $timezone_temp * 3600;
             $timezone = str_replace("+", "-", $timezone);
         }
     }
     $opts = "";
     /* pChart library inclusions */
     include_once "../lib/pChart2.1.3/class/pData.class.php";
     include_once "../lib/pChart2.1.3/class/pDraw.class.php";
     include_once "../lib/pChart2.1.3/class/pImage.class.php";
     $MyData = new pData();
     // ** Get in table serviceevents
     $mydatat = array();
     $a_labels = array();
     $a_ref = array();
     $pmServiceevent = new PluginMonitoringServiceevent();
     $pmService = new PluginMonitoringService();
     $pmService->getFromDB($items_id);
     $begin = '';
     switch ($time) {
         case '2h':
             $begin = date('Y-m-d H:i:s', date('U') - 2 * 3600);
             $query = "SELECT * FROM `glpi_plugin_monitoring_serviceevents`\n               WHERE `plugin_monitoring_services_id`='" . $items_id . "'\n                  AND `date` > '" . $begin . "'\n               ORDER BY `date`";
             $result = $DB->query($query);
             $ret = array();
             if (isset($this->jsongraph_a_ref[$rrdtool_template])) {
                 $ret = $pmServiceevent->getData($result, $rrdtool_template, array($this->jsongraph_a_ref[$rrdtool_template], $this->jsongraph_a_convert[$rrdtool_template]));
             } else {
                 $ret = $pmServiceevent->getData($result, $rrdtool_template);
             }
             if (is_array($ret)) {
                 $mydatat = $ret[0];
                 $a_labels = $ret[1];
                 $a_ref = $ret[2];
                 if (!isset($this->jsongraph_a_ref[$rrdtool_template])) {
                     $this->jsongraph_a_ref[$rrdtool_template] = $ret[2];
                     $this->jsongraph_a_convert[$rrdtool_template] = $ret[3];
                 }
             }
             break;
         case '12h':
             $begin = date('Y-m-d H:i:s', date('U') - 12 * 3600);
             $query = "SELECT * FROM `glpi_plugin_monitoring_serviceevents`\n               WHERE `plugin_monitoring_services_id`='" . $items_id . "'\n                  AND `date` > '" . $begin . "'\n               ORDER BY `date`";
             $result = $DB->query($query);
             $ret = $pmServiceevent->getData($result, $rrdtool_template);
             if (is_array($ret)) {
                 $mydatat = $ret[0];
                 $a_labels = $ret[1];
                 $a_ref = $ret[2];
             }
             break;
         case '1d':
             $begin = date('Y-m-d H:i:s', date('U') - 24 * 3600);
             $query = "SELECT * FROM `" . $this->getTable() . "`\n               WHERE `plugin_monitoring_services_id`='" . $items_id . "'\n                  AND `type`='30m'\n               ORDER BY `date`";
             $result = $DB->query($query);
             while ($edata = $DB->fetch_array($result)) {
                 $dat = importArrayFromDB($edata['data']);
                 if (count($dat) > 0) {
                     $datemod = $edata['date'];
                     $split = explode(' ', $datemod);
                     $split2 = explode(':', $split[1]);
                     array_push($a_labels, $split2[0] . ':' . $split2[1]);
                 }
                 foreach ($dat as $name => $value) {
                     if (!isset($mydatat[$name])) {
                         $mydatat[$name] = array();
                     }
                     array_push($mydatat[$name], $value);
                 }
             }
             $ret = $pmServiceevent->getRef($rrdtool_template);
             $a_ref = $ret[0];
             break;
         case '1w':
             $begin = date('Y-m-d H:i:s', date('U') - 7 * 24 * 3600);
             $query = "SELECT * FROM `" . $this->getTable() . "`\n               WHERE `plugin_monitoring_services_id`='" . $items_id . "'\n                  AND `type`='6h'\n               ORDER BY `date`";
             $result = $DB->query($query);
             while ($edata = $DB->fetch_array($result)) {
                 $dat = importArrayFromDB($edata['data']);
                 if (count($dat) > 0) {
                     $datemod = $edata['date'];
                     $daynum = Calendar::getDayNumberInWeek(PluginMonitoringServiceevent::convert_datetime_timestamp($edata['date']));
                     $split = explode(' ', $datemod);
                     $split2 = explode(':', $split[1]);
                     array_push($a_labels, $LANG['calendarDay'][$daynum] . " " . $split2[0] . ':' . $split2[1]);
                 }
                 foreach ($dat as $name => $value) {
                     if (!isset($mydatat[$name])) {
                         $mydatat[$name] = array();
                     }
                     array_push($mydatat[$name], $value);
                 }
             }
             $ret = $pmServiceevent->getRef($rrdtool_template);
             $a_ref = $ret[0];
             break;
         case '1m':
             $begin = date('Y-m-d H:i:s', date('U') - 30 * 24 * 3600);
             $query = "SELECT * FROM `" . $this->getTable() . "`\n               WHERE `plugin_monitoring_services_id`='" . $items_id . "'\n                  AND `type`='1d'\n               ORDER BY `date`";
             $result = $DB->query($query);
             while ($edata = $DB->fetch_array($result)) {
                 $dat = importArrayFromDB($edata['data']);
                 if (count($dat) > 0) {
                     $datemod = $edata['date'];
                     $daynum = Calendar::getDayNumberInWeek(PluginMonitoringServiceevent::convert_datetime_timestamp($edata['date']));
                     $split = explode(' ', $datemod);
                     $split2 = explode(':', $split[1]);
                     $day = explode("-", $split[0]);
                     array_push($a_labels, $LANG['calendarDay'][$daynum] . " " . $day[2]);
                 }
                 foreach ($dat as $name => $value) {
                     if (!isset($mydatat[$name])) {
                         $mydatat[$name] = array();
                     }
                     array_push($mydatat[$name], $value);
                 }
             }
             $ret = $pmServiceevent->getRef($rrdtool_template);
             $a_ref = $ret[0];
             break;
         case '0y6m':
             $begin = date('Y-m-d H:i:s', date('U') - 364 / 2 * 24 * 3600);
             $query = "SELECT * FROM `" . $this->getTable() . "`\n               WHERE `plugin_monitoring_services_id`='" . $items_id . "'\n                  AND `type`='5d'\n               ORDER BY `date`";
             $result = $DB->query($query);
             while ($edata = $DB->fetch_array($result)) {
                 $dat = importArrayFromDB($edata['data']);
                 if (count($dat) > 0) {
                     $datemod = $edata['date'];
                     $daynum = date('m', PluginMonitoringServiceevent::convert_datetime_timestamp($edata['date']));
                     $daynum = $daynum - 1;
                     $split = explode(' ', $datemod);
                     $day = explode("-", $split[0]);
                     array_push($a_labels, $LANG['calendarM'][$daynum] . " " . $day[2]);
                 }
                 foreach ($dat as $name => $value) {
                     if (!isset($mydatat[$name])) {
                         $mydatat[$name] = array();
                     }
                     array_push($mydatat[$name], $value);
                 }
             }
             $ret = $pmServiceevent->getRef($rrdtool_template);
             $a_ref = $ret[0];
             break;
         case '1y':
             $begin = date('Y-m-d H:i:s', date('U') - 365 * 24 * 3600);
             $query = "SELECT * FROM `" . $this->getTable() . "`\n               WHERE `plugin_monitoring_services_id`='" . $items_id . "'\n                  AND `type`='10d'\n               ORDER BY `date`";
             $result = $DB->query($query);
             while ($edata = $DB->fetch_array($result)) {
                 $dat = importArrayFromDB($edata['data']);
                 if (count($dat) > 0) {
                     $datemod = $edata['date'];
                     $daynum = date('m', PluginMonitoringServiceevent::convert_datetime_timestamp($edata['date']));
                     $daynum = $daynum - 1;
                     $split = explode(' ', $datemod);
                     $day = explode("-", $split[0]);
                     array_push($a_labels, $LANG['calendarM'][$daynum] . " " . $day[2]);
                 }
                 foreach ($dat as $name => $value) {
                     if (!isset($mydatat[$name])) {
                         $mydatat[$name] = array();
                     }
                     array_push($mydatat[$name], $value);
                 }
             }
             $ret = $pmServiceevent->getRef($rrdtool_template);
             $a_ref = $ret[0];
             break;
     }
     $i = 0;
     foreach ($mydatat as $name => $data) {
         $i++;
         if ($i == '2') {
             $datat = $data;
             $data = array();
             foreach ($datat as $val) {
                 array_push($data, -$val);
             }
         }
         if (empty($data)) {
             array_push($data, 0);
         }
         $MyData->addPoints($data, $name);
         $color = str_split($a_ref[$name]);
         $MyData->setPalette($name, array("R" => hexdec($color[0] . $color[1]), "G" => hexdec($color[2] . $color[3]), "B" => hexdec($color[4] . $color[5])));
     }
     $MyData->setAxisDisplay(0, AXIS_FORMAT_METRIC, 1);
     //    $MyData->setSerieTicks("Probe 2",4);
     //    $MyData->setAxisName(0,"Temperatures");
     $MyData->addPoints($a_labels, "Labels");
     //    $MyData->setSerieDescription("Labels","Months");
     $MyData->setAbscissa("Labels");
     $myPicture = new pImage(700, 230, $MyData);
     $myPicture->Antialias = FALSE;
     $Settings = array("R" => 225, "G" => 204, "B" => 123);
     $myPicture->drawFilledRectangle(0, 0, 700, 230, $Settings);
     $Settings = array("R" => 255, "G" => 255, "B" => 255);
     $myPicture->drawFilledRectangle(60, 40, 650, 200, $Settings);
     /* Add a border to the picture */
     $myPicture->drawRectangle(0, 0, 699, 229, array("R" => 0, "G" => 0, "B" => 0));
     /* Write the chart title */
     $myPicture->setFontProperties(array("FontName" => "../lib/pChart2.1.3/fonts/verdana.ttf", "FontSize" => 11));
     $myPicture->drawText(350, 20, $a_jsong->data[0]->labels[0]->title, array("FontSize" => 13, "Align" => TEXT_ALIGN_MIDDLEMIDDLE));
     /* Set the default font */
     $myPicture->setFontProperties(array("FontName" => "../lib/pChart2.1.3/fonts/verdana.ttf", "FontSize" => 7));
     /* Define the chart area */
     $myPicture->setGraphArea(60, 40, 650, 200);
     /* Draw the scale */
     $labelskip = round(count($a_labels) / 8);
     if ($time == '1d') {
         $labelskip = 3;
     } else {
         if ($time == '1m') {
             $labelskip = 3;
         } else {
             if ($time == '0y6m') {
                 $labelskip = 4;
             } else {
                 if ($time == '1y') {
                     $labelskip = 3;
                 }
             }
         }
     }
     $scaleSettings = array("XMargin" => 10, "YMargin" => 10, "Floating" => TRUE, "GridR" => 158, "GridG" => 158, "GridB" => 158, "GridAlpha" => 80, "DrawSubTicks" => TRUE, "CycleBackground" => FALSE, "LabelSkip" => $labelskip);
     $myPicture->drawScale($scaleSettings);
     /* Write the chart legend */
     $myPicture->drawLegend(540, 20, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL));
     /* Turn on Antialiasing */
     $myPicture->Antialias = TRUE;
     $Config = array("ForceTransparency" => 60);
     /* Draw the area chart */
     $myPicture->drawAreaChart($Config);
     $myPicture->render(GLPI_PLUGIN_DOC_DIR . "/monitoring/" . $itemtype . "-" . $items_id . "-" . $time . $timezonefile . ".png");
     return;
 }
 /**
  * Desenha um gráfico de torta
  * @param $title título do graico
  * @param $data vetor contendo os dados do gráfico
  * @param $width largura do gráfico
  * @param $height altura do gráfico
  * @param $outputPath caminho de saída do gráfico
  */
 public function drawPieChart($title, $data, $width, $height, $outputPath)
 {
     // cria o modelo de dados
     $modelo = new pData();
     $newdata = array();
     foreach ($data as $legend => $value) {
         $newdata[] = $value == NULL ? VOID : $value;
         $labels[] = $legend;
     }
     $modelo->addPoints($newdata, "ScoreA");
     /* Define the absissa serie */
     $modelo->addPoints($labels, "Labels");
     $modelo->setAbscissa("Labels");
     // cria o objeto que irá conter a imagem do gráfico
     $imagem = new pImage($width, $height, $modelo);
     // adiciona uma borda na forma de um retângulo dentro da imagem
     $imagem->drawRectangle(0, 0, $width - 1, $height - 1, array("R" => 0, "G" => 0, "B" => 0));
     // escreve um título dentro do gráfico
     $imagem->setFontProperties(array("FontName" => "app/lib/pchart/fonts/Forgotte.ttf", "FontSize" => 11));
     $imagem->drawText(60, 35, $title, array("FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMLEFT));
     // define a fonte dos dados do gráfico
     $imagem->setFontProperties(array("FontName" => "app/lib/pchart/fonts/Forgotte.ttf", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80));
     // cria o gráfico de torta
     $pie = new pPie($imagem, $modelo);
     // desenha o gráfico de torta
     $pie->draw3DPie($width / 2, $height / 2, array('WriteValues' => TRUE, 'DrawLabels' => TRUE, "Radius" => $width / 4, 'ValueR' => 0, 'ValueG' => 0, 'ValueB' => 0, 'ValueAlpha' => 80));
     // desenha a legenda do gráfico
     $imagem->setShadow(FALSE);
     $pie->drawPieLegend(15, 40, array("Alpha" => 20));
     // grava o gráfico em um arquivo
     $imagem->render($outputPath);
 }
Example #5
0
/* Draw the scale */
$scaleSettings = array("XMargin" => 10, "YMargin" => 10, "Floating" => TRUE, "GridR" => 200, "GridG" => 200, "GridB" => 200, "GridAlpha" => 100, "DrawSubTicks" => TRUE, "CycleBackground" => TRUE);
$myPicture->drawScale($scaleSettings);
/* Write the chart legend */
//$myPicture->drawLegend(640,20,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));
/* Turn on Antialiasing */
$myPicture->Antialias = TRUE;
/* Enable shadow computing */
//$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
/* Draw the area chart */
//$Threshold = "";
// $Threshold[] = array("Min"=>0,"Max"=>5,"R"=>187,"G"=>220,"B"=>0,"Alpha"=>100);
//$Threshold[] = array("Min"=>5,"Max"=>10,"R"=>240,"G"=>132,"B"=>20,"Alpha"=>100);
// $Threshold[] = array("Min"=>10,"Max"=>20,"R"=>240,"G"=>91,"B"=>20,"Alpha"=>100);
//$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>20));
//$myPicture->drawAreaChart(array("Threshold"=>$Threshold));
/* Draw a line chart over */
$myPicture->drawLineChart(array("ForceColor" => TRUE, "ForceR" => 0, "ForceG" => 0, "ForceB" => 0));
/* Draw a plot chart over */
//$myPicture->drawPlotChart(array("PlotBorder"=>TRUE,"BorderSize"=>1,"Surrounding"=>-255,"BorderAlpha"=>80));
/* Write the thresholds */
$myPicture->drawThreshold(3000, array("WriteCaption" => FALSE, "Caption" => "tiefentladen", "Alpha" => 70, "Ticks" => 2, "R" => 0, "G" => 0, "B" => 255));
$myPicture->drawThreshold(4250, array("WriteCaption" => FALSE, "Caption" => "tiefentladen", "Alpha" => 70, "Ticks" => 2, "R" => 0, "G" => 0, "B" => 255));
//$myPicture->drawThreshold(10,array("WriteCaption"=>TRUE,"Caption"=>"Error Zone","Alpha"=>70,"Ticks"=>2,"R"=>0,"G"=>0,"B"=>255));
/* Render the picture (choose the best way) */
//imagejpeg ( $myPicture, "myPicture.jpg" , 100);		//saves Image to Server
$myPicture->render("voltage.png");
// debug ==> picture debug... show image
// header('Content-Type: image/png');
// imagejpeg ( $myPicture);
//$myPicture->autoOutput("pictures/example.drawAreaChart.threshold.png");
 function func_bargraphGenerate($student_id, $time, $type, $basepath, $success, $r = "", $g = "", $b = "", $name)
 {
     $bookIdResult = $this->func_getBookId('1,2');
     $bookID = array();
     foreach ($bookIdResult as $book) {
         $bookID[] = $book['book_id'];
     }
     $getActivityTypeIdResult = $this->func_getActivityTypeId('WORD HUNT');
     foreach ($getActivityTypeIdResult as $activityTypeId) {
         $activityTypeId = $activityTypeId['activity_type_id'];
     }
     $getActivityIdResult = $this->func_getActivityId($bookID, $activityTypeId);
     $actId = array();
     foreach ($getActivityIdResult as $activityId) {
         $actId[] = $activityId['activity_id'];
     }
     $actNewId = implode(',', $actId);
     $k = 0;
     $j = 0;
     for ($i = 0; $i < 5; $i = $i + 1) {
         $date[$k] = date("Y-m-d", strtotime("-{$i} day"));
         $dateRec[] = date('M d', strtotime("-{$i} day"));
         $k = $k + 1;
     }
     $successaccessmentResult = $this->fun_getAssmentResult($student_id, $actNewId, '', $date, "word_hunt", $success);
     $totalaccessmentResult = $this->fun_getAssmentResult($student_id, $actNewId, '', $date, "word_hunt", '0,1');
     for ($i = 0; $i < 5; $i = $i + 1) {
         $j = $i;
         if ($totalaccessmentResult['0']['count_' . $j] == "0") {
             $totalaccessmentResult['0']['count_' . $j] = 1;
         }
         $per[$i] = $successaccessmentResult['0']['count_' . $j] / $totalaccessmentResult['0']['count_' . $j] * 100;
     }
     $MyData = new pData();
     $MyData->addPoints($per, "Server A");
     $MyData->setAxisName(0, "Percentage");
     $MyData->addPoints(array_reverse($dateRec), "Months");
     $MyData->setSerieDescription("Months", "Month");
     $MyData->setAbscissa("Months");
     $myPicture = new pImage(350, 230, $MyData);
     /* Turn of Antialiasing */
     $myPicture->Antialias = FALSE;
     /* Add a border to the picture */
     $myPicture->drawGradientArea(0, 0, 400, 230, DIRECTION_VERTICAL, array("StartR" => 255, "StartG" => 255, "StartB" => 255, "EndR" => 255, "EndG" => 255, "EndB" => 255, "Alpha" => 100));
     // $myPicture->drawRectangle(0,0,400,229,array("R"=>0,"G"=>0,"B"=>0));
     /* Set the default font */
     $myPicture->setFontProperties(array("FontName" => $basepath . "Silkscreen.ttf", "FontSize" => 6));
     /* Define the chart area */
     $myPicture->setGraphArea(60, 40, 350, 200);
     /* Draw the scale */
     $scaleSettings = array("GridR" => 300, "GridG" => 300, "GridB" => 200, "DrawSubTicks" => FALSE, "CycleBackground" => FALSE, "Pos" => SCALE_POS_LEFTRIGHT, "Mode" => SCALE_MODE_MANUAL, "LabelingMethod" => LABELING_ALL);
     $myPicture->drawScale($scaleSettings);
     /* Turn on shadow computing */
     $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10));
     /* Draw the chart */
     $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10));
     $settings = array("Surrounding" => -30, "InnerSurrounding" => 30, "Mode" => 0);
     $myPicture->drawBarChart($settings, $r, $g, $b);
     /* Render the picture (choose the best way) */
     $picname = $student_id . '_' . $name . '_' . $time . '.png';
     $this->fun_getImageLog($student_id, $picname, $type, $time, $name);
     $myPicture->render("uploads/graph/" . $picname);
 }
Example #7
0
    /* Draw the border */
    $myPicture->drawRectangle(0, 0, $xsize - 1, $ysize - 1, array("R" => 0, "G" => 0, "B" => 0));
    /* Write the title */
    $myPicture->setFontProperties(array("FontName" => "../../fonts/verdana.ttf", "FontSize" => 9));
    $myPicture->drawText(70, 45, $title, array("FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMLEFT));
    /* Draw the 1st scale */
    $myPicture->setGraphArea(70, 60, $xsize - 40, $ysize - 30);
    $myPicture->drawFilledRectangle(70, 60, $xsize - 40, $ysize - 30, array("R" => 255, "G" => 255, "B" => 255, "Surrounding" => -200, "Alpha" => 10));
    $AxisBoundaries = array(0 => array("Min" => $minscale, "Max" => $maxscale));
    $myPicture->drawScale(array("DrawSubTicks" => TRUE, "CycleBackground" => TRUE, "Mode" => SCALE_MODE_MANUAL, "ManualScale" => $AxisBoundaries));
    /* Draw the 1st stock chart */
    $mystockChart = new pStock($myPicture, $MyData);
    $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 30));
    $mystockChart->drawStockChart();
    /* Reset the display mode because of the graph small size */
    //$MyData->setAxisDisplay(0,AXIS_FORMAT_DEFAULT);
    /* Draw the 2nd scale */
    //$myPicture->setShadow(FALSE);
    //$myPicture->setGraphArea(500,60,670,190);
    //$myPicture->drawFilledRectangle(500,60,670,190,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10));
    //$myPicture->drawScale(array("Pos"=>SCALE_POS_TOPBOTTOM,"DrawSubTicks"=>TRUE));
    /* Draw the 2nd stock chart */
    //$mystockChart = new pStock($myPicture,$MyData);
    //$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>30));
    //$mystockChart->drawStockChart();
    /* Render the picture (choose the best way) */
    //$myPicture->autoOutput("pictures/example.drawStockChart.png");
    $myPicture->render($imagefilename);
    $graphgendate = $current_time;
}
renderpage($title, $permalink, $altimage, $imagepath, $graphgendate, $message, false, $navigation);
Example #8
0
function buildgraph($MyData, $xsize, $ysize, $title, $minscale, $maxscale, $date, $type, $imagefilename)
{
    //include("../cfg/nmcgraph_cfg.php");
    /* Create and populate the pData object */
    $MyData = new pData();
    load_nmc_data($MyData, $date, $type, $minscale, $maxscale);
    //var_dump($MyData);
    //echo $minscale." ".$maxscale; exit;
    //printf("minscale: $minscale maxscale: $maxscale <br />\n");
    //buildgraph( $MyData, $xsize, $ysize, $title  );
    $MyData->setAxisDisplay(0, AXIS_FORMAT_CURRENCY, "฿");
    //$MyData->addPoints(array("8h","10h","12h","14h","16h","18h"),"Time");
    //$MyData->setAbscissa("Months");
    //$MyData->setAxisName(0,"Price in BTC");
    //$MyData->setSerieDescription("Time","Hour of the day");
    /* Create the pChart object */
    $myPicture = new pImage($xsize, $ysize, $MyData);
    /* Draw the background */
    $Settings = array("R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107);
    $myPicture->drawFilledRectangle(0, 0, $xsize, $ysize, $Settings);
    /* Overlay with a gradient */
    $Settings = array("StartR" => 219, "StartG" => 231, "StartB" => 139, "EndR" => 1, "EndG" => 138, "EndB" => 68, "Alpha" => 50);
    $myPicture->drawGradientArea(0, 0, $xsize, $ysize, DIRECTION_VERTICAL, $Settings);
    /* Draw the border */
    $myPicture->drawRectangle(0, 0, $xsize - 1, $ysize - 1, array("R" => 0, "G" => 0, "B" => 0));
    /* Write the title */
    $myPicture->setFontProperties(array("FontName" => dirname(__FILE__) . "/../../fonts/verdana.ttf", "FontSize" => 9));
    $myPicture->drawText(70, 45, $title, array("FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMLEFT));
    /* Draw the 1st scale */
    $myPicture->setGraphArea(70, 60, $xsize - 40, $ysize - 30);
    $myPicture->drawFilledRectangle(70, 60, $xsize - 40, $ysize - 30, array("R" => 255, "G" => 255, "B" => 255, "Surrounding" => -200, "Alpha" => 10));
    // Y scale
    $AxisBoundariesY = array(0 => array("Min" => $minscale, "Max" => $maxscale));
    $myPicture->drawScale(array("DrawSubTicks" => TRUE, "CycleBackground" => TRUE, "Mode" => SCALE_MODE_MANUAL, "ManualScale" => $AxisBoundariesY));
    //X scale
    //$AxisBoundariesX = array("01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23");
    //$MyData->setSerieDescription("Labels","Months");
    //$MyData->setAbscissa("Labels");
    $MyData->setXAxisDisplay(0, AXIS_FORMAT_TIME, "H");
    //$myPicture->drawScale(array("DrawXLines"=>array(0)));
    /* Draw the 1st stock chart */
    $mystockChart = new pStock($myPicture, $MyData);
    $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 30));
    $mystockChart->drawStockChart();
    /* Reset the display mode because of the graph small size */
    //$MyData->setAxisDisplay(0,AXIS_FORMAT_DEFAULT);
    /* Draw the 2nd scale */
    //$myPicture->setShadow(FALSE);
    //$myPicture->setGraphArea(500,60,670,190);
    //$myPicture->drawFilledRectangle(500,60,670,190,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10));
    //$myPicture->drawScale(array("Pos"=>SCALE_POS_TOPBOTTOM,"DrawSubTicks"=>TRUE));
    /* Draw the 2nd stock chart */
    //$mystockChart = new pStock($myPicture,$MyData);
    //$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>30));
    //$mystockChart->drawStockChart();
    /* Render the picture (choose the best way) */
    //$myPicture->autoOutput("pictures/example.drawStockChart.png");
    $myPicture->render($imagefilename);
    $current_time = time();
    $graphgendate = $current_time;
    return $graphgendate;
}
Example #9
0
/**
 * eval_ccpc_genGraphLine - Génère un graphique de type Line simple sous forme d'image au format PNG
 *
 * @category : eval_ccpc_functions
 * @param array $data Données à partir desquelles le graphique est généré
 * @return string URL de l'image générée
 *
 * @Author Ali Bellamine
 *
 * Structure de $data :<br>
 * 	['option'] => (array) Liste des labels disponibles<br>
 * 	['data'][nom de la catégorie][nom du label] => (int) Valeur du label<br>
 * 	['settings']['min'] => (int) Valeur (ordonnée) minimale<br>
 * 	['settings']['max'] => (int) Valeur (ordonnée) maximale<br>
 * 	['settings']['height'] => (int) Hauteur du graphique (en px)<br>
 * 	['settings']['width'] => (int) Largeur du graphique (en px)
 *
 */
function eval_ccpc_genGraphLine($data)
{
    // On vérifie les données fournit
    if (isset($data) && isset($data['data']) && count($data['data']) > 0 && isset($data['option']) && count($data['option']) > 0) {
        // On récupère le hash de $data
        $hash = md5(json_encode($data));
        // Chemin du fichier
        $filePath = PLUGIN_PATH . 'cache/' . $hash . '.png';
        $filePathURI = ROOT . 'evaluations/ccpc/cache/' . $hash . '.png';
        // Si le hash existe déjà : on renvoie le lien de l'image // sinon en crée le graphique
        if (is_file($filePath)) {
            return $filePathURI;
        } else {
            // On crée l'image
            /* On inclut la librairie */
            require_once PLUGIN_PATH . 'core/pChart2.1.4/class/pData.class.php';
            require_once PLUGIN_PATH . 'core/pChart2.1.4/class/pDraw.class.php';
            require_once PLUGIN_PATH . 'core/pChart2.1.4/class/pImage.class.php';
            /* On crée l'objet pData */
            // Préparation des données
            $tempDataArray = array();
            // Contient les données chiffrés
            foreach ($data['data'] as $tempDataLegend => $tempDataValue) {
                if (is_array($tempDataValue)) {
                    foreach ($data['option'] as $key) {
                        if (isset($tempDataValue[$key]) && is_numeric($tempDataValue[$key])) {
                            $tempDataArray[$tempDataLegend][$key] = $tempDataValue[$key];
                        } else {
                            $tempDataArray[$tempDataLegend][$key] = VOID;
                        }
                    }
                } else {
                    return FALSE;
                }
            }
            $MyData = new pData();
            foreach ($tempDataArray as $key => $value) {
                $MyData->addPoints($value, $key);
            }
            $MyData->addPoints($data['option'], 'Label');
            $MyData->setAbscissa("Label");
            $MyData->setSerieDescription("Label", "Label");
            /* On crée l'objet pChart */
            if (isset($data['settings']['width'])) {
                $width = $data['settings']['width'];
            } else {
                $width = 600;
            }
            if (isset($data['settings']['height'])) {
                $height = $data['settings']['height'];
            } else {
                $height = 300;
            }
            $myPicture = new pImage($width, $height, $MyData, TRUE);
            $myPicture->setFontProperties(array("FontName" => PLUGIN_PATH . "core/pChart2.1.4/fonts/MankSans.ttf", "FontSize" => 14, "R" => 80, "G" => 80, "B" => 80));
            // On détermine les limites
            $myPicture->setGraphArea(0, 0, $width, $height - 30);
            $scaleSettings = array("DrawSubTicks" => TRUE);
            if (isset($data['settings']['min']) && is_numeric($data['settings']['min']) && isset($data['settings']['max']) && is_numeric($data['settings']['max']) && $data['settings']['min'] < $data['settings']['max']) {
                // Prise en charge de la possibilité d'imposer le min et le max
                $scaleSettings['Mode'] = SCALE_MODE_MANUAL;
                $scaleSettings['ManualScale'][0] = array('Min' => $data['settings']['min'], 'Max' => $data['settings']['max']);
                // Min et Max sur l'axe des ordonnées
            }
            $myPicture->drawScale($scaleSettings);
            $myPicture->drawLegend(10, 10, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL));
            $settings = array("Surrounding" => -30, "InnerSurrounding" => 30, "DisplayValues" => TRUE, "ORIENTATION_HORIZONTAL" => TRUE);
            $myPicture->drawLineChart($settings);
            $myPicture->render($filePath);
            return $filePathURI;
        }
    } else {
        return FALSE;
    }
}
 private function drawOverAllImage($date)
 {
     $res1 = $this->dataForGraph($date, 0);
     $res2 = $this->dataForGraph($date, 1);
     $MyData = new pData();
     $MyData->addPoints($res1['percents'], "Load in % for server 1");
     $MyData->addPoints($res2['percents'], "Load in % for server 2");
     $MyData->setAxisName(0, "Participants");
     $MyData->addPoints($res1['times'], "Labels");
     //        $MyData->addPoints($res2['times'], "Labels");
     $MyData->setSerieDescription("Labels", "Months");
     $MyData->setAbscissa("Labels");
     /* Create the pChart object */
     $myPicture = new pImage(1200, 560, $MyData);
     /* Turn of Antialiasing */
     $myPicture->Antialias = TRUE;
     /* Add a border to the picture */
     //$myPicture->drawRectangle(0,0,890,290,array("R"=>0,"G"=>0,"B"=>0));
     /* Write the chart title */
     $myPicture->setFontProperties(array("FontName" => CORE_REPOSITORY_REAL_PATH . "class/pChart/fonts/Forgotte.ttf", "FontSize" => 11));
     $myPicture->drawText(200, 35, "All Servers Resource Usage (" . $date . ")", array("FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMMIDDLE));
     /* Set the default font */
     $myPicture->setFontProperties(array("FontName" => CORE_REPOSITORY_REAL_PATH . "class/pChart/fonts/pf_arma_five.ttf", "FontSize" => 8));
     /* Define the chart area */
     $myPicture->setGraphArea(60, 40, 1100, 500);
     $AxisBoundaries = array(0 => array("Min" => 0, "Max" => 100));
     /* Draw the scale */
     $scaleSettings = array("XMargin" => 10, "YMargin" => 10, "Floating" => TRUE, "GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => TRUE, "CycleBackground" => TRUE, "LabelSkip" => 1, 'Mode' => SCALE_MODE_MANUAL, "ManualScale" => $AxisBoundaries);
     $myPicture->drawScale($scaleSettings);
     $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10));
     /* Draw the stacked area chart */
     $myPicture->drawStackedAreaChart(array("DrawLine" => TRUE, "LineSurrounding" => -20));
     /* Turn on Antialiasing */
     $myPicture->Antialias = TRUE;
     /* Draw the line chart */
     $myPicture->drawLineChart();
     /* Write the chart legend */
     $myPicture->drawLegend(800, 20, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL));
     /* Render the picture (choose the best way) */
     //$myPicture->autoOutput(App::$instance->opt->fizPath."class/pChart/pictures/example.drawLineChart.simple.png");
     $myPicture->render(CORE_REPOSITORY_REAL_PATH . "class/pChart/pictures/load_at_" . $date . "_on_overall.png");
     $path = CORE_REPOSITORY_HTTP_PATH . "class/pChart/pictures/load_at_" . $date . "_on_overall.png";
     if (ST::isAjaxRequest()) {
         $data = [];
         print json_encode($data['path'] = $path);
     } else {
         return $path;
     }
 }
Example #11
0
function electrique_mois()
{
    //initialisation des variables tableau
    $timestamp = "";
    $conso = "";
    $sql = mysql_query("SELECT TIMESTAMP(CONCAT(YEAR(date_histo ),'-',MONTH(date_histo ),'-',DAY(date_histo ),' ',HOUR(date_histo ),':00')),\n\t\t\t\t\tdate_histo, AVG(valeur1),MAX(valeur1),MIN(valeur1)\n\t\t\t\t\tFROM historique_donnees\n\t\t\t\t\tWHERE id_objet = 2\n\t\t\t\t\tAND date_histo >  DATE_SUB(NOW( ), INTERVAL 31 DAY)\n\t\t\t\t\tGROUP BY YEAR( date_histo ) , MONTH( date_histo ) , DAY( date_histo ),  HOUR( date_histo ),  id_objet\n\t\t\t\t\tHAVING HOUR( date_histo ) IN ( 00, 06, 12, 18 ) \n\t\t\t\t\tORDER BY date_histo");
    while (list($date_histo, $date_histo2, $conso_sql, $conso_sql_max, $conso_sql_min) = mysql_fetch_array($sql)) {
        $timestamp[] = strtotime($date_histo);
        $conso[] = $conso_sql;
        $conso_max[] = $conso_sql_max;
        $conso_min[] = $conso_sql_min;
    }
    $myData = new pData();
    $myData->addPoints($timestamp, "Timestamp");
    $myData->addPoints($conso, "Consommation Instantanée Moyenne");
    $myData->addPoints($conso_max, "Conso. Inst. Max");
    $myData->addPoints($conso_min, "Conso. Inst. Min");
    $myData->setSerieOnAxis("Consommation Instantanée", 0);
    $myData->setSerieOnAxis("Conso. Inst. Max", 0);
    $myData->setSerieOnAxis("Conso. Inst. Min", 0);
    $myData->setAbscissa("Timestamp");
    $myData->setXAxisName("Time");
    $myData->setXAxisDisplay(AXIS_FORMAT_TIME, "d/m");
    $myData->setAxisName(0, "Consommation Instantanée");
    $myData->setAxisUnit(0, "W");
    $myPicture = new pImage(1250, 550, $myData);
    $Settings = array("StartR" => 48, "StartG" => 124, "StartB" => 183, "EndR" => 33, "EndG" => 86, "EndB" => 128, "Alpha" => 50);
    $myPicture->drawGradientArea(0, 0, 1250, 550, DIRECTION_VERTICAL, $Settings);
    $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 50, "G" => 50, "B" => 50, "Alpha" => 20));
    $myPicture->setFontProperties(array("FontName" => "fonts/Forgotte.ttf", "FontSize" => 18));
    $TextSettings = array("Align" => TEXT_ALIGN_MIDDLEMIDDLE, "R" => 255, "G" => 255, "B" => 255);
    $myPicture->drawText(350, 25, "Consommation éléctrique", $TextSettings);
    $myPicture->setShadow(FALSE);
    $myPicture->setGraphArea(110, 50, 1160, 500);
    $myPicture->setFontProperties(array("R" => 0, "G" => 0, "B" => 0, "FontName" => "fonts/Forgotte.ttf", "FontSize" => 14));
    $Settings = array("Pos" => SCALE_POS_LEFTRIGHT, "Mode" => SCALE_MODE_FLOATING, "LabelingMethod" => LABELING_ALL, "GridR" => 255, "GridG" => 255, "GridB" => 255, "GridAlpha" => 50, "TickR" => 0, "TickG" => 0, "TickB" => 0, "TickAlpha" => 50, "LabelRotation" => 45, "CycleBackground" => 1, "DrawXLines" => 1, "DrawSubTicks" => 1, "SubTickR" => 255, "SubTickG" => 0, "SubTickB" => 0, "SubTickAlpha" => 50, "DrawYLines" => ALL, "LabelSkip" => 3);
    $myPicture->drawScale($Settings);
    $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 50, "G" => 50, "B" => 50, "Alpha" => 10));
    $Config = "";
    $myPicture->drawSplineChart($Config);
    $Config = array("FontR" => 0, "FontG" => 0, "FontB" => 0, "FontName" => "fonts/Forgotte.ttf", "FontSize" => 14, "Margin" => 6, "Alpha" => 30, "BoxSize" => 5, "Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL);
    $myPicture->drawLegend(563, 16, $Config);
    $myPicture->render("tmp/graphe_em.png");
    echo "<img src='tmp/graphe_em.png' alt='graphe'/>";
}
Example #12
0
    $myPicture->setFontProperties(array("FontName" => "../../../fonts/calibri.ttf", "FontSize" => 8));
    $TextSettings = array("R" => 15, "G" => 15, "B" => 255, "Angle" => 0);
    $Config = "";
    if (dvb($chanel_id, $group_id) == true) {
        if ($last <= 1000) {
            $Settings = array("R" => 230, "G" => 56, "B" => 30);
        } else {
            $Settings = array("R" => 41, "G" => 183, "B" => 31);
        }
        $myPicture->drawFilledRectangle(0, 0, 100, 55, $Settings);
        $myPicture->drawSplineChart($Config);
        $myPicture->drawText(0, 20, "Sig:" . $last, $TextSettings);
    } else {
        if ($last <= 1000 or $onair == 0) {
            $Settings = array("R" => 230, "G" => 56, "B" => 30);
        } else {
            $Settings = array("R" => 76, "G" => 224, "B" => 175);
        }
        $myPicture->drawFilledRectangle(0, 0, 100, 55, $Settings);
        $myPicture->drawSplineChart($Config);
        $myPicture->drawText(0, 20, "Bit:" . $last, $TextSettings);
    }
    $myPicture->drawText(0, 10, $name, $TextSettings);
    $myPicture->drawText(0, 50, $ldt, $TextSettings);
    $rnd = GetRandomId(10);
    $myPicture->render("../../../files/tmp" . $chanel_id . $group_id . ".png");
    echo "<img src='/files/tmp" . $chanel_id . $group_id . ".png?" . $rnd . "'> ";
}
echo "<div class='alert alert-success'><ul>";
echo "<button onclick='openMonurl({$astra_id})'>Обновить</button>";
echo "</ul></div>";
Example #13
0
 function createStatistics($graph, $limit, $lastUpdate, $language)
 {
     SpotTranslation::initialize($language);
     $spotStatistics = new SpotStatistics($this->_db);
     include_once "images/pchart/pData.class.php";
     include_once "images/pchart/pDraw.class.php";
     include_once "images/pchart/pImage.class.php";
     $width = 800;
     $height = 500;
     $titleHeight = 20;
     $dataSet = array();
     $graphs = $this->getValidStatisticsGraphs();
     $limits = $this->getValidStatisticsLimits();
     switch ($graph) {
         case 'spotsperhour':
             $prepData = $this->prepareData($spotStatistics->getSpotCountPerHour($limit, $lastUpdate));
             $legend = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23');
             for ($x = 0; $x <= 23; $x++) {
                 $dataSet[] = @$prepData[$x];
             }
             $graphicType = "bar";
             break;
         case 'spotsperweekday':
             $prepData = $this->prepareData($spotStatistics->getSpotCountPerWeekday($limit, $lastUpdate));
             $legend = array(_("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday"), _("Sunday"));
             $dataSet = array(@$prepData[1], @$prepData[2], @$prepData[3], @$prepData[4], @$prepData[5], @$prepData[6], @$prepData[0]);
             $graphicType = "bar";
             break;
         case 'spotspermonth':
             $prepData = $this->prepareData($spotStatistics->getSpotCountPerMonth($limit, $lastUpdate));
             $legend = array(_("January"), _("February"), _("March"), _("April"), _("May"), _("June"), _("July"), _("August"), _("September"), _("October"), _("November"), _("December"));
             for ($x = 1; $x <= 12; $x++) {
                 $dataSet[] = @$prepData[$x];
             }
             $graphicType = "bar";
             break;
         case 'spotspercategory':
             $prepData = $this->prepareData($spotStatistics->getSpotCountPerCategory($limit, $lastUpdate));
             $legend = array(_(SpotCategories::HeadCat2Desc(0)), _(SpotCategories::HeadCat2Desc(1)), _(SpotCategories::HeadCat2Desc(2)), _(SpotCategories::HeadCat2Desc(3)));
             for ($x = 0; $x <= 3; $x++) {
                 $dataSet[] = @$prepData[$x];
             }
             $graphicType = "3Dpie";
             break;
     }
     # switch
     array_walk($dataSet, create_function('& $item, $key', 'if ($item === NULL) $item = 0;'));
     $title = $graphs[$graph];
     if (!empty($limit)) {
         $title .= " (" . $limits[$limit] . ")";
     }
     # if
     $imgData = new pData();
     if ($graphicType == "bar") {
         $imgData->addPoints($dataSet, "data");
         $imgData->addPoints($legend, "legend");
         $imgData->setAbscissa("legend");
         $imgData->setPalette("data", array("R" => 0, "G" => 108, "B" => 171, "Alpha" => 100));
         $img = new pImage($width, $height, $imgData);
         $img->drawGradientArea(0, $titleHeight, $width, $height, DIRECTION_VERTICAL, array("StartR" => 200, "StartG" => 200, "StartB" => 200, "EndR" => 18, "EndG" => 52, "EndB" => 86, "Alpha" => 100));
         $img->drawGradientArea(0, 0, $width, $titleHeight, DIRECTION_VERTICAL, array("StartR" => 18, "StartG" => 52, "StartB" => 86, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 100));
         $img->setFontProperties(array("FontName" => "images/ttf/liberation-sans/LiberationSans-Bold.ttf", "FontSize" => 10));
         $img->drawText($width / 2, 13, $title, array("Align" => TEXT_ALIGN_MIDDLEMIDDLE, "R" => 255, "G" => 255, "B" => 255));
         $img->setFontProperties(array("R" => 255, "G" => 255, "B" => 255, "FontName" => "images/ttf/liberation-sans/LiberationSans-Regular.ttf", "FontSize" => 9));
         $img->setGraphArea(60, $titleHeight + 20, $width - 50, $height - 30);
         $img->drawScale(array("GridR" => 200, "GridG" => 200, "GridB" => 200, "Mode" => SCALE_MODE_START0));
         $img->drawBarChart(array("Gradient" => TRUE, "GradientMode" => GRADIENT_EFFECT_CAN, "DisplayPos" => LABEL_POS_INSIDE, "DisplayValues" => TRUE, "Surrounding" => 10));
     } elseif ($graphicType == "3Dpie") {
         include_once "images/pchart/pPie.class.php";
         $imgData->addPoints($dataSet, "data");
         $imgData->addPoints($legend, "legend");
         $imgData->setAbscissa("legend");
         $img = new pImage($width, $height, $imgData, TRUE);
         $PieChart = new pPie($img, $imgData);
         $img->drawGradientArea(0, $titleHeight, $width, $height, DIRECTION_VERTICAL, array("StartR" => 200, "StartG" => 200, "StartB" => 200, "EndR" => 18, "EndG" => 52, "EndB" => 86, "Alpha" => 100));
         $img->drawGradientArea(0, 0, $width, $titleHeight, DIRECTION_VERTICAL, array("StartR" => 18, "StartG" => 52, "StartB" => 86, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 100));
         $img->setFontProperties(array("FontName" => "images/ttf/liberation-sans/LiberationSans-Bold.ttf", "FontSize" => 10));
         $img->drawText($width / 2, 13, $title, array("Align" => TEXT_ALIGN_MIDDLEMIDDLE, "R" => 255, "G" => 255, "B" => 255));
         $PieChart->setSliceColor(0, array("R" => 0, "G" => 108, "B" => 171));
         $PieChart->setSliceColor(1, array("R" => 205, "G" => 159, "B" => 0));
         $PieChart->setSliceColor(2, array("R" => 0, "G" => 171, "B" => 0));
         $PieChart->setSliceColor(3, array("R" => 171, "G" => 28, "B" => 0));
         $img->setFontProperties(array("FontName" => "images/ttf/liberation-sans/LiberationSans-Regular.ttf", "FontSize" => 9));
         $PieChart->draw3DPie($width / 2, $height / 2 + $titleHeight, array("Radius" => $width / 2 - 100, "SecondPass" => TRUE, "DrawLabels" => TRUE, "WriteValues" => TRUE, "Precision" => 2, "ValueR" => 0, "ValueG" => 0, "ValueB" => 0, "ValueAlpha" => 100, "SkewFactor" => 0.6, "LabelR" => 255, "LabelG" => 255, "LabelB" => 255, "LabelAlpha" => 100));
     }
     # if
     if (isset($img)) {
         ob_start();
         $img->render(NULL);
         $imageString = ob_get_clean();
         $data = $this->getImageInfoFromString($imageString);
         return array('metadata' => $data['metadata'], 'content' => $imageString);
     }
     # img
 }
Example #14
0
$scaleSettings = array("XMargin" => 10, "YMargin" => 10, "Floating" => TRUE, "GridR" => 200, "GridG" => 200, "GridB" => 200, "GridAlpha" => 100, "DrawSubTicks" => TRUE, "CycleBackground" => TRUE);
$myPicture->drawScale($scaleSettings);
/* Write the chart legend */
//$myPicture->drawLegend(640,20,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));
/* Turn on Antialiasing */
$myPicture->Antialias = TRUE;
/* Enable shadow computing */
//$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
/* Draw the area chart */
//$Threshold = "";
// $Threshold[] = array("Min"=>0,"Max"=>5,"R"=>187,"G"=>220,"B"=>0,"Alpha"=>100);
//$Threshold[] = array("Min"=>5,"Max"=>10,"R"=>240,"G"=>132,"B"=>20,"Alpha"=>100);
// $Threshold[] = array("Min"=>10,"Max"=>20,"R"=>240,"G"=>91,"B"=>20,"Alpha"=>100);
//$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>20));
//$myPicture->drawAreaChart(array("Threshold"=>$Threshold));
/* Draw a line chart over */
$myPicture->drawLineChart(array("ForceColor" => TRUE, "ForceR" => 0, "ForceG" => 0, "ForceB" => 0));
/* Draw a plot chart over */
//$myPicture->drawPlotChart(array("PlotBorder"=>TRUE,"BorderSize"=>1,"Surrounding"=>-255,"BorderAlpha"=>80));
/* Write the thresholds */
$myPicture->drawThreshold(3000, array("WriteCaption" => FALSE, "Caption" => "max", "Alpha" => 70, "Ticks" => 2, "R" => 0, "G" => 0, "B" => 255));
$myPicture->drawThreshold(4250, array("WriteCaption" => FALSE, "Caption" => "min", "Alpha" => 70, "Ticks" => 2, "R" => 0, "G" => 0, "B" => 255));
//$myPicture->drawThreshold(10,array("WriteCaption"=>TRUE,"Caption"=>"Error Zone","Alpha"=>70,"Ticks"=>2,"R"=>0,"G"=>0,"B"=>255));
/* Render the picture (choose the best way) */
//imagejpeg ( $myPicture, "myPicture.jpg" , 100);		//saves Image to Server
$voltagedatapng = $path . "/voltage.png";
$myPicture->render($voltagedatapng);
// debug ==> picture debug... show image
// header('Content-Type: image/png');
// imagejpeg ( $myPicture);
//$myPicture->autoOutput("pictures/example.drawAreaChart.threshold.png");
 function showTimeline(CommonGLPI $ticket, $params = array())
 {
     global $CFG_GLPI;
     /* Create and populate the pData object */
     $MyData = new pData();
     /* Create the pChart object */
     $myPicture = new pImage(820, 29, $MyData);
     /* Create the pIndicator object */
     $Indicator = new pIndicator($myPicture);
     $myPicture->setFontProperties(array("FontName" => GLPI_ROOT . "/plugins/timelineticket/lib/pChart2.1.4/fonts/pf_arma_five.ttf", "FontSize" => 6));
     /* Define the indicator sections */
     $IndicatorSections = array();
     $_groupsfinished = array();
     $a_groups_list = array();
     $IndicatorSections = PluginTimelineticketToolbox::getDetails($ticket, 'group');
     foreach ($IndicatorSections as $groups_id => $data) {
         $a_groups_list[$groups_id] = $groups_id;
         $a_end = end($data);
         if ($a_end['R'] == 235 && $a_end['G'] == 235 && $a_end['B'] == 235) {
             $_groupsfinished[$groups_id] = true;
         } else {
             $_groupsfinished[$groups_id] = false;
         }
     }
     echo "<tr>";
     echo "<th colspan='2'>";
     if (count($a_groups_list) > 1) {
         _e('Groups in charge of the ticket', 'timelineticket');
     } else {
         _e('Group in charge of the ticket');
     }
     echo "</th>";
     echo "</tr>";
     $mylevels = array();
     $restrict = getEntitiesRestrictRequest('', "glpi_plugin_timelineticket_grouplevels", '', '', true);
     $restrict .= " ORDER BY rank";
     $levels = getAllDatasFromTable("glpi_plugin_timelineticket_grouplevels", $restrict);
     if (!empty($levels)) {
         foreach ($levels as $level) {
             if (!empty($level["groups"])) {
                 $groups = json_decode($level["groups"], true);
                 $mylevels[$level["name"]] = $groups;
             }
         }
     }
     $ticketlevels = array();
     foreach ($IndicatorSections as $groups_id => $array) {
         foreach ($mylevels as $name => $groups) {
             if (in_array($groups_id, $groups)) {
                 $ticketlevels[$name][] = $groups_id;
             }
         }
     }
     //No levels
     if (sizeof($ticketlevels) == 0) {
         foreach ($IndicatorSections as $groups_id => $array) {
             $ticketlevels[0][] = $groups_id;
         }
     }
     ksort($ticketlevels);
     foreach ($ticketlevels as $name => $groups) {
         if (!isset($ticketlevels[0])) {
             echo "<tr>";
             echo "<th colspan='2'>";
             echo $name;
             echo "</th>";
             echo "</tr>";
         }
         foreach ($IndicatorSections as $groups_id => $array) {
             if (in_array($groups_id, $groups)) {
                 echo "<tr class='tab_bg_2'>";
                 echo "<td width='100'>";
                 echo Dropdown::getDropdownName("glpi_groups", $groups_id);
                 echo "</td>";
                 echo "<td>";
                 if ($ticket->fields['status'] != Ticket::CLOSED && $_groupsfinished[$groups_id] === false) {
                     $IndicatorSettings = array("Values" => array(100, 201), "CaptionPosition" => INDICATOR_CAPTION_BOTTOM, "CaptionLayout" => INDICATOR_CAPTION_DEFAULT, "CaptionR" => 0, "CaptionG" => 0, "CaptionB" => 0, "DrawLeftHead" => false, "DrawRightHead" => true, "ValueDisplay" => false, "IndicatorSections" => $array, "SectionsMargin" => 0);
                     $Indicator->draw(2, 2, 805, 25, $IndicatorSettings);
                 } else {
                     $IndicatorSettings = array("Values" => array(100, 201), "CaptionPosition" => INDICATOR_CAPTION_BOTTOM, "CaptionLayout" => INDICATOR_CAPTION_DEFAULT, "CaptionR" => 0, "CaptionG" => 0, "CaptionB" => 0, "DrawLeftHead" => false, "DrawRightHead" => false, "ValueDisplay" => false, "IndicatorSections" => $array, "SectionsMargin" => 0);
                     $Indicator->draw(2, 2, 814, 25, $IndicatorSettings);
                 }
                 $filename = $uid = Session::getLoginUserID(false) . "_testgroup" . $groups_id;
                 $myPicture->render(GLPI_GRAPH_DIR . "/" . $filename . ".png");
                 echo "<img src='" . $CFG_GLPI['root_doc'] . "/front/graph.send.php?file=" . $filename . ".png'><br/>";
                 echo "</td>";
                 echo "</tr>";
             }
         }
     }
     // Return list for unit tests
     return $IndicatorSections;
 }
Example #16
0
 private function drawBarChart($filename, $yAxisLabel, $dataSeries, $labelSeries)
 {
     /* Create and populate the pData object */
     $MyData = new pData();
     $MyData->addPoints($dataSeries, "Members");
     $MyData->setAxisName(0, "Members");
     $MyData->addPoints($labelSeries, "Languages");
     $MyData->setSerieDescription("Languages", "Languages");
     $MyData->setAbscissa("Languages");
     /* Create the pChart object */
     $myPicture = new pImage(400, 250, $MyData, true);
     //$myPicture->drawGradientArea(0,0,500,500,DIRECTION_VERTICAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>100));
     //$myPicture->drawGradientArea(0,0,500,500,DIRECTION_HORIZONTAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>20));
     $myPicture->setFontProperties(array("FontName" => "../lib/pchart-2.1.3/fonts/verdana.ttf", "FontSize" => 6));
     /* Draw the chart scale */
     $myPicture->setGraphArea(70, 20, 380, 200);
     $myPicture->drawScale(array("CycleBackground" => TRUE, "LabelRotation" => 30, "DrawSubTicks" => TRUE, "GridR" => 0, "GridG" => 0, "GridB" => 0, "GridAlpha" => 10));
     /* Turn on shadow computing */
     $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10));
     /* Create the per bar palette */
     $Palette = array("0" => array("R" => 188, "G" => 224, "B" => 46, "Alpha" => 100), "1" => array("R" => 224, "G" => 100, "B" => 46, "Alpha" => 100), "2" => array("R" => 224, "G" => 214, "B" => 46, "Alpha" => 100), "3" => array("R" => 46, "G" => 151, "B" => 224, "Alpha" => 100), "4" => array("R" => 176, "G" => 46, "B" => 224, "Alpha" => 100), "5" => array("R" => 224, "G" => 46, "B" => 117, "Alpha" => 100), "6" => array("R" => 92, "G" => 224, "B" => 46, "Alpha" => 100), "7" => array("R" => 224, "G" => 176, "B" => 46, "Alpha" => 100), "8" => array("R" => 120, "G" => 59, "B" => 19, "Alpha" => 100), "9" => array("R" => 10, "G" => 79, "B" => 39, "Alpha" => 100), "10" => array("R" => 100, "G" => 200, "B" => 59, "Alpha" => 100));
     /* Draw the chart */
     $myPicture->drawBarChart(array("DisplayPos" => LABEL_POS_OUTSIDE, "DisplayValues" => TRUE, "Surrounding" => 30, "OverrideColors" => $Palette));
     /* Write the legend */
     $myPicture->drawLegend(570, 215, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL));
     $myPicture->render($filename . ".png");
 }
 public function generate_chart($chart_name)
 {
     global $wgBugzillaChartStorage, $wgBugzillaFontStorage;
     $pData = new pData();
     $pData->addPoints($this->query->data['data'], 'Counts');
     $pData->setAxisName(0, 'Bugs');
     $pData->addPoints($this->query->data['x_labels'], "Bugs");
     $pData->setSerieDescription("Bugs", "Bugs");
     $pData->setAbscissa("Bugs");
     $pImage = new pImage(600, 300, $pData);
     $pImage->setFontProperties(array('FontName' => $wgBugzillaFontStorage . '/verdana.ttf', 'FontSize' => 6));
     $pImage->setGraphArea(75, 30, 580, 280);
     $pImage->drawScale(array("CycleBackground" => TRUE, 'Factors' => array(1), "DrawSubTicks" => FALSE, "GridR" => 0, "GridG" => 0, "GridB" => 0, "GridAlpha" => 10, "Pos" => SCALE_POS_TOPBOTTOM));
     $pImage->drawBarChart();
     $pImage->render($wgBugzillaChartStorage . '/' . $chart_name . '.png');
     $cache = $this->_getCache();
     $cache->set($chart_name, $chart_name . '.png');
     return $chart_name;
 }
Example #18
0
/* Create and populate the pData object */
$MyData = new pData();
$MyData->addPoints($NbSuicide, "Nombre de suicides");
$MyData->setAxisName(0, "Nombre de suicides");
$MyData->addPoints($NbAxe, "Numéro de l'expérience");
$MyData->setSerieDescription("Months", "Month");
$MyData->setAbscissa("Numéro de l'expérience");
/* Create the pChart object */
$myPicture = new pImage($LongueurGraph + 100, $HauteurGraph + 30, $MyData);
/* Turn of Antialiasing */
$myPicture->Antialias = TRUE;
/* Add a border to the picture */
$myPicture->drawRectangle(0, 0, $LongueurGraph + 99, $HauteurGraph + 29, array("R" => 0, "G" => 0, "B" => 0));
/* Set the default font */
$myPicture->setFontProperties(array("FontName" => "./pf_arma_five.ttf", "FontSize" => 6));
/* Define the chart area */
$myPicture->setGraphArea(60, 40, $LongueurGraph + 50, $HauteurGraph);
/* Draw the scale */
$scaleSettings = array("GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => TRUE, "CycleBackground" => TRUE);
$myPicture->drawScale($scaleSettings);
/* Write the chart legend */
$myPicture->drawLegend($LongueurGraph, 12, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL));
/* Turn on shadow computing */
$myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10));
/* Draw the chart */
$myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10));
$settings = array("Gradient" => TRUE, "GradientMode" => GRADIENT_EFFECT_CAN, "DisplayPos" => LABEL_POS_INSIDE, "DisplayValues" => TRUE, "DisplayR" => 255, "DisplayG" => 255, "DisplayB" => 255, "DisplayShadow" => TRUE, "Surrounding" => 10);
$myPicture->drawBarChart();
/* Render the picture (choose the best way) */
$myPicture->render($fichier . ".png");
 function launch()
 {
     global $configArray;
     global $interface;
     //////////Populate the Date Filter Start
     //Grab the Selected Date Start
     if (isset($_REQUEST['dateFilterStart'])) {
         if (preg_match('/\\d{1,2}\\/\\d{1,2}\\/\\d{4}/', $_REQUEST['dateFilterStart'])) {
             $selectedDateStart = DateTime::createFromFormat('m/d/Y', $_REQUEST['dateFilterStart']);
             $selectedDateStart = $selectedDateStart->getTimestamp();
         } else {
             $selectedDateStart = strtotime($_REQUEST['dateFilterStart']);
         }
     } else {
         $selectedDateStart = strtotime('-30 days');
     }
     $selectedDateStart = date('Y-m-d', $selectedDateStart);
     $interface->assign('selectedDateStart', $selectedDateStart);
     //Populate the Date Filter End
     //Grab the Selected End Date
     if (isset($_REQUEST['dateFilterEnd'])) {
         if (preg_match('/\\d{1,2}\\/\\d{1,2}\\/\\d{4}/', $_REQUEST['dateFilterEnd'])) {
             $selectedDateEnd = DateTime::createFromFormat('m/d/Y', $_REQUEST['dateFilterEnd']);
             $selectedDateEnd = $selectedDateEnd->getTimestamp();
         } else {
             $selectedDateEnd = strtotime($_REQUEST['dateFilterEnd']);
         }
     } else {
         $selectedDateEnd = strtotime('today');
     }
     $selectedDateEnd = date('Y-m-d', $selectedDateEnd);
     $interface->assign('selectedDateEnd', $selectedDateEnd);
     //////////Populate the Stores Filter
     $queryHostsFilter = "SELECT DISTINCT linkHost AS linkHost FROM external_link_tracking ORDER BY linkHost ASC";
     $externalLinkTracking = new ExternalLinkTracking();
     $externalLinkTracking->query($queryHostsFilter);
     $allHosts = array();
     while ($externalLinkTracking->fetch()) {
         $allHosts[] = $externalLinkTracking->linkHost;
     }
     $interface->assign('hostFilter', $allHosts);
     //////////Grab the Selected Hosts Filter Value
     if (isset($_REQUEST['hostFilter'])) {
         $selectedHosts = $_REQUEST['hostFilter'];
     } else {
         $selectedHosts = $allHosts;
     }
     $interface->assign('selectedHosts', $selectedHosts);
     $baseQueryLinks = "SELECT COUNT(externalLinkId) AS timesFollowed, recordId, linkUrl, linkHost " . "FROM external_link_tracking " . "WHERE (DATE_FORMAT(trackingDate, '%Y-%m-%d')) BETWEEN '" . $selectedDateStart . "' AND '" . $selectedDateEnd . "' ";
     if (count($selectedHosts) > 0) {
         $hosts = join("','", $selectedHosts);
         $baseQueryLinks .= "AND linkHost IN ('" . $hosts . "') ";
     }
     $baseQueryLinks .= "GROUP BY recordId, linkUrl ";
     //////////Get a count of the page view data
     $queryPurchasesCount = "SELECT COUNT(*) AS RowCount from ( " . $baseQueryLinks . ") As ResultCount";
     $resPurchasesCount = mysql_query($queryPurchasesCount);
     if ($resPurchasesCount > 0) {
         $rowCount = mysql_fetch_object($resPurchasesCount);
         $totalResultCount = $rowCount->RowCount;
     } else {
         $totalResultCount = 0;
     }
     //////////Create the items per page array
     $itemsPerPageList = $this->getItemsPerPageList();
     ///////////////////PAGING
     $currentPage = 1;
     $resultTotal = $totalResultCount;
     $startRecord = 1;
     if (isset($_GET['itemsPerPage'])) {
         switch ($_GET['itemsPerPage']) {
             case "20":
                 $itemsPerPage = 20;
                 $itemsPerPageList["20"]["selected"] = true;
                 break;
             case "100":
                 $itemsPerPage = 100;
                 $itemsPerPageList["100"]["selected"] = true;
                 break;
             default:
                 $itemsPerPage = 50;
                 $itemsPerPageList["50"]["selected"] = true;
         }
     } else {
         $itemsPerPage = 50;
         $itemsPerPageList["50"]["selected"] = true;
     }
     $endRecord = $itemsPerPage;
     $interface->assign('itemsPerPageList', $itemsPerPageList);
     if (isset($_GET['page'])) {
         $currentPage = $_GET['page'];
         // 1st record is easy, work out the start of this page
         $startRecord = ($currentPage - 1) * $itemsPerPage + 1;
         // Last record needs more care
         if ($resultTotal < $itemsPerPage) {
             // There are less records returned then one page, use total results
             $endRecord = $resultTotal;
         } else {
             if ($currentPage * $itemsPerPage > $resultTotal) {
                 // The end of the current page runs past the last record, use total results
                 $endRecord = $resultTotal;
             } else {
                 // Otherwise use the last record on this page
                 $endRecord = $currentPage * $itemsPerPage;
             }
         }
     }
     //////////Get the Page View Data with paging and sorting
     if (isset($_GET['reportSort'])) {
         $sortValue = $_GET['reportSort'];
     }
     //Create values for how to sort the table.
     $sortList = $this->getSortList();
     if (!isset($sortValue)) {
         $sortValue = 'UrlASC';
     }
     $sortList[$sortValue]["selected"] = true;
     $baseQueryLinks .= $sortList[$sortValue]['sql'];
     //append on a limit to return a result
     if (!isset($_REQUEST['exportToExcel'])) {
         $baseQueryLinks .= "LIMIT " . ($startRecord - 1) . ", " . $itemsPerPage . " ";
     }
     $resPurchases = mysql_query($baseQueryLinks);
     $resultsPurchases = array();
     if ($resPurchases > 0) {
         //Build an array based on the data to dump out to the grid
         $i = 0;
         while ($r = mysql_fetch_array($resPurchases)) {
             $recordId = $r['recordId'];
             $fullId = $r['recordId'];
             if (preg_match('/econtentRecord(\\d+)/', $recordId, $matches)) {
                 require_once ROOT_DIR . '/sys/eContent/EContentRecord.php';
                 $econtentRecord = new EContentRecord();
                 $econtentRecord->id = $matches[1];
                 $econtentRecord->find(true);
                 $recordId = $econtentRecord->ilsId;
                 $title = $econtentRecord->title;
             } else {
                 $resource = new Resource();
                 $resource->record_id = $recordId;
                 $resource->source = 'VuFind';
                 $resource->find(true);
                 $title = $resource->title;
             }
             $tmp = array('recordId' => $recordId, 'recordUrl' => '/Record/' . $fullId, 'title' => $title, 'timesFollowed' => $r['timesFollowed'], 'linkHost' => $r['linkHost'], 'linkUrl' => $r['linkUrl']);
             $resultsPurchases[$i++] = $tmp;
         }
     }
     $interface->assign('resultLinks', $resultsPurchases);
     //////////Paging Array
     $summary = array('page' => $currentPage, 'perPage' => $itemsPerPage, 'resultTotal' => $totalResultCount, 'startRecord' => $startRecord, 'endRecord' => $endRecord);
     $interface->assign('recordCount', $summary['resultTotal']);
     $interface->assign('recordStart', $summary['startRecord']);
     $interface->assign('recordEnd', $summary['endRecord']);
     // Process Paging using VuFind Pager object
     if (strrpos($_SERVER["REQUEST_URI"], "page=")) {
         //replace the page variable with a new one
         $link = str_replace("page=" . $currentPage, "page=%d", $_SERVER["REQUEST_URI"]);
     } else {
         if (strrpos($_SERVER["REQUEST_URI"], "?")) {
             $link = $_SERVER["REQUEST_URI"] . "&page=%d";
         } else {
             $link = $_SERVER["REQUEST_URI"] . "?page=%d";
         }
     }
     $options = array('totalItems' => $summary['resultTotal'], 'fileName' => $link, 'perPage' => $summary['perPage']);
     $pager = new VuFindPager($options);
     $interface->assign('pageLinks', $pager->getLinks());
     ///////////////////END PAGING
     //////////Sorting
     $sortUrl = $_SERVER["REQUEST_URI"];
     if (isset($sortValue)) {
         //Set the URL for sorting
         if (strrpos($_SERVER["REQUEST_URI"], "reportSort=")) {
             //replace the page variable with a new one
             $sortUrl = str_replace("sort=" . $currentPage, "reportSort=" . $sortValue, $_SERVER["REQUEST_URI"]);
         } else {
             if (strrpos($_SERVER["REQUEST_URI"], "?")) {
                 $sortUrl = $_SERVER["REQUEST_URI"] . "&reportSort=" . $sortValue;
             } else {
                 $sortUrl = $_SERVER["REQUEST_URI"] . "?reportSort=" . $sortValue;
             }
         }
     }
     $interface->assign('sortUrl', $sortUrl);
     $interface->assign('sortList', $sortList);
     //////////CHART
     //Create the chart and load data into the results.
     $queryDailyPurchases = "SELECT DATE_FORMAT(trackingDate, '%Y-%m-%d') as date, COUNT(externalLinkId) AS timesFollowed, linkHost FROM external_link_tracking  " . "WHERE (DATE_FORMAT(trackingDate, '%Y-%m-%d')) BETWEEN '" . $selectedDateStart . "' AND '" . $selectedDateEnd . "' ";
     if (count($selectedHosts) > 0) {
         $hosts = join("','", $selectedHosts);
         $queryDailyPurchases .= "AND linkHost IN ('" . $hosts . "') ";
     }
     $queryDailyPurchases .= "GROUP BY DATE_FORMAT(trackingDate, '%Y-%m-%d'), linkHost ORDER BY trackingDate ASC";
     $dailyUsage = mysql_query($queryDailyPurchases);
     //Initialize data by loading all of the dates that we are looking at so we can show the correct counts or each series on the right day.
     $check_date = $selectedDateStart;
     $datesInReport = array();
     $linkUsageByHostByDay = array();
     foreach ($allHosts as $hostName) {
         $linkUsageByHostByDay[$hostName] = array();
     }
     while ($check_date != $selectedDateEnd) {
         $check_date = date("Y-m-d", strtotime("+1 day", strtotime($check_date)));
         $datesInReport[] = $check_date;
         //Default number of link usage for the day to 0
         foreach ($allHosts as $host) {
             $linkUsageByHostByDay[$host][$check_date] = 0;
         }
     }
     //Chart section
     $reportData = new pData();
     while ($r = mysql_fetch_array($dailyUsage)) {
         $linkHost = $r['linkHost'];
         $linkUsageByHostByDay[$linkHost][$r['date']] = $r['timesFollowed'];
     }
     foreach ($linkUsageByHostByDay as $hostName => $dailyResults) {
         $reportData->addPoints($dailyResults, $hostName);
     }
     $reportData->setAxisName(0, "Usage");
     $reportData->addPoints($datesInReport, "Dates");
     $reportData->setAbscissa("Dates");
     /* Create the pChart object */
     $myPicture = new pImage(700, 290, $reportData);
     /* Draw the background */
     $Settings = array("R" => 225, "G" => 225, "B" => 225);
     $myPicture->drawFilledRectangle(0, 0, 700, 290, $Settings);
     /* Add a border to the picture */
     $myPicture->drawRectangle(0, 0, 699, 289, array("R" => 0, "G" => 0, "B" => 0));
     $myPicture->setFontProperties(array("FontName" => "sys/pChart/Fonts/verdana.ttf", "FontSize" => 9));
     $myPicture->setGraphArea(50, 30, 670, 190);
     //$myPicture->drawFilledRectangle(30,30,670,150,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10));
     $myPicture->drawScale(array("DrawSubTicks" => TRUE, "LabelRotation" => 90));
     $myPicture->setFontProperties(array("FontName" => "sys/pChart/Fonts/verdana.ttf", "FontSize" => 9));
     $myPicture->drawLineChart(array("DisplayValues" => TRUE, "DisplayColor" => DISPLAY_AUTO));
     /* Write the chart legend */
     $myPicture->drawLegend(80, 20, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL));
     /* Render the picture (choose the best way) */
     $time = time();
     $chartHref = "/images/charts/dailyPurchases{$time}.png";
     $chartPath = $configArray['Site']['local'] . $chartHref;
     $myPicture->render($chartPath);
     $interface->assign('chartPath', $chartHref);
     //////////EXPORT To EXCEL
     if (isset($_REQUEST['exportToExcel'])) {
         //PHPEXCEL
         // Create new PHPExcel object
         $objPHPExcel = new PHPExcel();
         // Set properties
         $objPHPExcel->getProperties()->setTitle("External Link Usage Report")->setCategory("External Link Usage Report");
         // Add some data
         $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'External Link Usage Report')->setCellValue('A3', 'Record Id')->setCellValue('B3', 'Url')->setCellValue('C3', 'Host')->setCellValue('D3', 'Usage');
         $a = 4;
         //Loop Through The Report Data
         foreach ($resultsPurchases as $resultsPurchase) {
             $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A' . $a, $resultsPurchase['recordId'])->setCellValue('B' . $a, $resultsPurchase['linkUrl'])->setCellValue('C' . $a, $resultsPurchase['linkHost'])->setCellValue('D' . $a, $resultsPurchase['timesFollowed']);
             $a++;
         }
         $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
         $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
         $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
         // Rename sheet
         $objPHPExcel->getActiveSheet()->setTitle('Simple');
         // Set active sheet index to the first sheet, so Excel opens this as the first sheet
         $objPHPExcel->setActiveSheetIndex(0);
         // Redirect output to a client's web browser (Excel5)
         header('Content-Type: application/vnd.ms-excel');
         header('Content-Disposition: attachment;filename="ExternalLinkReport.xls"');
         header('Cache-Control: max-age=0');
         $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
         $objWriter->save('php://output');
         exit;
     }
     $interface->setPageTitle('Report - External Link Tracking');
     $interface->setTemplate('reportExternalLinks.tpl');
     $interface->display('layout.tpl');
 }
 function generateGraphByStatus($periodData, $periods, $statuses)
 {
     global $configArray;
     global $interface;
     $reportData = new pData();
     //Add points for each status
     $periodsFormatted = array();
     foreach ($statuses as $status => $statusLabel) {
         $statusData = array();
         foreach ($periodData as $date => $periodInfo) {
             $periodsFormatted[$date] = date('M-d-Y', $date);
             $statusData[$date] = isset($periodInfo[$status]) ? $periodInfo[$status] : 0;
         }
         $reportData->addPoints($statusData, $status);
     }
     $reportData->setAxisName(0, "Number of files");
     $reportData->addPoints($periodsFormatted, "Dates");
     $reportData->setAbscissa("Dates");
     /* Create the pChart object */
     $myPicture = new pImage(700, 290, $reportData);
     /* Draw the background */
     $Settings = array("R" => 225, "G" => 225, "B" => 225);
     $myPicture->drawFilledRectangle(0, 0, 700, 290, $Settings);
     /* Add a border to the picture */
     $myPicture->drawRectangle(0, 0, 699, 289, array("R" => 0, "G" => 0, "B" => 0));
     $myPicture->setFontProperties(array("FontName" => "sys/pChart/Fonts/verdana.ttf", "FontSize" => 9));
     $myPicture->setGraphArea(50, 30, 670, 190);
     //$myPicture->drawFilledRectangle(30,30,670,150,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10));
     $myPicture->drawScale(array("DrawSubTicks" => TRUE, "LabelRotation" => 90));
     $myPicture->setFontProperties(array("FontName" => "sys/pChart/Fonts/verdana.ttf", "FontSize" => 9));
     $myPicture->drawLineChart(array("DisplayValues" => TRUE, "DisplayColor" => DISPLAY_AUTO));
     /* Write the chart legend */
     $myPicture->drawLegend(80, 20, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL));
     /* Render the picture (choose the best way) */
     $chartHref = "/images/charts/eContentImportSummaryByStatus" . time() . ".png";
     $chartPath = $configArray['Site']['local'] . $chartHref;
     $myPicture->render($chartPath);
     $interface->assign('chartByStatus', $chartHref);
 }
 function showTimeline($ticket, $params = array())
 {
     global $CFG_GLPI;
     /* Create and populate the pData object */
     $MyData = new pData();
     /* Create the pChart object */
     $myPicture = new pImage(820, 29, $MyData);
     /* Create the pIndicator object */
     $Indicator = new pIndicator($myPicture);
     $myPicture->setFontProperties(array("FontName" => GLPI_ROOT . "/plugins/timelineticket/lib/pChart2.1.4/fonts/pf_arma_five.ttf", "FontSize" => 6));
     /* Define the indicator sections */
     $IndicatorSections = array();
     $_usersfinished = array();
     $a_users_list = array();
     $IndicatorSections = PluginTimelineticketToolbox::getDetails($ticket, 'user');
     foreach ($IndicatorSections as $users_id => $data) {
         $a_users_list[$users_id] = $users_id;
         $a_end = end($data);
         if ($a_end['R'] == 235 && $a_end['G'] == 235 && $a_end['B'] == 235) {
             $_usersfinished[$users_id] = true;
         } else {
             $_usersfinished[$users_id] = false;
         }
     }
     echo "<tr>";
     echo "<th colspan='2'>";
     if (count($a_users_list) > 1) {
         _e('Technicians in charge of the ticket', 'timelineticket');
     } else {
         _e('Technician in charge of the ticket');
     }
     echo "</th>";
     echo "</tr>";
     foreach ($IndicatorSections as $users_id => $array) {
         echo "<tr class='tab_bg_2'>";
         echo "<td width='100'>";
         echo getUsername($users_id);
         echo "</td>";
         echo "<td>";
         if ($ticket->fields['status'] != Ticket::CLOSED && $_usersfinished[$users_id] != 0) {
             $IndicatorSettings = array("Values" => array(100, 201), "CaptionPosition" => INDICATOR_CAPTION_BOTTOM, "CaptionLayout" => INDICATOR_CAPTION_DEFAULT, "CaptionR" => 0, "CaptionG" => 0, "CaptionB" => 0, "DrawLeftHead" => false, "DrawRightHead" => true, "ValueDisplay" => false, "IndicatorSections" => $array, "SectionsMargin" => 0);
             $Indicator->draw(2, 2, 805, 25, $IndicatorSettings);
         } else {
             $IndicatorSettings = array("Values" => array(100, 201), "CaptionPosition" => INDICATOR_CAPTION_BOTTOM, "CaptionLayout" => INDICATOR_CAPTION_DEFAULT, "CaptionR" => 0, "CaptionG" => 0, "CaptionB" => 0, "DrawLeftHead" => false, "DrawRightHead" => false, "ValueDisplay" => false, "IndicatorSections" => $array, "SectionsMargin" => 0);
             $Indicator->draw(2, 2, 814, 25, $IndicatorSettings);
         }
         $filename = $uid = Session::getLoginUserID(false) . "_testuser" . $users_id;
         $myPicture->render(GLPI_GRAPH_DIR . "/" . $filename . ".png");
         echo "<img src='" . $CFG_GLPI['root_doc'] . "/front/graph.send.php?file=" . $filename . ".png'><br/>";
         echo "</td>";
         echo "</tr>";
     }
 }
Example #22
0
$Config = array("DisplayValues" => 0, "AroundZero" => 0, "BreakVoid" => 1, "RecordImageMap" => FALSE);
$GraphType = 'SplineChart';
switch ($GraphType) {
    case 'AreaChart':
        $myPicture->drawAreaChart($Config);
        break;
    case 'FilledSplineChart':
        $myPicture->drawFilledSplineChart($Config);
        break;
    case 'SplineChart':
        $myPicture->drawSplineChart($Config);
        break;
    case 'BarChart':
        $myPicture->drawBarChart($Config, 'tetimes');
        break;
    case 'StackedBarChart':
        $myPicture->drawStackedBarChart($Config);
        break;
    case 'PlotChart':
        $myPicture->drawPlotChart($Config);
        break;
    default:
        break;
}
$Config = array("FontR" => 0, "FontG" => 0, "FontB" => 0, "FontName" => $LibPath . "fonts/verdana.ttf", "FontSize" => 8, "Margin" => 6, "Alpha" => 30, "BoxSize" => 5, "Style" => LEGEND_NOBORDER, "Mode" => LEGEND_VERTICAL);
$myPicture->drawLegend($Graphwidth - 65, 40, $Config);
$myPicture->setFontProperties(array("FontName" => $LibPath . "fonts/verdana.ttf", "FontSize" => 10));
$TextSettings = array("Align" => TEXT_ALIGN_MIDDLEMIDDLE, "R" => 0, "G" => 0, "B" => 0);
$myPicture->drawText(200, 15, $GraphLabel, $TextSettings);
$myPicture->render(__DIR__ . '/temp/' . $Type . '_' . $SensorID . '.png');
 function showTimeline(Ticket $ticket, $params = array())
 {
     global $DB, $CFG_GLPI;
     /* Create and populate the pData object */
     $MyData = new pData();
     /* Create the pChart object */
     $myPicture = new pImage(820, 29, $MyData);
     /* Create the pIndicator object */
     $Indicator = new pIndicator($myPicture);
     $myPicture->setFontProperties(array("FontName" => GLPI_ROOT . "/plugins/timelineticket/lib/pChart2.1.4/fonts/pf_arma_five.ttf", "FontSize" => 6));
     /* Define the indicator sections */
     $IndicatorSections = array();
     $a_states = array(Ticket::INCOMING, Ticket::ASSIGNED, Ticket::PLANNED, Ticket::WAITING, Ticket::SOLVED, Ticket::CLOSED);
     $a_status_color = array();
     $a_status_color[Ticket::INCOMING] = array('R' => 197, 'G' => 204, 'B' => 79);
     $a_status_color[Ticket::ASSIGNED] = array('R' => 38, 'G' => 174, 'B' => 38);
     $a_status_color[Ticket::PLANNED] = array('R' => 255, 'G' => 102, 'B' => 0);
     $a_status_color[Ticket::WAITING] = array('R' => 229, 'G' => 184, 'B' => 0);
     $a_status_color[Ticket::SOLVED] = array('R' => 83, 'G' => 141, 'B' => 184);
     $a_status_color[Ticket::CLOSED] = array('R' => 51, 'G' => 51, 'B' => 51);
     $delaystatus = array();
     foreach ($a_states as $status) {
         $IndicatorSections[$status] = '';
         $delaystatus[$status] = 0;
     }
     $a_status = $this->find("`tickets_id`='" . $ticket->getField('id') . "'", "`date`");
     $begin = 0;
     if ($params['totaltime'] > 0) {
         foreach ($a_status as $data) {
             foreach ($a_states as $statusSection) {
                 $R = 235;
                 $G = 235;
                 $B = 235;
                 $caption = '';
                 if ($statusSection == $data['old_status']) {
                     $R = $a_status_color[$statusSection]['R'];
                     $G = $a_status_color[$statusSection]['G'];
                     $B = $a_status_color[$statusSection]['B'];
                     //$caption = $status;
                     $delaystatus[$statusSection] += round($data['delay'] * 100 / $params['totaltime'], 2);
                 }
                 $IndicatorSections[$statusSection][] = array("Start" => $begin, "End" => $begin + $data['delay'], "Caption" => $caption, "R" => $R, "G" => $G, "B" => $B);
             }
             $begin += $data['delay'];
         }
         if ($ticket->fields['status'] != Ticket::CLOSED) {
             foreach ($a_states as $statusSection) {
                 $R = 235;
                 $G = 235;
                 $B = 235;
                 $caption = ' ';
                 if ($statusSection == $ticket->fields['status']) {
                     $R = $a_status_color[$statusSection]['R'];
                     $G = $a_status_color[$statusSection]['G'];
                     $B = $a_status_color[$statusSection]['B'];
                     //$caption = $status;
                     $delaystatus[$statusSection] += round(($params['totaltime'] - $begin) * 100 / $params['totaltime'], 2);
                 }
                 $IndicatorSections[$statusSection][] = array("Start" => $begin, "End" => $begin + ($params['totaltime'] - $begin), "Caption" => $caption, "R" => $R, "G" => $G, "B" => $B);
             }
         }
     }
     if (count($a_status) > 1) {
         foreach ($a_states as $status) {
             echo "<tr class='tab_bg_2'>";
             echo "<td width='100'>";
             echo Ticket::getStatus($status);
             echo "<br/>(" . $delaystatus[$status] . "%)";
             echo "</td>";
             echo "<td>";
             if ($ticket->fields['status'] != Ticket::CLOSED) {
                 $IndicatorSettings = array("Values" => array(100, 201), "CaptionPosition" => INDICATOR_CAPTION_BOTTOM, "CaptionLayout" => INDICATOR_CAPTION_DEFAULT, "CaptionR" => 0, "CaptionG" => 0, "CaptionB" => 0, "DrawLeftHead" => FALSE, "ValueDisplay" => false, "IndicatorSections" => $IndicatorSections[$status], "SectionsMargin" => 0);
                 $Indicator->draw(2, 2, 805, 25, $IndicatorSettings);
             } else {
                 $IndicatorSettings = array("Values" => array(100, 201), "CaptionPosition" => INDICATOR_CAPTION_BOTTOM, "CaptionLayout" => INDICATOR_CAPTION_DEFAULT, "CaptionR" => 0, "CaptionG" => 0, "CaptionB" => 0, "DrawLeftHead" => FALSE, "DrawRightHead" => FALSE, "ValueDisplay" => false, "IndicatorSections" => $IndicatorSections[$status], "SectionsMargin" => 0);
                 $Indicator->draw(2, 2, 814, 25, $IndicatorSettings);
             }
             $filename = $uid = Session::getLoginUserID(false) . "_test" . $status;
             $myPicture->render(GLPI_GRAPH_DIR . "/" . $filename . ".png");
             echo "<img src='" . $CFG_GLPI['root_doc'] . "/front/graph.send.php?file=" . $filename . ".png'><br/>";
             echo "</td>";
             echo "</tr>";
         }
     }
     // Display ticket have Due date
     if ($ticket->fields['due_date'] && strtotime(date('Y-m-d H:i:s') - strtotime($ticket->fields['due_date'])) > 0) {
         $calendar = new Calendar();
         $calendars_id = Entity::getUsedConfig('calendars_id', $ticket->fields['entities_id']);
         if ($calendars_id > 0 && $calendar->getFromDB($calendars_id)) {
             $duedate = $calendar->getActiveTimeBetween($ticket->fields['date'], $ticket->fields['due_date']);
             if ($ticket->fields['closedate']) {
                 $dateend = $calendar->getActiveTimeBetween($ticket->fields['due_date'], $ticket->fields['closedate']);
             } else {
                 $dateend = $calendar->getActiveTimeBetween($ticket->fields['due_date'], date('Y-m-d H:i:s'));
             }
         } else {
             // cas 24/24 - 7/7
             $duedate = strtotime($ticket->fields['due_date']) - strtotime($ticket->fields['date']);
             if ($ticket->fields['closedate']) {
                 $dateend = strtotime($ticket->fields['closedate']) - strtotime($ticket->fields['due_date']);
             } else {
                 $dateend = strtotime(date('Y-m-d H:i:s')) - strtotime($ticket->fields['due_date']);
             }
         }
         echo "<tr class='tab_bg_2'>";
         echo "<td width='100' class='tab_bg_2_2'>";
         _e('Late');
         echo "<br/>(" . round($dateend * 100 / $params['totaltime'], 2) . "%)";
         echo "</td>";
         echo "<td>";
         $calendar = new Calendar();
         $calendars_id = Entity::getUsedConfig('calendars_id', $ticket->fields['entities_id']);
         if ($ticket->fields['status'] != Ticket::CLOSED) {
             $IndicatorSettings = array("Values" => array(100, 201), "CaptionPosition" => INDICATOR_CAPTION_BOTTOM, "CaptionLayout" => INDICATOR_CAPTION_DEFAULT, "CaptionR" => 0, "CaptionG" => 0, "CaptionB" => 0, "DrawLeftHead" => FALSE, "ValueDisplay" => false, "IndicatorSections" => array(array("Start" => 0, "End" => $duedate, "Caption" => "", "R" => 235, "G" => 235, "B" => 235), array("Start" => $duedate, "End" => $dateend + $duedate, "Caption" => "", "R" => 255, "G" => 0, "B" => 0)), "SectionsMargin" => 0);
             $Indicator->draw(2, 2, 805, 25, $IndicatorSettings);
         } else {
             $IndicatorSettings = array("Values" => array(100, 201), "CaptionPosition" => INDICATOR_CAPTION_BOTTOM, "CaptionLayout" => INDICATOR_CAPTION_DEFAULT, "CaptionR" => 0, "CaptionG" => 0, "CaptionB" => 0, "DrawLeftHead" => FALSE, "DrawRightHead" => FALSE, "ValueDisplay" => false, "IndicatorSections" => array(array("Start" => 0, "End" => $duedate, "Caption" => "", "R" => 235, "G" => 235, "B" => 235), array("Start" => $duedate, "End" => $dateend + $duedate, "Caption" => "", "R" => 255, "G" => 0, "B" => 0)), "SectionsMargin" => 0);
             $Indicator->draw(2, 2, 814, 25, $IndicatorSettings);
         }
         $filename = $uid = Session::getLoginUserID(false) . "_testduedate";
         $myPicture->render(GLPI_GRAPH_DIR . "/" . $filename . ".png");
         echo "<img src='" . $CFG_GLPI['root_doc'] . "/front/graph.send.php?file=" . $filename . ".png'><br/>";
         echo "</td>";
         echo "</tr>";
     }
 }
 function generate_graph_image($outputfile)
 {
     // Create Graph Dataset and set axis attributes
     $graphData = new pData();
     $graphData->setAxisName(0, $this->ytitle_actual);
     $graphData->addPoints($this->xlabels, "xaxis");
     $graphData->setSerieDescription("xaxis", "xaxis");
     $graphData->setAbscissa("xaxis");
     $graphData->setXAxisName("ooo");
     // Add each series of plot values to dataset, but Reportico will
     // duplicate series were the same data are displayed in different forms
     // so only add each unique series once
     $seriesadded = array();
     foreach ($this->plot as $k => $v) {
         $series = $v["name"] . $k;
         $graphData->addPoints($v["data"], $series);
         $graphData->setSerieDescription($series, $v["legend"]);
     }
     /*
     $graph->xgrid->SetColor($this->xgridcolor);
     $graph->ygrid->SetColor($this->ygridcolor);
     */
     /*
     switch ( $this->xgriddisplay )
     {
     	case "all":
     		$graph->xgrid->Show(true,true);
     		break;
     	case "major":
     		$graph->xgrid->Show(true,false);
     		break;
     	case "minor":
     		$graph->xgrid->Show(false,true);
     		break;
     	case "none":
     	default:
     		$graph->xgrid->Show(false,false);
     		break;
     }
     
     switch ( $this->ygriddisplay )
     {
     	case "all":
     		$graph->ygrid->Show(true,true);
     		break;
     	case "major":
     		$graph->ygrid->Show(true,false);
     		break;
     	case "minor":
     		$graph->ygrid->Show(false,true);
     		break;
     	case "none":
     	default:
     		$graph->ygrid->Show(false,false);
     		break;
     }
     */
     /*
     $graph->xaxis->SetFont($fontfamilies[$xaxisfont],$fontstyles[$xaxisfontstyle], $xaxisfontsize);
     $graph->xaxis->SetColor($xaxiscolor,$xaxisfontcolor);
     $graph->yaxis->SetFont($fontfamilies[$yaxisfont],$fontstyles[$yaxisfontstyle], $yaxisfontsize);
     $graph->yaxis->SetColor($yaxiscolor,$yaxisfontcolor);
     $graph->xaxis->title->SetFont($fontfamilies[$xtitlefont],$fontstyles[$xtitlefontstyle], $xtitlefontsize);
     $graph->xaxis->title->SetColor($xtitlecolor);
     $graph->yaxis->title->SetFont($fontfamilies[$ytitlefont],$fontstyles[$ytitlefontstyle], $ytitlefontsize);
     $graph->yaxis->title->SetColor($ytitlecolor);
     $graph->xaxis->SetLabelAngle(90);
     $graph->xaxis->SetLabelMargin(15); 
     $graph->yaxis->SetLabelMargin(15); 
     $graph->xaxis->SetTickLabels($xlabels);
     $graph->xaxis->SetTextLabelInterval($xticklabint);
     $graph->yaxis->SetTextLabelInterval($yticklabint);
     $graph->xaxis->SetTextTickInterval($xtickinterval);
     $graph->yaxis->SetTextTickInterval($ytickinterval);
     */
     /*
     if ( $gridpos == "front" )
     	$graph->SetGridDepth(DEPTH_FRONT); 
     */
     // Display the graph
     /*?$graph->Stroke();*/
     $this->apply_defaults_internal();
     //echo "oo<BR>";
     //echo "<PRE>";
     //var_dump($graphData);
     //echo $this->width."<BR>";
     //echo $this->height_actual."<BR>";
     $graphImage = new pImage($this->width_actual, $this->height_actual, $graphData);
     /* Turn of Antialiasing */
     $graphImage->Antialias = TRUE;
     // Add gradient fill from chosen background color to white
     $startgradient = $this->htmltorgb("#ffffff");
     $color = $this->htmltorgb($this->graphcolor);
     $graphImage->drawGradientArea(0, 0, $this->width_actual, $this->height_actual, DIRECTION_VERTICAL, array("StartR" => $startgradient[0], "StartG" => $startgradient[1], "StartB" => $startgradient[2], "EndR" => $color[0], "EndG" => $color[1], "EndB" => $color[2], "Alpha" => 100));
     /* Add a border to the picture */
     $graphImage->drawRectangle(0, 0, $this->width_actual - 1, $this->height_actual - 1, array("R" => 200, "G" => 200, "B" => 200));
     /* Set the title font and draw it */
     $graphImage->setFontProperties(array("FontName" => PCHARTFONTS_DIR . $this->titlefont, "FontSize" => $this->titlefontsize));
     $this->titlecolor = $this->htmltorgb($this->titlecolor);
     $graphImage->drawText(20, 30, $this->title_actual, array("R" => $this->titlecolor[0], "G" => $this->titlecolor[1], "B" => $this->titlecolor[2]));
     /* Set the default font from the X title font */
     $graphImage->setFontProperties(array("FontName" => PCHARTFONTS_DIR . $this->xtitlefont, "FontSize" => $this->xtitlefontsize));
     /* Define the chart area */
     $graphImage->setGraphArea($this->marginleft, $this->margintop, $this->width_actual - $this->marginright, $this->height_actual - $this->marginbottom);
     //$scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE,"LabelRotation"=>30);
     //$graphImage->drawScale($scaleSettings);
     //$settings = array("Surrounding"=>-30,"InnerSurrounding"=>30);
     //$graphImage->drawBarChart($settings);
     //$graphImage->autoOutput("pictures/example.drawBarChart.simple.png");
     //return;
     // Before plotting a series ensure they are all not drawable.
     /// Plot the chart data
     $stackeddrawn = false;
     $stackedexists = false;
     $barexists = false;
     foreach ($this->plot as $k => $v) {
         if ($v["type"] == "STACKEDBAR") {
             $stackedexists = true;
         }
         if ($v["type"] == "STACKEDBAR" || $v["type"] == "BAR") {
             $barexists = true;
         }
     }
     /* Draw the scale */
     $scaleSettings = array("GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => TRUE, "CycleBackground" => TRUE, "LabelRotation" => 30);
     // For stacked charts fix up the Max and Min values;
     if ($stackedexists) {
         $scaleMin = "Unknown";
         $scaleMax = 0;
         foreach ($this->plot as $k => $v) {
             if ($v["type"] == "BAR" || $v["type"] == "STACKEDBAR") {
                 $series = $v["name"] . $k;
                 $min = $graphData->getMin($series);
                 if ($scaleMin == "Unknown" || $min < $scaleMin) {
                     $scaleMin = $min;
                 }
                 $scaleMax = $scaleMax + $graphData->getMax($series);
             }
         }
         if ($scaleMin > 0) {
             $scaleMin = 0;
         }
         $range = $scaleMax - $scaleMin;
         // Make scales based on 5% of the range of values
         $scaleMax = round($range * 0.05 + $scaleMax);
         if ($scaleMin < 0) {
             $scaleMin = $scaleMin - round($range * 0.05);
         }
         $AxisBoundaries = array(0 => array("Min" => $scaleMin, "Max" => $scaleMax));
         $scaleSettings["Mode"] = SCALE_MODE_MANUAL;
         $scaleSettings["ManualScale"] = $AxisBoundaries;
     } else {
         if ($barexists) {
             $scaleMin = "Unknown";
             $scaleMax = 0;
             foreach ($this->plot as $k => $v) {
                 if ($v["type"] == "BAR" || $v["type"] == "STACKEDBAR") {
                     $series = $v["name"] . $k;
                     $min = $graphData->getMin($series);
                     if ($scaleMin == "Unknown" || $min < $scaleMin) {
                         $scaleMin = $min;
                     }
                     $max = $graphData->getMax($series);
                     if ($scaleMax == "Unknown" || $max > $scaleMax) {
                         $scaleMax = $max;
                     }
                 }
             }
             if ($scaleMin > 0) {
                 $scaleMin = 0;
             }
             $range = $scaleMax - $scaleMin;
             // Make scales based on 5% of the range of values
             $scaleMax = round($range * 0.05 + $scaleMax);
             if ($scaleMin < 0) {
                 $scaleMin = $scaleMin - round($range * 0.05);
             }
             $AxisBoundaries = array(0 => array("Min" => $scaleMin, "Max" => $scaleMax));
             $scaleSettings["Mode"] = SCALE_MODE_MANUAL;
             $scaleSettings["ManualScale"] = $AxisBoundaries;
         }
     }
     $graphImage->drawScale($scaleSettings);
     // If there's a Pie chart we want to draw different legends
     $piechart = false;
     foreach ($this->plot as $k => $v) {
         foreach ($this->plot as $k1 => $v1) {
             $series = $v1["name"] . $k1;
             $graphData->setSerieDrawable($series, FALSE);
         }
         $series = $v["name"] . $k;
         $graphData->setSerieDrawable($series, TRUE);
         switch ($v["type"]) {
             case "PIE":
                 $piechart = true;
                 $pie = new pPie($graphImage, $graphData);
                 //$pie->draw2DPie($width_actual / 2,$height_actual / 2,80,array("DrawLabels"=>TRUE,"LabelStacked"=>TRUE,"Border"=>TRUE));
                 $pie->draw2DPie($width_actual / 2, $height_actual / 2, 80, array("WriteValues" => PIE_VALUE_PERCENTAGE, "DataGapAngle" => 10, "DataGapRadius" => 6, "Border" => TRUE, "BorderR" => 255, "BorderG" => 255, "BorderB" => 255));
                 break;
             case "PIE3D":
                 $piechart = true;
                 $pie = new pPie($graphImage, $graphData);
                 $pie->draw3DPie($this->width_actual / 2, $this->height_actual / 2, 80, array("SecondPass" => FALSE));
                 break;
             case "STACKEDBAR":
             case "BAR":
                 if ($stackeddrawn) {
                     break;
                 }
                 if ($barexists) {
                     foreach ($this->plot as $k1 => $v1) {
                         if ($v1["type"] == "BAR" || $v1["type"] == "STACKEDBAR") {
                             $graphData->setSerieDrawable($v1["name"] . $k1, TRUE);
                         }
                     }
                 }
                 $stackeddrawn = true;
                 $settings = array("Surrounding" => -30, "InnerSurrounding" => 30);
                 if ($stackedexists) {
                     $graphImage->drawStackedBarChart($settings);
                 } else {
                     $graphImage->drawBarChart($settings);
                 }
                 break;
             case "LINE":
             default:
                 if (count($v["data"]) == 1) {
                     $v["data"][] = 0;
                 }
                 $graphImage->drawLineChart($settings);
                 break;
         }
     }
     $graphData->drawAll();
     if ($piechart) {
         $pie->drawPieLegend($this->width_actual - 100, 30, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_VERTICAL));
     } else {
         $graphImage->drawLegend($this->width_actual - 180, 22, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_VERTICAL));
     }
     $graphImage->setShadow(TRUE, array("X" => 0, "Y" => 0, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10));
     $graphImage->render($outputfile);
     return true;
 }
 function GetGraphImageTag($_data, $_texts, $_metric = true)
 {
     if (!StatisticProvider::$DrawChartImages || !function_exists("gd_info")) {
         return "";
     }
     require_once LIVEZILLA_PATH . "_lib/trdp/pchart/class/pData.class.php";
     require_once LIVEZILLA_PATH . "_lib/trdp/pchart/class/pDraw.class.php";
     require_once LIVEZILLA_PATH . "_lib/trdp/pchart/class/pImage.class.php";
     $MyData = new pData();
     $dobject = array();
     foreach ($_data as $obid => $values) {
         foreach ($values as $key => $val) {
             $values[$key] = round($val, 1);
         }
         $dv1[] = $values[0];
         if (count($values) > 1) {
             $dv2[] = $values[1];
         }
         if (count($values) > 2) {
             $dv3[] = $values[2];
         }
         if (count($values) > 3) {
             $dv4[] = $values[3];
         }
         $dobject[] = $obid;
         if (count($dobject) == 5) {
             break;
         }
     }
     $MyData->addPoints($dv1, $_texts[1] . "   ");
     if (isset($dv2)) {
         $MyData->addPoints($dv2, $_texts[2] . "   ");
     }
     if (isset($dv3)) {
         $MyData->addPoints($dv3, $_texts[3] . "   ");
     }
     if (isset($dv4)) {
         $MyData->addPoints($dv4, $_texts[4] . "   ");
     }
     $MyData->setAxisName(0, $_texts[0]);
     $MyData->setAxisDisplay(0, $_metric ? AXIS_FORMAT_METRIC : AXIS_FORMAT_RAW);
     $MyData->addPoints($dobject, "Groups");
     $MyData->setSerieDescription("Groups", "Group");
     $MyData->setAbscissa("Groups");
     $myPicture = new pImage(630, 210, $MyData);
     $myPicture->Antialias = FALSE;
     $myPicture->setFontProperties(array("FontName" => LIVEZILLA_PATH . "_lib/trdp/pchart/fonts/arimo.ttf", "FontSize" => 8, "R" => 120, "G" => 120, "B" => 120));
     $myPicture->setGraphArea(46, 0, 620, 160);
     $scaleSettings = array("GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => TRUE, "YMargin" => 12, "CycleBackground" => TRUE);
     $myPicture->drawScale($scaleSettings);
     $myPicture->drawLegend(40, 190, array("Style" => LEGEND_BOX, "Mode" => LEGEND_HORIZONTAL, "BoxSize" => 4, "R" => 200, "G" => 200, "B" => 200, "Surrounding" => 20, "Alpha" => 30));
     $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10));
     $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10));
     $settings = array("Surrounding" => -30, "InnerSurrounding" => 30, "DisplayValues" => TRUE);
     $myPicture->drawBarChart($settings);
     $file = PATH_STATS . $this->Type . "/temp.png";
     $myPicture->render($file);
     return "<img src=\"data:image/png;base64," . IOStruct::ToBase64($file) . "\" />";
 }
 protected function drawBarChart(ChartDataset $CDs)
 {
     if (!extension_loaded("gd") && !extension_loaded("gd2")) {
         /* Extension not loaded */
         // NO BARCHARTS AND ERRORS FOR YOU!
         return;
     }
     /* Create and populate the pData object */
     $MyData = new pData();
     if (empty($CDs->data)) {
         return;
     }
     //print_r($CDs->data);
     foreach ($CDs->data as $points) {
         //print_r($points);
         $MyData->addPoints($points["points"], $points["label"]);
     }
     $MyData->setAxisName(0, "Amount Sold");
     $MyData->setSerieDescription($points["label"], $points["label"]);
     $MyData->setAbscissa($points["label"]);
     /* Create the pChart object */
     $myPicture = new pImage(1000, 230, $MyData);
     // the horrible way to add fonts is just one bunch of f****d up shit, not making sense. bullshit parameters and paths.
     //$myPicture->setFontProperties(array("FontName"=>"Bedizen"));
     $myPicture->setFontProperties(array("FontName" => "pChart2.1.4//fonts/calibri.ttf", "FontSize" => 11));
     //print_r(is_file("C:/xampp_jan2015/htdocs/hackerbar/web/fonts/GeosansLight.ttf"));
     /* Turn of Antialiasing */
     $myPicture->Antialias = false;
     /* Add a border to the picture */
     $myPicture->drawGradientArea(0, 0, 1000, 230, DIRECTION_VERTICAL, array("StartR" => 240, "StartG" => 240, "StartB" => 240, "EndR" => 180, "EndG" => 180, "EndB" => 180, "Alpha" => 100));
     $myPicture->drawGradientArea(0, 0, 1000, 230, DIRECTION_HORIZONTAL, array("StartR" => 240, "StartG" => 240, "StartB" => 240, "EndR" => 180, "EndG" => 180, "EndB" => 180, "Alpha" => 20));
     $myPicture->drawRectangle(0, 0, 999, 229, array("R" => 0, "G" => 0, "B" => 0));
     /* Set the default font */
     //$myPicture->setFontProperties(array("FontName"=>"../fonts/pf_arma_five.ttf","FontSize"=>6));
     /* Define the chart area */
     $myPicture->setGraphArea(60, 40, 850, 200);
     /* Draw the scale */
     $scaleSettings = array("GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => TRUE, "CycleBackground" => TRUE);
     $myPicture->drawScale($scaleSettings);
     /* Write the chart legend */
     $myPicture->drawLegend(860, 25, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_VERTICAL));
     /* Turn on shadow computing */
     $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10));
     /* Draw the chart */
     $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10));
     $settings = array("Surrounding" => -30, "InnerSurrounding" => 30);
     $myPicture->drawBarChart($settings);
     /* Render the picture (choose the best way) */
     $myPicture->autoOutput("images/barcharts/" . $points["label"] . ".png");
     //$myPicture->auto
     $myPicture->render("myfile.png");
 }
Example #27
0
 function launch()
 {
     global $configArray;
     global $interface;
     global $user;
     //////////Populate the Date Filter Start
     $today = getdate();
     //Grab the Selected Date Start
     if (isset($_REQUEST['dateFilterStart'])) {
         if (preg_match('/\\d{1,2}\\/\\d{1,2}\\/\\d{4}/', $_REQUEST['dateFilterStart'])) {
             $selectedDateStart = DateTime::createFromFormat('m/d/Y', $_REQUEST['dateFilterStart']);
             $selectedDateStart = $selectedDateStart->getTimestamp();
         } else {
             $selectedDateStart = strtotime($_REQUEST['dateFilterStart']);
         }
     } else {
         $selectedDateStart = strtotime('-30 days');
     }
     $selectedDateStart = date('Y-m-d', $selectedDateStart);
     $interface->assign('selectedDateStart', $selectedDateStart);
     //Populate the Date Filter End
     //Grab the Selected End Date
     if (isset($_REQUEST['dateFilterEnd'])) {
         if (preg_match('/\\d{1,2}\\/\\d{1,2}\\/\\d{4}/', $_REQUEST['dateFilterEnd'])) {
             $selectedDateEnd = DateTime::createFromFormat('m/d/Y', $_REQUEST['dateFilterEnd']);
             $selectedDateEnd = $selectedDateEnd->getTimestamp();
         } else {
             $selectedDateEnd = strtotime($_REQUEST['dateFilterEnd']);
         }
     } else {
         $selectedDateEnd = strtotime('today');
     }
     $selectedDateEnd = date('Y-m-d', $selectedDateEnd);
     $interface->assign('selectedDateEnd', $selectedDateEnd);
     //////////Populate the Stores Filter
     $queryStoresFilter = "SELECT DISTINCT store AS Store FROM purchase_link_tracking ORDER BY Store ASC";
     $resStoresFilter = mysql_query($queryStoresFilter);
     $allStores = array();
     $i = 0;
     while ($r = mysql_fetch_array($resStoresFilter)) {
         $allStores[] = $r['Store'];
     }
     $interface->assign('resultsStoresFilter', $allStores);
     //////////Grab the Selected Stores Filter Value
     $selectedStoresFilter = array();
     if (isset($_REQUEST['storesFilter'])) {
         $selectedStoresFilter = $_REQUEST['storesFilter'];
     } else {
         //Pre-Populate the Stores Filter MultiSelect list
         $queryStoresPreSelect = "SELECT DISTINCT store AS Store FROM purchase_link_tracking\n\t\t\t\tORDER BY Store ASC";
         $resStoresPreSelect = mysql_query($queryStoresPreSelect);
         $i = 0;
         while ($r = mysql_fetch_array($resStoresPreSelect)) {
             $selectedStoresFilter[$i++] = $r['Store'];
         }
     }
     $interface->assign('selectedStoresFilter', $selectedStoresFilter);
     $baseQueryPurchases = "SELECT COUNT(purchaseLinkId) AS Purchases, store AS Store " . "FROM purchase_link_tracking " . "WHERE (DATE_FORMAT(trackingDate, '%Y-%m-%d')) BETWEEN '" . $selectedDateStart . "' AND '" . $selectedDateEnd . "' ";
     if (count($selectedStoresFilter) > 0) {
         $stores = join("','", $selectedStoresFilter);
         $baseQueryPurchases .= "AND store IN ('" . $stores . "') ";
     }
     $baseQueryPurchases .= "GROUP BY store ";
     //////////Get a count of the page view data
     $queryPurchasesCount = "SELECT COUNT(*) AS RowCount from ( " . $baseQueryPurchases . ") As ResultCount";
     $resPurchasesCount = mysql_query($queryPurchasesCount);
     $rowCount = mysql_fetch_object($resPurchasesCount);
     $totalResultCount = $rowCount->RowCount;
     //////////Create the items per page array
     $itemsPerPageList = array();
     $itemsPerPageList = $this->getItemsPerPageList();
     ///////////////////PAGING
     $currentPage = 1;
     $resultTotal = $totalResultCount;
     $startRecord = 1;
     if (isset($_GET['itemsPerPage'])) {
         switch ($_GET['itemsPerPage']) {
             case "20":
                 $itemsPerPage = 20;
                 $itemsPerPageList["20"]["selected"] = true;
                 break;
             case "100":
                 $itemsPerPage = 100;
                 $itemsPerPageList["100"]["selected"] = true;
                 break;
             default:
                 $itemsPerPage = 50;
                 $itemsPerPageList["50"]["selected"] = true;
         }
     } else {
         $itemsPerPage = 50;
         $itemsPerPageList["50"]["selected"] = true;
     }
     $endRecord = $itemsPerPage;
     $interface->assign('itemsPerPageList', $itemsPerPageList);
     if (isset($_GET['page'])) {
         $currentPage = $_GET['page'];
         // 1st record is easy, work out the start of this page
         $startRecord = ($currentPage - 1) * $itemsPerPage + 1;
         // Last record needs more care
         if ($resultTotal < $itemsPerPage) {
             // There are less records returned then one page, use total results
             $endRecord = $resultTotal;
         } else {
             if ($currentPage * $itemsPerPage > $resultTotal) {
                 // The end of the curent page runs past the last record, use total results
                 $endRecord = $resultTotal;
             } else {
                 // Otherwise use the last record on this page
                 $endRecord = $currentPage * $itemsPerPage;
             }
         }
     }
     //////////Get the Page View Data with paging and sorting
     if (isset($_GET['reportSort'])) {
         $sortValue = $_GET['reportSort'];
     }
     //////////Create a sort array
     $sortList = $this->getSortList();
     if (isset($sortValue)) {
         switch ($sortValue) {
             case "PurchasesDESC":
                 $baseQueryPurchases .= "ORDER BY purchases DESC ";
                 $sortList["PurchasesDESC"]["selected"] = true;
                 break;
             case "PurchasesASC":
                 $baseQueryPurchases .= "ORDER BY purchases ASC ";
                 $sortList["PurchasesASC"]["selected"] = true;
                 break;
             case "StoreASC":
                 $baseQueryPurchases .= "ORDER BY store ASC ";
                 $sortList["StoreASC"]["selected"] = true;
                 break;
             case "StoreDESC":
                 $baseQueryPurchases .= "ORDER BY store DESC ";
                 $sortList["StoreDESC"]["selected"] = true;
                 break;
             default:
                 $baseQueryPurchases .= "ORDER BY store ASC  ";
                 $sortList["StoreASC"]["selected"] = true;
         }
     } else {
         $baseQueryPurchases .= "ORDER BY store ASC ";
     }
     //append on a limit to return a result
     if (!isset($_REQUEST['exportToExcel'])) {
         $baseQueryPurchases .= "LIMIT " . ($startRecord - 1) . ", " . $itemsPerPage . " ";
     }
     $resPurchases = mysql_query($baseQueryPurchases);
     //Build an array based on the data to dump out to the grid
     $resultsPurchases = array();
     $i = 0;
     while ($r = mysql_fetch_array($resPurchases)) {
         $tmp = array('Purchases' => $r['Purchases'], 'Store' => $r['Store']);
         $resultsPurchases[$i++] = $tmp;
     }
     $interface->assign('resultsPurchases', $resultsPurchases);
     //////////Paging Array
     $summary = array('page' => $currentPage, 'perPage' => $itemsPerPage, 'resultTotal' => $totalResultCount, 'startRecord' => $startRecord, 'endRecord' => $endRecord);
     $interface->assign('recordCount', $summary['resultTotal']);
     $interface->assign('recordStart', $summary['startRecord']);
     $interface->assign('recordEnd', $summary['endRecord']);
     // Process Paging using VuFind Pager object
     if (strrpos($_SERVER["REQUEST_URI"], "page=")) {
         //replace the page variable with a new one
         $link = str_replace("page=" . $currentPage, "page=%d", $_SERVER["REQUEST_URI"]);
     } else {
         if (strrpos($_SERVER["REQUEST_URI"], "?")) {
             $link = $_SERVER["REQUEST_URI"] . "&page=%d";
         } else {
             $link = $_SERVER["REQUEST_URI"] . "?page=%d";
         }
     }
     $options = array('totalItems' => $summary['resultTotal'], 'fileName' => $link, 'perPage' => $summary['perPage']);
     $pager = new VuFindPager($options);
     $interface->assign('pageLinks', $pager->getLinks());
     ///////////////////END PAGING
     //////////Sorting
     $sortUrl = $_SERVER["REQUEST_URI"];
     if (isset($sortValue)) {
         //Set the URL for sorting
         if (strrpos($_SERVER["REQUEST_URI"], "reportSort=")) {
             //replace the page variable with a new one
             $sortUrl = str_replace("sort=" . $currentPage, "reportSort=" . $sortValue, $_SERVER["REQUEST_URI"]);
         } else {
             if (strrpos($_SERVER["REQUEST_URI"], "?")) {
                 $sortUrl = $_SERVER["REQUEST_URI"] . "&reportSort=" . $sortValue;
             } else {
                 $sortUrl = $_SERVER["REQUEST_URI"] . "?reportSort=" . $sortValue;
             }
         }
     }
     $interface->assign('sortUrl', $sortUrl);
     $interface->assign('sortList', $sortList);
     //////////CHART
     //Create the chart and load data into the results.
     $queryDailyPurchases = "SELECT DATE_FORMAT(trackingDate, '%Y-%m-%d') as date, COUNT(recordId) AS Purchases, store AS Store FROM purchase_link_tracking  " . "WHERE (DATE_FORMAT(trackingDate, '%Y-%m-%d')) BETWEEN '" . $selectedDateStart . "' AND '" . $selectedDateEnd . "' ";
     if (count($selectedStoresFilter) > 0) {
         $stores = join("','", $selectedStoresFilter);
         $queryDailyPurchases .= "AND store IN ('" . $stores . "') ";
     }
     $queryDailyPurchases .= "GROUP BY DATE_FORMAT(trackingDate, '%Y-%m-%d'), store ORDER BY trackingDate ASC";
     $dailyPurchases = mysql_query($queryDailyPurchases);
     //Initialize data by loading all of the dates that we are looking at so we can show the correct counts or each series on the right day.
     $check_date = $selectedDateStart;
     $datesInReport = array();
     $purchasesByStoreByDay = array();
     foreach ($allStores as $storeName) {
         $purchasesByStoreByDay[$storeName] = array();
     }
     $numDatesChecked = 0;
     //Prevent infinite loops
     while ($check_date != $selectedDateEnd && $numDatesChecked < 3000) {
         $check_date = date("Y-m-d", strtotime("+1 day", strtotime($check_date)));
         $datesInReport[] = $check_date;
         //Default number of purchases for the day to 0
         foreach ($allStores as $storeName) {
             $purchasesByStoreByDay[$storeName][$check_date] = 0;
         }
         $numDatesChecked++;
     }
     //Chart section
     $reportData = new pData();
     while ($r = mysql_fetch_array($dailyPurchases)) {
         $store = $r['Store'];
         $purchasesByStoreByDay[$store][$r['date']] = $r['Purchases'];
     }
     foreach ($purchasesByStoreByDay as $storeName => $dailyResults) {
         $reportData->addPoints($dailyResults, $storeName);
     }
     $reportData->setAxisName(0, "Purchases");
     $reportData->addPoints($datesInReport, "Dates");
     $reportData->setAbscissa("Dates");
     /* Create the pChart object */
     $myPicture = new pImage(700, 290, $reportData);
     /* Draw the background */
     $Settings = array("R" => 225, "G" => 225, "B" => 225);
     $myPicture->drawFilledRectangle(0, 0, 700, 290, $Settings);
     /* Add a border to the picture */
     $myPicture->drawRectangle(0, 0, 699, 289, array("R" => 0, "G" => 0, "B" => 0));
     $myPicture->setFontProperties(array("FontName" => "sys/pChart/Fonts/verdana.ttf", "FontSize" => 9));
     $myPicture->setGraphArea(50, 30, 670, 190);
     //$myPicture->drawFilledRectangle(30,30,670,150,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10));
     $myPicture->drawScale(array("DrawSubTicks" => TRUE, "LabelRotation" => 90));
     $myPicture->setFontProperties(array("FontName" => "sys/pChart/Fonts/verdana.ttf", "FontSize" => 9));
     $myPicture->drawLineChart(array("DisplayValues" => TRUE, "DisplayColor" => DISPLAY_AUTO));
     /* Write the chart legend */
     $myPicture->drawLegend(80, 20, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL));
     /* Render the picture (choose the best way) */
     $time = time();
     $chartHref = "/images/charts/dailyPurchases{$time}.png";
     $chartPath = $configArray['Site']['local'] . $chartHref;
     $myPicture->render($chartPath);
     $interface->assign('chartPath', $chartHref);
     //EXPORT To EXCEL
     if (isset($_REQUEST['exportToExcel'])) {
         //PHPEXCEL
         // Create new PHPExcel object
         $objPHPExcel = new PHPExcel();
         // Set properties
         $objPHPExcel->getProperties()->setCreator("DCL")->setLastModifiedBy("DCL")->setTitle("Office 2007 XLSX Document")->setSubject("Office 2007 XLSX Document")->setDescription("Office 2007 XLSX, generated using PHP.")->setKeywords("office 2007 openxml php")->setCategory("Purchases Report");
         // Add some data
         $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'Purchases Report')->setCellValue('A3', 'STORE')->setCellValue('B3', 'PURCHASES');
         $a = 4;
         //Loop Through The Report Data
         foreach ($resultsPurchases as $resultsPurchases) {
             $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A' . $a, $resultsPurchases['Store'])->setCellValue('B' . $a, $resultsPurchases['Purchases']);
             $a++;
         }
         $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
         $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
         // Rename sheet
         $objPHPExcel->getActiveSheet()->setTitle('Purchases');
         // Set active sheet index to the first sheet, so Excel opens this as the first sheet
         $objPHPExcel->setActiveSheetIndex(0);
         // Redirect output to a client's web browser (Excel5)
         header('Content-Type: application/vnd.ms-excel');
         header('Content-Disposition: attachment;filename="PurchaseLinkReport.xls"');
         header('Cache-Control: max-age=0');
         $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
         $objWriter->save('php://output');
         exit;
     }
     $interface->setPageTitle('Report - Purchase Tracking');
     $interface->setTemplate('reportPurchase.tpl');
     $interface->display('layout.tpl');
 }
function pieGen($stats, $mode)
{
    global $centreon_path;
    // Create and populate the pData object
    $MyData = new pData();
    // print_r($stats["average"]);
    $arrPoints = array();
    $i = 0;
    // Host groups
    if ($mode == "hgs") {
        $MyData->addPoints(array($stats["average"]["UP_TP"], $stats["average"]["DOWN_TP"], $stats["average"]["UNDETERMINED_TP"], $stats["average"]["UNREACHABLE_TP"], $stats["average"]["MAINTENANCE_TP"]), "Hostgroups");
        $MyData->setSerieDescription("Hostgroups", "Hostgroups");
        $arrPoints = array("Up", "Down", "Undeterminded", "Unreachable", "Schedule Downtime");
        // Define the absissa serie
        $MyData->addPoints($arrPoints, "Labels");
        $MyData->setAbscissa("Labels");
        // Create the pChart object
        $myPicture = new pImage(120, 120, $MyData, TRUE);
        // Create the pPie object
        $PieChart = new pPie($myPicture, $MyData);
        $i = 0;
        /* Define the slice color */
        if ($stats["average"]["UP_TP"] > 0) {
            $PieChart->setSliceColor($i, array("R" => 25, "G" => 238, "B" => 17));
            // UP
            $i++;
        }
        if ($stats["average"]["DOWN_TP"] > 0) {
            $PieChart->setSliceColor($i, array("R" => 249, "G" => 30, "B" => 5));
            // DOWN
            $i++;
        }
        if ($stats["average"]["UNDETERMINED_TP"] > 0) {
            $PieChart->setSliceColor($i, array("R" => 204, "G" => 248, "B" => 255));
            // UNDETERMINED
            //$PieChart->setSliceColor($i,array("R"=>240,"G"=>240,"B"=>240));
            $i++;
        }
        if ($stats["average"]["UNREACHABLE_TP"] > 0) {
            $PieChart->setSliceColor($i, array("R" => 130, "G" => 207, "B" => 216));
            // UNREACHABLE
            $i++;
        }
        if ($stats["average"]["MAINTENANCE_TP"] > 0) {
            $PieChart->setSliceColor($i, array("R" => 204, "G" => 153, "B" => 255));
            // MAINTENANCE
            $i++;
        }
    }
    // Service Groups
    if ($mode == "sgs") {
        $MyData->addPoints(array($stats["average"]["OK_TP"], $stats["average"]["WARNING_TP"], $stats["average"]["CRITICAL_TP"], $stats["average"]["UNKNOWN_TP"], $stats["average"]["MAINTENANCE_TP"], $stats["average"]["UNDETERMINED_TP"]), "Servicegroups");
        $MyData->setSerieDescription("Servicegroups", "Servicegroups");
        $arrPoints = array("Ok", "Warning", "Critical", "Unknown", "Schedule Downtime", "Undeterminded");
        // Define the absissa serie
        $MyData->addPoints($arrPoints, "Labels");
        $MyData->setAbscissa("Labels");
        // Create the pChart object
        $myPicture = new pImage(120, 120, $MyData, TRUE);
        // Create the pPie object
        $PieChart = new pPie($myPicture, $MyData);
        /* Define the slice color */
        if ($stats["average"]["OK_TP"] > 0) {
            $PieChart->setSliceColor($i, array("R" => 13, "G" => 235, "B" => 58));
            // OK
            $i++;
        }
        if ($stats["average"]["WARNING_TP"] > 0) {
            $PieChart->setSliceColor($i, array("R" => 248, "G" => 199, "B" => 6));
            // DOWN
            $i++;
        }
        if ($stats["average"]["CRITICAL_TP"] > 0) {
            $PieChart->setSliceColor($i, array("R" => 249, "G" => 30, "B" => 5));
            // DOWN
            $i++;
        }
        if ($stats["average"]["UNKNOWN_TP"] > 0) {
            $PieChart->setSliceColor($i, array("R" => 220, "G" => 218, "B" => 218));
            // UNKNOWN
            $i++;
        }
        if ($stats["average"]["MAINTENANCE_TP"] > 0) {
            $PieChart->setSliceColor($i, array("R" => 204, "G" => 153, "B" => 255));
            // MAINTENANCE
            $i++;
        }
        if ($stats["average"]["UNDETERMINED_TP"] > 0) {
            $PieChart->setSliceColor($i, array("R" => 204, "G" => 248, "B" => 255));
            // UNDETERMINED
            //$PieChart->setSliceColor($i,array("R"=>240,"G"=>240,"B"=>240)); // UNDETERMINED
            $i++;
        }
    }
    $Settings = array("R" => 255, "G" => 255, "B" => 255);
    $myPicture->drawFilledRectangle(0, 0, 120, 120, $Settings);
    //  Enable shadow computing
    // $myPicture->setShadow(TRUE,array("X"=>3,"Y"=>3,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
    // Draw a splitted pie chart
    $PieChart->draw3DPie(60, 70, array("Radius" => 50, "DataGapAngle" => 8, "DataGapRadius" => 6, "Border" => TRUE, "BorderR" => 0, "BorderG" => 0, "BorderB" => 0));
    /* Render the picture  */
    //	$pie_file = tempnam( "/tmp" , "reportreon_pie_" );
    $pie_file = tempnam($centreon_path . "/www/modules/pdfreports/generatedFiles/tmp", "reportreon_pie_");
    $myPicture->render($pie_file . ".png");
    @unlink($pie_file);
    return $pie_file . ".png";
}
Example #29
0
 $max = max($average) + 5;
 if ($max <= 0) {
     $max = 1;
 }
 if ($max > 64) {
     $max = 64;
 }
 $min = min($average) - 5;
 if ($min < 0) {
     $min = 0;
 }
 $Settings = array("Pos" => SCALE_POS_LEFTRIGHT, "Mode" => SCALE_MODE_MANUAL, "ManualScale" => array(0 => array("Min" => $min, "Max" => $max)), "LabelingMethod" => LABELING_ALL, "GridR" => 200, "GridG" => 200, "GridB" => 200, "GridAlpha" => 75, "TickR" => 240, "TickG" => 240, "TickB" => 240, "TickAlpha" => 75, "LabelRotation" => 0, "LabelSkip" => 1, "DrawXLines" => 0, "DrawSubTicks" => 1, "DrawYLines" => ALL, "SubTickR" => 210, "SubTickG" => 210, "SubTickB" => 210, "SubTickAlpha" => 75, "AxisR" => 210, "AxisG" => 210, "AxisB" => 210, "AxisAlpha" => 75);
 $myPicture->drawScale($Settings);
 $Config = "";
 $myPicture->drawSplineChart();
 $myPicture->render("./cache/graph_sid{$sid}.png");
 // graph is done
 // query for server info
 $Basic_q = @mysqli_query($BF4stats, "\n\t\t\tSELECT `mapName`, `Gamemode`, `maxSlots`, `usedSlots`, `ServerName`, `IP_Address`\n\t\t\tFROM `tbl_server`\n\t\t\tWHERE `ServerID` = {$sid}\n\t\t\tAND `GameID` = {$GameID}\n\t\t");
 // information was found
 if (@mysqli_num_rows($Basic_q) != 0) {
     $Basic_r = @mysqli_fetch_assoc($Basic_q);
     $used_slots = $Basic_r['usedSlots'];
     $available_slots = $Basic_r['maxSlots'];
     $ip = $Basic_r['IP_Address'];
     $servername = $Basic_r['ServerName'];
     if (strlen($servername) > 34) {
         $servername = substr($servername, 0, 33);
         $servername .= '..';
     }
     $mode = $Basic_r['Gamemode'];