/** * @param $report * @param $name (default 'type') * @param $label (default '') **/ function __construct($report, $name = 'type', $label = '') { $options = array('all' => Dropdown::EMPTY_VALUE); foreach (Ticket::getTypes() as $k => $v) { $options[$k] = $v; } parent::__construct($report, $name, $label ? $label : _n('Type', 'Type', 1), $options); }
/** * Create a new ticket * for an authenticated user * * @param $params array of options * (entity, user, group, date, itemtype, itemid, title, content, urgency, category) * @param $protocol the communication protocol used * * @return array of hashtable **/ static function methodCreateTicket($params = array(), $protocol) { global $CFG_GLPI; if (isset($params['help'])) { return array('content' => 'string,mandatory', 'title' => 'string,optional', 'entity' => 'integer,optional', 'urgency' => 'integer,optional', 'impact' => 'integer,optional', 'category' => 'integer,optional', 'user' => 'integer,optional', 'requester' => 'integer,optional', 'observer' => 'integer,optional', 'group' => 'integer,optional', 'groupassign' => 'integer,optional', 'date' => 'datetime,optional', 'type' => 'integer,optional', 'category' => 'integer,optional', 'itemtype' => 'string,optional', 'item' => 'integer,optional', 'source' => 'string,optional', 'user_email' => 'string,optional', 'use_email_notification' => 'bool,optional', 'help' => 'bool,optional'); } if (!Session::getLoginUserID()) { return self::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED); } // ignore config for content : always mandatory if (!isset($params['content']) || empty($params['content'])) { return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'content'); } // Source of the ticket, dynamically created if (isset($params['source'])) { if (empty($params['content'])) { return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'source'); } $source = Dropdown::importExternal('RequestType', $params['source']); } else { $source = Dropdown::importExternal('RequestType', 'WebServices'); } // ===== Build the Ticket ===== // author : always the logged user $data = array('_users_id_requester' => Session::getLoginUserID(), 'users_id_recipient' => Session::getLoginUserID(), 'requesttypes_id' => $source, 'status' => Ticket::INCOMING, 'content' => addslashes(Toolbox::clean_cross_side_scripting_deep($params["content"])), 'itemtype' => '', 'type' => Ticket::INCIDENT_TYPE, 'items_id' => 0); // Title : optional (default = start of contents set by add method) if (isset($params['title'])) { $data['name'] = addslashes(Toolbox::clean_cross_side_scripting_deep($params['title'])); } // entity : optionnal, default = current one if (!isset($params['entity'])) { $data['entities_id'] = $_SESSION['glpiactive_entity']; } else { if (!is_numeric($params['entity']) || !in_array($params['entity'], $_SESSION['glpiactiveentities'])) { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'entity'); } $data['entities_id'] = $params['entity']; } // user (author) : optionnal, default = current one if (isset($params['user'])) { if (!is_numeric($params['user'])) { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'user'); } $data['_users_id_requester'] = $params['user']; } // Email notification if (isset($params['user_email'])) { if (!NotificationMail::isUserAddressValid($params['user_email'])) { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'user_email'); } $data['_users_id_requester_notif']['alternative_email'] = $params['user_email']; $data['_users_id_requester_notif']['use_notification'] = 1; } else { if (isset($params['use_email_notification']) && $params['use_email_notification']) { $data['_users_id_requester_notif']['use_notification'] = 1; } else { if (isset($params['use_email_notification']) && !$params['use_email_notification']) { $data['_users_id_requester_notif']['use_notification'] = 0; } } } if (isset($params['requester'])) { if (is_array($params['requester'])) { foreach ($params['requester'] as $id) { if (is_numeric($id) && $id > 0) { $data['_additional_requesters'][] = array('users_id' => $id, 'use_notification' => true); } else { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'requester'); } } } else { if (is_numeric($params['requester']) && $params['requester'] > 0) { $data['_additional_requesters'][] = array('users_id' => $params['requester'], 'use_notification' => true); } else { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'requester'); } } } if (isset($params['victim'])) { if (is_array($params['victim'])) { foreach ($params['victim'] as $id) { if (is_numeric($id) && $id > 0) { $data['_additional_requesters'][] = array('users_id' => $id, 'use_notification' => false); } else { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'victim'); } } } else { if (is_numeric($params['victim']) && $params['victim'] > 0) { $data['_additional_requesters'][] = array('users_id' => $params['victim'], 'use_notification' => false); } else { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'victim'); } } } if (isset($params['observer'])) { if (is_array($params['observer'])) { foreach ($params['observer'] as $id) { if (is_numeric($id) && $id > 0) { $data['_additional_observers'][] = array('users_id' => $id, 'use_notification' => true); } else { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'observer'); } } } else { if (is_numeric($params['observer']) && $params['observer'] > 0) { $data['_additional_observers'][] = array('users_id' => $params['observer'], 'use_notification' => true); } else { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'observer'); } } } // group (author) : optionnal, default = none if (!isset($params['group'])) { $data['_groups_id_requester'] = 0; } else { if (!is_numeric($params['group'])) { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'group'); } $data['_groups_id_requester'] = $params['group']; } // groupassign (technicians group) : optionnal, default = none if (!isset($params['groupassign'])) { $data['_groups_id_assign'] = 0; } else { if (!is_numeric($params['groupassign'])) { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'groupassign'); } $data['_groups_id_assign'] = $params['groupassign']; } // date (open) : optional, default set by add method if (isset($params['date'])) { if (preg_match(WEBSERVICES_REGEX_DATETIME, $params['date'])) { $data['date'] = $params['date']; } else { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'date'); } } if (isset($params['itemtype']) && empty($params['itemtype'])) { unset($params['itemtype']); } if (isset($params['item']) && !$params['item']) { unset($params['item']); } // Item type + id if (isset($params['itemtype'])) { if (!isset($params['item'])) { return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'item'); } if (!class_exists($params['itemtype'])) { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', '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=' . $params['item']); } // Both ok $data['itemtype'] = $params['itemtype']; $data['items_id'] = $params['item']; } // Hack for compatibility with previous version if (isset($params['urgence'])) { $params['urgency'] = $params['urgence']; } // urgence (priority while not exists) : optionnal, default = 3 if (!isset($params['urgency'])) { $data['urgency'] = 3; } else { if (!is_numeric($params['urgency']) || $params['urgency'] < 1 || $params['urgency'] > 5 || isset($params['urgency']) && !($CFG_GLPI['urgency_mask'] & 1 << $params["urgency"])) { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'urgency'); } else { $data['urgency'] = $params['urgency']; } } if (isset($params['impact'])) { if (!is_numeric($params['impact']) || $params['impact'] < 1 || $params['impact'] > 5 || isset($params['impact']) && !($CFG_GLPI['impact_mask'] & 1 << $params["impact"])) { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'impact'); } else { $data['impact'] = $params['impact']; } } // category : optionnal if (isset($params['category'])) { if (!is_numeric($params['category']) || $params['category'] < 1) { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'category'); } $data['itilcategories_id'] = $params['category']; } // type : optionnal (default = INCIDENT) if (isset($params['type'])) { $types = Ticket::getTypes(); if (!is_numeric($params['type']) || !isset($types[$params['type']])) { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'type'); } $data['type'] = $params['type']; } $ticket = new Ticket(); if ($newID = $ticket->add($data)) { return self::methodGetTicket(array('ticket' => $newID), $protocol); } return self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', self::getDisplayError()); }
static function getItems($date1, $date2, $type) { global $CFG_GLPI, $DB; $val = array(); switch ($type) { case "technicien": $val = Ticket::getUsedTechBetween($date1, $date2); break; case "technicien_followup": $val = Ticket::getUsedTechTaskBetween($date1, $date2); break; case "enterprise": $val = Ticket::getUsedSupplierBetween($date1, $date2); break; case "user": $val = Ticket::getUsedAuthorBetween($date1, $date2); break; case "users_id_recipient": $val = Ticket::getUsedRecipientBetween($date1, $date2); break; case "ticketcategories_id": // Get all ticket categories for tree merge management $query = "SELECT DISTINCT `glpi_ticketcategories`.`id`,\n `glpi_ticketcategories`.`completename` AS category\n FROM `glpi_ticketcategories`" . getEntitiesRestrictRequest(" WHERE", "glpi_ticketcategories", '', '', 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 "type": $types = Ticket::getTypes(); $val = array(); foreach ($types as $id => $v) { $tmp['id'] = $id; $tmp['link'] = $v; $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 { // 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; }