Exemple #1
0
 function prepareInputForUpdate($input)
 {
     global $CFG_GLPI;
     // Get ticket : need for comparison
     $this->getFromDB($input['id']);
     // automatic recalculate if user changes urgence or technician change impact
     if (isset($input['urgency']) && isset($input['impact']) && ($input['urgency'] != $this->fields['urgency'] || $input['impact'] != $this->fields['impact']) && !isset($input['priority'])) {
         $input['priority'] = self::computePriority($input['urgency'], $input['impact']);
     }
     // Security checks
     if (!Session::isCron() && !Session::haveRight("assign_ticket", "1")) {
         if (isset($input["_itil_assign"]) && isset($input['_itil_assign']['_type']) && $input['_itil_assign']['_type'] == 'user') {
             // must own_ticket to grab a non assign ticket
             if ($this->countUsers(CommonITILActor::ASSIGN) == 0) {
                 if (!Session::haveRight("steal_ticket", "1") && !Session::haveRight("own_ticket", "1") || !isset($input["_itil_assign"]['users_id']) || $input["_itil_assign"]['users_id'] != Session::getLoginUserID()) {
                     unset($input["_itil_assign"]);
                 }
             } else {
                 // Can not steal or can steal and not assign to me
                 if (!Session::haveRight("steal_ticket", "1") || !isset($input["_itil_assign"]['users_id']) || $input["_itil_assign"]['users_id'] != Session::getLoginUserID()) {
                     unset($input["_itil_assign"]);
                 }
             }
         }
         // No supplier assign
         if (isset($input["_itil_assign"]) && isset($input['_itil_assign']['_type']) && $input['_itil_assign']['_type'] == 'supplier') {
             unset($input["_itil_assign"]);
         }
         // No group
         if (isset($input["_itil_assign"]) && isset($input['_itil_assign']['_type']) && $input['_itil_assign']['_type'] == 'group') {
             unset($input["_itil_assign"]);
         }
     }
     $check_allowed_fields_for_template = false;
     if (!Session::isCron() && !Session::haveRight("update_ticket", "1")) {
         $allowed_fields = array('id');
         $check_allowed_fields_for_template = true;
         if ($this->canApprove() && isset($input["status"])) {
             $allowed_fields[] = 'status';
         }
         // for post-only with validate right or validation created by rules
         if (TicketValidation::canValidate($this->fields['id']) || TicketValidation::canCreate() || isset($input["_rule_process"])) {
             $allowed_fields[] = 'global_validation';
         }
         // Manage assign and steal right
         if (Session::haveRight('assign_ticket', 1) || Session::haveRight('steal_ticket', 1)) {
             $allowed_fields[] = '_itil_assign';
         }
         // Can only update initial fields if no followup or task already added
         if ($this->numberOfFollowups() == 0 && $this->numberOfTasks() == 0 && $this->isUser(CommonITILActor::REQUESTER, Session::getLoginUserID())) {
             $allowed_fields[] = 'content';
             $allowed_fields[] = 'urgency';
             $allowed_fields[] = 'priority';
             // automatic recalculate if user changes urgence
             $allowed_fields[] = 'itilcategories_id';
             $allowed_fields[] = 'itemtype';
             $allowed_fields[] = 'items_id';
             $allowed_fields[] = 'name';
         }
         if ($this->canSolve()) {
             $allowed_fields[] = 'solutiontypes_id';
             $allowed_fields[] = 'solution';
         }
         foreach ($allowed_fields as $field) {
             if (isset($input[$field])) {
                 $ret[$field] = $input[$field];
             }
         }
         $input = $ret;
     }
     //// check mandatory fields
     // First get ticket template associated : entity and type/category
     if (isset($input['entities_id'])) {
         $entid = $input['entities_id'];
     } else {
         $entid = $this->fields['entities_id'];
     }
     if (isset($input['type'])) {
         $type = $input['type'];
     } else {
         $type = $this->fields['type'];
     }
     if (isset($input['itilcategories_id'])) {
         $categid = $input['itilcategories_id'];
     } else {
         $categid = $this->fields['itilcategories_id'];
     }
     $tt = $this->getTicketTemplateToUse(0, $type, $categid, $entid);
     if (count($tt->mandatory)) {
         $mandatory_missing = array();
         $fieldsname = $tt->getAllowedFieldsNames(true);
         foreach ($tt->mandatory as $key => $val) {
             if ((!$check_allowed_fields_for_template || in_array($key, $allowed_fields)) && (isset($input[$key]) && (empty($input[$key]) || $input[$key] == 'NULL') && !empty($this->fields[$key]))) {
                 $mandatory_missing[$key] = $fieldsname[$val];
             }
         }
         if (count($mandatory_missing)) {
             //TRANS: %s are the fields concerned
             $message = sprintf(__('Mandatory fields are not filled. Please correct: %s'), implode(", ", $mandatory_missing));
             Session::addMessageAfterRedirect($message, false, ERROR);
             return false;
         }
     }
     // Manage fields from auto update : map rule actions to standard ones
     if (isset($input['_auto_update'])) {
         if (isset($input['_users_id_assign'])) {
             $input['_itil_assign']['_type'] = 'user';
             $input['_itil_assign']['users_id'] = $input['_users_id_assign'];
         }
         if (isset($input['_groups_id_assign'])) {
             $input['_itil_assign']['_type'] = 'group';
             $input['_itil_assign']['groups_id'] = $input['_groups_id_assign'];
         }
         if (isset($input['_suppliers_id_assign'])) {
             $input['_itil_assign']['_type'] = 'supplier';
             $input['_itil_assign']['suppliers_id'] = $input['_suppliers_id_assign'];
         }
         if (isset($input['_users_id_requester'])) {
             $input['_itil_requester']['_type'] = 'user';
             $input['_itil_requester']['users_id'] = $input['_users_id_requester'];
         }
         if (isset($input['_groups_id_requester'])) {
             $input['_itil_requester']['_type'] = 'group';
             $input['_itil_requester']['groups_id'] = $input['_groups_id_requester'];
         }
         if (isset($input['_users_id_observer'])) {
             $input['_itil_observer']['_type'] = 'user';
             $input['_itil_observer']['users_id'] = $input['_users_id_observer'];
         }
         if (isset($input['_groups_id_observer'])) {
             $input['_itil_observer']['_type'] = 'group';
             $input['_itil_observer']['groups_id'] = $input['_groups_id_observer'];
         }
     }
     if (isset($input['_link'])) {
         $ticket_ticket = new Ticket_Ticket();
         if (!empty($input['_link']['tickets_id_2'])) {
             if ($ticket_ticket->can(-1, 'w', $input['_link'])) {
                 if ($ticket_ticket->add($input['_link'])) {
                     $input['_forcenotif'] = true;
                 }
             } else {
                 Session::addMessageAfterRedirect(__('Unknown ticket'), false, ERROR);
             }
         }
     }
     if (isset($input["items_id"]) && $input["items_id"] >= 0 && isset($input["itemtype"])) {
         if (isset($this->fields['groups_id']) && $this->fields['groups_id'] == 0 && (!isset($input['groups_id']) || $input['groups_id'] == 0)) {
             if ($input["itemtype"] && ($item = getItemForItemtype($input["itemtype"]))) {
                 $item->getFromDB($input["items_id"]);
                 if ($item->isField('groups_id')) {
                     $input["groups_id"] = $item->getField('groups_id');
                 }
             }
         }
     } else {
         if (isset($input["itemtype"]) && empty($input["itemtype"])) {
             $input["items_id"] = 0;
         } else {
             unset($input["items_id"]);
             unset($input["itemtype"]);
         }
     }
     //Action for send_validation rule
     if (isset($this->input["_add_validation"]) && $this->input["_add_validation"] > 0) {
         $validation = new TicketValidation();
         // if auto_update, tranfert it for validation
         if (isset($this->input['_auto_update'])) {
             $values['_auto_update'] = $this->input['_auto_update'];
         }
         $values['tickets_id'] = $this->input['id'];
         $values['users_id_validate'] = $this->input["_add_validation"];
         if (Session::isCron() || $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'), is_numeric(Session::getLoginUserID(false)) ? $_SESSION["glpiname"] : 'cron', $this->fields['id']));
         }
     }
     if (isset($this->input["slas_id"]) && $this->input["slas_id"] > 0 && $this->fields['slas_id'] == 0) {
         $date = $this->fields['date'];
         /// Use updated date if also done
         if (isset($this->input["date"])) {
             $date = $this->input["date"];
         }
         // Get datas to initialize SLA and set it
         $sla_data = $this->getDatasToAddSLA($this->input["slas_id"], $this->fields['entities_id'], $date);
         if (count($sla_data)) {
             foreach ($sla_data as $key => $val) {
                 $input[$key] = $val;
             }
         }
     }
     $input = parent::prepareInputForUpdate($input);
     return $input;
 }
