/** * Get all available types to which an ITIL object can be assigned **/ static function getAllTypesForHelpdesk() { global $PLUGIN_HOOKS, $CFG_GLPI; /// TODO ticket_types -> itil_types $types = array(); $ptypes = array(); //Types of the plugins (keep the plugin hook for right check) if (isset($PLUGIN_HOOKS['assign_to_ticket'])) { foreach ($PLUGIN_HOOKS['assign_to_ticket'] as $plugin => $value) { $ptypes = Plugin::doOneHook($plugin, 'AssignToTicket', $ptypes); } } asort($ptypes); //Types of the core (after the plugin for robustness) foreach ($CFG_GLPI["ticket_types"] as $itemtype) { if ($item = getItemForItemtype($itemtype)) { if (!isPluginItemType($itemtype) && in_array($itemtype, $_SESSION["glpiactiveprofile"]["helpdesk_item_type"])) { $types[$itemtype] = $item->getTypeName(1); } } } asort($types); // core type first... asort could be better ? // Drop not available plugins foreach ($ptypes as $itemtype => $itemtype_name) { if (!in_array($itemtype, $_SESSION["glpiactiveprofile"]["helpdesk_item_type"])) { unset($ptypes[$itemtype]); } } $types = array_merge($types, $ptypes); return $types; }
if (isset($_POST['submitname']) && $_POST['submitname']) { $submitname = stripslashes($_POST['submitname']); } if (isset($_POST["itemtype"]) && isset($_POST["id_field"]) && $_POST["id_field"]) { $search = Search::getOptions($_POST["itemtype"]); if (!isset($search[$_POST["id_field"]])) { exit; } $search = $search[$_POST["id_field"]]; $FIELDNAME_PRINTED = false; $USE_TABLE = false; echo "<table class='tab_glpi' width='100%'><tr><td>"; $plugdisplay = false; // Specific plugin Type case if (($plug = isPluginItemType($_POST["itemtype"])) || ($plug = isPluginItemType(getItemTypeForTable($search['table'])))) { $plugdisplay = Plugin::doOneHook($plug['plugin'], 'MassiveActionsFieldsDisplay', array('itemtype' => $_POST["itemtype"], 'options' => $search)); } $fieldname = ''; if (empty($search["linkfield"]) || $search['table'] == 'glpi_infocoms') { $fieldname = $search["field"]; } else { $fieldname = $search["linkfield"]; } if (!$plugdisplay) { $options = array(); $values = array(); // For ticket template or aditional options of massive actions if (isset($_POST['options'])) { $options = $_POST['options']; } if (isset($_POST['additionalvalues'])) {
switch ($params["type"]) { case "comp_champ": $val = Stat::getItems($_GET["itemtype"], $params["date1"], $params["date2"], $params["dropdown"]); Stat::showTable($_GET["itemtype"], $params["type"], $params["date1"], $params["date2"], $params["start"], $val, $params["dropdown"]); break; case "device": $val = Stat::getItems($_GET["itemtype"], $params["date1"], $params["date2"], $params["dropdown"]); Stat::showTable($_GET["itemtype"], $params["type"], $params["date1"], $params["date2"], $params["start"], $val, $params["dropdown"]); break; default: $val2 = isset($params['value2']) ? $params['value2'] : 0; $val = Stat::getItems($_GET["itemtype"], $params["date1"], $params["date2"], $params["type"], $val2); Stat::showTable($_GET["itemtype"], $params["type"], $params["date1"], $params["date2"], $params["start"], $val, $val2); } } else { if (isset($_GET["type"]) && $_GET["type"] == "hardwares") { Stat::showItems("", $_GET["date1"], $_GET["date2"], $_GET['start']); } } break; default: // Plugin case if ($plug = isPluginItemType($_GET["item_type"])) { if (Plugin::doOneHook($plug['plugin'], 'dynamicReport', $_GET)) { exit; } } $params = Search::manageParams($_GET["item_type"], $_GET); Search::showList($_GET["item_type"], $params); } }
/** * Check if it's possible to assign ITIL object to a type (core or plugin) * * @param $itemtype the object's type * * @return true if ticket can be assign to this type, false if not **/ static function isPossibleToAssignType($itemtype) { global $PLUGIN_HOOKS; /// TODO : assign_to_ticket to assign_to_itil // Plugin case if ($plug = isPluginItemType($itemtype)) { //If it's not a core's type, then check plugins $types = array(); if (isset($PLUGIN_HOOKS['assign_to_ticket'])) { $types = Plugin::doOneHook($plug['plugin'], 'AssignToTicket', $types); if (array_key_exists($itemtype, $types)) { return true; } } // standard case } else { if (in_array($itemtype, $_SESSION["glpiactiveprofile"]["helpdesk_item_type"])) { return true; } } return false; }
/** * Execute a hook if necessary and merge results * * @since version 0.84 * * @param $hook the hook to execute * @param $params array input parameters * @param $itemtype (default '') * * @return input parameters merged with hook parameters **/ static function doHookAndMergeResults($hook, $params = array(), $itemtype = '') { global $PLUGIN_HOOKS; if (empty($itemtype)) { $itemtype = static::getType(); } //Agregate all plugins criteria for this rules engine $toreturn = $params; if (isset($PLUGIN_HOOKS['use_rules'])) { foreach ($PLUGIN_HOOKS['use_rules'] as $plugin => $val) { if (is_array($val) && in_array($itemtype, $val)) { $results = Plugin::doOneHook($plugin, $hook, array('rule_itemtype' => $itemtype, 'values' => $params)); if (is_array($results)) { foreach ($results as $id => $result) { $toreturn[$id] = $result; } } } } } return $toreturn; }
/** * @see CommonDBTM::showMassiveActionsSubForm() **/ static function showMassiveActionsSubForm(MassiveAction $ma) { global $CFG_GLPI; switch ($ma->getAction()) { case 'update': if (!isset($ma->POST['id_field'])) { $itemtypes = array_keys($ma->items); $options_per_type = array(); $options_counts = array(); foreach ($itemtypes as $itemtype) { $options_per_type[$itemtype] = array(); $group = ''; $show_all = true; $show_infocoms = true; $itemtable = getTableForItemType($itemtype); if (InfoCom::canApplyOn($itemtype) && (!$itemtype::canUpdate() || !Infocom::canUpdate())) { $show_all = false; $show_infocoms = Infocom::canUpdate(); } foreach (Search::getCleanedOptions($itemtype, UPDATE) as $index => $option) { if (!is_array($option)) { $group = $option; $options_per_type[$itemtype][$group] = array(); } else { if ($option['field'] != 'id' && $index != 1 && ($option["linkfield"] != 'entities_id' || isset($option['massiveaction']) && $option['massiveaction'])) { if (!isset($option['massiveaction']) || $option['massiveaction']) { if ($show_all || ($show_infocoms && Search::isInfocomOption($itemtype, $index) || !$show_infocoms && !Search::isInfocomOption($itemtype, $index))) { $options_per_type[$itemtype][$group][$itemtype . ':' . $index] = $option['name']; if ($itemtable == $option['table']) { $field_key = 'MAIN:' . $option['field'] . ':' . $index; } else { $field_key = $option['table'] . ':' . $option['field'] . ':' . $index; } if (!isset($options_count[$field_key])) { $options_count[$field_key] = array(); } $options_count[$field_key][] = $itemtype . ':' . $index . ':' . $group; if (isset($option['MA_common_field'])) { if (!isset($options_count[$option['MA_common_field']])) { $options_count[$option['MA_common_field']] = array(); } $options_count[$option['MA_common_field']][] = $itemtype . ':' . $index . ':' . $group; } } } } } } } if (count($itemtypes) > 1) { $common_options = array(); foreach ($options_count as $field => $users) { if (count($users) > 1) { $labels = array(); foreach ($users as $user) { $user = explode(':', $user); $itemtype = $user[0]; $index = $itemtype . ':' . $user[1]; $group = implode(':', array_slice($user, 2)); if (isset($options_per_type[$itemtype][$group][$index])) { if (!in_array($options_per_type[$itemtype][$group][$index], $labels)) { $labels[] = $options_per_type[$itemtype][$group][$index]; } } $common_options[$field][] = $index; } $options[$group][$field] = implode('/', $labels); } } $choose_itemtype = true; $itemtype_choices = array(-1 => Dropdown::EMPTY_VALUE); foreach ($itemtypes as $itemtype) { $itemtype_choices[$itemtype] = $itemtype::getTypeName(Session::getPluralNumber()); } } else { $options = $options_per_type[$itemtypes[0]]; $common_options = false; $choose_itemtype = false; } $choose_field = count($options) > 1; // Beware: "class='tab_cadre_fixe'" induce side effects ... echo "<table width='100%'><tr>"; $colspan = 0; if ($choose_field) { $colspan++; echo "<td>"; if ($common_options) { echo __('Select the common field that you want to update'); } else { echo __('Select the field that you want to update'); } echo "</td>"; if ($choose_itemtype) { $colspan++; echo "<td rowspan='2'>" . __('or') . "</td>"; } } if ($choose_itemtype) { $colspan++; echo "<td>" . __('Select the type of the item on which applying this action') . "</td>"; } echo "</tr><tr>"; if ($choose_field) { echo "<td>"; $field_rand = Dropdown::showFromArray('id_field', $options, array('display_emptychoice' => true)); echo "</td>"; } if ($choose_itemtype) { echo "<td>"; $itemtype_rand = Dropdown::showFromArray('specialize_itemtype', $itemtype_choices); echo "</td>"; } $next_step_rand = mt_rand(); echo "</tr></table>"; echo "<span id='update_next_step{$next_step_rand}'> </span>"; if ($choose_field) { $params = $ma->POST; $params['id_field'] = '__VALUE__'; $params['common_options'] = $common_options; Ajax::updateItemOnSelectEvent("dropdown_id_field{$field_rand}", "update_next_step{$next_step_rand}", $_SERVER['REQUEST_URI'], $params); } if ($choose_itemtype) { $params = $ma->POST; $params['specialize_itemtype'] = '__VALUE__'; $params['common_options'] = $common_options; Ajax::updateItemOnSelectEvent("dropdown_specialize_itemtype{$itemtype_rand}", "update_next_step{$next_step_rand}", $_SERVER['REQUEST_URI'], $params); } // Only display the form for this stage exit; } if (!isset($ma->POST['common_options'])) { echo "<div class='center'><img src='" . $CFG_GLPI["root_doc"] . "/pics/warning.png' alt='" . __s('Warning') . "'><br><br>"; echo "<span class='b'>" . __('Implementation error !') . "</span><br>"; echo "</div>"; exit; } if ($ma->POST['common_options'] == 'false') { $search_options = array($ma->POST['id_field']); } else { if (isset($ma->POST['common_options'][$ma->POST['id_field']])) { $search_options = $ma->POST['common_options'][$ma->POST['id_field']]; } else { $search_options = array(); } } $items = array(); foreach ($search_options as $search_option) { $search_option = explode(':', $search_option); $itemtype = $search_option[0]; $index = $search_option[1]; if (!($item = getItemForItemtype($itemtype))) { continue; } if (InfoCom::canApplyOn($itemtype)) { Session::checkSeveralRightsOr(array($itemtype => UPDATE, "infocom" => UPDATE)); } else { $item->checkGlobal(UPDATE); } $search = Search::getOptions($itemtype); if (!isset($search[$index])) { exit; } $item->search = $search[$index]; $items[] = $item; } if (count($items) == 0) { exit; } // TODO: ensure that all items are equivalent ... $item = $items[0]; $search = $item->search; $plugdisplay = false; if (($plug = isPluginItemType($item->getType())) || ($plug = isPluginItemType(getItemTypeForTable($item->search['table'])))) { $plugdisplay = Plugin::doOneHook($plug['plugin'], 'MassiveActionsFieldsDisplay', array('itemtype' => $item->getType(), 'options' => $item->search)); } if (empty($search["linkfield"]) || $search['table'] == 'glpi_infocoms') { $fieldname = $search["field"]; } else { $fieldname = $search["linkfield"]; } if (!$plugdisplay) { $options = array(); $values = array(); // For ticket template or aditional options of massive actions if (isset($ma->POST['options'])) { $options = $ma->POST['options']; } if (isset($ma->POST['additionalvalues'])) { $values = $ma->POST['additionalvalues']; } $values[$search["field"]] = ''; echo $item->getValueToSelect($search, $fieldname, $values, $options); } $items_index = array(); foreach ($search_options as $search_option) { $search_option = explode(':', $search_option); $items_index[$search_option[0]] = $search_option[1]; } echo Html::hidden('search_options', array('value' => $items_index)); echo Html::hidden('field', array('value' => $fieldname)); echo "<br>\n"; $submitname = _sx('button', 'Post'); if (isset($ma->POST['submitname']) && $ma->POST['submitname']) { $submitname = stripslashes($ma->POST['submitname']); } echo Html::submit($submitname, array('name' => 'massiveaction')); return true; } return false; }
/** * @see Rule::findWithGlobalCriteria() **/ function findWithGlobalCriteria($input) { global $DB, $PLUGIN_HOOKS; $complex_criterias = array(); $sql_where = ''; $sql_from = ''; $continue = true; $global_criteria = array('manufacturer', 'model', 'name', 'serial'); //Add plugin global criteria if (isset($PLUGIN_HOOKS['use_rules'])) { foreach ($PLUGIN_HOOKS['use_rules'] as $plugin => $val) { if (is_array($val) && in_array($this->getType(), $val)) { $global_criteria = Plugin::doOneHook($plugin, "ruleImportComputer_addGlobalCriteria", $global_criteria); } } } foreach ($global_criteria as $criterion) { $criteria = $this->getCriteriaByID($criterion); if (!empty($criteria)) { foreach ($criteria as $crit) { // is a real complex criteria if ($crit->fields["condition"] == Rule::PATTERN_FIND) { if (!isset($input[$criterion]) || $input[$criterion] == '') { $continue = false; } else { $complex_criterias[] = $crit; } } } } } foreach ($this->getCriteriaByID('states_id') as $crit) { $complex_criterias[] = $crit; } //If a value is missing, then there's a problem ! if (!$continue) { return false; } //No complex criteria if (empty($complex_criterias)) { return true; } //Build the request to check if the machine exists in GLPI if (is_array($input['entities_id'])) { $where_entity = implode($input['entities_id'], ','); } else { $where_entity = $input['entities_id']; } $sql_where = '1'; $sql_from = ''; $needport = false; $needip = false; foreach ($complex_criterias as $criteria) { switch ($criteria->fields['criteria']) { case 'name': if ($criteria->fields['condition'] == Rule::PATTERN_IS_EMPTY) { $sql_where .= " AND (`glpi_computers`.`name`=''\n OR `glpi_computers`.`name` IS NULL) "; } else { $sql_where .= " AND (`glpi_computers`.`name`='" . $input['name'] . "') "; } break; case 'serial': $sql_where .= " AND `glpi_computers`.`serial`='" . $input["serial"] . "'"; break; case 'model': // search for model, don't create it if not found $options = array('manufacturer' => addslashes($input['manufacturer'])); $mid = Dropdown::importExternal('ComputerModel', addslashes($input['model']), -1, $options, '', false); $sql_where .= " AND `glpi_computers`.`computermodels_id` = '{$mid}'"; break; case 'manufacturer': // search for manufacturer, don't create it if not found $mid = Dropdown::importExternal('Manufacturer', addslashes($input['manufacturer']), -1, array(), '', false); $sql_where .= " AND `glpi_computers`.`manufacturers_id` = '{$mid}'"; break; case 'states_id': if ($criteria->fields['condition'] == Rule::PATTERN_IS) { $condition = " IN "; } else { $condition = " NOT IN "; } $sql_where .= " AND `glpi_computers`.`states_id`\n {$condition} ('" . $criteria->fields['pattern'] . "')"; break; } } if (isset($PLUGIN_HOOKS['use_rules'])) { foreach ($PLUGIN_HOOKS['use_rules'] as $plugin => $val) { if (is_array($val) && in_array($this->getType(), $val)) { $params = array('where_entity' => $where_entity, 'input' => $input, 'criteria' => $complex_criterias, 'sql_where' => $sql_where, 'sql_from' => $sql_from); $sql_results = Plugin::doOneHook($plugin, "ruleImportComputer_getSqlRestriction", $params); $sql_where = $sql_results['sql_where']; $sql_from = $sql_results['sql_from']; } } } $sql_glpi = "SELECT `glpi_computers`.`id`\n FROM {$sql_from}\n WHERE {$sql_where}\n ORDER BY `glpi_computers`.`is_deleted` ASC"; $result_glpi = $DB->query($sql_glpi); if ($DB->numrows($result_glpi) > 0) { while ($data = $DB->fetch_assoc($result_glpi)) { $this->criterias_results['found_computers'][] = $data['id']; } return true; } if (count($this->actions)) { foreach ($this->actions as $action) { if ($action->fields['field'] == '_fusion') { if ($action->fields["value"] == self::RULE_ACTION_LINK_OR_NO_IMPORT) { return true; } } } } return false; }
/** * @param $output **/ function preProcessPreviewResults($output) { global $PLUGIN_HOOKS; if (isset($PLUGIN_HOOKS['use_rules'])) { $params['rule_itemtype'] = $this->getType(); foreach ($PLUGIN_HOOKS['use_rules'] as $plugin => $val) { if (is_array($val) && in_array($this->getType(), $val)) { $results = Plugin::doOneHook($plugin, "preProcessRuleCollectionPreviewResults", array('output' => $output, 'params' => $params)); if (is_array($results)) { foreach ($results as $id => $result) { $output[$id] = $result; } } } } } return $this->cleanTestOutputCriterias($output); }
/** * If rule have found computer or rule give to create computer * * @param $items_id integer id of the computer found (or 0 if must be created) * @param $itemtype value Computer type here * * @return nothing * **/ function rulepassed($items_id, $itemtype) { global $DB, $PLUGIN_FUSIONINVENTORY_XML, $PF_ESXINVENTORY, $CFG_GLPI; PluginFusioninventoryToolbox::logIfExtradebug("pluginFusioninventory-rules", "Rule passed : " . $items_id . ", " . $itemtype . "\n"); $pfFormatconvert = new PluginFusioninventoryFormatconvert(); $a_computerinventory = $pfFormatconvert->replaceids($this->arrayinventory); $entities_id = $_SESSION["plugin_fusioninventory_entity"]; if ($itemtype == 'Computer') { $pfInventoryComputerLib = new PluginFusioninventoryInventoryComputerLib(); $pfAgent = new PluginFusioninventoryAgent(); $computer = new Computer(); if ($items_id == '0') { if ($entities_id == -1) { $entities_id = 0; $_SESSION["plugin_fusioninventory_entity"] = 0; } $_SESSION['glpiactiveentities'] = array($entities_id); $_SESSION['glpiactiveentities_string'] = $entities_id; $_SESSION['glpiactive_entity'] = $entities_id; } else { $computer->getFromDB($items_id); $a_computerinventory['Computer']['states_id'] = $computer->fields['states_id']; $input = array(); PluginFusioninventoryInventoryComputerInventory::addDefaultStateIfNeeded($input); if (isset($input['states_id'])) { $a_computerinventory['Computer']['states_id'] = $input['states_id']; } if ($entities_id == -1) { $entities_id = $computer->fields['entities_id']; $_SESSION["plugin_fusioninventory_entity"] = $computer->fields['entities_id']; } $_SESSION['glpiactiveentities'] = array($entities_id); $_SESSION['glpiactiveentities_string'] = $entities_id; $_SESSION['glpiactive_entity'] = $entities_id; if ($computer->fields['entities_id'] != $entities_id) { $pfEntity = new PluginFusioninventoryEntity(); $pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer(); $moveentity = FALSE; if ($pfEntity->getValue('transfers_id_auto', $computer->fields['entities_id']) > 0) { if (!$pfInventoryComputerComputer->getLock($items_id)) { $moveentity = TRUE; } } if ($moveentity) { $pfEntity = new PluginFusioninventoryEntity(); $transfer = new Transfer(); $transfer->getFromDB($pfEntity->getValue('transfers_id_auto', $entities_id)); $item_to_transfer = array("Computer" => array($items_id => $items_id)); $transfer->moveItems($item_to_transfer, $entities_id, $transfer->fields); } else { $_SESSION["plugin_fusioninventory_entity"] = $computer->fields['entities_id']; $_SESSION['glpiactiveentities'] = array($computer->fields['entities_id']); $_SESSION['glpiactiveentities_string'] = $computer->fields['entities_id']; $_SESSION['glpiactive_entity'] = $computer->fields['entities_id']; $entities_id = $computer->fields['entities_id']; } } } $a_computerinventory = $pfFormatconvert->extraCollectInfo($a_computerinventory, $items_id); $a_computerinventory = $pfFormatconvert->computerSoftwareTransformation($a_computerinventory, $entities_id); $no_history = FALSE; // * New $setdynamic = 1; if ($items_id == '0') { $input = array(); $input['entities_id'] = $entities_id; PluginFusioninventoryInventoryComputerInventory::addDefaultStateIfNeeded($input); if (isset($input['states_id'])) { $a_computerinventory['Computer']['states_id'] = $input['states_id']; } else { $a_computerinventory['Computer']['states_id'] = 0; } $items_id = $computer->add($input); $no_history = TRUE; $setdynamic = 0; } if (isset($_SESSION['plugin_fusioninventory_locations_id'])) { $a_computerinventory['Computer']['locations_id'] = $_SESSION['plugin_fusioninventory_locations_id']; unset($_SESSION['plugin_fusioninventory_locations_id']); } $serialized = gzcompress(serialize($a_computerinventory)); $a_computerinventory['fusioninventorycomputer']['serialized_inventory'] = Toolbox::addslashes_deep($serialized); if (!$PF_ESXINVENTORY) { $pfAgent->setAgentWithComputerid($items_id, $this->device_id, $entities_id); } $pfConfig = new PluginFusioninventoryConfig(); $query = "INSERT INTO `glpi_plugin_fusioninventory_dblockinventories`\n SET `value`='" . $items_id . "'"; $CFG_GLPI["use_log_in_files"] = FALSE; if (!$DB->query($query)) { $communication = new PluginFusioninventoryCommunication(); $communication->setMessage("<?xml version='1.0' encoding='UTF-8'?>\n <REPLY>\n <ERROR>ERROR: SAME COMPUTER IS CURRENTLY UPDATED</ERROR>\n </REPLY>"); $communication->sendMessage($_SESSION['plugin_fusioninventory_compressmode']); exit; } $CFG_GLPI["use_log_in_files"] = TRUE; // * For benchs //$start = microtime(TRUE); PluginFusioninventoryInventoryComputerStat::increment(); $pfInventoryComputerLib->updateComputer($a_computerinventory, $items_id, $no_history, $setdynamic); $query = "DELETE FROM `glpi_plugin_fusioninventory_dblockinventories`\n WHERE `value`='" . $items_id . "'"; $DB->query($query); $plugin = new Plugin(); if ($plugin->isActivated('monitoring')) { Plugin::doOneHook("monitoring", "ReplayRulesForItem", array('Computer', $items_id)); } // * For benchs //Toolbox::logInFile("exetime", (microtime(TRUE) - $start)." (".$items_id.")\n". // memory_get_usage()."\n". // memory_get_usage(TRUE)."\n". // memory_get_peak_usage()."\n". // memory_get_peak_usage()."\n"); if (isset($_SESSION['plugin_fusioninventory_rules_id'])) { $pfRulematchedlog = new PluginFusioninventoryRulematchedlog(); $inputrulelog = array(); $inputrulelog['date'] = date('Y-m-d H:i:s'); $inputrulelog['rules_id'] = $_SESSION['plugin_fusioninventory_rules_id']; if (isset($_SESSION['plugin_fusioninventory_agents_id'])) { $inputrulelog['plugin_fusioninventory_agents_id'] = $_SESSION['plugin_fusioninventory_agents_id']; } $inputrulelog['items_id'] = $items_id; $inputrulelog['itemtype'] = $itemtype; $inputrulelog['method'] = 'inventory'; $pfRulematchedlog->add($inputrulelog, array(), FALSE); $pfRulematchedlog->cleanOlddata($items_id, $itemtype); unset($_SESSION['plugin_fusioninventory_rules_id']); } // Write XML file if (!empty($PLUGIN_FUSIONINVENTORY_XML)) { PluginFusioninventoryToolbox::writeXML($items_id, $PLUGIN_FUSIONINVENTORY_XML->asXML(), 'computer'); } } else { if ($itemtype == 'PluginFusioninventoryUnmanaged') { $a_computerinventory = $pfFormatconvert->computerSoftwareTransformation($a_computerinventory, $entities_id); $class = new $itemtype(); if ($items_id == "0") { if ($entities_id == -1) { $entities_id = 0; $_SESSION["plugin_fusioninventory_entity"] = 0; } $input = array(); $input['date_mod'] = date("Y-m-d H:i:s"); $items_id = $class->add($input); if (isset($_SESSION['plugin_fusioninventory_rules_id'])) { $pfRulematchedlog = new PluginFusioninventoryRulematchedlog(); $inputrulelog = array(); $inputrulelog['date'] = date('Y-m-d H:i:s'); $inputrulelog['rules_id'] = $_SESSION['plugin_fusioninventory_rules_id']; if (isset($_SESSION['plugin_fusioninventory_agents_id'])) { $inputrulelog['plugin_fusioninventory_agents_id'] = $_SESSION['plugin_fusioninventory_agents_id']; } $inputrulelog['items_id'] = $items_id; $inputrulelog['itemtype'] = $itemtype; $inputrulelog['method'] = 'inventory'; $pfRulematchedlog->add($inputrulelog); $pfRulematchedlog->cleanOlddata($items_id, $itemtype); unset($_SESSION['plugin_fusioninventory_rules_id']); } } $class->getFromDB($items_id); $_SESSION["plugin_fusioninventory_entity"] = $class->fields['entities_id']; $input = array(); $input['id'] = $class->fields['id']; // Write XML file if (!empty($PLUGIN_FUSIONINVENTORY_XML)) { PluginFusioninventoryToolbox::writeXML($items_id, $PLUGIN_FUSIONINVENTORY_XML->asXML(), 'PluginFusioninventoryUnmanaged'); } if (isset($a_computerinventory['Computer']['name'])) { $input['name'] = $a_computerinventory['Computer']['name']; } $input['item_type'] = "Computer"; if (isset($a_computerinventory['Computer']['domains_id'])) { $input['domain'] = $a_computerinventory['Computer']['domains_id']; } if (isset($a_computerinventory['Computer']['serial'])) { $input['serial'] = $a_computerinventory['Computer']['serial']; } $class->update($input); } } }
/** * Get the standard massive actions * * @since version 0.84 * * This must not be overloaded in Class * @param $is_deleted massive action for deleted items ? (default 0) * @param $checkitem link item to check right (default NULL) * * @return an array of massive actions **/ function getAllMassiveActions($is_deleted = 0, $checkitem = NULL) { global $CFG_GLPI, $PLUGIN_HOOKS; if (!is_null($checkitem)) { $isadmin = $checkitem->canUpdate(); } else { $isadmin = static::canUpdate(); } $itemtype = $this->getType(); $actions = array(); if ($is_deleted) { if ($isadmin) { $actions['purge'] = _x('button', 'Delete permanently'); $actions['restore'] = _x('button', 'Restore'); } } else { if ($isadmin || in_array($itemtype, $CFG_GLPI["infocom_types"]) && Infocom::canUpdate()) { //TRANS: select action 'update' (before doing it) $actions['update'] = _x('button', 'Update'); } if (in_array($itemtype, $CFG_GLPI["infocom_types"]) && Infocom::canCreate()) { $actions['activate_infocoms'] = __('Enable the financial and administrative information'); } // No delete for entities and tracking of not have right if ($isadmin) { // do not take into account is_deleted if items may be dynamic if ($this->maybeDeleted() && !$this->useDeletedToLockIfDynamic()) { $actions['delete'] = _x('button', 'Put in dustbin'); } else { $actions['purge'] = _x('button', 'Delete permanently'); } } if (in_array($itemtype, $CFG_GLPI["document_types"])) { if (Document::canView()) { $actions['add_document'] = _x('button', 'Add a document'); $actions['remove_document'] = _x('button', 'Remove a document'); } } if (in_array($itemtype, $CFG_GLPI["contract_types"])) { if (Contract::canUpdate()) { $actions['add_contract_item'] = _x('button', 'Add a contract'); $actions['remove_contract_item'] = _x('button', 'Remove a contract'); } } // Specific actions $actions += $this->getSpecificMassiveActions($checkitem); // Plugin Specific actions if (isset($PLUGIN_HOOKS['use_massive_action'])) { foreach ($PLUGIN_HOOKS['use_massive_action'] as $plugin => $val) { $plug_actions = Plugin::doOneHook($plugin, 'MassiveActions', $itemtype); if (count($plug_actions)) { $actions += $plug_actions; } } } } //Add unlock if needed $actions += Lock::getUnlockMassiveActions($itemtype); // Manage forbidden actions $forbidden_actions = $this->getForbiddenStandardMassiveAction(); if (is_array($forbidden_actions) && count($forbidden_actions)) { foreach ($forbidden_actions as $actiontodel) { if (isset($actions[$actiontodel])) { unset($actions[$actiontodel]); } } } return $actions; }
echo "<input type='hidden' name='specific_action' value='0'>"; if (!isset($actions[$_POST['action']])) { Html::displayRightError(); exit; } } else { if (!isset($actions[$_POST['action']])) { echo "<input type='hidden' name='specific_action' value='1'>"; } else { echo "<input type='hidden' name='specific_action' value='0'>"; } } echo "<input type='hidden' name='action' value='" . $_POST["action"] . "'>"; echo "<input type='hidden' name='itemtype' value='" . $_POST["itemtype"] . "'>"; echo "<input type='hidden' name='is_deleted' value='" . $_POST["is_deleted"] . "'>"; echo ' '; // Plugin specific actions $split = explode('_', $_POST["action"]); if ($split[0] == 'plugin' && isset($split[1])) { // Normalized name plugin_name_action // Allow hook from any plugin on any (core or plugin) type Plugin::doOneHook($split[1], 'MassiveActionsDisplay', array('itemtype' => $_POST["itemtype"], 'action' => $_POST["action"])); // } else if ($plug=isPluginItemType($_POST["itemtype"])) { // non-normalized name // hook from the plugin defining the type // Plugin::doOneHook($plug['plugin'], 'MassiveActionsDisplay', $_POST["itemtype"], // $_POST["action"]); } else { $item->showMassiveActionsParameters($_POST); } }
/** * @param $hook_name * @param $params array **/ function plugin_datainjection_loadHook($hook_name, $params = array()) { global $PLUGIN_HOOKS; if (!empty($params)) { $type = $params["type"]; //If a plugin type is defined Plugin::doOneHook($PLUGIN_HOOKS['plugin_types'][$type], 'datainjection_' . $hook_name); } else { if (isset($PLUGIN_HOOKS['plugin_types'])) { //Browse all plugins foreach ($PLUGIN_HOOKS['plugin_types'] as $type => $name) { Plugin::doOneHook($name, 'datainjection_' . $hook_name); } } } }