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>";
     }
 }
 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;
 }
Ejemplo n.º 3
0
 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>";
     }
 }
/* Create the pChart object */
$myPicture = new pImage(700, 230, $MyData);
/* Draw the background */
$Settings = array("R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107);
$myPicture->drawFilledRectangle(0, 0, 700, 230, $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, 700, 230, DIRECTION_VERTICAL, $Settings);
$myPicture->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, array("StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 80));
/* Add a border to the picture */
$myPicture->drawRectangle(0, 0, 699, 229, array("R" => 0, "G" => 0, "B" => 0));
/* Write the picture title */
$myPicture->setFontProperties(array("FontName" => "../fonts/Silkscreen.ttf", "FontSize" => 6));
$myPicture->drawText(10, 13, "drawIndicator() - Create nice looking indicators", array("R" => 255, "G" => 255, "B" => 255));
/* Create the pIndicator object */
$Indicator = new pIndicator($myPicture);
$myPicture->setFontProperties(array("FontName" => "../fonts/pf_arma_five.ttf", "FontSize" => 6));
/* Define the indicator sections */
$IndicatorSections = "";
$IndicatorSections[] = array("Start" => 0, "End" => 199, "Caption" => "Low", "R" => 0, "G" => 142, "B" => 176);
$IndicatorSections[] = array("Start" => 200, "End" => 239, "Caption" => "Moderate", "R" => 108, "G" => 157, "B" => 49);
$IndicatorSections[] = array("Start" => 240, "End" => 300, "Caption" => "High", "R" => 157, "G" => 140, "B" => 49);
/* Draw the 1st indicator */
$IndicatorSettings = array("Values" => array(20, 230), "ValueFontName" => "../fonts/Forgotte.ttf", "ValueFontSize" => 15, "IndicatorSections" => $IndicatorSections, "SubCaptionColorFactor" => -40);
$Indicator->draw(80, 50, 550, 50, $IndicatorSettings);
/* Define the indicator sections */
$IndicatorSections = "";
$IndicatorSections[] = array("Start" => 0, "End" => 99, "Caption" => "Low", "R" => 135, "G" => 49, "B" => 15);
$IndicatorSections[] = array("Start" => 100, "End" => 119, "Caption" => "Borderline", "R" => 183, "G" => 62, "B" => 15);
$IndicatorSections[] = array("Start" => 120, "End" => 220, "Caption" => "High", "R" => 226, "G" => 74, "B" => 14);
/* Draw the 2nd indicator */
/* Turn on Antialiasing */
$myPicture->Antialias = TRUE;
/* Draw the line of best fit */
$myPicture->drawBestFit(array("Ticks" => 4, "Alpha" => 50, "R" => 0, "G" => 0, "B" => 0));
/* Draw the line chart */
$myPicture->drawLineChart();
/* Draw the series derivative graph */
$myPicture->drawDerivative(array("ShadedSlopeBox" => TRUE, "CaptionLine" => TRUE));
/* Write the chart legend */
$myPicture->drawLegend(570, 20, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL));
/* Set the default font & shadow settings */
$myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10));
$myPicture->setFontProperties(array("FontName" => "../fonts/Forgotte.ttf", "FontSize" => 11));
/* Write the chart title */
$myPicture->setFontProperties(array("FontName" => "../fonts/Forgotte.ttf", "FontSize" => 11));
$myPicture->drawText(150, 35, "Probability of heart disease", array("FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMMIDDLE, "R" => 255, "G" => 255, "B" => 255));
/* Write a label over the chart */
$LabelSettings = array("DrawVerticalLine" => TRUE, "TitleMode" => LABEL_TITLE_BACKGROUND, "TitleR" => 255, "TitleG" => 255, "TitleB" => 255);
$myPicture->writeLabel("Statistical probability", 35, $LabelSettings);
/* Create the pIndicator object */
$Indicator = new pIndicator($myPicture);
/* Define the indicator sections */
$IndicatorSections = "";
$IndicatorSections[] = array("Start" => 0, "End" => 29, "Caption" => "Low", "R" => 0, "G" => 142, "B" => 176);
$IndicatorSections[] = array("Start" => 30, "End" => 49, "Caption" => "Moderate", "R" => 108, "G" => 157, "B" => 49);
$IndicatorSections[] = array("Start" => 50, "End" => 80, "Caption" => "High", "R" => 226, "G" => 74, "B" => 14);
/* Draw the 2nd indicator */
$IndicatorSettings = array("Values" => 35, "Unit" => "%", "CaptionPosition" => INDICATOR_CAPTION_BOTTOM, "CaptionR" => 0, "CaptionG" => 0, "CaptionB" => 0, "DrawLeftHead" => FALSE, "ValueDisplay" => INDICATOR_VALUE_LABEL, "ValueFontName" => "../fonts/Forgotte.ttf", "ValueFontSize" => 15, "IndicatorSections" => $IndicatorSections);
$Indicator->draw(60, 275, 580, 30, $IndicatorSettings);
/* Render the picture (choose the best way) */
$myPicture->autoOutput("pictures/example.mixed.png");