예제 #1
1
 /**
  * Do a specific SLAlevel for a ticket
  *
  * @param $data array data of an entry of slalevels_tickets
  *
  * @return nothing
  **/
 static function doLevelForTicket(array $data)
 {
     $ticket = new Ticket();
     $slalevelticket = new self();
     // existing ticket and not deleted
     if ($ticket->getFromDB($data['tickets_id']) && !$ticket->isDeleted()) {
         $slalevel = new SlaLevel();
         $sla = new SLA();
         // Check if sla datas are OK
         if ($ticket->fields['slas_id'] > 0 && $ticket->fields['slalevels_id'] == $data['slalevels_id']) {
             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) {
                     // 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) && $sla->getFromDB($ticket->fields['slas_id'])) {
                         $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->getNextSlaLevel($ticket->fields['slas_id'], $ticket->fields['slalevels_id']);
                     $input['slalevels_id'] = $next;
                     $ticket->update($input);
                     $sla->addLevelToDo($ticket);
                     // Action done : drop the 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 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]);
     }
 }
예제 #3
0
 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>")));
     }
 }
예제 #4
0
 function post_addItem()
 {
     global $LANG, $CFG_GLPI;
     // Add document if needed
     $this->addFiles($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"] == "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"]) || isset($this->input["_hour"]) && isset($this->input["_minute"]) && isset($this->input["realtime"]) && $this->input["realtime"] > 0) {
         $task = new TicketTask();
         $type = "new";
         if (isset($this->fields["status"]) && $this->fields["status"] == "solved") {
             $type = "solved";
         }
         $toadd = array("type" => $type, "tickets_id" => $this->fields['id']);
         if (isset($this->input["_hour"])) {
             $toadd["hour"] = $this->input["_hour"];
         }
         if (isset($this->input["_minute"])) {
             $toadd["minute"] = $this->input["_minute"];
         }
         if (isset($this->input["plan"])) {
             $toadd["plan"] = $this->input["plan"];
         }
         $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'];
         if ($ticket_ticket->can(-1, 'w', $this->input['_link'])) {
             $ticket_ticket->add($this->input['_link']);
         }
     }
     // 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) {
         $sla = new SLA();
         if ($sla->getFromDB($this->input["slas_id"])) {
             // Add first level in working table
             if ($this->input["slalevels_id"] > 0) {
                 $sla->addLevelToDo($this);
             }
         }
     }
     // Add user groups linked to tickets
     $ticket_user = new Ticket_User();
     $group_ticket = new Group_Ticket();
     if (isset($this->input["_users_id_requester"]) && ($this->input["_users_id_requester"] > 0 || isset($this->input["_users_id_requester_notif"]['alternative_email']) && !empty($this->input["_users_id_requester_notif"]['alternative_email']))) {
         $input2 = array('tickets_id' => $this->fields['id'], 'users_id' => $this->input["_users_id_requester"], 'type' => self::REQUESTER);
         if (isset($this->input["_users_id_requester_notif"])) {
             foreach ($this->input["_users_id_requester_notif"] as $key => $val) {
                 $input2[$key] = $val;
             }
         }
         $ticket_user->add($input2);
     }
     if (isset($this->input["_users_id_observer"]) && ($this->input["_users_id_observer"] > 0 || isset($this->input["_users_id_observer_notif"]['alternative_email']) && !empty($this->input["_users_id_observer_notif"]['alternative_email']))) {
         $input2 = array('tickets_id' => $this->fields['id'], 'users_id' => $this->input["_users_id_observer"], 'type' => self::OBSERVER);
         if (isset($this->input["_users_id_observer_notif"])) {
             foreach ($this->input["_users_id_observer_notif"] as $key => $val) {
                 $input2[$key] = $val;
             }
         }
         $ticket_user->add($input2);
     }
     if (isset($this->input["_users_id_assign"]) && $this->input["_users_id_assign"] > 0) {
         $input2 = array('tickets_id' => $this->fields['id'], 'users_id' => $this->input["_users_id_assign"], 'type' => self::ASSIGN);
         if (isset($this->input["_users_id_assign_notif"])) {
             foreach ($this->input["_users_id_assign_notif"] as $key => $val) {
                 $input2[$key] = $val;
             }
         }
         $ticket_user->add($input2);
     }
     if (isset($this->input["_groups_id_requester"]) && $this->input["_groups_id_requester"] > 0) {
         $group_ticket->add(array('tickets_id' => $this->fields['id'], 'groups_id' => $this->input["_groups_id_requester"], 'type' => self::REQUESTER));
     }
     if (isset($this->input["_groups_id_assign"]) && $this->input["_groups_id_assign"] > 0) {
         $group_ticket->add(array('tickets_id' => $this->fields['id'], 'groups_id' => $this->input["_groups_id_assign"], 'type' => self::ASSIGN));
     }
     if (isset($this->input["_groups_id_observer"]) && $this->input["_groups_id_observer"] > 0) {
         $group_ticket->add(array('tickets_id' => $this->fields['id'], 'groups_id' => $this->input["_groups_id_observer"], 'type' => self::OBSERVER));
     }
     // Additional actors : using default notification parameters
     // Observers : for mailcollector
     if (isset($this->input["_additional_observers"]) && is_array($this->input["_additional_observers"]) && count($this->input["_additional_observers"])) {
         $input2 = array('tickets_id' => $this->fields['id'], 'type' => self::OBSERVER);
         foreach ($this->input["_additional_observers"] as $tmp) {
             if (isset($tmp['users_id'])) {
                 foreach ($tmp as $key => $val) {
                     $input2[$key] = $val;
                 }
                 $ticket_user->add($input2);
             }
         }
     }
     if (isset($this->input["_additional_assigns"]) && is_array($this->input["_additional_assigns"]) && count($this->input["_additional_assigns"])) {
         $input2 = array('tickets_id' => $this->fields['id'], 'type' => self::ASSIGN);
         foreach ($this->input["_additional_assigns"] as $tmp) {
             if (isset($tmp['users_id'])) {
                 foreach ($tmp as $key => $val) {
                     $input2[$key] = $val;
                 }
                 $ticket_user->add($input2);
             }
         }
     }
     if (isset($this->input["_additional_requesters"]) && is_array($this->input["_additional_requesters"]) && count($this->input["_additional_requesters"])) {
         $input2 = array('tickets_id' => $this->fields['id'], 'type' => self::REQUESTER);
         foreach ($this->input["_additional_requesters"] as $tmp) {
             if (isset($tmp['users_id'])) {
                 foreach ($tmp as $key => $val) {
                     $input2[$key] = $val;
                 }
                 $ticket_user->add($input2);
             }
         }
     }
     //Action for send_validation rule
     if (isset($this->input["_add_validation"]) && $this->input["_add_validation"] > 0) {
         $validation = new Ticketvalidation();
         $values['tickets_id'] = $this->fields['id'];
         $values['users_id_validate'] = $this->input["_add_validation"];
         if ($validation->can(-1, 'w', $values)) {
             $validation->add($values);
             Event::log($this->fields['id'], "ticket", 4, "tracking", $_SESSION["glpiname"] . "  " . $LANG['log'][21]);
         }
     }
     // 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"] == "solved") {
             $type = "solved";
         }
         NotificationEvent::raiseEvent($type, $this);
     }
     if (isset($_SESSION['glpiis_ids_visible']) && !$_SESSION['glpiis_ids_visible']) {
         addMessageAfterRedirect($LANG['help'][18] . " (" . $LANG['job'][38] . "&nbsp;" . "<a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $this->fields['id'] . "'>" . $this->fields['id'] . "</a>)");
     }
 }
