Get the SEARCH_OPTION array
static public getOptions ( $itemtype, $withplugins = true ) : the | ||
$itemtype | ||
$withplugins | boolean get search options from plugins (true by default) | |
Résultat | the | reference to array of search options for the given item type |
/** * @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::getOptions() **/ function getOptions($primary_type = '') { $tab = Search::getOptions(get_parent_class($this)); //Specific to location $tab[5]['checktype'] = 'date'; $tab[6]['minvalue'] = 0; $tab[6]['maxvalue'] = 120; $tab[6]['step'] = 1; $tab[6]['checktype'] = 'integer'; $tab[7]['minvalue'] = 0; $tab[7]['maxvalue'] = 120; $tab[7]['step'] = 1; $tab[7]['checktype'] = 'integer'; $tab[11]['checktype'] = 'float'; $tab[20]['checktype'] = 'date'; $tab[22]['linkfield'] = 'billing'; // Associated suppliers $tab[29]['linkfield'] = 'suppliers_id'; $tab[29]['displaytype'] = 'relation'; $tab[29]['relationclass'] = 'Contract_Supplier'; $tab[29]['relationfield'] = $tab[29]['linkfield']; //Remove some options because some fields cannot be imported $blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this)); $notimportable = array(12, 13, 20, 41, 42, 43, 44, 45, 72); $options['ignore_fields'] = array_merge($blacklist, $notimportable); $options['displaytype'] = array("dropdown" => array(4), "date" => array(5), "dropdown_integer" => array(6, 7, 21), "bool" => array(86), "alert" => array(59), "billing" => array(22), "renewal" => array(23), "multiline_text" => array(16, 90)); return PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); }
/** * @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::getOptions() **/ function getOptions($primary_type = '') { $tab = Search::getOptions(get_parent_class($this)); ${$blacklist} = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this)); $notimportable = array(); $options['ignore_fields'] = array_merge($blacklist, $notimportable); $options['displaytype'] = array("multiline_text" => array(16)); return PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); }
/** * @see PluginDatainjectionInjectionInterface::getOptions() */ function getOptions($primary_type = '') { $tab = Search::getOptions(get_parent_class($this)); $notimportable = array(5, 9, 29, 30, 31, 50, 53, 56, 57, 58, 59, 60, 80, 91, 92, 122, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140); $options['ignore_fields'] = $notimportable; $options['displaytype'] = array("dropdown" => array(2, 32, 3, 8, 49, 10), "user" => array(6, 24), "multiline_text" => array(4), "date" => array(9), "bool" => array(11, 7)); $tab = PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); return $tab; }
/** * @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::getOptions() */ function getOptions($primary_type = '') { $tab = Search::getOptions(get_parent_class($this)); //Remove some options because some fields cannot be imported $blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this)); $notimportable = array(); $options['ignore_fields'] = array_merge($blacklist, $notimportable); return PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); }
/** * @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::getOptions() **/ function getOptions($primary_type = '') { $tab = Search::getOptions(get_parent_class($this)); //Remove some options because some fields cannot be imported $blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this)); $notimportable = array(14, 26, 27, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 47, 48, 49, 50, 51, 52, 53, 54, 55, 91, 92, 93); $options['ignore_fields'] = array_merge($blacklist, $notimportable); $options['displaytype'] = array("multiline_text" => array(3, 16, 17, 24), "dropdown" => array(9)); return PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); }
/** * @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::getOptions() **/ function getOptions($primary_type = '') { $tab = Search::getOptions(get_parent_class($this)); //Remove some options because some fields cannot be imported $blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this)); $notimportable = array(8, 29); $options['ignore_fields'] = array_merge($blacklist, $notimportable); $options['displaytype'] = array("dropdown" => array(9), "multiline_text" => array(3, 16, 90), "bool" => array(86)); return PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); }
function getOptions($primary_type = '') { $tab = Search::getOptions(get_parent_class($this)); //$blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(); //Remove some options because some fields cannot be imported $options['ignore_fields'] = array(2, 80, 86, 19); $options['displaytype'] = array("multiline_text" => array(16)); $tab = PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); return $tab; }
/** * @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::getOptions() **/ function getOptions($primary_type = '') { $tab = Search::getOptions(get_parent_class($this)); $tab[5]['checktype'] = 'datetime'; //Remove some options because some fields cannot be imported $blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this)); $notimportable = array(); $options['ignore_fields'] = array_merge($blacklist, $notimportable); $options['displaytype'] = array("dropdown" => array(4), "date" => array(5), "multiline_text" => array(6, 7), "bool" => array(8, 9, 86), "user" => array(70)); return PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); }
function getOptions($primary_type = '') { $tab = Search::getOptions(get_parent_class($this)); //Specific to location $tab[12]['linkfield'] = 'locations_id'; //$blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(); //Remove some options because some fields cannot be imported $notimportable = array(7, 30, 80); $options['ignore_fields'] = $notimportable; $options['displaytype'] = array("dropdown" => array(2, 3, 4, 6, 10, 12), "user" => array(11), "multiline_text" => array(9), "date" => array(14), "bool" => array(8, 13)); return PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); }
/** * @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::getOptions() **/ function getOptions($primary_type = '') { $tab = Search::getOptions(get_parent_class($this)); //Specific to location $tab[3]['linkfield'] = 'locations_id'; //Remove some options because some fields cannot be imported $blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this)); $notimportable = array(10, 11, 12, 13, 14, 15, 19, 34, 35, 36, 39, 91, 92, 93, 150, 151, 152, 153, 154, 155, 156, 160, 161, 162, 163, 164, 165, 166); $options['ignore_fields'] = array_merge($blacklist, $notimportable); $options['displaytype'] = array("dropdown" => array(3, 4, 23, 31, 32, 33, 40, 41, 42, 45, 46, 49, 71), "user" => array(24, 70), "multiline_text" => array(16, 90)); return PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); }
/** * @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::getOptions() **/ function getOptions($primary_type = '') { $tab = Search::getOptions(get_parent_class($this)); //Specific to location $tab[3]['linkfield'] = 'locations_id'; //Remove some options because some fields cannot be imported $blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this)); $notimportable = array(91, 92, 93); $options['ignore_fields'] = array_merge($blacklist, $notimportable); $options['displaytype'] = array("dropdown" => array(3, 4, 23, 31, 40, 49, 46, 71), "user" => array(24, 70), "float" => array(11), "bool" => array(41, 42, 43, 44, 45, 46, 47, 48), "multiline_text" => array(16, 90)); return PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); }
/** * @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::getOptions() **/ function getOptions($primary_type = '') { $tab = Search::getOptions(get_parent_class($this)); $tab[3]['checktype'] = 'date'; $tab[4]['checktype'] = 'float'; $tab[5]['checktype'] = 'date'; //Remove some options because some fields cannot be imported $blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this)); $notimportable = array(); $options['ignore_fields'] = array_merge($blacklist, $notimportable); $options['displaytype'] = array("date" => array(3, 5), "yesno" => array(86), "multiline_text" => array(16, 90), "decimal" => array(4)); return PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); }
function getOptions($primary_type = '') { $tab = Search::getOptions(get_parent_class($this)); //Specific to location $tab[12]['linkfield'] = 'locations_id'; //$blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(); //Remove some options because some fields cannot be imported $notimportable = array(8, 16, 18, 19, 31, 80); $options['ignore_fields'] = $notimportable; $options['displaytype'] = array("dropdown" => array(3, 11, 12, 17, 21, 22, 23, 24, 25), "user" => array(4, 10, 14), "multiline_text" => array(7), "date" => array(5, 6, 9), "bool" => array(13, 15), "decimal" => array(20)); $tab = PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); return $tab; }
function getOptions($primary_type = '') { $tab = Search::getOptions(get_parent_class($this)); //Specific to location $tab[4]['checktype'] = 'date'; //$blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(); //Remove some options because some fields cannot be imported $notimportable = array(30, 80); $options['ignore_fields'] = $notimportable; $options['displaytype'] = array("user" => array(2), "multiline_text" => array(3), "date" => array(4)); $tab = PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); return $tab; }
/** * @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::getOptions() **/ function getOptions($primary_type = '') { $tab = Search::getOptions(get_parent_class($this)); $tab[3]['checktype'] = 'bool'; $tab[3]['displaytype'] = 'bool'; $tab[4]['checktype'] = 'text'; $tab[4]['displaytype'] = 'dropdown'; //Remove some options because some fields cannot be imported $blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this)); $notimportable = array(4); $options['ignore_fields'] = array_merge($blacklist, $notimportable); $options['displaytype'] = array("bool" => array(3, 6, 7), "dropdown" => array(4)); return PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); }
function getOptions($primary_type = '') { $tab = Search::getOptions(get_parent_class($this)); //Specific to location $tab[3]['linkfield'] = 'locations_id'; //Remove some options because some fields cannot be imported $blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this)); $notimportable = array(5, 9, 31, 91, 92, 93); $options['ignore_fields'] = array_merge($blacklist, $notimportable); $key = array_search(2, $options['ignore_fields']); unset($options['ignore_fields'][$key]); $options['displaytype'] = array("dropdown" => array(2, 3, 8, 10, 32, 49), "user" => array(6, 24), "multiline_text" => array(4), "bool" => array(7, 11)); $tab = PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); return $tab; }
/** * @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::getOptions() **/ function getOptions($primary_type = '') { $tab = Search::getOptions(get_parent_class($this)); //Specific to location $tab[3]['linkfield'] = 'locations_id'; $tab[8]['minvalue'] = '1'; $tab[8]['maxvalue'] = '100'; $tab[8]['step'] = 1; $tab[8]['-1'] = __('Never'); //Remove some options because some fields cannot be imported $blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this)); $notimportable = array(91, 92, 93); $options['ignore_fields'] = array_merge($blacklist, $notimportable); $options['displaytype'] = array("dropdown" => array(3, 4, 23, 49), "user" => array(24), "multiline_text" => array(16, 90), "dropdown_integer" => array(8)); $options['checktype'] = array("integer" => array(8)); return PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); }
function plugin_itilcategorygroups_giveItem($type, $ID, $data, $num) { $searchopt =& Search::getOptions($type); $table = $searchopt[$ID]["table"]; $field = $searchopt[$ID]["field"]; $value = $data['raw']["ITEM_{$num}"]; switch ($table . '.' . $field) { case "glpi_plugin_itilcategorygroups_groups_levels.lvl": switch ($value) { case 1: case 2: case 3: case 4: return __('Level ' . $value, 'itilcategorygroups'); } } return ""; }
/** * @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::getOptions() **/ function getOptions($primary_type = '') { $tab = Search::getOptions(get_parent_class($this)); //Specific to location $tab[3]['linkfield'] = 'locations_id'; //Virtual type : need to be processed at the end ! $tab[200]['table'] = 'glpi_networkequipments'; $tab[200]['field'] = 'nb_ports'; $tab[200]['name'] = __('Number of ports', 'datainjection'); $tab[200]['checktype'] = 'integer'; $tab[200]['displaytype'] = 'virtual'; $tab[200]['linkfield'] = 'nb_ports'; $tab[200]['injectable'] = PluginDatainjectionCommonInjectionLib::FIELD_VIRTUAL; //Remove some options because some fields cannot be imported $blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this)); $notimportable = array(91, 92, 93); $options['ignore_fields'] = array_merge($blacklist, $notimportable); $options['displaytype'] = array("dropdown" => array(3, 4, 11, 23, 31, 32, 33, 40, 49, 71), "bool" => array(86), "user" => array(24, 70), "multiline_text" => array(16, 90)); return PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); }
/** * @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::getOptions() **/ function getOptions($primary_type = '') { $tab = Search::getOptions(get_parent_class($this)); if ($primary_type == 'SoftwareVersion') { $tab[100]['name'] = _n('Software', 'Software', 1); $tab[100]['field'] = 'name'; $tab[100]['table'] = getTableForItemType('Software'); $tab[100]['linkfield'] = 'softwares_id'; $tab[100]['displaytype'] = 'dropdown'; $tab[100]['checktype'] = 'text'; $tab[100]['injectable'] = true; } //Remove some options because some fields cannot be imported $blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this)); $notimportable = array(); $options['ignore_fields'] = array_merge($blacklist, $notimportable); $key = array_search(2, $options['ignore_fields']); unset($options['ignore_fields'][$key]); $options['displaytype'] = array("dropdown" => array(4, 31), "multiline_text" => array(16), "software" => array(100)); return PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); }
/** * Return item description * * @param $itemtype * @param $ID * @param $data * @param $num * @return string */ function plugin_rackview_giveItem($itemtype, $ID, $data, $num) { $searchopt = Search::getOptions($itemtype); $NAME = "ITEM_"; $unit = ''; if (isset($searchopt[$ID]['unit'])) { $unit = $searchopt[$ID]['unit']; } if (isset($searchopt[$ID]["itemlink_type"])) { $link = Toolbox::getItemTypeFormURL($searchopt[$ID]["itemlink_type"]); } else { $link = Toolbox::getItemTypeFormURL($itemtype); } $out = ""; $rackDisplay = ""; if ($ID == 1) { $rack = new PluginRackviewRack(); $rack->getFromDB($data['id']); $rackDisplay = '<div style="float:left; margin-right: 1em" ' . 'class="CSSTableGenerator">' . $rack->buildRack(true) . '</div>'; } $sub = ""; if (isset($data[$NAME . $num . "_2"])) { $sub = $data[$NAME . $num . "_2"]; } $out .= "<a id='" . $itemtype . "_" . $sub . "' href=\"" . $link; $out .= strstr($link, '?') ? '&' : '?'; $out .= 'id=' . $sub; if (isset($searchopt[$ID]['forcetab'])) { $out .= "&forcetab=" . $searchopt[$ID]['forcetab']; } $out .= "\">" . $data[$NAME . $num] . $unit; if (($_SESSION["glpiis_ids_visible"] || empty($data[$NAME . $num])) && isset($data[$NAME . $num . "_2"])) { $out .= " (" . $data[$NAME . $num . "_2"] . ")"; } $out .= "</a>"; if ($rackDisplay != "") { $out .= HTML::showToolTip($rackDisplay, array('applyto' => $itemtype . "_" . $sub, 'display' => false)); } return $out; }
/** * @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::getOptions() **/ function getOptions($primary_type = '') { $tab = Search::getOptions(get_parent_class($this)); $tab[4]['checktype'] = 'mac'; //To manage vlans : relies on a CommonDBRelation object ! $tab[51]['name'] = sprintf(__('%1$s: %2$s'), __('Connected to'), __('Device name')); $tab[51]['field'] = 'netname'; $tab[51]['table'] = getTableForItemType('NetworkPort'); $tab[51]['linkfield'] = "netname"; $tab[51]['injectable'] = true; $tab[51]['displaytype'] = 'text'; $tab[51]['checktype'] = 'text'; $tab[52]['name'] = sprintf(__('%1$s: %2$s'), __('Connected to'), __('Port number')); $tab[52]['field'] = 'netport'; $tab[52]['table'] = getTableForItemType('NetworkPort'); $tab[52]['linkfield'] = "netport"; $tab[52]['injectable'] = true; $tab[52]['displaytype'] = 'text'; $tab[52]['checktype'] = 'text'; $tab[53]['name'] = sprintf(__('%1$s: %2$s'), __('Connected to'), __('Port MAC address', 'datainjection')); $tab[53]['field'] = 'netmac'; $tab[53]['table'] = getTableForItemType('NetworkPort'); $tab[53]['linkfield'] = "netmac"; $tab[53]['injectable'] = true; $tab[53]['displaytype'] = 'text'; $tab[53]['checktype'] = 'text'; //To manage vlans : relies on a CommonDBRelation object ! $tab[100]['name'] = __('VLAN'); $tab[100]['field'] = 'name'; $tab[100]['table'] = getTableForItemType('Vlan'); $tab[100]['linkfield'] = getForeignKeyFieldForTable($tab[100]['table']); $tab[100]['displaytype'] = 'relation'; $tab[100]['relationclass'] = 'NetworkPort_Vlan'; $tab[100]['storevaluein'] = $tab[100]['linkfield']; $blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this)); $notimportable = array(20, 21); $options['ignore_fields'] = array_merge($blacklist, $notimportable); $options['displaytype'] = array("dropdown" => array(9), "multiline_text" => array(16), "instantiation_type" => array(87)); return PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); }
function plugin_vip_giveItem($type, $ID, $data, $num) { global $CFG_GLPI, $DB; $searchopt =& Search::getOptions($type); $table = $searchopt[$ID]["table"]; $field = $searchopt[$ID]["field"]; $ticketid = $data['ITEM_0']; $vipdisplay = " "; $userquery = "SELECT users_id\n\t\t\t\t\t FROM glpi_tickets_users\n\t\t\t\t\tWHERE type = 1\n\t\t\t\t\t AND tickets_id = " . $ticketid; $userresult = $DB->query($userquery); $vipimg = "<img src=\"" . $CFG_GLPI['root_doc'] . "/plugins/vip/pics/vip.png\" alt='vip' >"; while ($uids = mysqli_fetch_object($userresult)) { foreach ($uids as $uid) { $vipquery = "SELECT count(*) AS nb\n\t\t\t\t\t\t FROM glpi_groups_users\n\t\t\t\t\t\t JOIN glpi_plugin_vip_groups\n\t\t\t\t\t\t\t ON glpi_plugin_vip_groups.id = glpi_groups_users.groups_id\n\t\t\t\t\t\t WHERE glpi_plugin_vip_groups.isvip = 1\n\t\t\t\t\t\t\tAND glpi_groups_users.users_id = " . $uid; $vipresult = $DB->query($vipquery); $vip = mysqli_fetch_object($vipresult)->nb; if ($vip) { $vipdisplay = $vipimg; } } } return $vipdisplay; }
/** * @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::getOptions() **/ function getOptions($primary_type = '') { $tab = Search::getOptions(get_parent_class($this)); //Specific to location $tab[1]['linkfield'] = 'name'; $tab[3]['linkfield'] = 'locations_id'; //Manage password $tab[4]['table'] = $this->getTable(); $tab[4]['field'] = 'password'; $tab[4]['linkfield'] = 'password'; $tab[4]['name'] = __('Password'); $tab[4]['displaytype'] = 'password'; $tab[5]['displaytype'] = 'text'; //To manage groups : relies on a CommonDBRelation object ! $tab[100]['name'] = __('Group'); $tab[100]['field'] = 'name'; $tab[100]['table'] = getTableForItemType('Group'); $tab[100]['linkfield'] = getForeignKeyFieldForTable($tab[100]['table']); $tab[100]['displaytype'] = 'relation'; $tab[100]['relationclass'] = 'Group_User'; $tab[100]['relationfield'] = $tab[100]['linkfield']; //To manage groups : relies on a CommonDBRelation object ! $tab[101]['name'] = __('Profile'); $tab[101]['field'] = 'name'; $tab[101]['table'] = getTableForItemType('Profile'); $tab[101]['linkfield'] = getForeignKeyFieldForTable($tab[101]['table']); $tab[101]['displaytype'] = 'relation'; $tab[101]['relationclass'] = 'Profile_User'; $tab[101]['relationfield'] = $tab[101]['linkfield']; //Remove some options because some fields cannot be imported $blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this)); $notimportable = array(13, 14, 15, 17, 20, 23, 30, 31, 60, 61, 77, 91, 92, 93); $options['ignore_fields'] = array_merge($blacklist, $notimportable); //Add displaytype value $options['displaytype'] = array("dropdown" => array(3, 79, 81, 82), "multiline_text" => array(16), "bool" => array(8), "password" => array(4)); return PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); }
/** * @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::getOptions() **/ function getOptions($primary_type = '') { $tab = Search::getOptions(get_parent_class($this)); $tab[4]['checktype'] = 'date'; $tab[5]['checktype'] = 'date'; //Warranty_duration $tab[6]['minvalue'] = 0; $tab[6]['maxvalue'] = 120; $tab[6]['step'] = 1; $tab[6]['-1'] = __('Lifelong'); $tab[6]['checktype'] = 'integer'; $tab[8]['checktype'] = 'float'; $tab[13]['checktype'] = 'float'; $tab[14]['minvalue'] = 0; $tab[14]['maxvalue'] = 15; $tab[14]['step'] = 1; $tab[14]['checktype'] = 'integer'; $tab[17]['size'] = 14; $tab[17]['default'] = 0; $tab[17]['checktype'] = 'integer'; $tab[15]['minvalue'] = 0; $tab[15]['maxvalue'] = 2; $tab[15]['step'] = 1; $tab[15]['checktype'] = 'integer'; $tab[23]['checktype'] = 'date'; $tab[24]['checktype'] = 'date'; $tab[25]['checktype'] = 'date'; $tab[26]['checktype'] = 'date'; //Remove some options because some fields cannot be imported $blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this)); $notimportable = array(20, 21, 86); $options['ignore_fields'] = array_merge($blacklist, $notimportable); $key = array_search(19, $options['ignore_fields']); unset($options['ignore_fields'][$key]); $options['displaytype'] = array("date" => array(4, 5, 23, 24, 25, 26), "dropdown" => array(6, 9, 19), "dropdown_integer" => array(6, 14), "decimal" => array(8, 13, 17), "sink_type" => array(15), "alert" => array(22), "multiline_text" => array(16)); return PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this); }
function constructSQL($itemtype, $params, $items_id_check = 0) { global $CFG_GLPI; // Instanciate an object to access method $item = NULL; if ($itemtype != 'States' && class_exists($itemtype)) { $item = new $itemtype(); } // Default values of parameters $p = array(); $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 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); } $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'] == GLOBAL_SEARCH) { $LIST_LIMIT = 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 for plugin Monitoring ============ */ $toview = array(); array_push($toview, 1); // 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 " . Search::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"], 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"], 0, 0, $searchopt[$itemtype][$key]["joinparams"]); } } } //// 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"][$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 .= 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 .= " ) "; } } } } //// 4 - ORDER $ORDER = " ORDER BY `id` "; foreach ($toview as $key => $val) { if ($p['sort'] == $val) { $ORDER = Search::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 .= Search::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]] =& Search::getOptions($p['itemtype2'][$i]); } if (!in_array($searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["table"] . "_" . $p['itemtype2'][$i], $already_link_tables2)) { $FROM .= Search::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 .= Search::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 .= Search::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 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; } /* =========== Add for plugin Monitoring ============ */ if ($items_id_check > 0) { if ($itemtype == "PluginMonitoringNetworkport") { if ($WHERE == '') { $WHERE .= " WHERE `" . getTableForItemType($itemtype) . "`.`networkports_id`='" . $items_id_check . "' "; } else { $WHERE .= " AND `" . getTableForItemType($itemtype) . "`.`networkports_id`='" . $items_id_check . "' "; } } else { $WHERE .= " AND `" . getTableForItemType($itemtype) . "`.`id`='" . $items_id_check . "' "; } } // 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,\n `{$reftable}`.`id` AS refID, " . "\n `{$ctable}`.`entities_id` AS ENTITY " . $FROM . $WHERE; $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 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); /// 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) { return $result; } else { return false; } }
/** * Print the search config form * * @param $target form target * @param $itemtype item type * * @return nothing **/ function showFormGlobal($target, $itemtype) { global $CFG_GLPI, $DB; $searchopt = Search::getOptions($itemtype); if (!is_array($searchopt)) { return false; } $IDuser = 0; $item = NULL; if ($itemtype != 'AllAssets') { $item = getItemForItemtype($itemtype); } $global_write = Session::haveRight(self::$rightname, self::GENERAL); echo "<div class='center' id='tabsbody' >"; // 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 = $DB->numrows($result); echo "<table class='tab_cadre_fixehov'><tr><th colspan='4'>"; echo __('Select default items to show') . "</th></tr>\n"; if ($global_write) { $already_added = self::getForTypeUser($itemtype, $IDuser); echo "<tr class='tab_bg_1'><td colspan='4' class='center'>"; echo "<form method='post' action='{$target}'>"; echo "<input type='hidden' name='itemtype' value='{$itemtype}'>"; echo "<input type='hidden' name='users_id' value='{$IDuser}'>"; $group = ''; $values = array(); $searchopt = Search::getCleanedOptions($itemtype); foreach ($searchopt as $key => $val) { if (!is_array($val)) { $group = $val; } else { if ($key != 1 && !in_array($key, $already_added) && (!isset($val['nodisplay']) || !$val['nodisplay'])) { $values[$group][$key] = $val["name"]; } } } if ($values) { Dropdown::showFromArray('num', $values); echo "<span class='small_space'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</span>"; } Html::closeForm(); echo "</td></tr>"; } // print first element echo "<tr class='tab_bg_2'>"; echo "<td class='center' width='50%'>" . $searchopt[1]["name"]; if ($global_write) { echo "</td><td colspan='3'> "; } echo "</td></tr>"; // print entity if (Session::isMultiEntitiesMode() && (isset($CFG_GLPI["union_search_type"][$itemtype]) || $item && $item->maybeRecursive() || count($_SESSION["glpiactiveentities"]) > 1) && isset($searchopt[80])) { echo "<tr class='tab_bg_2'>"; echo "<td class='center' width='50%'>" . $searchopt[80]["name"] . "</td>"; echo "<td colspan='3'> </td>"; echo "</tr>"; } $i = 0; if ($numrows) { while ($data = $DB->fetch_assoc($result)) { if ($data["num"] != 1 && isset($searchopt[$data["num"]])) { echo "<tr class='tab_bg_2'><td class='center' width='50%'>"; echo $searchopt[$data["num"]]["name"]; echo "</td>"; if ($global_write) { if ($i != 0) { echo "<td class='center middle'>"; echo "<form method='post' action='{$target}'>"; echo "<input type='hidden' name='id' value='" . $data["id"] . "'>"; echo "<input type='hidden' name='users_id' value='{$IDuser}'>"; echo "<input type='hidden' name='itemtype' value='{$itemtype}'>"; echo "<input type='image' name='up' value=\"" . __s('Bring up') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/puce-up.png' alt=\"" . __s('Bring up') . "\" title=\"" . __s('Bring up') . "\" class='pointer'>"; Html::closeForm(); echo "</td>"; } else { echo "<td> </td>\n"; } if ($i != $numrows - 1) { echo "<td class='center middle'>"; echo "<form method='post' action='{$target}'>"; echo "<input type='hidden' name='id' value='" . $data["id"] . "'>"; echo "<input type='hidden' name='users_id' value='{$IDuser}'>"; echo "<input type='hidden' name='itemtype' value='{$itemtype}'>"; echo "<input type='image' name='down' value=\"" . __s('Bring down') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/puce-down.png' alt=\"" . __s('Bring down') . "\" title=\"" . __s('Bring down') . "\" class='pointer'>"; Html::closeForm(); echo "</td>"; } else { echo "<td> </td>\n"; } echo "<td class='center middle'>"; echo "<form method='post' action='{$target}'>"; echo "<input type='hidden' name='id' value='" . $data["id"] . "'>"; echo "<input type='hidden' name='users_id' value='{$IDuser}'>"; echo "<input type='hidden' name='itemtype' value='{$itemtype}'>"; echo "<input type='image' name='purge' value=\"" . _sx('button', 'Delete permanently') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/delete.png' alt=\"" . __s('Delete permanently') . "\" title=\"" . __s('Delete permanently') . "\" class='pointer'>"; Html::closeForm(); echo "</td>\n"; } echo "</tr>"; $i++; } } } echo "</table>"; echo "</div>"; }
function plugin_databases_giveItem($type, $ID, $data, $num) { global $DB; $searchopt =& Search::getOptions($type); $table = $searchopt[$ID]["table"]; $field = $searchopt[$ID]["field"]; switch ($table . '.' . $field) { case "glpi_plugin_databases_databases_items.items_id": $query_device = "SELECT DISTINCT `itemtype`\n FROM `glpi_plugin_databases_databases_items`\n WHERE `plugin_databases_databases_id` = '" . $data['id'] . "'\n ORDER BY `itemtype`"; $result_device = $DB->query($query_device); $number_device = $DB->numrows($result_device); $y = 0; $out = ''; $databases = $data['id']; if ($number_device > 0) { for ($i = 0; $i < $number_device; $i++) { $column = "name"; $itemtype = $DB->result($result_device, $i, "itemtype"); if (!class_exists($itemtype)) { continue; } $item = new $itemtype(); if ($item->canView()) { $table_item = getTableForItemType($itemtype); $query = "SELECT `" . $table_item . "`.*, `glpi_plugin_databases_databases_items`.`id` AS items_id, `glpi_entities`.`id` AS entity " . " FROM `glpi_plugin_databases_databases_items`, `" . $table_item . "` LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `" . $table_item . "`.`entities_id`) " . " WHERE `" . $table_item . "`.`id` = `glpi_plugin_databases_databases_items`.`items_id`\n AND `glpi_plugin_databases_databases_items`.`itemtype` = '{$itemtype}'\n AND `glpi_plugin_databases_databases_items`.`plugin_databases_databases_id` = '" . $databases . "' " . getEntitiesRestrictRequest(" AND ", $table_item, '', '', $item->maybeRecursive()); if ($item->maybeTemplate()) { $query .= " AND `" . $table_item . "`.`is_template` = '0'"; } $query .= " ORDER BY `glpi_entities`.`completename`, `" . $table_item . "`.`{$column}`"; if ($result_linked = $DB->query($query)) { if ($DB->numrows($result_linked)) { $item = new $itemtype(); while ($data = $DB->fetch_assoc($result_linked)) { if ($item->getFromDB($data['id'])) { $out .= $item::getTypeName(1) . " - " . $item->getLink() . "<br>"; } } } else { $out .= ' '; } } } else { $out .= ' '; } } } return $out; break; case 'glpi_plugin_databases_databases.name': if ($type == 'Ticket') { $databases_id = array(); if ($data['raw']["ITEM_{$num}"] != '') { $databases_id = explode('$$$$', $data['raw']["ITEM_{$num}"]); } else { $databases_id = explode('$$$$', $data['raw']["ITEM_" . $num . "_2"]); } $ret = array(); $paDatabase = new PluginDatabasesDatabase(); foreach ($databases_id as $ap_id) { $paDatabase->getFromDB($ap_id); $ret[] = $paDatabase->getLink(); } return implode('<br>', $ret); } break; } return ""; }
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 plugin_monitoring_addWhere($link, $nott, $type, $id, $val) { global $SEARCH_OPTION; $searchopt =& Search::getOptions($type); $table = $searchopt[$id]["table"]; $field = $searchopt[$id]["field"]; switch ($type) { // * Computer List (front/computer.php) case 'PluginMonitoringService': switch ($table . "." . $field) { case "glpi_plugin_monitoring_services.Computer": case "glpi_plugin_monitoring_services.Printer": case "glpi_plugin_monitoring_services.NetworkEquipment": return $link . " (`glpi_plugin_monitoring_componentscatalogs_hosts`.`items_id` = '" . $val . "') "; break; } } return ""; }