/** * Display datas extracted from DB * * @param $data array of search datas prepared to get datas * * @return nothing **/ static function displayDatas(array &$data) { global $CFG_GLPI; $item = null; if (class_exists($data['itemtype'])) { $item = new $data['itemtype'](); } $rand = mt_rand(); if (!isset($data['data']) || !isset($data['data']['totalcount'])) { return false; } // Contruct Pager parameters $globallinkto = Toolbox::append_params(array('criteria' => Toolbox::stripslashes_deep($data['search']['criteria']), 'metacriteria' => Toolbox::stripslashes_deep($data['search']['metacriteria'])), '&'); $parameters = "sort=" . $data['search']['sort'] . "&order=" . $data['search']['order'] . '&' . $globallinkto; if (isset($_GET['_in_modal'])) { $parameters .= "&_in_modal=1"; } // Global search header if ($data['display_type'] == self::GLOBAL_SEARCH) { if ($data['item']) { echo "<div class='center'><h2>" . $data['item']->getTypeName(); // More items if ($data['data']['totalcount'] > $data['search']['start'] + self::GLOBAL_DISPLAY_COUNT) { echo " <a href='" . $data['search']['target'] . "?{$parameters}'>" . __('All') . "</a>"; } echo "</h2></div>\n"; } else { return false; } } // If the begin of the view is before the number of items if ($data['data']['count'] > 0) { // Display pager only for HTML if ($data['display_type'] == self::HTML_OUTPUT) { // For plugin add new parameter if available if ($plug = isPluginItemType($data['itemtype'])) { $function = 'plugin_' . $plug['plugin'] . '_addParamFordynamicReport'; if (function_exists($function)) { $out = $function($data['itemtype']); if (is_array($out) && count($out)) { $parameters .= Toolbox::append_params($out, '&'); } } } $search_config_top = ""; $search_config_bottom = ""; if (!isset($_GET['_in_modal']) && Session::haveRightsOr('search_config', array(DisplayPreference::PERSONAL, DisplayPreference::GENERAL))) { $search_config_top = $search_config_bottom = "<div class='pager_controls'><img alt=\"" . __s('Select default items to show') . "\" title=\"" . __s('Select default items to show') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/options_search.png' "; $search_config_top .= " class='pointer' onClick=\""; $search_config_top .= Html::jsGetElementbyID('search_config_top') . ".dialog('open');\">"; $search_config_bottom .= " class='pointer' onClick=\""; $search_config_bottom .= Html::jsGetElementbyID('search_config_bottom') . ".dialog('open');\">"; $search_config_top .= Ajax::createIframeModalWindow('search_config_top', $CFG_GLPI["root_doc"] . "/front/displaypreference.form.php?itemtype=" . $data['itemtype'], array('title' => __('Select default items to show'), 'reloadonclose' => true, 'display' => false)); $search_config_bottom .= Ajax::createIframeModalWindow('search_config_bottom', $CFG_GLPI["root_doc"] . "/front/displaypreference.form.php?itemtype=" . $data['itemtype'], array('title' => __('Select default items to show'), 'reloadonclose' => true, 'display' => false)); } if ($item !== null && $item->maybeDeleted()) { $delete_ctrl = self::isDeletedSwitch($data['search']['is_deleted']); $search_config_top .= $delete_ctrl; } Html::printPager($data['search']['start'], $data['data']['totalcount'], $data['search']['target'], $parameters, $data['itemtype'], 0, $search_config_top); $search_config_top .= "</div>"; $search_config_bottom .= "</div>"; } // Define begin and end var for loop // Search case $begin_display = $data['data']['begin']; $end_display = $data['data']['end']; // Form to massive actions $isadmin = $data['item'] && $data['item']->canUpdate(); if (!$isadmin && InfoCom::canApplyOn($data['itemtype'])) { $isadmin = Infocom::canUpdate() || Infocom::canCreate(); } if ($data['itemtype'] != 'AllAssets') { $showmassiveactions = count(MassiveAction::getAllMassiveActions($data['item'], $data['search']['is_deleted'])); } else { $showmassiveactions = true; } $massformid = 'massform' . $data['itemtype']; if ($showmassiveactions && $data['display_type'] == self::HTML_OUTPUT) { Html::openMassiveActionsForm($massformid); $massiveactionparams = $data['search']['massiveactionparams']; $massiveactionparams['num_displayed'] = $end_display - $begin_display; $massiveactionparams['fixed'] = false; $massiveactionparams['is_deleted'] = $data['search']['is_deleted']; $massiveactionparams['container'] = $massformid; Html::showMassiveActions($massiveactionparams); } // Compute number of columns to display // Add toview elements $nbcols = count($data['data']['cols']); if ($data['display_type'] == self::HTML_OUTPUT && $showmassiveactions) { // HTML display - massive modif $nbcols++; } // Display List Header echo self::showHeader($data['display_type'], $end_display - $begin_display + 1, $nbcols); // New Line for Header Items Line $headers_line = ''; $headers_line_top = ''; $headers_line_bottom = ''; $headers_line_top .= self::showBeginHeader($data['display_type']); $headers_line_top .= self::showNewLine($data['display_type']); if ($data['display_type'] == self::HTML_OUTPUT) { // $headers_line_bottom .= self::showBeginHeader($data['display_type']); $headers_line_bottom .= self::showNewLine($data['display_type']); } $header_num = 1; if ($data['display_type'] == self::HTML_OUTPUT && $showmassiveactions) { // HTML display - massive modif $headers_line_top .= self::showHeaderItem($data['display_type'], Html::getCheckAllAsCheckbox($massformid), $header_num, "", 0, $data['search']['order']); if ($data['display_type'] == self::HTML_OUTPUT) { $headers_line_bottom .= self::showHeaderItem($data['display_type'], Html::getCheckAllAsCheckbox($massformid), $header_num, "", 0, $data['search']['order']); } } // Display column Headers for toview items $metanames = array(); foreach ($data['data']['cols'] as $key => $val) { $linkto = ''; if (!$val['meta'] && (!isset($val['searchopt']['nosort']) || !$val['searchopt']['nosort'])) { $linkto = $data['search']['target'] . (strpos($data['search']['target'], '?') ? '&' : '?') . "itemtype=" . $data['itemtype'] . "&sort=" . $val['id'] . "&order=" . ($data['search']['order'] == "ASC" ? "DESC" : "ASC") . "&start=" . $data['search']['start'] . "&" . $globallinkto; } $name = $val["name"]; // prefix by group name (corresponding to optgroup in dropdown) if exists if (isset($val['groupname'])) { $name = $val['groupname'] . " - " . $name; } // Not main itemtype add itemtype to display if ($data['itemtype'] != $val['itemtype']) { if (!isset($metanames[$val['itemtype']])) { if ($metaitem = getItemForItemtype($val['itemtype'])) { $metanames[$val['itemtype']] = $metaitem->getTypeName(); } } $name = sprintf(__('%1$s - %2$s'), $metanames[$val['itemtype']], $val["name"]); } $headers_line .= self::showHeaderItem($data['display_type'], $name, $header_num, $linkto, !$val['meta'] && $data['search']['sort'] == $val['id'], $data['search']['order']); } // Add specific column Header if (isset($CFG_GLPI["union_search_type"][$data['itemtype']])) { $headers_line .= self::showHeaderItem($data['display_type'], __('Item type'), $header_num); } // End Line for column headers $headers_line .= self::showEndLine($data['display_type']); $headers_line_top .= $headers_line; if ($data['display_type'] == self::HTML_OUTPUT) { $headers_line_bottom .= $headers_line; } $headers_line_top .= self::showEndHeader($data['display_type']); // $headers_line_bottom .= self::showEndHeader($data['display_type']); echo $headers_line_top; // Init list of items displayed if ($data['display_type'] == self::HTML_OUTPUT) { Session::initNavigateListItems($data['itemtype']); } // Num of the row (1=header_line) $row_num = 1; $massiveaction_field = 'id'; if ($data['itemtype'] != 'AllAssets' && isset($CFG_GLPI["union_search_type"][$data['itemtype']])) { $massiveaction_field = 'refID'; } $typenames = array(); // Display Loop foreach ($data['data']['rows'] as $rowkey => $row) { // Column num $item_num = 1; $row_num++; // New line echo self::showNewLine($data['display_type'], $row_num % 2, $data['search']['is_deleted']); $current_type = isset($row['TYPE']) ? $row['TYPE'] : $data['itemtype']; $massiveaction_type = $current_type; if ($data['itemtype'] != 'AllAssets' && isset($CFG_GLPI["union_search_type"][$data['itemtype']])) { $massiveaction_type = $data['itemtype']; } // Add item in item list Session::addToNavigateListItems($current_type, $row["id"]); if ($data['display_type'] == self::HTML_OUTPUT && $showmassiveactions) { // HTML display - massive modif $tmpcheck = ""; if ($data['itemtype'] == 'Entity' && !in_array($row["id"], $_SESSION["glpiactiveentities"])) { $tmpcheck = " "; } else { if ($data['item'] instanceof CommonDBTM && $data['item']->maybeRecursive() && !in_array($row["entities_id"], $_SESSION["glpiactiveentities"])) { $tmpcheck = " "; } else { $tmpcheck = Html::getMassiveActionCheckBox($massiveaction_type, $row[$massiveaction_field]); } } echo self::showItem($data['display_type'], $tmpcheck, $item_num, $row_num, "width='10'"); } // Print other toview items foreach ($data['data']['cols'] as $colkey => $col) { if (!$col['meta']) { echo self::showItem($data['display_type'], $row[$colkey]['displayname'], $item_num, $row_num, self::displayConfigItem($data['itemtype'], $col['id'], $row, $colkey)); } else { // META case echo self::showItem($data['display_type'], $row[$colkey]['displayname'], $item_num, $row_num); } } if (isset($CFG_GLPI["union_search_type"][$data['itemtype']])) { if (!isset($typenames[$row["TYPE"]])) { if ($itemtmp = getItemForItemtype($row["TYPE"])) { $typenames[$row["TYPE"]] = $itemtmp->getTypeName(); } } echo self::showItem($data['display_type'], $typenames[$row["TYPE"]], $item_num, $row_num); } // End Line echo self::showEndLine($data['display_type']); } // Create title $title = ''; if ($data['display_type'] == self::PDF_OUTPUT_LANDSCAPE || $data['display_type'] == self::PDF_OUTPUT_PORTRAIT) { $title = self::computeTitle($data); } if ($data['display_type'] == self::HTML_OUTPUT) { echo $headers_line_bottom; } // Display footer echo self::showFooter($data['display_type'], $title); // Delete selected item if ($data['display_type'] == self::HTML_OUTPUT) { if ($showmassiveactions) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); // End form for delete item Html::closeForm(); } else { echo "<br>"; } } if ($data['display_type'] == self::HTML_OUTPUT) { // In case of HTML display Html::printPager($data['search']['start'], $data['data']['totalcount'], $data['search']['target'], $parameters, '', 0, $search_config_bottom); } } else { if ($item !== null && $item->maybeDeleted()) { echo "<div class='center'>" . self::isDeletedSwitch($data['search']['is_deleted']) . "</div><br/>"; } echo self::showError($data['display_type']); } }
function __construct($name, $title, $itemtype, $options = array()) { parent::__construct($name, $title, $options); $this->obj = getItemForItemtype($itemtype); if (isset($options['with_comment'])) { $this->with_comment = $options['with_comment']; } if (isset($options['with_navigate'])) { $this->with_navigate = $options['with_navigate']; Session::initNavigateListItems($this->obj->getType(), _n('Report', 'Reports', 2)); } }
/** * Display tickets for an item * * Will also display tickets of linked items * * @param $item CommonDBTM object * * @return nothing (display a table) **/ static function showListForItem(CommonDBTM $item) { global $DB, $CFG_GLPI; if (!Session::haveRightsOr(self::$rightname, array(self::READALL, self::READMY, self::READASSIGN, CREATE))) { return false; } if ($item->isNewID($item->getID())) { return false; } $restrict = ''; $order = ''; $options['reset'] = 'reset'; switch ($item->getType()) { case 'User': $restrict = "(`glpi_tickets_users`.`users_id` = '" . $item->getID() . "' " . " AND `glpi_tickets_users`.`type` = " . CommonITILActor::REQUESTER . ")"; $order = '`glpi_tickets`.`date_mod` DESC'; $options['reset'] = 'reset'; $options['criteria'][0]['field'] = 4; // status $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'AND'; break; case 'SLT': $restrict = "`slts_tto_id` = '" . $item->getID() . "'\n OR `slts_ttr_id` = '" . $item->getID() . "'"; $order = '`glpi_tickets`.`due_date` DESC'; $options['criteria'][0]['field'] = 30; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'AND'; break; case 'Supplier': $restrict = "(`glpi_suppliers_tickets`.`suppliers_id` = '" . $item->getID() . "' " . " AND `glpi_suppliers_tickets`.`type` = " . CommonITILActor::ASSIGN . ")"; $order = '`glpi_tickets`.`date_mod` DESC'; $options['criteria'][0]['field'] = 6; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'AND'; break; case 'Group': // Mini search engine if ($item->haveChildren()) { $tree = Session::getSavedOption(__CLASS__, 'tree', 0); echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th>" . __('Last tickets') . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; echo __('Child groups') . " "; Dropdown::showYesNo('tree', $tree, -1, array('on_change' => 'reloadTab("start=0&tree="+this.value)')); } else { $tree = 0; } echo "</td></tr></table>"; if ($tree) { $restrict = "IN (" . implode(',', getSonsOf('glpi_groups', $item->getID())) . ")"; } else { $restrict = "='" . $item->getID() . "'"; } $restrict = "(`glpi_groups_tickets`.`groups_id` {$restrict}" . " AND `glpi_groups_tickets`.`type` = " . CommonITILActor::REQUESTER . ")"; $order = '`glpi_tickets`.`date_mod` DESC'; $options['criteria'][0]['field'] = 71; $options['criteria'][0]['searchtype'] = $tree ? 'under' : 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'AND'; break; default: $restrict = "(`glpi_items_tickets`.`items_id` = '" . $item->getID() . "' " . " AND `glpi_items_tickets`.`itemtype` = '" . $item->getType() . "')"; // you can only see your tickets if (!Session::haveRight(self::$rightname, self::READALL)) { $restrict .= " AND (`glpi_tickets`.`users_id_recipient` = '" . Session::getLoginUserID() . "'\n OR (`glpi_tickets_users`.`tickets_id` = '" . $item->getID() . "'\n AND `glpi_tickets_users`.`users_id`\n = '" . Session::getLoginUserID() . "'))"; } $order = '`glpi_tickets`.`date_mod` DESC'; $options['criteria'][0]['field'] = 12; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = 'all'; $options['criteria'][0]['link'] = 'AND'; $options['metacriteria'][0]['itemtype'] = $item->getType(); $options['metacriteria'][0]['field'] = Search::getOptionNumber($item->getType(), 'id'); $options['metacriteria'][0]['searchtype'] = 'equals'; $options['metacriteria'][0]['value'] = $item->getID(); $options['metacriteria'][0]['link'] = 'AND'; break; } $query = "SELECT " . self::getCommonSelect() . "\n FROM `glpi_tickets` " . self::getCommonLeftJoin() . "\n WHERE {$restrict} " . getEntitiesRestrictRequest("AND", "glpi_tickets") . "\n ORDER BY {$order}\n LIMIT " . intval($_SESSION['glpilist_limit']); $result = $DB->query($query); $number = $DB->numrows($result); $colspan = 11; if (count($_SESSION["glpiactiveentities"]) > 1) { $colspan++; } // Ticket for the item echo "<div class='firstbloc'>"; // Link to open a new ticket if ($item->getID() && Ticket::isPossibleToAssignType($item->getType()) && self::canCreate()) { Html::showSimpleForm($CFG_GLPI["root_doc"] . "/front/ticket.form.php", '_add_fromitem', __('New ticket for this item...'), array('itemtype' => $item->getType(), 'items_id' => $item->getID())); } echo "</div><div>"; if ($number > 0) { echo "<table class='tab_cadre_fixehov'>"; if (Session::haveRight(self::$rightname, self::READALL)) { Session::initNavigateListItems('Ticket', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); echo "<tr class='noHover'><th colspan='{$colspan}'>"; $title = sprintf(_n('Last %d ticket', 'Last %d tickets', $number), $number); $link = "<a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.php?" . Toolbox::append_params($options, '&') . "'>" . __('Show all') . "</a>"; $title = printf(__('%1$s (%2$s)'), $title, $link); echo "</th></tr>"; } else { echo "<tr><th colspan='{$colspan}'>" . __("You don't have right to see all tickets") . "</th></tr>"; } } else { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('No ticket found.') . "</th></tr>"; } if ($item->getID() && $item->getType() == 'User' && self::canCreate()) { echo "<tr><td class='tab_bg_2 center b' colspan='{$colspan}'>"; Html::showSimpleForm($CFG_GLPI["root_doc"] . "/front/ticket.form.php", '_add_fromitem', __('New ticket for this item...'), array('_users_id_requester' => $item->getID())); echo "</td></tr>"; } // Ticket list if ($number > 0) { self::commonListHeader(Search::HTML_OUTPUT); while ($data = $DB->fetch_assoc($result)) { Session::addToNavigateListItems('Ticket', $data["id"]); self::showShort($data["id"]); } self::commonListHeader(Search::HTML_OUTPUT); } echo "</table></div>"; // Tickets for linked items $linkeditems = $item->getLinkedItems(); $restrict = array(); if (count($linkeditems)) { foreach ($linkeditems as $ltype => $tab) { foreach ($tab as $lID) { $restrict[] = "(`glpi_items_tickets`.`itemtype` = '{$ltype}' AND `glpi_items_tickets`.`items_id` = '{$lID}')"; } } } if (count($restrict) && Session::haveRight(self::$rightname, self::READALL)) { $query = "SELECT " . self::getCommonSelect() . "\n FROM `glpi_tickets` " . self::getCommonLeftJoin() . "\n WHERE " . implode(' OR ', $restrict) . getEntitiesRestrictRequest(' AND ', 'glpi_tickets') . "\n ORDER BY `glpi_tickets`.`date_mod` DESC\n LIMIT " . intval($_SESSION['glpilist_limit']); $result = $DB->query($query); $number = $DB->numrows($result); echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='12'>"; echo _n('Ticket on linked items', 'Tickets on linked items', $number); echo "</th></tr>"; if ($number > 0) { self::commonListHeader(Search::HTML_OUTPUT); while ($data = $DB->fetch_assoc($result)) { // Session::addToNavigateListItems(TRACKING_TYPE,$data["id"]); self::showShort($data["id"]); } self::commonListHeader(Search::HTML_OUTPUT); } else { echo "<tr><th>" . __('No ticket found.') . "</th></tr>"; } echo "</table></div>"; } // Subquery for linked item }
/** * Print out list kb item * * @param $options $_GET * @param $type string search type : browse / search (default search) **/ static function showList($options, $type = 'search') { global $DB, $CFG_GLPI; // Default values of parameters $params['faq'] = !Session::haveRight("knowbase", "r"); $params["start"] = "0"; $params["knowbaseitemcategories_id"] = "0"; $params["contains"] = ""; $params["target"] = $_SERVER['PHP_SELF']; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $params[$key] = $val; } } $ki = new self(); switch ($type) { case 'myunpublished': if (!Session::haveRight('knowbase', 'w') && !Session::haveRight('faq', 'w')) { return false; } break; case 'allunpublished': if (!Session::haveRight('knowbase_admin', 1)) { return false; } break; default: break; } if (!$params["start"]) { $params["start"] = 0; } $query = self::getListRequest($params, $type); // Get it from database if ($result = $DB->query($query)) { $KbCategory = new KnowbaseItemCategory(); $title = ""; if ($KbCategory->getFromDB($params["knowbaseitemcategories_id"])) { $title = empty($KbCategory->fields['name']) ? "(" . $params['knowbaseitemcategories_id'] . ")" : $KbCategory->fields['name']; $title = sprintf(__('%1$s: %2$s'), __('Category'), $title); } Session::initNavigateListItems('KnowbaseItem', $title); $numrows = $DB->numrows($result); $list_limit = $_SESSION['glpilist_limit']; $showwriter = in_array($type, array('myunpublished', 'allunpublished', 'allmy')); // Limit the result, if no limit applies, use prior result if ($numrows > $list_limit && !isset($_GET['export_all'])) { $query_limit = $query . " LIMIT " . intval($params["start"]) . ", " . intval($list_limit) . " "; $result_limit = $DB->query($query_limit); $numrows_limit = $DB->numrows($result_limit); } else { $numrows_limit = $numrows; $result_limit = $result; } if ($numrows_limit > 0) { // Set display type for export if define $output_type = Search::HTML_OUTPUT; if (isset($_GET["display_type"])) { $output_type = $_GET["display_type"]; } // Pager $parameters = "start=" . $params["start"] . "&knowbaseitemcategories_id=" . $params['knowbaseitemcategories_id'] . "&contains=" . $params["contains"] . "&is_faq=" . $params['faq']; if (isset($options['item_itemtype']) && isset($options['item_items_id'])) { $parameters .= "&item_items_id=" . $options['item_items_id'] . "&item_itemtype=" . $options['item_itemtype']; } if ($output_type == Search::HTML_OUTPUT) { Html::printPager($params['start'], $numrows, Toolbox::getItemTypeSearchURL('KnowbaseItem'), $parameters, 'KnowbaseItem'); } $nbcols = 1; // Display List Header echo Search::showHeader($output_type, $numrows_limit + 1, $nbcols); $header_num = 1; echo Search::showHeaderItem($output_type, __('Subject'), $header_num); if ($output_type != Search::HTML_OUTPUT) { echo Search::showHeaderItem($output_type, __('Content'), $header_num); } if ($showwriter) { echo Search::showHeaderItem($output_type, __('Writer'), $header_num); } echo Search::showHeaderItem($output_type, __('Category'), $header_num); if (isset($options['item_itemtype']) && isset($options['item_items_id']) && $output_type == Search::HTML_OUTPUT) { echo Search::showHeaderItem($output_type, ' ', $header_num); } // Num of the row (1=header_line) $row_num = 1; for ($i = 0; $i < $numrows_limit; $i++) { $data = $DB->fetch_assoc($result_limit); Session::addToNavigateListItems('KnowbaseItem', $data["id"]); // Column num $item_num = 1; $row_num++; echo Search::showNewLine($output_type, $i % 2); if ($output_type == Search::HTML_OUTPUT) { if (isset($options['item_itemtype']) && isset($options['item_items_id'])) { $href = " href='#' onClick=\"var w = window.open('" . $CFG_GLPI["root_doc"] . "/front/popup.php?popup=show_kb&id=" . $data['id'] . "' ,'glpipopup', " . "'height=400, width=1000, top=100, left=100, scrollbars=yes' );" . "w.focus();\""; } else { $href = " href=\"" . $CFG_GLPI['root_doc'] . "/front/knowbaseitem.form.php?id=" . $data["id"] . "\" "; } echo Search::showItem($output_type, "<div class='kb'><a " . ($data['is_faq'] ? " class='pubfaq' " : " class='knowbase' ") . " {$href}>" . Html::resume_text($data["name"], 80) . "</a></div>\n <div class='kb_resume'>" . Html::resume_text(Html::clean(Toolbox::unclean_cross_side_scripting_deep($data["answer"])), 600) . "</div>", $item_num, $row_num); } else { echo Search::showItem($output_type, $data["name"], $item_num, $row_num); echo Search::showItem($output_type, Html::clean(Toolbox::unclean_cross_side_scripting_deep(html_entity_decode($data["answer"], ENT_QUOTES, "UTF-8"))), $item_num, $row_num); } if ($showwriter) { echo Search::showItem($output_type, getUserName($data["users_id"], 1), $item_num, $row_num); } $categ = $data["category"]; if ($output_type == Search::HTML_OUTPUT) { $cathref = $ki->getSearchURL() . "?knowbaseitemcategories_id=" . $data["knowbaseitemcategories_id"] . '&forcetab=Knowbase$2'; $categ = "<a href='{$cathref}'>" . $categ . '</a>'; } echo Search::showItem($output_type, $categ, $item_num, $row_num); if (isset($options['item_itemtype']) && isset($options['item_items_id']) && $output_type == Search::HTML_OUTPUT) { $content = "<a href='" . Toolbox::getItemTypeFormURL($options['item_itemtype']) . "?load_kb_sol=" . $data['id'] . "&id=" . $options['item_items_id'] . "&forcetab=" . $options['item_itemtype'] . "\$2'>" . __('Use as a solution') . "</a>"; echo Search::showItem($output_type, $content, $item_num, $row_num); } // End Line echo Search::showEndLine($output_type); } // Display footer if ($output_type == Search::PDF_OUTPUT_LANDSCAPE || $output_type == Search::PDF_OUTPUT_PORTRAIT) { echo Search::showFooter($output_type, Dropdown::getDropdownName("glpi_knowbaseitemcategories", $params['knowbaseitemcategories_id'])); } else { echo Search::showFooter($output_type); } echo "<br>"; if ($output_type == Search::HTML_OUTPUT) { Html::printPager($params['start'], $numrows, Toolbox::getItemTypeSearchURL('KnowbaseItem'), $parameters, 'KnowbaseItem'); } } else { echo "<div class='center b'>" . __('No item found') . "</div>"; } } }
public function showAesKey($ID) { global $DB; $this->h->getFromDB($ID); Session::initNavigateListItems("PluginAccountsAesKey", __('Hash', 'accounts') . " = " . $this->h->fields["name"]); $candelete = $this->h->can($ID, 'w'); $query = "SELECT *\n FROM `glpi_plugin_accounts_aeskeys`\n WHERE `plugin_accounts_hashes_id` = '{$ID}' "; $result = $DB->query($query); $rand = mt_rand(); echo "<div class='center'>"; echo "<form method='post' name='show_aeskey{$rand}' id='show_aeskey{$rand}' action=\"./aeskey.form.php\">"; echo "<input type='hidden' name='plugin_accounts_hashes_id' value='" . $ID . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='5'>" . __('Encryption key', 'accounts') . "</th></tr>"; echo "<tr><th> </th>"; echo "<th class='left'>" . __('Name') . "</th>"; echo "</tr>"; if ($DB->numrows($result) > 0) { while ($data = $DB->fetch_array($result)) { Session::addToNavigateListItems("PluginAccountsAesKey", $data['id']); echo "<input type='hidden' name='item[" . $data["id"] . "]' value='" . $ID . "'>"; echo "<tr class='tab_bg_1 center'>"; echo "<td width='10'>"; if ($candelete) { echo "<input type='checkbox' name='check[" . $data["id"] . "]'"; if (isset($_POST['check']) && $_POST['check'] == 'all') { echo " checked "; } echo ">"; } echo "</td>"; $link = Toolbox::getItemTypeFormURL("PluginAccountsAesKey"); echo "<td class='left'><a href='" . $link . "?id=" . $data["id"] . "&plugin_accounts_hashes_id=" . $ID . "'>"; echo __('Encryption key', 'accounts') . "</a></td>"; echo "</tr>"; } echo "</table>"; if ($candelete) { Html::openArrowMassives("show_aeskey{$rand}", true); Html::closeArrowMassives(array('delete' => __('Delete permanently'))); } } else { echo "</table>"; } Html::closeForm(); echo "</div>"; }
/** * Show the aliases contained by the alias * * @param $item the FQDN owning the aliases * @param $withtemplate integer withtemplate param **/ static function showForFQDN(CommonGLPI $item, $withtemplate) { global $DB; $alias = new self(); $address = new NetworkName(); $item->check($item->getID(), 'r'); $canedit = $item->can($item->getID(), 'w'); if (isset($_POST["start"])) { $start = $_POST["start"]; } else { $start = 0; } if (!empty($_POST["order"])) { $order = $_POST["order"]; } else { $order = "alias"; } $number = countElementsInTable($alias->getTable(), "`fqdns_id`='" . $item->getID() . "'"); echo "<br><div class='center'>"; if ($number < 1) { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . self::getTypeName(1) . "</th><th>" . __('No item found') . "</th></tr>"; echo "</table>\n"; } else { Html::printAjaxPager(self::getTypeName($number), $start, $number); echo "<table class='tab_cadre_fixe'><tr>"; echo "<th><a href='javascript:reloadTab(\"order=alias\");'>" . self::getTypeName(1) . "</a></th>"; // Alias echo "<th><a href='javascript:reloadTab(\"order=realname\");'>" . __("Computer's name") . "</a></th>"; echo "<th>" . __('Comments') . "</th>"; echo "</tr>\n"; Session::initNavigateListItems($item->getType(), sprintf(__('%1$s = %2$s'), self::getTypeName(1), $item->fields['name'])); $query = "SELECT `glpi_networkaliases`.`id` AS alias_id,\n `glpi_networkaliases`.`name` AS alias,\n `glpi_networknames`.`id` AS address_id,\n `glpi_networkaliases`.`comment` AS comment\n FROM `glpi_networkaliases`, `glpi_networknames`\n WHERE `glpi_networkaliases`.`fqdns_id` = '" . $item->getID() . "'\n AND `glpi_networknames`.`id` = `glpi_networkaliases`.`networknames_id`\n ORDER BY `{$order}`\n LIMIT " . $_SESSION['glpilist_limit'] . "\n OFFSET {$start}"; foreach ($DB->request($query) as $data) { Session::addToNavigateListItems($alias->getType(), $data["alias_id"]); if ($address->getFromDB($data["address_id"])) { echo "<tr class='tab_bg_1'>"; echo "<td><a href='" . $alias->getFormURL() . '?id=' . $data['alias_id'] . "'>" . $data['alias'] . "</a></td>"; echo "<td><a href='" . $address->getLinkURL() . "'>" . $address->getInternetName() . "</a></td>"; echo "<td>" . $data['comment'] . "</td>"; echo "</tr>\n"; } } echo "</table>\n"; Html::printAjaxPager(self::getTypeName($number), $start, $number); } echo "</div>\n"; }
/** * Display changes for an item * * Will also display changes of linked items * * @param $item CommonDBTM object * * @return nothing (display a table) **/ static function showListForItem(CommonDBTM $item) { global $DB, $CFG_GLPI; if (!Session::haveRight(self::$rightname, self::READALL)) { return false; } if ($item->isNewID($item->getID())) { return false; } $restrict = ''; $order = ''; $options['reset'] = 'reset'; switch ($item->getType()) { case 'User': $restrict = "(`glpi_changes_users`.`users_id` = '" . $item->getID() . "')"; $order = '`glpi_changes`.`date_mod` DESC'; $options['criteria'][0]['field'] = 4; // status $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'OR'; $options['criteria'][1]['field'] = 66; // status $options['criteria'][1]['searchtype'] = 'equals'; $options['criteria'][1]['value'] = $item->getID(); $options['criteria'][1]['link'] = 'OR'; $options['criteria'][5]['field'] = 5; // status $options['criteria'][5]['searchtype'] = 'equals'; $options['criteria'][5]['value'] = $item->getID(); $options['criteria'][5]['link'] = 'OR'; break; case 'Supplier': $restrict = "(`glpi_changes_suppliers`.`suppliers_id` = '" . $item->getID() . "')"; $order = '`glpi_changes`.`date_mod` DESC'; $options['criteria'][0]['field'] = 6; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'AND'; break; case 'Group': // Mini search engine if ($item->haveChildren()) { $tree = Session::getSavedOption(__CLASS__, 'tree', 0); echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th>" . __('Last changes') . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; _e('Child groups'); Dropdown::showYesNo('tree', $tree, -1, array('on_change' => 'reloadTab("start=0&tree="+this.value)')); } else { $tree = 0; } echo "</td></tr></table>"; if ($tree) { $restrict = "IN (" . implode(',', getSonsOf('glpi_groups', $item->getID())) . ")"; } else { $restrict = "='" . $item->getID() . "'"; } $restrict = "(`glpi_changes_groups`.`groups_id` {$restrict}\n AND `glpi_changes_groups`.`type` = " . CommonITILActor::REQUESTER . ")"; $order = '`glpi_changes`.`date_mod` DESC'; $options['criteria'][0]['field'] = 71; $options['criteria'][0]['searchtype'] = $tree ? 'under' : 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'AND'; break; default: $restrict = "(`items_id` = '" . $item->getID() . "'\n AND `itemtype` = '" . $item->getType() . "')"; $order = '`glpi_changes`.`date_mod` DESC'; break; } $query = "SELECT " . self::getCommonSelect() . "\n FROM `glpi_changes`\n LEFT JOIN `glpi_changes_items`\n ON (`glpi_changes`.`id` = `glpi_changes_items`.`changes_id`) " . self::getCommonLeftJoin() . "\n WHERE {$restrict} " . getEntitiesRestrictRequest("AND", "glpi_changes") . "\n ORDER BY {$order}\n LIMIT " . intval($_SESSION['glpilist_limit']); $result = $DB->query($query); $number = $DB->numrows($result); // Ticket for the item echo "<div class='firstbloc'><table class='tab_cadre_fixe'>"; $colspan = 11; if (count($_SESSION["glpiactiveentities"]) > 1) { $colspan++; } if ($number > 0) { Session::initNavigateListItems('Change', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); echo "<tr><th colspan='{$colspan}'>"; //TRANS : %d is the number of problems echo sprintf(_n('Last %d change', 'Last %d changes', $number), $number); // echo "<span class='small_space'><a href='".$CFG_GLPI["root_doc"]."/front/ticket.php?". // Toolbox::append_params($options,'&')."'>".__('Show all')."</a></span>"; echo "</th></tr>"; } else { echo "<tr><th>" . __('No change found.') . "</th></tr>"; } // Ticket list if ($number > 0) { self::commonListHeader(Search::HTML_OUTPUT); while ($data = $DB->fetch_assoc($result)) { Session::addToNavigateListItems('Problem', $data["id"]); self::showShort($data["id"]); } self::commonListHeader(Search::HTML_OUTPUT); } echo "</table></div>"; // Tickets for linked items $linkeditems = $item->getLinkedItems(); $restrict = array(); if (count($linkeditems)) { foreach ($linkeditems as $ltype => $tab) { foreach ($tab as $lID) { $restrict[] = "(`itemtype` = '{$ltype}' AND `items_id` = '{$lID}')"; } } } if (count($restrict)) { $query = "SELECT " . self::getCommonSelect() . "\n FROM `glpi_changes`\n LEFT JOIN `glpi_changes_items`\n ON (`glpi_changes`.`id` = `glpi_changes_items`.`changes_id`) " . self::getCommonLeftJoin() . "\n WHERE " . implode(' OR ', $restrict) . getEntitiesRestrictRequest(' AND ', 'glpi_changes') . "\n ORDER BY `glpi_changes`.`date_mod` DESC\n LIMIT " . intval($_SESSION['glpilist_limit']); $result = $DB->query($query); $number = $DB->numrows($result); echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='{$colspan}'>"; _e('Changes on linked items'); echo "</th></tr>"; if ($number > 0) { self::commonListHeader(Search::HTML_OUTPUT); while ($data = $DB->fetch_assoc($result)) { // Session::addToNavigateListItems(TRACKING_TYPE,$data["id"]); self::showShort($data["id"]); } self::commonListHeader(Search::HTML_OUTPUT); } else { echo "<tr><th>" . __('No change found.') . "</th></tr>"; } echo "</table></div>"; } // Subquery for linked item }
/** * Show changes for a ticket * * @param $ticket Ticket object **/ static function showForTicket(Ticket $ticket) { global $DB, $CFG_GLPI; $ID = $ticket->getField('id'); if (!$ticket->can($ID, READ)) { return false; } $canedit = $ticket->canEdit($ID); $rand = mt_rand(); $query = "SELECT DISTINCT `glpi_changes_tickets`.`id` AS linkID,\n `glpi_changes`.*\n FROM `glpi_changes_tickets`\n LEFT JOIN `glpi_changes`\n ON (`glpi_changes_tickets`.`changes_id` = `glpi_changes`.`id`)\n WHERE `glpi_changes_tickets`.`tickets_id` = '{$ID}'\n ORDER BY `glpi_changes`.`name`"; $result = $DB->query($query); $changes = array(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $changes[$data['id']] = $data; $used[$data['id']] = $data['id']; } } if ($canedit) { echo "<div class='firstbloc'>"; echo "<form name='changeticket_form{$rand}' id='changeticket_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2'><th colspan='3'>" . __('Add a change') . "</th></tr>"; echo "<tr class='tab_bg_2'><td>"; echo "<input type='hidden' name='tickets_id' value='{$ID}'>"; Change::dropdown(array('used' => $used, 'entity' => $ticket->getEntityID())); echo "</td><td class='center'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td><td>"; if (Session::haveRight('change', CREATE)) { echo "<a href='" . Toolbox::getItemTypeFormURL('Change') . "?tickets_id={$ID}'>"; _e('Create a change from this ticket'); echo "</a>"; } echo "</td></tr></table>"; Html::closeForm(); echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $numrows) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $numrows, 'container' => 'mass' . __CLASS__ . $rand); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixehov'>"; echo "<tr class='noHover'><th colspan='12'>" . Change::getTypeName($numrows) . "</th>"; echo "</tr>"; if ($numrows) { Change::commonListHeader(Search::HTML_OUTPUT, 'mass' . __CLASS__ . $rand); Session::initNavigateListItems('Change', sprintf(__('%1$s = %2$s'), Ticket::getTypeName(1), $ticket->fields["name"])); $i = 0; foreach ($changes as $data) { Session::addToNavigateListItems('Change', $data["id"]); Change::showShort($data['id'], array('row_num' => $i, 'type_for_massiveaction' => __CLASS__, 'id_for_massiveaction' => $data['linkID'])); $i++; } Change::commonListHeader(Search::HTML_OUTPUT, 'mass' . __CLASS__ . $rand); } echo "</table>"; if ($canedit && $numrows) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * Show Licenses of a software * * @param $software Software object * * @return nothing **/ static function showForSoftware(Software $software) { global $DB, $CFG_GLPI; $softwares_id = $software->getField('id'); $license = new self(); $computer = new Computer(); if (!$software->can($softwares_id, READ)) { return false; } $columns = array('name' => __('Name'), 'entity' => __('Entity'), 'serial' => __('Serial number'), 'number' => _x('quantity', 'Number'), '_affected' => __('Affected computers'), 'typename' => __('Type'), 'buyname' => __('Purchase version'), 'usename' => __('Version in use'), 'expire' => __('Expiration')); if (!$software->isRecursive()) { unset($columns['entity']); } if (isset($_GET["start"])) { $start = $_GET["start"]; } else { $start = 0; } if (isset($_GET["order"]) && $_GET["order"] == "DESC") { $order = "DESC"; } else { $order = "ASC"; } if (isset($_GET["sort"]) && !empty($_GET["sort"]) && isset($columns[$_GET["sort"]])) { $sort = "`" . $_GET["sort"] . "`"; } else { $sort = "`entity` {$order}, `name`"; } // Righ type is enough. Can add a License on a software we have Read access $canedit = Software::canUpdate(); $showmassiveactions = $canedit; // Total Number of events $number = countElementsInTable("glpi_softwarelicenses", "glpi_softwarelicenses.softwares_id = {$softwares_id} " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true)); echo "<div class='spaced'>"; Session::initNavigateListItems('SoftwareLicense', sprintf(__('%1$s = %2$s'), Software::getTypeName(1), $software->getName())); if ($canedit) { echo "<div class='center firstbloc'>"; echo "<a class='vsubmit' href='softwarelicense.form.php?softwares_id={$softwares_id}'>" . _x('button', 'Add a license') . "</a>"; echo "</div>"; } $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']); if ($result = $DB->query($query)) { if ($num_displayed = $DB->numrows($result)) { // Display the pager Html::printAjaxPager(self::getTypeName(Session::getPluralNumber()), $start, $number); if ($showmassiveactions) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $num_displayed, 'container' => 'mass' . __CLASS__ . $rand, 'extraparams' => array('options' => array('glpi_softwareversions.name' => array('condition' => "`glpi_softwareversions`.`softwares_id`\n = {$softwares_id}"), 'glpi_softwarelicenses.name' => array('itemlink_as_string' => true)))); Html::showMassiveActions($massiveactionparams); } $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>"; $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'>"; $header_begin = "<tr><th>"; $header_top = Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_bottom = Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_end = ''; foreach ($columns as $key => $val) { // Non order column if ($key[0] == '_') { $header_end .= "<th>{$val}</th>"; } else { $header_end .= "<th>" . ($sort == "`{$key}`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort={$key}&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>{$val}</a></th>"; } } $header_end .= "</tr>\n"; echo $header_begin . $header_top . $header_end; $tot_assoc = 0; for ($tot = 0; $data = $DB->fetch_assoc($result);) { Session::addToNavigateListItems('SoftwareLicense', $data['id']); $expired = true; if (is_null($data['expire']) || $data['expire'] > date('Y-m-d')) { $expired = false; } echo "<tr class='tab_bg_2" . ($expired ? '_2' : '') . "'>"; if ($license->canEdit($data['id'])) { echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</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 (isset($columns['entity'])) { echo "<td>"; echo $data['entity']; echo "</td>"; } echo "<td>" . $data['serial'] . "</td>"; echo "<td class='numeric'>" . ($data['number'] > 0 ? $data['number'] : __('Unlimited')) . "</td>"; $nb_assoc = Computer_SoftwareLicense::countForLicense($data['id']); $tot_assoc += $nb_assoc; $color = $data['is_valid'] ? 'green' : 'red'; echo "<td class='numeric {$color}'>" . $nb_assoc . "</td>"; echo "<td>" . $data['typename'] . "</td>"; echo "<td>" . $data['buyname'] . "</td>"; echo "<td>" . $data['usename'] . "</td>"; echo "<td class='center'>" . Html::convDate($data['expire']) . "</td>"; echo "</tr>"; if ($data['number'] < 0) { // One illimited license, total is illimited $tot = -1; } else { if ($tot >= 0) { // Expire license not count if (!$expired) { // Not illimited, add the current number $tot += $data['number']; } } } } echo "<tr class='tab_bg_1 noHover'>"; echo "<td colspan='" . ($software->isRecursive() ? 4 : 3) . "' class='right b'>" . __('Total') . "</td>"; echo "<td class='numeric'>" . ($tot > 0 ? $tot . "" : __('Unlimited')) . "</td>"; $color = $software->fields['is_valid'] ? 'green' : 'red'; echo "<td class='numeric {$color}'>" . $tot_assoc . "</td><td></td><td></td><td></td><td></td>"; echo "</tr>"; echo "</table>\n"; if ($showmassiveactions) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } Html::printAjaxPager(self::getTypeName(Session::getPluralNumber()), $start, $number); } else { echo "<table class='tab_cadre_fixe'><tr><th>" . __('No item found') . "</th></tr></table>"; } } echo "</div>"; }
function showMinimalList($params) { global $DB, $CFG_GLPI; $itemtype = "PluginResourcesDirectory"; $itemtable = $this->table; if (class_exists($itemtype)) { $item = new $itemtype(); } // Default values of parameters $p['link'] = array(); // $p['field'] = array(); // $p['contains'] = array(); // $p['searchtype'] = array(); // $p['sort'] = '1'; // $p['order'] = 'ASC'; // $p['start'] = 0; // $p['is_deleted'] = 0; $p['id'] = 0; $p['withtemplate'] = 0; $p['export_all'] = 0; $p['link2'] = ''; // $p['contains2'] = ''; // $p['field2'] = ''; // $p['itemtype2'] = ''; $p['searchtype2'] = ''; foreach ($params as $key => $val) { $p[$key] = $val; } if ($p['export_all']) { $p['start'] = 0; } $PluginResourcesResource = new PluginResourcesResource(); $canedit = $PluginResourcesResource->can($p['id'], 'w'); // Manage defautlt seachtype value : for bookmark compatibility if (count($p['contains'])) { foreach ($p['contains'] as $key => $val) { if (!isset($p['searchtype'][$key])) { $p['searchtype'][$key] = 'contains'; } } } if (is_array($p['contains2']) && count($p['contains2'])) { foreach ($p['contains2'] as $key => $val) { if (!isset($p['searchtype2'][$key])) { $p['searchtype2'][$key] = 'contains'; } } } $target = $CFG_GLPI["root_doc"] . "/plugins/resources/front/directory.php"; $limitsearchopt = Search::getCleanedOptions("PluginResourcesDirectory"); $LIST_LIMIT = $_SESSION['glpilist_limit']; // Set display type for export if define $output_type = Search::HTML_OUTPUT; if (isset($_GET['display_type'])) { $output_type = $_GET['display_type']; // Limit to 10 element if ($_GET['display_type'] == Search::GLOBAL_SEARCH) { $LIST_LIMIT = Search::GLOBAL_DISPLAY_COUNT; } } $entity_restrict = $PluginResourcesResource->isEntityAssign(); // Get the items to display $toview = Search::addDefaultToView("User"); // Add items to display depending of personal prefs $displaypref = DisplayPreference::getForTypeUser("PluginResourcesDirectory", Session::getLoginUserID()); if (count($displaypref)) { foreach ($displaypref as $val) { array_push($toview, $val); } } // Add searched items if (count($p['field']) > 0) { foreach ($p['field'] as $key => $val) { if (!in_array($val, $toview) && $val != 'all' && $val != 'view') { array_push($toview, $val); } } } // Add order item if (!in_array($p['sort'], $toview)) { array_push($toview, $p['sort']); } // Clean toview array $toview = array_unique($toview); foreach ($toview as $key => $val) { if (!isset($limitsearchopt[$val])) { unset($toview[$key]); } } $toview_count = count($toview); //// 1 - SELECT $query = "SELECT " . Search::addDefaultSelect("User"); // Add select for all toview item foreach ($toview as $key => $val) { $query .= self::addSelect("PluginResourcesDirectory", $val, $key, 0); } $query .= "`glpi_plugin_resources_resources`.`id` AS id "; //// 2 - FROM AND LEFT JOIN // Set reference table $query .= " FROM `" . $itemtable . "`"; // Init already linked tables array in order not to link a table several times $already_link_tables = array(); // Put reference table array_push($already_link_tables, $itemtable); // Add default join $COMMONLEFTJOIN = Search::addDefaultJoin("PluginResourcesDirectory", $itemtable, $already_link_tables); $query .= $COMMONLEFTJOIN; $searchopt = array(); $searchopt["PluginResourcesDirectory"] =& Search::getOptions("PluginResourcesDirectory"); // Add all table for toview items foreach ($toview as $key => $val) { $query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt["PluginResourcesDirectory"][$val]["table"], $searchopt["PluginResourcesDirectory"][$val]["linkfield"], 0, 0, $searchopt["PluginResourcesDirectory"][$val]["joinparams"]); } // Search all case : if (in_array("all", $p['field'])) { foreach ($searchopt[$itemtype] as $key => $val) { // Do not search on Group Name if (is_array($val)) { $query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt["PluginResourcesDirectory"][$key]["table"], $searchopt["PluginResourcesDirectory"][$key]["linkfield"], 0, 0, $searchopt["PluginResourcesDirectory"][$key]["joinparams"]); } } } $ASSIGN = " `glpi_plugin_resources_resources`.`is_leaving` = 0 AND `glpi_users`.`is_active` = 1 AND "; //// 3 - WHERE // default string $COMMONWHERE = Search::addDefaultWhere($itemtype); $first = empty($COMMONWHERE); // Add deleted if item have it if ($PluginResourcesResource && $PluginResourcesResource->maybeDeleted()) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } $COMMONWHERE .= $LINK . "`glpi_plugin_resources_resources`.`is_deleted` = '" . $p['is_deleted'] . "' "; } // Remove template items if ($PluginResourcesResource && $PluginResourcesResource->maybeTemplate()) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } $COMMONWHERE .= $LINK . "`glpi_plugin_resources_resources`.`is_template` = '0' "; } // Add Restrict to current entities if ($entity_restrict) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } if (isset($CFG_GLPI["union_search_type"][$itemtype])) { // Will be replace below in Union/Recursivity Hack $COMMONWHERE .= $LINK . " ENTITYRESTRICT "; } else { $COMMONWHERE .= getEntitiesRestrictRequest($LINK, "glpi_plugin_resources_resources", '', '', $PluginResourcesResource->maybeRecursive()); } } $WHERE = ""; $HAVING = ""; // Add search conditions // If there is search items if ($_SESSION["glpisearchcount"]["PluginResourcesDirectory"] > 0 && count($p['contains']) > 0) { for ($key = 0; $key < $_SESSION["glpisearchcount"]["PluginResourcesDirectory"]; $key++) { // if real search (strlen >0) and not all and view search if (isset($p['contains'][$key]) && strlen($p['contains'][$key]) > 0) { // common search if ($p['field'][$key] != "all" && $p['field'][$key] != "view") { $LINK = " "; $NOT = 0; $tmplink = ""; if (is_array($p['link']) && isset($p['link'][$key])) { if (strstr($p['link'][$key], "NOT")) { $tmplink = " " . str_replace(" NOT", "", $p['link'][$key]); $NOT = 1; } else { $tmplink = " " . $p['link'][$key]; } } else { $tmplink = " AND "; } if (isset($searchopt["PluginResourcesDirectory"][$p['field'][$key]]["usehaving"])) { // Manage Link if not first item if (!empty($HAVING)) { $LINK = $tmplink; } // Find key $item_num = array_search($p['field'][$key], $toview); $HAVING .= Search::addHaving($LINK, $NOT, "PluginResourcesDirectory", $p['field'][$key], $p['searchtype'][$key], $p['contains'][$key], 0, $item_num); } else { // Manage Link if not first item if (!empty($WHERE)) { $LINK = $tmplink; } $WHERE .= self::addWhere($LINK, $NOT, "PluginResourcesDirectory", $p['field'][$key], $p['searchtype'][$key], $p['contains'][$key]); } // view and all search } else { $LINK = " OR "; $NOT = 0; $globallink = " AND "; if (is_array($p['link']) && isset($p['link'][$key])) { switch ($p['link'][$key]) { case "AND": $LINK = " OR "; $globallink = " AND "; break; case "AND NOT": $LINK = " AND "; $NOT = 1; $globallink = " AND "; break; case "OR": $LINK = " OR "; $globallink = " OR "; break; case "OR NOT": $LINK = " AND "; $NOT = 1; $globallink = " OR "; break; } } else { $tmplink = " AND "; } // Manage Link if not first item if (!empty($WHERE)) { $WHERE .= $globallink; } $WHERE .= " ( "; $first2 = true; $items = array(); if ($p['field'][$key] == "all") { $items = $searchopt["PluginResourcesDirectory"]; } else { // toview case : populate toview foreach ($toview as $key2 => $val2) { $items[$val2] = $searchopt["PluginResourcesDirectory"][$val2]; } } foreach ($items as $key2 => $val2) { if (is_array($val2)) { // Add Where clause if not to be done in HAVING CLAUSE if (!isset($val2["usehaving"])) { $tmplink = $LINK; if ($first2) { $tmplink = " "; $first2 = false; } $WHERE .= self::addWhere($tmplink, $NOT, "PluginResourcesDirectory", $key2, $p['searchtype'][$key], $p['contains'][$key]); } } } $WHERE .= " ) "; } } } } if (!empty($WHERE) || !empty($COMMONWHERE)) { if (!empty($COMMONWHERE)) { $WHERE = ' WHERE ' . $ASSIGN . ' ' . $COMMONWHERE . (!empty($WHERE) ? ' AND ( ' . $WHERE . ' )' : ''); } else { $WHERE = ' WHERE ' . $ASSIGN . ' ' . $WHERE . ' '; } $first = false; } $query .= $WHERE; //// 7 - Manage GROUP BY $GROUPBY = ""; // Meta Search / Search All / Count tickets if (in_array('all', $p['field'])) { $GROUPBY = " GROUP BY `" . $itemtable . "`.`id`"; } if (empty($GROUPBY)) { foreach ($toview as $key2 => $val2) { if (!empty($GROUPBY)) { break; } if (isset($searchopt["PluginResourcesDirectory"][$val2]["forcegroupby"])) { $GROUPBY = " GROUP BY `" . $itemtable . "`.`id`"; } } } $query .= $GROUPBY; //// 4 - ORDER $ORDER = " ORDER BY `id` "; foreach ($toview as $key => $val) { if ($p['sort'] == $val) { $ORDER = Search::addOrderBy($itemtype, $p['sort'], $p['order'], $key); } } $query .= $ORDER; // Get it from database if ($result = $DB->query($query)) { $numrows = $DB->numrows($result); $globallinkto = Search::getArrayUrlLink("field", $p['field']) . Search::getArrayUrlLink("link", $p['link']) . Search::getArrayUrlLink("contains", $p['contains']) . Search::getArrayUrlLink("searchtype", $p['searchtype']) . Search::getArrayUrlLink("field2", $p['field2']) . Search::getArrayUrlLink("contains2", $p['contains2']) . Search::getArrayUrlLink("searchtype2", $p['searchtype2']) . Search::getArrayUrlLink("itemtype2", $p['itemtype2']) . Search::getArrayUrlLink("link2", $p['link2']); $parameters = "sort=" . $p['sort'] . "&order=" . $p['order'] . $globallinkto; if ($output_type == Search::GLOBAL_SEARCH) { if (class_exists($itemtype)) { echo "<div class='center'><h2>" . $this->getTypeName(); // More items if ($numrows > $p['start'] + Search::GLOBAL_DISPLAY_COUNT) { echo " <a href='{$target}?{$parameters}'>" . __('All') . "</a>"; } echo "</h2></div>\n"; } else { return false; } } if ($p['start'] < $numrows) { // Pager if ($output_type == Search::HTML_OUTPUT) { // HTML display - massive modif $search_config = ""; if ($item->canCreate() && $canedit) { $tmp = " class='pointer' onClick=\"var w = window.open('" . $CFG_GLPI["root_doc"] . "/front/popup.php?popup=search_config&itemtype=" . $itemtype . "' ,'glpipopup', " . "'height=400, width=1000, top=100, left=100, scrollbars=yes' ); w.focus();\""; $search_config = "<img alt='" . __('Select default items to show') . "' title='" . __('Select default items to show') . "' src='" . $CFG_GLPI["root_doc"] . "/pics/options_search.png' "; $search_config .= $tmp . ">"; } //echo Search::showHeaderItem($output_type,$search_config,$header_num,"",0,$p['order']); } // Pager if ($output_type == Search::HTML_OUTPUT) { Html::printPager($p['start'], $numrows, $target, $parameters, $itemtype, 0, $search_config); echo "<br>"; } // Define begin and end var for loop // Search case $begin_display = $p['start']; $end_display = $p['start'] + $LIST_LIMIT; // Export All case if ($p['export_all']) { $begin_display = 0; $end_display = $numrows; } //massive action $sel = ""; if (isset($_GET["select"]) && $_GET["select"] == "all") { $sel = "checked"; } if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) { Html::openMassiveActionsForm('massform' . $itemtype); $massiveactionparams = array('num_displayed' => $end_display - $begin_display, 'fixed' => false, 'is_deleted' => $p['is_deleted']); Html::showMassiveActions("PluginResourcesDirectory", $massiveactionparams); } // Add toview elements $nbcols = $toview_count; if ($output_type == Search::HTML_OUTPUT) { // HTML display - massive modif $nbcols++; } // Display List Header echo Search::showHeader($output_type, $end_display - $begin_display + 1, $nbcols); $header_num = 1; // Display column Headers for toview items $headers_line = ''; $headers_line_top = ''; $headers_line_bottom = ''; echo Search::showNewLine($output_type); if ($output_type == Search::HTML_OUTPUT && $item->canCreate() && $canedit) { // HTML display - massive modif $headers_line_top .= Search::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']); $headers_line_bottom .= Search::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']); } // Display column Headers for toview items foreach ($toview as $key => $val) { $linkto = ''; if (!isset($searchopt["PluginResourcesDirectory"][$val]['nosort']) || !$searchopt["PluginResourcesDirectory"][$val]['nosort']) { $linkto = "javascript:reloadTab('sort=" . $val . "&order=" . ($p['order'] == "ASC" ? "DESC" : "ASC") . "&start=" . $p['start'] . $globallinkto . "')"; } $headers_line .= Search::showHeaderItem($output_type, $searchopt["PluginResourcesDirectory"][$val]["name"], $header_num, $linkto, $p['sort'] == $val, $p['order']); } // End Line for column headers $headers_line .= Search::showEndLine($output_type); $headers_line_top .= $headers_line; $headers_line_bottom .= $headers_line; echo $headers_line_top; $DB->data_seek($result, $p['start']); // Define begin and end var for loop // Search case $i = $begin_display; // Init list of items displayed if ($output_type == Search::HTML_OUTPUT) { Session::initNavigateListItems($itemtype); } // Num of the row (1=header_line) $row_num = 1; // Display Loop while ($i < $numrows && $i < $end_display) { $item_num = 1; $data = $DB->fetch_array($result); $i++; $row_num++; echo Search::showNewLine($output_type, $i % 2); Session::addToNavigateListItems($itemtype, $data['id']); $tmpcheck = ""; if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) { $sel = ""; $tmpcheck = "<input type='checkbox' name='item[" . $data["id"] . "]' value='1' {$sel}>"; echo Search::showItem($output_type, $tmpcheck, $item_num, $row_num, "width='10'"); } foreach ($toview as $key => $val) { echo Search::showItem($output_type, Search::giveItem("PluginResourcesDirectory", $val, $data, $key), $item_num, $row_num, Search::displayConfigItem("PluginResourcesDirectory", $val, $data, $key)); } echo Search::showEndLine($output_type); } // Close Table $title = ""; // Create title if ($output_type == Search::PDF_OUTPUT_PORTRAIT || $output_type == Search::PDF_OUTPUT_LANDSCAPE) { $title .= self::getTypeName(1); } // Display footer echo Search::showFooter($output_type, $title); //massive action if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) { $massiveactionparams['ontop'] = false; $massiveactionparams['fixed'] = false; Html::showMassiveActions("PluginResourcesDirectory", $massiveactionparams); Html::closeForm(); } else { echo "</table></div>"; } // Pager if ($output_type == Search::HTML_OUTPUT) { echo "<br>"; Html::printPager($p['start'], $numrows, $target, $parameters, "PluginResourcesDirectory", 0, $search_config); } } else { echo Search::showError($output_type); } } }
/** * Print the validation list into ticket * * @param $ticket class **/ function showSummary($ticket) { global $DB, $CFG_GLPI; if (!Session::haveRight('validate_request', 1) && !Session::haveRight('validate_incident', 1) && !Session::haveRight('create_incident_validation', 1) && !Session::haveRight('create_request_validation', 1)) { return false; } $tID = $ticket->fields['id']; $tmp = array('tickets_id' => $tID); $canadd = $this->can(-1, 'w', $tmp); $rand = mt_rand(); echo "<div id='viewfollowup" . $tID . "{$rand}'></div>\n"; if ($canadd) { echo "<script type='text/javascript' >\n"; echo "function viewAddValidation" . $tID . "{$rand}() {\n"; $params = array('type' => __CLASS__, 'parenttype' => 'Ticket', 'tickets_id' => $tID, 'id' => -1); Ajax::updateItemJsCode("viewfollowup" . $tID . "{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params); echo "};"; echo "</script>\n"; if ($ticket->fields["status"] != CommonITILObject::SOLVED && $ticket->fields["status"] != CommonITILObject::CLOSED) { echo "<div class='center'>"; echo "<a class='vsubmit' href='javascript:viewAddValidation" . $tID . "{$rand}();'>"; echo __('Send an approval request') . "</a></div><br>\n"; } } $query = "SELECT *\n FROM `" . $this->getTable() . "`\n WHERE `tickets_id` = '" . $ticket->getField('id') . "'"; if (!$canadd) { $query .= " AND `users_id_validate` = '" . Session::getLoginUserID() . "' "; } $query .= " ORDER BY submission_date DESC"; $result = $DB->query($query); $number = $DB->numrows($result); if ($number) { $colonnes = array(__('State'), sprintf(__('%1$s: %2$s'), __('Request'), __('Date')), __('Approval requester'), sprintf(__('%1$s: %2$s'), __('Request'), __('Comments')), __('Approval date'), __('Approver'), sprintf(__('%1$s: %2$s'), __('Approval'), __('Comments'))); $nb_colonnes = count($colonnes); echo "<table class='tab_cadre_fixehov'>"; echo "<tr><th colspan='" . $nb_colonnes . "'>" . __('Approvals for the ticket') . "</th></tr>"; echo "<tr>"; foreach ($colonnes as $colonne) { echo "<th>" . $colonne . "</th>"; } echo "</tr>"; Session::initNavigateListItems('TicketValidation', sprintf(__('%1$s = %2$s'), $ticket->getTypeName(1), $ticket->fields["name"])); while ($row = $DB->fetch_assoc($result)) { $canedit = $this->can($row["id"], 'w'); Session::addToNavigateListItems('TicketValidation', $row["id"]); $bgcolor = $this->getStatusColor($row['status']); $status = $this->getStatus($row['status']); echo "<tr class='tab_bg_1' " . ($canedit ? "style='cursor:pointer' onClick=\"viewEditValidation" . $ticket->fields['id'] . $row["id"] . "{$rand}();\"" : '') . " id='viewfollowup" . $this->fields['tickets_id'] . $row["id"] . "{$rand}'>"; echo "<td>"; if ($canedit) { echo "\n<script type='text/javascript' >\n"; echo "function viewEditValidation" . $ticket->fields['id'] . $row["id"] . "{$rand}() {\n"; $params = array('type' => __CLASS__, 'parenttype' => 'Ticket', 'tickets_id' => $this->fields["tickets_id"], 'id' => $row["id"]); Ajax::updateItemJsCode("viewfollowup" . $ticket->fields['id'] . "{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params); echo "};"; echo "</script>\n"; } echo "<div style='background-color:" . $bgcolor . ";'>" . $status . "</div></td>"; echo "<td>" . Html::convDateTime($row["submission_date"]) . "</td>"; echo "<td>" . getUserName($row["users_id"]) . "</td>"; echo "<td>" . $row["comment_submission"] . "</td>"; echo "<td>" . Html::convDateTime($row["validation_date"]) . "</td>"; echo "<td>" . getUserName($row["users_id_validate"]) . "</td>"; echo "<td>" . $row["comment_validation"] . "</td>"; echo "</tr>"; } echo "</table>"; } else { echo "<div class='center b'>" . __('No item found') . "</div>"; } }
/** * Print out list kb item * * @param $options $_GET * @param $type string search type : browse / search (default search) **/ static function showList($options, $type = 'search') { global $DB, $CFG_GLPI; // Default values of parameters $params['faq'] = !Session::haveRight(self::$rightname, READ); $params["start"] = "0"; $params["knowbaseitemcategories_id"] = "0"; $params["contains"] = ""; $params["target"] = $_SERVER['PHP_SELF']; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $params[$key] = $val; } } $ki = new self(); switch ($type) { case 'myunpublished': if (!Session::haveRightsOr(self::$rightname, array(UPDATE, self::PUBLISHFAQ))) { return false; } break; case 'allunpublished': if (!Session::haveRight(self::$rightname, self::KNOWBASEADMIN)) { return false; } break; default: break; } if (!$params["start"]) { $params["start"] = 0; } $query = self::getListRequest($params, $type); // Get it from database if ($result = $DB->query($query)) { $KbCategory = new KnowbaseItemCategory(); $title = ""; if ($KbCategory->getFromDB($params["knowbaseitemcategories_id"])) { $title = empty($KbCategory->fields['name']) ? "(" . $params['knowbaseitemcategories_id'] . ")" : $KbCategory->fields['name']; $title = sprintf(__('%1$s: %2$s'), __('Category'), $title); } Session::initNavigateListItems('KnowbaseItem', $title); $numrows = $DB->numrows($result); $list_limit = $_SESSION['glpilist_limit']; $showwriter = in_array($type, array('myunpublished', 'allunpublished', 'allmy')); // Limit the result, if no limit applies, use prior result if ($numrows > $list_limit && !isset($_GET['export_all'])) { $query_limit = $query . " LIMIT " . intval($params["start"]) . ", " . intval($list_limit) . " "; $result_limit = $DB->query($query_limit); $numrows_limit = $DB->numrows($result_limit); } else { $numrows_limit = $numrows; $result_limit = $result; } if ($numrows_limit > 0) { // Set display type for export if define $output_type = Search::HTML_OUTPUT; if (isset($_GET["display_type"])) { $output_type = $_GET["display_type"]; } // Pager $parameters = "start=" . $params["start"] . "&knowbaseitemcategories_id=" . $params['knowbaseitemcategories_id'] . "&contains=" . $params["contains"] . "&is_faq=" . $params['faq']; if (isset($options['item_itemtype']) && isset($options['item_items_id'])) { $parameters .= "&item_items_id=" . $options['item_items_id'] . "&item_itemtype=" . $options['item_itemtype']; } if ($output_type == Search::HTML_OUTPUT) { Html::printPager($params['start'], $numrows, Toolbox::getItemTypeSearchURL('KnowbaseItem'), $parameters, 'KnowbaseItem'); } $nbcols = 1; // Display List Header echo Search::showHeader($output_type, $numrows_limit + 1, $nbcols); echo Search::showNewLine($output_type); $header_num = 1; echo Search::showHeaderItem($output_type, __('Subject'), $header_num); if ($output_type != Search::HTML_OUTPUT) { echo Search::showHeaderItem($output_type, __('Content'), $header_num); } if ($showwriter) { echo Search::showHeaderItem($output_type, __('Writer'), $header_num); } echo Search::showHeaderItem($output_type, __('Category'), $header_num); if (isset($options['item_itemtype']) && isset($options['item_items_id']) && $output_type == Search::HTML_OUTPUT) { echo Search::showHeaderItem($output_type, ' ', $header_num); } // Num of the row (1=header_line) $row_num = 1; for ($i = 0; $i < $numrows_limit; $i++) { $data = $DB->fetch_assoc($result_limit); Session::addToNavigateListItems('KnowbaseItem', $data["id"]); // Column num $item_num = 1; $row_num++; echo Search::showNewLine($output_type, $i % 2); $item = new self(); $item->getFromDB($data["id"]); $name = $data["name"]; $answer = $data["answer"]; // Manage translations if (isset($data['transname']) && !empty($data['transname'])) { $name = $data["transname"]; } if (isset($data['transanswer']) && !empty($data['transanswer'])) { $answer = $data["transanswer"]; } if ($output_type == Search::HTML_OUTPUT) { $toadd = ''; if (isset($options['item_itemtype']) && isset($options['item_items_id'])) { $href = " href='#' onClick=\"" . Html::jsGetElementbyID('kbshow' . $data["id"]) . ".dialog('open');\""; $toadd = Ajax::createIframeModalWindow('kbshow' . $data["id"], $CFG_GLPI["root_doc"] . "/front/knowbaseitem.form.php?id=" . $data["id"], array('display' => false)); } else { $href = " href=\"" . $CFG_GLPI['root_doc'] . "/front/knowbaseitem.form.php?id=" . $data["id"] . "\" "; } echo Search::showItem($output_type, "<div class='kb'>{$toadd}<a " . ($data['is_faq'] ? " class='pubfaq' title='" . __("This item is part of the FAQ") . "' " : " class='knowbase' ") . " {$href}>" . Html::resume_text($name, 80) . "</a></div>\n <div class='kb_resume'>" . Html::resume_text(Html::clean(Toolbox::unclean_cross_side_scripting_deep($answer)), 600) . "</div>", $item_num, $row_num); } else { echo Search::showItem($output_type, $name, $item_num, $row_num); echo Search::showItem($output_type, Html::clean(Toolbox::unclean_cross_side_scripting_deep(html_entity_decode($answer, ENT_QUOTES, "UTF-8"))), $item_num, $row_num); } $showuserlink = 0; if (Session::haveRight('user', READ)) { $showuserlink = 1; } if ($showwriter) { echo Search::showItem($output_type, getUserName($data["users_id"], $showuserlink), $item_num, $row_num); } $categ = $data["category"]; if ($output_type == Search::HTML_OUTPUT) { $cathref = $ki->getSearchURL() . "?knowbaseitemcategories_id=" . $data["knowbaseitemcategories_id"] . '&forcetab=Knowbase$2'; $categ = "<a href='{$cathref}'>" . $categ . '</a>'; } echo Search::showItem($output_type, $categ, $item_num, $row_num); if (isset($options['item_itemtype']) && isset($options['item_items_id']) && $output_type == Search::HTML_OUTPUT) { $forcetab = $options['item_itemtype']; if (!$_SESSION['glpiticket_timeline'] || $_SESSION['glpiticket_timeline_keep_replaced_tabs']) { $forcetab .= '$2'; //Solution tab } else { $forcetab .= '$1'; //Timeline tab } $content = "<a href='" . Toolbox::getItemTypeFormURL($options['item_itemtype']) . "?load_kb_sol=" . $data['id'] . "&id=" . $options['item_items_id'] . "&forcetab=" . $forcetab . "'>" . __('Use as a solution') . "</a>"; echo Search::showItem($output_type, $content, $item_num, $row_num); } // End Line echo Search::showEndLine($output_type); } // Display footer if ($output_type == Search::PDF_OUTPUT_LANDSCAPE || $output_type == Search::PDF_OUTPUT_PORTRAIT) { echo Search::showFooter($output_type, Dropdown::getDropdownName("glpi_knowbaseitemcategories", $params['knowbaseitemcategories_id'])); } else { echo Search::showFooter($output_type); } echo "<br>"; if ($output_type == Search::HTML_OUTPUT) { Html::printPager($params['start'], $numrows, Toolbox::getItemTypeSearchURL('KnowbaseItem'), $parameters, 'KnowbaseItem'); } } else { echo "<div class='center b'>" . __('No item found') . "</div>"; } } }
/** * Show holidays for a calendar * * @param $calendar Calendar object **/ static function showForCalendar(Calendar $calendar) { global $DB, $CFG_GLPI; $ID = $calendar->getField('id'); if (!$calendar->can($ID, 'r')) { return false; } $canedit = $calendar->can($ID, 'w'); $rand = mt_rand(); $query = "SELECT DISTINCT `glpi_calendars_holidays`.`id` AS linkID,\n `glpi_holidays`.*\n FROM `glpi_calendars_holidays`\n LEFT JOIN `glpi_holidays`\n ON (`glpi_calendars_holidays`.`holidays_id` = `glpi_holidays`.`id`)\n WHERE `glpi_calendars_holidays`.`calendars_id` = '{$ID}'\n ORDER BY `glpi_holidays`.`name`"; $result = $DB->query($query); $holidays = array(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $holidays[$data['id']] = $data; $used[$data['id']] = $data['id']; } } if ($canedit) { echo "<div class='firstbloc'>"; echo "<form name='calendarsegment_form{$rand}' id='calendarsegment_form{$rand}' method='post'\n action='"; echo Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th colspan='7'>" . __('Add a close time') . "</tr>"; echo "<tr class='tab_bg_2'><td class='right' colspan='4'>"; echo "<input type='hidden' name='calendars_id' value='{$ID}'>"; Holiday::dropdown(array('used' => $used, 'entity' => $calendar->fields["entities_id"])); echo "</td><td class='center'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $numrows) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $paramsma = array('num_displayed' => $numrows); Html::showMassiveActions(__CLASS__, $paramsma); } echo "<table class='tab_cadre_fixehov'>"; echo "<tr>"; if ($canedit && $numrows) { echo "<th width='10'>"; Html::checkAllAsCheckbox('mass' . __CLASS__ . $rand); echo "</th>"; } echo "<th>" . __('Name') . "</th>"; echo "<th>" . __('Start') . "</th>"; echo "<th>" . __('End') . "</th>"; echo "<th>" . __('Recurrent') . "</th>"; echo "</tr>"; $used = array(); if ($numrows) { Session::initNavigateListItems('Holiday', sprintf(__('%1$s = %2$s'), Calendar::getTypeName(1), $calendar->fields["name"])); foreach ($holidays as $data) { Session::addToNavigateListItems('Holiday', $data["id"]); echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td>"; Html::showMassiveActionCheckBox(__CLASS__, $data["linkID"]); echo "</td>"; } echo "<td><a href='" . Toolbox::getItemTypeFormURL('Holiday') . "?id=" . $data['id'] . "'>" . $data["name"] . "</a></td>"; echo "<td>" . Html::convDate($data["begin_date"]) . "</td>"; echo "<td>" . Html::convDate($data["end_date"]) . "</td>"; echo "<td>" . Dropdown::getYesNo($data["is_perpetual"]) . "</td>"; echo "</tr>"; } } echo "</table>"; if ($canedit && $numrows) { $paramsma['ontop'] = false; Html::showMassiveActions(__CLASS__, $paramsma); Html::closeForm(); } echo "</div>"; }
public function showOrderReception($orders_id) { global $DB, $CFG_GLPI; $order_order = new PluginOrderOrder(); $order_item = new PluginOrderOrder_Item(); $reference = new PluginOrderReference(); $order_order->getFromDB($orders_id); Session::initNavigateListItems($this->getType(), __("Order", "order") . " = " . $order_order->fields["name"]); $canedit = self::canCreate() && !$order_order->canUpdateOrder() && !$order_order->isCanceled(); $result_ref = $order_item->queryDetail($orders_id); $numref = $DB->numrows($result_ref); while ($data_ref = $DB->fetch_array($result_ref)) { echo "<div class='center'><table class='tab_cadre_fixe'>"; if (!$numref) { echo "<tr><th>" . __("No item to take delivery of", "order") . "</th></tr></table></div>"; } else { $references_id = $data_ref["id"]; $typeRef = $data_ref["itemtype"]; $price_taxfree = $data_ref["price_taxfree"]; $discount = $data_ref["discount"]; $item = new $typeRef(); $rand = mt_rand(); echo "<tr><th><ul><li>"; echo "<a href=\"javascript:showHideDiv('reception{$rand}','reception_img{$rand}', '" . $CFG_GLPI['root_doc'] . "/pics/plus.png','" . $CFG_GLPI['root_doc'] . "/pics/moins.png');\">"; echo "<img alt='' name='reception_img{$rand}' src=\"" . $CFG_GLPI['root_doc'] . "/pics/plus.png\">"; echo "</a>"; echo "</li></ul></th>"; echo "<th>" . __("Type") . "</th>"; echo "<th>" . __("Manufacturer") . "</th>"; echo "<th>" . __("Product reference", "order") . "</th>"; echo "<th>" . __("Delivered items", "order") . "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1 center'>"; echo "<td></td>"; echo "<td align='center'>" . $item->getTypeName() . "</td>"; echo "<td align='center'>" . Dropdown::getDropdownName("glpi_manufacturers", $data_ref["manufacturers_id"]) . "</td>"; echo "<td>" . $reference->getReceptionReferenceLink($data_ref) . "</td>"; $total = $order_item->getTotalQuantityByRefAndDiscount($orders_id, $references_id, $data_ref["price_taxfree"], $data_ref["discount"]); echo "<td>" . $order_item->getDeliveredQuantity($orders_id, $references_id, $data_ref["price_taxfree"], $data_ref["discount"]) . " / " . $total . "</td>"; echo "</tr></table>"; echo "<div class='center' id='reception{$rand}' style='display:none'>"; echo "<form method='post' name='order_reception_form{$rand}' id='order_reception_form{$rand}'" . " action=\"" . Toolbox::getItemTypeFormURL("PluginOrderReception") . "\">"; echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; echo "<th width='15'></th>"; if ($typeRef != 'SoftwareLicense') { echo "<th>" . __("ID") . "</th>"; } echo "<th>" . __("Reference") . "</th>"; echo "<th>" . __("Status") . "</th>"; echo "<th>" . __("Delivery date") . "</th>"; echo "<th>" . __("Delivery form") . "</th>"; echo "<th>" . __("Delivery status", "order") . "</th>"; echo "</tr>"; $query = "SELECT `glpi_plugin_order_orders_items`.`id` AS IDD,\n `glpi_plugin_order_references`.`id` AS id,\n `glpi_plugin_order_references`.`templates_id`,\n `glpi_plugin_order_orders_items`.`states_id`,\n `glpi_plugin_order_orders_items`.`comment`,\n `glpi_plugin_order_orders_items`.`plugin_order_deliverystates_id`,\n `glpi_plugin_order_orders_items`.`delivery_date`,\n `glpi_plugin_order_orders_items`.`delivery_number`,\n `glpi_plugin_order_references`.`name`,\n `glpi_plugin_order_references`.`itemtype`,\n `glpi_plugin_order_orders_items`.`items_id`\n FROM `glpi_plugin_order_orders_items`, `glpi_plugin_order_references`\n WHERE `plugin_order_orders_id` = '{$orders_id}'\n AND `glpi_plugin_order_orders_items`.`plugin_order_references_id` = '" . $references_id . "'\n AND `glpi_plugin_order_orders_items`.`plugin_order_references_id` = `glpi_plugin_order_references`.`id`\n AND `glpi_plugin_order_orders_items`.`discount` LIKE '" . $discount . "'\n AND `glpi_plugin_order_orders_items`.`price_taxfree` LIKE '" . $price_taxfree . "' "; if ($typeRef == 'SoftwareLicense') { $query .= " GROUP BY `glpi_plugin_order_references`.`name` "; } $query .= " ORDER BY `glpi_plugin_order_references`.`name` "; $result = $DB->query($query); $num = $DB->numrows($result); while ($data = $DB->fetch_array($result)) { $random = mt_rand(); $detailID = $data["IDD"]; Session::addToNavigateListItems($this->getType(), $detailID); echo "<tr class='tab_bg_2'>"; $status = 1; if ($typeRef != 'SoftwareLicense') { $status = $this->checkThisItemStatus($detailID, PluginOrderOrder::ORDER_DEVICE_NOT_DELIVRED); } if ($order_order->canDeliver() && $status) { echo "<td width='15' align='left'>"; $sel = ""; if (isset($_GET["select"]) && $_GET["select"] == "all") { $sel = "checked"; } echo "<input type='checkbox' name='item[" . $detailID . "]' value='1' {$sel}>"; echo "</td>"; } else { echo "<td width='15' align='left'></td>"; } if ($typeRef != 'SoftwareLicense') { echo "<td align='center'>" . $data["IDD"] . " "; Html::showTooltip($data['comment']); echo "</td>"; } echo "<td align='center'>" . $reference->getReceptionReferenceLink($data) . "</td>"; echo "<td align='center'>"; $link = Toolbox::getItemTypeFormURL($this->getType()); if ($canedit && $data["states_id"] == PluginOrderOrder::ORDER_DEVICE_DELIVRED) { echo "<a href=\"" . $link . "?id=" . $data["IDD"] . "\">"; } echo $this->getReceptionStatus($detailID); if ($canedit && $data["states_id"] == PluginOrderOrder::ORDER_DEVICE_DELIVRED) { echo "</a>"; } echo "</td>"; echo "<td align='center'>" . Html::convDate($data["delivery_date"]) . "</td>"; echo "<td align='center'>" . $data["delivery_number"] . "</td>"; echo "<td align='center'>" . Dropdown::getDropdownName("glpi_plugin_order_deliverystates", $data["plugin_order_deliverystates_id"]) . "</td>"; echo "<input type='hidden' name='id[{$detailID}]' value='{$detailID}'>"; echo "<input type='hidden' name='name[{$detailID}]' value='" . $data["name"] . "'>"; echo "<input type='hidden' name='plugin_order_references_id[{$detailID}]' value='" . $data["id"] . "'>"; echo "<input type='hidden' name='itemtype[{$detailID}]' value='" . $data["itemtype"] . "'>"; echo "<input type='hidden' name='templates_id[{$detailID}]' value='" . $data["templates_id"] . "'>"; echo "<input type='hidden' name='states_id[{$detailID}]' value='" . $data["states_id"] . "'>"; } echo "</table>"; if ($order_order->canDeliver() && $this->checkItemStatus($orders_id, $references_id, PluginOrderOrder::ORDER_DEVICE_NOT_DELIVRED)) { Html::openArrowMassives("order_reception_form{$rand}", true); echo "<input type='hidden' name='plugin_order_orders_id' value='{$orders_id}'>"; $this->dropdownReceptionActions($typeRef, $references_id, $orders_id); Html::closeArrowMassives(array()); $rand = mt_rand(); if ($typeRef != 'SoftwareLicense') { echo "<div id='massreception" . $orders_id . $rand . "'></div>\n"; echo "<script type='text/javascript' >\n"; echo "function viewmassreception" . $orders_id . "{$rand}(){\n"; $params = array('plugin_order_orders_id' => $orders_id, 'plugin_order_references_id' => $references_id); Ajax::updateItemJsCode("massreception" . $orders_id . $rand, $CFG_GLPI["root_doc"] . "/plugins/order/ajax/massreception.php", $params, false); echo "};"; echo "</script>\n"; echo "<p><a href='javascript:viewmassreception" . $orders_id . "{$rand}();'>"; echo __("Take item delivery (bulk)", "order") . "</a></p><br>\n"; } } Html::closeForm(); echo "</div>"; } echo "<br>"; } }
/** * Show users of a group * * @since version 0.83 * * @param $group Group object: the group **/ static function showForGroup(Group $group) { global $DB, $CFG_GLPI; $ID = $group->getID(); if (!User::canView() || !$group->can($ID, READ)) { return false; } // Have right to manage members $canedit = self::canUpdate(); $rand = mt_rand(); $user = new User(); $crit = Session::getSavedOption(__CLASS__, 'criterion', ''); $tree = Session::getSavedOption(__CLASS__, 'tree', 0); $used = array(); $ids = array(); // Retrieve member list $entityrestrict = self::getDataForGroup($group, $used, $ids, $crit, $tree); if ($canedit) { self::showAddUserForm($group, $ids, $entityrestrict, $crit); } // Mini Search engine echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th colspan='2'>" . User::getTypeName(Session::getPluralNumber()) . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; echo _n('Criterion', 'Criteria', 1) . " "; $crits = array('' => Dropdown::EMPTY_VALUE, 'is_manager' => __('Manager'), 'is_userdelegate' => __('Delegatee')); Dropdown::showFromArray('crit', $crits, array('value' => $crit, 'on_change' => 'reloadTab("start=0&criterion="+this.value)')); if ($group->haveChildren()) { echo "</td><td class='center'>" . __('Child groups'); Dropdown::showYesNo('tree', $tree, -1, array('on_change' => 'reloadTab("start=0&tree="+this.value)')); } else { $tree = 0; } echo "</td></tr></table>"; $number = count($used); $start = isset($_GET['start']) ? intval($_GET['start']) : 0; if ($start >= $number) { $start = 0; } // Display results if ($number) { echo "<div class='spaced'>"; Html::printAjaxPager(sprintf(__('%1$s (%2$s)'), User::getTypeName(Session::getPluralNumber()), __('D=Dynamic')), $start, $number); Session::initNavigateListItems('User', sprintf(__('%1$s = %2$s'), Group::getTypeName(1), $group->getName())); if ($canedit) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => min($number - $start, $_SESSION['glpilist_limit']), 'container' => 'mass' . __CLASS__ . $rand); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixehov table-striped table-hover'>"; $header_begin = "<tr>"; $header_top = ''; $header_bottom = ''; $header_end = ''; if ($canedit) { $header_begin .= "<th width='10'>"; $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_end .= "</th>"; } $header_end .= "<th>" . User::getTypeName(1) . "</th>"; if ($tree) { $header_end .= "<th>" . Group::getTypeName(1) . "</th>"; } $header_end .= "<th>" . __('Dynamic') . "</th>"; $header_end .= "<th>" . __('Manager') . "</th>"; $header_end .= "<th>" . __('Delegatee') . "</th></tr>"; echo $header_begin . $header_top . $header_end; $tmpgrp = new Group(); for ($i = $start, $j = 0; $i < $number && $j < $_SESSION['glpilist_limit']; $i++, $j++) { $data = $used[$i]; $user->getFromDB($data["id"]); Session::addToNavigateListItems('User', $data["id"]); echo "\n<tr class='tab_bg_" . ($user->isDeleted() ? '1_2' : '1') . "'>"; if ($canedit) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["linkID"]); echo "</td>"; } echo "<td>" . $user->getLink(); if ($tree) { echo "</td><td>"; if ($tmpgrp->getFromDB($data['groups_id'])) { echo $tmpgrp->getLink(array('comments' => true)); } } echo "</td><td class='center'>"; if ($data['is_dynamic']) { echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' width='14' height='14' alt=\"" . __('Dynamic') . "\">"; } echo "</td><td class='center'>"; if ($data['is_manager']) { echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' width='14' height='14' alt=\"" . __('Manager') . "\">"; } echo "</td><td class='center'>"; if ($data['is_userdelegate']) { echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' width='14' height='14' alt=\"" . __('Delegatee') . "\">"; } echo "</tr>"; } echo $header_begin . $header_bottom . $header_end; echo "</table>"; if ($canedit) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } Html::printAjaxPager(sprintf(__('%1$s (%2$s)'), User::getTypeName(Session::getPluralNumber()), __('D=Dynamic')), $start, $number); echo "</div>"; } else { echo "<p class='center b'>" . __('No item found') . "</p>"; } }
public static function showOrderSupplierInfos($ID) { //TODO : en cours global $DB; $order = new PluginOrderOrder(); $order->getFromDB($ID); $suppliers_id = $order->fields["suppliers_id"]; Session::initNavigateListItems(__CLASS__, __("Order", "order") . " = " . $order->fields["name"]); $candelete = $order->can($ID, UPDATE); $rand = mt_rand(); $link = Toolbox::getItemTypeFormURL(__CLASS__); echo "<form method='post' name='show_supplierinfos{$rand}' id='show_supplierinfos{$rand}' " . "action=\"" . $link . "\">"; echo "<div class='center'>"; echo "<input type='hidden' name='plugin_order_orders_id' value='" . $ID . "'>"; $table = getTableForItemType(__CLASS__); $nb_elements = countElementsInTable($table, "`plugin_order_orders_id` = '{$ID}'"); if ($nb_elements > 0) { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='4'>" . __("Supplier Detail", "order") . "</th></tr>"; echo "<tr>"; echo "<th> </th>"; echo "<th>" . __("Supplier") . "</th>"; echo "<th>" . __("Quote number", "order") . "</th>"; echo "<th>" . __("Order number") . "</th>"; echo "</tr>"; $datas = getAllDatasFromTable($table, "`plugin_order_orders_id` = '{$ID}'"); foreach ($datas as $data) { Session::addToNavigateListItems(__CLASS__, $data['id']); echo "<input type='hidden' name='item[" . $data["id"] . "]' value='" . $ID . "'>"; echo "<tr class='tab_bg_1 center'>"; echo "<td>"; if ($candelete) { echo "<input type='checkbox' name='check[" . $data["id"] . "]'"; if (isset($_POST['check']) && $_POST['check'] == 'all') { echo " checked "; } echo ">"; } echo "</td>"; echo "<td><a href='" . $link . "?id=" . $data["id"] . "&plugin_order_orders_id=" . $ID . "'>" . Dropdown::getDropdownName("glpi_suppliers", $data["suppliers_id"]) . "</a></td>"; echo "<td>" . $data["num_quote"] . "</td>"; echo "<td>" . $data["num_order"] . "</td>"; echo "</tr>"; } echo "</table></div>"; if ($candelete) { Html::openArrowMassives("show_supplierinfos{$rand}", true); Html::closeArrowMassives(array('delete' => __("Delete permanently"))); } } Html::closeForm(); }
static function showForItem(CommonGLPI $item, $withtemplate = 0) { global $CFG_GLPI; $is_device = $item instanceof CommonDevice; $ID = $item->getField('id'); if (!$item->can($ID, READ)) { return false; } $canedit = $withtemplate != 2 && $item->canEdit($ID) && Session::haveRightsOr('device', array(UPDATE, PURGE)); echo "<div class='spaced'>"; $rand = mt_rand(); if ($canedit) { echo "\n<form id='form_device_add{$rand}' name='form_device_add{$rand}'\n action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "' method='post'>\n"; echo "\t<input type='hidden' name='items_id' value='{$ID}'>\n"; echo "\t<input type='hidden' name='itemtype' value='" . $item->getType() . "'>\n"; } $table = new HTMLTableMain(); $table->setTitle(_n('Component', 'Components', Session::getPluralNumber())); if ($canedit) { $delete_all_column = $table->addHeader('delete all', Html::getCheckAllAsCheckbox("form_device_action{$rand}", '__RAND__')); $delete_all_column->setHTMLClass('center'); } else { $delete_all_column = NULL; } $column_label = $is_device ? _n('Item', 'Items', Session::getPluralNumber()) : __('Type of component'); $common_column = $table->addHeader('common', $column_label); $specific_column = $table->addHeader('specificities', __('Specificities')); $specific_column->setHTMLClass('center'); $dynamic_column = ''; if ($item->isDynamic()) { $dynamic_column = $table->addHeader('is_dynamic', __('Automatic inventory')); $dynamic_column->setHTMLClass('center'); } if ($canedit) { $massiveactionparams = array('container' => "form_device_action{$rand}", 'fixed' => false, 'display_arrow' => false); $content = array(array('function' => 'Html::showMassiveActions', 'parameters' => array($massiveactionparams))); $delete_column = $table->addHeader('delete one', $content); $delete_column->setHTMLClass('center'); } else { $delete_column = NULL; } $table_options = array('canedit' => $canedit, 'rand' => $rand); if ($is_device) { Session::initNavigateListItems(static::getType(), sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach (array_merge(array(''), self::getConcernedItems()) as $itemtype) { $table_options['itemtype'] = $itemtype; $link = getItemForItemtype(static::getType()); $link->getTableGroup($item, $table, $table_options, $delete_all_column, $common_column, $specific_column, $delete_column, $dynamic_column); } } else { $devtypes = array(); foreach (self::getItemAffinities($item->getType()) as $link_type) { $devtypes[] = $link_type::getDeviceType(); $link = getItemForItemtype($link_type); Session::initNavigateListItems($link_type, sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); $link->getTableGroup($item, $table, $table_options, $delete_all_column, $common_column, $specific_column, $delete_column, $dynamic_column); } } if ($canedit) { echo "<table class='tab_cadre_fixe'><tr class='tab_bg_1'><td>"; echo __('Add a new component') . "</td><td class=left width='70%'>"; if ($is_device) { Dropdown::showNumber('number_devices_to_add', array('value' => 0, 'min' => 0, 'max' => 10)); } else { Dropdown::showSelectItemFromItemtypes(array('itemtype_name' => 'devicetype', 'items_id_name' => 'devices_id', 'itemtypes' => $devtypes, 'entity_restrict' => $item->getEntityID(), 'showItemSpecificity' => $CFG_GLPI['root_doc'] . '/ajax/selectUnaffectedOrNewItem_Device.php')); } echo "</td><td>"; echo "<input type='submit' class='submit' name='add' value='" . _sx('button', 'Add') . "'>"; echo "</td></tr></table>"; Html::closeForm(); } if ($canedit) { echo "\n<form id='form_device_action{$rand}' name='form_device_action{$rand}'\n action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "' method='post'>\n"; echo "\t<input type='hidden' name='items_id' value='{$ID}'>\n"; echo "\t<input type='hidden' name='itemtype' value='" . $item->getType() . "'>\n"; } $table->display(array('display_super_for_each_group' => false, 'display_title_for_each_group' => false)); if ($canedit) { // echo "<input type='submit' class='submit' name='updateall' value='" . // _sx('button', 'Save')."'>"; Html::closeForm(); } echo "</div>"; // Force disable selected items $_SESSION['glpimassiveactionselected'] = array(); }
/** * \brief Show names for an item from its form * Beware that the rendering can be different if readden from direct item form (ie : add new * NetworkName, remove, ...) or if readden from item of the item (for instance from the computer * form through NetworkPort::ShowForItem). * * @param $item CommonGLPI object * @param $withtemplate integer withtemplate param (default 0) **/ static function showForItem(CommonDBTM $item, $withtemplate = 0) { global $DB, $CFG_GLPI; $ID = $item->getID(); if (!$item->can($ID, READ)) { return false; } $rand = mt_rand(); if ($item->getType() == 'NetworkPort' && Session::haveRight('internet', UPDATE) && $item->canUpdateItem()) { $items_id = $item->getID(); $itemtype = $item->getType(); echo "<div class='firstbloc'>\n"; echo "<form method='post' action='" . static::getFormURL() . "'>\n"; echo "<table class='tab_cadre_fixe'>\n"; echo "<tr><th colspan='4'>" . __('Add a network name') . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='right'>"; echo "<input type='hidden' name='items_id' value='{$items_id}'>\n"; echo "<input type='hidden' name='itemtype' value='{$itemtype}'>\n"; _e('Not associated'); echo "</td><td class='left'>"; self::dropdown(array('name' => 'addressID', 'condition' => '`items_id`=0')); echo "</td><td class='left'>"; echo "<input type='submit' name='assign_address' value='" . _sx('button', 'Associate') . "' class='submit'>"; echo "</td>"; if (static::canCreate()) { echo "<td class='right' width='30%'>"; echo "<a href=\"" . static::getFormURL() . "?items_id={$items_id}&itemtype={$itemtype}\">"; echo __('Create a new network name') . "</a>"; echo "</td>"; } echo "</tr>\n"; echo "</table>\n"; Html::closeForm(); echo "</div>\n"; } $table_options = array('createRow' => true); if ($item->getType() == 'FQDN' || $item->getType() == 'NetworkEquipment') { if (isset($_GET["start"])) { $start = $_GET["start"]; } else { $start = 0; } if (!empty($_GET["order"])) { $table_options['order'] = $_GET["order"]; } else { $table_options['order'] = 'name'; } if ($item->getType() == 'FQDN') { $table_options['column_links'] = array('NetworkName' => 'javascript:reloadTab("order=name");', 'NetworkAlias' => 'javascript:reloadTab("order=alias");', 'IPAddress' => 'javascript:reloadTab("order=ip");'); } $table_options['SQL_options'] = "LIMIT " . $_SESSION['glpilist_limit'] . "\n OFFSET {$start}"; $canedit = false; } else { $canedit = Session::haveRight('internet', UPDATE) && $item->canUpdateItem(); } $table_options['canedit'] = false; $table_options['rand'] = $rand; $table_options['massiveactionnetworkname'] = $canedit; $table = new HTMLTableMain(); $column = $table->addHeader('Internet', self::getTypeName(Session::getPluralNumber())); $t_group = $table->createGroup('Main', ''); self::getHTMLTableHeader(__CLASS__, $t_group, $column, NULL, $table_options); $t_row = $t_group->createRow(); self::getHTMLTableCellsForItem($t_row, $item, NULL, $table_options); if ($table->getNumberOfRows() > 0) { $number = $table->getNumberOfRows(); if ($item->getType() == 'FQDN') { $number = min($_SESSION['glpilist_limit'], $table->getNumberOfRows()); Html::printAjaxPager(self::getTypeName(Session::getPluralNumber()), $start, self::countForItem($item)); } Session::initNavigateListItems(__CLASS__, sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); if ($canedit && $number) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $number, 'container' => 'mass' . __CLASS__ . $rand); Html::showMassiveActions($massiveactionparams); } $table->display(array('display_title_for_each_group' => false, 'display_thead' => false, 'display_tfoot' => false, 'display_header_on_foot_for_each_group' => true)); if ($canedit && $number) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } if ($item->getType() == 'FQDN') { Html::printAjaxPager(self::getTypeName(Session::getPluralNumber()), $start, self::countForItem($item)); } } else { echo "<table class='tab_cadre_fixe'><tr><th>" . __('No network name found') . "</th></tr>"; echo "</table>"; } }
/** * @param $template NotificationTemplate object * @param $options array **/ function showSummary(NotificationTemplate $template, $options = array()) { global $DB, $CFG_GLPI; $nID = $template->getField('id'); $canedit = Config::canUpdate(); if ($canedit) { echo "<div class='center'>" . "<a class='vsubmit' href='" . Toolbox::getItemTypeFormURL('NotificationTemplateTranslation') . "?notificationtemplates_id=" . $nID . "'>" . __('Add a new translation') . "</a></div><br>"; } echo "<div class='center' id='tabsbody'>"; Session::initNavigateListItems('NotificationTemplateTranslation', sprintf(__('%1$s = %2$s'), NotificationTemplate::getTypeName(1), $template->getName())); if ($canedit) { $rand = mt_rand(); Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('container' => 'mass' . __CLASS__ . $rand); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<th width='10'>"; Html::checkAllAsCheckbox('mass' . __CLASS__ . $rand); echo "</th>"; } echo "<th>" . __('Language') . "</th></tr>"; foreach ($DB->request('glpi_notificationtemplatetranslations', array('notificationtemplates_id' => $nID)) as $data) { if ($this->getFromDB($data['id'])) { Session::addToNavigateListItems('NotificationTemplateTranslation', $data['id']); echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td class='center'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["id"]); echo "</td>"; } echo "<td class='center'>"; echo "<a href='" . Toolbox::getItemTypeFormURL('NotificationTemplateTranslation') . "?id=" . $data['id'] . "&notificationtemplates_id=" . $nID . "'>"; if ($data['language'] != '') { echo $CFG_GLPI['languages'][$data['language']][0]; } else { _e('Default translation'); } echo "</a></td></tr>"; } } echo "</table>"; if ($canedit) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * Show Versions of a software * * @param $soft Software object * * @return nothing **/ static function showForSoftware(Software $soft) { global $DB, $CFG_GLPI; $softwares_id = $soft->getField('id'); if (!$soft->can($softwares_id, READ)) { return false; } $canedit = $soft->canEdit($softwares_id); echo "<div class='spaced'>"; if ($canedit) { echo "<div class='center firstbloc'>"; echo "<a class='vsubmit' href='softwareversion.form.php?softwares_id={$softwares_id}'>" . _x('button', 'Add a version') . "</a>"; echo "</div>"; } $query = "SELECT `glpi_softwareversions`.*,\n `glpi_states`.`name` AS sname\n FROM `glpi_softwareversions`\n LEFT JOIN `glpi_states` ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`)\n WHERE `softwares_id` = '{$softwares_id}'\n ORDER BY `name`"; Session::initNavigateListItems('SoftwareVersion', sprintf(__('%1$s = %2$s'), Software::getTypeName(1), $soft->getName())); if ($result = $DB->query($query)) { if ($DB->numrows($result)) { echo "<table class='tab_cadre_fixehov'><tr>"; echo "<th>" . self::getTypeName(Session::getPluralNumber()) . "</th>"; echo "<th>" . __('Status') . "</th>"; echo "<th>" . __('Operating system') . "</th>"; echo "<th>" . _n('Installation', 'Installations', Session::getPluralNumber()) . "</th>"; echo "<th>" . __('Comments') . "</th>"; echo "</tr>\n"; for ($tot = $nb = 0; $data = $DB->fetch_assoc($result); $tot += $nb) { Session::addToNavigateListItems('SoftwareVersion', $data['id']); $nb = Computer_SoftwareVersion::countForVersion($data['id']); echo "<tr class='tab_bg_2'>"; echo "<td><a href='softwareversion.form.php?id=" . $data['id'] . "'>"; echo $data['name'] . (empty($data['name']) ? "(" . $data['id'] . ")" : "") . "</a></td>"; echo "<td>" . $data['sname'] . "</td>"; echo "<td class='right'>" . Dropdown::getDropdownName('glpi_operatingsystems', $data['operatingsystems_id']); echo "</td>"; echo "<td class='numeric'>{$nb}</td>"; echo "<td>" . $data['comment'] . "</td></tr>\n"; } echo "<tr class='tab_bg_1 noHover'><td class='right b' colspan='3'>" . __('Total') . "</td>"; echo "<td class='numeric b'>{$tot}</td><td></td></tr>"; echo "</table>\n"; } else { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('No item found') . "</th></tr>"; echo "</table>\n"; } } echo "</div>"; }
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); } } }
/** * Print the HTML array of the Netpoint associated to a Location * * @param $item Location * * @return Nothing (display) **/ static function showForLocation($item) { global $DB, $CFG_GLPI; $ID = $item->getField('id'); $netpoint = new self(); $item->check($ID, READ); $canedit = $item->canEdit($ID); if (isset($_GET["start"])) { $start = intval($_GET["start"]); } else { $start = 0; } $number = countElementsInTable('glpi_netpoints', "`locations_id`='{$ID}'"); if ($canedit) { echo "<div class='first-bloc'>"; // Minimal form for quick input. echo "<form action='" . $netpoint->getFormURL() . "' method='post'>"; echo "<br><table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2 center'>"; echo "<td class='b'>" . _n('Network outlet', 'Network outlets', 1) . "</td>"; echo "<td>" . __('Name') . "</td><td>"; Html::autocompletionTextField($item, "name", array('value' => '')); echo "<input type='hidden' name='entities_id' value='" . $_SESSION['glpiactive_entity'] . "'>"; echo "<input type='hidden' name='locations_id' value='{$ID}'></td>"; echo "<td><input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>\n"; echo "</table>\n"; Html::closeForm(); // Minimal form for massive input. echo "<form action='" . $netpoint->getFormURL() . "' method='post'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2 center'>"; echo "<td class='b'>" . _n('Network outlet', 'Network outlets', Session::getPluralNumber()) . "</td>"; echo "<td>" . __('Name') . "</td><td>"; echo "<input type='text' maxlength='100' size='10' name='_before'> "; Dropdown::showNumber('_from', array('value' => 0, 'min' => 0, 'max' => 400)); echo " --> "; Dropdown::showNumber('_to', array('value' => 0, 'min' => 0, 'max' => 400)); echo " <input type='text' maxlength='100' size='10' name='_after'><br>"; echo "<input type='hidden' name='entities_id' value='" . $_SESSION['glpiactive_entity'] . "'>"; echo "<input type='hidden' name='locations_id' value='{$ID}'>"; echo "<input type='hidden' name='_method' value='AddMulti'></td>"; echo "<td><input type='submit' name='execute' value=\"" . _sx('button', 'Add') . "\"\n class='submit'>"; echo "</td></tr>\n"; echo "</table>\n"; Html::closeForm(); echo "</div>"; } echo "<div class='spaced'>"; if ($number < 1) { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . self::getTypeName(1) . "</th>"; echo "<th>" . __('No item found') . "</th></tr>"; echo "</table>\n"; } else { Html::printAjaxPager(sprintf(__('Network outlets for %s'), $item->getTreeLink()), $start, $number); if ($canedit) { $rand = mt_rand(); Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $_SESSION['glpilist_limit'], 'container' => 'mass' . __CLASS__ . $rand, 'specific_actions' => array('purge' => _x('button', 'Delete permanently'))); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixe'><tr>"; if ($canedit) { echo "<th width='10'>"; Html::checkAllAsCheckbox('mass' . __CLASS__ . $rand); echo "</th>"; } echo "<th>" . __('Name') . "</th>"; // Name echo "<th>" . __('Comments') . "</th>"; // Comment echo "</tr>\n"; $crit = array('locations_id' => $ID, 'ORDER' => 'name', 'START' => $start, 'LIMIT' => $_SESSION['glpilist_limit']); Session::initNavigateListItems('Netpoint', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($DB->request('glpi_netpoints', $crit) as $data) { Session::addToNavigateListItems('Netpoint', $data["id"]); echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>"; } echo "<td><a href='" . $netpoint->getFormURL(); echo '?id=' . $data['id'] . "'>" . $data['name'] . "</a></td>"; echo "<td>" . $data['comment'] . "</td>"; echo "</tr>\n"; } echo "</table>\n"; if ($canedit) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } Html::printAjaxPager(sprintf(__('Network outlets for %s'), $item->getTreeLink()), $start, $number); } echo "</div>\n"; }
/** * Print the contract costs * * @param $contract Contract object * @param $withtemplate boolean Template or basic item (default '') * * @return Nothing (call to classes members) **/ static function showForContract(Contract $contract, $withtemplate = '') { global $DB, $CFG_GLPI; $ID = $contract->fields['id']; if (!$contract->getFromDB($ID) || !$contract->can($ID, READ)) { return false; } $canedit = $contract->can($ID, UPDATE); echo "<div class='center'>"; $query = "SELECT *\n FROM `glpi_contractcosts`\n WHERE `contracts_id` = '{$ID}'\n ORDER BY `begin_date`"; $rand = mt_rand(); if ($canedit) { echo "<div id='viewcost" . $ID . "_{$rand}'></div>\n"; echo "<script type='text/javascript' >\n"; echo "function viewAddCost" . $ID . "_{$rand}() {\n"; $params = array('type' => __CLASS__, 'parenttype' => 'Contract', 'contracts_id' => $ID, 'id' => -1); Ajax::updateItemJsCode("viewcost" . $ID . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params); echo "};"; echo "</script>\n"; echo "<div class='center firstbloc'>" . "<a class='vsubmit' href='javascript:viewAddCost" . $ID . "_{$rand}();'>"; echo __('Add a new cost') . "</a></div>\n"; } if ($result = $DB->query($query)) { echo "<table class='tab_cadre_fixehov'>"; echo "<tr><th colspan='5'>" . self::getTypeName($DB->numrows($result)) . "</th></tr>"; if ($DB->numrows($result)) { echo "<tr><th>" . __('Name') . "</th>"; echo "<th>" . __('Begin date') . "</th>"; echo "<th>" . __('End date') . "</th>"; echo "<th>" . __('Budget') . "</th>"; echo "<th>" . __('Cost') . "</th>"; echo "</tr>"; Session::initNavigateListItems(__CLASS__, sprintf(__('%1$s = %2$s'), Contract::getTypeName(1), $contract->getName())); $total = 0; while ($data = $DB->fetch_assoc($result)) { echo "<tr class='tab_bg_2' " . ($canedit ? "style='cursor:pointer' onClick=\"viewEditCost" . $data['contracts_id'] . "_" . $data['id'] . "_{$rand}();\"" : '') . ">"; $name = empty($data['name']) ? sprintf(__('%1$s (%2$s)'), $data['name'], $data['id']) : $data['name']; echo "<td>"; printf(__('%1$s %2$s'), $name, Html::showToolTip($data['comment'], array('display' => false))); if ($canedit) { echo "\n<script type='text/javascript' >\n"; echo "function viewEditCost" . $data['contracts_id'] . "_" . $data["id"] . "_{$rand}() {\n"; $params = array('type' => __CLASS__, 'parenttype' => 'Contract', 'contracts_id' => $data["contracts_id"], 'id' => $data["id"]); Ajax::updateItemJsCode("viewcost" . $ID . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params); echo "};"; echo "</script>\n"; } echo "</td>"; echo "<td>" . Html::convDate($data['begin_date']) . "</td>"; echo "<td>" . Html::convDate($data['end_date']) . "</td>"; echo "<td>" . Dropdown::getDropdownName('glpi_budgets', $data['budgets_id']) . "</td>"; echo "<td class='numeric'>" . Html::formatNumber($data['cost']) . "</td>"; $total += $data['cost']; echo "</tr>"; Session::addToNavigateListItems(__CLASS__, $data['id']); } echo "<tr class='b noHover'><td colspan='3'> </td>"; echo "<td class='right'>" . __('Total cost') . '</td>'; echo "<td class='numeric'>" . Html::formatNumber($total) . '</td></tr>'; } else { echo "<tr><th colspan='5'>" . __('No item found') . "</th></tr>"; } echo "</table>"; } echo "</div><br>"; }
/** * Display the table itself * * @param $params array of possible options: * 'html_id' the global HTML ID of the table * 'display_thead' display the header before the first group * 'display_tfoot' display the header at the end of the table * 'display_header_for_each_group' display the header of each group * 'display_super_for_each_group' display the super header befor each group * 'display_title_for_each_group' display the title of each group * * @return nothing (display only) **/ function display(array $params) { $p['html_id'] = ''; $p['display_thead'] = true; $p['display_tfoot'] = true; foreach ($params as $key => $val) { $p[$key] = $val; } foreach ($this->groups as $group) { $group->prepareDisplay(); } $totalNumberOfRow = $this->getNumberOfRows(); $totalNumberOfColumn = 0; foreach ($this->getHeaders() as $header) { $colspan = $header['']->getColSpan(); $totalNumberOfColumn += $colspan; } foreach ($this->itemtypes as $itemtype => $title) { Session::initNavigateListItems($itemtype, $title); } echo "\n<table class='tab_cadre_fixe'"; if (!empty($p['html_id'])) { echo " id='" . $p['html_id'] . "'"; } echo ">\n"; $open_thead = !empty($this->title) || $p['display_thead']; if ($open_thead) { echo "\t<thead>\n"; } if (!empty($this->title)) { echo "\t\t<tr><th colspan='{$totalNumberOfColumn}'>" . $this->title . "</th></tr>\n"; } if ($totalNumberOfRow == 0) { if ($open_thead) { echo "\t</thead>\n"; } echo "\t\t<tr class='tab_bg_1'>" . "<td class='center' colspan='{$totalNumberOfColumn}'>" . __('None') . "</td></tr>\n"; } else { if ($p['display_thead']) { $this->displaySuperHeader(); } if ($open_thead) { echo "\t</thead>\n"; } if ($p['display_tfoot']) { echo "\t<tfoot>\n"; $this->displaySuperHeader(); echo "\t</tfoot>\n"; } foreach ($this->groups as $group) { $group->displayGroup($totalNumberOfColumn, $p); } } echo "</table>\n"; }
/** * Print the computers disks * * @param $comp Computer object * * @return Nothing (call to classes members) **/ static function showForComputer(Computer $comp) { global $DB; $ID = $comp->fields['id']; if (!$comp->getFromDB($ID) || !$comp->can($ID, "r")) { return false; } $canedit = $comp->can($ID, "w"); echo "<div class='spaced center'>"; $virtualmachines = getAllDatasFromTable('glpi_computervirtualmachines', "`computers_id` = '{$ID}' AND `is_deleted` = '0'"); echo "<table class='tab_cadre_fixe'>"; Session::initNavigateListItems('ComputerVirtualMachine', sprintf(__('%1$s = %2$s'), __('Computer'), empty($comp->fields['name']) ? "({$ID})" : $comp->fields['name'])); if (empty($virtualmachines)) { echo "<tr><th>" . __('No virtual machine associated with the computer') . "</th></tr>"; } else { echo "<tr><th colspan='10'>" . __('List of virtual machines') . "</th></tr>"; echo "<tr><th>" . __('Name') . "</th>"; if (Plugin::haveImport()) { echo "<th>" . __('Automatic inventory') . "</th>"; } echo "<th>" . __('Virtualization system') . "</th>"; echo "<th>" . __('Virtualization model') . "</th>"; echo "<th>" . __('State of the virtual machine') . "</th>"; echo "<th>" . __('UUID') . "</th>"; echo "<th>" . _x('quantity', 'Processors number') . "</th>"; echo "<th>" . sprintf(__('%1$s (%2$s)'), __('Memory'), __('Mio')) . "</th>"; echo "<th>" . __('Machine') . "</th>"; echo "</tr>"; $vm = new self(); foreach ($virtualmachines as $virtualmachine) { $vm->getFromDB($virtualmachine['id']); echo "<tr class='tab_bg_2'>"; echo "<td>" . $vm->getLink() . "</td>"; if (Plugin::haveImport()) { echo "<td>"; echo Dropdown::getYesNo($vm->isDynamic()); echo "</td>"; } echo "<td>"; echo Dropdown::getDropdownName('glpi_virtualmachinetypes', $virtualmachine['virtualmachinetypes_id']); echo "</td>"; echo "<td>"; echo Dropdown::getDropdownName('glpi_virtualmachinesystems', $virtualmachine['virtualmachinesystems_id']); echo "</td>"; echo "<td>"; echo Dropdown::getDropdownName('glpi_virtualmachinestates', $virtualmachine['virtualmachinestates_id']); echo "</td>"; echo "<td>" . $virtualmachine['uuid'] . "</a></td>"; echo "<td>" . $virtualmachine['vcpu'] . "</td>"; echo "<td>" . $virtualmachine['ram'] . "</td>"; echo "<td>"; if ($link_computer = self::findVirtualMachine($virtualmachine)) { $computer = new Computer(); if ($computer->can($link_computer, 'r')) { $url = "<a href='computer.form.php?id=" . $link_computer . "'>"; $url .= $computer->fields["name"] . "</a>"; $tooltip = "<table><tr><td>" . __('Name') . "</td><td>" . $computer->fields['name'] . '</td></tr>'; $tooltip .= "<tr><td>" . __('Serial number') . "</td><td>" . $computer->fields['serial'] . '</td></tr>'; $tooltip .= "<tr><td>" . __('Comments') . "</td><td>" . $computer->fields['comment'] . '</td></tr></table>'; $url .= " " . Html::showToolTip($tooltip, array('display' => false)); } else { $url = $computer->fields['name']; } echo $url; } echo "</td>"; echo "</tr>"; Session::addToNavigateListItems('ComputerVirtualMachine', $virtualmachine['id']); } } if ($canedit) { echo "<tr class='tab_bg_1'><td colspan='8' class='center'>"; echo "<a class='vsubmit' href='computervirtualmachine.form.php?computers_id={$ID}'>" . __('Add a virtual machine') . "</a></td></tr>"; } echo "</table>"; echo "</div>"; }
static function showForItem(CommonGLPI $item, $withtemplate = 0) { global $DB, $CFG_GLPI; if ($item->getType() == 'IPNetwork') { if (isset($_GET["start"])) { $start = $_GET["start"]; } else { $start = 0; } if (!empty($_GET["order"])) { $table_options['order'] = $_GET["order"]; } else { $table_options['order'] = 'ip'; } $order_by_itemtype = $table_options['order'] == 'itemtype'; $table_options['SQL_options'] = "LIMIT " . $_SESSION['glpilist_limit'] . "\n OFFSET {$start}"; $table = new HTMLTableMain(); $content = "<a href='javascript:reloadTab(\"order=ip\");'>" . self::getTypeName(Session::getPluralNumber()) . "</a>"; $internet_column = $table->addHeader('IP Address', $content); $content = sprintf(__('%1$s - %2$s'), _n('Item', 'Items', Session::getPluralNumber()), "<a href='javascript:reloadTab(\"order=itemtype\");'>" . __('Order by item type') . "</a>"); $item_column = $table->addHeader('Item', $content); if ($order_by_itemtype) { foreach ($CFG_GLPI["networkport_types"] as $itemtype) { $table_options['group_' . $itemtype] = $table->createGroup($itemtype, $itemtype::getTypeName(Session::getPluralNumber())); self::getHTMLTableHeader($item->getType(), $table_options['group_' . $itemtype], $item_column, NULL, $table_options); } } $table_options['group_None'] = $table->createGroup('Main', __('Other kind of items')); self::getHTMLTableHeader($item->getType(), $table_options['group_None'], $item_column, NULL, $table_options); self::getHTMLTableCellsForItem(NULL, $item, NULL, $table_options); if ($table->getNumberOfRows() > 0) { Html::printAjaxPager(self::getTypeName(Session::getPluralNumber()), $start, self::countForItem($item)); Session::initNavigateListItems(__CLASS__, sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); $table->display(array('display_title_for_each_group' => $order_by_itemtype, 'display_super_for_each_group' => false, 'display_tfoot' => false)); Html::printAjaxPager(self::getTypeName(Session::getPluralNumber()), $start, self::countForItem($item)); } else { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('No IP address found') . "</th></tr>"; echo "</table>"; } } }
/** * Show ports for an item * * @param $item CommonDBTM object * @param $withtemplate integer withtemplate param (default '') **/ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI; $rand = mt_rand(); $itemtype = $item->getType(); $items_id = $item->getField('id'); if (!Session::haveRight('networking', 'r') || !$item->can($items_id, 'r')) { return false; } $netport = new self(); $netport->item = $item; if ($itemtype == 'NetworkPort') { $canedit = false; } else { $canedit = $item->can($items_id, 'w'); } $showmassiveactions = false; if ($withtemplate != 2) { $showmassiveactions = $canedit; } // Show Add Form if ($canedit && (empty($withtemplate) || $withtemplate != 2)) { echo "\n<form method='get' action='" . $netport->getFormURL() . "'>\n"; echo "<input type='hidden' name='items_id' value='" . $item->getID() . "'>\n"; echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>\n"; echo "<div class='firstbloc'><table class='tab_cadre_fixe'>\n"; echo "<tr class='tab_bg_2'><td class='center'>\n"; _e('Network port type to be added'); echo " "; $instantiations = array(); foreach (self::getNetworkPortInstantiations() as $inst_type) { if (call_user_func(array($inst_type, 'canCreate'))) { $instantiations[$inst_type] = call_user_func(array($inst_type, 'getTypeName')); } } Dropdown::showFromArray('instantiation_type', $instantiations, array('value' => 'NetworkPortEthernet')); echo "</td>\n"; echo "<td class='tab_bg_2 center' width='50%'>"; _e('Add several ports'); echo " <input type='checkbox' name='several' value='1'></td>\n"; echo "<td>\n"; echo "<input type='submit' name='create' value=\"" . _sx('button', 'Add') . "\" class='submit'>\n"; echo "</td></tr></table></div>\n"; Html::closeForm(); } if ($showmassiveactions) { $checkbox_column = true; Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); } else { $checkbox_column = false; } $is_active_network_port = false; Session::initNavigateListItems('NetworkPort', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); if ($itemtype == 'NetworkPort') { $porttypes = array('NetworkPortAlias', 'NetworkPortAggregate'); } else { $porttypes = self::getNetworkPortInstantiations(); // Manage NetworkportMigration $porttypes[] = ''; } $display_options = self::getDisplayOptions($itemtype); $table = new HTMLTableMain(); $number_port = self::countForItem($item); $table_options = array('canedit' => $canedit, 'display_options' => &$display_options); // Make table name and add the correct show/hide parameters $table_name = sprintf(__('%1$s: %2$d'), self::getTypeName($number_port), $number_port); // Add the link to the popup to display the options ... $table_namelink = self::getDisplayOptionsLink($itemtype); $table_name = sprintf(__('%1$s - %2$s'), $table_name, $table_namelink); $table->setTitle($table_name); $c_main = $table->addHeader('main', self::getTypeName(2)); if ($display_options['dynamic_import'] && $item->isDynamic()) { $table_options['display_isDynamic'] = true; } else { $table_options['display_isDynamic'] = false; } if ($display_options['characteristics']) { $c_instant = $table->addHeader('Instantiation', __('Characteristics')); $c_instant->setHTMLClass('center'); } if ($display_options['internet']) { $options = array('names' => 'NetworkName', 'aliases' => 'NetworkAlias', 'ipaddresses' => 'IPAddress', 'ipnetworks' => 'IPNetwork'); $table_options['dont_display'] = array(); foreach ($options as $option => $itemtype_for_option) { if (!$display_options[$option]) { $table_options['dont_display'][$itemtype_for_option] = true; } } $c_network = $table->addHeader('Internet', _n(__('Internet information'), __('Internet information'), 2)); $c_network->setHTMLClass('center'); } else { $c_network = NULL; } foreach ($porttypes as $portType) { if (empty($portType)) { $group_name = 'Migration'; $group_title = __('Network ports waiting for manual migration'); } else { $group_name = $portType; $group_title = $portType::getTypeName(2); } $t_group = $table->createGroup($group_name, $group_title); if ($withtemplate != 2 && $canedit) { $c_checkbox = $t_group->addHeader('checkbox', Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand, '__RAND__'), $c_main); } else { $c_checkbox = NULL; } $c_number = $t_group->addHeader('NetworkPort', "#", $c_main); $c_name = $t_group->addHeader("Name", __('Name'), $c_main); $c_name->setItemType('NetworkPort'); $c_name->setHTMLClass('center'); if ($table_options['display_isDynamic']) { $c_dynamic = $t_group->addHeader("Dynamic", __('Automatic inventory'), $c_main); $c_dynamic->setHTMLClass('center'); } if ($display_options['characteristics']) { if (empty($portType)) { NetworkPortMigration::getMigrationInstantiationHTMLTableHeaders($t_group, $c_instant, $c_network, NULL, $table_options); } else { $instantiation = new $portType(); $instantiation->getInstantiationHTMLTableHeaders($t_group, $c_instant, $c_network, NULL, $table_options); unset($instantiation); } } if ($display_options['internet'] && !$display_options['characteristics']) { NetworkName::getHTMLTableHeader(__CLASS__, $t_group, $c_network, NULL, $table_options); } if ($itemtype == 'NetworkPort') { switch ($portType) { case 'NetworkPortAlias': $search_table = 'glpi_networkportaliases'; $search_request = "`networkports_id_alias`='{$items_id}'"; break; case 'NetworkPortAggregate': $search_table = 'glpi_networkportaggregates'; $search_request = "`networkports_id_list` like '%\"{$items_id}\"%'"; break; } $query = "SELECT `networkports_id` AS id\n FROM `{$search_table}`\n WHERE {$search_request}"; } else { $query = "SELECT `id`\n FROM `glpi_networkports`\n WHERE `items_id` = '{$items_id}'\n AND `itemtype` = '{$itemtype}'\n AND `instantiation_type` = '{$portType}'\n AND `is_deleted` = '0'\n ORDER BY `name`,\n `logical_number`"; } if ($result = $DB->query($query)) { echo "<div class='spaced'>"; $number_port = $DB->numrows($result); if ($number_port != 0) { $is_active_network_port = true; $save_canedit = $canedit; if (!empty($portType)) { $name = sprintf(__('%1$s (%2$s)'), self::getTypeName($number_port), call_user_func(array($portType, 'getTypeName'))); $name = sprintf(__('%1$s: %2$s'), $name, $number_port); } else { $name = __('Network ports waiting for manual migration'); $canedit = false; } while ($devid = $DB->fetch_row($result)) { $t_row = $t_group->createRow(); $netport->getFromDB(current($devid)); // No massive action for migration ports if ($withtemplate != 2 && $canedit && !empty($portType)) { $ce_checkbox = $t_row->addCell($c_checkbox, "<input type='checkbox' name='item[" . $netport->fields["id"] . "]' value='1'>"); } else { $ce_checkbox = NULL; } $content = "<span class='b'>"; // Display link based on default rights if ($save_canedit && $withtemplate != 2) { if (!empty($portType)) { $content .= "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?id=" . $netport->fields["id"] . "\">"; } else { $content .= "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/networkportmigration.form.php?id=" . $netport->fields["id"] . "\">"; } } $content .= $netport->fields["logical_number"]; if ($canedit && $withtemplate != 2) { $content .= "</a>"; } $content .= "</span>"; $content .= Html::showToolTip($netport->fields['comment'], array('display' => false)); $t_row->addCell($c_number, $content); $value = $netport->fields["name"]; $t_row->addCell($c_name, $value, NULL, $netport); if ($table_options['display_isDynamic']) { $t_row->addCell($c_dynamic, Dropdown::getYesNo($netport->fields['is_dynamic'])); } $instant_cell = NULL; if ($display_options['characteristics']) { $instantiation = $netport->getInstantiation(); if ($instantiation !== false) { $instantiation->getInstantiationHTMLTable($netport, $t_row, NULL, $table_options); unset($instantiation); } } else { if ($display_options['internet']) { NetworkName::getHTMLTableCellsForItem($t_row, $netport, NULL, $table_options); } } } $canedit = $save_canedit; } echo "</div>"; } } if ($is_active_network_port && $showmassiveactions) { $massiveactionparams = array('num_displayed' => $number_port, 'check_itemtype' => $itemtype, 'check_items_id' => $items_id); Html::showMassiveActions('NetworkPort', $massiveactionparams); } $table->display(array('display_thead' => false, 'display_tfoot' => false)); unset($table); if (!$is_active_network_port) { echo "<table class='tab_cadre_fixe'><tr><th>" . __('No network port found') . "</th></tr>"; echo "</table>"; } if ($showmassiveactions) { $massiveactionparams['ontop'] = false; Html::showMassiveActions('NetworkPort', $massiveactionparams); Html::closeForm(); } }
/** * Print the computers disks * * @param $comp Computer object * @param $withtemplate boolean Template or basic item (default '') * * @return Nothing (call to classes members) **/ static function showForComputer(Computer $comp, $withtemplate = '') { global $DB; $ID = $comp->fields['id']; if (!$comp->getFromDB($ID) || !$comp->can($ID, READ)) { return false; } $canedit = $comp->canEdit($ID); if ($canedit && !(!empty($withtemplate) && $withtemplate == 2)) { echo "<div class='center firstbloc'>" . "<a class='vsubmit' href='computerdisk.form.php?computers_id={$ID}&withtemplate=" . $withtemplate . "'>"; _e('Add a volume'); echo "</a></div>\n"; } echo "<div class='center'>"; $query = "SELECT `glpi_filesystems`.`name` AS fsname,\n `glpi_computerdisks`.*\n FROM `glpi_computerdisks`\n LEFT JOIN `glpi_filesystems`\n ON (`glpi_computerdisks`.`filesystems_id` = `glpi_filesystems`.`id`)\n WHERE `computers_id` = '{$ID}'\n AND `is_deleted` = '0'"; if ($result = $DB->query($query)) { echo "<table class='tab_cadre_fixehov table-striped table-hover'>"; $colspan = 7; if (Plugin::haveImport()) { $colspan++; } echo "<tr class='noHover'><th colspan='{$colspan}'>" . self::getTypeName($DB->numrows($result)) . "</th></tr>"; if ($DB->numrows($result)) { $header = "<tr><th>" . __('Name') . "</th>"; if (Plugin::haveImport()) { $header .= "<th>" . __('Automatic inventory') . "</th>"; } $header .= "<th>" . __('Partition') . "</th>"; $header .= "<th>" . __('Mount point') . "</th>"; $header .= "<th>" . __('File system') . "</th>"; $header .= "<th>" . __('Global size') . "</th>"; $header .= "<th>" . __('Free size') . "</th>"; $header .= "<th>" . __('Free percentage') . "</th>"; $header .= "</tr>"; echo $header; Session::initNavigateListItems(__CLASS__, sprintf(__('%1$s = %2$s'), Computer::getTypeName(1), $comp->getName())); $disk = new self(); while ($data = $DB->fetch_assoc($result)) { $disk->getFromDB($data['id']); echo "<tr class='tab_bg_2'>"; echo "<td>" . $disk->getLink() . "</td>"; if (Plugin::haveImport()) { echo "<td>" . Dropdown::getYesNo($data['is_dynamic']) . "</td>"; } echo "<td>" . $data['device'] . "</td>"; echo "<td>" . $data['mountpoint'] . "</td>"; echo "<td>" . $data['fsname'] . "</td>"; //TRANS: %s is a size $tmp = sprintf(__('%s Mio'), Html::formatNumber($data['totalsize'], false, 0)); echo "<td class='right'>{$tmp}<span class='small_space'></span></td>"; $tmp = sprintf(__('%s Mio'), Html::formatNumber($data['freesize'], false, 0)); echo "<td class='right'>{$tmp}<span class='small_space'></span></td>"; echo "<td>"; $percent = 0; if ($data['totalsize'] > 0) { $percent = round(100 * $data['freesize'] / $data['totalsize']); } Html::displayProgressBar('100', $percent, array('simple' => true, 'forcepadding' => false)); echo "</td>"; echo "</tr>"; Session::addToNavigateListItems(__CLASS__, $data['id']); } echo $header; } else { echo "<tr class='tab_bg_2'><th colspan='{$colspan}'>" . __('No item found') . "</th></tr>"; } echo "</table>"; } echo "</div><br>"; }
/** * Show projecttasks for a ticket * * @param $ticket Ticket object **/ static function showForTicket(Ticket $ticket) { global $DB, $CFG_GLPI; $ID = $ticket->getField('id'); if (!$ticket->can($ID, READ)) { return false; } $canedit = $ticket->canEdit($ID); $rand = mt_rand(); $query = "SELECT DISTINCT `glpi_projecttasks_tickets`.`id` AS linkID,\n `glpi_projecttasks`.*\n FROM `glpi_projecttasks`\n LEFT JOIN `glpi_projecttasks_tickets`\n ON (`glpi_projecttasks_tickets`.`projecttasks_id` = `glpi_projecttasks`.`id`)\n WHERE `glpi_projecttasks_tickets`.`tickets_id` = '{$ID}'\n ORDER BY `glpi_projecttasks`.`name`"; $result = $DB->query($query); $pjtasks = array(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $pjtasks[$data['id']] = $data; $used[$data['id']] = $data['id']; } } // if ($canedit) { // echo "<div class='firstbloc'>"; // echo "<form name='projecttaskticket_form$rand' id='projecttaskticket_form$rand' // method='post' action='".Toolbox::getItemTypeFormURL(__CLASS__)."'>"; // // echo "<table class='tab_cadre_fixe'>"; // echo "<tr class='tab_bg_2'><th colspan='3'>".__('Add a project task')."</th></tr>"; // // echo "<tr class='tab_bg_2'><td class='right'>"; // echo "<input type='hidden' name='tickets_id' value='$ID'>"; // $condition = "`glpi_projecttasks`.`projectstates_id` <> 3"; // ProjectTask::dropdown(array('used' => $used, // 'entity' => $ticket->getEntityID(), // 'entity_sons' => $ticket->isRecursive(), // 'condition' => $condition, // 'displaywith' => array('id'))); // echo "</td><td width='20%'>"; // // echo "<a href='".Toolbox::getItemTypeFormURL('ProjectTask')."?tickets_id=$ID'>"; // // _e('Create a project task from this ticket'); // // echo "</a>"; // echo "</td><td class='center'>"; // echo "<input type='submit' name='add' value=\""._sx('button', 'Add')."\" class='submit'>"; // echo "</td></tr>"; // // echo "</table>"; // Html::closeForm(); // echo "</div>"; // } echo "<div class='spaced'>"; if ($numrows) { $columns = array('projectname' => Project::getTypeName(Session::getPluralNumber()), 'name' => ProjectTask::getTypeName(Session::getPluralNumber()), 'tname' => __('Type'), 'sname' => __('Status'), 'percent_done' => __('Percent done'), 'plan_start_date' => __('Planned start date'), 'plan_end_date' => __('Planned end date'), 'planned_duration' => __('Planned duration'), '_effect_duration' => __('Effective duration'), 'fname' => __('Father')); if (isset($_GET["order"]) && $_GET["order"] == "DESC") { $order = "DESC"; } else { $order = "ASC"; } if (!isset($_GET["sort"]) || empty($_GET["sort"])) { $_GET["sort"] = "plan_start_date"; } if (isset($_GET["sort"]) && !empty($_GET["sort"]) && isset($columns[$_GET["sort"]])) { $sort = "`" . $_GET["sort"] . "`"; } else { $sort = "`plan_start_date` {$order}, `name`"; } $query = "SELECT `glpi_projecttasks`.*,\n `glpi_projecttasktypes`.`name` AS tname,\n `glpi_projectstates`.`name` AS sname,\n `glpi_projectstates`.`color`,\n `father`.`name` AS fname,\n `father`.`id` AS fID,\n `glpi_projects`.`name` AS projectname,\n `glpi_projects`.`content` AS projectcontent\n FROM `glpi_projecttasks`\n LEFT JOIN `glpi_projecttasktypes`\n ON (`glpi_projecttasktypes`.`id` = `glpi_projecttasks`.`projecttasktypes_id`)\n LEFT JOIN `glpi_projectstates`\n ON (`glpi_projectstates`.`id` = `glpi_projecttasks`.`projectstates_id`)\n LEFT JOIN `glpi_projecttasks` as father\n ON (`father`.`id` = `glpi_projecttasks`.`projecttasks_id`)\n LEFT JOIN `glpi_projecttasks_tickets`\n ON (`glpi_projecttasks_tickets`.`projecttasks_id` = `glpi_projecttasks`.`id`)\n LEFT JOIN `glpi_projects`\n ON (`glpi_projecttasks`.`projects_id` = `glpi_projects`.`id`)\n WHERE `glpi_projecttasks_tickets`.`tickets_id` = '{$ID}'\n ORDER BY {$sort} {$order}"; Session::initNavigateListItems('ProjectTask', sprintf(__('%1$s = %2$s'), $ticket::getTypeName(1), $ticket->getName())); if ($result = $DB->query($query)) { if ($DB->numrows($result)) { echo "<table class='tab_cadre_fixehov'>"; echo "<tr><th colspan='10'>" . ProjectTask::getTypeName($numrows) . "</th>"; echo "</tr>"; $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>"; $header = '<tr>'; foreach ($columns as $key => $val) { // Non order column if ($key[0] == '_') { $header .= "<th>{$val}</th>"; } else { $header .= "<th>" . ($sort == "`{$key}`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort={$key}&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>{$val}</a></th>"; } } $header .= "</tr>\n"; echo $header; while ($data = $DB->fetch_assoc($result)) { Session::addToNavigateListItems('ProjectTask', $data['id']); $rand = mt_rand(); echo "<tr class='tab_bg_2'>"; echo "<td>"; $link = "<a id='Project" . $data["projects_id"] . $rand . "' href='project.form.php?id=" . $data['projects_id'] . "'>" . $data['projectname'] . (empty($data['projectname']) ? "(" . $data['projects_id'] . ")" : "") . "</a>"; echo sprintf(__('%1$s %2$s'), $link, Html::showToolTip($data['projectcontent'], array('display' => false, 'applyto' => "Project" . $data["projects_id"] . $rand))); echo "</td>"; echo "<td>"; $link = "<a id='ProjectTask" . $data["id"] . $rand . "' href='projecttask.form.php?id=" . $data['id'] . "'>" . $data['name'] . (empty($data['name']) ? "(" . $data['id'] . ")" : "") . "</a>"; echo sprintf(__('%1$s %2$s'), $link, Html::showToolTip($data['content'], array('display' => false, 'applyto' => "ProjectTask" . $data["id"] . $rand))); echo "</td>"; echo "<td>" . $data['tname'] . "</td>"; echo "<td"; echo " style=\"background-color:" . $data['color'] . "\""; echo ">" . $data['sname'] . "</td>"; echo "<td>"; echo Dropdown::getValueWithUnit($data["percent_done"], "%"); echo "</td>"; echo "<td>" . Html::convDateTime($data['plan_start_date']) . "</td>"; echo "<td>" . Html::convDateTime($data['plan_end_date']) . "</td>"; echo "<td>" . Html::timestampToString($data['planned_duration'], false) . "</td>"; echo "<td>" . Html::timestampToString(ProjectTask::getTotalEffectiveDuration($data['id']), false) . "</td>"; echo "<td>"; if ($data['projecttasks_id'] > 0) { $father = Dropdown::getDropdownName('glpi_projecttasks', $data['projecttasks_id']); echo "<a id='ProjectTask" . $data["projecttasks_id"] . $rand . "' href='projecttask.form.php?id=" . $data['projecttasks_id'] . "'>" . $father . (empty($father) ? "(" . $data['projecttasks_id'] . ")" : "") . "</a>"; } echo "</td></tr>"; } echo $header; echo "</table>\n"; } else { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('No item found') . "</th></tr>"; echo "</table>\n"; } } echo "</div>"; } }
/** * Show users of an entity * * @param $entity Entity object **/ static function showForEntity(Entity $entity) { global $DB; $ID = $entity->getField('id'); if (!$entity->can($ID, READ)) { return false; } $canedit = $entity->canEdit($ID); $canshowuser = User::canView(); $nb_per_line = 3; $rand = mt_rand(); if ($canedit) { $headerspan = $nb_per_line * 2; } else { $headerspan = $nb_per_line; } if ($canedit) { echo "<div class='firstbloc'>"; echo "<form name='entityuser_form{$rand}' id='entityuser_form{$rand}' method='post' action='"; echo Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th colspan='6'>" . __('Add an authorization to a user') . "</tr>"; echo "<tr class='tab_bg_1'><td class='tab_bg_2 center'>" . __('User') . " "; echo "<input type='hidden' name='entities_id' value='{$ID}'>"; User::dropdown(array('right' => 'all')); echo "</td><td class='tab_bg_2 center'>" . self::getTypeName(1) . "</td><td>"; Profile::dropdownUnder(array('value' => Profile::getDefault())); echo "</td><td class='tab_bg_2 center'>" . __('Recursive') . "</td><td>"; Dropdown::showYesNo("is_recursive", 0); echo "</td><td class='tab_bg_2 center'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; } $query = "SELECT DISTINCT `glpi_profiles`.`id`, `glpi_profiles`.`name`\n FROM `glpi_profiles_users`\n LEFT JOIN `glpi_profiles`\n ON (`glpi_profiles_users`.`profiles_id` = `glpi_profiles`.`id`)\n LEFT JOIN `glpi_users` ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)\n WHERE `glpi_profiles_users`.`entities_id` = '{$ID}'\n AND `glpi_users`.`is_deleted` = '0'"; $result = $DB->query($query); $nb = $DB->numrows($result); echo "<div class='spaced'>"; if ($canedit && $nb) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('container' => 'mass' . __CLASS__ . $rand, 'specific_actions' => array('purge' => _x('button', 'Delete permanently'))); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixehov'>"; echo "<thead><tr>"; echo "<th class='noHover' colspan='{$headerspan}'>"; printf(__('%1$s (%2$s)'), _n('User', 'Users', Session::getPluralNumber()), __('D=Dynamic, R=Recursive')); echo "</th></tr></thead>"; if ($nb) { Session::initNavigateListItems('User', sprintf(__('%1$s = %2$s'), Entity::getTypeName(1), $entity->getName())); while ($data = $DB->fetch_assoc($result)) { echo "<tbody><tr class='noHover'>"; $reduce_header = 0; if ($canedit && $nb) { echo "<th width='10'>"; echo Html::checkAllAsCheckbox("profile" . $data['id'] . "_{$rand}"); echo "</th>"; $reduce_header++; } echo "<th colspan='" . ($headerspan - $reduce_header) . "'>"; printf(__('%1$s: %2$s'), __('Profile'), $data["name"]); echo "</th></tr></tbody>"; echo "<tbody id='profile" . $data['id'] . "_{$rand}'>"; $query = "SELECT `glpi_users`.*,\n `glpi_profiles_users`.`id` AS linkID,\n `glpi_profiles_users`.`is_recursive`,\n `glpi_profiles_users`.`is_dynamic`\n FROM `glpi_profiles_users`\n LEFT JOIN `glpi_users`\n ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)\n WHERE `glpi_profiles_users`.`entities_id` = '{$ID}'\n AND `glpi_users`.`is_deleted` = '0'\n AND `glpi_profiles_users`.`profiles_id` = '" . $data['id'] . "'\n ORDER BY `glpi_profiles_users`.`profiles_id`,\n `glpi_users`.`name`,\n `glpi_users`.`realname`,\n `glpi_users`.`firstname`"; $result2 = $DB->query($query); if ($DB->numrows($result2) > 0) { $i = 0; while ($data2 = $DB->fetch_assoc($result2)) { Session::addToNavigateListItems('User', $data2["id"]); if ($i % $nb_per_line == 0) { if ($i != 0) { echo "</tr>"; } echo "<tr class='tab_bg_1'>"; } if ($canedit) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data2["linkID"]); echo "</td>"; } $username = formatUserName($data2["id"], $data2["name"], $data2["realname"], $data2["firstname"], $canshowuser); if ($data2["is_dynamic"] || $data2["is_recursive"]) { $username = sprintf(__('%1$s %2$s'), $username, "<span class='b'>("); if ($data2["is_dynamic"]) { $username = sprintf(__('%1$s%2$s'), $username, __('D')); } if ($data2["is_dynamic"] && $data2["is_recursive"]) { $username = sprintf(__('%1$s%2$s'), $username, ", "); } if ($data2["is_recursive"]) { $username = sprintf(__('%1$s%2$s'), $username, __('R')); } $username = sprintf(__('%1$s%2$s'), $username, ")</span>"); } echo "<td>" . $username . "</td>"; $i++; } while ($i % $nb_per_line != 0) { echo "<td> </td>"; if ($canedit) { echo "<td> </td>"; } $i++; } echo "</tr>"; echo "</tbody>"; } else { echo "<tr colspan='{$headerspan}'>" . __('Item not found') . "</tr>"; } } } echo "</table>"; if ($canedit && $nb) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }