/** * Change active entity to the $ID one. Update glpiactiveentities session variable. * Reload groups related to this entity. * * @param $ID : ID of the new active entity ("all"=>load all possible entities) * @param $is_recursive : also display sub entities of the active entity ? * * @return Nothing **/ function changeActiveEntities($ID = "all", $is_recursive = false) { global $LANG; $newentities = array(); $newroots = array(); if (isset($_SESSION['glpiactiveprofile'])) { if ($ID == "all") { $ancestors = array(); foreach ($_SESSION['glpiactiveprofile']['entities'] as $key => $val) { $ancestors = array_unique(array_merge(getAncestorsOf("glpi_entities", $val['id']), $ancestors)); $newroots[$val['id']] = $val['is_recursive']; $newentities[$val['id']] = $val['id']; if ($val['is_recursive']) { $entities = getSonsOf("glpi_entities", $val['id']); if (count($entities)) { foreach ($entities as $key2 => $val2) { $newentities[$key2] = $key2; } } } } } else { /// Check entity validity $ancestors = getAncestorsOf("glpi_entities", $ID); $ok = false; foreach ($_SESSION['glpiactiveprofile']['entities'] as $key => $val) { if ($val['id'] == $ID || in_array($val['id'], $ancestors)) { // Not recursive or recursive and root entity is recursive if (!$is_recursive || $val['is_recursive']) { $ok = true; } } } if (!$ok) { return false; } $newroots[$ID] = $is_recursive; $newentities[$ID] = $ID; if ($is_recursive) { $entities = getSonsOf("glpi_entities", $ID); if (count($entities)) { foreach ($entities as $key2 => $val2) { $newentities[$key2] = $key2; } } } } } if (count($newentities) > 0) { $_SESSION['glpiactiveentities'] = $newentities; $_SESSION['glpiactiveentities_string'] = "'" . implode("', '", $newentities) . "'"; $active = reset($newentities); $_SESSION['glpiparententities'] = $ancestors; $_SESSION['glpiparententities_string'] = implode("', '", $ancestors); if (!empty($_SESSION['glpiparententities_string'])) { $_SESSION['glpiparententities_string'] = "'" . $_SESSION['glpiparententities_string'] . "'"; } // Active entity loading $_SESSION["glpiactive_entity"] = $active; $_SESSION["glpiactive_entity_name"] = Dropdown::getDropdownName("glpi_entities", $active); $_SESSION["glpiactive_entity_shortname"] = getTreeLeafValueName("glpi_entities", $active); if ($is_recursive) { $_SESSION["glpiactive_entity_name"] .= " (" . $LANG['entity'][7] . ")"; $_SESSION["glpiactive_entity_shortname"] .= " (" . $LANG['entity'][7] . ")"; } if ($ID == "all") { $_SESSION["glpiactive_entity_name"] .= " (" . $LANG['buttons'][40] . ")"; $_SESSION["glpiactive_entity_shortname"] .= " (" . $LANG['buttons'][40] . ")"; } if (countElementsInTable('glpi_entities') < count($_SESSION['glpiactiveentities'])) { $_SESSION['glpishowallentities'] = 1; } else { $_SESSION['glpishowallentities'] = 0; } // Clean session variable to search system if (isset($_SESSION['glpisearch']) && count($_SESSION['glpisearch'])) { foreach ($_SESSION['glpisearch'] as $itemtype => $tab) { if (isset($tab['start']) && $tab['start'] > 0) { $_SESSION['glpisearch'][$itemtype]['start'] = 0; } } } loadGroups(); doHook("change_entity"); return true; } return false; }
/** * transfer an item to another item (may be the same) in the new entity * * @param $itemtype item type to transfer * @param $ID ID of the item to transfer * @param $newID new ID of the ite * * Transfer item to a new Item if $ID==$newID : only update entities_id field : $ID!=$new ID -> copy datas (like template system) * @return nothing (diplays) **/ function transferItem($itemtype, $ID, $newID) { global $CFG_GLPI, $DB; if (!class_exists($itemtype)) { return; } $item = new $itemtype(); // Is already transfer ? if (!isset($this->already_transfer[$itemtype][$ID])) { // Check computer exists ? if ($item->getFromDB($newID)) { // Manage Ocs links $dataocslink = array(); $ocs_computer = false; if ($itemtype == 'Computer' && $CFG_GLPI['use_ocs_mode']) { $query = "SELECT *\n FROM `glpi_ocslinks`\n WHERE `computers_id` = '{$ID}'"; if ($result = $DB->query($query)) { if ($DB->numrows($result) > 0) { $dataocslink = $DB->fetch_assoc($result); $ocs_computer = true; } } } // Network connection ? keep connected / keep_disconnected / delete if (in_array($itemtype, array('Computer', 'Monitor', 'NetworkEquipment', 'Peripheral', 'Phone', 'Printer'))) { $this->transferNetworkLink($itemtype, $ID, $newID, $ocs_computer); } // Device : keep / delete : network case : delete if net connection delete in ocs case if (in_array($itemtype, array('Computer'))) { $this->transferDevices($itemtype, $ID, $ocs_computer); } // Reservation : keep / delete if (in_array($itemtype, $CFG_GLPI["reservation_types"])) { $this->transferReservations($itemtype, $ID, $newID); } // History : keep / delete $this->transferHistory($itemtype, $ID, $newID); // Ticket : delete / keep and clean ref / keep and move $this->transferTickets($itemtype, $ID, $newID); // Infocoms : keep / delete if (in_array($itemtype, $this->INFOCOMS_TYPES)) { $this->transferInfocoms($itemtype, $ID, $newID); } if ($itemtype == 'Software') { $this->transferSoftwareLicensesAndVersions($ID); } if ($itemtype == 'Computer') { // Monitor Direct Connect : keep / delete + clean unused / keep unused $this->transferDirectConnection($itemtype, $ID, 'Monitor', $ocs_computer); // Peripheral Direct Connect : keep / delete + clean unused / keep unused $this->transferDirectConnection($itemtype, $ID, 'Peripheral', $ocs_computer); // Phone Direct Connect : keep / delete + clean unused / keep unused $this->transferDirectConnection($itemtype, $ID, 'Phone'); // Printer Direct Connect : keep / delete + clean unused / keep unused $this->transferDirectConnection($itemtype, $ID, 'Printer', $ocs_computer); // Licence / Software : keep / delete + clean unused / keep unused $this->transferComputerSoftwares($ID, $ocs_computer); // Computer Disks : delete them or not ? $this->transferComputerDisks($ID); } // Computer Direct Connect : delete link if it is the initial transfer item (no recursion) if ($this->inittype == $itemtype && in_array($itemtype, array('Monitor', 'Phone', 'Peripheral', 'Printer'))) { $this->deleteDirectConnection($itemtype, $ID); } // Contract : keep / delete + clean unused / keep unused if (in_array($itemtype, $this->CONTRACTS_TYPES)) { $this->transferContracts($itemtype, $ID, $newID); } // Contact / Supplier : keep / delete + clean unused / keep unused if ($itemtype == 'Supplier') { $this->transferSupplierContacts($ID, $newID); } // Document : keep / delete + clean unused / keep unused if (in_array($itemtype, $this->DOCUMENTS_TYPES)) { $this->transferDocuments($itemtype, $ID, $newID); } // transfer compatible printers if ($itemtype == 'CartridgeItem') { $this->transferCompatiblePrinters($ID, $newID); } // Cartridges and cartridges items linked to printer if ($itemtype == 'Printer') { $this->transferPrinterCartridges($ID, $newID); } // Transfer Item $input = array('id' => $newID, 'entities_id' => $this->to); // Manage Location dropdown if (isset($item->fields['locations_id'])) { $input['locations_id'] = $this->transferDropdownLocation($item->fields['locations_id']); } if ($itemtype == 'Ticket') { $input2 = $this->transferTicketAdditionalInformations($item->fields); $input = array_merge($input, $input2); $this->transferTicketTaskCategory($ID, $newID); } $item->update($input); $this->addToAlreadyTransfer($itemtype, $ID, $newID); doHook("item_transfer", array('type' => $itemtype, 'id' => $ID, 'newID' => $newID)); } } }
/** * Restore an item trashed in the database. * * @param $input array : the _POST vars returned by the item form when press restore * @param $history boolean : do history log ? * * @return boolean : true on success **/ function restore($input, $history = 1) { if (!$this->getFromDB($input[$this->getIndexName()])) { return false; } if (isset($input['restore'])) { $input['_restore'] = $input['restore']; unset($input['restore']); } // Store input in the object to be available in all sub-method / hook $this->input = $input; doHook("pre_item_restore", $this); if ($this->restoreInDB()) { $this->addMessageOnRestoreAction(); if ($this->dohistory && $history) { $changes[0] = 0; $changes[1] = $changes[2] = ""; Log::history($this->input["id"], $this->getType(), $changes, 0, HISTORY_RESTORE_ITEM); } $this->post_restoreItem(); doHook("item_restore", $this); return true; } return false; }
function &getForTemplate($event, $options) { global $CFG_GLPI, $LANG; $this->datas = array(); $this->addTagToList(array('tag' => 'glpi.url', 'value' => $CFG_GLPI['root_doc'], 'label' => $LANG['setup'][227])); $this->getDatasForTemplate($event, $options); doHook('item_get_datas', $this); return $this->datas; }
/** * Process the rule * * @param $input the input data used to check criterias * @param $output the initial ouput array used to be manipulate by actions * @param $params parameters for all internal functions * * @return the output array updated by actions. If rule matched add field _rule_process to return value **/ function process(&$input, &$output, &$params) { if (count($this->criterias)) { $this->regex_results = array(); $this->criterias_results = array(); $input = $this->prepareInputDataForProcess($input, $params); if ($this->checkCriterias($input)) { $output = $this->executeActions($output, $params); //Hook $hook_params["sub_type"] = $this->getType(); $hook_params["ruleid"] = $this->fields["id"]; $hook_params["input"] = $input; $hook_params["output"] = $output; doHook("rule_matched", $hook_params); $output["_rule_process"] = true; unset($output["_no_rule_matches"]); } } }
/** * Init session for the user is defined * * @return nothing **/ function initSession() { global $CFG_GLPI, $LANG; if ($this->auth_succeded) { // Restart GLPi session : complete destroy to prevent lost datas $tosave = array('glpi_plugins', 'glpicookietest', 'phpCAS'); $save = array(); foreach ($tosave as $t) { if (isset($_SESSION[$t])) { $save[$t] = $_SESSION[$t]; } } $this->destroySession(); startGlpiSession(); $_SESSION = $save; // Normal mode for this request $_SESSION["glpi_use_mode"] = NORMAL_MODE; // Check ID exists and load complete user from DB (plugins...) if (isset($this->user->fields['id']) && $this->user->getFromDB($this->user->fields['id'])) { if (!$this->user->fields['is_deleted'] && $this->user->fields['is_active']) { $_SESSION["glpiID"] = $this->user->fields['id']; $_SESSION["glpiname"] = $this->user->fields['name']; $_SESSION["glpirealname"] = $this->user->fields['realname']; $_SESSION["glpifirstname"] = $this->user->fields['firstname']; $_SESSION["glpidefault_entity"] = $this->user->fields['entities_id']; $_SESSION["glpiusers_idisation"] = true; $_SESSION["glpiextauth"] = $this->extauth; $_SESSION["glpiauthtype"] = $this->user->fields['authtype']; $_SESSION["glpisearchcount"] = array(); $_SESSION["glpisearchcount2"] = array(); $_SESSION["glpiroot"] = $CFG_GLPI["root_doc"]; $_SESSION["glpi_use_mode"] = $this->user->fields['use_mode']; $_SESSION["glpicrontimer"] = time(); // Default tab // $_SESSION['glpi_tab']=1; $_SESSION['glpi_tabs'] = array(); $this->user->computePreferences(); foreach ($CFG_GLPI['user_pref_field'] as $field) { if (isset($this->user->fields[$field])) { $_SESSION["glpi{$field}"] = $this->user->fields[$field]; } } // Do it here : do not reset on each page, cause export issue if ($_SESSION["glpilist_limit"] > $CFG_GLPI['list_limit_max']) { $_SESSION["glpilist_limit"] = $CFG_GLPI['list_limit_max']; } // Init not set value for language if (empty($_SESSION["glpilanguage"])) { $_SESSION["glpilanguage"] = $CFG_GLPI['language']; } loadLanguage(); // glpiprofiles -> other available profile with link to the associated entities doHook("init_session"); initEntityProfiles(getLoginUserID()); // Use default profile if exist if (isset($_SESSION['glpiprofiles'][$this->user->fields['profiles_id']])) { changeProfile($this->user->fields['profiles_id']); } else { // Else use first changeProfile(key($_SESSION['glpiprofiles'])); } if (!isset($_SESSION["glpiactiveprofile"]["interface"])) { $this->auth_succeded = false; $this->addToError($LANG['login'][25]); } } else { $this->auth_succeded = false; $this->addToError($LANG['login'][20]); } } else { $this->auth_succeded = false; $this->addToError($LANG['login'][25]); } } }
// PLugin already included $PLUGINS_INCLUDED = 1; $LOADED_PLUGINS = array(); $plugin = new Plugin(); if (!isset($_SESSION["glpi_plugins"])) { $plugin->init(); } if (isset($_SESSION["glpi_plugins"]) && is_array($_SESSION["glpi_plugins"])) { //doHook("config"); if (count($_SESSION["glpi_plugins"])) { foreach ($_SESSION["glpi_plugins"] as $name) { Plugin::load($name); } } // For plugins which require action after all plugin init doHook("post_init"); } } if (!isset($_SESSION["MESSAGE_AFTER_REDIRECT"])) { $_SESSION["MESSAGE_AFTER_REDIRECT"] = ""; } // Manage force tab if (isset($_REQUEST['forcetab'])) { if (preg_match('/([a-zA-Z]+).form.php/', $_SERVER['PHP_SELF'], $matches)) { $itemtype = $matches[1]; setActiveTab($matches[1], $_REQUEST['forcetab']); } } // Manage tabs if (isset($_REQUEST['glpi_tab']) && isset($_REQUEST['itemtype'])) { setActiveTab($_REQUEST['itemtype'], $_REQUEST['glpi_tab']);