Exemple #2
0
 function prepareInputForUpdate($input)
 {
     global $CFG_GLPI, $DB;
     // Get ticket : need for comparison
     $this->getFromDB($input['id']);
     // Clean new lines before passing to rules
     if ($CFG_GLPI["use_rich_text"] && isset($input["content"])) {
         $input["content"] = preg_replace('/\\\\r\\\\n/', "\n", $input['content']);
         $input["content"] = preg_replace('/\\\\n/', "\n", $input['content']);
     }
     // automatic recalculate if user changes urgence or technician change impact
     if (isset($input['urgency']) && isset($input['impact']) && ($input['urgency'] != $this->fields['urgency'] || $input['impact'] != $this->fields['impact']) && !isset($input['priority'])) {
         $input['priority'] = self::computePriority($input['urgency'], $input['impact']);
     }
     // Security checks
     if (!Session::isCron() && !Session::haveRight(self::$rightname, self::ASSIGN)) {
         if (isset($input["_itil_assign"]) && isset($input['_itil_assign']['_type']) && $input['_itil_assign']['_type'] == 'user') {
             // must own_ticket to grab a non assign ticket
             if ($this->countUsers(CommonITILActor::ASSIGN) == 0) {
                 if (!Session::haveRightsOr(self::$rightname, array(self::STEAL, self::OWN)) || !isset($input["_itil_assign"]['users_id']) || $input["_itil_assign"]['users_id'] != Session::getLoginUserID()) {
                     unset($input["_itil_assign"]);
                 }
             } else {
                 // Can not steal or can steal and not assign to me
                 if (!Session::haveRight(self::$rightname, self::STEAL) || !isset($input["_itil_assign"]['users_id']) || $input["_itil_assign"]['users_id'] != Session::getLoginUserID()) {
                     unset($input["_itil_assign"]);
                 }
             }
         }
         // No supplier assign
         if (isset($input["_itil_assign"]) && isset($input['_itil_assign']['_type']) && $input['_itil_assign']['_type'] == 'supplier') {
             unset($input["_itil_assign"]);
         }
         // No group
         if (isset($input["_itil_assign"]) && isset($input['_itil_assign']['_type']) && $input['_itil_assign']['_type'] == 'group') {
             unset($input["_itil_assign"]);
         }
     }
     $check_allowed_fields_for_template = false;
     $allowed_fields = array();
     if (!Session::isCron() && (!Session::haveRight(self::$rightname, UPDATE) || in_array($this->fields['status'], $this->getClosedStatusArray()))) {
         $allowed_fields = array('id');
         $check_allowed_fields_for_template = true;
         if (in_array($this->fields['status'], $this->getClosedStatusArray())) {
             $allowed_fields[] = 'status';
             // probably transfer
             $allowed_fields[] = 'entities_id';
         } else {
             if ($this->canApprove() && isset($input["status"])) {
                 $allowed_fields[] = 'status';
             }
             // for post-only with validate right or validation created by rules
             if (TicketValidation::canValidate($this->fields['id']) || TicketValidation::canCreate() || isset($input["_rule_process"])) {
                 $allowed_fields[] = 'global_validation';
             }
             // Manage assign and steal right
             if (Session::haveRightsOr(self::$rightname, array(self::ASSIGN, self::STEAL))) {
                 $allowed_fields[] = '_itil_assign';
             }
             // Can only update initial fields if no followup or task already added
             if ($this->numberOfFollowups() == 0 && $this->numberOfTasks() == 0 && $this->isUser(CommonITILActor::REQUESTER, Session::getLoginUserID())) {
                 $allowed_fields[] = 'content';
                 $allowed_fields[] = 'urgency';
                 $allowed_fields[] = 'priority';
                 // automatic recalculate if user changes urgence
                 $allowed_fields[] = 'itilcategories_id';
                 $allowed_fields[] = 'name';
             }
             if ($this->canSolve()) {
                 $allowed_fields[] = 'solutiontypes_id';
                 $allowed_fields[] = 'solution';
             }
         }
         foreach ($allowed_fields as $field) {
             if (isset($input[$field])) {
                 $ret[$field] = $input[$field];
             }
         }
         $input = $ret;
         // Only ID return false
         if (count($input) == 1) {
             return false;
         }
     }
     //// check mandatory fields
     // First get ticket template associated : entity and type/category
     if (isset($input['entities_id'])) {
         $entid = $input['entities_id'];
     } else {
         $entid = $this->fields['entities_id'];
     }
     if (isset($input['type'])) {
         $type = $input['type'];
     } else {
         $type = $this->fields['type'];
     }
     if (isset($input['itilcategories_id'])) {
         $categid = $input['itilcategories_id'];
     } else {
         $categid = $this->fields['itilcategories_id'];
     }
     $tt = $this->getTicketTemplateToUse(0, $type, $categid, $entid);
     if (count($tt->mandatory)) {
         $mandatory_missing = array();
         $fieldsname = $tt->getAllowedFieldsNames(true);
         foreach ($tt->mandatory as $key => $val) {
             if ((!$check_allowed_fields_for_template || in_array($key, $allowed_fields)) && (isset($input[$key]) && (empty($input[$key]) || $input[$key] == 'NULL') && !empty($this->fields[$key]))) {
                 $mandatory_missing[$key] = $fieldsname[$val];
             }
         }
         if (count($mandatory_missing)) {
             //TRANS: %s are the fields concerned
             $message = sprintf(__('Mandatory fields are not filled. Please correct: %s'), implode(", ", $mandatory_missing));
             Session::addMessageAfterRedirect($message, false, ERROR);
             return false;
         }
     }
     /// Process Business Rules
     // Add actors on standard input
     $rules = new RuleTicketCollection($entid);
     $rule = $rules->getRuleClass();
     $changes = array();
     $tocleanafterrules = array();
     $usertypes = array('assign', 'requester', 'observer');
     foreach ($usertypes as $t) {
         if (isset($input['_itil_' . $t]) && isset($input['_itil_' . $t]['_type'])) {
             $field = $input['_itil_' . $t]['_type'] . 's_id';
             if (isset($input['_itil_' . $t][$field]) && !isset($input[$field . '_' . $t])) {
                 $input['_' . $field . '_' . $t] = $input['_itil_' . $t][$field];
                 $tocleanafterrules['_' . $field . '_' . $t] = $input['_itil_' . $t][$field];
             }
         }
     }
     foreach ($rule->getCriterias() as $key => $val) {
         if (array_key_exists($key, $input)) {
             if (!isset($this->fields[$key]) || $DB->escape($this->fields[$key]) != $input[$key]) {
                 $changes[] = $key;
             }
         }
     }
     // Business Rules do not override manual SLT
     $manual_slts_id = array();
     foreach (array(SLT::TTR, SLT::TTO) as $sltType) {
         list($dateField, $sltField) = SLT::getSltFieldNames($sltType);
         if (isset($input[$sltField]) && $input[$sltField] > 0) {
             $manual_slts_id[$sltType] = $input[$sltField];
         }
     }
     // Only process rules on changes
     if (count($changes)) {
         if (in_array('_users_id_requester', $changes)) {
             // If _users_id_requester changed : set users_locations
             $user = new User();
             if (isset($input["_users_id_requester"]) && $user->getFromDB($input["_users_id_requester"])) {
                 $input['users_locations'] = $user->fields['locations_id'];
                 $changes[] = 'users_locations';
             }
             // If _users_id_requester changed : add _groups_id_of_requester to changes
             $changes[] = '_groups_id_of_requester';
         }
         $input = $rules->processAllRules(Toolbox::stripslashes_deep($input), Toolbox::stripslashes_deep($input), array('recursive' => true, 'entities_id' => $entid), array('condition' => RuleTicket::ONUPDATE, 'only_criteria' => $changes));
     }
     //Action for send_validation rule : do validation before clean
     $this->manageValidationAdd($input);
     // Clean actors fields added for rules
     foreach ($tocleanafterrules as $key => $val) {
         if ($input[$key] == $val) {
             unset($input[$key]);
         }
     }
     // Manage fields from auto update or rules : map rule actions to standard additional ones
     $usertypes = array('assign', 'requester', 'observer');
     $actortypes = array('user', 'group', 'supplier');
     foreach ($usertypes as $t) {
         foreach ($actortypes as $a) {
             if (isset($input['_' . $a . 's_id_' . $t])) {
                 switch ($a) {
                     case 'user':
                         $additionalfield = '_additional_' . $t . 's';
                         $input[$additionalfield][] = array('users_id' => $input['_' . $a . 's_id_' . $t]);
                         break;
                     default:
                         $additionalfield = '_additional_' . $a . 's_' . $t . 's';
                         $input[$additionalfield][] = $input['_' . $a . 's_id_' . $t];
                         break;
                 }
             }
         }
     }
     if (isset($input['_link'])) {
         $ticket_ticket = new Ticket_Ticket();
         if (!empty($input['_link']['tickets_id_2'])) {
             if ($ticket_ticket->can(-1, CREATE, $input['_link'])) {
                 if ($ticket_ticket->add($input['_link'])) {
                     $input['_forcenotif'] = true;
                 }
             } else {
                 Session::addMessageAfterRedirect(__('Unknown ticket'), false, ERROR);
             }
         }
     }
     // SLT affect by rules : reset due_date
     // Manual SLT defined : reset due date
     // No manual SLT and due date defined : reset auto SLT
     foreach (array(SLT::TTR, SLT::TTO) as $sltType) {
         $this->sltAffect($sltType, $input, $manual_slts_id);
     }
     if (isset($input['content'])) {
         if (isset($input['_stock_image'])) {
             $this->addImagePaste();
             $input['content'] = $input['content'];
             $input['_disablenotif'] = true;
         } else {
             if ($CFG_GLPI["use_rich_text"]) {
                 $input['content'] = $this->convertTagToImage($input['content']);
                 if (!isset($input['_filename'])) {
                     $input['_donotadddocs'] = true;
                 }
             }
         }
     }
     $input = parent::prepareInputForUpdate($input);
     return $input;
 }
 function prepareInputForUpdate($input)
 {
     global $LANG, $CFG_GLPI;
     // Get ticket : need for comparison
     $this->getFromDB($input['id']);
     if (isset($input["date"]) && empty($input["date"])) {
         unset($input["date"]);
     }
     if (isset($input["closedate"]) && empty($input["closedate"])) {
         unset($input["closedate"]);
     }
     if (isset($input["solvedate"]) && empty($input["solvedate"])) {
         unset($input["solvedate"]);
     }
     // check mandatory fields
     if ($CFG_GLPI["is_ticket_title_mandatory"] && isset($input['name'])) {
         $title = trim($input['name']);
         if (empty($title)) {
             addMessageAfterRedirect($LANG['tracking'][6], false, ERROR);
             unset($input['name']);
         }
     }
     if ($CFG_GLPI["is_ticket_content_mandatory"] && isset($input['content'])) {
         $content = trim($input['content']);
         if (empty($content)) {
             addMessageAfterRedirect($LANG['tracking'][7], false, ERROR);
             unset($input['content']);
         }
     }
     // Security checks
     if (is_numeric(getLoginUserID(false)) && !haveRight("assign_ticket", "1")) {
         if (isset($input["_ticket_assign"]) && isset($input['_ticket_assign']['_type']) && $input['_ticket_assign']['_type'] == 'user') {
             // must own_ticket to grab a non assign ticket
             if ($this->countUsers(self::ASSIGN) == 0) {
                 if (!haveRight("steal_ticket", "1") && !haveRight("own_ticket", "1") || !isset($input["_ticket_assign"]['users_id']) || $input["_ticket_assign"]['users_id'] != getLoginUserID()) {
                     unset($input["_ticket_assign"]);
                 }
             } else {
                 // Can not steal or can steal and not assign to me
                 if (!haveRight("steal_ticket", "1") || !isset($input["_ticket_assign"]['users_id']) || $input["_ticket_assign"]['users_id'] != getLoginUserID()) {
                     unset($input["_ticket_assign"]);
                 }
             }
         }
         // No supplier assign
         if (isset($input["suppliers_id_assign"])) {
             unset($input["suppliers_id_assign"]);
         }
         // No group
         if (isset($input["_ticket_assign"]) && isset($input['_ticket_assign']['_type']) && $input['_ticket_assign']['_type'] == 'group') {
             unset($input["_ticket_assign"]);
         }
     }
     if (is_numeric(getLoginUserID(false)) && !haveRight("update_ticket", "1")) {
         $allowed_fields = array('id');
         if ($this->canApprove() && isset($input["status"])) {
             $allowed_fields[] = 'status';
         }
         // for post-only with validate right
         $ticketval = new TicketValidation();
         if (TicketValidation::canValidate($this->fields['id']) || $ticketval->canCreate()) {
             $allowed_fields[] = 'global_validation';
         }
         // Manage assign and steal right
         if (haveRight('assign_ticket', 1) || haveRight('steal_ticket', 1)) {
             $allowed_fields[] = '_ticket_assign';
         }
         if (haveRight('assign_ticket', 1)) {
             $allowed_fields[] = 'suppliers_id_assign';
         }
         // Can only update initial fields if no followup or task already added
         if ($this->numberOfFollowups() == 0 && $this->numberOfTasks() == 0 && $this->isUser(self::REQUESTER, getLoginUserID())) {
             $allowed_fields[] = 'content';
             $allowed_fields[] = 'urgency';
             $allowed_fields[] = 'ticketcategories_id';
             $allowed_fields[] = 'itemtype';
             $allowed_fields[] = 'items_id';
             $allowed_fields[] = 'name';
         }
         if ($this->canSolve()) {
             $allowed_fields[] = 'ticketsolutiontypes_id';
             $allowed_fields[] = 'solution';
         }
         foreach ($allowed_fields as $field) {
             if (isset($input[$field])) {
                 $ret[$field] = $input[$field];
             }
         }
         $input = $ret;
     }
     // Manage fields from auto update : map rule actions to standard ones
     if (isset($input['_auto_update'])) {
         if (isset($input['_users_id_assign'])) {
             $input['_ticket_assign']['_type'] = 'user';
             $input['_ticket_assign']['users_id'] = $input['_users_id_assign'];
         }
         if (isset($input['_groups_id_assign'])) {
             $input['_ticket_assign']['_type'] = 'group';
             $input['_ticket_assign']['groups_id'] = $input['_groups_id_assign'];
         }
         if (isset($input['_users_id_requester'])) {
             $input['_ticket_requester']['_type'] = 'user';
             $input['_ticket_requester']['users_id'] = $input['_users_id_requester'];
         }
         if (isset($input['_groups_id_requester'])) {
             $input['_ticket_requester']['_type'] = 'group';
             $input['_ticket_requester']['groups_id'] = $input['_groups_id_requester'];
         }
         if (isset($input['_users_id_observer'])) {
             $input['_ticket_observer']['_type'] = 'user';
             $input['_ticket_observer']['users_id'] = $input['_users_id_observer'];
         }
         if (isset($input['_groups_id_observer'])) {
             $input['_ticket_observer']['_type'] = 'group';
             $input['_ticket_observer']['groups_id'] = $input['_groups_id_observer'];
         }
     }
     if (isset($input['_link'])) {
         $ticket_ticket = new Ticket_Ticket();
         if (!empty($input['_link']['tickets_id_2']) && $ticket_ticket->can(-1, 'w', $input['_link'])) {
             if ($ticket_ticket->add($input['_link'])) {
                 $input['_forcenotif'] = true;
             }
         }
     }
     if (isset($input['_ticket_requester'])) {
         if (isset($input['_ticket_requester']['_type'])) {
             $input['_ticket_requester']['type'] = self::REQUESTER;
             $input['_ticket_requester']['tickets_id'] = $input['id'];
             switch ($input['_ticket_requester']['_type']) {
                 case "user":
                     if (isset($input['_ticket_requester']['alternative_email']) && $input['_ticket_requester']['alternative_email'] && !NotificationMail::isUserAddressValid($input['_ticket_requester']['alternative_email'])) {
                         addMessageAfterRedirect($LANG['mailing'][111] . ' : ' . $LANG['mailing'][110], false, ERROR);
                         $input['_ticket_requester']['alternative_email'] = '';
                     }
                     if (isset($input['_ticket_requester']['alternative_email']) && $input['_ticket_requester']['alternative_email'] || $input['_ticket_requester']['users_id'] > 0) {
                         $ticket_user = new Ticket_User();
                         if ($ticket_user->can(-1, 'w', $input['_ticket_requester'])) {
                             $ticket_user->add($input['_ticket_requester']);
                             $input['_forcenotif'] = true;
                         }
                     }
                     break;
                 case "group":
                     $group_ticket = new Group_Ticket();
                     if ($group_ticket->can(-1, 'w', $input['_ticket_requester'])) {
                         $group_ticket->add($input['_ticket_requester']);
                         $input['_forcenotif'] = true;
                     }
                     break;
             }
         }
     }
     if (isset($input['_ticket_observer'])) {
         if (isset($input['_ticket_observer']['_type'])) {
             $input['_ticket_observer']['type'] = self::OBSERVER;
             $input['_ticket_observer']['tickets_id'] = $input['id'];
             switch ($input['_ticket_observer']['_type']) {
                 case "user":
                     if (isset($input['_ticket_observer']['alternative_email']) && $input['_ticket_observer']['alternative_email'] && !NotificationMail::isUserAddressValid($input['_ticket_observer']['alternative_email'])) {
                         $input['_ticket_observer']['alternative_email'] = '';
                         addMessageAfterRedirect($LANG['mailing'][111] . ' : ' . $LANG['mailing'][110], false, ERROR);
                     }
                     if (isset($input['_ticket_observer']['alternative_email']) && $input['_ticket_observer']['alternative_email'] || $input['_ticket_observer']['users_id'] > 0) {
                         $ticket_user = new Ticket_User();
                         if ($ticket_user->can(-1, 'w', $input['_ticket_observer'])) {
                             $ticket_user->add($input['_ticket_observer']);
                             $input['_forcenotif'] = true;
                         }
                     }
                     break;
                 case "group":
                     $group_ticket = new Group_Ticket();
                     if ($group_ticket->can(-1, 'w', $input['_ticket_observer'])) {
                         $group_ticket->add($input['_ticket_observer']);
                         $input['_forcenotif'] = true;
                     }
                     break;
             }
         }
     }
     if (isset($input['_ticket_assign'])) {
         if (isset($input['_ticket_assign']['_type'])) {
             $input['_ticket_assign']['type'] = self::ASSIGN;
             $input['_ticket_assign']['tickets_id'] = $input['id'];
             switch ($input['_ticket_assign']['_type']) {
                 case "user":
                     $ticket_user = new Ticket_User();
                     if ($ticket_user->can(-1, 'w', $input['_ticket_assign'])) {
                         $ticket_user->add($input['_ticket_assign']);
                         $input['_forcenotif'] = true;
                         if (!isset($input['status']) && $this->fields['status'] == 'new' || isset($input['status']) && $input['status'] == 'new') {
                             $input['status'] = 'assign';
                         }
                     }
                     break;
                 case "group":
                     $group_ticket = new Group_Ticket();
                     if ($group_ticket->can(-1, 'w', $input['_ticket_assign'])) {
                         $group_ticket->add($input['_ticket_assign']);
                         $input['_forcenotif'] = true;
                         if (!isset($input['status']) && $this->fields['status'] == 'new' || isset($input['status']) && $input['status'] == 'new') {
                             $input['status'] = 'assign';
                         }
                     }
                     break;
             }
         }
     }
     // set last updater when non auto update
     if (!isset($input['_auto_update']) && ($lastupdater = getLoginUserID(true))) {
         $input['users_id_lastupdater'] = $lastupdater;
     }
     if (isset($input["items_id"]) && $input["items_id"] >= 0 && isset($input["itemtype"])) {
         if (isset($this->fields['groups_id']) && $this->fields['groups_id'] == 0 && (!isset($input['groups_id']) || $input['groups_id'] == 0)) {
             if ($input["itemtype"] && class_exists($input["itemtype"])) {
                 $item = new $input["itemtype"]();
                 $item->getFromDB($input["items_id"]);
                 if ($item->isField('groups_id')) {
                     $input["groups_id"] = $item->getField('groups_id');
                 }
             }
         }
     } else {
         if (isset($input["itemtype"]) && empty($input["itemtype"])) {
             $input["items_id"] = 0;
         } else {
             unset($input["items_id"]);
             unset($input["itemtype"]);
         }
     }
     // Add document if needed
     $this->getFromDB($input["id"]);
     // entities_id field required
     if (!isset($input['_donotadddocs']) || !$input['_donotadddocs']) {
         $docadded = $this->addFiles($input["id"]);
     }
     /*
     if (count($docadded)>0) {
        $input["date_mod"]=$_SESSION["glpi_currenttime"];
        if ($CFG_GLPI["add_followup_on_update_ticket"]) {
           $input['_doc_added']=$docadded;
        }
     }
     */
     if (isset($input["document"]) && $input["document"] > 0) {
         $doc = new Document();
         if ($doc->getFromDB($input["document"])) {
             $docitem = new Document_Item();
             if ($docitem->add(array('documents_id' => $input["document"], 'itemtype' => $this->getType(), 'items_id' => $input["id"]))) {
                 // Force date_mod of tracking
                 $input["date_mod"] = $_SESSION["glpi_currenttime"];
                 $input['_doc_added'][] = $doc->fields["name"];
             }
         }
         unset($input["document"]);
     }
     //Action for send_validation rule
     if (isset($input["_add_validation"]) && $input["_add_validation"] > 0) {
         $validation = new Ticketvalidation();
         $values['tickets_id'] = $input['id'];
         $values['users_id_validate'] = $input["_add_validation"];
         if (isset($input["_auto_update"])) {
             $values['_auto_update'] = true;
         }
         if ($validation->can(-1, 'w', $values)) {
             $validation->add($values);
             Event::log($this->fields['id'], "ticket", 4, "tracking", $_SESSION["glpiname"] . "  " . $LANG['log'][21]);
         }
     }
     if (isset($input["status"]) && $input["status"] != 'solved' && $input["status"] != 'closed') {
         $input['solvedate'] = 'NULL';
     }
     if (isset($input["status"]) && $input["status"] != 'closed') {
         $input['closedate'] = 'NULL';
     }
     return $input;
 }