grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026. -------------------------------------------------------------------------- */ /** @file * @brief */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } /// OCS Rules class class RuleImportEntity extends Rule { // From Rule static $rightname = 'rule_import'; public $can_sort = true; function getTitle() { return __('Rules for assigning an item to an entity'); } /** * @see Rule::maxActionsCount() **/ function maxActionsCount() { // Unlimited return 2; } /** * @see Rule::executeActions() **/ function executeActions($output, $params) { if (count($this->actions)) { foreach ($this->actions as $action) { switch ($action->fields["action_type"]) { case "assign" : $output[$action->fields["field"]] = $action->fields["value"]; break; case "regex_result" : //Assign entity using the regex's result if ($action->fields["field"] == "_affect_entity_by_tag") { //Get the TAG from the regex's results if (isset($this->regex_results[0])) { $res = RuleAction::getRegexResultById($action->fields["value"], $this->regex_results[0]); } else { $res = $action->fields["value"]; } if ($res != null) { //Get the entity associated with the TAG $target_entity = Entity::getEntityIDByTag(addslashes($res)); if ($target_entity != '') { $output["entities_id"] = $target_entity; } } } break; } } } return $output; } /** * @see Rule::getCriterias() **/ function getCriterias() { static $criterias = array(); if (count($criterias)) { return $criterias; } $criterias['_source']['table'] = ''; $criterias['_source']['field'] = '_source'; $criterias['_source']['name'] = __('Source'); $criterias['_source']['allow_condition'] = array(Rule::PATTERN_IS, Rule::PATTERN_IS_NOT); return $criterias; } /** * @since version 0.84 * * @see Rule::displayAdditionalRuleCondition() **/ function displayAdditionalRuleCondition($condition, $criteria, $name, $value, $test=false) { global $PLUGIN_HOOKS; if ($criteria['field'] == '_source') { $tab = array(); foreach ($PLUGIN_HOOKS['import_item'] as $plug => $types) { $tab[$plug] = Plugin::getInfo($plug, 'name'); } Dropdown::showFromArray($name, $tab); return true; } return false; } /** * @since version 0.84 * * @see Rule::getAdditionalCriteriaDisplayPattern() **/ function getAdditionalCriteriaDisplayPattern($ID, $condition, $pattern) { $crit = $this->getCriteria($ID); if ($crit['field'] == '_source') { $name = Plugin::getInfo($pattern, 'name'); if (empty($name)) { return false; } return $name; } } /** * @see Rule::getActions() **/ function getActions() { $actions = array(); $actions['entities_id']['name'] = __('Entity'); $actions['entities_id']['type'] = 'dropdown'; $actions['entities_id']['table'] = 'glpi_entities'; $actions['locations_id']['name'] = __('Location'); $actions['locations_id']['type'] = 'dropdown'; $actions['locations_id']['table'] = 'glpi_locations'; $actions['_ignore_import']['name'] = __('To be unaware of import'); $actions['_ignore_import']['type'] = 'yesonly'; return $actions; } } ?>