/** * 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>"; } } }
/** * 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>"; } } }
/** *Print out list kb item * * @param $options : $_GET * @param $faq display on faq ? **/ static function showList($options, $faq = 0) { global $DB, $LANG, $CFG_GLPI; // Default values of parameters $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; } } // Lists kb Items $where = ""; $order = ""; $score = ""; // Build query if (getLoginUserID()) { $where = getEntitiesRestrictRequest("", "glpi_knowbaseitems", "", "", true) . " AND "; } else { // Anonymous access if (isMultiEntitiesMode()) { $where = " (`glpi_knowbaseitems`.`entities_id` = '0'\n AND `glpi_knowbaseitems`.`is_recursive` = '1')\n AND "; } } if ($faq) { // helpdesk $where .= " (`glpi_knowbaseitems`.`is_faq` = '1')\n AND "; } // a search with $contains if (strlen($params["contains"]) > 0) { $search = unclean_cross_side_scripting_deep($params["contains"]); $score = " ,MATCH(glpi_knowbaseitems.question, glpi_knowbaseitems.answer)\n AGAINST('{$search}' IN BOOLEAN MODE) AS SCORE "; $where_1 = $where . " MATCH(glpi_knowbaseitems.question, glpi_knowbaseitems.answer)\n AGAINST('{$search}' IN BOOLEAN MODE) "; $order = "ORDER BY `SCORE` DESC"; // preliminar query to allow alternate search if no result with fulltext $query_1 = "SELECT COUNT(`id`)\n FROM `glpi_knowbaseitems`\n WHERE {$where_1}"; $result_1 = $DB->query($query_1); $numrows_1 = $DB->result($result_1, 0, 0); if ($numrows_1 <= 0) { // not result this fulltext try with alternate search $search1 = array('/\\\\"/', "/\\+/", "/\\*/", "/~/", "/</", "/>/", "/\\(/", "/\\)/", "/\\-/"); $contains = preg_replace($search1, "", $params["contains"]); $where .= " (`glpi_knowbaseitems`.`question` " . makeTextSearch($contains) . "\n OR `glpi_knowbaseitems`.`answer` " . makeTextSearch($contains) . ")"; } else { $where = $where_1; } } else { // no search -> browse by category $where .= " (`glpi_knowbaseitems`.`knowbaseitemcategories_id`\n = '" . $params["knowbaseitemcategories_id"] . "')"; $order = " ORDER BY `glpi_knowbaseitems`.`question` ASC"; } if (!$params["start"]) { $params["start"] = 0; } $query = "SELECT `glpi_knowbaseitems`.*,\n `glpi_knowbaseitemcategories`.`completename` AS category\n {$score}\n FROM `glpi_knowbaseitems`\n LEFT JOIN `glpi_knowbaseitemcategories`\n ON (`glpi_knowbaseitemcategories`.`id`\n = `glpi_knowbaseitems`.`knowbaseitemcategories_id`)\n WHERE {$where}\n {$order}"; // Get it from database if ($result = $DB->query($query)) { $KbCategory = new KnowbaseItemCategory(); $title = ""; if ($KbCategory->getFromDB($params["knowbaseitemcategories_id"])) { $title = $LANG['common'][36] . " = " . (empty($KbCategory->fields['name']) ? "(" . $params['knowbaseitemcategories_id'] . ")" : $KbCategory->fields['name']); } initNavigateListItems('KnowbaseItem', $title); $numrows = $DB->numrows($result); $list_limit = $_SESSION['glpilist_limit']; // 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 = 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={$faq}"; if (isset($options['tickets_id'])) { $parameters .= "&tickets_id=" . $options['tickets_id']; } if ($output_type == HTML_OUTPUT) { printPager($params['start'], $numrows, 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, $LANG['knowbase'][14], $header_num); if ($output_type != HTML_OUTPUT) { echo Search::showHeaderItem($output_type, $LANG['knowbase'][15], $header_num); } echo Search::showHeaderItem($output_type, $LANG['common'][36], $header_num); if (isset($options['tickets_id']) && $output_type == 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_array($result_limit); addToNavigateListItems('KnowbaseItem', $data["id"]); // Column num $item_num = 1; $row_num++; echo Search::showNewLine($output_type, $i % 2); if ($output_type == HTML_OUTPUT) { if (isset($options['tickets_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=\"" . $params['target'] . "?id=" . $data["id"] . "\" "; } echo Search::showItem($output_type, "<div class='kb'><a " . ($data['is_faq'] ? " class='pubfaq' " : " class='knowbase' ") . " {$href}>" . resume_text($data["question"], 80) . "</a></div>\n <div class='kb_resume'>" . resume_text(html_clean(unclean_cross_side_scripting_deep($data["answer"])), 600) . "</div>", $item_num, $row_num); } else { echo Search::showItem($output_type, $data["question"], $item_num, $row_num); echo Search::showItem($output_type, html_clean(unclean_cross_side_scripting_deep(html_entity_decode($data["answer"], ENT_QUOTES, "UTF-8"))), $item_num, $row_num); } echo Search::showItem($output_type, $data["category"], $item_num, $row_num); if (isset($options['tickets_id']) && $output_type == HTML_OUTPUT) { $content = "<a href='" . $CFG_GLPI['root_doc'] . "/front/ticket.form.php?load_kb_sol=" . $data['id'] . "&id=" . $options['tickets_id'] . "&forcetab=4'>" . $LANG['job'][24] . "</a>"; echo Search::showItem($output_type, $content, $item_num, $row_num); } // End Line echo Search::showEndLine($output_type); } // Display footer if ($output_type == PDF_OUTPUT_LANDSCAPE || $output_type == 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 == HTML_OUTPUT) { printPager($params['start'], $numrows, getItemTypeSearchURL('KnowbaseItem'), $parameters, 'KnowbaseItem'); } } else { if ($params["knowbaseitemcategories_id"] != 0) { echo "<div class='center b'>" . $LANG['search'][15] . "</div>"; } } } }