/** * Do a specific SLAlevel for a ticket * * @param $data array data of an entry of slalevels_tickets * @param $sltType Type of slt * * @since version 9.1 2 parameters mandatory * * @return nothing **/ static function doLevelForTicket(array $data, $sltType) { $ticket = new Ticket(); $slalevelticket = new self(); // existing ticket and not deleted if ($ticket->getFromDB($data['tickets_id']) && !$ticket->isDeleted()) { // search all actors of a ticket foreach ($ticket->getUsers(CommonITILActor::REQUESTER) as $user) { $ticket->fields['_users_id_requester'][] = $user['users_id']; } foreach ($ticket->getUsers(CommonITILActor::ASSIGN) as $user) { $ticket->fields['_users_id_assign'][] = $user['users_id']; } foreach ($ticket->getUsers(CommonITILActor::OBSERVER) as $user) { $ticket->fields['_users_id_observer'][] = $user['users_id']; } foreach ($ticket->getGroups(CommonITILActor::REQUESTER) as $group) { $ticket->fields['_groups_id_requester'][] = $group['groups_id']; } foreach ($ticket->getGroups(CommonITILActor::ASSIGN) as $group) { $ticket->fields['_groups_id_assign'][] = $group['groups_id']; } foreach ($ticket->getGroups(CommonITILActor::OBSERVER) as $group) { $ticket->fields['_groups_id_observer'][] = $group['groups_id']; } foreach ($ticket->getSuppliers(CommonITILActor::ASSIGN) as $supplier) { $ticket->fields['_suppliers_id_assign'][] = $supplier['suppliers_id']; } $slalevel = new SlaLevel(); $slt = new SLT(); // Check if slt datas are OK list($dateField, $sltField) = SLT::getSltFieldNames($sltType); if ($ticket->fields[$sltField] > 0) { if ($ticket->fields['status'] == CommonITILObject::CLOSED) { // Drop line when status is closed $slalevelticket->delete(array('id' => $data['id'])); } else { if ($ticket->fields['status'] != CommonITILObject::SOLVED) { // No execution if ticket has been taken into account if (!($sltType == SLT::TTO && $ticket->fields['takeintoaccount_delay_stat'] > 0)) { // If status = solved : keep the line in case of solution not validated $input['id'] = $ticket->getID(); $input['_auto_update'] = true; if ($slalevel->getRuleWithCriteriasAndActions($data['slalevels_id'], 1, 1) && $slt->getFromDB($ticket->fields[$sltField])) { $doit = true; if (count($slalevel->criterias)) { $doit = $slalevel->checkCriterias($ticket->fields); } // Process rules if ($doit) { $input = $slalevel->executeActions($input, array()); } } // Put next level in todo list $next = $slalevel->getNextSltLevel($ticket->fields[$sltField], $data['slalevels_id']); $slt->addLevelToDo($ticket, $next); // Action done : drop the line $slalevelticket->delete(array('id' => $data['id'])); $ticket->update($input); } else { // Drop line $slalevelticket->delete(array('id' => $data['id'])); } } } } else { // Drop line $slalevelticket->delete(array('id' => $data['id'])); } } else { // Drop line $slalevelticket->delete(array('id' => $data['id'])); } }
function post_addItem() { global $CFG_GLPI; if (isset($this->input['content'])) { if (isset($this->input['_stock_image'])) { $this->addImagePaste(); } } // Log this event $username = '******'; if (isset($_SESSION["glpiname"])) { $username = $_SESSION["glpiname"]; } Event::log($this->fields['id'], "ticket", 4, "tracking", sprintf(__('%1$s adds the item %2$s'), $username, $this->fields['id'])); if (isset($this->input["_followup"]) && is_array($this->input["_followup"]) && strlen($this->input["_followup"]['content']) > 0) { $fup = new TicketFollowup(); $type = "new"; if (isset($this->fields["status"]) && $this->fields["status"] == self::SOLVED) { $type = "solved"; } $toadd = array("type" => $type, "tickets_id" => $this->fields['id']); if (isset($this->input["_followup"]['content']) && strlen($this->input["_followup"]['content']) > 0) { $toadd["content"] = $this->input["_followup"]['content']; } if (isset($this->input["_followup"]['is_private'])) { $toadd["is_private"] = $this->input["_followup"]['is_private']; } // $toadd['_no_notif'] = true; $fup->add($toadd); } if (isset($this->input["plan"]) && count($this->input["plan"]) || isset($this->input["actiontime"]) && $this->input["actiontime"] > 0) { $task = new TicketTask(); $type = "new"; if (isset($this->fields["status"]) && $this->fields["status"] == self::SOLVED) { $type = "solved"; } $toadd = array("type" => $type, "tickets_id" => $this->fields['id'], "actiontime" => $this->input["actiontime"]); if (isset($this->input["plan"]) && count($this->input["plan"])) { $toadd["plan"] = $this->input["plan"]; } if (isset($_SESSION['glpitask_private'])) { $toadd['is_private'] = $_SESSION['glpitask_private']; } // $toadd['_no_notif'] = true; $task->add($toadd); } $ticket_ticket = new Ticket_Ticket(); // From interface if (isset($this->input['_link'])) { $this->input['_link']['tickets_id_1'] = $this->fields['id']; // message if ticket's ID doesn't exist if (!empty($this->input['_link']['tickets_id_2'])) { if ($ticket_ticket->can(-1, CREATE, $this->input['_link'])) { $ticket_ticket->add($this->input['_link']); } else { Session::addMessageAfterRedirect(__('Unknown ticket'), false, ERROR); } } } // From mailcollector : do not check rights if (isset($this->input["_linkedto"])) { $input2['tickets_id_1'] = $this->fields['id']; $input2['tickets_id_2'] = $this->input["_linkedto"]; $input2['link'] = Ticket_Ticket::LINK_TO; $ticket_ticket->add($input2); } // Manage SLT Level : add actions foreach (array(SLT::TTR, SLT::TTO) as $sltType) { list($dateField, $sltField) = SLT::getSltFieldNames($sltType); if (isset($this->input[$sltField]) && $this->input[$sltField] > 0) { $this->manageSltLevel($this->input[$sltField]); } } // Add project task link if needed if (isset($this->input['_projecttasks_id'])) { $projecttask = new ProjectTask(); if ($projecttask->getFromDB($this->input['_projecttasks_id'])) { $pt = new ProjectTask_Ticket(); $pt->add(array('projecttasks_id' => $this->input['_projecttasks_id'], 'tickets_id' => $this->fields['id'])); } } if (!empty($this->input['items_id'])) { $item_ticket = new Item_Ticket(); foreach ($this->input['items_id'] as $itemtype => $items) { foreach ($items as $items_id) { $item_ticket->add(array('items_id' => $items_id, 'itemtype' => $itemtype, 'tickets_id' => $this->fields['id'], '_disablenotif' => true)); } } } parent::post_addItem(); $this->manageValidationAdd($this->input); // Processing Email if ($CFG_GLPI["use_mailing"]) { // Clean reload of the ticket $this->getFromDB($this->fields['id']); $type = "new"; if (isset($this->fields["status"]) && $this->fields["status"] == self::SOLVED) { $type = "solved"; } NotificationEvent::raiseEvent($type, $this); } if (isset($_SESSION['glpiis_ids_visible']) && !$_SESSION['glpiis_ids_visible']) { Session::addMessageAfterRedirect(sprintf(__('%1$s (%2$s)'), __('Your ticket has been registered, its treatment is in progress.'), sprintf(__('%1$s: %2$s'), __('Ticket'), "<a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $this->fields['id'] . "'>" . $this->fields['id'] . "</a>"))); } }
function cleanDBonPurge() { global $DB; // Clean sla_levels $query = "SELECT `id`\n FROM `glpi_slalevels`\n WHERE `slts_id` = '" . $this->fields['id'] . "'"; if ($result = $DB->query($query)) { if ($DB->numrows($result) > 0) { $slalevel = new SlaLevel(); while ($data = $DB->fetch_assoc($result)) { $slalevel->delete($data); } } } // Update tickets : clean SLT list($dateField, $sltField) = SLT::getSltFieldNames($this->fields['type']); $query = "SELECT `id`\n FROM `glpi_tickets`\n WHERE `{$sltField}` = '" . $this->fields['id'] . "'"; if ($result = $DB->query($query)) { if ($DB->numrows($result) > 0) { $ticket = new Ticket(); while ($data = $DB->fetch_assoc($result)) { $ticket->deleteSLT($data['id'], $this->fields['type']); } } } Rule::cleanForItemAction($this); }