/**
  * @see CommonGLPI::getTabNameForItem()
  **/
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     // can exists for template
     if ($item->getType() == 'Project' && Project::canView()) {
         if ($_SESSION['glpishow_count_on_tabs']) {
             return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), countElementsInTable('glpi_projectcosts', "projects_id = '" . $item->getID() . "'"));
         }
         return self::getTypeName(Session::getPluralNumber());
     }
     return '';
 }
Example #2
0
 /** show GANTT diagram for a project or for all
  *
  * @param $ID ID of the project or -1 for all projects
  */
 static function showGantt($ID)
 {
     global $DB;
     if ($ID > 0) {
         $project = new Project();
         if ($project->getFromDB($ID) && $project->canView()) {
             $todisplay = static::getDataToDisplayOnGantt($ID);
         } else {
             return false;
         }
     } else {
         $todisplay = array();
         // Get all root projects
         $query = "SELECT *\n                   FROM `glpi_projects`\n                   WHERE `projects_id` = '0'\n                        AND `show_on_global_gantt` = '1'\n                         " . getEntitiesRestrictRequest("AND", 'glpi_projects', "", '', true);
         foreach ($DB->request($query) as $data) {
             $todisplay += static::getDataToDisplayOnGantt($data['id'], false);
         }
         ksort($todisplay);
     }
     $data = array();
     $invalid = array();
     if (count($todisplay)) {
         // Prepare for display
         foreach ($todisplay as $key => $val) {
             if (!empty($val['from']) && !empty($val['to'])) {
                 $temp = array();
                 $color = 'ganttRed';
                 if ($val['percent'] > 50) {
                     $color = 'ganttOrange';
                 }
                 if ($val['percent'] == 100) {
                     $color = 'ganttGreen';
                 }
                 switch ($val['type']) {
                     case 'project':
                         $temp = array('name' => $val['link'], 'desc' => '', 'values' => array(array('from' => "/Date(" . strtotime($val['from']) . "000)/", 'to' => "/Date(" . strtotime($val['to']) . "000)/", 'desc' => $val['desc'], 'label' => $val['percent'] . "%", 'customClass' => $color)));
                         break;
                     case 'task':
                         if (isset($val['is_milestone']) && $val['is_milestone']) {
                             $color = 'ganttMilestone';
                         }
                         $temp = array('name' => ' ', 'desc' => str_repeat('-', $val['parents']) . $val['link'], 'values' => array(array('from' => "/Date(" . strtotime($val['from']) . "000)/", 'to' => "/Date(" . strtotime($val['to']) . "000)/", 'desc' => $val['desc'], 'label' => strlen($val['percent'] == 0) ? '' : $val['percent'] . "%", 'customClass' => $color)));
                         break;
                 }
                 $data[] = $temp;
             } else {
                 $invalid[] = $val['link'];
             }
         }
         // Html::printCleanArray($data);
     }
     if (count($invalid)) {
         echo sprintf(__('Invalid items (no start or end date): %s'), implode(',', $invalid));
         echo "<br><br>";
     }
     if (count($data)) {
         $months = array(__('January'), __('February'), __('March'), __('April'), __('May'), __('June'), __('July'), __('August'), __('September'), __('October'), __('November'), __('December'));
         $dow = array(Toolbox::substr(__('Sunday'), 0, 1), Toolbox::substr(__('Monday'), 0, 1), Toolbox::substr(__('Tuesday'), 0, 1), Toolbox::substr(__('Wednesday'), 0, 1), Toolbox::substr(__('Thursday'), 0, 1), Toolbox::substr(__('Friday'), 0, 1), Toolbox::substr(__('Saturday'), 0, 1));
         echo "<div class='gantt'></div>";
         $js = "\n                           \$('.gantt').gantt({\n                                 source: " . json_encode($data) . ",\n                                 navigate: 'scroll',\n                                 maxScale: 'months',\n                                 itemsPerPage: 20,\n                                 months: " . json_encode($months) . ",\n                                 dow: " . json_encode($dow) . ",\n                                 onItemClick: function(data) {\n                                 //    alert('Item clicked - show some details');\n                                 },\n                                 onAddClick: function(dt, rowId) {\n                                 //    alert('Empty space clicked - add an item!');\n                                 },\n                           });";
         echo Html::scriptBlock($js);
     } else {
         _e('No item to display');
     }
 }