예제 #5
0
 /**
  * Do a specific SLAlevel for a ticket
  *
  * @param $data array data of an entry of slalevels_tickets
  *
  * @return nothing
  **/
 static function doLevelForTicket(array $data)
 {
     $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 $groups) {
             $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();
         $sla = new SLA();
         // Check if sla datas are OK
         if ($ticket->fields['slas_id'] > 0 && $ticket->fields['slalevels_id'] == $data['slalevels_id']) {
             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) {
                     // 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) && $sla->getFromDB($ticket->fields['slas_id'])) {
                         $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->getNextSlaLevel($ticket->fields['slas_id'], $ticket->fields['slalevels_id']);
                     $input['slalevels_id'] = $next;
                     $ticket->update($input);
                     $sla->addLevelToDo($ticket);
                     // Action done : drop the 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']));
     }
 }
예제 #6
0
 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>")));
     }
 }
 /**
  * Cron for ticket's automatic close
  * @param $task : crontask object
  *
  * @return integer (0 : nothing done - 1 : done)
  *
  */
 static function cronSlaTicket($task)
 {
     global $DB;
     $tot = 0;
     $query = "SELECT *\n                FROM `glpi_slalevels_tickets`\n                WHERE `glpi_slalevels_tickets`.`date` < NOW()";
     $slalevelticket = new self();
     foreach ($DB->request($query) as $data) {
         $tot++;
         $ticket = new Ticket();
         if ($ticket->getFromDB($data['tickets_id'])) {
             $slalevel = new SlaLevel();
             $sla = new SLA();
             // Check if sla datas are OK
             if ($ticket->fields['slas_id'] > 0 && $ticket->fields['slalevels_id'] == $data['slalevels_id']) {
                 if ($ticket->fields['status'] == 'closed') {
                     // Drop line when status is closed
                     $slalevelticket->delete(array('id' => $data['id']));
                 } else {
                     if ($ticket->fields['status'] != 'solved') {
                         // If status = solved : keep the line in case of solution not validated
                         $input = $ticket->fields;
                         $input['_auto_update'] = true;
                         if ($slalevel->getRuleWithCriteriasAndActions($data['slalevels_id'], 0, 1) && $sla->getFromDB($ticket->fields['slas_id'])) {
                             // Process rules
                             $input = $slalevel->executeActions($input, array());
                         }
                         // Put next level in todo list
                         $next = $slalevel->getNextSlaLevel($ticket->fields['slas_id'], $ticket->fields['slalevels_id']);
                         $input['slalevels_id'] = $next;
                         $ticket->update($input);
                         $sla->addLevelToDo($ticket);
                     }
                 }
             }
         } else {
             // Drop line
             $slalevelticket->delete(array('id' => $data['id']));
         }
     }
     $task->setVolume($tot);
     return $tot > 0;
 }