function post_addItem() { if ($this->fields['itemtype'] == 'Ticket') { $ticket = new Ticket(); $ticket->update(array('id' => $this->fields['items_id'], 'date_mod' => $_SESSION["glpi_currenttime"], '_forcenotif' => true, '_donotadddocs' => true)); } parent::post_addItem(); }
/** * @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); }
/** * @see CommonDBTM::doSpecificMassiveActions() **/ function doSpecificMassiveActions($input = array()) { $res = array('ok' => 0, 'ko' => 0, 'noright' => 0); switch ($input['action']) { default: return parent::doSpecificMassiveActions($input); } return $res; }
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); }
/** * @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); }
function post_addItem() { $t = new Ticket(); $no_stat_computation = true; if ($this->input['type'] == Ticket::ASSIGN) { $no_stat_computation = false; } $t->updateDateMod($this->fields['tickets_id'], $no_stat_computation); parent::post_addItem(); }
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); }
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); }
/** * Check right on an contract - overloaded to check max_links_allowed * * @param $ID ID of the item (-1 if new item) * @param $right Right to check : r / w / recursive * @param $input array of input data (used for adding item) * * @return boolean **/ function can($ID, $right, &$input = NULL) { if ($ID < 0) { // Ajout $contract = new Contract(); if (!$contract->getFromDB($input['contracts_id'])) { return false; } if ($contract->fields['max_links_allowed'] > 0 && countElementsInTable($this->getTable(), "`contracts_id`='" . $input['contracts_id'] . "'") >= $contract->fields['max_links_allowed']) { return false; } } return parent::can($ID, $right, $input); }
/** * Check right on an item - overloaded to check is_global * * @param $ID ID of the item (-1 if new item) * @param $right Right to check : r / w / recursive * @param $input array of input data (used for adding item) (default NULL) * * @return boolean **/ function can($ID, $right, array &$input = NULL) { if ($ID < 0) { // Ajout if (!($item = new $input['itemtype']())) { return false; } if (!$item->getFromDB($input['items_id'])) { return false; } if ($item->getField('is_global') == 0 && self::countForItem($ID) > 0) { return false; } } return parent::can($ID, $right, $input); }
/** * Check right on an item - overloaded to check is_global * * @param $ID ID of the item (-1 if new item) * @param $right Right to check : r / w / recursive * @param $input array of input data (used for adding item) * * @return boolean **/ function can($ID, $right, &$input = NULL) { if ($ID < 0) { // Ajout if (!class_exists($input['itemtype'])) { return false; } $item = new $input['itemtype'](); if (!$item->getFromDB($input['items_id'])) { return false; } if ($item->getField('is_global') == 0 && $this->countForItem($item) > 0) { return false; } } return parent::can($ID, $right, $input); }
/** * @since version 0.85 * * @see CommonDBRelation::getRelationMassiveActionsSpecificities() **/ static function getRelationMassiveActionsSpecificities() { global $CFG_GLPI; $specificities = parent::getRelationMassiveActionsSpecificities(); $specificities['dropdown_method_2'] = 'dropdownUnder'; $specificities['can_remove_all_at_once'] = false; return $specificities; }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'add_task': if (!($task = getItemForItemtype('TicketTask'))) { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); break; } $ticket = new Ticket(); $field = $ticket->getForeignKeyField(); $input = $ma->getInput(); foreach ($ids as $id) { if ($item->can($id, READ)) { if ($ticket->getFromDB($item->fields['tickets_id'])) { $input2 = array($field => $item->fields['tickets_id'], 'taskcategories_id' => $input['taskcategories_id'], 'actiontime' => $input['actiontime'], 'content' => $input['content']); if ($task->can(-1, CREATE, $input2)) { if ($task->add($input2)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } } return; case 'solveticket': $input = $ma->getInput(); $ticket = new Ticket(); foreach ($ids as $id) { if ($item->can($id, READ)) { if ($ticket->getFromDB($item->fields['tickets_id']) && $ticket->canSolve()) { $toupdate = array(); $toupdate['id'] = $ticket->getID(); $toupdate['solutiontypes_id'] = $input['solutiontypes_id']; $toupdate['solution'] = $input['solution']; if ($ticket->update($toupdate)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($ticket->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($ticket->getErrorMessage(ERROR_RIGHT)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($ticket->getErrorMessage(ERROR_RIGHT)); } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBRelation::getRelationMassiveActionsSpecificities() **/ static function getRelationMassiveActionsSpecificities() { global $CFG_GLPI; $specificities = parent::getRelationMassiveActionsSpecificities(); // Set the labels for add_item and remove_item $specificities['button_labels']['add'] = _sx('button', 'Associate'); $specificities['button_labels']['remove'] = _sx('button', 'Dissociate'); return $specificities; }
/** * @since version 0.84 * * @param $field * @param $name (default '') * @param $values (default '') * @param $options array * * @return string **/ static function getSpecificValueToSelect($field, $name = '', $values = '', array $options = array()) { if (!is_array($values)) { $values = array($field => $values); } $options['display'] = false; switch ($field) { case 'items_id': if (isset($values['itemtype']) && !empty($values['itemtype'])) { $options['name'] = $name; $options['value'] = $values[$field]; return Dropdown::show($values['itemtype'], $options); } else { self::dropdownAllDevices($name, 0, 0); return ' '; } break; } return parent::getSpecificValueToSelect($field, $name, $values, $options); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'solveticket': $input = $ma->getInput(); $ticket = new Ticket(); foreach ($ids as $id) { if ($item->can($id, READ)) { if ($ticket->getFromDB($item->fields['tickets_id']) && $ticket->canSolve()) { $toupdate = array(); $toupdate['id'] = $ticket->getID(); $toupdate['solutiontypes_id'] = $input['solutiontypes_id']; $toupdate['solution'] = $input['solution']; if ($ticket->update($toupdate)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($ticket->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($ticket->getErrorMessage(ERROR_RIGHT)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($ticket->getErrorMessage(ERROR_RIGHT)); } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * @since version 0.85 * * @see CommonDBRelation::getRelationMassiveActionsSpecificities() **/ static function getRelationMassiveActionsSpecificities() { global $CFG_GLPI; $specificities = parent::getRelationMassiveActionsSpecificities(); $specificities['select_items_options_1'] = array('right' => 'all'); $specificities['select_items_options_2'] = array('condition' => '`is_usergroup`'); // Define normalized action for add_item and remove_item $specificities['normalized']['add'][] = 'add_supervisor'; $specificities['normalized']['add'][] = 'add_delegatee'; $specificities['button_labels']['add_supervisor'] = $specificities['button_labels']['add']; $specificities['button_labels']['add_delegatee'] = $specificities['button_labels']['add']; $specificities['update_if_different'] = true; return $specificities; }
/** * @since version 0.85 * * @see CommonDBConnexity::getConnexityMassiveActionsSpecificities() **/ static function getConnexityMassiveActionsSpecificities() { $specificities = parent::getConnexityMassiveActionsSpecificities(); $specificities['reaffect'] = 1; $specificities['itemtypes'] = self::getConcernedItems(); return $specificities; }
/** * @since version 0.85 * * @see CommonDBRelation::getRelationMassiveActionsSpecificities() **/ static function getRelationMassiveActionsSpecificities() { global $CFG_GLPI; $specificities = parent::getRelationMassiveActionsSpecificities(); $specificities['itemtypes'] = Document::getItemtypesThatCanHave(); // Define normalized action for add_item and remove_item $specificities['normalized']['add'][] = 'add_item'; $specificities['normalized']['remove'][] = 'remove_item'; // Set the labels for add_item and remove_item $specificities['button_labels']['add_item'] = $specificities['button_labels']['add']; $specificities['button_labels']['remove_item'] = $specificities['button_labels']['remove']; return $specificities; }
/** * @since version 0.85 * * @see CommonDBRelation::getRelationMassiveActionsSpecificities() **/ static function getRelationMassiveActionsSpecificities() { global $CFG_GLPI; $specificities = parent::getRelationMassiveActionsSpecificities(); $specificities['itemtypes'] = $CFG_GLPI['contract_types']; return $specificities; }
/** * Do the specific massive actions * * @since version 0.84 * * @param $input array of input datas * * @return an array of results (nbok, nbko, nbnoright counts) **/ function doSpecificMassiveActions($input = array()) { $res = array('ok' => 0, 'ko' => 0, 'noright' => 0); $typo_item = new PluginTypologyTypology_Item(); switch ($input['action']) { case "delete_item": if ($input['itemtype'] == 'PluginTypologyTypology_Item') { foreach ($input["item"] as $key => $val) { if ($val != 0) { $typo_item->getFromDB($key); if ($typo_item->delete(array('id' => $key))) { $values = array('plugin_typology_typologies_id' => $input['plugin_typology_typologies_id'], 'items_id' => $typo_item->fields['items_id'], 'itemtype' => $typo_item->fields['itemtype']); PluginTypologyTypology_Item::addLog($values, PluginTypologyTypology_Item::LOG_DELETE); $res['ok']++; } else { $res['ko']++; } } } } break; case "update_allitem": if ($input['itemtype'] == 'PluginTypologyTypology_Item') { foreach ($input["item"] as $key => $val) { if ($val != 0) { $typo_item->getFromDB($key); $result = PluginTypologyTypology_Item::checkValidated(array('items_id' => $typo_item->fields['items_id'], 'plugin_typology_typologies_id' => $typo_item->fields['plugin_typology_typologies_id'], 'id' => $typo_item->fields['id'])); if ($typo_item->update($result)) { $values = array('plugin_typology_typologies_id' => $typo_item->fields['plugin_typology_typologies_id'], 'items_id' => $typo_item->fields['items_id'], 'itemtype' => $typo_item->fields['itemtype']); PluginTypologyTypology_Item::addLog($values, PluginTypologyTypology_Item::LOG_UPDATE); $res['ok']++; } else { $res['ko']++; } } } } break; default: return parent::doSpecificMassiveActions($input); } return $res; }
/** * Get search function for the class * * @return array of search option **/ function getSearchOptions() { $tab = parent::getSearchOptions(); return $tab; }
function post_addItem() { global $CFG_GLPI; $t = new Ticket(); $t->updateDateMod($this->fields['tickets_id_1']); $t->updateDateMod($this->fields['tickets_id_2']); parent::post_addItem(); $donotif = $CFG_GLPI["use_mailing"]; if ($donotif) { $t->getFromDB($this->fields['tickets_id_1']); NotificationEvent::raiseEvent("update", $t); $t->getFromDB($this->fields['tickets_id_2']); NotificationEvent::raiseEvent("update", $t); } }
/** * @see CommonDBTM::doSpecificMassiveActions() * * @since version 0.84 **/ function doSpecificMassiveActions($input = array()) { $res = array('ok' => 0, 'ko' => 0, 'noright' => 0); switch ($input['action']) { case "solveticket": $ticket = new Ticket(); foreach ($input["item"] as $key => $val) { if ($val == 1) { if ($this->can($key, 'r')) { if ($ticket->getFromDB($this->fields['tickets_id']) && $ticket->canSolve()) { $toupdate = array(); $toupdate['id'] = $ticket->getID(); $toupdate['solutiontypes_id'] = $input['solutiontypes_id']; $toupdate['solution'] = $input['solution']; if ($ticket->update($toupdate)) { $res['ok']++; } else { $res['ko']++; } } else { $res['noright']++; } } else { $res['noright']++; } } } break; default: return parent::doSpecificMassiveActions($input); } return $res; }
function post_addItem() { $item = new static::$itemtype_1(); $no_stat_computation = true; if ($this->input['type'] == CommonITILActor::ASSIGN) { $no_stat_computation = false; } $item->updateDateMod($this->fields[static::getItilObjectForeignKey()], $no_stat_computation); // Check object status and update it if needed if (!isset($this->input['_from_object'])) { if ($item->getFromDB($this->fields[static::getItilObjectForeignKey()])) { if (in_array($item->fields["status"], $item->getNewStatusArray()) && in_array(CommonITILObject::ASSIGNED, array_keys($item->getAllStatusArray()))) { $item->update(array('id' => $item->getID(), 'status' => CommonITILObject::ASSIGNED)); } } } parent::post_addItem(); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $DB; switch ($ma->getAction()) { case 'move_license': $input = $ma->getInput(); if (isset($input['softwarelicenses_id'])) { foreach ($ids as $id) { if ($item->can($id, UPDATE)) { //Process rules if ($item->update(array('id' => $id, 'softwarelicenses_id' => $input['softwarelicenses_id']))) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } return; case 'install': $csl = new self(); $csv = new Computer_SoftwareVersion(); foreach ($ids as $id) { if ($csl->getFromDB($id)) { $sl = new SoftwareLicense(); if ($sl->getFromDB($csl->fields["softwarelicenses_id"])) { $version = 0; if ($sl->fields["softwareversions_id_use"] > 0) { $version = $sl->fields["softwareversions_id_use"]; } else { $version = $sl->fields["softwareversions_id_buy"]; } if ($version > 0) { $params = array('computers_id' => $csl->fields['computers_id'], 'softwareversions_id' => $version); //Get software name and manufacturer if ($csv->can(-1, CREATE, $params)) { //Process rules if ($csv->add($params)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); } } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * Get search function for the class * * @return array of search option **/ function getSearchOptions() { return parent::getSearchOptions(); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $DB; switch ($ma->getAction()) { case 'move_version': $input = $ma->getInput(); if (isset($input['softwareversions_id'])) { foreach ($ids as $id) { if ($item->can($id, UPDATE)) { //Process rules if ($item->update(array('id' => $id, 'softwareversions_id' => $input['softwareversions_id']))) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } return; case 'add': $itemtoadd = new Computer_SoftwareVersion(); if (isset($_POST['peer_softwareversions_id'])) { foreach ($ids as $id) { if ($item->can($id, UPDATE)) { //Process rules if ($itemtoadd->add(array('computers_id' => $id, 'softwareversions_id' => $_POST['peer_softwareversions_id']))) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($itemtoadd->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($itemtoadd->getErrorMessage(ERROR_RIGHT)); } } } else { $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO); } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
function getForbiddenStandardMassiveAction() { $forbidden = parent::getForbiddenStandardMassiveAction(); $forbidden[] = 'update'; return $forbidden; }
/** * Get search function for the class * * @return array of search option **/ function getSearchOptions() { global $LANG; $tab = parent::getSearchOptions(); return $tab; }