function showMinimalList($params) { global $DB, $CFG_GLPI; // Instanciate an object to access method $item = NULL; $itemtype = $this->getType(); $itemtable = $this->getTable(); if (class_exists($itemtype)) { $item = new $itemtype(); } // Default values of parameters $p['link'] = array(); // $p['field'] = array(); // $p['contains'] = array(); // $p['searchtype'] = array(); // $p['sort'] = '1'; // $p['order'] = 'ASC'; // $p['start'] = 0; // $p['is_deleted'] = 0; $p['export_all'] = 0; $p['link2'] = ''; // $p['contains2'] = ''; // $p['field2'] = ''; // $p['itemtype2'] = ''; $p['searchtype2'] = ''; foreach ($params as $key => $val) { $p[$key] = $val; } if ($p['export_all']) { $p['start'] = 0; } // Manage defautlt seachtype value : for bookmark compatibility if (count($p['contains'])) { foreach ($p['contains'] as $key => $val) { if (!isset($p['searchtype'][$key])) { $p['searchtype'][$key] = 'contains'; } } } if (is_array($p['contains2']) && count($p['contains2'])) { foreach ($p['contains2'] as $key => $val) { if (!isset($p['searchtype2'][$key])) { $p['searchtype2'][$key] = 'contains'; } } } //$target = Toolbox::getItemTypeSearchURL($itemtype); $target = $CFG_GLPI["root_doc"] . "/plugins/resources/front/resourceresting.php"; $limitsearchopt = Search::getCleanedOptions("PluginResourcesResourceResting"); $LIST_LIMIT = $_SESSION['glpilist_limit']; // Set display type for export if define $output_type = Search::HTML_OUTPUT; if (isset($_GET['display_type'])) { $output_type = $_GET['display_type']; // Limit to 10 element if ($_GET['display_type'] == Search::GLOBAL_SEARCH) { $LIST_LIMIT = Search::GLOBAL_DISPLAY_COUNT; } } $PluginResourcesResource = new PluginResourcesResource(); $entity_restrict = $PluginResourcesResource->isEntityAssign(); // Get the items to display $toview = Search::addDefaultToView($itemtype); // Add items to display depending of personal prefs $displaypref = DisplayPreference::getForTypeUser("PluginResourcesResourceResting", Session::getLoginUserID()); if (count($displaypref)) { foreach ($displaypref as $val) { array_push($toview, $val); } } // Add searched items if (count($p['field']) > 0) { foreach ($p['field'] as $key => $val) { if (!in_array($val, $toview) && $val != 'all' && $val != 'view') { array_push($toview, $val); } } } // Add order item if (!in_array($p['sort'], $toview)) { array_push($toview, $p['sort']); } // Clean toview array $toview = array_unique($toview); foreach ($toview as $key => $val) { if (!isset($limitsearchopt[$val])) { unset($toview[$key]); } } $toview_count = count($toview); //// 1 - SELECT $query = "SELECT " . Search::addDefaultSelect($itemtype); // Add select for all toview item foreach ($toview as $key => $val) { $query .= Search::addSelect($itemtype, $val, $key, 0); } $query .= "`" . $itemtable . "`.`id` AS id "; //// 2 - FROM AND LEFT JOIN // Set reference table $query .= " FROM `" . $itemtable . "`"; // Init already linked tables array in order not to link a table several times $already_link_tables = array(); // Put reference table array_push($already_link_tables, $itemtable); // Add default join $COMMONLEFTJOIN = Search::addDefaultJoin($itemtype, $itemtable, $already_link_tables); $query .= $COMMONLEFTJOIN; $searchopt = array(); $searchopt[$itemtype] =& Search::getOptions($itemtype); // Add all table for toview items foreach ($toview as $key => $val) { $query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$val]["table"], $searchopt[$itemtype][$val]["linkfield"]); } // Search all case : if (in_array("all", $p['field'])) { foreach ($searchopt[$itemtype] as $key => $val) { // Do not search on Group Name if (is_array($val)) { $query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$key]["table"], $searchopt[$itemtype][$key]["linkfield"]); } } } //// 3 - WHERE // default string $COMMONWHERE = Search::addDefaultWhere($itemtype); $first = empty($COMMONWHERE); // Add deleted if item have it if ($item && $item->maybeDeleted()) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } $COMMONWHERE .= $LINK . "`{$itemtable}`.`is_deleted` = '" . $p['is_deleted'] . "' "; } // Remove template items if ($item && $item->maybeTemplate()) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } $COMMONWHERE .= $LINK . "`{$itemtable}`.`is_template` = '0' "; } // Add Restrict to current entities if ($entity_restrict) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } if ($itemtype == 'Entity') { $COMMONWHERE .= getEntitiesRestrictRequest($LINK, $itemtable, 'id', '', true); } else { if (isset($CFG_GLPI["union_search_type"]["PluginResourcesResource"])) { // Will be replace below in Union/Recursivity Hack $COMMONWHERE .= $LINK . " ENTITYRESTRICT "; } else { $COMMONWHERE .= getEntitiesRestrictRequest($LINK, "glpi_plugin_resources_resources", '', '', $PluginResourcesResource->maybeRecursive()); } } } ///R�cup�ration des groupes de l'utilisateur connect� $who = Session::getLoginUserID(); if (!plugin_resources_haveRight("all", "r")) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } $COMMONWHERE .= $LINK . "(`glpi_plugin_resources_resources`.`users_id_recipient` = '{$who}' OR `glpi_plugin_resources_resources`.`users_id` = '{$who}') "; } $WHERE = ""; $HAVING = ""; // Add search conditions // If there is search items if ($_SESSION["glpisearchcount"][$itemtype] > 0 && count($p['contains']) > 0) { for ($key = 0; $key < $_SESSION["glpisearchcount"][$itemtype]; $key++) { // if real search (strlen >0) and not all and view search if (isset($p['contains'][$key]) && strlen($p['contains'][$key]) > 0) { // common search if ($p['field'][$key] != "all" && $p['field'][$key] != "view") { $LINK = " "; $NOT = 0; $tmplink = ""; if (is_array($p['link']) && isset($p['link'][$key])) { if (strstr($p['link'][$key], "NOT")) { $tmplink = " " . str_replace(" NOT", "", $p['link'][$key]); $NOT = 1; } else { $tmplink = " " . $p['link'][$key]; } } else { $tmplink = " AND "; } if (isset($searchopt[$itemtype][$p['field'][$key]]["usehaving"])) { // Manage Link if not first item if (!empty($HAVING)) { $LINK = $tmplink; } // Find key $item_num = array_search($p['field'][$key], $toview); $HAVING .= Search::addHaving($LINK, $NOT, $itemtype, $p['field'][$key], $p['searchtype'][$key], $p['contains'][$key], 0, $item_num); } else { // Manage Link if not first item if (!empty($WHERE)) { $LINK = $tmplink; } $WHERE .= Search::addWhere($LINK, $NOT, $itemtype, $p['field'][$key], $p['searchtype'][$key], $p['contains'][$key]); } // view and all search } else { $LINK = " OR "; $NOT = 0; $globallink = " AND "; if (is_array($p['link']) && isset($p['link'][$key])) { switch ($p['link'][$key]) { case "AND": $LINK = " OR "; $globallink = " AND "; break; case "AND NOT": $LINK = " AND "; $NOT = 1; $globallink = " AND "; break; case "OR": $LINK = " OR "; $globallink = " OR "; break; case "OR NOT": $LINK = " AND "; $NOT = 1; $globallink = " OR "; break; } } else { $tmplink = " AND "; } // Manage Link if not first item if (!empty($WHERE)) { $WHERE .= $globallink; } $WHERE .= " ( "; $first2 = true; $items = array(); if ($p['field'][$key] == "all") { $items = $searchopt[$itemtype]; } else { // toview case : populate toview foreach ($toview as $key2 => $val2) { $items[$val2] = $searchopt[$itemtype][$val2]; } } foreach ($items as $key2 => $val2) { if (is_array($val2)) { // Add Where clause if not to be done in HAVING CLAUSE if (!isset($val2["usehaving"])) { $tmplink = $LINK; if ($first2) { $tmplink = " "; $first2 = false; } $WHERE .= Search::addWhere($tmplink, $NOT, $itemtype, $key2, $p['searchtype'][$key], $p['contains'][$key]); } } } $WHERE .= " ) "; } } } } if (!empty($WHERE) || !empty($COMMONWHERE)) { if (!empty($COMMONWHERE)) { $WHERE = ' WHERE ' . $COMMONWHERE . (!empty($WHERE) ? ' AND ( ' . $WHERE . ' )' : ''); } else { $WHERE = ' WHERE ' . $WHERE . ' '; } $first = false; } $query .= $WHERE; //// 7 - Manage GROUP BY $GROUPBY = ""; // Meta Search / Search All / Count tickets if (in_array('all', $p['field'])) { $GROUPBY = " GROUP BY `" . $itemtable . "`.`id`"; } if (empty($GROUPBY)) { foreach ($toview as $key2 => $val2) { if (!empty($GROUPBY)) { break; } if (isset($searchopt[$itemtype][$val2]["forcegroupby"])) { $GROUPBY = " GROUP BY `" . $itemtable . "`.`id`"; } } } $query .= $GROUPBY; //// 4 - ORDER $ORDER = " ORDER BY `id` "; foreach ($toview as $key => $val) { if ($p['sort'] == $val) { $ORDER = Search::addOrderBy($itemtype, $p['sort'], $p['order'], $key); } } $query .= $ORDER; // Get it from database if ($result = $DB->query($query)) { $numrows = $DB->numrows($result); $globallinkto = Search::getArrayUrlLink("field", $p['field']) . Search::getArrayUrlLink("link", $p['link']) . Search::getArrayUrlLink("contains", $p['contains']) . Search::getArrayUrlLink("field2", $p['field2']) . Search::getArrayUrlLink("contains2", $p['contains2']) . Search::getArrayUrlLink("itemtype2", $p['itemtype2']) . Search::getArrayUrlLink("link2", $p['link2']); $parameters = "sort=" . $p['sort'] . "&order=" . $p['order'] . $globallinkto; if ($output_type == Search::GLOBAL_SEARCH) { if (class_exists($itemtype)) { echo "<div class='center'><h2>" . $this->getTypeName(); // More items if ($numrows > $p['start'] + Search::GLOBAL_DISPLAY_COUNT) { echo " <a href='{$target}?{$parameters}'>" . __('All') . "</a>"; } echo "</h2></div>\n"; } else { return false; } } if ($p['start'] < $numrows) { // Pager if ($output_type == Search::HTML_OUTPUT) { Html::printPager($p['start'], $numrows, $target, $parameters, $itemtype); } //massive action $sel = ""; if (isset($_GET["select"]) && $_GET["select"] == "all") { $sel = "checked"; } // Add toview elements $nbcols = $toview_count; if ($output_type == Search::HTML_OUTPUT) { // HTML display - massive modif $nbcols++; } // Define begin and end var for loop // Search case $begin_display = $p['start']; $end_display = $p['start'] + $LIST_LIMIT; // Export All case if ($p['export_all']) { $begin_display = 0; $end_display = $numrows; } // Display List Header echo Search::showHeader($output_type, $end_display - $begin_display + 1, $nbcols); $header_num = 1; // Display column Headers for toview items echo Search::showNewLine($output_type); // Display column Headers for toview items foreach ($toview as $key => $val) { $linkto = ''; if (!isset($searchopt[$itemtype][$val]['nosort']) || !$searchopt[$itemtype][$val]['nosort']) { $linkto = "{$target}?itemtype={$itemtype}&sort=" . $val . "&order=" . ($p['order'] == "ASC" ? "DESC" : "ASC") . "&start=" . $p['start'] . $globallinkto; } echo Search::showHeaderItem($output_type, $searchopt[$itemtype][$val]["name"], $header_num, $linkto, $p['sort'] == $val, $p['order']); } // End Line for column headers echo Search::showEndLine($output_type); $DB->data_seek($result, $p['start']); // Define begin and end var for loop // Search case $i = $begin_display; // Init list of items displayed if ($output_type == Search::HTML_OUTPUT) { Session::initNavigateListItems($itemtype); } // Num of the row (1=header_line) $row_num = 1; // Display Loop while ($i < $numrows && $i < $end_display) { $item_num = 1; $data = $DB->fetch_array($result); $i++; $row_num++; echo Search::showNewLine($output_type, $i % 2); Session::addToNavigateListItems($itemtype, $data['id']); foreach ($toview as $key => $val) { echo Search::showItem($output_type, Search::giveItem($itemtype, $val, $data, $key), $item_num, $row_num, Search::displayConfigItem($itemtype, $val, $data, $key)); } echo Search::showEndLine($output_type); } // Close Table $title = ""; // Create title if ($output_type == Search::PDF_OUTPUT_PORTRAIT || $output_type == Search::PDF_OUTPUT_LANDSCAPE) { $title .= __('List of non contract periods', 'resources'); } // Display footer echo Search::showFooter($output_type, $title); // Pager if ($output_type == Search::HTML_OUTPUT) { echo "<br>"; Html::printPager($p['start'], $numrows, $target, $parameters); } } else { echo Search::showError($output_type); } } }
static function uninstall() { global $DB; $displayPreference = new DisplayPreference(); $displayPreference->deleteByCriteria(array('itemtype' => __CLASS__)); $table = getTableForItemType(__CLASS__); $DB->query("DROP TABLE IF EXISTS `{$table}`"); }
static function uninstall() { global $DB; $displayPreference = new DisplayPreference(); $displayPreference->deleteByCriteria(array('itemtype' => __CLASS__)); // Remove dropdowns localization $dropdownTranslation = new DropdownTranslation(); $dropdownTranslation->deleteByCriteria(array("itemtype = 'PluginSimcardSimcardSize'"), 1); $table = getTableForItemType(__CLASS__); $DB->query("DROP TABLE IF EXISTS `{$table}`"); }
/** * Install or update containers * * @param Migration $migration Migration instance * @param string $version Plugin current version * * @return boolean */ static function install(Migration $migration, $version) { global $DB; $obj = new self(); $table = $obj->getTable(); if (!TableExists($table)) { $migration->displayMessage(sprintf(__("Installing %s"), $table)); $query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n `id` INT(11) NOT NULL auto_increment,\n `name` VARCHAR(255) DEFAULT NULL,\n `label` VARCHAR(255) DEFAULT NULL,\n `itemtypes` LONGTEXT DEFAULT NULL,\n `type` VARCHAR(255) DEFAULT NULL,\n `subtype` VARCHAR(255) DEFAULT NULL,\n `entities_id` INT(11) NOT NULL DEFAULT '0',\n `is_recursive` TINYINT(1) NOT NULL DEFAULT '0',\n `is_active` TINYINT(1) NOT NULL DEFAULT '0',\n PRIMARY KEY (`id`),\n KEY `entities_id` (`entities_id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query) or die($DB->error()); } // multiple itemtype for one container if (!FieldExists($table, "itemtypes")) { $migration->changeField($table, 'itemtype', 'itemtypes', 'longtext'); $migration->migrationOneTable($table); $query = "UPDATE `{$table}` SET `itemtypes` = CONCAT('[\"', `itemtypes`, '\"]')"; $DB->query($query) or die($DB->error()); } //add display preferences for this class $d_pref = new DisplayPreference(); $found = $d_pref->find("itemtype = '" . __CLASS__ . "'"); if (count($found) == 0) { for ($i = 2; $i <= 5; $i++) { $DB->query("REPLACE INTO glpi_displaypreferences VALUES\n (NULL, '" . __CLASS__ . "', {$i}, " . ($i - 1) . ", 0)"); } } if (!FieldExists($table, "subtype")) { $migration->addField($table, 'subtype', 'VARCHAR(255) DEFAULT NULL', array('after' => 'type')); $migration->migrationOneTable($table); } $migration->displayMessage(__("Updating generated containers files", "fields")); // -> 0.90-1.3: generated class moved // OLD path: GLPI_ROOT."/plugins/fields/inc/$class_filename" // NEW path: PLUGINFIELDS_CLASS_PATH . "/$class_filename" $obj = new self(); $containers = $obj->find(); foreach ($containers as $container) { //First, drop old fields from plugin directories $itemtypes = count($container['itemtypes']) > 0 ? json_decode($container['itemtypes'], true) : array(); foreach ($itemtypes as $itemtype) { $class_filename = strtolower($itemtype . preg_replace('/s$/', '', $container['name']) . ".class.php"); if (file_exists(GLPI_ROOT . "/plugins/fields/inc/{$class_filename}")) { unlink(GLPI_ROOT . "/plugins/fields/inc/{$class_filename}"); } $injclass_filename = strtolower($itemtype . preg_replace('/s$/', '', $container['name']) . "injection.class.php"); if (file_exists(GLPI_ROOT . "/plugins/fields/inc/{$injclass_filename}")) { unlink(GLPI_ROOT . "/plugins/fields/inc/{$injclass_filename}"); } } //Second, create new files self::generateTemplate($container); } return true; }
static function install(Migration $migration) { global $DB; $obj = new self(); $table = $obj->getTable(); if (!TableExists($table)) { $migration->displayMessage("Installing {$table}"); $query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n `id` INT(11) NOT NULL auto_increment,\n `name` VARCHAR(255) DEFAULT NULL,\n `label` VARCHAR(255) DEFAULT NULL,\n `itemtype` VARCHAR(255) DEFAULT NULL,\n `type` VARCHAR(255) DEFAULT NULL,\n `subtype` VARCHAR(255) DEFAULT NULL,\n `entities_id` INT(11) NOT NULL DEFAULT '0',\n `is_recursive` TINYINT(1) NOT NULL DEFAULT '0',\n `is_active` TINYINT(1) NOT NULL DEFAULT '0',\n PRIMARY KEY (`id`),\n KEY `entities_id` (`entities_id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query) or die($DB->error()); } //add display preferences for this class $d_pref = new DisplayPreference(); $found = $d_pref->find("itemtype = '" . __CLASS__ . "'"); if (count($found) == 0) { for ($i = 2; $i <= 5; $i++) { $DB->query("INSERT INTO glpi_displaypreferences VALUES\n (NULL, '" . __CLASS__ . "', {$i}, " . ($i - 1) . ", 0)"); } } if (!FieldExists($table, "subtype")) { $migration->addField($table, 'subtype', 'VARCHAR(255) DEFAULT NULL', array('after' => 'type')); $migration->migrationOneTable($table); } return true; }
*/ // ---------------------------------------------------------------------- // Original Author of file: // Purpose of file: // ---------------------------------------------------------------------- define('GLPI_ROOT', '..'); include GLPI_ROOT . "/inc/includes.php"; header("Content-Type: text/html; charset=UTF-8"); header_nocache(); if (!isset($_REQUEST['glpi_tab'])) { exit; } checkLoginUser(); $user = new User(); switch ($_REQUEST['glpi_tab']) { case 2: $config = new Config(); $user->getFromDB(getLoginUserID()); $user->computePreferences(); $config->showFormUserPrefs($user->fields); break; case 3: DisplayPreference::showForUser(getLoginUserID()); break; default: $pref = new Preference(); if (!Plugin::displayAction($pref, $_REQUEST['glpi_tab'])) { $user->showMyForm($CFG_GLPI['root_doc'] . "/front/preference.php", getLoginUserID()); } } ajaxFooter();
/** * * * **/ static function uninstall() { global $DB; $displayPreference = new DisplayPreference(); $displayPreference->deleteByCriteria(array("`num` >= " . self::RESERVED_TYPE_RANGE_MIN . " AND `num` <= " . self::RESERVED_TYPE_RANGE_MAX)); $table = getTableForItemType(__CLASS__); $query = "DROP TABLE IF EXISTS `" . $table . "`"; $DB->query($query) or die($DB->error()); }
You should have received a copy of the GNU General Public License along with GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief */ if (!defined('GLPI_ROOT')) { include '../inc/includes.php'; } if (!strpos($_SERVER['PHP_SELF'], "popup")) { Html::header(__('Setup'), $_SERVER['PHP_SELF'], "config", "display"); } Session::checkSeveralRightsOr(array("search_config_global" => "w", "search_config" => "w")); $setupdisplay = new DisplayPreference(); if (isset($_POST["activate"])) { $setupdisplay->activatePerso($_POST); } else { if (isset($_POST["add"])) { $setupdisplay->add($_POST); } else { if (isset($_POST["delete"]) || isset($_POST["delete_x"])) { $setupdisplay->delete($_POST); } else { if (isset($_POST["up"]) || isset($_POST["up_x"])) { $setupdisplay->orderItem($_POST, 'up'); } else { if (isset($_POST["down"]) || isset($_POST["down_x"])) { $setupdisplay->orderItem($_POST, 'down'); }
along with GLPI; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -------------------------------------------------------------------------- */ // ---------------------------------------------------------------------- // Original Author of file: Julien Dombre // Purpose of file: // ---------------------------------------------------------------------- define('GLPI_ROOT', '..'); include GLPI_ROOT . "/inc/includes.php"; header("Content-Type: text/html; charset=UTF-8"); header_nocache(); if (!isset($_POST["id"]) || !isset($_POST["itemtype"])) { exit; } if (!isset($_REQUEST['glpi_tab'])) { exit; } $setupdisplay = new DisplayPreference(); if ($_POST["id"] < 0) { switch ($_REQUEST['glpi_tab']) { case 1: $setupdisplay->showFormGlobal($_POST['target'], $_POST["displaytype"]); break; case 2: checkRight('search_config', 'w'); $setupdisplay->showFormPerso($_POST['target'], $_POST["displaytype"]); break; } } ajaxFooter();
static function showMinimalList($params = array()) { global $DB, $CFG_GLPI; $item = new self(); $itemtype = $item->getType(); $itemtable = $item->getTable(); // Default values of parameters $p['link'] = array(); // $p['field'] = array(); // $p['contains'] = array(); // $p['searchtype'] = array(); // $p['sort'] = '1'; // $p['order'] = 'ASC'; // $p['start'] = 0; // $p['is_deleted'] = 0; $p['id'] = 0; $p['export_all'] = 0; $p['link2'] = ''; // $p['contains2'] = ''; // $p['field2'] = ''; // $p['itemtype2'] = ''; $p['searchtype2'] = ''; $p['withtemplate'] = 0; foreach ($params as $key => $val) { $p[$key] = $val; } $PluginResourcesResource = new PluginResourcesResource(); $PluginResourcesResource->getFromDB($p['id']); $canedit = $PluginResourcesResource->can($p['id'], 'w'); if (isset($_POST["start"])) { $p['start'] = $_POST["start"]; } else { $p['start'] = 0; } if (isset($_POST["sort"])) { $p['sort'] = $_POST["sort"]; } else { $p['sort'] = 1; } if (isset($_POST["order"]) && $_POST["order"] == "DESC") { $p['order'] = "DESC"; } else { $p['order'] = "ASC"; } // Manage defautll seachtype value : for bookmark compatibility if (count($p['contains'])) { foreach ($p['contains'] as $key => $val) { if (!isset($p['searchtype'][$key])) { $p['searchtype'][$key] = 'contains'; } } } if (is_array($p['contains2']) && count($p['contains2'])) { foreach ($p['contains2'] as $key => $val) { if (!isset($p['searchtype2'][$key])) { $p['searchtype2'][$key] = 'contains'; } } } $target = Toolbox::getItemTypeSearchURL($itemtype); $limitsearchopt = Search::getCleanedOptions($itemtype); $LIST_LIMIT = $_SESSION['glpilist_limit']; // Set display type for export if define $output_type = Search::HTML_OUTPUT; if (isset($_GET['display_type'])) { $output_type = $_GET['display_type']; // Limit to 10 element if ($_GET['display_type'] == Search::GLOBAL_SEARCH) { $LIST_LIMIT = Search::GLOBAL_DISPLAY_COUNT; } } $entity_restrict = $item->isEntityAssign(); // Get the items to display $toview = Search::addDefaultToView($itemtype); // Add items to display depending of personal prefs $displaypref = DisplayPreference::getForTypeUser($itemtype, Session::getLoginUserID()); if (count($displaypref)) { foreach ($displaypref as $val) { array_push($toview, $val); } } // Add searched items if (count($p['field']) > 0) { foreach ($p['field'] as $key => $val) { if (!in_array($val, $toview) && $val != 'all' && $val != 'view') { array_push($toview, $val); } } } // Add order item if (!in_array($p['sort'], $toview)) { array_push($toview, $p['sort']); } // Clean toview array $toview = array_unique($toview); foreach ($toview as $key => $val) { if (!isset($limitsearchopt[$val])) { unset($toview[$key]); } } $toview_count = count($toview); //// 1 - SELECT $query = "SELECT " . Search::addDefaultSelect($itemtype); // Add select for all toview item foreach ($toview as $key => $val) { $query .= Search::addSelect($itemtype, $val, $key, 0); } $query .= "`" . $itemtable . "`.`id` AS id "; //// 2 - FROM AND LEFT JOIN // Set reference table $query .= " FROM `" . $itemtable . "`"; // Init already linked tables array in order not to link a table several times $already_link_tables = array(); // Put reference table array_push($already_link_tables, $itemtable); // Add default join $COMMONLEFTJOIN = Search::addDefaultJoin($itemtype, $itemtable, $already_link_tables); $query .= $COMMONLEFTJOIN; $searchopt = array(); $searchopt[$itemtype] =& Search::getOptions($itemtype); // Add all table for toview items foreach ($toview as $key => $val) { $query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$val]["table"], $searchopt[$itemtype][$val]["linkfield"], 0, 0, $searchopt[$itemtype][$val]["joinparams"]); } // Search all case : if (in_array("all", $p['field'])) { foreach ($searchopt[$itemtype] as $key => $val) { // Do not search on Group Name if (is_array($val)) { $query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$key]["table"], $searchopt[$itemtype][$key]["linkfield"], 0, 0, $searchopt[$itemtype][$key]["joinparams"]); } } } $query .= " WHERE `" . $itemtable . "`.`plugin_resources_resources_id` = '" . $p['id'] . "'"; $query .= " AND `" . $itemtable . "`.`is_deleted` = '" . $p['is_deleted'] . "' "; //// 7 - Manage GROUP BY $GROUPBY = ""; // Meta Search / Search All / Count tickets if (in_array('all', $p['field'])) { $GROUPBY = " GROUP BY `" . $itemtable . "`.`id`"; } if (empty($GROUPBY)) { foreach ($toview as $key2 => $val2) { if (!empty($GROUPBY)) { break; } if (isset($searchopt[$itemtype][$val2]["forcegroupby"])) { $GROUPBY = " GROUP BY `" . $itemtable . "`.`id`"; } } } $query .= $GROUPBY; //// 4 - ORDER $ORDER = " ORDER BY `id` "; foreach ($toview as $key => $val) { if ($p['sort'] == $val) { $ORDER = Search::addOrderBy($itemtype, $p['sort'], $p['order'], $key); } } $query .= $ORDER; // Get it from database if ($result = $DB->query($query)) { $numrows = $DB->numrows($result); $globallinkto = Search::getArrayUrlLink("field", $p['field']) . Search::getArrayUrlLink("link", $p['link']) . Search::getArrayUrlLink("contains", $p['contains']) . Search::getArrayUrlLink("field2", $p['field2']) . Search::getArrayUrlLink("contains2", $p['contains2']) . Search::getArrayUrlLink("itemtype2", $p['itemtype2']) . Search::getArrayUrlLink("link2", $p['link2']); $parameters = "sort=" . $p['sort'] . "&order=" . $p['order'] . $globallinkto; if ($output_type == Search::GLOBAL_SEARCH) { if (class_exists($itemtype)) { echo "<div class='center'><h2>" . $item->getTypeName(); // More items if ($numrows > $p['start'] + Search::GLOBAL_DISPLAY_COUNT) { echo " <a href='{$target}?{$parameters}'>" . __('All') . "</a>"; } echo "</h2></div>\n"; } else { return false; } } if ($p['start'] < $numrows) { if ($output_type == Search::HTML_OUTPUT && !$p['withtemplate']) { echo "<div align='center'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/resources/front/task.php?contains%5B0%5D=" . $p['id'] . "&field%5B0%5D=13&sort=1&is_deleted=0&start=0'>" . _x('button', 'Search') . "</a><br>"; echo "</div>"; } // Pager if ($output_type == Search::HTML_OUTPUT) { // HTML display - massive modif $search_config = ""; if ($item->canCreate() && $canedit) { $tmp = " class='pointer' onClick=\"var w = window.open('" . $CFG_GLPI["root_doc"] . "/front/popup.php?popup=search_config&itemtype=" . $itemtype . "' ,'glpipopup', " . "'height=400, width=1000, top=100, left=100, scrollbars=yes' ); w.focus();\""; $search_config = "<img alt='" . __('Select default items to show') . "' title='" . __('Select default items to show') . "' src='" . $CFG_GLPI["root_doc"] . "/pics/options_search.png' "; $search_config .= $tmp . ">"; } //echo Search::showHeaderItem($output_type,$search_config,$header_num,"",0,$p['order']); } // Pager if ($output_type == Search::HTML_OUTPUT) { Html::printAjaxPager(self::getTypeName(2), $p['start'], $numrows, $search_config); echo "<br>"; } // Define begin and end var for loop // Search case $begin_display = $p['start']; $end_display = $p['start'] + $LIST_LIMIT; // Export All case if ($p['export_all']) { $begin_display = 0; $end_display = $numrows; } //massive action $sel = ""; if (isset($_GET["select"]) && $_GET["select"] == "all") { $sel = "checked"; } if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) { Html::openMassiveActionsForm('massform' . $itemtype); $massiveactionparams = array('num_displayed' => $end_display - $begin_display, 'fixed' => true, 'is_deleted' => $p['is_deleted']); Html::showMassiveActions($itemtype, $massiveactionparams); } // Add toview elements $nbcols = $toview_count; if ($output_type == Search::HTML_OUTPUT) { // HTML display - massive modif $nbcols++; } // Display List Header echo Search::showHeader($output_type, $end_display - $begin_display + 1, $nbcols, 1); $header_num = 1; // Display column Headers for toview items $headers_line = ''; $headers_line_top = ''; $headers_line_bottom = ''; echo Search::showNewLine($output_type); if ($output_type == Search::HTML_OUTPUT && $item->canCreate() && $canedit) { // HTML display - massive modif $headers_line_top .= Search::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']); $headers_line_bottom .= Search::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']); } // Display column Headers for toview items foreach ($toview as $key => $val) { $linkto = ''; if (!isset($searchopt[$itemtype][$val]['nosort']) || !$searchopt[$itemtype][$val]['nosort']) { $linkto = "javascript:reloadTab('sort=" . $val . "&order=" . ($p['order'] == "ASC" ? "DESC" : "ASC") . "&start=" . $p['start'] . $globallinkto . "')"; } $headers_line .= Search::showHeaderItem($output_type, $searchopt[$itemtype][$val]["name"], $header_num, $linkto, $p['sort'] == $val, $p['order']); } // End Line for column headers $headers_line .= Search::showEndLine($output_type); $headers_line_top .= $headers_line; $headers_line_bottom .= $headers_line; echo $headers_line_top; $DB->data_seek($result, $p['start']); // Define begin and end var for loop // Search case $i = $begin_display; // Init list of items displayed if ($output_type == Search::HTML_OUTPUT) { Session::initNavigateListItems($itemtype, PluginResourcesResource::getTypeName(2) . " = " . (empty($PluginResourcesResource->fields['name']) ? "(" . $p['id'] . ")" : $PluginResourcesResource->fields['name'])); } // Num of the row (1=header_line) $row_num = 1; // Display Loop while ($i < $numrows && $i < $end_display) { $item_num = 1; $data = $DB->fetch_array($result); $i++; $row_num++; echo Search::showNewLine($output_type, $i % 2); Session::addToNavigateListItems($itemtype, $data['id']); $tmpcheck = ""; if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) { $sel = ""; $tmpcheck = "<input type='checkbox' name='item[" . $data["id"] . "]' value='1' {$sel}>"; } echo Search::showItem($output_type, $tmpcheck, $item_num, $row_num, "width='10'"); foreach ($toview as $key => $val) { echo Search::showItem($output_type, Search::giveItem($itemtype, $val, $data, $key), $item_num, $row_num, Search::displayConfigItem($itemtype, $val, $data, $key)); } echo Search::showEndLine($output_type); } // Close Table $title = ""; // Create title if ($output_type == Search::PDF_OUTPUT_PORTRAIT || $output_type == Search::PDF_OUTPUT_LANDSCAPE) { $title .= __('Tasks list', 'resources'); } // Display footer echo Search::showFooter($output_type, $title); //massive action if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($itemtype, $massiveactionparams); Html::closeForm(); } else { echo "</table></div>"; } // Pager if ($output_type == Search::HTML_OUTPUT) { echo "<br>"; Html::printAjaxPager(self::getTypeName(2), $p['start'], $numrows); } } else { echo Search::showError($output_type); } } }
function showMinimalList($params) { global $DB, $CFG_GLPI; $itemtype = "PluginResourcesDirectory"; $itemtable = $this->table; if (class_exists($itemtype)) { $item = new $itemtype(); } // Default values of parameters $p['link'] = array(); // $p['field'] = array(); // $p['contains'] = array(); // $p['searchtype'] = array(); // $p['sort'] = '1'; // $p['order'] = 'ASC'; // $p['start'] = 0; // $p['is_deleted'] = 0; $p['id'] = 0; $p['withtemplate'] = 0; $p['export_all'] = 0; $p['link2'] = ''; // $p['contains2'] = ''; // $p['field2'] = ''; // $p['itemtype2'] = ''; $p['searchtype2'] = ''; foreach ($params as $key => $val) { $p[$key] = $val; } if ($p['export_all']) { $p['start'] = 0; } $PluginResourcesResource = new PluginResourcesResource(); $canedit = $PluginResourcesResource->can($p['id'], 'w'); // Manage defautlt seachtype value : for bookmark compatibility if (count($p['contains'])) { foreach ($p['contains'] as $key => $val) { if (!isset($p['searchtype'][$key])) { $p['searchtype'][$key] = 'contains'; } } } if (is_array($p['contains2']) && count($p['contains2'])) { foreach ($p['contains2'] as $key => $val) { if (!isset($p['searchtype2'][$key])) { $p['searchtype2'][$key] = 'contains'; } } } $target = $CFG_GLPI["root_doc"] . "/plugins/resources/front/directory.php"; $limitsearchopt = Search::getCleanedOptions("PluginResourcesDirectory"); $LIST_LIMIT = $_SESSION['glpilist_limit']; // Set display type for export if define $output_type = Search::HTML_OUTPUT; if (isset($_GET['display_type'])) { $output_type = $_GET['display_type']; // Limit to 10 element if ($_GET['display_type'] == Search::GLOBAL_SEARCH) { $LIST_LIMIT = Search::GLOBAL_DISPLAY_COUNT; } } $entity_restrict = $PluginResourcesResource->isEntityAssign(); // Get the items to display $toview = Search::addDefaultToView("User"); // Add items to display depending of personal prefs $displaypref = DisplayPreference::getForTypeUser("PluginResourcesDirectory", Session::getLoginUserID()); if (count($displaypref)) { foreach ($displaypref as $val) { array_push($toview, $val); } } // Add searched items if (count($p['field']) > 0) { foreach ($p['field'] as $key => $val) { if (!in_array($val, $toview) && $val != 'all' && $val != 'view') { array_push($toview, $val); } } } // Add order item if (!in_array($p['sort'], $toview)) { array_push($toview, $p['sort']); } // Clean toview array $toview = array_unique($toview); foreach ($toview as $key => $val) { if (!isset($limitsearchopt[$val])) { unset($toview[$key]); } } $toview_count = count($toview); //// 1 - SELECT $query = "SELECT " . Search::addDefaultSelect("User"); // Add select for all toview item foreach ($toview as $key => $val) { $query .= self::addSelect("PluginResourcesDirectory", $val, $key, 0); } $query .= "`glpi_plugin_resources_resources`.`id` AS id "; //// 2 - FROM AND LEFT JOIN // Set reference table $query .= " FROM `" . $itemtable . "`"; // Init already linked tables array in order not to link a table several times $already_link_tables = array(); // Put reference table array_push($already_link_tables, $itemtable); // Add default join $COMMONLEFTJOIN = Search::addDefaultJoin("PluginResourcesDirectory", $itemtable, $already_link_tables); $query .= $COMMONLEFTJOIN; $searchopt = array(); $searchopt["PluginResourcesDirectory"] =& Search::getOptions("PluginResourcesDirectory"); // Add all table for toview items foreach ($toview as $key => $val) { $query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt["PluginResourcesDirectory"][$val]["table"], $searchopt["PluginResourcesDirectory"][$val]["linkfield"], 0, 0, $searchopt["PluginResourcesDirectory"][$val]["joinparams"]); } // Search all case : if (in_array("all", $p['field'])) { foreach ($searchopt[$itemtype] as $key => $val) { // Do not search on Group Name if (is_array($val)) { $query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt["PluginResourcesDirectory"][$key]["table"], $searchopt["PluginResourcesDirectory"][$key]["linkfield"], 0, 0, $searchopt["PluginResourcesDirectory"][$key]["joinparams"]); } } } $ASSIGN = " `glpi_plugin_resources_resources`.`is_leaving` = 0 AND `glpi_users`.`is_active` = 1 AND "; //// 3 - WHERE // default string $COMMONWHERE = Search::addDefaultWhere($itemtype); $first = empty($COMMONWHERE); // Add deleted if item have it if ($PluginResourcesResource && $PluginResourcesResource->maybeDeleted()) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } $COMMONWHERE .= $LINK . "`glpi_plugin_resources_resources`.`is_deleted` = '" . $p['is_deleted'] . "' "; } // Remove template items if ($PluginResourcesResource && $PluginResourcesResource->maybeTemplate()) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } $COMMONWHERE .= $LINK . "`glpi_plugin_resources_resources`.`is_template` = '0' "; } // Add Restrict to current entities if ($entity_restrict) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } if (isset($CFG_GLPI["union_search_type"][$itemtype])) { // Will be replace below in Union/Recursivity Hack $COMMONWHERE .= $LINK . " ENTITYRESTRICT "; } else { $COMMONWHERE .= getEntitiesRestrictRequest($LINK, "glpi_plugin_resources_resources", '', '', $PluginResourcesResource->maybeRecursive()); } } $WHERE = ""; $HAVING = ""; // Add search conditions // If there is search items if ($_SESSION["glpisearchcount"]["PluginResourcesDirectory"] > 0 && count($p['contains']) > 0) { for ($key = 0; $key < $_SESSION["glpisearchcount"]["PluginResourcesDirectory"]; $key++) { // if real search (strlen >0) and not all and view search if (isset($p['contains'][$key]) && strlen($p['contains'][$key]) > 0) { // common search if ($p['field'][$key] != "all" && $p['field'][$key] != "view") { $LINK = " "; $NOT = 0; $tmplink = ""; if (is_array($p['link']) && isset($p['link'][$key])) { if (strstr($p['link'][$key], "NOT")) { $tmplink = " " . str_replace(" NOT", "", $p['link'][$key]); $NOT = 1; } else { $tmplink = " " . $p['link'][$key]; } } else { $tmplink = " AND "; } if (isset($searchopt["PluginResourcesDirectory"][$p['field'][$key]]["usehaving"])) { // Manage Link if not first item if (!empty($HAVING)) { $LINK = $tmplink; } // Find key $item_num = array_search($p['field'][$key], $toview); $HAVING .= Search::addHaving($LINK, $NOT, "PluginResourcesDirectory", $p['field'][$key], $p['searchtype'][$key], $p['contains'][$key], 0, $item_num); } else { // Manage Link if not first item if (!empty($WHERE)) { $LINK = $tmplink; } $WHERE .= self::addWhere($LINK, $NOT, "PluginResourcesDirectory", $p['field'][$key], $p['searchtype'][$key], $p['contains'][$key]); } // view and all search } else { $LINK = " OR "; $NOT = 0; $globallink = " AND "; if (is_array($p['link']) && isset($p['link'][$key])) { switch ($p['link'][$key]) { case "AND": $LINK = " OR "; $globallink = " AND "; break; case "AND NOT": $LINK = " AND "; $NOT = 1; $globallink = " AND "; break; case "OR": $LINK = " OR "; $globallink = " OR "; break; case "OR NOT": $LINK = " AND "; $NOT = 1; $globallink = " OR "; break; } } else { $tmplink = " AND "; } // Manage Link if not first item if (!empty($WHERE)) { $WHERE .= $globallink; } $WHERE .= " ( "; $first2 = true; $items = array(); if ($p['field'][$key] == "all") { $items = $searchopt["PluginResourcesDirectory"]; } else { // toview case : populate toview foreach ($toview as $key2 => $val2) { $items[$val2] = $searchopt["PluginResourcesDirectory"][$val2]; } } foreach ($items as $key2 => $val2) { if (is_array($val2)) { // Add Where clause if not to be done in HAVING CLAUSE if (!isset($val2["usehaving"])) { $tmplink = $LINK; if ($first2) { $tmplink = " "; $first2 = false; } $WHERE .= self::addWhere($tmplink, $NOT, "PluginResourcesDirectory", $key2, $p['searchtype'][$key], $p['contains'][$key]); } } } $WHERE .= " ) "; } } } } if (!empty($WHERE) || !empty($COMMONWHERE)) { if (!empty($COMMONWHERE)) { $WHERE = ' WHERE ' . $ASSIGN . ' ' . $COMMONWHERE . (!empty($WHERE) ? ' AND ( ' . $WHERE . ' )' : ''); } else { $WHERE = ' WHERE ' . $ASSIGN . ' ' . $WHERE . ' '; } $first = false; } $query .= $WHERE; //// 7 - Manage GROUP BY $GROUPBY = ""; // Meta Search / Search All / Count tickets if (in_array('all', $p['field'])) { $GROUPBY = " GROUP BY `" . $itemtable . "`.`id`"; } if (empty($GROUPBY)) { foreach ($toview as $key2 => $val2) { if (!empty($GROUPBY)) { break; } if (isset($searchopt["PluginResourcesDirectory"][$val2]["forcegroupby"])) { $GROUPBY = " GROUP BY `" . $itemtable . "`.`id`"; } } } $query .= $GROUPBY; //// 4 - ORDER $ORDER = " ORDER BY `id` "; foreach ($toview as $key => $val) { if ($p['sort'] == $val) { $ORDER = Search::addOrderBy($itemtype, $p['sort'], $p['order'], $key); } } $query .= $ORDER; // Get it from database if ($result = $DB->query($query)) { $numrows = $DB->numrows($result); $globallinkto = Search::getArrayUrlLink("field", $p['field']) . Search::getArrayUrlLink("link", $p['link']) . Search::getArrayUrlLink("contains", $p['contains']) . Search::getArrayUrlLink("searchtype", $p['searchtype']) . Search::getArrayUrlLink("field2", $p['field2']) . Search::getArrayUrlLink("contains2", $p['contains2']) . Search::getArrayUrlLink("searchtype2", $p['searchtype2']) . Search::getArrayUrlLink("itemtype2", $p['itemtype2']) . Search::getArrayUrlLink("link2", $p['link2']); $parameters = "sort=" . $p['sort'] . "&order=" . $p['order'] . $globallinkto; if ($output_type == Search::GLOBAL_SEARCH) { if (class_exists($itemtype)) { echo "<div class='center'><h2>" . $this->getTypeName(); // More items if ($numrows > $p['start'] + Search::GLOBAL_DISPLAY_COUNT) { echo " <a href='{$target}?{$parameters}'>" . __('All') . "</a>"; } echo "</h2></div>\n"; } else { return false; } } if ($p['start'] < $numrows) { // Pager if ($output_type == Search::HTML_OUTPUT) { // HTML display - massive modif $search_config = ""; if ($item->canCreate() && $canedit) { $tmp = " class='pointer' onClick=\"var w = window.open('" . $CFG_GLPI["root_doc"] . "/front/popup.php?popup=search_config&itemtype=" . $itemtype . "' ,'glpipopup', " . "'height=400, width=1000, top=100, left=100, scrollbars=yes' ); w.focus();\""; $search_config = "<img alt='" . __('Select default items to show') . "' title='" . __('Select default items to show') . "' src='" . $CFG_GLPI["root_doc"] . "/pics/options_search.png' "; $search_config .= $tmp . ">"; } //echo Search::showHeaderItem($output_type,$search_config,$header_num,"",0,$p['order']); } // Pager if ($output_type == Search::HTML_OUTPUT) { Html::printPager($p['start'], $numrows, $target, $parameters, $itemtype, 0, $search_config); echo "<br>"; } // Define begin and end var for loop // Search case $begin_display = $p['start']; $end_display = $p['start'] + $LIST_LIMIT; // Export All case if ($p['export_all']) { $begin_display = 0; $end_display = $numrows; } //massive action $sel = ""; if (isset($_GET["select"]) && $_GET["select"] == "all") { $sel = "checked"; } if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) { Html::openMassiveActionsForm('massform' . $itemtype); $massiveactionparams = array('num_displayed' => $end_display - $begin_display, 'fixed' => false, 'is_deleted' => $p['is_deleted']); Html::showMassiveActions("PluginResourcesDirectory", $massiveactionparams); } // Add toview elements $nbcols = $toview_count; if ($output_type == Search::HTML_OUTPUT) { // HTML display - massive modif $nbcols++; } // Display List Header echo Search::showHeader($output_type, $end_display - $begin_display + 1, $nbcols); $header_num = 1; // Display column Headers for toview items $headers_line = ''; $headers_line_top = ''; $headers_line_bottom = ''; echo Search::showNewLine($output_type); if ($output_type == Search::HTML_OUTPUT && $item->canCreate() && $canedit) { // HTML display - massive modif $headers_line_top .= Search::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']); $headers_line_bottom .= Search::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']); } // Display column Headers for toview items foreach ($toview as $key => $val) { $linkto = ''; if (!isset($searchopt["PluginResourcesDirectory"][$val]['nosort']) || !$searchopt["PluginResourcesDirectory"][$val]['nosort']) { $linkto = "javascript:reloadTab('sort=" . $val . "&order=" . ($p['order'] == "ASC" ? "DESC" : "ASC") . "&start=" . $p['start'] . $globallinkto . "')"; } $headers_line .= Search::showHeaderItem($output_type, $searchopt["PluginResourcesDirectory"][$val]["name"], $header_num, $linkto, $p['sort'] == $val, $p['order']); } // End Line for column headers $headers_line .= Search::showEndLine($output_type); $headers_line_top .= $headers_line; $headers_line_bottom .= $headers_line; echo $headers_line_top; $DB->data_seek($result, $p['start']); // Define begin and end var for loop // Search case $i = $begin_display; // Init list of items displayed if ($output_type == Search::HTML_OUTPUT) { Session::initNavigateListItems($itemtype); } // Num of the row (1=header_line) $row_num = 1; // Display Loop while ($i < $numrows && $i < $end_display) { $item_num = 1; $data = $DB->fetch_array($result); $i++; $row_num++; echo Search::showNewLine($output_type, $i % 2); Session::addToNavigateListItems($itemtype, $data['id']); $tmpcheck = ""; if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) { $sel = ""; $tmpcheck = "<input type='checkbox' name='item[" . $data["id"] . "]' value='1' {$sel}>"; echo Search::showItem($output_type, $tmpcheck, $item_num, $row_num, "width='10'"); } foreach ($toview as $key => $val) { echo Search::showItem($output_type, Search::giveItem("PluginResourcesDirectory", $val, $data, $key), $item_num, $row_num, Search::displayConfigItem("PluginResourcesDirectory", $val, $data, $key)); } echo Search::showEndLine($output_type); } // Close Table $title = ""; // Create title if ($output_type == Search::PDF_OUTPUT_PORTRAIT || $output_type == Search::PDF_OUTPUT_LANDSCAPE) { $title .= self::getTypeName(1); } // Display footer echo Search::showFooter($output_type, $title); //massive action if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) { $massiveactionparams['ontop'] = false; $massiveactionparams['fixed'] = false; Html::showMassiveActions("PluginResourcesDirectory", $massiveactionparams); Html::closeForm(); } else { echo "</table></div>"; } // Pager if ($output_type == Search::HTML_OUTPUT) { echo "<br>"; Html::printPager($p['start'], $numrows, $target, $parameters, "PluginResourcesDirectory", 0, $search_config); } } else { echo Search::showError($output_type); } } }
/** * Prepare search criteria to be used for a search * * @since version 0.85 * * @param $itemtype item type * @param $params array of parameters * may include sort, order, start, list_limit, deleted, criteria, metacriteria * @param $forcedisplay array of columns to display (default empty = empty use display pref and search criterias) * * @return array prepare to be used for a search (include criterias and others needed informations) **/ static function prepareDatasForSearch($itemtype, array $params, array $forcedisplay = array()) { global $CFG_GLPI; // Default values of parameters $p['criteria'] = array(); $p['metacriteria'] = array(); $p['sort'] = '1'; // $p['order'] = 'ASC'; // $p['start'] = 0; // $p['is_deleted'] = 0; $p['export_all'] = 0; if (class_exists($itemtype)) { $p['target'] = $itemtype::getSearchURL(); } else { $p['target'] = Toolbox::getItemTypeSearchURL($itemtype); } $p['display_type'] = self::HTML_OUTPUT; $p['list_limit'] = $_SESSION['glpilist_limit']; $p['massiveactionparams'] = array(); foreach ($params as $key => $val) { $p[$key] = $val; } // Set display type for export if define if (isset($p['display_type'])) { // Limit to 10 element if ($p['display_type'] == self::GLOBAL_SEARCH) { $p['list_limit'] = self::GLOBAL_DISPLAY_COUNT; } } if ($p['export_all']) { $p['start'] = 0; } $data = array(); $data['search'] = $p; $data['itemtype'] = $itemtype; // Instanciate an object to access method $data['item'] = NULL; if ($itemtype != 'AllAssets') { $data['item'] = getItemForItemtype($itemtype); } $data['display_type'] = $data['search']['display_type']; if (!$CFG_GLPI['allow_search_all']) { foreach ($p['criteria'] as $val) { if ($val['field'] == 'all') { Html::displayRightError(); } } } if (!$CFG_GLPI['allow_search_view']) { foreach ($p['criteria'] as $val) { if ($val['field'] == 'view') { Html::displayRightError(); } } } /// Get the items to display // Add searched items $forcetoview = false; if (is_array($forcedisplay) && count($forcedisplay)) { $forcetoview = true; } $data['search']['all_search'] = false; $data['search']['view_search'] = false; // If no research limit research to display item and compute number of item using simple request $data['search']['no_search'] = true; $data['toview'] = self::addDefaultToView($itemtype); if (!$forcetoview) { // Add items to display depending of personal prefs $displaypref = DisplayPreference::getForTypeUser($itemtype, Session::getLoginUserID()); if (count($displaypref)) { foreach ($displaypref as $val) { array_push($data['toview'], $val); } } } if (count($p['criteria']) > 0) { foreach ($p['criteria'] as $key => $val) { if (!in_array($val['field'], $data['toview'])) { if ($val['field'] != 'all' && $val['field'] != 'view') { array_push($data['toview'], $val['field']); } else { if ($val['field'] == 'all') { $data['search']['all_search'] = true; } else { if ($val['field'] == 'view') { $data['search']['view_search'] = true; } } } } if (isset($val['value']) && strlen($val['value']) > 0) { $data['search']['no_search'] = false; } } } if (count($p['metacriteria'])) { $data['search']['no_search'] = false; } // Add order item if (!in_array($p['sort'], $data['toview'])) { array_push($data['toview'], $p['sort']); } // Special case for Ticket : put ID in front if ($itemtype == 'Ticket') { array_unshift($data['toview'], 2); } $limitsearchopt = self::getCleanedOptions($itemtype); // Clean and reorder toview $tmpview = array(); foreach ($data['toview'] as $key => $val) { if (isset($limitsearchopt[$val]) && !in_array($val, $tmpview)) { $tmpview[] = $val; } } $data['toview'] = $tmpview; $data['tocompute'] = $data['toview']; // Force item to display if ($forcetoview) { foreach ($data['toview'] as $val) { if (!in_array($val, $data['tocompute'])) { array_push($data['tocompute'], $val); } } } return $data; }
/** * Display detail networkport based on glpi core networkport and fusioninventory * networkport * * @param array $data with id ant fusionid * @param boolean $monitoring true if monitoring installed && actived * @param boolean $aggrega true if this port is aggregate port * * @return nothing */ function showNetworkPortDetail($data, $monitoring, $aggrega = 0) { global $CFG_GLPI, $DB; $nw = new NetworkPort_NetworkPort(); $networkName = new NetworkName(); $networkPort = new NetworkPort(); $pfNetworkPort = new PluginFusioninventoryNetworkPort(); $iPAddress = new IPAddress(); $networkPort->getFromDB($data['id']); $pfNetworkPort->getFromDB($data['fusionid']); $background_img = ""; if ($pfNetworkPort->fields["trunk"] == "1" && (strstr($pfNetworkPort->fields["ifstatus"], "up") || $pfNetworkPort->fields["ifstatus"] == 1)) { $background_img = " style='background-image: url(\"" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/port_trunk.png\"); '"; } else { if (PluginFusioninventoryNetworkPort::isPortHasMultipleMac($data['id']) && (strstr($pfNetworkPort->fields["ifstatus"], "up") || $pfNetworkPort->fields["ifstatus"] == 1)) { $background_img = " style='background-image: url(\"" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/multiple_mac_addresses.png\"); '"; } else { if (strstr($pfNetworkPort->fields["ifstatus"], "up") || $pfNetworkPort->fields["ifstatus"] == 1) { $background_img = " style='background-image: url(\"" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/connected_trunk.png\"); '"; } } } echo "<tr class='tab_bg_1 center' height='40'" . $background_img . ">"; if ($aggrega) { echo "<td style='background-color: #f2f2f2;'></td><td>"; } if (!$aggrega) { if ($networkPort->fields['instantiation_type'] == 'NetworkPortAggregate') { echo "<td>"; } else { echo "<td colspan='2'>"; } } echo "<a href='networkport.form.php?id=" . $networkPort->fields["id"] . "'>" . $networkPort->fields["name"] . "</a>"; Html::showToolTip($pfNetworkPort->fields['ifdescr']); if (!$aggrega) { if ($networkPort->fields['instantiation_type'] == 'NetworkPortAggregate') { echo "<td><i><font style='color: grey'>" . __('Aggregation port') . "</font></i></td>"; } } if ($monitoring == '1') { echo "<td>"; $state = PluginMonitoringNetworkport::isMonitoredNetworkport($data['id']); if (Session::haveRight("plugin_monitoring_componentscatalog", UPDATE)) { $checked = ''; if ($state) { $checked = 'checked'; } echo "<input type='checkbox' name='networkports_id[]' value='" . $data['id'] . "' " . $checked . "/>"; } else { if (Session::haveRight("plugin_monitoring_componentscatalog", READ)) { echo Dropdown::getYesNo($state); } } echo "</td>"; } $a_pref = DisplayPreference::getForTypeUser('PluginFusioninventoryNetworkport', Session::getLoginUserID()); foreach ($a_pref as $data_array) { switch ($data_array) { case 3: echo "<td>" . $pfNetworkPort->fields["ifmtu"] . "</td>"; break; case 5: echo "<td>" . $this->byteSize($pfNetworkPort->fields["ifspeed"], 1000) . "bps</td>"; break; case 6: echo "<td>"; if (strstr($pfNetworkPort->fields["ifstatus"], "up") || strstr($pfNetworkPort->fields["ifinternalstatus"], "1")) { echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/greenbutton.png'/>"; } else { if (strstr($pfNetworkPort->fields["ifstatus"], "down") || strstr($pfNetworkPort->fields["ifinternalstatus"], "2")) { echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png'/>"; } else { if (strstr($pfNetworkPort->fields["ifstatus"], "testing") || strstr($pfNetworkPort->fields["ifinternalstatus"], "3")) { echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/yellowbutton.png'/>"; } } } echo "</td>"; break; case 7: echo "<td>" . $pfNetworkPort->fields["iflastchange"] . "</td>"; break; case 8: echo "<td>"; if ($pfNetworkPort->fields["ifinoctets"] == "0") { echo "-"; } else { echo $this->byteSize($pfNetworkPort->fields["ifinoctets"], 1000) . "o"; } echo " / "; if ($pfNetworkPort->fields["ifinoctets"] == "0") { echo "-"; } else { echo $this->byteSize($pfNetworkPort->fields["ifoutoctets"], 1000) . "o"; } echo "</td>"; break; case 9: $color = ''; if ($pfNetworkPort->fields["ifinerrors"] != "0" || $pfNetworkPort->fields["ifouterrors"] != "0") { $color = "background='#cf9b9b' class='tab_bg_1_2'"; } if ($pfNetworkPort->fields["ifinerrors"] == "0") { echo "<td " . $color . ">-"; } else { echo "<td " . $color . ">"; echo $pfNetworkPort->fields["ifinerrors"]; } echo " / "; if ($pfNetworkPort->fields["ifouterrors"] == "0") { echo "-"; } else { echo $pfNetworkPort->fields["ifouterrors"]; } echo "</td>"; break; case 10: if ($pfNetworkPort->fields["portduplex"] == 2) { echo "<td background='#cf9b9b' class='tab_bg_1_2'>"; echo __('Half', 'fusioninventory'); echo '</td>'; } else { if ($pfNetworkPort->fields["portduplex"] == 3) { echo '<td>'; echo __('Full', 'fusioninventory'); echo '</td>'; } else { echo "<td></td>"; } } break; case 11: // ** internal mac echo "<td>" . $networkPort->fields["mac"] . "</td>"; break; case 13: // ** Mac address and link to device which are connected to this port $opposite_port = $nw->getOppositeContact($data["id"]); if ($opposite_port != "" && $opposite_port != 0) { $networkPortOpposite = new NetworkPort(); if ($networkPortOpposite->getFromDB($opposite_port)) { $data_device = $networkPortOpposite->fields; $item = new $data_device["itemtype"](); $item->getFromDB($data_device["items_id"]); $link1 = $item->getLink(1); $link = str_replace($item->getName(0), $data_device["mac"], $item->getLink()); // * GetIP $a_networknames = current($networkName->find("`itemtype`='NetworkPort'\n AND `items_id`='" . $item->getID() . "'", "", 1)); $a_ipaddresses = current($iPAddress->find("`itemtype`='NetworkName'\n AND `items_id`='" . $a_networknames['id'] . "'", "", 1)); $link2 = str_replace($item->getName(0), $a_ipaddresses['name'], $item->getLink()); if ($data_device["itemtype"] == 'PluginFusioninventoryUnmanaged') { $icon = $this->getItemtypeIcon($item->fields["item_type"]); if ($item->getField("accepted") == "1") { echo "<td style='background:#bfec75'\n class='tab_bg_1_2'>" . $icon . $link1; } else { echo "<td background='#cf9b9b'\n class='tab_bg_1_2'>" . $icon . $link1; } if (!empty($link)) { echo "<br/>" . $link; } if (!empty($link2)) { echo "<br/>" . $link2; } if ($item->getField("hub") == "1") { $this->displayHubConnections($data_device["items_id"], $background_img); } echo "</td>"; } else { $icon = $this->getItemtypeIcon($data_device["itemtype"]); echo "<td>" . $icon . $link1; if (!empty($link)) { echo "<br/>" . $link; } if (!empty($link2)) { echo "<br/>" . $link2; } if ($data_device["itemtype"] == 'Phone') { $query_devicephone = "SELECT *\n FROM `glpi_networkports`\n WHERE `itemtype`='Phone'\n AND `items_id`='" . $data_device["items_id"] . "'\n AND `id`!='" . $data_device["id"] . "'\n LIMIT 1"; $result_devicephone = $DB->query($query_devicephone); if ($DB->numrows($result_devicephone) > 0) { $data_devicephone = $DB->fetch_assoc($result_devicephone); $computer_ports_id = $nw->getOppositeContact($data_devicephone["id"]); if ($computer_ports_id) { $networkport = new NetworkPort(); $networkport->getFromDB($computer_ports_id); if ($networkport->fields['itemtype'] == 'Computer') { echo "<hr/>"; echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/computer_icon.png' " . "style='float:left'/> "; $computer = new Computer(); $computer->getFromDB($networkport->fields["items_id"]); $link1 = $computer->getLink(1); $link = str_replace($computer->getName(0), $networkport->fields["mac"], $computer->getLink()); $link2 = str_replace($computer->getName(0), $networkport->fields["ip"], $computer->getLink()); echo $icon . $link1; if (!empty($link)) { echo "<br/>" . $link; } if (!empty($link2)) { echo "<br/>" . $link2; } } } } } echo "</td>"; } } else { echo "<td></td>"; } } else { echo "<td></td>"; } break; case 14: // ** Connection status echo "<td>"; if (strstr($pfNetworkPort->fields["ifstatus"], "up") || strstr($pfNetworkPort->fields["ifstatus"], "1")) { echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/wired_on.png'/>"; } else { if (strstr($pfNetworkPort->fields["ifstatus"], "down") || strstr($pfNetworkPort->fields["ifstatus"], "2")) { echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/wired_off.png'/>"; } else { if (strstr($pfNetworkPort->fields["ifstatus"], "testing") || strstr($pfNetworkPort->fields["ifstatus"], "3")) { echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/yellowbutton.png'/>"; } else { if (strstr($pfNetworkPort->fields["ifstatus"], "dormant") || strstr($pfNetworkPort->fields["ifstatus"], "5")) { echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/orangebutton.png'/>"; } } } } echo "</td>"; break; case 12: echo "<td>"; $canedit = Session::haveRight('networking', UPDATE); $used = array(); $query_vlan = "SELECT * FROM glpi_networkports_vlans\n WHERE networkports_id='" . $data["id"] . "'"; $result_vlan = $DB->query($query_vlan); if ($DB->numrows($result_vlan) > 0) { echo "<table cellpadding='0' cellspacing='0'>"; while ($line = $DB->fetch_array($result_vlan)) { $used[] = $line["vlans_id"]; $vlan = new Vlan(); $vlan->getFromDB($line["vlans_id"]); if ($line['tagged'] == '1') { $state = 'T'; } else { $state = 'U'; } echo "<tr><td>" . $vlan->fields['name'] . " [" . $vlan->fields['tag'] . "] " . $state; echo "</td><td>"; if ($canedit) { echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?unassign_vlan=unassigned&id=" . $line["id"] . "'>"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/delete.png\" alt='" . __('Delete', 'fusioninventory') . "' title='" . __('Delete', 'fusioninventory') . "'></a>"; } else { echo " "; } echo "</td>"; echo "</tr>"; } echo "</table>"; } else { echo " "; } echo "</td>"; break; case 15: echo "<td align='center'>"; if ($pfNetworkPort->fields['ifstatus'] == 1) { echo __('Connected'); } else { if ($pfNetworkPort->fields['lastup'] == "0000-00-00 00:00:00") { echo '-'; } else { $time = strtotime(date('Y-m-d H:i:s')) - strtotime($pfNetworkPort->fields['lastup']); echo Html::timestampToString($time, FALSE); } } echo "</td>"; break; case 16: echo "<td>" . $pfNetworkPort->fields["ifalias"] . "</td>"; break; } } echo "</tr>"; }
static function showList($itemtype, $params) { global $DB, $CFG_GLPI, $LANG, $PLUGIN_HOOKS; // Instanciate an object to access method $item = NULL; if ($itemtype != 'States' && class_exists($itemtype)) { $item = new $itemtype(); } $_SESSION['plugin_mobile']['rows_limit'] = 10; // sdb38l $_SESSION['plugin_mobile']['cols_limit'] = 5; // sdb38l $LIST_LIMIT = $_SESSION['plugin_mobile']['rows_limit']; // Default values of parameters $p['link'] = array(); // $p['field'] = array(); // $p['contains'] = array(); // $p['searchtype'] = array(); // $p['sort'] = '1'; // $p['order'] = 'ASC'; // $p['start'] = 0; // $p['is_deleted'] = 0; $p['export_all'] = 0; $p['link2'] = ''; // $p['contains2'] = ''; // $p['field2'] = ''; // $p['itemtype2'] = ''; $p['searchtype2'] = ''; $p['showheader'] = true; foreach ($params as $key => $val) { $p[$key] = $val; } if ($p['export_all']) { $p['start'] = 0; } // Manage defautll seachtype value : for bookmark compatibility if (count($p['contains'])) { foreach ($p['contains'] as $key => $val) { if (!isset($p['searchtype'][$key])) { $p['searchtype'][$key] = 'contains'; } } } if (is_array($p['contains2']) && count($p['contains2'])) { foreach ($p['contains2'] as $key => $val) { if (!isset($p['searchtype2'][$key])) { $p['searchtype2'][$key] = 'contains'; } } } $target = Toolbox::getItemTypeSearchURL($itemtype); $limitsearchopt = Search::getCleanedOptions($itemtype); if (isset($CFG_GLPI['union_search_type'][$itemtype])) { $itemtable = $CFG_GLPI['union_search_type'][$itemtype]; } else { $itemtable = getTableForItemType($itemtype); } // Set display type for export if define $output_type = Search::HTML_OUTPUT; if (isset($_GET['display_type'])) { $output_type = $_GET['display_type']; // Limit to 10 element if ($_GET['display_type'] == Search::GLOBAL_SEARCH) { $LIST_LIMIT = Search::GLOBAL_SEARCH_DISPLAY_COUNT; } } // hack for States if (isset($CFG_GLPI['union_search_type'][$itemtype])) { $entity_restrict = true; } else { $entity_restrict = $item->isEntityAssign(); } $metanames = array(); // Get the items to display $toview = Search::addDefaultToView($itemtype); // Add items to display depending of personal prefs $displaypref = DisplayPreference::getForTypeUser($itemtype, Session::getLoginUserID()); if (count($displaypref)) { foreach ($displaypref as $val) { array_push($toview, $val); } } // Add searched items if (count($p['field']) > 0) { foreach ($p['field'] as $key => $val) { if (!in_array($val, $toview) && $val != 'all' && $val != 'view') { array_push($toview, $val); } } } // Add order item if (!in_array($p['sort'], $toview)) { array_push($toview, $p['sort']); } // Special case for Ticket : put ID in front if ($itemtype == 'Ticket') { array_unshift($toview, 2); } // Clean toview array $toview = array_unique($toview); foreach ($toview as $key => $val) { if (!isset($limitsearchopt[$val])) { unset($toview[$key]); } } // delete entities display //var_dump($toview); if (array_search('80', $toview) !== false) { unset($toview[array_search('80', $toview)]); } $toview_count = count($toview); // Construct the request //// 1 - SELECT //$SELECT = "SELECT ".PluginMobileSearch::addDefaultSelect($itemtype); $SELECT = "SELECT '" . $_SESSION['glpiname'] . "' AS currentuser, " . PluginMobileSearch::addDefaultSelect($itemtype); // Add select for all toview item foreach ($toview as $key => $val) { $SELECT .= Search::addSelect($itemtype, $val, $key, 0); } //// 2 - FROM AND LEFT JOIN // Set reference table $FROM = " FROM `{$itemtable}`"; // Init already linked tables array in order not to link a table several times $already_link_tables = array(); // Put reference table array_push($already_link_tables, $itemtable); // Add default join $COMMONLEFTJOIN = Search::addDefaultJoin($itemtype, $itemtable, $already_link_tables); $FROM .= $COMMONLEFTJOIN; $searchopt = array(); $searchopt[$itemtype] =& Search::getOptions($itemtype); // Add all table for toview items //foreach ($toview as $key => $val) { // $FROM .= Search::addLeftJoin($itemtype,$itemtable,$already_link_tables, // $searchopt[$itemtype][$val]["table"], // $searchopt[$itemtype][$val]["linkfield"]); //} foreach ($toview as $key => $val) { $FROM .= self::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$val]["table"], $searchopt[$itemtype][$val]["linkfield"], 0, 0, $searchopt[$itemtype][$val]["joinparams"]); } // Search all case : //if (in_array("all",$p['field'])) { // foreach ($searchopt[$itemtype] as $key => $val) { // // Do not search on Group Name // if (is_array($val)) { // $FROM .= Search::addLeftJoin($itemtype,$itemtable,$already_link_tables, // $searchopt[$itemtype][$key]["table"], // $searchopt[$itemtype][$key]["linkfield"]); // } // } //} // Search all case : if (in_array("all", $p['field'])) { foreach ($searchopt[$itemtype] as $key => $val) { // Do not search on Group Name if (is_array($val)) { $FROM .= self::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$key]["table"], $searchopt[$itemtype][$key]["linkfield"], 0, 0, $searchopt[$itemtype][$key]["joinparams"]); } } } //// 3 - WHERE // default string $COMMONWHERE = self::addDefaultWhere($itemtype); $first = empty($COMMONWHERE); // Add deleted if item have it if ($item && $item->maybeDeleted()) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } $COMMONWHERE .= $LINK . "`{$itemtable}`.`is_deleted` = '" . $p['is_deleted'] . "' "; } // Remove template items if ($item && $item->maybeTemplate()) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } $COMMONWHERE .= $LINK . "`{$itemtable}`.`is_template` = '0' "; } // Add Restrict to current entities if ($entity_restrict) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } if ($itemtype == 'Entity') { $COMMONWHERE .= getEntitiesRestrictRequest($LINK, $itemtable, 'id', '', true); } else { if (isset($CFG_GLPI["union_search_type"][$itemtype])) { // Will be replace below in Union/Recursivity Hack $COMMONWHERE .= $LINK . " ENTITYRESTRICT "; } else { $COMMONWHERE .= getEntitiesRestrictRequest($LINK, $itemtable, '', '', $item->maybeRecursive()); } } } $WHERE = ""; $HAVING = ""; // Add search conditions // If there is search items if ($_SESSION["glpisearchcount"][$itemtype] > 0 && count($p['contains']) > 0) { for ($key = 0; $key < $_SESSION["glpisearchcount"][$itemtype]; $key++) { // if real search (strlen >0) and not all and view search if (isset($p['contains'][$key]) && strlen($p['contains'][$key]) > 0) { // common search if ($p['field'][$key] != "all" && $p['field'][$key] != "view") { $LINK = " "; $NOT = 0; $tmplink = ""; if (is_array($p['link']) && isset($p['link'][$key])) { if (strstr($p['link'][$key], "NOT")) { $tmplink = " " . str_replace(" NOT", "", $p['link'][$key]); $NOT = 1; } else { $tmplink = " " . $p['link'][$key]; } } else { $tmplink = " AND "; } if (isset($searchopt[$itemtype][$p['field'][$key]]["usehaving"])) { // Manage Link if not first item if (!empty($HAVING)) { $LINK = $tmplink; } // Find key $item_num = array_search($p['field'][$key], $toview); $HAVING .= Search::addHaving($LINK, $NOT, $itemtype, $p['field'][$key], $p['searchtype'][$key], $p['contains'][$key], 0, $item_num); } else { // Manage Link if not first item if (!empty($WHERE)) { $LINK = $tmplink; } $WHERE .= self::addWhere($LINK, $NOT, $itemtype, $p['field'][$key], $p['searchtype'][$key], $p['contains'][$key]); } // view and all search } else { $LINK = " OR "; $NOT = 0; $globallink = " AND "; if (is_array($p['link']) && isset($p['link'][$key])) { switch ($p['link'][$key]) { case "AND": $LINK = " OR "; $globallink = " AND "; break; case "AND NOT": $LINK = " AND "; $NOT = 1; $globallink = " AND "; break; case "OR": $LINK = " OR "; $globallink = " OR "; break; case "OR NOT": $LINK = " AND "; $NOT = 1; $globallink = " OR "; break; } } else { $tmplink = " AND "; } // Manage Link if not first item if (!empty($WHERE)) { $WHERE .= $globallink; } $WHERE .= " ( "; $first2 = true; $items = array(); if ($p['field'][$key] == "all") { $items = $searchopt[$itemtype]; } else { // toview case : populate toview foreach ($toview as $key2 => $val2) { $items[$val2] = $searchopt[$itemtype][$val2]; } } foreach ($items as $key2 => $val2) { if (is_array($val2)) { // Add Where clause if not to be done in HAVING CLAUSE if (!isset($val2["usehaving"])) { $tmplink = $LINK; if ($first2) { $tmplink = " "; $first2 = false; } $WHERE .= self::addWhere($tmplink, $NOT, $itemtype, $key2, $p['searchtype'][$key], $p['contains'][$key]); } } } $WHERE .= " ) "; } } } } //// 4 - ORDER $ORDER = " ORDER BY `id` "; foreach ($toview as $key => $val) { if ($p['sort'] == $val) { $ORDER = self::addOrderBy($itemtype, $p['sort'], $p['order'], $key); } } //// 5 - META SEARCH // Preprocessing if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && is_array($p['itemtype2'])) { // a - SELECT for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { if (isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0) { $SELECT .= self::addSelect($p['itemtype2'][$i], $p['field2'][$i], $i, 1, $p['itemtype2'][$i]); } } // b - ADD LEFT JOIN // Already link meta table in order not to linked a table several times $already_link_tables2 = array(); // Link reference tables for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { if (isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0) { if (!in_array(getTableForItemType($p['itemtype2'][$i]), $already_link_tables2)) { $FROM .= Search::addMetaLeftJoin($itemtype, $p['itemtype2'][$i], $already_link_tables2, $p['contains2'][$i] == "NULL" || strstr($p['link2'][$i], "NOT")); } } } // Link items tables for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { if (isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0) { if (!isset($searchopt[$p['itemtype2'][$i]])) { $searchopt[$p['itemtype2'][$i]] =& self::getOptions($p['itemtype2'][$i]); } if (!in_array($searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["table"] . "_" . $p['itemtype2'][$i], $already_link_tables2)) { $FROM .= self::addLeftJoin($p['itemtype2'][$i], getTableForItemType($p['itemtype2'][$i]), $already_link_tables2, $searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["table"], $searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["linkfield"], 1, $p['itemtype2'][$i], $searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["joinparams"]); } } } } //// 6 - Add item ID // Add ID to the select if (!empty($itemtable)) { $SELECT .= "`{$itemtable}`.`id` AS id "; } //// 7 - Manage GROUP BY $GROUPBY = ""; // Meta Search / Search All / Count tickets if ($_SESSION["glpisearchcount2"][$itemtype] > 0 || !empty($HAVING) || in_array('all', $p['field'])) { $GROUPBY = " GROUP BY `{$itemtable}`.`id`"; } if (empty($GROUPBY)) { foreach ($toview as $key2 => $val2) { if (!empty($GROUPBY)) { break; } if (isset($searchopt[$itemtype][$val2]["forcegroupby"])) { $GROUPBY = " GROUP BY `{$itemtable}`.`id`"; } } } // Specific search for others item linked (META search) if (is_array($p['itemtype2'])) { for ($key = 0; $key < $_SESSION["glpisearchcount2"][$itemtype]; $key++) { if (isset($p['itemtype2'][$key]) && !empty($p['itemtype2'][$key]) && isset($p['contains2'][$key]) && strlen($p['contains2'][$key]) > 0) { $LINK = ""; // For AND NOT statement need to take into account all the group by items if (strstr($p['link2'][$key], "AND NOT") || isset($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["usehaving"])) { $NOT = 0; if (strstr($p['link2'][$key], "NOT")) { $tmplink = " " . str_replace(" NOT", "", $p['link2'][$key]); $NOT = 1; } else { $tmplink = " " . $p['link2'][$key]; } if (!empty($HAVING)) { $LINK = $tmplink; } $HAVING .= self::addHaving($LINK, $NOT, $p['itemtype2'][$key], $p['field2'][$key], $p['searchtype2'][$key], $p['contains2'][$key], 1, $key); } else { // Meta Where Search $LINK = " "; $NOT = 0; // Manage Link if not first item if (is_array($p['link2']) && isset($p['link2'][$key]) && strstr($p['link2'][$key], "NOT")) { $tmplink = " " . str_replace(" NOT", "", $p['link2'][$key]); $NOT = 1; } else { if (is_array($p['link2']) && isset($p['link2'][$key])) { $tmplink = " " . $p['link2'][$key]; } else { $tmplink = " AND "; } } if (!empty($WHERE)) { $LINK = $tmplink; } $WHERE .= self::addWhere($LINK, $NOT, $p['itemtype2'][$key], $p['field2'][$key], $p['searchtype2'][$key], $p['contains2'][$key], 1); } } } } // Use a ReadOnly connection if available and configured to be used $DBread = DBConnection::getReadConnection(); // If no research limit research to display item and compute number of item using simple request $nosearch = true; for ($i = 0; $i < $_SESSION["glpisearchcount"][$itemtype]; $i++) { if (isset($p['contains'][$i]) && strlen($p['contains'][$i]) > 0) { $nosearch = false; } } if ($_SESSION["glpisearchcount2"][$itemtype] > 0) { $nosearch = false; } $LIMIT = ""; $numrows = 0; //No search : count number of items using a simple count(ID) request and LIMIT search if ($nosearch) { $LIMIT = " LIMIT " . $p['start'] . ", " . $LIST_LIMIT; // Force group by for all the type -> need to count only on table ID if (!isset($searchopt[$itemtype][1]['forcegroupby'])) { $count = "count(*)"; } else { $count = "count(DISTINCT `{$itemtable}`.`id`)"; } // request currentuser for SQL supervision, not displayed $query_num = "SELECT {$count}, '" . $_SESSION['glpiname'] . "' AS currentuser\n FROM `{$itemtable}`" . $COMMONLEFTJOIN; $first = true; if (!empty($COMMONWHERE)) { $LINK = " AND "; if ($first) { $LINK = " WHERE "; $first = false; } $query_num .= $LINK . $COMMONWHERE; } // Union Search : if (isset($CFG_GLPI["union_search_type"][$itemtype])) { $tmpquery = $query_num; $numrows = 0; foreach ($CFG_GLPI[$CFG_GLPI["union_search_type"][$itemtype]] as $ctype) { $ctable = getTableForItemType($ctype); $citem = new $ctype(); if ($citem->canView()) { // State case if ($itemtype == 'States') { $query_num = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $tmpquery); $query_num .= " AND {$ctable}.`states_id` > '0' "; // Add deleted if item have it if ($citem && $citem->maybeDeleted()) { $query_num .= " AND `{$ctable}`.`is_deleted` = '0' "; } // Remove template items if ($citem && $citem->maybeTemplate()) { $query_num .= " AND `{$ctable}`.`is_template` = '0' "; } } else { // Ref table case $reftable = getTableForItemType($itemtype); $replace = "FROM `{$reftable}`\n INNER JOIN `{$ctable}`\n ON (`{$reftable}`.`items_id`=`{$ctable}`.`id`\n AND `{$reftable}`.`itemtype` = '{$ctype}')"; $query_num = str_replace("FROM `" . $CFG_GLPI["union_search_type"][$itemtype] . "`", $replace, $tmpquery); $query_num = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $query_num); } $query_num = str_replace("ENTITYRESTRICT", getEntitiesRestrictRequest('', $ctable, '', '', $citem->maybeRecursive()), $query_num); $result_num = $DBread->query($query_num); $numrows += $DBread->result($result_num, 0, 0); } } } else { $result_num = $DBread->query($query_num); $numrows = $DBread->result($result_num, 0, 0); } } // If export_all reset LIMIT condition if ($p['export_all']) { $LIMIT = ""; } if (!empty($WHERE) || !empty($COMMONWHERE)) { if (!empty($COMMONWHERE)) { $WHERE = ' WHERE ' . $COMMONWHERE . (!empty($WHERE) ? ' AND ( ' . $WHERE . ' )' : ''); } else { $WHERE = ' WHERE ' . $WHERE . ' '; } $first = false; } if (!empty($HAVING)) { $HAVING = ' HAVING ' . $HAVING; } $DB->query("SET SESSION group_concat_max_len = 9999999;"); // Create QUERY if (isset($CFG_GLPI["union_search_type"][$itemtype])) { $first = true; $QUERY = ""; foreach ($CFG_GLPI[$CFG_GLPI["union_search_type"][$itemtype]] as $ctype) { $ctable = getTableForItemType($ctype); $citem = new $ctype(); if ($citem->canView()) { if ($first) { $first = false; } else { $QUERY .= " UNION "; } $tmpquery = ""; // State case if ($itemtype == 'States') { $tmpquery = $SELECT . ", '{$ctype}' AS TYPE " . $FROM . $WHERE; $tmpquery = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $tmpquery); $tmpquery .= " AND `{$ctable}`.`states_id` > '0' "; // Add deleted if item have it if ($citem && $citem->maybeDeleted()) { $tmpquery .= " AND `{$ctable}`.`is_deleted` = '0' "; } // Remove template items if ($citem && $citem->maybeTemplate()) { $tmpquery .= " AND `{$ctable}`.`is_template` = '0' "; } } else { // Ref table case $reftable = getTableForItemType($itemtype); $tmpquery = $SELECT . ", '{$ctype}' AS TYPE, `{$reftable}`.`id` AS refID, " . "`{$ctable}`.`entities_id` AS ENTITY " . $FROM . $WHERE; $replace = "FROM `{$reftable}`" . " INNER JOIN `{$ctable}`" . " ON (`{$reftable}`.`items_id`=`{$ctable}`.`id`" . " AND `{$reftable}`.`itemtype` = '{$ctype}')"; $tmpquery = str_replace("FROM `" . $CFG_GLPI["union_search_type"][$itemtype] . "`", $replace, $tmpquery); $tmpquery = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $tmpquery); } $tmpquery = str_replace("ENTITYRESTRICT", getEntitiesRestrictRequest('', $ctable, '', '', $citem->maybeRecursive()), $tmpquery); // SOFTWARE HACK if ($ctype == 'Software') { $tmpquery = str_replace("glpi_softwares.serial", "''", $tmpquery); $tmpquery = str_replace("glpi_softwares.otherserial", "''", $tmpquery); } $QUERY .= $tmpquery; } } if (empty($QUERY)) { echo Search::showError($output_type); return; } $QUERY .= str_replace($CFG_GLPI["union_search_type"][$itemtype] . ".", "", $ORDER) . $LIMIT; } else { $QUERY = $SELECT . $FROM . $WHERE . $GROUPBY . $HAVING . $ORDER . $LIMIT; } $DBread->query("SET SESSION group_concat_max_len = 4096;"); $result = $DBread->query($QUERY); if ($result2 = $DBread->query('SHOW WARNINGS')) { if ($DBread->numrows($result2) > 0) { $data = $DBread->fetch_assoc($result2); if ($data['Code'] == 1260) { $DBread->query("SET SESSION group_concat_max_len = 4194304;"); $result = $DBread->query($QUERY); } } } if ($result) { // if real search or complete export : get numrows from request if (!$nosearch || $p['export_all']) { $numrows = $DBread->numrows($result); } // Contruct Pager parameters $globallinkto = ""; if (count($p['field']) > 0) { $globallinkto .= self::getArrayUrlLink("field", $p['field']); } if ($p['link'] != '') { $globallinkto .= self::getArrayUrlLink("link", $p['link']); } if ($p['contains'] != array("")) { $globallinkto .= self::getArrayUrlLink("contains", $p['contains']); } if (count($p['field2']) > 0) { $globallinkto .= self::getArrayUrlLink("field2", $p['field2']); } if ($p['contains2'] != array("")) { $globallinkto .= self::getArrayUrlLink("contains2", $p['contains2']); } if ($p['itemtype2'] != '') { $globallinkto .= self::getArrayUrlLink("itemtype2", $p['itemtype2']); } if ($p['link2'] != '') { $globallinkto .= self::getArrayUrlLink("link2", $p['link2']); } $parameters = "sort=" . $p['sort'] . "&order=" . $p['order'] . $globallinkto; if ($output_type == Search::GLOBAL_SEARCH) { if (class_exists($itemtype)) { echo "<div class='center'><h2>" . $item->getTypeName(); // More items if ($numrows > $p['start'] + Search::GLOBAL_SEARCH_DISPLAY_COUNT) { echo " <a href='{$target}?{$parameters}' data-back='false'>" . $LANG['common'][66] . "</a>"; } echo "</h2></div>\n"; } else { return false; } } // If the begin of the view is before the number of items if ($p['start'] < $numrows) { // Form to massive actions $isadmin = false; // Compute number of columns to display // Add toview elements $nbcols = $toview_count; $already_printed = array(); // Add meta search elements if real search (strlen>0) or only NOT search if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && is_array($p['itemtype2'])) { for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { if (isset($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0 && !empty($p['itemtype2'][$i]) && (!isset($p['link2'][$i]) || !strstr($p['link2'][$i], "NOT"))) { if (!isset($already_printed[$p['itemtype2'][$i] . $p['field2'][$i]])) { $nbcols++; $already_printed[$p['itemtype2'][$i] . $p['field2'][$i]] = 1; } } } } if ($output_type == Search::HTML_OUTPUT) { // HTML display - massive modif $nbcols++; } // Define begin and end var for loop // Search case $begin_display = $p['start']; $end_display = $p['start'] + $LIST_LIMIT; // No search Case if ($nosearch) { $begin_display = 0; $end_display = min($numrows - $p['start'], $LIST_LIMIT); } // Export All case if ($p['export_all']) { $begin_display = 0; $end_display = $numrows; } // Display List Header echo PluginMobileSearch::showHeader($output_type, $end_display - $begin_display + 1, $nbcols); // New Line for Header Items Line echo self::showNewLine($output_type); $header_num = 1; if ($output_type == Search::HTML_OUTPUT) { // HTML display - massive modif $search_config = ""; echo PluginMobileSearch::showHeaderItem($output_type, $search_config, $header_num, "", 0, $p['order']); } if ($p['showheader']) { // Display column Headers for toview items echo "<div data-type='horizontal' data-role='controlgroup' class='mobile_list_header'>"; $cpt = 0; foreach ($toview as $key => $val) { $linkto = ''; if (!isset($searchopt[$itemtype][$val]['nosort']) || !$searchopt[$itemtype][$val]['nosort']) { /*$linkto = "$target?itemtype=$itemtype&sort=".$val."&order=".($p['order']=="ASC"?"DESC":"ASC"). "&start=".$p['start'].$globallinkto;*/ $linkto = "search.php?itemtype={$itemtype}&menu=" . $_GET['menu'] . "&ssmenu=" . $_GET['ssmenu'] . "&sort=" . $val . "&order=" . ($p['order'] == "ASC" ? "DESC" : "ASC") . "&start=" . $p['start'] . $globallinkto; } echo PluginMobileSearch::showHeaderItem($output_type, $searchopt[$itemtype][$val]["name"], $header_num, $linkto, $p['sort'] == $val, $p['order']); $cpt++; if ($cpt == $_SESSION['plugin_mobile']['cols_limit']) { break; } } echo "<a href='searchconfig.php?type=global&itemtype={$itemtype}&rand=" . mt_rand() . "' data-icon='plus'\n data-role='button' class='button-header'> </a>"; echo "</div>"; // Display columns Headers for meta items $already_printed = array(); if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && is_array($p['itemtype2'])) { for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { if (isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0) { if (!isset($already_printed[$p['itemtype2'][$i] . $p['field2'][$i]])) { if (!isset($metanames[$p['itemtype2'][$i]])) { $metaitem = new $p['itemtype2'][$i](); echo PluginMobileSearch::showHeaderItem($output_type, $metanames[$p['itemtype2'][$i]] . " - " . $searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["name"], $header_num); $already_printed[$p['itemtype2'][$i] . $p['field2'][$i]] = 1; } } } } } // End Line for column headers echo PluginMobileSearch::showEndLine($output_type); } // if real search seek to begin of items to display (because of complete search) if (!$nosearch) { $DB->data_seek($result, $p['start']); } // Define begin and end var for loop // Search case $i = $begin_display; // Init list of items displayed if ($output_type == Search::HTML_OUTPUT) { Session::initNavigateListItems($itemtype); } // Num of the row (1=header_line) $row_num = 1; // Display Loop while ($i < $numrows && $i < $end_display) { // Column num $item_num = 1; // Get data and increment loop variables $data = $DBread->fetch_assoc($result); $i++; $row_num++; // New line // Add item in item list Session::addToNavigateListItems($itemtype, $data["id"]); /*if ($output_type==Search::HTML_OUTPUT) { // HTML display - massive modif $tmpcheck=""; if ($isadmin) { if ($itemtype == 'Entity' && !in_array($data["id"],$_SESSION["glpiactiveentities"])) { $tmpcheck=" "; } else if ($item->maybeRecursive() && !in_array($data["entities_id"],$_SESSION["glpiactiveentities"])) { $tmpcheck=" "; } else { $sel=""; if (isset($_GET["select"]) && $_GET["select"]=="all") { $sel="checked"; } if (isset($_SESSION['glpimassiveactionselected'][$data["id"]])) { $sel="checked"; } $tmpcheck="<input type='checkbox' name='item[".$data["id"]."]' value='1' $sel>"; } } echo PluginMobileSearch::showItem($output_type,$tmpcheck,$item_num,$row_num,"width='10'"); }*/ // Print other toview items $itemsToShow = array(); $cpt = 0; foreach ($toview as $key => $val) { $itemsToShow[] = PluginMobileSearch::showItem($output_type, PluginMobileSearch::giveItem($itemtype, $val, $data, $key), $item_num, $row_num, self::displayConfigItem($itemtype, $val, $data, $key)); $cpt++; if ($cpt == $_SESSION['plugin_mobile']['cols_limit']) { break; } } // Print Meta Item if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && is_array($p['itemtype2'])) { for ($j = 0; $j < $_SESSION["glpisearchcount2"][$itemtype]; $j++) { if (isset($p['itemtype2'][$j]) && !empty($p['itemtype2'][$j]) && isset($p['contains2'][$j]) && strlen($p['contains2'][$j]) > 0) { // General case if (strpos($data["META_{$j}"], "\$\$\$\$") === false) { $out = self::giveItem($p['itemtype2'][$j], $p['field2'][$j], $data, $j, 1); $itemsToShow[] = PluginMobileSearch::showItem($output_type, $out, $item_num, $row_num); // Case of GROUP_CONCAT item : split item and multilline display } else { $split = explode("\$\$\$\$", $data["META_{$j}"]); $count_display = 0; $out = ""; $unit = ""; $separate = '<br>'; if (isset($searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['splititems']) && $searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['splititems']) { $separate = '<hr>'; } if (isset($searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['unit'])) { $unit = $searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['unit']; } for ($k = 0; $k < count($split); $k++) { if ($p['contains2'][$j] == "NULL" || strlen($p['contains2'][$j]) == 0 || preg_match('/' . $p['contains2'][$j] . '/i', $split[$k]) || isset($searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['forcegroupby'])) { if ($count_display) { $out .= $separate; } $count_display++; // Manage Link to item $split2 = explode("\$\$", $split[$k]); if (isset($split2[1])) { $out .= "<a href=\"" . getItemTypeFormURLMobile($p['itemtype2'][$j]) . "?id=" . $split2[1] . "\" data-back='false'>"; $out .= $split2[0] . $unit; if ($_SESSION["glpiis_ids_visible"] || empty($split2[0])) { $out .= " (" . $split2[1] . ")"; } $out .= "</a>"; } else { $out .= $split[$k] . $unit; } } } $itemsToShow[] = PluginMobileSearch::showItem($output_type, $out, $item_num, $row_num); } } } } // Specific column display if ($itemtype == 'CartridgeItem') { $itemsToShow[] = PluginMobileSearch::showItem($output_type, Cartridge::getCount($data["id"], $data["ALARM"], $output_type), $item_num, $row_num); } if ($itemtype == 'ConsumableItem') { $itemsToShow[] = PluginMobileSearch::showItem($output_type, Consumable::getCount($data["id"], $data["ALARM"], $output_type), $item_num, $row_num); } if ($itemtype == 'States' || $itemtype == 'ReservationItem') { $typename = $data["TYPE"]; if (class_exists($data["TYPE"])) { $itemtmp = new $data["TYPE"](); $typename = $itemtmp->getTypeName(); } $itemsToShow[] = PluginMobileSearch::showItem($output_type, $typename, $item_num, $row_num); } if ($itemtype == 'ReservationItem' && $output_type == Search::HTML_OUTPUT) { if (Session::haveRight("reservation_central", UPDATE)) { if (!haveAccessToEntity($data["ENTITY"])) { $itemsToShow[] = PluginMobileSearch::showItem($output_type, " ", $item_num, $row_num); $itemsToShow[] = PluginMobileSearch::showItem($output_type, " ", $item_num, $row_num); } else { $itemsToShow[] = PluginMobileSearch::showItem($output_type, "<a href=\"" . getItemTypeFormURLMobile($itemtype) . "?id=" . $data["refID"] . "&is_active=" . ($data["ACTIVE"] ? 0 : 1) . "&update=update\" " . "title='" . ($data["ACTIVE"] ? $LANG['buttons'][42] : $LANG['buttons'][41]) . "' data-back='false'><img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($data["ACTIVE"] ? "moins" : "plus") . ".png\" alt='' title=''></a>", $item_num, $row_num, "class='center'"); /*echo PluginMobileSearch::showItem($output_type,"<a href=\"javascript:confirmAction('". addslashes($LANG['reservation'][38])."\\n". addslashes($LANG['reservation'][39])."','". Toolbox::getItemTypeFormURL($itemtype)."?id=".$data["refID"]. "&delete=delete')\" title='". $LANG['reservation'][6]."'><img src=\"". $CFG_GLPI["root_doc"]."/pics/delete.png\" alt='' title=''></a>", $item_num,$row_num,"class='center'");*/ } } if ($data["ACTIVE"]) { $itemsToShow[] = PluginMobileSearch::showItem($output_type, "<a href='reservation.php?reservationitems_id=" . $data["refID"] . "' title='" . $LANG['reservation'][21] . "' data-back='false'><img src=\"" . $CFG_GLPI["root_doc"] . "/pics/reservation-3.png\" alt='' title=''></a>", $item_num, $row_num, "class='center'"); } else { $itemsToShow[] = PluginMobileSearch::showItem($output_type, " ", $item_num, $row_num); } } echo PluginMobileSearch::showNewLine($output_type, $i % 2); foreach ($itemsToShow as $item) { echo $item; } // End Line echo PluginMobileSearch::showEndLine($output_type); } $title = ""; // Create title if ($output_type == Search::PDF_OUTPUT_LANDSCAPE || $output_type == Search::PDF_OUTPUT_PORTRAIT) { if ($_SESSION["glpisearchcount"][$itemtype] > 0 && count($p['contains']) > 0) { for ($key = 0; $key < $_SESSION["glpisearchcount"][$itemtype]; $key++) { if (strlen($p['contains'][$key]) > 0) { if (isset($p["link"][$key])) { $title .= " " . $p["link"][$key] . " "; } switch ($p['field'][$key]) { case "all": $title .= $LANG['common'][66]; break; case "view": $title .= $LANG['search'][11]; break; default: $title .= $searchopt[$itemtype][$p['field'][$key]]["name"]; } $title .= " = " . $p['contains'][$key]; } } } if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && count($p['contains2']) > 0) { for ($key = 0; $key < $_SESSION["glpisearchcount2"][$itemtype]; $key++) { if (strlen($p['contains2'][$key]) > 0) { if (isset($p['link2'][$key])) { $title .= " " . $p['link2'][$key] . " "; } $title .= $metanames[$p['itemtype2'][$key]] . "/"; $title .= $searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["name"]; $title .= " = " . $p['contains2'][$key]; } } } } // Display footer echo PluginMobileSearch::showFooter($output_type, $title); // Delete selected item if ($output_type == Search::HTML_OUTPUT) { if ($isadmin) { openArrowMassives("massiveaction_form"); Dropdown::showForMassiveAction($itemtype, $p['is_deleted']); closeArrowMassives(); // End form for delete item //echo "</form>\n"; Html::closeForm(); } else { echo "<br>"; } } } else { echo Search::showError($output_type); } } else { echo $DBread > error(); } // Clean selection $_SESSION['glpimassiveactionselected'] = array(); //echo $QUERY; return $numrows; }
/** * This test will add all serachoptions in each itemtype and check if the * search give a SQL error */ public function testSearchOptions() { $displaypref = new DisplayPreference(); // save table glpi_displaypreferences $dp = getAllDatasFromTable($displaypref->getTable()); $itemtypeslist = $this->getClasses('getSearchOptions'); foreach ($itemtypeslist as $itemtype) { $number = 0; if (!file_exists('front/' . strtolower($itemtype) . '.php') || substr($itemtype, 0, 4) === "Rule" || substr($itemtype, 0, 6) === "Common" || substr($itemtype, 0, 2) === "DB" || $itemtype == 'SlaLevel' || $itemtype == 'Reservation' || $itemtype == 'Event' || $itemtype == 'KnowbaseItem' || $itemtype == 'NetworkPortMigration') { // it's the case where not have search possible in this itemtype continue; } $item = getItemForItemtype($itemtype); foreach ($item->getSearchOptions() as $key => $data) { if (is_int($key)) { $input = array('itemtype' => $itemtype, 'users_id' => 0, 'num' => $key); $displaypref->add($input); $number++; } } $this->assertEquals($number, countElementsInTable($displaypref->getTable(), "`itemtype`='" . $itemtype . "' AND `users_id`=0")); // do a search query $search_params = array('is_deleted' => 0, 'start' => 0, 'criteria' => array(), 'metacriteria' => array()); $data = $this->doSearch($itemtype, $search_params); // check for sql error (data key missing or empty) $this->assertArrayHasKey('data', $data, $data['last_errors']); $this->assertNotCount(0, $data['data'], $data['last_errors']); } // restore displaypreference table foreach (getAllDatasFromTable($displaypref->getTable()) as $line) { $displaypref->delete($line, true); } $this->assertEquals(0, countElementsInTable($displaypref->getTable())); foreach ($dp as $input) { $displaypref->add($input); } }
public function showSearchConfigList($itemtype, $type = 'global') { global $LANG, $CFG_GLPI, $DB; $IDuser = 0; if ($type == 'perso') { $IDuser = Session::getLoginUserID(); } $searchopt = Search::getOptions($itemtype); if (!is_array($searchopt)) { return false; } $item = NULL; if ($itemtype != 'States' && class_exists($itemtype)) { $item = new $itemtype(); } $global_write = Session::haveRight("search_config_global", "w"); // Defined items $query = "SELECT *\n FROM `" . $this->getTable() . "`\n WHERE `itemtype` = '{$itemtype}'\n AND `users_id` = '{$IDuser}'\n ORDER BY `rank`"; $result = $DB->query($query); $numrows = 0; $numrows = $DB->numrows($result); if ($numrows == 0) { Session::checkRight("search_config", "w"); echo $LANG['setup'][241] . " "; echo "<a href='searchconfig.form.php?type={$type}&itemtype={$itemtype}&users_id={$IDuser}&activate' data-role='button' data-inline='true' data-theme='a'>" . $LANG['buttons'][2] . "</a>"; } else { $already_added = DisplayPreference::getForTypeUser($itemtype, $IDuser); echo $LANG['setup'][252]; echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/plugins/mobile/front/searchconfig.form.php?type={$type}&itemtype={$itemtype}&users_id={$IDuser}'>"; //echo "<form method='post' action='../../../plugins/mobile/front/searchconfig.form.php?type=$type&itemtype=$itemtype&users_id=$IDuser'>"; echo "<input type='hidden' name='users_id' value='{$IDuser}'>"; echo "<select name='num'>"; $first_group = true; $searchopt = Search::getCleanedOptions($itemtype); foreach ($searchopt as $key => $val) { if (!is_array($val)) { if (!$first_group) { echo "</optgroup>\n"; } else { $first_group = false; } echo "<optgroup label='{$val}'>"; } else { if ($key != 1 && !in_array($key, $already_added)) { echo "<option value='{$key}'>" . $val["name"] . "</option>"; } } } if (!$first_group) { echo "</optgroup>\n"; } echo "</select>"; echo "<input type='submit' name='add' value='" . $LANG['buttons'][8] . "' data-inline='true' data-theme='a'>"; //echo "</form>"; Html::closeForm(); //print list echo "<ul data-role='listview' data-inset='true' data-theme='d' data-dividertheme='a'>"; // print first element echo "<li>" . $searchopt[1]["name"] . "</li>"; // print entity if (Session::isMultiEntitiesMode() && (isset($CFG_GLPI["union_search_type"][$itemtype]) || $item && $item->maybeRecursive() || count($_SESSION["glpiactiveentities"]) > 1) && isset($searchopt[80])) { echo "<li>" . $searchopt[80]["name"] . "</li>"; } $i = 0; if ($numrows) { while ($data = $DB->fetch_array($result)) { if ($data["num"] != 1 && isset($searchopt[$data["num"]])) { echo "<li>"; echo $searchopt[$data["num"]]["name"]; if ($global_write) { echo "<span class='right_searchconfig'>"; if ($i != 0) { echo "<a data-role='button' data-icon='arrow-u' data-inline='true' " . "href='searchconfig.form.php?type={$type}&itemtype={$itemtype}" . "&users_id={$IDuser}&up&id=" . $data['id'] . "&rand=" . mt_rand() . "'> </a>"; } if ($i != $numrows - 1) { echo "<a data-role='button' data-icon='arrow-d' data-inline='true' " . "href='searchconfig.form.php?type={$type}&itemtype={$itemtype}" . "&users_id={$IDuser}&down&id=" . $data['id'] . "&rand=" . mt_rand() . "'> </a>"; } echo "<a data-role='button' data-icon='delete' data-inline='true' " . "href='searchconfig.form.php?type={$type}&itemtype={$itemtype}" . "&users_id={$IDuser}&delete&id=" . $data['id'] . "'>" . " </a>"; echo "</span>"; } echo "</li>"; $i++; } } } echo "</ul>"; } $this->showNavBar($itemtype, $type); }
-------------------------------------------------------------------------- */ define('GLPI_ROOT', '../../..'); include GLPI_ROOT . "/inc/includes.php"; if (!isset($_GET["itemtype"])) { exit; } else { $itemtype = $_GET["itemtype"]; } if (!isset($_GET["type"])) { exit; } else { $type = $_GET["type"]; } Session::checkSeveralRightsOr(array("search_config_global" => "w", "search_config" => "w")); $setupdisplay = new DisplayPreference(); if (isset($_GET["activate"])) { $setupdisplay->activatePerso($_GET); } else { if (isset($_POST["add"])) { $setupdisplay->add($_REQUEST); } else { if (isset($_GET["delete"]) || isset($_GET["delete_x"])) { $setupdisplay->delete($_GET); } else { if (isset($_GET["up"]) || isset($_GET["up_x"])) { $setupdisplay->orderItem($_GET, 'up'); } else { if (isset($_GET["down"]) || isset($_GET["down_x"])) { $setupdisplay->orderItem($_GET, 'down'); }
static function install(Migration $migration) { global $DB; $table = getTableForItemType(__CLASS__); if (!TableExists($table)) { $query = "CREATE TABLE `{$table}` (\n `id` INT( 11 ) NOT NULL AUTO_INCREMENT,\n `entities_id` INT( 11 ) NOT NULL DEFAULT 0,\n `itemtype` varchar(255) collate utf8_unicode_ci default NULL,\n `is_active` tinyint(1) NOT NULL default '0',\n `name` varchar(255) collate utf8_unicode_ci default NULL,\n `comment` text NULL,\n `date_mod` datetime NOT NULL default '0000-00-00 00:00:00',\n `use_global_search` tinyint(1) NOT NULL default '0',\n `use_unicity` tinyint(1) NOT NULL default '0',\n `use_history` tinyint(1) NOT NULL default '0',\n `use_infocoms` tinyint(1) NOT NULL default '0',\n `use_contracts` tinyint(1) NOT NULL default '0',\n `use_documents` tinyint(1) NOT NULL default '0',\n `use_tickets` tinyint(1) NOT NULL default '0',\n `use_links` tinyint(1) NOT NULL default '0',\n `use_loans` tinyint(1) NOT NULL default '0',\n `use_network_ports` tinyint(1) NOT NULL default '0',\n `use_direct_connections` tinyint(1) NOT NULL default '0',\n `use_plugin_datainjection` tinyint(1) NOT NULL default '0',\n `use_plugin_pdf` tinyint(1) NOT NULL default '0',\n `use_plugin_order` tinyint(1) NOT NULL default '0',\n `use_plugin_uninstall` tinyint(1) NOT NULL default '0',\n `use_plugin_geninventorynumber` tinyint(1) NOT NULL default '0',\n `use_menu_entry` tinyint(1) NOT NULL default '0',\n `linked_itemtypes` text NULL,\n PRIMARY KEY ( `id` )\n ) ENGINE = MYISAM COMMENT = 'Object types definition table' DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query) or die($DB->error()); } $migration->addField($table, "use_network_ports", "bool"); $migration->addField($table, "use_direct_connections", "bool"); $migration->addField($table, "use_plugin_geninventorynumber", "bool"); $migration->addField($table, "use_contracts", "bool"); $migration->addField($table, "use_menu_entry", "bool"); $migration->addField($table, "use_global_search", "bool"); $migration->addField($table, "comment", "text"); $migration->addField($table, "date_mod", "datetime"); $migration->addField($table, "linked_itemtypes", "text"); $migration->migrationOneTable($table); //Displayprefs $prefs = array(10 => 6, 9 => 5, 8 => 4, 7 => 3, 6 => 2, 2 => 1, 4 => 1, 11 => 7, 12 => 8, 14 => 10, 15 => 11); foreach ($prefs as $num => $rank) { if (!countElementsInTable("glpi_displaypreferences", "`itemtype`='" . __CLASS__ . "' AND `num`='{$num}'\n AND `users_id`='0'")) { $preference = new DisplayPreference(); $tmp['itemtype'] = __CLASS__; $tmp['num'] = $num; $tmp['rank'] = $rank; $tmp['users_id'] = 0; $preference->add($tmp); } } //If files are missing, recreate them! self::checkClassAndFilesForItemType(); }
static function deleteDisplayPreferences($table, $field) { $pref = new DisplayPreference(); $itemtype = getItemTypeForTable($table); $searchopt = Search::getCleanedOptions($itemtype); foreach ($searchopt as $num => $option) { if (isset($option['field']) && $option['field'] == $field || isset($option['field']) && $option['linkfield'] == $field) { $criteria = array('itemtype' => $itemtype, 'num' => $num); $pref->deleteByCriteria($criteria); break; } } }
/** * Generic Search and list function * * Build the query, make the search and list items after a search. * * @param $itemtype item type * @param $params array of parameters may include field, contains, searchtype, sort, order, * start, deleted, link, link2, contains2, field2, itemtype2, searchtype2 * * @return Nothing (display) **/ static function showList($itemtype, array $params) { global $DB, $CFG_GLPI; // Instanciate an object to access method $item = NULL; if ($itemtype != 'AllAssets') { $item = getItemForItemtype($itemtype); } // Default values of parameters $p['link'] = array(); // $p['field'] = array(); // $p['contains'] = array(); // $p['searchtype'] = array(); // $p['sort'] = '1'; // $p['order'] = 'ASC'; // $p['start'] = 0; // $p['is_deleted'] = 0; $p['export_all'] = 0; $p['link2'] = ''; // $p['contains2'] = ''; // $p['field2'] = ''; // $p['itemtype2'] = ''; $p['searchtype2'] = ''; foreach ($params as $key => $val) { $p[$key] = $val; } if ($p['export_all']) { $p['start'] = 0; } if (in_array('all', $p['field']) && !$CFG_GLPI['allow_search_all']) { Html::displayRightError(); } if (in_array('view', $p['field']) && !$CFG_GLPI['allow_search_view']) { Html::displayRightError(); } // Manage defautll seachtype value : for bookmark compatibility if (count($p['contains'])) { foreach ($p['contains'] as $key => $val) { if (!isset($p['searchtype'][$key])) { $p['searchtype'][$key] = 'contains'; } } } if (is_array($p['contains2']) && count($p['contains2'])) { foreach ($p['contains2'] as $key => $val) { if (!isset($p['searchtype2'][$key])) { $p['searchtype2'][$key] = 'contains'; } } } $target = Toolbox::getItemTypeSearchURL($itemtype); $limitsearchopt = self::getCleanedOptions($itemtype); $blacklist_tables = array(); if (isset($CFG_GLPI['union_search_type'][$itemtype])) { $itemtable = $CFG_GLPI['union_search_type'][$itemtype]; $blacklist_tables[] = getTableForItemType($itemtype); } else { $itemtable = getTableForItemType($itemtype); } $LIST_LIMIT = $_SESSION['glpilist_limit']; // Set display type for export if define $output_type = self::HTML_OUTPUT; if (isset($_GET['display_type'])) { $output_type = $_GET['display_type']; // Limit to 10 element if ($_GET['display_type'] == self::GLOBAL_SEARCH) { $LIST_LIMIT = self::GLOBAL_DISPLAY_COUNT; } } // hack for AllAssets if (isset($CFG_GLPI['union_search_type'][$itemtype])) { $entity_restrict = true; } else { $entity_restrict = $item->isEntityAssign(); } self::$output_type = $output_type; $metanames = array(); // Get the items to display $toview = self::addDefaultToView($itemtype); // Add items to display depending of personal prefs $displaypref = DisplayPreference::getForTypeUser($itemtype, Session::getLoginUserID()); if (count($displaypref)) { foreach ($displaypref as $val) { array_push($toview, $val); } } // Add searched items if (count($p['field']) > 0) { foreach ($p['field'] as $key => $val) { if (!in_array($val, $toview) && $val != 'all' && $val != 'view') { array_push($toview, $val); } } } // Add order item if (!in_array($p['sort'], $toview)) { array_push($toview, $p['sort']); } // Special case for Ticket : put ID in front if ($itemtype == 'Ticket') { array_unshift($toview, 2); } // Clean toview array $toview = array_unique($toview); foreach ($toview as $key => $val) { if (!isset($limitsearchopt[$val])) { unset($toview[$key]); } } $toview_count = count($toview); // Construct the request //// 1 - SELECT // request currentuser for SQL supervision, not displayed $SELECT = "SELECT '" . Toolbox::addslashes_deep($_SESSION['glpiname']) . "' AS currentuser,\n " . self::addDefaultSelect($itemtype); // Add select for all toview item foreach ($toview as $key => $val) { $SELECT .= self::addSelect($itemtype, $val, $key, 0); } //// 2 - FROM AND LEFT JOIN // Set reference table $FROM = " FROM `{$itemtable}`"; // Init already linked tables array in order not to link a table several times $already_link_tables = array(); // Put reference table array_push($already_link_tables, $itemtable); // Add default join $COMMONLEFTJOIN = self::addDefaultJoin($itemtype, $itemtable, $already_link_tables); $FROM .= $COMMONLEFTJOIN; $searchopt = array(); $searchopt[$itemtype] =& self::getOptions($itemtype); // Add all table for toview items foreach ($toview as $key => $val) { if (!in_array($searchopt[$itemtype][$val]["table"], $blacklist_tables)) { $FROM .= self::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$val]["table"], $searchopt[$itemtype][$val]["linkfield"], 0, 0, $searchopt[$itemtype][$val]["joinparams"]); } } // Search all case : if (in_array("all", $p['field'])) { foreach ($searchopt[$itemtype] as $key => $val) { // Do not search on Group Name if (is_array($val)) { if (!in_array($searchopt[$itemtype][$key]["table"], $blacklist_tables)) { $FROM .= self::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$key]["table"], $searchopt[$itemtype][$key]["linkfield"], 0, 0, $searchopt[$itemtype][$key]["joinparams"]); } } } } //// 3 - WHERE // default string $COMMONWHERE = self::addDefaultWhere($itemtype); $first = empty($COMMONWHERE); // Add deleted if item have it if ($item && $item->maybeDeleted()) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } $COMMONWHERE .= $LINK . "`{$itemtable}`.`is_deleted` = '" . $p['is_deleted'] . "' "; } // Remove template items if ($item && $item->maybeTemplate()) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } $COMMONWHERE .= $LINK . "`{$itemtable}`.`is_template` = '0' "; } // Add Restrict to current entities if ($entity_restrict) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } if ($itemtype == 'Entity') { $COMMONWHERE .= getEntitiesRestrictRequest($LINK, $itemtable, 'id', '', true); } else { if (isset($CFG_GLPI["union_search_type"][$itemtype])) { // Will be replace below in Union/Recursivity Hack $COMMONWHERE .= $LINK . " ENTITYRESTRICT "; } else { $COMMONWHERE .= getEntitiesRestrictRequest($LINK, $itemtable, '', '', $item->maybeRecursive()); } } } $WHERE = ""; $HAVING = ""; // Add search conditions // If there is search items if ($_SESSION["glpisearchcount"][$itemtype] > 0 && count($p['contains']) > 0) { for ($key = 0; $key < $_SESSION["glpisearchcount"][$itemtype]; $key++) { // if real search (strlen >0) and not all and view search if (isset($p['contains'][$key]) && strlen($p['contains'][$key]) > 0) { // common search if ($p['field'][$key] != "all" && $p['field'][$key] != "view") { $LINK = " "; $NOT = 0; $tmplink = ""; if (is_array($p['link']) && isset($p['link'][$key])) { if (strstr($p['link'][$key], "NOT")) { $tmplink = " " . str_replace(" NOT", "", $p['link'][$key]); $NOT = 1; } else { $tmplink = " " . $p['link'][$key]; } } else { $tmplink = " AND "; } if (isset($searchopt[$itemtype][$p['field'][$key]]["usehaving"])) { // Manage Link if not first item if (!empty($HAVING)) { $LINK = $tmplink; } // Find key $item_num = array_search($p['field'][$key], $toview); $HAVING .= self::addHaving($LINK, $NOT, $itemtype, $p['field'][$key], $p['searchtype'][$key], $p['contains'][$key], 0, $item_num); } else { // Manage Link if not first item if (!empty($WHERE)) { $LINK = $tmplink; } $WHERE .= self::addWhere($LINK, $NOT, $itemtype, $p['field'][$key], $p['searchtype'][$key], $p['contains'][$key]); } // view and all search } else { $LINK = " OR "; $NOT = 0; $globallink = " AND "; if (is_array($p['link']) && isset($p['link'][$key])) { switch ($p['link'][$key]) { case "AND": $LINK = " OR "; $globallink = " AND "; break; case "AND NOT": $LINK = " AND "; $NOT = 1; $globallink = " AND "; break; case "OR": $LINK = " OR "; $globallink = " OR "; break; case "OR NOT": $LINK = " AND "; $NOT = 1; $globallink = " OR "; break; } } else { $tmplink = " AND "; } // Manage Link if not first item if (!empty($WHERE)) { $WHERE .= $globallink; } $WHERE .= " ( "; $first2 = true; $items = array(); if ($p['field'][$key] == "all") { $items = $searchopt[$itemtype]; } else { // toview case : populate toview foreach ($toview as $key2 => $val2) { $items[$val2] = $searchopt[$itemtype][$val2]; } } foreach ($items as $key2 => $val2) { if (isset($val2['nosearch']) && $val2['nosearch']) { continue; } if (is_array($val2)) { // Add Where clause if not to be done in HAVING CLAUSE if (!isset($val2["usehaving"])) { $tmplink = $LINK; if ($first2) { $tmplink = " "; $first2 = false; } $WHERE .= self::addWhere($tmplink, $NOT, $itemtype, $key2, $p['searchtype'][$key], $p['contains'][$key]); } } } $WHERE .= " ) "; } } } } //// 4 - ORDER $ORDER = " ORDER BY `id` "; foreach ($toview as $key => $val) { if ($p['sort'] == $val) { $ORDER = self::addOrderBy($itemtype, $p['sort'], $p['order'], $key); } } //// 5 - META SEARCH // Preprocessing if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && is_array($p['itemtype2'])) { // a - SELECT for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { if (isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0) { $SELECT .= self::addSelect($p['itemtype2'][$i], $p['field2'][$i], $i, 1, $p['itemtype2'][$i]); } } // b - ADD LEFT JOIN // Already link meta table in order not to linked a table several times $already_link_tables2 = array(); // Link reference tables for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { if (isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0) { if (!in_array(getTableForItemType($p['itemtype2'][$i]), $already_link_tables2)) { $FROM .= self::addMetaLeftJoin($itemtype, $p['itemtype2'][$i], $already_link_tables2, $p['contains2'][$i] == "NULL" || strstr($p['link2'][$i], "NOT")); } } } // Link items tables for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { if (isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0) { if (!isset($searchopt[$p['itemtype2'][$i]])) { $searchopt[$p['itemtype2'][$i]] =& self::getOptions($p['itemtype2'][$i]); } if (!in_array($searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["table"] . "_" . $p['itemtype2'][$i], $already_link_tables2)) { $FROM .= self::addLeftJoin($p['itemtype2'][$i], getTableForItemType($p['itemtype2'][$i]), $already_link_tables2, $searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["table"], $searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["linkfield"], 1, $p['itemtype2'][$i], $searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["joinparams"]); } } } } //// 6 - Add item ID // Add ID to the select if (!empty($itemtable)) { $SELECT .= "`{$itemtable}`.`id` AS id "; } //// 7 - Manage GROUP BY $GROUPBY = ""; // Meta Search / Search All / Count tickets if ($_SESSION["glpisearchcount2"][$itemtype] > 0 || !empty($HAVING) || in_array('all', $p['field'])) { $GROUPBY = " GROUP BY `{$itemtable}`.`id`"; } if (empty($GROUPBY)) { foreach ($toview as $key2 => $val2) { if (!empty($GROUPBY)) { break; } if (isset($searchopt[$itemtype][$val2]["forcegroupby"])) { $GROUPBY = " GROUP BY `{$itemtable}`.`id`"; } } } // Specific search for others item linked (META search) if (is_array($p['itemtype2'])) { for ($key = 0; $key < $_SESSION["glpisearchcount2"][$itemtype]; $key++) { if (isset($p['itemtype2'][$key]) && !empty($p['itemtype2'][$key]) && isset($p['contains2'][$key]) && strlen($p['contains2'][$key]) > 0) { $LINK = ""; // For AND NOT statement need to take into account all the group by items if (strstr($p['link2'][$key], "AND NOT") || isset($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["usehaving"])) { $NOT = 0; if (strstr($p['link2'][$key], "NOT")) { $tmplink = " " . str_replace(" NOT", "", $p['link2'][$key]); $NOT = 1; } else { $tmplink = " " . $p['link2'][$key]; } if (!empty($HAVING)) { $LINK = $tmplink; } $HAVING .= self::addHaving($LINK, $NOT, $p['itemtype2'][$key], $p['field2'][$key], $p['searchtype2'][$key], $p['contains2'][$key], 1, $key); } else { // Meta Where Search $LINK = " "; $NOT = 0; // Manage Link if not first item if (is_array($p['link2']) && isset($p['link2'][$key]) && strstr($p['link2'][$key], "NOT")) { $tmplink = " " . str_replace(" NOT", "", $p['link2'][$key]); $NOT = 1; } else { if (is_array($p['link2']) && isset($p['link2'][$key])) { $tmplink = " " . $p['link2'][$key]; } else { $tmplink = " AND "; } } if (!empty($WHERE)) { $LINK = $tmplink; } $WHERE .= self::addWhere($LINK, $NOT, $p['itemtype2'][$key], $p['field2'][$key], $p['searchtype2'][$key], $p['contains2'][$key], 1); } } } } // Use a ReadOnly connection if available and configured to be used $DBread = DBConnection::getReadConnection(); // If no research limit research to display item and compute number of item using simple request $nosearch = true; for ($i = 0; $i < $_SESSION["glpisearchcount"][$itemtype]; $i++) { if (isset($p['contains'][$i]) && strlen($p['contains'][$i]) > 0) { $nosearch = false; } } if ($_SESSION["glpisearchcount2"][$itemtype] > 0) { $nosearch = false; } $LIMIT = ""; $numrows = 0; //No search : count number of items using a simple count(ID) request and LIMIT search if ($nosearch) { $LIMIT = " LIMIT " . $p['start'] . ", " . $LIST_LIMIT; // Force group by for all the type -> need to count only on table ID if (!isset($searchopt[$itemtype][1]['forcegroupby'])) { $count = "count(*)"; } else { $count = "count(DISTINCT `{$itemtable}`.`id`)"; } // request currentuser for SQL supervision, not displayed $query_num = "SELECT {$count},\n '" . Toolbox::addslashes_deep($_SESSION['glpiname']) . "' AS currentuser\n FROM `{$itemtable}`" . $COMMONLEFTJOIN; $first = true; if (!empty($COMMONWHERE)) { $LINK = " AND "; if ($first) { $LINK = " WHERE "; $first = false; } $query_num .= $LINK . $COMMONWHERE; } // Union Search : if (isset($CFG_GLPI["union_search_type"][$itemtype])) { $tmpquery = $query_num; $numrows = 0; foreach ($CFG_GLPI[$CFG_GLPI["union_search_type"][$itemtype]] as $ctype) { $ctable = getTableForItemType($ctype); if (($citem = getItemForItemtype($ctype)) && $citem->canView()) { // State case if ($itemtype == 'AllAssets') { $query_num = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $tmpquery); $query_num = str_replace($itemtype, $ctype, $query_num); $query_num .= " AND `{$ctable}`.`id` IS NOT NULL "; // Add deleted if item have it if ($citem && $citem->maybeDeleted()) { $query_num .= " AND `{$ctable}`.`is_deleted` = '0' "; } // Remove template items if ($citem && $citem->maybeTemplate()) { $query_num .= " AND `{$ctable}`.`is_template` = '0' "; } } else { // Ref table case $reftable = getTableForItemType($itemtype); if ($item && $item->maybeDeleted()) { $tmpquery = str_replace("`" . $CFG_GLPI["union_search_type"][$itemtype] . "`.`is_deleted`", "`{$reftable}`.`is_deleted`", $tmpquery); } $replace = "FROM `{$reftable}`\n INNER JOIN `{$ctable}`\n ON (`{$reftable}`.`items_id` =`{$ctable}`.`id`\n AND `{$reftable}`.`itemtype` = '{$ctype}')"; $query_num = str_replace("FROM `" . $CFG_GLPI["union_search_type"][$itemtype] . "`", $replace, $tmpquery); $query_num = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $query_num); } $query_num = str_replace("ENTITYRESTRICT", getEntitiesRestrictRequest('', $ctable, '', '', $citem->maybeRecursive()), $query_num); $result_num = $DBread->query($query_num); $numrows += $DBread->result($result_num, 0, 0); } } } else { $result_num = $DBread->query($query_num); $numrows = $DBread->result($result_num, 0, 0); } } // If export_all reset LIMIT condition if ($p['export_all']) { $LIMIT = ""; } if (!empty($WHERE) || !empty($COMMONWHERE)) { if (!empty($COMMONWHERE)) { $WHERE = ' WHERE ' . $COMMONWHERE . (!empty($WHERE) ? ' AND ( ' . $WHERE . ' )' : ''); } else { $WHERE = ' WHERE ' . $WHERE . ' '; } $first = false; } if (!empty($HAVING)) { $HAVING = ' HAVING ' . $HAVING; } // Create QUERY if (isset($CFG_GLPI["union_search_type"][$itemtype])) { $first = true; $QUERY = ""; foreach ($CFG_GLPI[$CFG_GLPI["union_search_type"][$itemtype]] as $ctype) { $ctable = getTableForItemType($ctype); if (($citem = getItemForItemtype($ctype)) && $citem->canView()) { if ($first) { $first = false; } else { $QUERY .= " UNION "; } $tmpquery = ""; // AllAssets case if ($itemtype == 'AllAssets') { $tmpquery = $SELECT . ", '{$ctype}' AS TYPE " . $FROM . $WHERE; if ($itemtype == 'AllAssets') { $tmpquery .= " AND `{$ctable}`.`id` IS NOT NULL "; } // Add deleted if item have it if ($citem && $citem->maybeDeleted()) { $tmpquery .= " AND `{$ctable}`.`is_deleted` = '0' "; } // Remove template items if ($citem && $citem->maybeTemplate()) { $tmpquery .= " AND `{$ctable}`.`is_template` = '0' "; } $tmpquery .= $GROUPBY . $HAVING; $tmpquery = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $tmpquery); $tmpquery = str_replace($itemtype, $ctype, $tmpquery); } else { // Ref table case $reftable = getTableForItemType($itemtype); $tmpquery = $SELECT . ", '{$ctype}' AS TYPE,\n `{$reftable}`.`id` AS refID, " . "\n `{$ctable}`.`entities_id` AS ENTITY " . $FROM . $WHERE; if ($item->maybeDeleted()) { $tmpquery = str_replace("`" . $CFG_GLPI["union_search_type"][$itemtype] . "`.`is_deleted`", "`{$reftable}`.`is_deleted`", $tmpquery); } $replace = "FROM `{$reftable}`" . "\n INNER JOIN `{$ctable}`" . "\n ON (`{$reftable}`.`items_id`=`{$ctable}`.`id`" . "\n AND `{$reftable}`.`itemtype` = '{$ctype}')"; $tmpquery = str_replace("FROM `" . $CFG_GLPI["union_search_type"][$itemtype] . "`", $replace, $tmpquery); $tmpquery = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $tmpquery); } $tmpquery = str_replace("ENTITYRESTRICT", getEntitiesRestrictRequest('', $ctable, '', '', $citem->maybeRecursive()), $tmpquery); // SOFTWARE HACK if ($ctype == 'Software') { $tmpquery = str_replace("glpi_softwares.serial", "''", $tmpquery); $tmpquery = str_replace("glpi_softwares.otherserial", "''", $tmpquery); } $QUERY .= $tmpquery; } } if (empty($QUERY)) { echo self::showError($output_type); return; } $QUERY .= str_replace($CFG_GLPI["union_search_type"][$itemtype] . ".", "", $ORDER) . $LIMIT; } else { $QUERY = $SELECT . $FROM . $WHERE . $GROUPBY . $HAVING . $ORDER . $LIMIT; } $DBread->query("SET SESSION group_concat_max_len = 4096;"); $result = $DBread->query($QUERY); /// Check group concat limit : if warning : increase limit if ($result2 = $DBread->query('SHOW WARNINGS')) { if ($DBread->numrows($result2) > 0) { $data = $DBread->fetch_assoc($result2); if ($data['Code'] == 1260) { $DBread->query("SET SESSION group_concat_max_len = 4194304;"); $result = $DBread->query($QUERY); } } } // Get it from database and DISPLAY if ($result) { // if real search or complete export : get numrows from request if (!$nosearch || $p['export_all']) { $numrows = $DBread->numrows($result); } // Contruct Pager parameters $globallinkto = self::getArrayUrlLink("field", $p['field']) . self::getArrayUrlLink("link", $p['link']) . self::getArrayUrlLink("contains", $p['contains']) . self::getArrayUrlLink("searchtype", $p['searchtype']) . self::getArrayUrlLink("field2", $p['field2']) . self::getArrayUrlLink("contains2", $p['contains2']) . self::getArrayUrlLink("itemtype2", $p['itemtype2']) . self::getArrayUrlLink("searchtype2", $p['searchtype2']) . self::getArrayUrlLink("link2", $p['link2']); $parameters = "sort=" . $p['sort'] . "&order=" . $p['order'] . $globallinkto; // Not more used : clean pages : try to comment it /* $tmp=explode('?',$target,2); if (count($tmp)>1) { $target = $tmp[0]; $parameters = $tmp[1].'&'.$parameters; } */ if ($output_type == self::GLOBAL_SEARCH) { if ($item = getItemForItemtype($itemtype)) { echo "<div class='center'><h2>" . $item->getTypeName(); // More items if ($numrows > $p['start'] + self::GLOBAL_DISPLAY_COUNT) { echo " <a href='{$target}?{$parameters}'>" . __('All') . "</a>"; } echo "</h2></div>\n"; } else { return false; } } // If the begin of the view is before the number of items if ($p['start'] < $numrows) { // Display pager only for HTML if ($output_type == self::HTML_OUTPUT) { // For plugin add new parameter if available if ($plug = isPluginItemType($itemtype)) { $function = 'plugin_' . $plug['plugin'] . '_addParamFordynamicReport'; if (function_exists($function)) { $out = $function($itemtype); if (is_array($out) && count($out)) { foreach ($out as $key => $val) { if (is_array($val)) { $parameters .= self::getArrayUrlLink($key, $val); } else { $parameters .= "&{$key}={$val}"; } } } } } $search_config = ""; if (Session::haveRight("search_config", DisplayPreference::GENERAL)) { //|| Session::haveRight("search_config_global",CREATE)) { // Ajax::createModalWindow('searchconfig_window', // $CFG_GLPI['root_doc']."/ajax/searchconfig.php?itemtype=$itemtype", // array('title' => __('Select default items to show'), // 'width' => '1000')); // $tmp = " class='pointer' onClick=\"searchconfig_window.show()\""; $tmp = " class='pointer' onClick=\"var w = window.open('" . $CFG_GLPI["root_doc"] . "/front/popup.php?popup=search_config&itemtype={$itemtype}' ,'glpipopup', " . "'height=400, width=1000, top=100, left=100, scrollbars=yes'); w.focus();\""; $search_config = "<img alt=\"" . __s('Select default items to show') . "\" title=\"" . __s('Select default items to show') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/options_search.png' "; $search_config .= $tmp . ">"; } Html::printPager($p['start'], $numrows, $target, $parameters, $itemtype, 0, $search_config); } // Define begin and end var for loop // Search case $begin_display = $p['start']; $end_display = min($numrows, $p['start'] + $LIST_LIMIT); // No search Case if ($nosearch) { $begin_display = 0; $end_display = min($numrows - $p['start'], $LIST_LIMIT); } // Export All case if ($p['export_all']) { $begin_display = 0; $end_display = $numrows; } // Form to massive actions $isadmin = $item && $item->canUpdate(); if (!$isadmin && in_array($itemtype, $CFG_GLPI["infocom_types"])) { $isadmin = Infocom::canUpdate() || Infocom::canCreate(); } $showmassiveactions = false; if ($itemtype != 'AllAssets') { $showmassiveactions = count($item->getAllMassiveActions($p['is_deleted'])); if ($showmassiveactions && $output_type == self::HTML_OUTPUT) { Html::openMassiveActionsForm('massform' . $itemtype); $massiveactionparams = array('num_displayed' => $end_display - $begin_display, 'fixed' => false, 'is_deleted' => $p['is_deleted']); Html::showMassiveActions($itemtype, $massiveactionparams); } } // Compute number of columns to display // Add toview elements $nbcols = $toview_count; $already_printed = array(); // Add meta search elements if real search (strlen>0) or only NOT search if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && is_array($p['itemtype2'])) { for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { if (isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0 && (!isset($p['link2'][$i]) || !strstr($p['link2'][$i], "NOT"))) { if (!isset($already_printed[$p['itemtype2'][$i] . $p['field2'][$i]])) { $nbcols++; $already_printed[$p['itemtype2'][$i] . $p['field2'][$i]] = 1; } } } } if ($output_type == self::HTML_OUTPUT) { // HTML display - massive modif $nbcols++; } // Display List Header echo self::showHeader($output_type, $end_display - $begin_display + 1, $nbcols); // New Line for Header Items Line $headers_line = ''; $headers_line_top = ''; $headers_line_bottom = ''; echo self::showNewLine($output_type); $header_num = 1; if ($output_type == self::HTML_OUTPUT && $showmassiveactions) { // HTML display - massive modif $headers_line_top .= self::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']); $headers_line_bottom .= self::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']); } // Display column Headers for toview items foreach ($toview as $key => $val) { $linkto = ''; if (!isset($searchopt[$itemtype][$val]['nosort']) || !$searchopt[$itemtype][$val]['nosort']) { $linkto = "{$target}?itemtype={$itemtype}&sort=" . $val . "&order=" . ($p['order'] == "ASC" ? "DESC" : "ASC") . "&start=" . $p['start'] . $globallinkto; } $headers_line .= self::showHeaderItem($output_type, $searchopt[$itemtype][$val]["name"], $header_num, $linkto, $p['sort'] == $val, $p['order']); } // Display columns Headers for meta items $already_printed = array(); if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && is_array($p['itemtype2'])) { for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { if (isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0) { if (!isset($already_printed[$p['itemtype2'][$i] . $p['field2'][$i]])) { if (!isset($metanames[$p['itemtype2'][$i]])) { if ($metaitem = getItemForItemtype($p['itemtype2'][$i])) { $metanames[$p['itemtype2'][$i]] = $metaitem->getTypeName(); } } $headers_line .= self::showHeaderItem($output_type, sprintf(__('%1$s - %2$s'), $metanames[$p['itemtype2'][$i]], $searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["name"]), $header_num); $already_printed[$p['itemtype2'][$i] . $p['field2'][$i]] = 1; } } } } // Add specific column Header if ($itemtype == 'CartridgeItem') { $headers_line .= self::showHeaderItem($output_type, _n('Cartridge', 'Cartridges', 2), $header_num); } if ($itemtype == 'ConsumableItem') { $headers_line .= self::showHeaderItem($output_type, _n('Consumable', 'Consumables', 2), $header_num); } if (isset($CFG_GLPI["union_search_type"][$itemtype])) { $headers_line .= self::showHeaderItem($output_type, __('Item type'), $header_num); } if ($itemtype == 'ReservationItem' && $output_type == self::HTML_OUTPUT) { $headers_line .= self::showHeaderItem($output_type, " ", $header_num); } // End Line for column headers $headers_line .= self::showEndLine($output_type); $headers_line_top .= $headers_line; $headers_line_bottom .= $headers_line; echo $headers_line_top; // if real search seek to begin of items to display (because of complete search) if (!$nosearch) { $DBread->data_seek($result, $p['start']); } // Define begin and end var for loop // Search case $i = $begin_display; // Init list of items displayed if ($output_type == self::HTML_OUTPUT) { Session::initNavigateListItems($itemtype); } // Num of the row (1=header_line) $row_num = 1; $massiveaction_field = 'id'; if (isset($CFG_GLPI["union_search_type"][$itemtype])) { $massiveaction_field = 'refID'; } // Display Loop while ($i < $numrows && $i < $end_display) { // Column num $item_num = 1; // Get data and increment loop variables $data = $DBread->fetch_assoc($result); $i++; $row_num++; // New line echo self::showNewLine($output_type, $i % 2, $p['is_deleted']); // Add item in item list Session::addToNavigateListItems($itemtype, $data["id"]); if ($output_type == self::HTML_OUTPUT && $showmassiveactions) { // HTML display - massive modif $tmpcheck = ""; if ($itemtype == 'Entity' && !in_array($data["id"], $_SESSION["glpiactiveentities"])) { $tmpcheck = " "; } else { if ($item->maybeRecursive() && !in_array($data["entities_id"], $_SESSION["glpiactiveentities"])) { $tmpcheck = " "; } else { $tmpcheck = Html::getMassiveActionCheckBox($itemtype, $data[$massiveaction_field]); } } echo self::showItem($output_type, $tmpcheck, $item_num, $row_num, "width='10'"); } // Print other toview items foreach ($toview as $key => $val) { echo self::showItem($output_type, self::giveItem($itemtype, $val, $data, $key), $item_num, $row_num, self::displayConfigItem($itemtype, $val, $data, $key)); } // Print Meta Item $already_printed = array(); if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && is_array($p['itemtype2'])) { for ($j = 0; $j < $_SESSION["glpisearchcount2"][$itemtype]; $j++) { if (isset($p['itemtype2'][$j]) && !empty($p['itemtype2'][$j]) && isset($p['contains2'][$j]) && strlen($p['contains2'][$j]) > 0) { if (!isset($already_printed[$p['itemtype2'][$j] . $p['field2'][$j]])) { // General case if (strpos($data["META_{$j}"], "\$\$\$\$") === false) { $out = self::giveItem($p['itemtype2'][$j], $p['field2'][$j], $data, $j, 1); echo self::showItem($output_type, $out, $item_num, $row_num); // Case of GROUP_CONCAT item : split item and multilline display } else { $split = explode("\$\$\$\$", $data["META_{$j}"]); $count_display = 0; $out = ""; $unit = ""; $separate = '<br>'; if (isset($searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['splititems']) && $searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['splititems']) { $separate = '<hr>'; } if (isset($searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['unit'])) { $unit = $searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['unit']; } for ($k = 0; $k < count($split); $k++) { if ($p['contains2'][$j] == "NULL" || strlen($p['contains2'][$j]) == 0 || preg_match('/' . $p['contains2'][$j] . '/i', $split[$k]) || isset($searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['forcegroupby'])) { if ($count_display) { $out .= $separate; } $count_display++; // Manage Link to item $split2 = self::explodeWithID("\$\$", $split[$k]); if (isset($split2[1])) { if (isset($searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['datatype']) && $searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['datatype'] == 'itemlink') { $out .= "<a id='" . $p['itemtype2'][$j] . '_' . $data["id"] . '_' . $split2[1] . "' "; $out .= "href=\"" . Toolbox::getItemTypeFormURL($p['itemtype2'][$j]) . "?id=" . $split2[1] . "\">"; $out .= Dropdown::getValueWithUnit($split2[0], $unit); $linkout = $out; if ($_SESSION["glpiis_ids_visible"] || empty($split2[0])) { $linkout = sprintf(__('%1$s (%2$s)'), $linkout, $split2[1]); } $out = $linkout . "</a>"; } else { $out .= Dropdown::getValueWithUnit($split2[0], $unit); } } else { $out .= Dropdown::getValueWithUnit($split[$k], $unit); } } } echo self::showItem($output_type, $out, $item_num, $row_num); } $already_printed[$p['itemtype2'][$j] . $p['field2'][$j]] = 1; } } } } // Specific column display if ($itemtype == 'CartridgeItem') { echo self::showItem($output_type, Cartridge::getCount($data["id"], $data["ALARM"], $output_type != self::HTML_OUTPUT), $item_num, $row_num); } if ($itemtype == 'ConsumableItem') { echo self::showItem($output_type, Consumable::getCount($data["id"], $data["ALARM"], $output_type != self::HTML_OUTPUT), $item_num, $row_num); } if (isset($CFG_GLPI["union_search_type"][$itemtype])) { $typename = $data["TYPE"]; if ($itemtmp = getItemForItemtype($data["TYPE"])) { $typename = $itemtmp->getTypeName(); } echo self::showItem($output_type, $typename, $item_num, $row_num); } if ($itemtype == 'ReservationItem' && $output_type == self::HTML_OUTPUT) { if ($data["ACTIVE"]) { echo self::showItem($output_type, "<a href='reservation.php?reservationitems_id=" . $data["refID"] . "' title=\"" . __s('See planning') . "\">" . "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/reservation-3.png\" alt='' title=''></a>", $item_num, $row_num, "class='center'"); } else { echo self::showItem($output_type, " ", $item_num, $row_num); } } // End Line echo self::showEndLine($output_type); } $title = ""; // Create title if ($output_type == self::PDF_OUTPUT_LANDSCAPE || $output_type == self::PDF_OUTPUT_PORTRAIT) { if ($_SESSION["glpisearchcount"][$itemtype] > 0 && count($p['contains']) > 0) { for ($key = 0; $key < $_SESSION["glpisearchcount"][$itemtype]; $key++) { $titlecontain = ''; if (strlen($p['contains'][$key]) > 0) { if (isset($p["link"][$key])) { $titlecontain = " " . $p["link"][$key] . " "; } switch ($p['field'][$key]) { case "all": $titlecontain = sprintf(__('%1$s %2$s'), $titlecontain, __('All')); break; case "view": $titlecontain = sprintf(__('%1$s %2$s'), $titlecontain, __('Items seen')); break; default: $titlecontain = sprintf(__('%1$s %2$s'), $titlecontain, $searchopt[$itemtype][$p['field'][$key]]["name"]); } switch ($p['searchtype'][$key]) { case "equals": if (in_array($searchopt[$itemtype][$p['field'][$key]]["field"], array('name', 'completename'))) { $titlecontain = sprintf(__('%1$s = %2$s'), $titlecontain, Dropdown::getDropdownName($searchopt[$itemtype][$p['field'][$key]]["table"], $p['contains'][$key])); } else { $titlecontain = sprintf(__('%1$s = %2$s'), $titlecontain, $p['contains'][$key]); } break; case "notequals": if (in_array($searchopt[$itemtype][$p['field'][$key]]["field"], array('name', 'completename'))) { $titlecontain = sprintf(__('%1$s <> %2$s'), $titlecontain, Dropdown::getDropdownName($searchopt[$itemtype][$p['field'][$key]]["table"], $p['contains'][$key])); } else { $titlecontain = sprintf(__('%1$s <> %2$s'), $titlecontain, $p['contains'][$key]); } break; case "lessthan": $titlecontain = sprintf(__('%1$s < %2$s'), $titlecontain, $p['contains'][$key]); break; case "morethan": $titlecontain = sprintf(__('%1$s > %2$s'), $titlecontain, $p['contains'][$key]); break; case "contains": $titlecontain = sprintf(__('%1$s = %2$s'), $titlecontain, '%' . $p['contains'][$key] . '%'); break; case "under": $titlecontain = sprintf(__('%1$s %2$s'), $titlecontain, sprintf(__('%1$s %2$s'), __('under'), Dropdown::getDropdownName($searchopt[$itemtype][$p['field'][$key]]["table"], $p['contains'][$key]))); break; case "notunder": $titlecontain = sprintf(__('%1$s %2$s'), $titlecontain, sprintf(__('%1$s %2$s'), __('not under'), Dropdown::getDropdownName($searchopt[$itemtype][$p['field'][$key]]["table"], $p['contains'][$key]))); break; default: $titlecontain = sprintf(__('%1$s = %2$s'), $titlecontain, $p['contains'][$key]); break; } } $title .= $titlecontain; } } if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && count($p['contains2']) > 0) { for ($key = 0; $key < $_SESSION["glpisearchcount2"][$itemtype]; $key++) { $titlecontain2 = ''; if (strlen($p['contains2'][$key]) > 0) { if (isset($p['link2'][$key])) { $titlecontain2 = sprintf(__('%1$s %2$s'), $titlecontain2, $p['link2'][$key]); } $titlecontain2 = sprintf(__('%1$s %2$s'), $titlecontain2, sprintf(__('%1$s / %2$s'), $metanames[$p['itemtype2'][$key]], $searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["name"])); switch ($p['searchtype2'][$key]) { case "equals": if (in_array($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["field"], array('name', 'completename'))) { $titlecontain2 = sprintf(__('%1$s = %2$s'), $titlecontain2, Dropdown::getDropdownName($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["table"], $p['contains2'][$key])); } else { $titlecontain2 = sprintf(__('%1$s = %2$s'), $titlecontain2, $p['contains2'][$key]); } break; case "notequals": if (in_array($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["field"], array('name', 'completename'))) { $titlecontain2 = sprintf(__('%1$s <> %2$s'), $titlecontain2, Dropdown::getDropdownName($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["table"], $p['contains2'][$key])); } else { $titlecontain2 = sprintf(__('%1$s <> %2$s'), $titlecontain2, $p['contains2'][$key]); } break; case "lessthan": $titlecontain2 = sprintf(__('%1$s < %2$s'), $titlecontain2, $p['contains2'][$key]); break; case "morethan": $titlecontain2 = sprintf(__('%1$s > %2$s'), $titlecontain2, $p['contains2'][$key]); break; case "contains": $titlecontain2 = sprintf(__('%1$s = %2$s'), $titlecontain2, '%' . $p['contains2'][$key] . '%'); break; case "under": $titlecontain2 = sprintf(__('%1$s %2$s'), $titlecontain2, sprintf(__('%1$s %2$s'), __('under'), Dropdown::getDropdownName($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["table"], $p['contains2'][$key]))); break; case "notunder": $titlecontain2 = sprintf(__('%1$s %2$s'), $titlecontain2, sprintf(__('%1$s %2$s'), __('not under'), Dropdown::getDropdownName($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["table"], $p['contains2'][$key]))); break; default: $titlecontain2 = sprintf(__('%1$s = %2$s'), $titlecontain2, $p['contains2'][$key]); break; } } $title .= $titlecontain2; } } } if ($output_type == self::HTML_OUTPUT) { echo $headers_line_bottom; } // Display footer echo self::showFooter($output_type, $title); // Delete selected item if ($output_type == self::HTML_OUTPUT) { if ($showmassiveactions) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($itemtype, $massiveactionparams); // End form for delete item Html::closeForm(); } else { echo "<br>"; } } if ($output_type == self::HTML_OUTPUT) { // In case of HTML display Html::printPager($p['start'], $numrows, $target, $parameters, '', 0, $search_config); } } else { echo self::showError($output_type); } } else { echo $DBread->error(); } }
static function install(Migration $migration) { global $DB; $table = getTableForItemType(__CLASS__); if (!TableExists($table)) { $query = "CREATE TABLE `{$table}` (\n `id` INT( 11 ) NOT NULL AUTO_INCREMENT,\n `entities_id` INT( 11 ) NOT NULL DEFAULT 0,\n `itemtype` varchar(255) collate utf8_unicode_ci default NULL,\n `is_active` tinyint(1) NOT NULL default '0',\n `name` varchar(255) collate utf8_unicode_ci default NULL,\n `comment` text NULL,\n `date_mod` datetime DEFAULT NULL,\n `date_creation` datetime DEFAULT NULL,\n `use_global_search` tinyint(1) NOT NULL default '0',\n `use_unicity` tinyint(1) NOT NULL default '0',\n `use_history` tinyint(1) NOT NULL default '0',\n `use_infocoms` tinyint(1) NOT NULL default '0',\n `use_contracts` tinyint(1) NOT NULL default '0',\n `use_documents` tinyint(1) NOT NULL default '0',\n `use_tickets` tinyint(1) NOT NULL default '0',\n `use_links` tinyint(1) NOT NULL default '0',\n `use_loans` tinyint(1) NOT NULL default '0',\n `use_network_ports` tinyint(1) NOT NULL default '0',\n `use_direct_connections` tinyint(1) NOT NULL default '0',\n `use_plugin_datainjection` tinyint(1) NOT NULL default '0',\n `use_plugin_pdf` tinyint(1) NOT NULL default '0',\n `use_plugin_order` tinyint(1) NOT NULL default '0',\n `use_plugin_uninstall` tinyint(1) NOT NULL default '0',\n `use_plugin_geninventorynumber` tinyint(1) NOT NULL default '0',\n `use_menu_entry` tinyint(1) NOT NULL default '0',\n `use_projects` tinyint(1) NOT NULL default '0',\n `linked_itemtypes` text NULL,\n `plugin_genericobject_typefamilies_id` INT( 11 ) NOT NULL DEFAULT 0,\n PRIMARY KEY ( `id` )\n ) ENGINE = MYISAM COMMENT = 'Object types definition table' DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query) or die($DB->error()); } $migration->addField($table, "use_network_ports", "bool"); $migration->addField($table, "use_direct_connections", "bool"); $migration->addField($table, "use_plugin_geninventorynumber", "bool"); $migration->addField($table, "use_contracts", "bool"); $migration->addField($table, "use_menu_entry", "bool"); $migration->addField($table, "use_global_search", "bool"); $migration->addField($table, "use_projects", "bool"); $migration->addField($table, "use_notepad", "bool"); $migration->addField($table, "comment", "text"); if (!$migration->addField($table, "date_mod", "datetime")) { $migration->changeField($table, "date_mod", "date_mod", "datetime"); } $migration->addField($table, "date_creation", "datetime"); $migration->addField($table, "linked_itemtypes", "text"); $migration->addField($table, "plugin_genericobject_typefamilies_id", "integer"); $migration->addField($table, "use_plugin_simcard", "bool"); $migration->migrationOneTable($table); // Migrate notepad data $allGenericObjectTypes = PluginGenericobjectType::getTypes(true); $notepad = new Notepad(); foreach ($allGenericObjectTypes as $genericObjectType => $genericObjectData) { $genericObjectTypeInstance = new $genericObjectType(); if (FieldExists($genericObjectTypeInstance->getTable(), "notepad")) { $query = "INSERT INTO `" . $notepad->getTable() . "`\n (`items_id`,\n `itemtype`,\n `date`,\n `date_mod`,\n `content`\n )\n SELECT\n `id` as `items_id`,\n '" . $genericObjectType . "' as `itemtype`,\n now() as `date`,\n now() as `date_mod`,\n `notepad` as `content`\n FROM `" . $genericObjectTypeInstance->getTable() . "`\n WHERE notepad IS NOT NULL\n AND notepad <> ''"; $DB->query($query) or die($DB->error()); } $query = "UPDATE`" . $notepad->getTable() . "`"; $migration->dropField($genericObjectTypeInstance->getTable(), "notepad"); $migration->migrationOneTable($genericObjectTypeInstance->getTable()); } //Displayprefs $prefs = array(10 => 6, 9 => 5, 8 => 4, 7 => 3, 6 => 2, 2 => 1, 4 => 1, 11 => 7, 12 => 8, 14 => 10, 15 => 11); foreach ($prefs as $num => $rank) { if (!countElementsInTable("glpi_displaypreferences", "`itemtype`='" . __CLASS__ . "' AND `num`='{$num}'\n AND `users_id`='0'")) { $preference = new DisplayPreference(); $tmp['itemtype'] = __CLASS__; $tmp['num'] = $num; $tmp['rank'] = $rank; $tmp['users_id'] = 0; $preference->add($tmp); } } //If files are missing, recreate them! self::checkClassAndFilesForItemType(); }
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief */ if (!defined('GLPI_ROOT')) { include '../inc/includes.php'; } Html::popHeader(__('Setup'), $_SERVER['PHP_SELF']); Session::haveRightsOr('serach_config', array(DisplayPreference::PERSONAL, DisplayPreference::GENERAL)); $setupdisplay = new DisplayPreference(); if (isset($_POST["activate"])) { $setupdisplay->activatePerso($_POST); } else { if (isset($_POST["disable"])) { if ($_POST['users_id'] == Session::getLoginUserID()) { $setupdisplay->deleteByCriteria(array('users_id' => $_POST['users_id'], 'itemtype' => $_POST['itemtype'])); } } else { if (isset($_POST["add"])) { $setupdisplay->add($_POST); } else { if (isset($_POST["purge"]) || isset($_POST["purge_x"])) { $setupdisplay->delete($_POST, 1); } else { if (isset($_POST["up"]) || isset($_POST["up_x"])) {
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -------------------------------------------------------------------------- */ // ---------------------------------------------------------------------- // Original Author of file: // Purpose of file: // ---------------------------------------------------------------------- if (!defined('GLPI_ROOT')) { define('GLPI_ROOT', '..'); include GLPI_ROOT . "/inc/includes.php"; } if (!strpos($_SERVER['PHP_SELF'], "popup")) { commonHeader($LANG['common'][12], $_SERVER['PHP_SELF'], "config", "display"); } checkSeveralRightsOr(array("search_config_global" => "w", "search_config" => "w")); $setupdisplay = new DisplayPreference(); if (isset($_POST["activate"])) { $setupdisplay->activatePerso($_POST); } else { if (isset($_POST["add"])) { $setupdisplay->add($_POST); } else { if (isset($_POST["delete"]) || isset($_POST["delete_x"])) { $setupdisplay->delete($_POST); } else { if (isset($_POST["up"]) || isset($_POST["up_x"])) { $setupdisplay->orderItem($_POST, 'up'); } else { if (isset($_POST["down"]) || isset($_POST["down_x"])) { $setupdisplay->orderItem($_POST, 'down'); } else {