/**
  * @param $itemtype
  * @param $date1
  * @param $date2
  * @param $type
  * @param $parent    (default 0)
  **/
 static function getItems($itemtype, $date1, $date2, $type, $parent = 0)
 {
     global $CFG_GLPI, $DB;
     if (!($item = getItemForItemtype($itemtype))) {
         return;
     }
     $val = array();
     $cond = '';
     switch ($type) {
         case "technicien":
             $val = $item->getUsedTechBetween($date1, $date2);
             break;
         case "technicien_followup":
             $val = $item->getUsedTechTaskBetween($date1, $date2);
             break;
         case "suppliers_id_assign":
             $val = $item->getUsedSupplierBetween($date1, $date2);
             break;
         case "user":
             $val = $item->getUsedAuthorBetween($date1, $date2);
             break;
         case "users_id_recipient":
             $val = $item->getUsedRecipientBetween($date1, $date2);
             break;
         case 'group_tree':
         case 'groups_tree_assign':
             // Get all groups
             $query = "SELECT `id`, `name`\n                      FROM `glpi_groups`" . getEntitiesRestrictRequest(" WHERE", "glpi_groups", '', '', true) . "\n                            AND (`id` = {$parent} OR `groups_id` = '{$parent}')\n                            AND " . ($type == 'group_tree' ? '`is_requester`' : '`is_assign`') . "\n                      ORDER BY `completename`";
             $result = $DB->query($query);
             $val = array();
             if ($DB->numrows($result) >= 1) {
                 while ($line = $DB->fetch_assoc($result)) {
                     $tmp['id'] = $line["id"];
                     $tmp['link'] = $line["name"];
                     $val[] = $tmp;
                 }
             }
             break;
         case "itilcategories_tree":
             $cond = "AND (`id` = '{$parent}'\n                          OR `itilcategories_id` = '{$parent}')";
             // nobreak
         // nobreak
         case "itilcategories_id":
             // Get all ticket categories for tree merge management
             $query = "SELECT DISTINCT `glpi_itilcategories`.`id`,\n                             `glpi_itilcategories`.`" . ($cond ? 'name' : 'completename') . "` AS category\n                      FROM `glpi_itilcategories`" . getEntitiesRestrictRequest(" WHERE", "glpi_itilcategories", '', '', true) . "\n                            {$cond}\n                      ORDER BY `completename`";
             $result = $DB->query($query);
             $val = array();
             if ($DB->numrows($result) >= 1) {
                 while ($line = $DB->fetch_assoc($result)) {
                     $tmp['id'] = $line["id"];
                     $tmp['link'] = $line["category"];
                     $val[] = $tmp;
                 }
             }
             break;
         case 'locations_tree':
             $cond = "AND (`id` = '{$parent}'\n                          OR `locations_id` = '{$parent}')";
             // nobreak
         // nobreak
         case 'locations_id':
             // Get all locations for tree merge management
             $query = "SELECT DISTINCT `glpi_locations`.`id`,\n                             `glpi_locations`.`" . ($cond ? 'name' : 'completename') . "` AS location\n                      FROM `glpi_locations`" . getEntitiesRestrictRequest(' WHERE', 'glpi_locations', '', '', true) . "\n                            {$cond}\n                      ORDER BY `completename`";
             $result = $DB->query($query);
             $val = array();
             if ($DB->numrows($result) >= 1) {
                 while ($line = $DB->fetch_assoc($result)) {
                     $tmp['id'] = $line['id'];
                     $tmp['link'] = $line['location'];
                     $val[] = $tmp;
                 }
             }
             break;
         case "type":
             $types = $item->getTypes();
             $val = array();
             foreach ($types as $id => $v) {
                 $tmp['id'] = $id;
                 $tmp['link'] = $v;
                 $val[] = $tmp;
             }
             break;
         case "group":
             $val = $item->getUsedGroupBetween($date1, $date2);
             break;
         case "groups_id_assign":
             $val = $item->getUsedAssignGroupBetween($date1, $date2);
             break;
         case "priority":
             $val = $item->getUsedPriorityBetween($date1, $date2);
             break;
         case "urgency":
             $val = $item->getUsedUrgencyBetween($date1, $date2);
             break;
         case "impact":
             $val = $item->getUsedImpactBetween($date1, $date2);
             break;
         case "requesttypes_id":
             $val = $item->getUsedRequestTypeBetween($date1, $date2);
             break;
         case "solutiontypes_id":
             $val = $item->getUsedSolutionTypeBetween($date1, $date2);
             break;
         case "usertitles_id":
             $val = $item->getUsedUserTitleOrTypeBetween($date1, $date2, true);
             break;
         case "usercategories_id":
             $val = $item->getUsedUserTitleOrTypeBetween($date1, $date2, false);
             break;
             // DEVICE CASE
         // DEVICE CASE
         default:
             if (($item = getItemForItemtype($type)) && $item instanceof CommonDevice) {
                 $device_table = $item->getTable();
                 //select devices IDs (table row)
                 $query = "SELECT `id`, `designation`\n                         FROM `" . $device_table . "`\n                         ORDER BY `designation`";
                 $result = $DB->query($query);
                 if ($DB->numrows($result) >= 1) {
                     $i = 0;
                     while ($line = $DB->fetch_assoc($result)) {
                         $val[$i]['id'] = $line['id'];
                         $val[$i]['link'] = $line['designation'];
                         $i++;
                     }
                 }
             } else {
                 // Dropdown case for computers
                 $field = "name";
                 $table = getTableFOrItemType($type);
                 if (($item = getItemForItemtype($type)) && $item instanceof CommonTreeDropdown) {
                     $field = "completename";
                 }
                 $where = '';
                 $order = " ORDER BY `{$field}`";
                 if ($item->isEntityAssign()) {
                     $where = getEntitiesRestrictRequest(" WHERE", $table);
                     $order = " ORDER BY `entities_id`, `{$field}`";
                 }
                 $query = "SELECT *\n                         FROM `{$table}`\n                         {$where}\n                         {$order}";
                 $val = array();
                 $result = $DB->query($query);
                 if ($DB->numrows($result) > 0) {
                     while ($line = $DB->fetch_assoc($result)) {
                         $tmp['id'] = $line["id"];
                         $tmp['link'] = $line[$field];
                         $val[] = $tmp;
                     }
                 }
             }
     }
     return $val;
 }
