Exemplo n.º 1
0
 /**
  * @see CommonDBTM::prepareInputForAdd()
  **/
 function prepareInputForAdd($input)
 {
     // Avoid duplicate entry
     if (countElementsInTable($this->getTable(), ['projects_id' => $input['projects_id'], 'itemtype' => $input['itemtype'], 'items_id' => $input['items_id']]) > 0) {
         return false;
     }
     return parent::prepareInputForAdd($input);
 }
Exemplo n.º 2
0
 /**
  * @see CommonDBTM::prepareInputForAdd()
  **/
 function prepareInputForAdd($input)
 {
     // Avoid duplicate entry
     $restrict = " `problems_id` = '" . $input['problems_id'] . "'\n                   AND `itemtype` = '" . $input['itemtype'] . "'\n                   AND `items_id` = '" . $input['items_id'] . "'";
     if (countElementsInTable($this->getTable(), $restrict) > 0) {
         return false;
     }
     return parent::prepareInputForAdd($input);
 }
Exemplo n.º 3
0
 function prepareInputForAdd($input)
 {
     // TODO: check if the entities should not be inherited from the profile or the user
     if (!isset($input['entities_id']) || $input['entities_id'] < 0) {
         Session::addMessageAfterRedirect(__('No selected element or badly defined operation'), false, ERROR);
         return false;
     }
     return parent::prepareInputForAdd($input);
 }
Exemplo n.º 4
0
 function prepareInputForAdd($input)
 {
     // Well, if I remember my PHP: empty(0) == true ...
     if (empty($input['changes_id']) || $input['changes_id'] == 0) {
         return false;
     }
     // Avoid duplicate entry
     if (countElementsInTable($this->getTable(), ['changes_id' => $input['changes_id'], 'itemtype' => $input['itemtype'], 'items_id' => $input['items_id']]) > 0) {
         return false;
     }
     return parent::prepareInputForAdd($input);
 }
Exemplo n.º 5
0
 function prepareInputForAdd($input)
 {
     // Well, if I remember my PHP: empty(0) == true ...
     if (empty($input['changes_id']) || $input['changes_id'] == 0) {
         return false;
     }
     // Avoid duplicate entry
     $restrict = "`changes_id` = '" . $input['changes_id'] . "'\n                   AND `itemtype` = '" . $input['itemtype'] . "'\n                   AND `items_id` = '" . $input['items_id'] . "'";
     if (countElementsInTable($this->getTable(), $restrict) > 0) {
         return false;
     }
     return parent::prepareInputForAdd($input);
 }
 function prepareInputForAdd($input)
 {
     if (!isset($input['is_template_computer']) || !isset($input['is_deleted_computer'])) {
         // Get template and deleted information from computer
         // If computer set update is_template / is_deleted infos to ensure data validity
         if (isset($input['computers_id'])) {
             $computer = new Computer();
             if ($computer->getFromDB($input['computers_id'])) {
                 $input['is_template_computer'] = $computer->getField('is_template');
                 $input['is_deleted_computer'] = $computer->getField('is_deleted');
             }
         }
     }
     return parent::prepareInputForAdd($input);
 }
Exemplo n.º 7
0
 function prepareInputForAdd($input)
 {
     if ((empty($input['items_id']) || $input['items_id'] == 0) && $input['itemtype'] != 'Entity') {
         return false;
     }
     // Do not insert circular link for document
     if ($input['itemtype'] == 'Document' && $input['items_id'] == $input['documents_id']) {
         return false;
     }
     // Avoid duplicate entry
     $restrict = "`documents_id` = '" . $input['documents_id'] . "'\n                   AND `itemtype` = '" . $input['itemtype'] . "'\n                   AND `items_id` = '" . $input['items_id'] . "'";
     if (countElementsInTable($this->getTable(), $restrict) > 0) {
         return false;
     }
     return parent::prepareInputForAdd($input);
 }
Exemplo n.º 8
0
 function prepareInputForAdd($input)
 {
     // Clean values
     $input['tickets_id_1'] = Toolbox::cleanInteger($input['tickets_id_1']);
     $input['tickets_id_2'] = Toolbox::cleanInteger($input['tickets_id_2']);
     // Check of existance of rights on both Ticket(s) is done by the parent
     if ($input['tickets_id_2'] == $input['tickets_id_1']) {
         return false;
     }
     if (!isset($input['link'])) {
         $input['link'] = self::LINK_TO;
     }
     // No multiple links
     $tickets = self::getLinkedTicketsTo($input['tickets_id_1']);
     if (count($tickets)) {
         foreach ($tickets as $key => $t) {
             if ($t['tickets_id'] == $input['tickets_id_2']) {
                 // Delete old simple link
                 if ($input['link'] == self::DUPLICATE_WITH && $t['link'] == self::LINK_TO) {
                     $tt = new Ticket_Ticket();
                     $tt->delete(array("id" => $key));
                 } else {
                     // No duplicate link
                     return false;
                 }
             }
         }
     }
     return parent::prepareInputForAdd($input);
 }
