/** * @param $notimported PluginOcsinventoryngNotimportedcomputer object **/ static function showActions(PluginOcsinventoryngNotimportedcomputer $notimported) { echo "<div class='spaced'>"; echo "<form name='actions' id='actions' method='post' value='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2'>"; echo "<th class='center'>" . __('Actions to be made on the computer', 'ocsinventoryng') . "</th></tr>"; echo "<tr class='tab_bg_2'><td class='center'>"; echo "<input type='hidden' name='id' value='" . $notimported->fields['id'] . "'>"; echo "<input type='hidden' name='action' value='massive'>"; Dropdown::showForMassiveAction('PluginOcsinventoryngNotimportedcomputer', 0, array('action' => 'massive')); echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; }
} echo "<td class='blue'>" . getLastOcsUpdate($data['BID']) . "</td>"; echo "</tr>\n"; } echo "<tr class='tab_bg_4'><td class='center' colspan='{$colspan}'>"; if ($i) { printf(__('%1$s: %2$s'), __('Duplicate computers', 'reports'), $i); } else { _e('No item found'); } echo "</td></tr>\n"; echo "</table>"; if ($canedit) { if ($i) { Html::openArrowMassives("massiveaction_form"); Dropdown::showForMassiveAction('Computer'); $options = array(); Html::closeArrowMassives($options); } Html::closeForm(); } } Html::footer(); function buildBookmarkUrl($url, $crit) { return $url . "?crit=" . $crit; } function getLastOcsUpdate($computers_id) { global $DB; $query = "SELECT `last_ocs_update`\n FROM `glpi_ocslinks`\n WHERE `computers_id` = '{$computers_id}'";
/** * Show Licenses of a software * * @param $software software object * * @return nothing **/ static function showForSoftware($software) { global $DB, $CFG_GLPI, $LANG; $softwares_id = $software->getField('id'); $license = new SoftwareLicense(); $computer = new Computer(); if (!$software->can($softwares_id, "r")) { return false; } if (isset($_REQUEST["start"])) { $start = $_REQUEST["start"]; } else { $start = 0; } if (isset($_REQUEST["order"]) && $_REQUEST["order"] == "DESC") { $order = "DESC"; } else { $order = "ASC"; } if (isset($_REQUEST["sort"]) && !empty($_REQUEST["sort"])) { $sort = "`" . $_REQUEST["sort"] . "`"; } else { $sort = "`entity` {$order}, `name`"; } // Righ type is enough. Can add a License on a software we have Read access $canedit = haveRight("software", "w"); // Total Number of events $number = countElementsInTable("glpi_softwarelicenses", "glpi_softwarelicenses.softwares_id = {$softwares_id} " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true)); echo "<div class='spaced'>"; if ($number < 1) { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . $LANG['search'][15] . "</th></tr>\n"; if ($canedit) { echo "<tr class='tab_bg_2'><td class='center'>"; echo "<a href='softwarelicense.form.php?softwares_id={$softwares_id}'>" . $LANG['software'][8] . "</a>"; echo "</td></tr>\n"; } echo "</table></div>\n"; return; } // Display the pager printAjaxPager($LANG['software'][11], $start, $number); $rand = mt_rand(); $query = "SELECT `glpi_softwarelicenses`.*,\n `buyvers`.`name` AS buyname,\n `usevers`.`name` AS usename,\n `glpi_entities`.`completename` AS entity,\n `glpi_softwarelicensetypes`.`name` AS typename\n FROM `glpi_softwarelicenses`\n LEFT JOIN `glpi_softwareversions` AS buyvers\n ON (`buyvers`.`id` = `glpi_softwarelicenses`.`softwareversions_id_buy`)\n LEFT JOIN `glpi_softwareversions` AS usevers\n ON (`usevers`.`id` = `glpi_softwarelicenses`.`softwareversions_id_use`)\n LEFT JOIN `glpi_entities`\n ON (`glpi_entities`.`id` = `glpi_softwarelicenses`.`entities_id`)\n LEFT JOIN `glpi_softwarelicensetypes`\n ON (`glpi_softwarelicensetypes`.`id`\n = `glpi_softwarelicenses`.`softwarelicensetypes_id`)\n WHERE (`glpi_softwarelicenses`.`softwares_id` = '{$softwares_id}') " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true) . "\n ORDER BY {$sort} {$order}\n LIMIT " . intval($start) . "," . intval($_SESSION['glpilist_limit']); initNavigateListItems('SoftwareLicense', $LANG['help'][31] . " = " . $software->fields["name"]); if ($result = $DB->query($query)) { if ($DB->numrows($result)) { if ($canedit) { echo "<form method='post' name='massiveactionlicense_form{$rand}' id='" . "massiveactionlicense_form{$rand}' action=\"" . $CFG_GLPI["root_doc"] . "/front/massiveaction.php\">"; } $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>"; echo "<table class='tab_cadre_fixehov'><tr>"; echo "<th> </th>"; echo "<th>" . ($sort == "`name`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=name&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['common'][16] . "</a></th>"; if ($software->isRecursive()) { // Ereg to search entity in string for match default order echo "<th>" . (strstr($sort, "entity") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=entity&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['entity'][0] . "</a></th>"; } echo "<th>" . ($sort == "`serial`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=serial&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['common'][19] . "</a></th>"; echo "<th>" . ($sort == "`number`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=number&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['tracking'][29] . "</a></th>"; echo "<th>" . $LANG['software'][9] . "</th>"; echo "<th>" . ($sort == "`typename`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=typename&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['common'][17] . "</a></th>"; echo "<th>" . ($sort == "`buyname`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=buyname&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['software'][1] . "</a></th>"; echo "<th>" . ($sort == "`usename`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=usename&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['software'][2] . "</a></th>"; echo "<th>" . ($sort == "`expire`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=expire&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['software'][32] . "</a></th>"; echo "</tr>\n"; $tot_assoc = 0; for ($tot = 0; $data = $DB->fetch_assoc($result);) { addToNavigateListItems('SoftwareLicense', $data['id']); echo "<tr class='tab_bg_2'>"; if ($license->can($data['id'], "w")) { echo "<td><input type='checkbox' name='item[" . $data["id"] . "]' value='1'></td>"; } else { echo "<td> </td>"; } echo "<td><a href='softwarelicense.form.php?id=" . $data['id'] . "'>" . $data['name'] . (empty($data['name']) ? $data['id'] : "") . "</a></td>"; if ($software->isRecursive()) { echo "<td>" . $data['entity'] . "</td>"; } echo "<td>" . $data['serial'] . "</td>"; echo "<td class='right'>" . ($data['number'] > 0 ? $data['number'] . " " : $LANG['software'][4]) . "</td>"; $nb_assoc = Computer_SoftwareLicense::countForLicense($data['id']); $tot_assoc += $nb_assoc; echo "<td class='right'>{$nb_assoc} </td>"; echo "<td>" . $data['typename'] . "</td>"; echo "<td>" . $data['buyname'] . "</td>"; echo "<td>" . $data['usename'] . "</td>"; echo "<td class='center'>" . convDate($data['expire']) . "</td>"; echo "</tr>"; if ($data['number'] < 0) { // One illimited license, total is illimited $tot = -1; } else { if ($tot >= 0) { // Not illimited, add the current number $tot += $data['number']; } } } echo "<tr class='tab_bg_1'>"; echo "<td colspan='" . ($software->isRecursive() ? 4 : 3) . "' class='right b'>" . $LANG['common'][33] . "</td>"; echo "<td class='right b'>" . ($tot > 0 ? $tot . " " : $LANG['software'][4]) . "</td>"; echo "<td class='right b'>{$tot_assoc} </td>"; echo "<td colspan='4' class='center'>"; if ($canedit) { echo "<a href='softwarelicense.form.php?softwares_id={$softwares_id}'>" . $LANG['software'][8] . "</a>"; } echo "</td></tr>"; echo "</table>\n"; if ($canedit) { openArrowMassive("massiveactionlicense_form{$rand}", true); Dropdown::showForMassiveAction('SoftwareLicense', 0, array('softwares_id' => $softwares_id)); closeArrowMassive(); echo "</form>"; } } else { echo $LANG['search'][15]; } } echo "</div>"; }
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; }
/** * Show ports for an item * * @param $itemtype integer : item type * @param $ID integer : item ID * @param $withtemplate integer : withtemplate param **/ static function showForItem($itemtype, $ID, $withtemplate = '') { global $DB, $CFG_GLPI, $LANG; $rand = mt_rand(); if (!class_exists($itemtype)) { return false; } $item = new $itemtype(); if (!haveRight('networking', 'r') || !$item->can($ID, 'r')) { return false; } $canedit = $item->can($ID, 'w'); // Show Add Form if ($canedit && (empty($withtemplate) || $withtemplate != 2)) { echo "\n<div class='firstbloc'><table class='tab_cadre_fixe'>"; echo "<tr><td class='tab_bg_2 center'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?items_id={$ID}&itemtype={$itemtype}'><strong>" . $LANG['networking'][19] . "</strong></a></td>\n"; echo "<td class='tab_bg_2 center' width='50%'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?items_id={$ID}&itemtype={$itemtype}&several=1'>\n <strong>" . $LANG['networking'][46] . "</strong></a></td>\n"; echo "</tr></table></div>\n"; } initNavigateListItems('NetworkPort', $item->getTypeName() . " = " . $item->getName()); $query = "SELECT `id`\n FROM `glpi_networkports`\n WHERE `items_id` = '{$ID}'\n AND `itemtype` = '{$itemtype}'\n ORDER BY `name`,\n `logical_number`"; if ($result = $DB->query($query)) { echo "<div class='spaced'>"; if ($DB->numrows($result) != 0) { $colspan = 9; if ($withtemplate != 2) { if ($canedit) { $colspan++; echo "\n<form id='networking_ports{$rand}' name='networking_ports{$rand}' method='post'\n action='" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php'>\n"; } } echo "<table class='tab_cadre_fixe'>\n"; echo "<tr><th colspan='{$colspan}'>\n"; if ($DB->numrows($result) == 1) { echo $LANG['networking'][12]; } else { echo $LANG['networking'][11]; } echo " : " . $DB->numrows($result) . "</th></tr>\n"; echo "<tr>"; if ($withtemplate != 2 && $canedit) { echo "<th> </th>\n"; } echo "<th>#</th>\n"; echo "<th>" . $LANG['common'][16] . "</th>\n"; echo "<th>" . $LANG['networking'][51] . "</th>\n"; echo "<th>" . $LANG['networking'][14] . "<br>" . $LANG['networking'][15] . "</th>\n"; echo "<th>" . $LANG['networking'][60] . " / " . $LANG['networking'][61] . "<br>" . $LANG['networking'][59] . "</th>\n"; echo "<th>" . $LANG['networking'][56] . "</th>\n"; echo "<th>" . $LANG['common'][65] . "</th>\n"; echo "<th>" . $LANG['networking'][17] . " :</th>\n"; echo "<th>" . $LANG['networking'][14] . "<br>" . $LANG['networking'][15] . "</th></tr>\n"; $i = 0; $netport = new NetworkPort(); while ($devid = $DB->fetch_row($result)) { $netport->getFromDB(current($devid)); addToNavigateListItems('NetworkPort', $netport->fields["id"]); echo "<tr class='tab_bg_1'>\n"; if ($withtemplate != 2 && $canedit) { echo "<td class='center' width='20'>"; echo "<input type='checkbox' name='del_port[" . $netport->fields["id"] . "]' value='1'>"; echo "</td>\n"; } echo "<td class='center'><strong>"; if ($canedit && $withtemplate != 2) { echo "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?id=" . $netport->fields["id"] . "\">"; } echo $netport->fields["logical_number"]; if ($canedit && $withtemplate != 2) { echo "</a>"; } echo "</strong>"; showToolTip($netport->fields['comment']); echo "</td>\n"; echo "<td>" . $netport->fields["name"] . "</td>\n"; echo "<td>" . Dropdown::getDropdownName("glpi_netpoints", $netport->fields["netpoints_id"]) . "</td>\n"; echo "<td>" . $netport->fields["ip"] . "<br>" . $netport->fields["mac"] . "</td>\n"; echo "<td>" . $netport->fields["netmask"] . " / " . $netport->fields["subnet"] . "<br>" . $netport->fields["gateway"] . "</td>\n"; // VLANs echo "<td>"; NetworkPort_Vlan::showForNetworkPort($netport->fields["id"], $canedit, $withtemplate); echo "</td>\n"; echo "<td>" . Dropdown::getDropdownName("glpi_networkinterfaces", $netport->fields["networkinterfaces_id"]) . "</td>\n"; echo "<td width='300' class='tab_bg_2'>"; self::showConnection($item, $netport, $withtemplate); echo "</td>\n"; echo "<td class='tab_bg_2'>"; if ($netport->getContact($netport->fields["id"])) { echo $netport->fields["ip"] . "<br>"; echo $netport->fields["mac"]; } echo "</td></tr>\n"; } echo "</table>\n"; if ($canedit && $withtemplate != 2) { openArrowMassive("networking_ports{$rand}", true); Dropdown::showForMassiveAction('NetworkPort'); closeArrowMassive(); } if ($canedit && $withtemplate != 2) { echo "</form>"; } } else { echo "<table class='tab_cadre_fixe'><tr><th>" . $LANG['networking'][10] . "</th></tr>"; echo "</table>"; } echo "</div>"; } }
/** * Execute the report * * @param $options array **/ function execute($options = array()) { global $DB, $CFG_GLPI, $HEADER_LOADED; // Require (for pager) when not called by displayCriteriasForm $this->manageCriteriasValues(); if (isset($_POST['list_limit'])) { $_SESSION['glpilist_limit'] = $_POST['list_limit']; unset($_POST['list_limit']); } $limit = $_SESSION['glpilist_limit']; if (isset($_POST["display_type"])) { $output_type = $_POST["display_type"]; if ($output_type < 0) { $output_type = -$output_type; $limit = 0; } } else { $output_type = Search::HTML_OUTPUT; } $title = $this->title; if ($this->subname) { $title = sprintf(__('%1$s - %2$s'), $title, $this->subname); } $res = $DB->query($this->sql); $nbtot = $res ? $DB->numrows($res) : 0; if ($limit) { $start = isset($_GET["start"]) ? $_GET["start"] : 0; if ($start >= $nbtot) { $start = 0; } if ($start > 0 || $start + $limit < $nbtot) { $res = $DB->query($this->sql . " LIMIT {$start},{$limit}"); } } else { $start = 0; } if ($nbtot == 0) { if (!$HEADER_LOADED) { Html::header($title, $_SERVER['PHP_SELF'], "utils", "report"); Report::title(); } echo "<div class='center'><font class='red b'>" . __('No item found') . "</font></div>"; Html::footer(); } else { if ($output_type == Search::PDF_OUTPUT_PORTRAIT || $output_type == Search::PDF_OUTPUT_LANDSCAPE) { include GLPI_ROOT . "/lib/ezpdf/class.ezpdf.php"; } else { if ($output_type == Search::HTML_OUTPUT) { if (!$HEADER_LOADED) { Html::header($title, $_SERVER['PHP_SELF'], "utils", "report"); Report::title(); } echo "<div class='center'><table class='tab_cadre_fixe'>"; echo "<tr><th>" . $title . "</th></tr>\n"; echo "<tr class='tab_bg_2 center'><td class='center'>"; echo "<form method='POST' action='" . $_SERVER["PHP_SELF"] . "?start={$start}'>\n"; $param = ""; foreach ($_POST as $key => $val) { if (is_array($val)) { foreach ($val as $k => $v) { echo "<input type='hidden' name='" . $key . "[{$k}]' value='{$v}' >"; if (!empty($param)) { $param .= "&"; } $param .= $key . "[" . $k . "]=" . urlencode($v); } } else { echo "<input type='hidden' name='" . $key . "' value='{$val}' >"; if (!empty($param)) { $param .= "&"; } $param .= "{$key}=" . urlencode($val); } } Dropdown::showOutputFormat(); Html::closeForm(); echo "</td></tr>"; echo "</table></div>"; Html::printPager($start, $nbtot, $_SERVER['PHP_SELF'], $param); } } } if (!isset($_POST["display_type"]) || $_POST["display_type"] == Search::HTML_OUTPUT) { if (isset($options['withmassiveaction']) && class_exists($options['withmassiveaction'])) { echo "<form method='post' name='massiveaction_form' id='massiveaction_form' action=\"" . $CFG_GLPI["root_doc"] . "/front/massiveaction.php\">"; } } plugin_reports_checkRight($this->plug, $this->name, "r"); if ($res && $nbtot > 0) { $nbcols = $DB->num_fields($res); $nbrows = $DB->numrows($res); echo Search::showHeader($output_type, $nbrows, $nbcols, true); echo Search::showNewLine($output_type); $num = 1; // fill $sqlcols with default sql query fields so we can validate $columns $sqlcols = array(); for ($i = 0; $i < $nbcols; $i++) { $colname = $DB->field_name($res, $i); $sqlcols[] = $colname; } $colsname = array(); // if $columns is not empty, display $columns if (count($this->columns) > 0) { foreach ($this->columns as $colname => $column) { // display only $columns that are valid if (in_array($colname, $sqlcols)) { $column->showTitle($output_type, $num); $colsname[$colname] = $column; } } } else { // else display default columns from SQL query foreach ($sqlcols as $colname) { $column = new PluginReportsColumn($colname, $colname); $column->showTitle($output_type, $num); $colsname[$colname] = $column; } } echo Search::showEndLine($output_type); $prev = ""; for ($row_num = 2; $row = $DB->fetch_assoc($res); $row_num++) { $crt = ""; foreach ($this->group_by as $colname) { if (isset($row[$colname])) { $crt .= $row[$colname] . "####"; } } echo Search::showNewLine($output_type); $num = 1; foreach ($colsname as $colname => $column) { //If value needs to be modified on the fly if (isset($this->columns_mapping[$colname]) && isset($this->columns_mapping[$colname][$row[$colname]])) { $new_value = $this->columns_mapping[$colname][$row[$colname]]; $row[$colname] = $new_value; } if (!in_array($colname, $this->group_by)) { $column->showValue($output_type, $row, $num, $row_num); } else { if ($crt == $prev) { $column->showValue($output_type, $output_type == Search::CSV_OUTPUT ? $row : array(), $num, $row_num); } else { $column->showValue($output_type, $row, $num, $row_num, true); } } } // Each column echo Search::showEndLine($output_type); $prev = $crt; } // Each row if (isset($options['withtotal']) && $options['withtotal']) { echo Search::showNewLine($output_type); $num = 1; foreach ($colsname as $colname => $column) { $column->showTotal($output_type, $num, $row_num); } echo Search::showEndLine($output_type); } } echo Search::showFooter($output_type, $title); if (!isset($_POST["display_type"]) || $_POST["display_type"] == Search::HTML_OUTPUT) { if (isset($options['withmassiveaction']) && class_exists($options['withmassiveaction'])) { Html::openArrowMassives("massiveaction_form", true); Dropdown::showForMassiveAction($options['withmassiveaction']); $options = array(); Html::closeArrowMassives($options); Html::closeForm(); } Html::footer(); } }