private function doSearch($itemtype, $params, array $forcedisplay = array()) { global $DEBUG_SQL; // check param itemtype exists (to avoid search errors) $this->assertTrue(is_subclass_of($itemtype, "CommonDBTM")); // login to glpi if needed if (!isset($_SESSION['glpiname'])) { $this->Login(); } // force session in debug mode (to store & retrieve sql errors) $glpi_use_mode = $_SESSION['glpi_use_mode']; $_SESSION['glpi_use_mode'] = Session::DEBUG_MODE; // don't compute last request from session $params['reset'] = 'reset'; // do search $params = Search::manageParams($itemtype, $params); $data = Search::getDatas($itemtype, $params, $forcedisplay); // append existing errors to returned data $data['last_errors'] = array(); if (isset($DEBUG_SQL['errors'])) { $data['last_errors'] = implode(', ', $DEBUG_SQL['errors']); unset($DEBUG_SQL['errors']); } // restore glpi mode to previous $_SESSION['glpi_use_mode'] = $glpi_use_mode; // do not store this search from session Search::resetSaveSearch(); return $data; }
/** * Change active profile to the $ID one. Update glpiactiveprofile session variable. * * @param $ID : ID of the new profile * * @return Nothing **/ function changeProfile($ID) { if (isset($_SESSION['glpiprofiles'][$ID]) && count($_SESSION['glpiprofiles'][$ID]['entities'])) { $profile = new Profile(); if ($profile->getFromDB($ID)) { $profile->cleanProfile(); $data = $profile->fields; $data['entities'] = $_SESSION['glpiprofiles'][$ID]['entities']; $_SESSION['glpiactiveprofile'] = $data; $_SESSION['glpiactiveentities'] = array(); Search::resetSaveSearch(); $active_entity_done = false; // Try to load default entity if it is a root entity foreach ($data['entities'] as $key => $val) { if ($val['id'] == $_SESSION["glpidefault_entity"]) { if (changeActiveEntities($val['id'], $val['is_recursive'])) { $active_entity_done = true; } } } if (!$active_entity_done) { // Try to load default entity if (!changeActiveEntities($_SESSION["glpidefault_entity"], true)) { // Load all entities changeActiveEntities("all"); } } doHook("change_profile"); } } // Clean specific datas if (isset($_SESSION['glpi_faqcategories'])) { unset($_SESSION['glpi_faqcategories']); } }
/** * Uninstall custom fields plugin * @return bool */ function pluginCustomfieldsUninstall() { global $LANG, $DB; // Cancel search in session (if search on customfields is in progress // before uninstall) Search::resetSaveSearch(); // Get customfields itemtypes $query = "SELECT `itemtype`\n FROM `glpi_plugin_customfields_itemtypes`\n WHERE `itemtype` <> 'Version'"; // Remove data tables $itemtypes = array(); if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $itemtypes[] = $data['itemtype']; $table = plugin_customfields_table($data['itemtype']); if ($table) { $query = "DROP TABLE IF EXISTS `{$table}`"; $DB->query($query) or die($DB->error()); } } } // Delete dropdown search option $query = "DELETE FROM glpi_displaypreferences \n WHERE itemtype = 'PluginCustomfieldsDropdownsItem'"; $DB->query($query) or die($DB->error()); // Delete object searchoption for itemptype existing links $searchopts_keys = array(); foreach ($itemtypes as $itemtype) { $searchoptions = plugin_customfields_getAddSearchOptions($itemtype); $searchopts_keys = array_merge(array_keys($searchoptions), $searchopts_keys); } $searchopts_keys_str = "'" . implode("', '", $searchopts_keys) . "'"; $query = "DELETE FROM glpi_displaypreferences\n WHERE num IN ({$searchopts_keys_str})"; $DB->query($query) or die($DB->error()); $query = "SELECT `dropdown_table`\n FROM `glpi_plugin_customfields_dropdowns`"; // Delete custom dropdown tables if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $table = $data['dropdown_table']; if ($table != '') { $query = "DROP TABLE IF EXISTS `{$table}`"; $DB->query($query) or die($DB->error()); } } } // Drop additional tables $tables = array('glpi_plugin_customfields_dropdowns', 'glpi_plugin_customfields_dropdownsitems', 'glpi_plugin_customfields_fields', 'glpi_plugin_customfields_itemtypes', 'glpi_plugin_customfields_profiles', 'glpi_plugin_customfields'); foreach ($tables as $table) { $DB->query("DROP TABLE `{$table}`"); } return true; }