diff --git a/knowledgebase.php b/knowledgebase.php index a192a293..22bea8b0 100644 --- a/knowledgebase.php +++ b/knowledgebase.php @@ -1,7 +1,7 @@ '.$article['subject'].' @@ -290,6 +295,7 @@ function hesk_show_kb_article($artid) echo '

'; } + // Article rating if ($hesk_settings['kb_rating'] && strpos( hesk_COOKIE('hesk_kb_rate'),'a'.$artid.'%')===false ) { echo ' @@ -300,6 +306,55 @@ function hesk_show_kb_article($artid) '; } + // Related articles + if ($hesk_settings['kb_related']) + { + require(HESK_PATH . 'inc/mail/email_parser.php'); + + $query = hesk_dbEscape( $article['subject'] . ' ' . convert_html_to_text($article['content']) ); + + // Get relevant articles from the database + $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)); + + // Array with related articles + $related_articles = array(); + + while ($related = hesk_dbFetchAssoc($res)) + { + // Get base match score from the first article + if ( ! isset($base_score) ) + { + $base_score = $related['score']; + } + + // Ignore this article + if ( $related['id'] == $artid ) + { + continue; + } + + // Stop when articles reach less than 10% of base score + if ($related['score'] / $base_score < 0.10) + { + break; + } + + // This is a valid related article + $related_articles[$related['id']] = $related['subject']; + } + + // Print related articles if we have any valid matches + if ( count($related_articles) ) + { + echo '
'.$hesklang['relart'].''; + foreach ($related_articles as $id => $subject) + { + echo ' '.$subject.'
'; + } + echo '
'; + } + } + if ($article['catid']==1) { $link = 'knowledgebase.php'; @@ -361,7 +416,7 @@ function hesk_show_kb_article($artid) function hesk_show_kb_category($catid, $is_search = 0) { global $hesk_settings, $hesklang; - $res = hesk_dbQuery("SELECT * FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_categories` WHERE `id`='{$catid}' AND `type`='0' LIMIT 1"); + $res = hesk_dbQuery("SELECT `name`,`parent` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_categories` WHERE `id`='{$catid}' AND `type`='0' LIMIT 1"); $thiscat = hesk_dbFetchAssoc($res) or hesk_error($hesklang['kb_cat_inv']); if ($is_search == 0) @@ -372,6 +427,17 @@ function hesk_show_kb_category($catid, $is_search = 0) { hesk_kb_header($hesk_settings['kb_link']); } + // If we are in "Knowledgebase only" mode show system messages + if ($catid == 1 && hesk_check_kb_only(false) ) + { + // Service messages + $res = hesk_dbQuery('SELECT `title`, `message`, `style` FROM `'.hesk_dbEscape($hesk_settings['db_pfix'])."service_messages` WHERE `type`='0' ORDER BY `order` ASC"); + while ($sm=hesk_dbFetchAssoc($res)) + { + hesk_service_message($sm); + } + } + if ($thiscat['parent']) { $link = ($thiscat['parent'] == 1) ? 'knowledgebase.php' : 'knowledgebase.php?category='.$thiscat['parent']; @@ -382,7 +448,7 @@ function hesk_show_kb_category($catid, $is_search = 0) { '; } - $result = hesk_dbQuery("SELECT * FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_categories` WHERE `parent`='{$catid}' AND `type`='0' ORDER BY `parent` ASC, `cat_order` ASC"); + $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"); if (hesk_dbNumRows($result) > 0) { ?> @@ -486,7 +552,7 @@ function hesk_show_kb_category($catid, $is_search = 0) { '.$hesklang['noac'].'

';