Exemplo n.º 9
0
 /**
  * @see CommonDBTM::prepareInputForAdd()
  **/
 function prepareInputForAdd($input)
 {
     // Avoid duplicate entry
     $restrict = " `tickets_id` = '" . $input['tickets_id'] . "'\n                   AND `itemtype` = '" . $input['itemtype'] . "'\n                   AND `items_id` = '" . $input['items_id'] . "'";
     if (countElementsInTable($this->getTable(), $restrict) > 0) {
         return false;
     }
     $ticket = new Ticket();
     $ticket->getFromDB($input['tickets_id']);
     // Get item location if location is not already set in ticket
     if (empty($ticket->fields['locations_id'])) {
         if ($input["items_id"] > 0 && !empty($input["itemtype"])) {
             if ($item = getItemForItemtype($input["itemtype"])) {
                 if ($item->getFromDB($input["items_id"])) {
                     if ($item->isField('locations_id')) {
                         $ticket->fields['items_locations'] = $item->fields['locations_id'];
                         // Process Business Rules
                         $rules = new RuleTicketCollection($ticket->fields['entities_id']);
                         $ticket->fields = $rules->processAllRules(Toolbox::stripslashes_deep($ticket->fields), Toolbox::stripslashes_deep($ticket->fields), array('recursive' => true));
                         unset($ticket->fields['items_locations']);
                         $ticket->updateInDB(array('locations_id'));
                     }
                 }
             }
         }
     }
     $group = new Group_Ticket();
     $groups = $group->find("`tickets_id` = " . $input['tickets_id'] . " AND `type` = " . CommonITILActor::REQUESTER);
     if (count($groups) <= 0) {
         if ($input["items_id"] > 0 && !empty($input["itemtype"])) {
             if ($item = getItemForItemtype($input["itemtype"])) {
                 if ($item->getFromDB($input["items_id"])) {
                     if ($item->isField('groups_id')) {
                         $ticket->fields['items_groups'] = $item->fields['groups_id'];
                         // Process Business Rules
                         $rules = new RuleTicketCollection($ticket->fields['entities_id']);
                         $ticket->fields = $rules->processAllRules(Toolbox::stripslashes_deep($ticket->fields), Toolbox::stripslashes_deep($ticket->fields), array('recursive' => true));
                         unset($ticket->fields['items_groups']);
                         $group->add(array('tickets_id' => $input['tickets_id'], 'groups_id' => $item->fields['groups_id'], 'type' => CommonITILActor::REQUESTER));
                     }
                 }
             }
         }
     }
     return parent::prepareInputForAdd($input);
 }
Exemplo n.º 10
0
 /**
  * Prepare input datas for adding the relation
  *
  * Overloaded to check is Disconnect needed (during OCS sync)
  * and to manage autoupdate feature
  *
  * @param $input array of datas used to add the item
  *
  * @return the modified $input array
  *
  **/
 function prepareInputForAdd($input)
 {
     global $DB, $CFG_GLPI;
     $item = static::getItemFromArray(static::$itemtype_2, static::$items_id_2, $input);
     if (!$item instanceof CommonDBTM || $item->getField('is_global') == 0 && $this->countForItem($item) > 0) {
         return false;
     }
     $comp = static::getItemFromArray(static::$itemtype_1, static::$items_id_1, $input);
     if (!$item instanceof CommonDBTM || self::countForAll($comp, $item) > 0) {
         // no duplicates
         return false;
     }
     if (!$item->getField('is_global')) {
         // Autoupdate some fields - should be in post_addItem (here to avoid more DB access)
         $updates = array();
         if ($CFG_GLPI["is_location_autoupdate"] && $comp->fields['locations_id'] != $item->getField('locations_id')) {
             $updates['locations_id'] = addslashes($comp->fields['locations_id']);
             Session::addMessageAfterRedirect(__('Location updated. The connected items have been moved in the same location.'), true);
         }
         if ($CFG_GLPI["is_user_autoupdate"] && $comp->fields['users_id'] != $item->getField('users_id') || $CFG_GLPI["is_group_autoupdate"] && $comp->fields['groups_id'] != $item->getField('groups_id')) {
             if ($CFG_GLPI["is_user_autoupdate"]) {
                 $updates['users_id'] = $comp->fields['users_id'];
             }
             if ($CFG_GLPI["is_group_autoupdate"]) {
                 $updates['groups_id'] = $comp->fields['groups_id'];
             }
             Session::addMessageAfterRedirect(__('User or group updated. The connected items have been moved in the same values.'), true);
         }
         if ($CFG_GLPI["is_contact_autoupdate"] && ($comp->fields['contact'] != $item->getField('contact') || $comp->fields['contact_num'] != $item->getField('contact_num'))) {
             $updates['contact'] = addslashes($comp->fields['contact']);
             $updates['contact_num'] = addslashes($comp->fields['contact_num']);
             Session::addMessageAfterRedirect(__('Alternate username updated. The connected items have been updated using this alternate username.'), true);
         }
         if ($CFG_GLPI["state_autoupdate_mode"] < 0 && $comp->fields['states_id'] != $item->getField('states_id')) {
             $updates['states_id'] = $comp->fields['states_id'];
             Session::addMessageAfterRedirect(__('Status updated. The connected items have been updated using this status.'), true);
         }
         if ($CFG_GLPI["state_autoupdate_mode"] > 0 && $item->getField('states_id') != $CFG_GLPI["state_autoupdate_mode"]) {
             $updates['states_id'] = $CFG_GLPI["state_autoupdate_mode"];
         }
         if (count($updates)) {
             $updates['id'] = $input['items_id'];
             $history = true;
             if (isset($input['_no_history']) && $input['_no_history']) {
                 $history = false;
             }
             $item->update($updates, $history);
         }
     }
     return parent::prepareInputForAdd($input);
 }
Exemplo n.º 11
0
 function prepareInputForAdd($input)
 {
     if ((empty($input['items_id']) || $input['items_id'] == 0) && $input['itemtype'] != 'Entity') {
         return false;
     }
     // Do not insert circular link for document
     if ($input['itemtype'] == 'Document' && $input['items_id'] == $input['documents_id']) {
         return false;
     }
     // Avoid duplicate entry
     if (countElementsInTable($this->getTable(), ['documents_id' => $input['documents_id'], 'itemtype' => $input['itemtype'], 'items_id' => $input['items_id']]) > 0) {
         return false;
     }
     return parent::prepareInputForAdd($input);
 }