Example #1
0
 /**
  * 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"] . '&amp;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'] . "&amp;id=" . $options['item_items_id'] . "&amp;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>";
         }
     }
 }
Example #2
0
 /**
  * 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"] . "&amp;knowbaseitemcategories_id=" . $params['knowbaseitemcategories_id'] . "&amp;contains=" . $params["contains"] . "&amp;is_faq=" . $params['faq'];
             if (isset($options['item_itemtype']) && isset($options['item_items_id'])) {
                 $parameters .= "&amp;item_items_id=" . $options['item_items_id'] . "&amp;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, '&nbsp;', $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&amp;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"] . '&amp;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'] . "&amp;id=" . $options['item_items_id'] . "&amp;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>";
         }
     }
 }