prepareInputForAdd() public method

public prepareInputForAdd ( $input )
Ejemplo n.º 1
0
 function prepareInputForAdd($input)
 {
     global $CFG_GLPI;
     // save value before clean;
     $title = ltrim($input['name']);
     // Standard clean datas
     $input = parent::prepareInputForAdd($input);
     // Do not check mandatory on auto import (mailgates)
     if (!isset($input['_auto_import'])) {
         if (isset($input['_tickettemplates_id']) && $input['_tickettemplates_id']) {
             $tt = new TicketTemplate();
             if ($tt->getFromDBWithDatas($input['_tickettemplates_id'])) {
                 if (count($tt->mandatory)) {
                     $mandatory_missing = array();
                     $fieldsname = $tt->getAllowedFieldsNames(true);
                     foreach ($tt->mandatory as $key => $val) {
                         // for title if mandatory (restore initial value)
                         if ($key == 'name') {
                             $input['name'] = $title;
                         }
                         // Check only defined values : Not defined not in form
                         if (isset($input[$key])) {
                             // If content is also predefined need to be different from predefined value
                             if ($key == 'content' && isset($tt->predefined['content'])) {
                                 // Clean new lines to be fix encoding
                                 if (strcmp(preg_replace("/\r?\n/", "", Html::cleanPostForTextArea($input[$key])), preg_replace("/\r?\n/", "", $tt->predefined['content'])) == 0) {
                                     $mandatory_missing[$key] = $fieldsname[$val];
                                 }
                             }
                             if (empty($input[$key]) || $input[$key] == 'NULL' || is_array($input[$key]) && $input[$key] === array(0 => "0")) {
                                 $mandatory_missing[$key] = $fieldsname[$val];
                             }
                         }
                         if ($key == '_add_validation' && !empty($input['users_id_validate']) && isset($input['users_id_validate'][0]) && $input['users_id_validate'][0] > 0) {
                             unset($mandatory_missing['_add_validation']);
                         }
                         // For due_date and time_to_own : check also slts
                         foreach (array(SLT::TTR, SLT::TTO) as $sltType) {
                             list($dateField, $sltField) = SLT::getSltFieldNames($sltType);
                             if ($key == $dateField && isset($input[$sltField]) && $input[$sltField] > 0 && isset($mandatory_missing[$dateField])) {
                                 unset($mandatory_missing[$dateField]);
                             }
                         }
                         // For document mandatory
                         if ($key == '_documents_id' && !isset($input['_filename']) && !isset($input['_tag_filename']) && !isset($input['_stock_image']) && !isset($input['_tag_stock_image'])) {
                             $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;
                     }
                 }
             }
         }
     }
     if (!isset($input["requesttypes_id"])) {
         $input["requesttypes_id"] = RequestType::getDefault('helpdesk');
     }
     if (!isset($input['global_validation'])) {
         $input['global_validation'] = CommonITILValidation::NONE;
     }
     // Set additional default dropdown
     $dropdown_fields = array('users_locations', 'items_locations');
     foreach ($dropdown_fields as $field) {
         if (!isset($input[$field])) {
             $input[$field] = 0;
         }
     }
     if (!isset($input['itemtype']) || !isset($input['items_id']) || !($input['items_id'] > 0)) {
         $input['itemtype'] = '';
     }
     // Get first item location
     $item = NULL;
     if (isset($input["items_id"]) && is_array($input["items_id"]) && count($input["items_id"]) > 0) {
         foreach ($input["items_id"] as $itemtype => $items) {
             foreach ($items as $items_id) {
                 if ($item = getItemForItemtype($itemtype)) {
                     $item->getFromDB($items_id);
                     $input['items_locations'] = $item->fields['locations_id'];
                     $input['items_groups'] = $item->fields['groups_id'];
                     break 2;
                 }
             }
         }
     }
     // 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];
         }
     }
     // Process Business Rules
     $rules = new RuleTicketCollection($input['entities_id']);
     // Set unset variables with are needed
     $user = new User();
     if (isset($input["_users_id_requester"]) && !is_array($input["_users_id_requester"]) && $user->getFromDB($input["_users_id_requester"])) {
         $input['users_locations'] = $user->fields['locations_id'];
         $tmprequester = $input["_users_id_requester"];
     } else {
         $tmprequester = 0;
     }
     // Clean new lines before passing to rules
     if (isset($input["content"])) {
         $input["content"] = preg_replace('/\\\\r\\\\n/', "\n", $input['content']);
         $input["content"] = preg_replace('/\\\\n/', "\n", $input['content']);
         if (!$CFG_GLPI['use_rich_text']) {
             $input["content"] = Html::entity_decode_deep($input["content"]);
             $input["content"] = Html::entity_decode_deep($input["content"]);
             $input["content"] = Html::clean($input["content"]);
         }
     }
     $input = $rules->processAllRules(Toolbox::stripslashes_deep($input), Toolbox::stripslashes_deep($input), array('recursive' => true), array('condition' => RuleTicket::ONADD));
     // Recompute default values based on values computed by rules
     $input = $this->computeDefaultValuesForAdd($input);
     if (isset($input['_users_id_requester']) && !is_array($input['_users_id_requester']) && $input['_users_id_requester'] != $tmprequester) {
         // if requester set by rule, clear address from mailcollector
         unset($input['_users_id_requester_notif']);
     }
     // Manage auto assign
     $auto_assign_mode = Entity::getUsedConfig('auto_assign_mode', $input['entities_id']);
     switch ($auto_assign_mode) {
         case Entity::CONFIG_NEVER:
             break;
         case Entity::AUTO_ASSIGN_HARDWARE_CATEGORY:
             if ($item != NULL) {
                 // Auto assign tech from item
                 if ((!isset($input['_users_id_assign']) || $input['_users_id_assign'] == 0) && $item->isField('users_id_tech')) {
                     $input['_users_id_assign'] = $item->getField('users_id_tech');
                 }
                 // Auto assign group from item
                 if ((!isset($input['_groups_id_assign']) || $input['_groups_id_assign'] == 0) && $item->isField('groups_id_tech')) {
                     $input['_groups_id_assign'] = $item->getField('groups_id_tech');
                 }
             }
             // Auto assign tech/group from Category
             if ($input['itilcategories_id'] > 0 && (!isset($input['_users_id_assign']) || !$input['_users_id_assign'] || (!isset($input['_groups_id_assign']) || !$input['_groups_id_assign']))) {
                 $cat = new ITILCategory();
                 $cat->getFromDB($input['itilcategories_id']);
                 if ((!isset($input['_users_id_assign']) || !$input['_users_id_assign']) && $cat->isField('users_id')) {
                     $input['_users_id_assign'] = $cat->getField('users_id');
                 }
                 if ((!isset($input['_groups_id_assign']) || !$input['_groups_id_assign']) && $cat->isField('groups_id')) {
                     $input['_groups_id_assign'] = $cat->getField('groups_id');
                 }
             }
             break;
         case Entity::AUTO_ASSIGN_CATEGORY_HARDWARE:
             // Auto assign tech/group from Category
             if ($input['itilcategories_id'] > 0 && (!isset($input['_users_id_assign']) || !$input['_users_id_assign'] || (!isset($input['_groups_id_assign']) || !$input['_groups_id_assign']))) {
                 $cat = new ITILCategory();
                 $cat->getFromDB($input['itilcategories_id']);
                 if ((!isset($input['_users_id_assign']) || !$input['_users_id_assign']) && $cat->isField('users_id')) {
                     $input['_users_id_assign'] = $cat->getField('users_id');
                 }
                 if ((!isset($input['_groups_id_assign']) || !$input['_groups_id_assign']) && $cat->isField('groups_id')) {
                     $input['_groups_id_assign'] = $cat->getField('groups_id');
                 }
             }
             if ($item != NULL) {
                 // Auto assign tech from item
                 if ((!isset($input['_users_id_assign']) || $input['_users_id_assign'] == 0) && $item->isField('users_id_tech')) {
                     $input['_users_id_assign'] = $item->getField('users_id_tech');
                 }
                 // Auto assign group from item
                 if ((!isset($input['_groups_id_assign']) || $input['_groups_id_assign'] == 0) && $item->isField('groups_id_tech')) {
                     $input['_groups_id_assign'] = $item->getField('groups_id_tech');
                 }
             }
             break;
     }
     // Replay setting auto assign if set in rules engine or by auto_assign_mode
     if ((isset($input["_users_id_assign"]) && (!is_array($input['_users_id_assign']) && $input["_users_id_assign"] > 0 || is_array($input['_users_id_assign']) && count($input['_users_id_assign']) > 0) || isset($input["_groups_id_assign"]) && (!is_array($input['_groups_id_assign']) && $input["_groups_id_assign"] > 0 || is_array($input['_groups_id_assign']) && count($input['_groups_id_assign']) > 0) || isset($input["_suppliers_id_assign"]) && (!is_array($input['_suppliers_id_assign']) && $input["_suppliers_id_assign"] > 0 || is_array($input['_suppliers_id_assign']) && count($input['_suppliers_id_assign']) > 0)) && in_array($input['status'], $this->getNewStatusArray())) {
         $input["status"] = self::ASSIGNED;
     }
     // Manage SLT signment
     // 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);
     }
     // auto set type if not set
     if (!isset($input["type"])) {
         $input['type'] = Entity::getUsedConfig('tickettype', $input['entities_id'], '', Ticket::INCIDENT_TYPE);
     }
     return $input;
 }
Ejemplo n.º 2
0
 function prepareInputForAdd($input)
 {
     $input = parent::prepareInputForAdd($input);
     return $input;
 }
Ejemplo n.º 3
0
 function prepareInputForAdd($input)
 {
     $input = parent::prepareInputForAdd($input);
     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) && in_array($input['status'], $this->getNewStatusArray())) {
         $input["status"] = self::ASSIGNED;
     }
     return $input;
 }