getProcessStatusArray() static public method

Get the ITIL object assign or plan status list
static public getProcessStatusArray ( ) : an
return an array
 /**
  * Get SQL code associated with the criteria
  *
  * @see plugins/reports/inc/PluginReportsArrayCriteria::getSqlCriteriasRestriction()
  **/
 public function getSqlCriteriasRestriction($link = 'AND')
 {
     $status = $this->getParameterValue();
     switch ($status) {
         case "notold":
             $list = implode("','", Ticket::getNewStatusArray());
             $list .= implode("','", Ticket::getProcessStatusArray());
             $list .= "','" . Ticket::WAITING;
             break;
         case "old":
             $list = implode("','", Ticket::getClosedStatusArray());
             break;
         case "process":
             $list = implode("','", Ticket::getProcessStatusArray());
             break;
         case Ticket::INCOMING:
         case Ticket::ASSIGNED:
         case Ticket::PLANNED:
         case Ticket::WAITING:
         case Ticket::SOLVED:
         case Ticket::CLOSED:
             $list = $status;
             break;
         case "all":
         default:
             return '';
     }
     return $link . " " . $this->getSqlField() . " IN ('" . $list . "') ";
 }
 /**
  * List the tickets for an authenticated user
  *
  * @param $params    array of options (author, group, category, status, startdate, enddate, itemtype)
  * @param $protocol        the communication protocol used
  *
  * @return array of hashtable
  **/
 static function methodListTickets($params, $protocol)
 {
     global $DB, $CFG_GLPI;
     if (isset($params['help'])) {
         return array('count' => 'bool,optional', 'start' => 'integer,optional', 'limit' => 'integer,optional', 'user' => 'integer,optional', 'recipient' => 'integer,optional', 'mine' => 'bool,optional', 'group' => 'integer,optional', 'mygroups' => 'bool,optional', 'category' => 'integer,optional', 'status' => 'integer,optional', 'startdate' => 'datetime,optional', 'enddate' => 'datetime,optional', 'itemtype' => 'string,optional', 'item' => 'integer,optional', 'entity' => 'integer,optional', 'satisfaction' => 'integer,optional', 'approval' => 'text,optional', 'approver' => 'integer,optional', 'id2name' => 'bool,optional', 'order' => 'array,optional', 'help' => 'bool,optional');
     }
     if (!Session::getLoginUserID()) {
         return self::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED);
     }
     $resp = array();
     $start = 0;
     if (isset($params['start']) && is_numeric($params['start'])) {
         $start = $params['start'];
     }
     $limit = $_SESSION['glpilist_limit'];
     if (isset($params['limit']) && is_numeric($params['limit'])) {
         $limit = $params['limit'];
     }
     $where = $join = '';
     // User (victim)
     if (isset($params['user'])) {
         if (!is_numeric($params['user']) || $params['user'] < 0) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'user');
         }
         if (Session::haveRight('show_all_ticket', '1') || Session::haveRight('show_group_ticket', '1') || $params['user'] == Session::getLoginUserID()) {
             // restrict to author parameter
             $where = " AND `glpi_tickets_users_request`.`users_id` = '" . $params['user'] . "'";
         } else {
             return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED);
         }
     } else {
         if (Session::haveRight('show_all_ticket', '1') || Session::haveRight('show_group_ticket', '1')) {
             $where = '';
             // Restrict will come from group (if needed)
         } else {
             // Only connected user's tickets'
             $where = " AND `glpi_tickets_users_request`.`users_id`\n                           = '" . Session::getLoginUserID() . "'";
         }
     }
     // Group
     if (isset($params['group'])) {
         if (!is_numeric($params['group']) || $params['group'] < 0) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'group');
         }
         if (Session::haveRight('show_all_ticket', '1') || Session::haveRight('show_group_ticket', '1') && in_array($params['group'], $_SESSION['glpigroups'])) {
             // restrict to group parameter
             $where = " AND `glpi_groups_tickets_request`.`groups_id` = '" . $params['group'] . "'";
         } else {
             return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED);
         }
     } else {
         if (Session::haveRight('show_group_ticket', '1') && !Session::haveRight('show_all_ticket', '1')) {
             // Connected user's group'
             if (count($_SESSION['glpigroups']) > 0) {
                 $where = " AND `glpi_groups_tickets_request`.`groups_id`\n                              IN (" . implode(',', $_SESSION['glpigroups']) . ")";
             } else {
                 $where = " AND `glpi_tickets_users_request`.`users_id`\n                              = '" . Session::getLoginUserID() . "'";
             }
         }
     }
     // Security
     if (empty($where) && !Session::haveRight('show_all_ticket', '1')) {
         return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, '', 'profil');
     }
     // Recipient (person creating the ticket)
     if (isset($params['recipient'])) {
         if (!is_numeric($params['recipient']) || $params['recipient'] < 0) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'recipient');
         }
         // restrict to recipient parameter
         $where = " AND `users_id_recipient`='" . $params['recipient'] . "'";
     }
     // Mine (user or recipient for the ticket)
     if (isset($params['mine'])) {
         $where = " AND (`glpi_tickets_users_request`.`users_id` = '" . Session::getLoginUserID() . "'\n                         OR `users_id_recipient` = '" . Session::getLoginUserID() . "')";
     }
     // Mygroups
     if (isset($param['mygroups'])) {
         $where = " AND `glpi_groups_tickets`.`groups_id`\n                        IN (" . implode(',', $_SESSION['glpigroups']) . ")";
     }
     // Entity
     if (isset($params['entity'])) {
         if (!Session::haveAccessToEntity($params['entity'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, '', 'entity');
         }
         $where = getEntitiesRestrictRequest("WHERE", "glpi_tickets", '', $params['entity']) . $where;
     } else {
         $where = getEntitiesRestrictRequest("WHERE", "glpi_tickets") . $where;
     }
     // Category
     if (isset($params['category'])) {
         if (!is_numeric($params['category']) || $params['category'] <= 0) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'category');
         }
         $where .= " AND " . getRealQueryForTreeItem("glpi_itilcategories", $params['category'], "glpi_tickets.itilcategories_id");
     }
     if (isset($params['approval']) || isset($params['approver'])) {
         $join .= "INNER JOIN `glpi_ticketvalidations`\n                         ON (`glpi_tickets`.`id` = `glpi_ticketvalidations`.`tickets_id` ) ";
         if (isset($params['approver']) && is_numeric($params['approver'])) {
             $where .= " AND `glpi_ticketvalidations`.`users_id_validate`=" . $params['approver'];
         }
         $tabstatus = TicketValidation::getAllStatusArray();
         if (isset($params['approval']) && isset($tabstatus[$params['approval']])) {
             $where .= " AND `glpi_ticketvalidations`.`status`='" . $params['approval'] . "'";
         }
     }
     if (isset($params['satisfaction'])) {
         $join .= "INNER JOIN `glpi_ticketsatisfactions`\n                        ON (`glpi_tickets`.`id` = `glpi_ticketsatisfactions`.`tickets_id` ) ";
         switch ($params['satisfaction']) {
             case 1:
                 $where .= " AND `glpi_ticketsatisfactions`.`date_answered` IS NULL";
                 break;
             case 2:
                 $where .= " AND `glpi_ticketsatisfactions`.`date_answered` IS NOT NULL";
                 break;
             default:
                 // survey exists (by Inner Join)
         }
         $params['status'] = Ticket::CLOSED;
     }
     // Status
     if (isset($params['status'])) {
         if (!in_array($params['status'], Ticket::getAllowedStatusArray(true))) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'status');
         }
         switch ($params['status']) {
             case 'all':
                 // No restriction
                 break;
             case 'notclosed':
                 $status = Ticket::getAllStatusArray();
                 unset($status[CLOSED]);
                 $where .= " AND `glpi_tickets`.`status` IN ('" . implode("','", $status) . "') ";
                 break;
             case 'notold':
                 $status = Ticket::getAllStatusArray();
                 unset($status[SOLVED], $status[CLOSED]);
                 $where .= " AND `glpi_tickets`.`status` IN ('" . implode("','", $status) . "') ";
                 break;
             case 'old':
                 $status = array_merge(Ticket::getSolvedStatusArray(), Ticket::getClosedStatusArray());
                 $where .= " AND `glpi_tickets`.`status` IN ('" . implode("','", $status) . "') ";
                 break;
             case 'process':
                 $status = Ticket::getProcessStatusArray();
                 $where .= " AND `glpi_tickets`.`status` IN ('" . implode("','", $status) . "') ";
                 break;
             default:
                 $where .= " AND `glpi_tickets`.`status` = '" . $params['status'] . "' ";
         }
     }
     // Dates
     if (isset($params["startdate"])) {
         if (preg_match(WEBSERVICES_REGEX_DATETIME, $params["startdate"]) || preg_match(WEBSERVICES_REGEX_DATE, $params["startdate"])) {
             $where .= " AND `glpi_tickets`.`date` >= '" . $params['startdate'] . "' ";
         } else {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'date');
         }
     }
     if (isset($params["enddate"])) {
         if (preg_match(WEBSERVICES_REGEX_DATETIME, $params["enddate"]) || preg_match(WEBSERVICES_REGEX_DATE, $params["enddate"])) {
             $where .= " AND `glpi_tickets`.`date` <= '" . $params['enddate'] . "' ";
         } else {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'date');
         }
     }
     if (isset($params['itemtype'])) {
         if (!empty($params['itemtype']) && !class_exists($params['itemtype'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'itemtype');
         }
         $where .= " AND `glpi_tickets`.`itemtype`='" . $params['itemtype'] . "'";
     }
     if (isset($params['item'])) {
         if (!isset($params['itemtype'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'itemtype');
         }
         if (!is_numeric($params['item']) || $params['item'] <= 0) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'item');
         }
         $where .= " AND `glpi_tickets`.`items_id`='" . $params['item'] . "'";
     }
     $orders = array();
     if (isset($params['order'])) {
         if (is_array($params['order'])) {
             $tab = $params['order'];
         } else {
             $tab = array($params['order'] => 'DESC');
         }
         foreach ($tab as $key => $val) {
             if ($val != 'ASC') {
                 $val = 'DESC';
             }
             $sqlkey = array('id' => '`glpi_tickets`.`id`', 'date' => '`glpi_tickets`.`date`', 'closedate' => '`glpi_tickets`.`closedate`', 'date_mod' => '`glpi_tickets`.`date_mod`', 'status' => '`glpi_tickets`.`status`', 'entities_id' => '`glpi_tickets`.`entities_id`', 'priority' => '`glpi_tickets`.`priority`');
             if (isset($sqlkey[$key])) {
                 $orders[] = $sqlkey[$key] . " {$val}";
             } else {
                 return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'order=$key');
             }
         }
     }
     if (count($orders)) {
         $order = implode(',', $orders);
     } else {
         $order = "`glpi_tickets`.`date_mod` DESC";
     }
     $resp = array();
     if (isset($params['count'])) {
         $query = "SELECT COUNT(DISTINCT `glpi_tickets`.`id`) AS count\n                   FROM `glpi_tickets`\n                   {$join}\n                   LEFT JOIN `glpi_tickets_users` AS glpi_tickets_users_request\n                        ON (`glpi_tickets`.`id` = `glpi_tickets_users_request`.`tickets_id`\n                            AND `glpi_tickets_users_request`.`type` = 1)\n                   LEFT JOIN `glpi_groups_tickets` AS glpi_groups_tickets_request\n                        ON (`glpi_tickets`.`id` = `glpi_groups_tickets_request`.`tickets_id`\n                            AND `glpi_groups_tickets_request`.`type` = 1 )\n                   {$where}";
         $resp = $DB->request($query)->next();
         //debug $resp['query'] = $query;
     } else {
         $query = "SELECT `glpi_tickets`.*,\n                          GROUP_CONCAT(DISTINCT `glpi_tickets_users_request`.`users_id` SEPARATOR ',')\n                                 AS users_id_request,\n                          GROUP_CONCAT(DISTINCT `glpi_tickets_users_observer`.`users_id` SEPARATOR ',')\n                                 AS users_id_observer,\n                          GROUP_CONCAT(DISTINCT `glpi_tickets_users_assign`.`users_id` SEPARATOR ',')\n                                 AS users_id_assign,\n                          GROUP_CONCAT(DISTINCT `glpi_groups_tickets_request`.`groups_id` SEPARATOR ',')\n                                 AS groups_id_request,\n                          GROUP_CONCAT(DISTINCT `glpi_groups_tickets_observer`.`groups_id` SEPARATOR ',')\n                                 AS groups_id_observer,\n                          GROUP_CONCAT(DISTINCT `glpi_groups_tickets_assign`.`groups_id` SEPARATOR ',')\n                                 AS groups_id_assign\n                   FROM `glpi_tickets`\n                   {$join}\n                   LEFT JOIN `glpi_tickets_users` AS glpi_tickets_users_request\n                        ON (`glpi_tickets`.`id` = `glpi_tickets_users_request`.`tickets_id`\n                            AND `glpi_tickets_users_request`.`type` = 1)\n                   LEFT JOIN `glpi_tickets_users` AS glpi_tickets_users_assign\n                        ON (`glpi_tickets`.`id` = `glpi_tickets_users_assign`.`tickets_id`\n                            AND `glpi_tickets_users_assign`.`type` = 2)\n                   LEFT JOIN `glpi_tickets_users` AS glpi_tickets_users_observer\n                        ON (`glpi_tickets`.`id` = `glpi_tickets_users_observer`.`tickets_id`\n                            AND `glpi_tickets_users_observer`.`type` = 3)\n                   LEFT JOIN `glpi_groups_tickets` AS glpi_groups_tickets_request\n                        ON (`glpi_tickets`.`id` = `glpi_groups_tickets_request`.`tickets_id`\n                            AND `glpi_groups_tickets_request`.`type` = 1)\n                   LEFT JOIN `glpi_groups_tickets` AS glpi_groups_tickets_assign\n                        ON (`glpi_tickets`.`id` = `glpi_groups_tickets_assign`.`tickets_id`\n                            AND `glpi_groups_tickets_assign`.`type` = 2)\n                   LEFT JOIN `glpi_groups_tickets` AS glpi_groups_tickets_observer\n                        ON (`glpi_tickets`.`id` = `glpi_groups_tickets_observer`.`tickets_id`\n                            AND `glpi_groups_tickets_observer`.`type` = 3)\n                   {$where}\n                   GROUP BY `glpi_tickets`.`id`\n                   ORDER BY {$order}\n                   LIMIT {$start},{$limit}";
         foreach ($DB->request($query) as $data) {
             $tmp = explode(',', $data['users_id_request']);
             $data['users']['requester'] = array();
             foreach ($tmp as $id) {
                 $data['users']['requester'][]['id'] = $id;
             }
             $tmp = explode(',', $data['users_id_observer']);
             $data['users']['observer'] = array();
             foreach ($tmp as $id) {
                 $data['users']['observer'][]['id'] = $id;
             }
             $tmp = explode(',', $data['users_id_assign']);
             $data['users']['assign'] = array();
             foreach ($tmp as $id) {
                 $data['users']['assign'][]['id'] = $id;
             }
             $tmp = explode(',', $data['groups_id_request']);
             $data['groups']['requester'] = array();
             foreach ($tmp as $id) {
                 $data['groups']['requester'][]['id'] = $id;
             }
             $tmp = explode(',', $data['groups_id_observer']);
             $data['groups']['observer'] = array();
             foreach ($tmp as $id) {
                 $data['groups']['observer'][]['id'] = $id;
             }
             $tmp = explode(',', $data['groups_id_assign']);
             $data['groups']['assign'] = array();
             foreach ($tmp as $id) {
                 $data['groups']['assign'][]['id'] = $id;
             }
             unset($data['groups_id_request'], $data['groups_id_observer'], $data['groups_id_assign'], $data['users_id_request'], $data['users_id_observer'], $data['users_id_assign']);
             $data['solution'] = Html::clean(Toolbox::unclean_cross_side_scripting_deep($data['solution']));
             if (isset($params['id2name'])) {
                 if ($data['itemtype'] && ($item = getItemForItemtype($data['itemtype']))) {
                     $data['itemtype_name'] = Html::clean($item->getTypeName());
                     if ($item->getFromDB($data['items_id'])) {
                         $data['items_name'] = Html::clean($item->getNameID());
                     } else {
                         $data['items_name'] = NOT_AVAILABLE;
                     }
                 }
                 foreach ($data['groups'] as $type => $tab) {
                     foreach ($tab as $key => $grp) {
                         $data['groups'][$type][$key]['name'] = Html::clean(Dropdown::getDropdownName('glpi_groups', $grp['id']));
                     }
                 }
                 foreach ($data['users'] as $type => $tab) {
                     foreach ($tab as $key => $usr) {
                         $data['users'][$type][$key]['name'] = Html::clean(getUserName($usr['id']));
                     }
                 }
                 $data['status_name'] = Html::clean(Ticket::getStatus($data['status']));
                 $data['urgency_name'] = Ticket::getUrgencyName($data['urgency']);
                 $data['impact_name'] = Ticket::getImpactName($data['impact']);
                 $data['priority_name'] = Ticket::getPriorityName($data['priority']);
                 $data['users_name_recipient'] = Html::clean(getUserName($data['users_id_recipient']));
                 $data['entities_name'] = Html::clean(Dropdown::getDropdownName('glpi_entities', $data['entities_id']));
                 $data['suppliers_name_assign'] = Html::clean(Dropdown::getDropdownName('glpi_suppliers', $data['suppliers_id_assign']));
                 $data['ticketcategories_name'] = Html::clean(Dropdown::getDropdownName('glpi_itilcategories', $data['itilcategories_id']));
                 $data['requesttypes_name'] = Html::clean(Dropdown::getDropdownName('glpi_requesttypes', $data['requesttypes_id']));
                 $data['solutiontypes_name'] = Html::clean(Dropdown::getDropdownName('glpi_solutiontypes', $data['solutiontypes_id']));
                 $data['slas_name'] = Html::clean(Dropdown::getDropdownName('glpi_slas', $data['slas_id']));
                 $data['slalevels_name'] = Html::clean(Dropdown::getDropdownName('glpi_slalevels', $data['slalevels_id']));
             }
             $resp[] = $data;
         }
     }
     return $resp;
 }