Bootswatch, Summernote, and Captcheck mods for Mods for HESK (mods-for-hesk.com). In use at support.netsyms.com.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

knowledgebase.php 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. <?php
  2. /**
  3. *
  4. * This file is part of HESK - PHP Help Desk Software.
  5. *
  6. * (c) Copyright Klemen Stirn. All rights reserved.
  7. * https://www.hesk.com
  8. *
  9. * For the full copyright and license agreement information visit
  10. * https://www.hesk.com/eula.php
  11. *
  12. */
  13. define('IN_SCRIPT', 1);
  14. define('HESK_PATH', './');
  15. /* Get all the required files and functions */
  16. require(HESK_PATH . 'hesk_settings.inc.php');
  17. require(HESK_PATH . 'inc/common.inc.php');
  18. // Connect to database
  19. hesk_load_database_functions();
  20. hesk_dbConnect();
  21. // Are we in maintenance mode?
  22. hesk_check_maintenance();
  23. define('PAGE_TITLE', 'CUSTOMER_KB');
  24. // Is Knowledgebase enabled?
  25. if (!$hesk_settings['kb_enable']) {
  26. hesk_error($hesklang['kbdis']);
  27. }
  28. // Do we have any public articles at all?
  29. $res = hesk_dbQuery("SELECT `t1`.`id` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_articles` AS `t1`
  30. LEFT JOIN `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_categories` AS `t2` ON `t1`.`catid` = `t2`.`id`
  31. WHERE `t1`.`type`='0' AND `t2`.`type`='0' LIMIT 1");
  32. // If yes, load KB functions; if not, disable and hide the KB
  33. if (hesk_dbNumRows($res) < 1) {
  34. hesk_error($hesklang['noa']);
  35. }
  36. // Load KB functions
  37. require(HESK_PATH . 'inc/knowledgebase_functions.inc.php');
  38. /* Rating? */
  39. if (isset($_GET['rating'])) {
  40. // Detect and block robots
  41. if (hesk_detect_bots()) {
  42. ?>
  43. <html>
  44. <head>
  45. <meta name="robots" content="noindex, nofollow">
  46. </head>
  47. <body>
  48. </body>
  49. </html>
  50. <?php
  51. }
  52. // Rating
  53. $rating = intval(hesk_GET('rating'));
  54. // Rating value may only be 1 or 5
  55. if ($rating != 1 && $rating != 5) {
  56. die($hesklang['attempt']);
  57. }
  58. // Article ID
  59. $artid = intval(hesk_GET('id', 0)) or die($hesklang['kb_art_id']);
  60. // Check cookies for already rated, rate and set cookie if not already
  61. $_COOKIE['hesk_kb_rate'] = hesk_COOKIE('hesk_kb_rate');
  62. if (strpos($_COOKIE['hesk_kb_rate'], 'a' . $artid . '%') === false) {
  63. // Update rating, make sure it's a public article in a public category
  64. hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_articles` AS `t1`
  65. LEFT JOIN `" . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_categories` AS `t2` ON t1.`catid` = t2.`id`
  66. SET `rating`=((`rating`*`votes`)+{$rating})/(`votes`+1), t1.`votes`=t1.`votes`+1
  67. WHERE t1.`id`='{$artid}' AND t1.`type`='0' AND t2.`type`='0'
  68. ");
  69. }
  70. hesk_setcookie('hesk_kb_rate', $_COOKIE['hesk_kb_rate'] . 'a' . $artid . '%', time() + 2592000);
  71. header('Location: knowledgebase.php?article=' . $artid . '&rated=1');
  72. exit();
  73. }
  74. /* Any category ID set? */
  75. $catid = intval(hesk_GET('category', 1));
  76. $artid = intval(hesk_GET('article', 0));
  77. if (isset($_GET['search'])) {
  78. $query = hesk_input(hesk_GET('search'));
  79. } else {
  80. $query = 0;
  81. }
  82. $hesk_settings['kb_link'] = ($artid || $catid != 1 || $query) ? '<a href="knowledgebase.php" class="smaller">' . $hesklang['kb_text'] . '</a>' : $hesklang['kb_text'];
  83. if ($hesk_settings['kb_search'] && $query) {
  84. hesk_kb_search($query);
  85. } elseif ($artid) {
  86. // Get article from DB, make sure that article and category are public
  87. $result = hesk_dbQuery("SELECT t1.*, t2.`name` AS `cat_name`
  88. FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_articles` AS `t1`
  89. LEFT JOIN `" . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_categories` AS `t2` ON `t1`.`catid` = `t2`.`id`
  90. WHERE `t1`.`id` = '{$artid}'
  91. AND `t1`.`type` = '0'
  92. AND `t2`.`type` = '0'
  93. ");
  94. $article = hesk_dbFetchAssoc($result) or hesk_error($hesklang['kb_art_id']);
  95. hesk_show_kb_article($artid);
  96. } else {
  97. hesk_show_kb_category($catid);
  98. }
  99. echo '</div>';
  100. require_once(HESK_PATH . 'inc/footer.inc.php');
  101. exit();
  102. /*** START FUNCTIONS ***/
  103. function hesk_kb_header($kb_link) {
  104. global $hesk_settings, $hesklang;
  105. ?>
  106. <ol class="breadcrumb">
  107. <li><a href="<?php echo $hesk_settings['site_url']; ?>"><?php echo $hesk_settings['site_title']; ?></a></li>
  108. <li><a href="<?php echo $hesk_settings['hesk_url']; ?>"><?php echo $hesk_settings['hesk_title']; ?></a></li>
  109. <li class="active"><?php echo $hesklang['kb_text']; ?></li>
  110. </ol>
  111. <?php
  112. $columnWidth = 'col-md-8';
  113. $showRs = hesk_dbQuery("SELECT `show` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "quick_help_sections` WHERE `id` = 4");
  114. $show = hesk_dbFetchAssoc($showRs);
  115. if (!$show['show']) {
  116. $columnWidth = 'col-md-10 col-md-offset-1';
  117. }
  118. ?>
  119. <div class="row">
  120. <?php if ($columnWidth == 'col-md-8'): ?>
  121. <div class="col-md-4">
  122. <div class="panel panel-default">
  123. <div class="panel-heading">
  124. <?php echo $hesklang['quick_help']; ?>
  125. </div>
  126. <div class="panel-body">
  127. <p style="text-align: justify;"><?php echo $hesklang['kb_is']; ?></p>
  128. </div>
  129. </div>
  130. </div>
  131. <?php endif; ?>
  132. <div class="<?php echo $columnWidth; ?>">
  133. <?php
  134. /* Print small search box */
  135. hesk_kbSearchSmall();
  136. /* Print large search box */
  137. hesk_kbSearchLarge();
  138. } // END hesk_kb_header()
  139. function hesk_kb_search($query)
  140. {
  141. global $hesk_settings, $hesklang;
  142. define('HESK_NO_ROBOTS', 1);
  143. /* Print header */
  144. $hesk_settings['tmp_title'] = $hesklang['sr'] . ': ' . hesk_mb_substr(hesk_htmlspecialchars(stripslashes($query)),0,20);
  145. require_once(HESK_PATH . 'inc/header.inc.php');
  146. hesk_kb_header($hesk_settings['kb_link']);
  147. $res = hesk_dbQuery('SELECT t1.`id`, t1.`subject`, LEFT(`t1`.`content`, ' . max(200, $hesk_settings['kb_substrart'] * 2) . ') AS `content`, t1.`rating` FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'kb_articles` AS t1
  148. LEFT JOIN `' . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_categories` AS t2 ON t1.`catid` = t2.`id`
  149. WHERE t1.`type`='0' AND t2.`type`='0' AND MATCH(`subject`,`content`,`keywords`) AGAINST ('" . hesk_dbEscape($query) . "') LIMIT " . intval($hesk_settings['kb_search_limit']));
  150. $num = hesk_dbNumRows($res);
  151. ?>
  152. <h4><?php echo $hesklang['sr']; ?> (<?php echo $num; ?>)</h4>
  153. <div class="footerWithBorder blankSpace"></div>
  154. <?php
  155. if ($num == 0) {
  156. echo '<p><i>' . $hesklang['nosr'] . '</i></p>
  157. <p>&nbsp;</p>
  158. ';
  159. hesk_show_kb_category(1, 1);
  160. } else {
  161. ?>
  162. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  163. <tr>
  164. <td class="roundcornersleft">&nbsp;</td>
  165. <td>
  166. <div align="center">
  167. <table border="0" cellspacing="1" cellpadding="3" width="100%">
  168. <?php
  169. while ($article = hesk_dbFetchAssoc($res)) {
  170. $txt = hesk_kbArticleContentPreview($article['content']);
  171. if ($hesk_settings['kb_rating']) {
  172. $alt = $article['rating'] ? sprintf($hesklang['kb_rated'], sprintf("%01.1f", $article['rating'])) : $hesklang['kb_not_rated'];
  173. $rat = '<td width="1" valign="top"><img src="img/star_' . (hesk_round_to_half($article['rating']) * 10) . '.png" width="85" height="16" alt="' . $alt . '" border="0" style="vertical-align:text-bottom" /></td>';
  174. } else {
  175. $rat = '';
  176. }
  177. echo '
  178. <tr>
  179. <td>
  180. <table border="0" width="100%" cellspacing="0" cellpadding="1">
  181. <tr>
  182. <td width="1" valign="top"><span class="glyphicon glyphicon-file"></span></td>
  183. <td valign="top"><a href="knowledgebase.php?article=' . $article['id'] . '">' . $article['subject'] . '</a></td>
  184. ' . $rat . '
  185. </tr>
  186. </table>
  187. <table border="0" width="100%" cellspacing="0" cellpadding="1">
  188. <tr>
  189. <td width="1" valign="top"><img src="img/blank.gif" width="16" height="10" style="vertical-align:middle" alt="" /></td>
  190. <td><span class="article_list">' . $txt . '</span></td>
  191. </tr>
  192. </table>
  193. </td>
  194. </tr>';
  195. }
  196. ?>
  197. </table>
  198. </div>
  199. </td>
  200. </tr>
  201. </table>
  202. <p>&nbsp;<br/>&laquo; <a href="javascript:history.go(-1)"><?php echo $hesklang['back']; ?></a></p>
  203. <?php
  204. } // END else
  205. } // END hesk_kb_search()
  206. function hesk_show_kb_article($artid)
  207. {
  208. global $hesk_settings, $hesklang, $article;
  209. // Print header
  210. $hesk_settings['tmp_title'] = $article['subject'];
  211. require_once(HESK_PATH . 'inc/header.inc.php');
  212. hesk_kb_header($hesk_settings['kb_link']);
  213. // Service messages
  214. $service_messages = mfh_get_service_messages('CUSTOMER_VIEW_KB_ARTICLE');
  215. foreach ($service_messages as $sm) {
  216. hesk_service_message($sm);
  217. }
  218. // Update views by 1 - exclude known bots and reloads because of ratings
  219. if (!isset($_GET['rated']) && !hesk_detect_bots()) {
  220. hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_articles` SET `views`=`views`+1 WHERE `id`={$artid}");
  221. }
  222. if (!isset($_GET['suggest'])) {
  223. $historyNumber = isset($_GET['rated']) ? '-2' : '-1';
  224. $goBackText = '<a href="javascript:history.go(' . $historyNumber . ')">
  225. <i class="fa fa-arrow-circle-left" data-toggle="tooltip" data-placement="top" title="' . $hesklang['back'] . '"></i></a>';
  226. } else {
  227. $goBackText = '';
  228. }
  229. echo '<h3 class="text-left">' . $goBackText . '&nbsp;' . $article['subject'] . '</h3>
  230. <div class="footerWithBorder blankSpace"></div>
  231. <h4 class="text-left">' . $hesklang['as'] . '</h4>
  232. <div class="kbContent">'
  233. . $article['content'] . '</div>';
  234. if (!empty($article['attachments'])) {
  235. echo '<p><b>' . $hesklang['attachments'] . ':</b><br />';
  236. $att = explode(',', substr($article['attachments'], 0, -1));
  237. foreach ($att as $myatt) {
  238. list($att_id, $att_name) = explode('#', $myatt);
  239. echo '<img src="img/clip.png" width="16" height="16" alt="' . $att_name . '" style="align:text-bottom" /> <a href="download_attachment.php?kb_att=' . $att_id . '" rel="nofollow">' . $att_name . '</a><br />';
  240. }
  241. echo '</p>';
  242. }
  243. // Article rating
  244. if ($hesk_settings['kb_rating'] && strpos(hesk_COOKIE('hesk_kb_rate'), 'a' . $artid . '%') === false) {
  245. echo '
  246. <div id="rating" class="rate" align="right">&nbsp;<br />' . $hesklang['rart'] . '
  247. <a href="Javascript:void(0)" onclick="Javascript:window.location=\'knowledgebase.php?rating=5&amp;id=' . $article['id'] . '\'" rel="nofollow">' . hesk_mb_strtolower($hesklang['yes']) . '</a> /
  248. <a href="Javascript:void(0)" onclick="Javascript:window.location=\'knowledgebase.php?rating=1&amp;id=' . $article['id'] . '\'" rel="nofollow">' . hesk_mb_strtolower($hesklang['no']) . '</a>
  249. </div>
  250. ';
  251. }
  252. // Related articles
  253. if ($hesk_settings['kb_related']) {
  254. $showRelated = false;
  255. $column = 'col-md-12';
  256. require(HESK_PATH . 'inc/mail/email_parser.php');
  257. $query = hesk_dbEscape($article['subject'] . ' ' . convert_html_to_text($article['content']));
  258. // Get relevant articles from the database
  259. $res = hesk_dbQuery("SELECT t1.`id`, t1.`subject`, MATCH(`subject`,`content`,`keywords`) AGAINST ('{$query}') AS `score` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . 'kb_articles` AS t1 LEFT JOIN `' . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_categories` AS t2 ON t1.`catid` = t2.`id` WHERE t1.`type`='0' AND t2.`type`='0' AND MATCH(`subject`,`content`,`keywords`) AGAINST ('{$query}') LIMIT " . intval($hesk_settings['kb_related'] + 1));
  260. // Array with related articles
  261. $related_articles = array();
  262. while ($related = hesk_dbFetchAssoc($res)) {
  263. // Get base match score from the first article
  264. if (!isset($base_score)) {
  265. $base_score = $related['score'];
  266. }
  267. // Ignore this article
  268. if ($related['id'] == $artid) {
  269. continue;
  270. }
  271. // Stop when articles reach less than 10% of base score
  272. if ($related['score'] / $base_score < 0.10) {
  273. break;
  274. }
  275. // This is a valid related article
  276. $related_articles[$related['id']] = $related['subject'];
  277. }
  278. // Print related articles if we have any valid matches
  279. if (count($related_articles)) {
  280. $column = 'col-md-6';
  281. $showRelated = true;
  282. }
  283. }
  284. if ($article['catid'] == 1) {
  285. $link = 'knowledgebase.php';
  286. } else {
  287. $link = 'knowledgebase.php?category=' . $article['catid'];
  288. }
  289. ?>
  290. <div class="row">
  291. <div class="<?php echo $column; ?> col-sm-12">
  292. <h4 class="text-left"><?php echo $hesklang['ad']; ?></h4>
  293. <div class="text-left">
  294. <p><?php echo $hesklang['aid']; ?>: <?php echo $article['id']; ?></p>
  295. <p><?php echo $hesklang['category']; ?>: <a
  296. href="<?php echo $link; ?>"><?php echo $article['cat_name']; ?></a></p>
  297. <?php
  298. if ($hesk_settings['kb_date']) {
  299. ?>
  300. <p><?php echo $hesklang['dta']; ?>: <?php echo hesk_date($article['dt'], true); ?></p>
  301. <?php
  302. }
  303. if ($hesk_settings['kb_views']) {
  304. ?>
  305. <p><?php echo $hesklang['views']; ?>
  306. : <?php echo(isset($_GET['rated']) ? $article['views'] : $article['views'] + 1); ?></p>
  307. <?php
  308. }
  309. if ($hesk_settings['kb_rating']) {
  310. $alt = $article['rating'] ? sprintf($hesklang['kb_rated'], sprintf("%01.1f", $article['rating'])) : $hesklang['kb_not_rated'];
  311. echo '
  312. <p>' . $hesklang['rating'] . ' (' . $hesklang['votes'] . '): <img src="img/star_' . (hesk_round_to_half($article['rating']) * 10) . '.png" width="85" height="16" alt="' . $alt . '" title="' . $alt . '" border="0" style="vertical-align:text-bottom" /> (' . $article['votes'] . ')</p>
  313. ';
  314. }
  315. ?>
  316. </div>
  317. </div>
  318. <?php if ($showRelated) { ?>
  319. <div class="col-md-6 col-sm-12">
  320. <h4 class="text-left"><?php echo $hesklang['relart']; ?></h4>
  321. <div class="text-left">
  322. <?php
  323. foreach ($related_articles as $id => $subject) {
  324. echo '<span class="glyphicon glyphicon-file icon-link"></span> <a href="knowledgebase.php?article=' . $id . '">' . $subject . '</a><br />';
  325. }
  326. ?>
  327. </div>
  328. </div>
  329. <?php } ?>
  330. </div>
  331. <?php
  332. hesk_kbFooter();
  333. } // END hesk_show_kb_article()
  334. function hesk_show_kb_category($catid, $is_search = 0)
  335. {
  336. global $hesk_settings, $hesklang;
  337. $res = hesk_dbQuery("SELECT `name`,`parent` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_categories` WHERE `id`='{$catid}' AND `type`='0' LIMIT 1");
  338. $thiscat = hesk_dbFetchAssoc($res) or hesk_error($hesklang['kb_cat_inv']);
  339. if ($is_search == 0) {
  340. /* Print header */
  341. $hesk_settings['tmp_title'] = $hesk_settings['hesk_title'] . ' - ' . hesk_htmlspecialchars($thiscat['name']);
  342. require_once(HESK_PATH . 'inc/header.inc.php');
  343. hesk_kb_header($hesk_settings['kb_link']);
  344. }
  345. // Display service messages on the default category
  346. if ($catid == 1) {
  347. // Service messages
  348. $service_messages = mfh_get_service_messages('CUSTOMER_KB_HOME');
  349. foreach ($service_messages as $sm) {
  350. hesk_service_message($sm);
  351. }
  352. }
  353. if ($thiscat['parent']) {
  354. $link = ($thiscat['parent'] == 1) ? 'knowledgebase.php' : 'knowledgebase.php?category=' . $thiscat['parent'];
  355. echo '<h3 class="text-left"><a href="javascript:history.go(-1)"><i class="fa fa-arrow-circle-left" data-toggle="tooltip" data-placement="top" title="' . $hesklang['back'] . '"></i></a>&nbsp;' . $hesklang['kb_cat'] . ': ' . $thiscat['name'] . ' </h3>
  356. <div class="footerWithBorder blankSpace"></div>
  357. <div class="blankSpace"></div>
  358. ';
  359. }
  360. $result = hesk_dbQuery("SELECT `id`,`name`,`articles` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_categories` WHERE `parent`='{$catid}' AND `type`='0' ORDER BY `cat_order` ASC");
  361. if (hesk_dbNumRows($result) > 0) {
  362. ?>
  363. <div class="panel panel-default">
  364. <div class="panel-heading">
  365. <h4 class="text-left"><?php echo $hesklang['kb_cat_sub']; ?></h4>
  366. </div>
  367. <table class="table table-striped">
  368. <?php
  369. $per_col = $hesk_settings['kb_cols'];
  370. $i = 1;
  371. while ($cat = hesk_dbFetchAssoc($result)) {
  372. if ($i == 1) {
  373. echo '<tr>';
  374. }
  375. echo '
  376. <td width="50%" valign="top">
  377. <table border="0">
  378. <tr><td><i class="fa fa-folder"></i>&nbsp;<a href="knowledgebase.php?category=' . $cat['id'] . '">' . $cat['name'] . '</a></td></tr>
  379. ';
  380. /* Print most popular/sticky articles */
  381. if ($hesk_settings['kb_numshow'] && $cat['articles']) {
  382. $res = hesk_dbQuery("SELECT `id`,`subject`, `sticky` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_articles` WHERE `catid`='{$cat['id']}' AND `type`='0' ORDER BY `sticky` DESC, `views` DESC, `art_order` ASC LIMIT " . (intval($hesk_settings['kb_numshow']) + 1));
  383. $num = 1;
  384. while ($art = hesk_dbFetchAssoc($res)) {
  385. $icon = 'glyphicon glyphicon-file';
  386. $style = '';
  387. if ($art['sticky']) {
  388. $icon = 'glyphicon glyphicon-pushpin';
  389. $style = 'style="color: #FF0000"';
  390. }
  391. echo '
  392. <tr>
  393. <td ' . $style . '>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="' . $icon . '"></span>
  394. <a href="knowledgebase.php?article=' . $art['id'] . '" class="article">' . $art['subject'] . '</a></td>
  395. </tr>';
  396. if ($num == $hesk_settings['kb_numshow']) {
  397. break;
  398. } else {
  399. $num++;
  400. }
  401. }
  402. if (hesk_dbNumRows($res) > $hesk_settings['kb_numshow']) {
  403. echo '<tr><td>&raquo; <a href="knowledgebase.php?category=' . $cat['id'] . '"><i>' . $hesklang['m'] . '</i></a></td></tr>';
  404. }
  405. }
  406. echo '
  407. </table>
  408. </td>
  409. ';
  410. if ($i == $per_col) {
  411. echo '</tr>';
  412. $i = 0;
  413. }
  414. $i++;
  415. }
  416. /* Finish the table if needed */
  417. if ($i != 1) {
  418. for ($j = 1; $j <= $per_col; $j++) {
  419. echo '<td width="50%">&nbsp;</td>';
  420. if ($i == $per_col) {
  421. echo '</tr>';
  422. break;
  423. }
  424. $i++;
  425. }
  426. }
  427. ?>
  428. </table>
  429. </div>
  430. <?php
  431. } // END if NumRows > 0
  432. ?>
  433. <div class="panel panel-default">
  434. <div class="panel-heading">
  435. <h4 class="text-left"><?php echo $hesklang['ac_no_colon']; ?></h4>
  436. </div>
  437. <table class="table table-striped">
  438. <tbody>
  439. <?php
  440. $res = hesk_dbQuery("SELECT `id`, `subject`, `sticky`, LEFT(`content`, " . max(200, $hesk_settings['kb_substrart'] * 2) . ") AS `content`, `rating` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_articles` WHERE `catid`='{$catid}' AND `type`='0' ORDER BY `sticky` DESC, `art_order` ASC");
  441. if (hesk_dbNumRows($res) == 0) {
  442. echo '<tr><td><i>' . $hesklang['noac'] . '</i></td></tr>';
  443. } else {
  444. while ($article = hesk_dbFetchAssoc($res)) {
  445. $icon = 'fa fa-file';
  446. $color = '';
  447. $style = '';
  448. $txt = hesk_kbArticleContentPreview($article['content']);
  449. if ($article['sticky']) {
  450. $icon = 'glyphicon glyphicon-pushpin';
  451. $style = 'style="color: #FF0000"';
  452. }
  453. if ($hesk_settings['kb_rating']) {
  454. $alt = $article['rating'] ? sprintf($hesklang['kb_rated'], sprintf("%01.1f", $article['rating'])) : $hesklang['kb_not_rated'];
  455. $rat = '<td><img src="img/star_' . (hesk_round_to_half($article['rating']) * 10) . '.png" width="85" height="16" alt="' . $alt . '" title="' . $alt . '" border="0" style="vertical-align:text-bottom" /></td>';
  456. } else {
  457. $rat = '';
  458. }
  459. echo '
  460. <tr>
  461. <td>
  462. <i class="' . $icon . '" ' . $style . '></i>
  463. <a href="knowledgebase.php?article=' . $article['id'] . '">' . $article['subject'] . '</a>
  464. <br>
  465. <span class="indent-15">' . $txt . '</span>
  466. </td>
  467. ' . $rat . '
  468. </tr>';
  469. }
  470. }
  471. ?>
  472. </tbody>
  473. </table>
  474. </div>
  475. <?php
  476. /* On the main KB page print out top and latest articles if needed */
  477. if ($catid == 1) {
  478. /* Get list of top articles */
  479. hesk_kbTopArticles($hesk_settings['kb_popart'], 0);
  480. /* Get list of latest articles */
  481. hesk_kbLatestArticles($hesk_settings['kb_latest'], 0);
  482. }
  483. hesk_kbFooter();
  484. } // END hesk_show_kb_category()
  485. function hesk_kbFooter()
  486. {
  487. global $hesk_settings;
  488. $showRs = hesk_dbQuery("SELECT `show` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "quick_help_sections` WHERE `id` = 4");
  489. $show = hesk_dbFetchAssoc($showRs);
  490. if (!$show['show']) {
  491. echo '<div class="col-md-1">&nbsp;</div></div>';
  492. }
  493. }
  494. ?>