function post_addItem() { global $CFG_GLPI; // 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, 'w', $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 SLA Level : add actions if (isset($this->input["slas_id"]) && $this->input["slas_id"] > 0 && isset($this->input["slalevels_id"]) && $this->input["slalevels_id"] > 0) { $calendars_id = Entity::getUsedConfig('calendars_id', $this->fields['entities_id']); $sla = new SLA(); if ($sla->getFromDB($this->input["slas_id"])) { $sla->setTicketCalendar($calendars_id); // Add first level in working table if ($this->input["slalevels_id"] > 0) { $sla->addLevelToDo($this); } // Replay action in case of open date is set before now } SlaLevel_Ticket::replayForTicket($this->getID()); } parent::post_addItem(); //Action for send_validation rule if (isset($this->input["_add_validation"])) { $validations_to_send = array(); if (!is_array($this->input["_add_validation"])) { $this->input["_add_validation"] = array($this->input["_add_validation"]); } foreach ($this->input["_add_validation"] as $validation) { switch ($validation) { case 'requester_supervisor': if (isset($this->input['_groups_id_requester']) && $this->input['_groups_id_requester']) { $users = Group_User::getGroupUsers($this->input['_groups_id_requester'], "is_manager='1'"); foreach ($users as $data) { $validations_to_send[] = $data['id']; } } break; case 'assign_supervisor': if (isset($this->input['_groups_id_assign']) && $this->input['_groups_id_assign']) { $users = Group_User::getGroupUsers($this->input['_groups_id_assign'], "is_manager='1'"); foreach ($users as $data) { $validations_to_send[] = $data['id']; } } break; default: $validations_to_send[] = $validation; } } // Keep only one $validations_to_send = array_unique($validations_to_send); $validation = new TicketValidation(); foreach ($validations_to_send as $users_id) { if ($users_id > 0) { $values = array(); $values['tickets_id'] = $this->fields['id']; $values['users_id_validate'] = $users_id; $values['_ticket_add'] = true; // to know update by rules if (isset($this->input["_rule_process"])) { $values['_rule_process'] = $this->input["_rule_process"]; } // if auto_import, tranfert it for validation if (isset($this->input['_auto_import'])) { $values['_auto_import'] = $this->input['_auto_import']; } // Cron or rule process of hability to do if (Session::isCron() || isset($this->input["_auto_import"]) || isset($this->input["_rule_process"]) || $validation->can(-1, 'w', $values)) { // cron or allowed user $validation->add($values); Event::log($this->fields['id'], "ticket", 4, "tracking", sprintf(__('%1$s updates the item %2$s'), $_SESSION["glpiname"], $this->fields['id'])); } } } } // 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 pre_updateInDB() { // get again object to reload actors $this->loadActors(); // Setting a solution or solution type means the problem is solved if (in_array("solutiontypes_id", $this->updates) && $this->input["solutiontypes_id"] > 0 || in_array("solution", $this->updates) && !empty($this->input["solution"])) { if (!in_array('status', $this->updates)) { $this->oldvalues['status'] = $this->fields['status']; $this->updates[] = 'status'; } // Special case for Ticket : use autoclose if ($this->getType() == 'Ticket') { $autoclosedelay = Entity::getUsedConfig('autoclose_delay', $this->getEntityID(), '', Entity::CONFIG_NEVER); // 0 = immediatly if ($autoclosedelay == 0) { $this->fields['status'] = self::CLOSED; $this->input['status'] = self::CLOSED; } else { $this->fields['status'] = self::SOLVED; $this->input['status'] = self::SOLVED; } } else { $this->fields['status'] = self::SOLVED; $this->input['status'] = self::SOLVED; } } // Check dates change interval due to the fact that second are not displayed in form if (($key = array_search('date', $this->updates)) !== false && substr($this->fields["date"], 0, 16) == substr($this->oldvalues['date'], 0, 16)) { unset($this->updates[$key]); unset($this->oldvalues['date']); } if (($key = array_search('closedate', $this->updates)) !== false && substr($this->fields["closedate"], 0, 16) == substr($this->oldvalues['closedate'], 0, 16)) { unset($this->updates[$key]); unset($this->oldvalues['closedate']); } if (($key = array_search('due_date', $this->updates)) !== false && substr($this->fields["due_date"], 0, 16) == substr($this->oldvalues['due_date'], 0, 16)) { unset($this->updates[$key]); unset($this->oldvalues['due_date']); } if (($key = array_search('solvedate', $this->updates)) !== false && substr($this->fields["solvedate"], 0, 16) == substr($this->oldvalues['solvedate'], 0, 16)) { unset($this->updates[$key]); unset($this->oldvalues['solvedate']); } if (isset($this->input["status"])) { if ($this->input["status"] != self::WAITING && $this->countSuppliers(CommonITILActor::ASSIGN) == 0 && $this->countUsers(CommonITILActor::ASSIGN) == 0 && $this->countGroups(CommonITILActor::ASSIGN) == 0 && !in_array($this->fields['status'], array_merge($this->getSolvedStatusArray(), $this->getClosedStatusArray()))) { if (!in_array('status', $this->updates)) { $this->oldvalues['status'] = $this->fields['status']; $this->updates[] = 'status'; } $this->fields['status'] = self::INCOMING; } if (in_array("status", $this->updates) && in_array($this->input["status"], $this->getSolvedStatusArray())) { $this->updates[] = "solvedate"; $this->oldvalues['solvedate'] = $this->fields["solvedate"]; $this->fields["solvedate"] = $_SESSION["glpi_currenttime"]; // If invalid date : set open date if ($this->fields["solvedate"] < $this->fields["date"]) { $this->fields["solvedate"] = $this->fields["date"]; } } if (in_array("status", $this->updates) && in_array($this->input["status"], $this->getClosedStatusArray())) { $this->updates[] = "closedate"; $this->oldvalues['closedate'] = $this->fields["closedate"]; $this->fields["closedate"] = $_SESSION["glpi_currenttime"]; // If invalid date : set open date if ($this->fields["closedate"] < $this->fields["date"]) { $this->fields["closedate"] = $this->fields["date"]; } // Set solvedate to closedate if (empty($this->fields["solvedate"])) { $this->updates[] = "solvedate"; $this->oldvalues['solvedate'] = $this->fields["solvedate"]; $this->fields["solvedate"] = $this->fields["closedate"]; } } } // check dates // check due_date (SLA) if ((in_array("date", $this->updates) || in_array("due_date", $this->updates)) && !is_null($this->fields["due_date"])) { // Date set if ($this->fields["due_date"] < $this->fields["date"]) { Session::addMessageAfterRedirect(__('Invalid dates. Update cancelled.'), false, ERROR); if (($key = array_search('date', $this->updates)) !== false) { unset($this->updates[$key]); unset($this->oldvalues['date']); } if (($key = array_search('due_date', $this->updates)) !== false) { unset($this->updates[$key]); unset($this->oldvalues['due_date']); } } } // Status close : check dates if (in_array($this->fields["status"], $this->getClosedStatusArray()) && (in_array("date", $this->updates) || in_array("closedate", $this->updates))) { // Invalid dates : no change // closedate must be > solvedate if ($this->fields["closedate"] < $this->fields["solvedate"]) { Session::addMessageAfterRedirect(__('Invalid dates. Update cancelled.'), false, ERROR); if (($key = array_search('closedate', $this->updates)) !== false) { unset($this->updates[$key]); unset($this->oldvalues['closedate']); } } // closedate must be > create date if ($this->fields["closedate"] < $this->fields["date"]) { Session::addMessageAfterRedirect(__('Invalid dates. Update cancelled.'), false, ERROR); if (($key = array_search('date', $this->updates)) !== false) { unset($this->updates[$key]); unset($this->oldvalues['date']); } if (($key = array_search('closedate', $this->updates)) !== false) { unset($this->updates[$key]); unset($this->oldvalues['closedate']); } } } if (($key = array_search('status', $this->updates)) !== false && $this->oldvalues['status'] == $this->fields['status']) { unset($this->updates[$key]); unset($this->oldvalues['status']); } // Status solved : check dates if (in_array($this->fields["status"], $this->getSolvedStatusArray()) && (in_array("date", $this->updates) || in_array("solvedate", $this->updates))) { // Invalid dates : no change // solvedate must be > create date if ($this->fields["solvedate"] < $this->fields["date"]) { Session::addMessageAfterRedirect(__('Invalid dates. Update cancelled.'), false, ERROR); if (($key = array_search('date', $this->updates)) !== false) { unset($this->updates[$key]); unset($this->oldvalues['date']); } if (($key = array_search('solvedate', $this->updates)) !== false) { unset($this->updates[$key]); unset($this->oldvalues['solvedate']); } } } // Manage come back to waiting state if (!is_null($this->fields['begin_waiting_date']) && ($key = array_search('status', $this->updates)) !== false && ($this->oldvalues['status'] == self::WAITING || in_array($this->oldvalues["status"], $this->getSolvedStatusArray()) && !in_array($this->fields["status"], $this->getClosedStatusArray()))) { // Compute ticket waiting time use calendar if exists $calendars_id = Entity::getUsedConfig('calendars_id', $this->fields['entities_id']); $calendar = new Calendar(); $delay_time = 0; // Compute ticket waiting time use calendar if exists // Using calendar if ($calendars_id > 0 && $calendar->getFromDB($calendars_id)) { $delay_time = $calendar->getActiveTimeBetween($this->fields['begin_waiting_date'], $_SESSION["glpi_currenttime"]); } else { // Not calendar defined $delay_time = strtotime($_SESSION["glpi_currenttime"]) - strtotime($this->fields['begin_waiting_date']); } // SLA case : compute sla duration if (isset($this->fields['slas_id']) && $this->fields['slas_id'] > 0) { $sla = new SLA(); if ($sla->getFromDB($this->fields['slas_id'])) { $sla->setTicketCalendar($calendars_id); $delay_time_sla = $sla->getActiveTimeBetween($this->fields['begin_waiting_date'], $_SESSION["glpi_currenttime"]); $this->updates[] = "sla_waiting_duration"; $this->fields["sla_waiting_duration"] += $delay_time_sla; } // Compute new due date $this->updates[] = "due_date"; $this->fields['due_date'] = $sla->computeDueDate($this->fields['date'], $this->fields["sla_waiting_duration"]); // Add current level to do $sla->addLevelToDo($this); } else { // Using calendar if ($calendars_id > 0 && $calendar->getFromDB($calendars_id)) { if ($this->fields['due_date'] > 0) { // compute new due date using calendar $this->updates[] = "due_date"; $this->fields['due_date'] = $calendar->computeEndDate($this->fields['due_date'], $delay_time); } } else { // Not calendar defined if ($this->fields['due_date'] > 0) { // compute new due date : no calendar so add computed delay_time $this->updates[] = "due_date"; $this->fields['due_date'] = date('Y-m-d H:i:s', $delay_time + strtotime($this->fields['due_date'])); } } } $this->updates[] = "waiting_duration"; $this->fields["waiting_duration"] += $delay_time; // Reset begin_waiting_date $this->updates[] = "begin_waiting_date"; $this->fields["begin_waiting_date"] = 'NULL'; } // Set begin waiting date if needed if (($key = array_search('status', $this->updates)) !== false && ($this->fields['status'] == self::WAITING || in_array($this->fields["status"], $this->getSolvedStatusArray()))) { $this->updates[] = "begin_waiting_date"; $this->fields["begin_waiting_date"] = $_SESSION["glpi_currenttime"]; // Specific for tickets if (isset($this->fields['slas_id']) && $this->fields['slas_id'] > 0) { SLA::deleteLevelsToDo($this); } } // solve_delay_stat : use delay between opendate and solvedate if (in_array("solvedate", $this->updates)) { $this->updates[] = "solve_delay_stat"; $this->fields['solve_delay_stat'] = $this->computeSolveDelayStat(); } // close_delay_stat : use delay between opendate and closedate if (in_array("closedate", $this->updates)) { $this->updates[] = "close_delay_stat"; $this->fields['close_delay_stat'] = $this->computeCloseDelayStat(); } // Do not take into account date_mod if no update is done if (count($this->updates) == 1 && ($key = array_search('date_mod', $this->updates)) !== false) { unset($this->updates[$key]); } }
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 SLA Level : add actions if (isset($this->input["slas_id"]) && $this->input["slas_id"] > 0 && isset($this->input["slalevels_id"]) && $this->input["slalevels_id"] > 0) { $calendars_id = Entity::getUsedConfig('calendars_id', $this->fields['entities_id']); $sla = new SLA(); if ($sla->getFromDB($this->input["slas_id"])) { $sla->setTicketCalendar($calendars_id); // Add first level in working table if ($this->input["slalevels_id"] > 0) { $sla->addLevelToDo($this); } // Replay action in case of open date is set before now } SlaLevel_Ticket::replayForTicket($this->getID()); } // 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['itemtype']) && !empty($this->input['items_id'])) { $item_ticket = new Item_Ticket(); $item_ticket->add(array('items_id' => $this->input['items_id'], 'itemtype' => $this->input['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>"))); } }