Пример #2
0
 static function getItems($date1, $date2, $type)
 {
     global $CFG_GLPI, $DB;
     $val = array();
     switch ($type) {
         case "technicien":
             $val = PluginMobileTicket::getUsedTechBetween($date1, $date2);
             break;
         case "technicien_followup":
             $val = PluginMobileTicket::getUsedTechFollowupBetween($date1, $date2);
             break;
         case "enterprise":
             $val = PluginMobileTicket::getUsedSupplierBetween($date1, $date2);
             break;
         case "user":
             $val = PluginMobileTicket::getUsedAuthorBetween($date1, $date2);
             break;
         case "users_id_recipient":
             $val = PluginMobileTicket::getUsedRecipientBetween($date1, $date2);
             break;
         case "ticketcategories_id":
             // Get all ticket categories for tree merge management
             $query = "SELECT DISTINCT `glpi_itilcategories`.`id`,\n                           `glpi_itilcategories`.`completename` AS category\n                     FROM `glpi_itilcategories`\n                     " . getEntitiesRestrictRequest(" WHERE", "glpi_itilcategories", '', '', true) . "\n                     ORDER BY category";
             $result = $DB->query($query);
             $val = array();
             if ($DB->numrows($result) >= 1) {
                 while ($line = $DB->fetch_assoc($result)) {
                     $tmp['id'] = $line["id"];
                     $tmp['link'] = $line["category"];
                     $val[] = $tmp;
                 }
             }
             break;
         case "group":
             $val = Ticket::getUsedGroupBetween($date1, $date2);
             break;
         case "groups_id_assign":
             $val = Ticket::getUsedAssignGroupBetween($date1, $date2);
             break;
         case "priority":
             $val = Ticket::getUsedPriorityBetween($date1, $date2);
             break;
         case "urgency":
             $val = Ticket::getUsedUrgencyBetween($date1, $date2);
             break;
         case "impact":
             $val = Ticket::getUsedImpactBetween($date1, $date2);
             break;
         case "requesttypes_id":
             $val = Ticket::getUsedRequestTypeBetween($date1, $date2);
             break;
         case "ticketsolutiontypes_id":
             $val = Ticket::getUsedSolutionTypeBetween($date1, $date2);
             break;
         case "usertitles_id":
             $val = Ticket::getUsedUserTitleOrTypeBetween($date1, $date2, true);
             break;
         case "usercategories_id":
             $val = Ticket::getUsedUserTitleOrTypeBetween($date1, $date2, false);
             break;
             // DEVICE CASE
         // DEVICE CASE
         default:
             $item = new $type();
             if ($item instanceof CommonDevice) {
                 $device_table = $item->getTable();
                 //select devices IDs (table row)
                 $query = "SELECT `id`, `designation`\n                        FROM `" . $device_table . "`\n                        ORDER BY `designation`";
                 $result = $DB->query($query);
                 if ($DB->numrows($result) >= 1) {
                     $i = 0;
                     while ($line = $DB->fetch_assoc($result)) {
                         $val[$i]['id'] = $line['id'];
                         $val[$i]['link'] = $line['designation'];
                         $i++;
                     }
                 }
             } else {
                 //echo $type;
                 // Dropdown case for computers
                 $field = "name";
                 $table = getTableFOrItemType($type);
                 $item = new $type();
                 if ($item instanceof CommonTreeDropdown) {
                     $field = "completename";
                 }
                 $where = '';
                 $order = " ORDER BY `{$field}`";
                 if ($item->isEntityAssign()) {
                     $where = getEntitiesRestrictRequest(" WHERE", $table);
                     $order = " ORDER BY `entities_id`, `{$field}`";
                 }
                 $query = "SELECT *\n                        FROM `{$table}`\n                        {$where}\n                        {$order}";
                 $val = array();
                 $result = $DB->query($query);
                 if ($DB->numrows($result) > 0) {
                     while ($line = $DB->fetch_assoc($result)) {
                         $tmp['id'] = $line["id"];
                         $tmp['link'] = $line[$field];
                         $val[] = $tmp;
                     }
                 }
             }
     }
     return $val;
 }