예제 #1
0
 /**
  * Get Datas to be added for SLA add
  *
  * @param $slas_id      SLA id
  * @param $entities_id  entity ID of the ticket
  * @param $date         begin date of the ticket
  *
  * @return array of datas to add in ticket
  **/
 function getDatasToAddSLA($slas_id, $entities_id, $date)
 {
     $calendars_id = Entity::getUsedConfig('calendars_id', $entities_id);
     $data = array();
     $sla = new SLA();
     if ($sla->getFromDB($slas_id)) {
         $sla->setTicketCalendar($calendars_id);
         // Get first SLA Level
         $data["slalevels_id"] = SlaLevel::getFirstSlaLevel($slas_id);
         // Compute due_date
         $data['due_date'] = $sla->computeDueDate($date);
         $data['sla_waiting_duration'] = 0;
     } else {
         $data["slalevels_id"] = 0;
         $data["slas_id"] = 0;
         $data['sla_waiting_duration'] = 0;
     }
     return $data;
 }
 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 prepareInputForAdd($input)
 {
     global $CFG_GLPI, $LANG;
     // Check mandatory
     $mandatory_ok = true;
     // Do not check mandatory on auto import (mailgates)
     if (!isset($input['_auto_import'])) {
         $_SESSION["helpdeskSaved"] = $input;
         if (!isset($input["urgency"])) {
             addMessageAfterRedirect($LANG['tracking'][4], false, ERROR);
             $mandatory_ok = false;
         }
         if ($CFG_GLPI["is_ticket_content_mandatory"] && (!isset($input['content']) || empty($input['content']))) {
             addMessageAfterRedirect($LANG['tracking'][8], false, ERROR);
             $mandatory_ok = false;
         }
         if ($CFG_GLPI["is_ticket_title_mandatory"] && (!isset($input['name']) || empty($input['name']))) {
             addMessageAfterRedirect($LANG['help'][40], false, ERROR);
             $mandatory_ok = false;
         }
         if ($CFG_GLPI["is_ticket_category_mandatory"] && (!isset($input['ticketcategories_id']) || empty($input['ticketcategories_id']))) {
             addMessageAfterRedirect($LANG['help'][41], false, ERROR);
             $mandatory_ok = false;
         }
         //          if (isset($input['use_email_notification']) && $input['use_email_notification']
         //              && (!isset($input['user_email']) || empty($input['user_email']))) {
         //
         //             addMessageAfterRedirect($LANG['help'][16], false, ERROR);
         //             $mandatory_ok = false;
         //          }
         if (!$mandatory_ok) {
             return false;
         }
     }
     if (!isset($input["urgency"]) || !($CFG_GLPI['urgency_mask'] & 1 << $input["urgency"])) {
         $input["urgency"] = 3;
     }
     if (!isset($input["impact"]) || !($CFG_GLPI['impact_mask'] & 1 << $input["impact"])) {
         $input["impact"] = 3;
     }
     if (!isset($input["priority"])) {
         $input["priority"] = $this->computePriority($input["urgency"], $input["impact"]);
     }
     unset($_SESSION["helpdeskSaved"]);
     // No Auto set Import for external source
     if (!isset($input['_auto_import'])) {
         if (!isset($input["_users_id_requester"])) {
             if ($uid = getLoginUserID()) {
                 $input["_users_id_requester"] = $uid;
             }
         }
     }
     // set last updater
     if ($lastupdater = getLoginUserID(true)) {
         $input['users_id_lastupdater'] = $lastupdater;
     }
     // No Auto set Import for external source
     if (($uid = getLoginUserID()) && !isset($input['_auto_import'])) {
         $input["users_id_recipient"] = $uid;
     } else {
         if (isset($input["_users_id_requester"]) && $input["_users_id_requester"]) {
             $input["users_id_recipient"] = $input["_users_id_requester"];
         }
     }
     if (!isset($input["requesttypes_id"])) {
         $input["requesttypes_id"] = RequestType::getDefault('helpdesk');
     }
     if (!isset($input["status"])) {
         $input["status"] = "new";
     }
     if (!isset($input['global_validation'])) {
         $input['global_validation'] = 'none';
     }
     if (!isset($input["date"]) || empty($input["date"])) {
         $input["date"] = $_SESSION["glpi_currenttime"];
     }
     if (!isset($input["_users_id_assign"])) {
         $input["_users_id_assign"] = 0;
     }
     if (!isset($input["_groups_id_assign"])) {
         $input["_groups_id_assign"] = 0;
     }
     // Set default dropdown
     $dropdown_fields = array('entities_id', 'items_id', 'suppliers_id_assign', 'ticketcategories_id');
     foreach ($dropdown_fields as $field) {
         if (!isset($input[$field])) {
             $input[$field] = 0;
         }
     }
     if (!isset($input['itemtype']) || !($input['items_id'] > 0)) {
         $input['itemtype'] = '';
     }
     $item = NULL;
     if ($input["items_id"] > 0 && !empty($input["itemtype"])) {
         if (class_exists($input["itemtype"])) {
             $item = new $input["itemtype"]();
             if (!$item->getFromDB($input["items_id"])) {
                 $item = NULL;
             }
         }
     }
     // Auto group define from item
     //       if ($item != NULL) {
     //          if ($item->isField('groups_id')
     //              && (!isset($input["_groups_id_requester"]) || $input["_groups_id_requester"]==0)) {
     //             $input["_groups_id_requester"] = $item->getField('groups_id');
     //          }
     //       }
     // Manage auto assign
     $entitydata = new EntityData();
     $auto_assign_mode = $CFG_GLPI['auto_assign_mode'];
     if ($entitydata->getFromDB($input['entities_id'])) {
         $auto_assign_mode = $entitydata->getField('auto_assign_mode');
         // Set global config value
         if ($auto_assign_mode == -1) {
             $auto_assign_mode = $CFG_GLPI['auto_assign_mode'];
         }
     }
     switch ($auto_assign_mode) {
         case NO_AUTO_ASSIGN:
             break;
         case AUTO_ASSIGN_HARDWARE_CATEGORY:
             // Auto assign tech from item
             if ($input["_users_id_assign"] == 0 && $item != NULL) {
                 if ($item->isField('users_id_tech')) {
                     $input["_users_id_assign"] = $item->getField('users_id_tech');
                     if ($input["_users_id_assign"] > 0) {
                         $input["status"] = "assign";
                     }
                 }
             }
             // Auto assign tech/group from Category
             if ($input['ticketcategories_id'] > 0 && (!$input['_users_id_assign'] || !$input['_groups_id_assign'])) {
                 $cat = new TicketCategory();
                 $cat->getFromDB($input['ticketcategories_id']);
                 if (!$input['_users_id_assign'] && $cat->isField('users_id')) {
                     $input['_users_id_assign'] = $cat->getField('users_id');
                 }
                 if (!$input['_groups_id_assign'] && $cat->isField('groups_id')) {
                     $input['_groups_id_assign'] = $cat->getField('groups_id');
                 }
             }
             break;
         case AUTO_ASSIGN_CATEGORY_HARDWARE:
             // Auto assign tech/group from Category
             if ($input['ticketcategories_id'] > 0 && (!$input['_users_id_assign'] || !$input['_groups_id_assign'])) {
                 $cat = new TicketCategory();
                 $cat->getFromDB($input['ticketcategories_id']);
                 if (!$input['_users_id_assign'] && $cat->isField('users_id')) {
                     $input['_users_id_assign'] = $cat->getField('users_id');
                 }
                 if (!$input['_groups_id_assign'] && $cat->isField('groups_id')) {
                     $input['_groups_id_assign'] = $cat->getField('groups_id');
                 }
             }
             // Auto assign tech from item
             if ($input["_users_id_assign"] == 0 && $item != NULL) {
                 if ($item->isField('users_id_tech')) {
                     $input["_users_id_assign"] = $item->getField('users_id_tech');
                     if ($input["_users_id_assign"] > 0) {
                         $input["status"] = "assign";
                     }
                 }
             }
             break;
     }
     // Process Business Rules
     $rules = new RuleTicketCollection($input['entities_id']);
     // Set unset variables with are needed
     $user = new User();
     if (isset($input["_users_id_requester"]) && $user->getFromDB($input["_users_id_requester"])) {
         $input['users_locations'] = $user->fields['locations_id'];
     }
     $input = $rules->processAllRules($input, $input, array('recursive' => true));
     //       if (isset($input["use_email_notification"])
     //           && $input["use_email_notification"]
     //           && empty($input["user_email"])) {
     //
     //          if ($user->getFromDB($input["users_id"])) {
     //             $input["user_email"] = $user->fields["email"];
     //          }
     //       }
     if ((isset($input["_users_id_assign"]) && $input["_users_id_assign"] > 0 || isset($input["_groups_id_assign"]) && $input["_groups_id_assign"] > 0 || isset($input["suppliers_id_assign"]) && $input["suppliers_id_assign"] > 0) && $input["status"] == "new") {
         $input["status"] = "assign";
     }
     if (isset($input["hour"]) && isset($input["minute"])) {
         $input["actiontime"] = $input["hour"] * HOUR_TIMESTAMP + $input["minute"] * MINUTE_TIMESTAMP;
         $input["_hour"] = $input["hour"];
         $input["_minute"] = $input["minute"];
         unset($input["hour"]);
         unset($input["minute"]);
     }
     if (isset($input["status"]) && $input["status"] == "solved") {
         if (isset($input["date"])) {
             $input["solvedate"] = $input["date"];
         } else {
             $input["solvedate"] = $_SESSION["glpi_currenttime"];
         }
     }
     if (isset($input["status"]) && $input["status"] == "closed") {
         if (isset($input["date"])) {
             $input["closedate"] = $input["date"];
         } else {
             $input["closedate"] = $_SESSION["glpi_currenttime"];
         }
         $input['solvedate'] = $input["closedate"];
     }
     // Set begin waiting time if status is waiting
     if (isset($input["status"]) && $input["status"] == "waiting") {
         $input['begin_waiting_date'] = $input['date'];
     }
     // No name set name
     if (empty($input["name"])) {
         $input["name"] = preg_replace('/\\r\\n/', ' ', $input['content']);
         $input["name"] = preg_replace('/\\n/', ' ', $input['name']);
         $input["name"] = utf8_substr($input['name'], 0, 70);
     }
     //// Manage SLA assignment
     // due date defined : no SLA
     if (isset($input["due_date"]) && $input['due_date'] != 'NULL') {
         // Valid due date
         if ($input['due_date'] > $input['date']) {
             if (isset($input["slas_id"])) {
                 unset($input["slas_id"]);
             }
         } else {
             // Unset due date
             unset($input["due_date"]);
         }
     }
     if (isset($input["slas_id"]) && $input["slas_id"] > 0) {
         $sla = new SLA();
         if ($sla->getFromDB($input["slas_id"])) {
             // Get first SLA Level
             $input["slalevels_id"] = SlaLevel::getFirstSlaLevel($input["slas_id"]);
             // Compute due_date
             $input['due_date'] = $sla->computeDueDate($input['date']);
             $input['sla_waiting_duration'] = 0;
         } else {
             $input["slalevels_id"] = 0;
             $input["slas_id"] = 0;
             $input['sla_waiting_duration'] = 0;
         }
     }
     // auto set type if not set
     if (!isset($input["type"])) {
         $input['type'] = EntityData::getUsedConfig('tickettype', $input['entities_id']);
     }
     return $input;
 }