2014-03-23 16:03:30 -04:00
< ? php
/*******************************************************************************
2015-09-12 00:46:46 -04:00
* Title : Help Desk Software HESK
2016-04-18 18:57:07 -04:00
* Version : 2.6 . 7 from 18 th April 2016
2015-09-12 00:46:46 -04:00
* Author : Klemen Stirn
* Website : http :// www . hesk . com
********************************************************************************
* COPYRIGHT AND TRADEMARK NOTICE
* Copyright 2005 - 2015 Klemen Stirn . All Rights Reserved .
* HESK is a registered trademark of Klemen Stirn .
* The HESK may be used and modified free of charge by anyone
* AS LONG AS COPYRIGHT NOTICES AND ALL THE COMMENTS REMAIN INTACT .
* By using this code you agree to indemnify Klemen Stirn from any
* liability that might arise from it ' s use .
* Selling the code for this program , in part or full , without prior
* written consent is expressly forbidden .
* Using this code , in part or full , to create derivate work ,
* new scripts or products is expressly forbidden . Obtain permission
* before redistributing this software over the Internet or in
* any other medium . In all cases copyright and header must remain intact .
* This Copyright is in full effect in any country that has International
* Trade Agreements with the United States of America or
* with the European Union .
* Removing any of the copyright notices without purchasing a license
* is expressly forbidden . To remove HESK copyright notice you must purchase
* a license for this script . For more information on how to obtain
* a license please visit the page below :
* https :// www . hesk . com / buy . php
*******************************************************************************/
2014-03-23 16:03:30 -04:00
/* Check if this is a valid include */
2015-09-12 00:46:46 -04:00
if ( ! defined ( 'IN_SCRIPT' )) {
die ( 'Invalid attempt' );
}
2014-03-23 16:03:30 -04:00
/*** FUNCTIONS ***/
function hesk_kbArticleContentPreview ( $txt )
{
2015-09-12 00:46:46 -04:00
global $hesk_settings ;
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
// Strip HTML tags
$txt = strip_tags ( $txt );
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
// If text is larger than article preview length, shorten it
if ( strlen ( $txt ) > $hesk_settings [ 'kb_substrart' ]) {
// The quick but not 100% accurate way (number of chars displayed may be lower than the limit)
return substr ( $txt , 0 , $hesk_settings [ 'kb_substrart' ]) . '...' ;
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
// If you want a more accurate, but also slower way, use this instead
// return hesk_htmlentities( substr( hesk_html_entity_decode($txt), 0, $hesk_settings['kb_substrart'] ) ) . '...';
}
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
return $txt ;
2014-03-23 16:03:30 -04:00
} // END hesk_kbArticleContentPreview()
function hesk_kbTopArticles ( $how_many , $index = 1 )
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang ;
// Index page or KB main page?
if ( $index ) {
// Disabled?
if ( ! $hesk_settings [ 'kb_index_popart' ]) {
return true ;
}
// Show title in italics
$font_weight = 'i' ;
} else {
// Disabled?
if ( ! $hesk_settings [ 'kb_popart' ]) {
return true ;
}
// Show title in bold
$font_weight = 'b' ;
// Print a line for spacing
echo '<hr />' ;
}
?>
2014-03-23 16:03:30 -04:00
2015-04-17 16:27:08 -04:00
< div class = " panel panel-default " >
< div class = " panel-heading " >
< h4 class = " text-left " >< ? php echo $hesklang [ 'popart_no_colon' ]; ?> </h4>
</ div >
2015-04-17 22:09:49 -04:00
< table border = " 0 " width = " 100% " class = " table table-striped table-fixed " >
2015-04-17 16:27:08 -04:00
< thead >
< tr >
< ? php
/* Get list of articles from the database */
2015-09-12 00:46:46 -04:00
$res = hesk_dbQuery ( " SELECT `t1`.`id`,`t1`.`subject`,`t1`.`views`,`t1`.`sticky` 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`
2014-03-23 16:03:30 -04:00
WHERE `t1` . `type` = '0' AND `t2` . `type` = '0'
2015-09-12 00:46:46 -04:00
ORDER BY `t1` . `sticky` DESC , `t1` . `views` DESC , `t1` . `art_order` ASC LIMIT " . intval( $how_many ));
2014-03-23 16:03:30 -04:00
2015-04-17 16:27:08 -04:00
/* Show number of views? */
2015-09-12 00:46:46 -04:00
if ( $hesk_settings [ 'kb_views' ] && hesk_dbNumRows ( $res ) != 0 ) {
2015-05-11 19:25:16 -04:00
echo '<th class="col-xs-8 col-sm-9"> </th>' ;
2015-04-17 22:09:49 -04:00
echo '<th class="col-xs-4 col-sm-3"><i>' . $hesklang [ 'views' ] . '</i></th>' ;
2015-04-17 16:27:08 -04:00
}
?>
</ tr >
</ thead >
< tbody >
< ? php
/* Get list of articles from the database */
2015-09-12 00:46:46 -04:00
$res = hesk_dbQuery ( " SELECT `t1`.`id`,`t1`.`subject`,`t1`.`dt`, `t1`.`views`,`t1`.`sticky` 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`
2015-04-17 16:27:08 -04:00
WHERE `t1` . `type` = '0' AND `t2` . `type` = '0'
2015-09-12 00:46:46 -04:00
ORDER BY `t1` . `sticky` DESC , `t1` . `views` DESC , `t1` . `art_order` ASC LIMIT " . intval( $how_many ));
2015-04-17 16:27:08 -04:00
/* If no results found end here */
2015-09-12 00:46:46 -04:00
if ( hesk_dbNumRows ( $res ) == 0 ) {
2015-04-17 16:27:08 -04:00
$colspan = '' ;
if ( ! $hesk_settings [ 'kb_views' ]) {
$colspan = 'colspan="2"' ;
}
2015-09-12 00:46:46 -04:00
echo '<tr><td ' . $colspan . '><i>' . $hesklang [ 'noa' ] . '</i></td></tr>' ;
2015-04-17 16:27:08 -04:00
}
/* We have some results, print them out */
$colspan = '' ;
if ( ! $hesk_settings [ 'kb_views' ]) {
$colspan = 'colspan="2"' ;
}
2015-09-12 00:46:46 -04:00
while ( $article = hesk_dbFetchAssoc ( $res )) {
2015-07-03 16:54:49 -04:00
$icon = 'fa fa-file' ;
$style = '' ;
if ( $article [ 'sticky' ]) {
$icon = 'glyphicon glyphicon-pushpin' ;
$style = 'style="color: #FF0000"' ;
}
2015-04-17 16:27:08 -04:00
echo '
< tr >
2015-09-12 00:46:46 -04:00
< td class = " col-xs-8 col-sm-9 " ' . $colspan . ' >
< i class = " ' . $icon . ' " ' . $style . ' ></ i > < a href = " knowledgebase.php?article=' . $article['id'] . ' " > ' . $article[' subject '] . ' </ a >
2015-04-17 16:27:08 -04:00
</ td >
' ;
if ( $hesk_settings [ 'kb_views' ]) {
2015-09-12 00:46:46 -04:00
echo '<td class="col-xs-4 col-sm-3">' . $article [ 'views' ] . '</td>' ;
2015-04-17 16:27:08 -04:00
}
echo '</tr>' ;
}
?>
</ tbody >
</ table >
2014-03-23 16:03:30 -04:00
</ div >
< ? php
2015-05-11 19:25:16 -04:00
return true ;
2014-03-23 16:03:30 -04:00
} // END hesk_kbTopArticles()
function hesk_kbLatestArticles ( $how_many , $index = 1 )
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang ;
// Index page or KB main page?
if ( $index ) {
// Disabled?
if ( ! $hesk_settings [ 'kb_index_latest' ]) {
return true ;
}
// Show title in italics
$font_weight = 'i' ;
} else {
// Disabled?
if ( ! $hesk_settings [ 'kb_latest' ]) {
return true ;
}
// Show title in bold
$font_weight = 'b' ;
// Print a line for spacing if we don't show popular articles
if ( ! $hesk_settings [ 'kb_popart' ]) {
echo '<hr />' ;
}
}
?>
2014-03-23 16:03:30 -04:00
2015-04-17 16:27:08 -04:00
< div class = " panel panel-default " >
< div class = " panel-heading " >
< h4 class = " text-left " >< ? php echo $hesklang [ 'latart_no_colon' ]; ?> </h4>
</ div >
2015-04-17 22:09:49 -04:00
< table class = " table table-striped table-fixed " >
2015-04-17 16:27:08 -04:00
< thead >
< tr >
2015-09-12 00:46:46 -04:00
< ? php
$colspan = '' ;
if ( ! $hesk_settings [ 'kb_date' ]) {
$colspan = 'colspan="2"' ;
}
/* Get list of articles from the database */
$res = hesk_dbQuery ( " SELECT `t1`.* 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`
2015-04-17 16:27:08 -04:00
WHERE `t1` . `type` = '0' AND `t2` . `type` = '0'
2015-09-12 00:46:46 -04:00
ORDER BY `t1` . `dt` DESC LIMIT " . intval( $how_many ));
/* Show number of views? */
if ( hesk_dbNumRows ( $res ) != 0 ) {
echo '<th class="col-xs-9" ' . $colspan . '> </th>' ;
if ( $hesk_settings [ 'kb_date' ]) {
echo '<th class="col-xs-3"><i>' . $hesklang [ 'dta' ] . '</i></th>' ;
}
2015-04-17 16:27:08 -04:00
}
2015-09-12 00:46:46 -04:00
?>
2015-04-17 16:27:08 -04:00
</ tr >
</ thead >
< tbody >
< ? php
/* Get list of articles from the database */
2015-09-12 00:46:46 -04:00
$res = hesk_dbQuery ( " SELECT `t1`.* 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`
2014-03-23 16:03:30 -04:00
WHERE `t1` . `type` = '0' AND `t2` . `type` = '0'
2015-09-12 00:46:46 -04:00
ORDER BY `t1` . `dt` DESC LIMIT " . intval( $how_many ));
2014-03-23 16:03:30 -04:00
2015-04-17 16:27:08 -04:00
/* If no results found end here */
2015-09-12 00:46:46 -04:00
if ( hesk_dbNumRows ( $res ) == 0 ) {
2015-04-17 16:27:08 -04:00
$colspan = '' ;
if ( $hesk_settings [ 'kb_date' ]) {
$colspan = 'colspan="2"' ;
}
2015-09-12 00:46:46 -04:00
echo '<td ' . $colspan . '><i>' . $hesklang [ 'noa' ] . '</i></td>' ;
2015-04-17 16:27:08 -04:00
}
/* We have some results, print them out */
$colspan = $hesk_settings [ 'kb_date' ] ? '' : 'colspan="2"' ;
2015-09-12 00:46:46 -04:00
while ( $article = hesk_dbFetchAssoc ( $res )) {
2015-07-03 16:54:49 -04:00
$icon = 'fa fa-file' ;
$style = '' ;
if ( $article [ 'sticky' ]) {
$icon = 'glyphicon glyphicon-pushpin' ;
$style = 'style="color: #FF0000"' ;
}
2015-04-17 16:27:08 -04:00
echo '
< tr >
2015-09-12 00:46:46 -04:00
< td class = " col-xs-9 " ' . $colspan . ' >
< i class = " ' . $icon . ' " ' . $style . ' ></ i > < a href = " knowledgebase.php?article=' . $article['id'] . ' " > ' . $article[' subject '] . ' </ a >
2015-04-17 16:27:08 -04:00
</ td > ' ;
if ( $hesk_settings [ 'kb_date' ]) {
2015-04-17 22:09:49 -04:00
echo '<td class="col-xs-3">' . hesk_date ( $article [ 'dt' ], true ) . '</td>' ;
2015-04-17 16:27:08 -04:00
}
echo '</tr>' ;
} ?>
2015-04-17 22:09:49 -04:00
</ tbody >
</ table >
2014-03-23 16:03:30 -04:00
</ div >
2015-09-12 00:46:46 -04:00
2014-03-23 16:03:30 -04:00
< ? php
2015-05-11 19:25:16 -04:00
return true ;
2014-03-23 16:03:30 -04:00
} // END hesk_kbLatestArticles()
function hesk_kbSearchLarge ( $admin = '' )
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang ;
2014-03-23 16:03:30 -04:00
2015-06-23 23:29:16 -04:00
$action = 'knowledgebase.php' ;
2015-09-12 00:46:46 -04:00
if ( $admin ) {
if ( ! $hesk_settings [ 'kb_search' ]) {
2015-06-23 23:29:16 -04:00
return '' ;
}
$action = 'knowledgebase_private.php' ;
2015-09-12 00:46:46 -04:00
} elseif ( $hesk_settings [ 'kb_search' ] != 2 ) {
return '' ;
2015-06-23 23:29:16 -04:00
}
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
?>
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
< div style = " text-align:center " >
< form role = " form " action = " <?php echo $action ; ?> " method = " get " style = " display: inline; margin: 0; "
name = " searchform " >
< div class = " input-group " >
< input type = " text " class = " form-control "
placeholder = " <?php echo htmlspecialchars( $hesklang['search_the_knowledgebase'] ); ?> "
name = " search " >
2014-03-23 16:03:30 -04:00
< span class = " input-group-btn " >
2015-09-12 00:46:46 -04:00
< button class = " btn btn-default " type = " submit " value = " <?php echo $hesklang['search'] ; ?> "
title = " <?php echo $hesklang['search'] ; ?> " >< ? php echo $hesklang [ 'search' ]; ?> </button>
2014-03-23 16:03:30 -04:00
</ span >
2015-09-12 00:46:46 -04:00
</ div >
2015-05-15 18:50:43 -04:00
</ form >
2015-09-12 00:46:46 -04:00
</ div >
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
< br />
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
<!-- START KNOWLEDGEBASE SUGGEST -->
< div id = " kb_suggestions " style = " display:none " >
< img src = " <?php echo HESK_PATH; ?>img/loading.gif " width = " 24 " height = " 24 " alt = " " border = " 0 "
style = " vertical-align:text-bottom " /> < i >< ? php echo $hesklang [ 'lkbs' ]; ?> </i>
</ div >
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
< script language = " Javascript " type = " text/javascript " ><!--
hesk_suggestKBsearch ( < ? php echo $admin ; ?> );
//-->
</ script >
<!-- END KNOWLEDGEBASE SUGGEST -->
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
< br />
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
< ? php
2014-03-23 16:03:30 -04:00
} // END hesk_kbSearchLarge()
function hesk_kbSearchSmall ()
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang ;
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
if ( $hesk_settings [ 'kb_search' ] != 1 ) {
return '' ;
}
2014-03-23 16:03:30 -04:00
?>
2015-09-12 00:46:46 -04:00
< td class = " text-right " valign = " top " width = " 300 " >
< div style = " display:inline;margin-left:auto;margin-right:auto " >
< form action = " knowledgebase.php " method = " get " class = " form-inline " style = " display: inline; margin: 0; " >
2015-05-15 18:50:43 -04:00
< div class = " input-group " style = " margin: 0 15px " >
< input type = " text " name = " search " class = " form-control " >
< span class = " input-group-btn " >
2015-09-12 00:46:46 -04:00
< button class = " btn btn-default " type = " submit "
value = " <?php echo $hesklang['search_the_knowledgebase'] ; ?> "
title = " <?php echo $hesklang['search_the_knowledgebase'] ; ?> " >
2015-05-15 18:50:43 -04:00
< ? php echo $hesklang [ 'search_the_knowledgebase' ]; ?>
</ button >
</ span >
</ div >
2015-09-12 00:46:46 -04:00
</ form >
2014-04-10 20:24:32 -04:00
< br >< br >
2015-09-12 00:46:46 -04:00
</ div >
</ td >
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
< ? php
2014-03-23 16:03:30 -04:00
} // END hesk_kbSearchSmall()
function hesk_detect_bots ()
{
2015-09-12 00:46:46 -04:00
$botlist = array ( 'googlebot' , 'msnbot' , 'slurp' , 'alexa' , 'teoma' , 'froogle' ,
'gigabot' , 'inktomi' , 'looksmart' , 'firefly' , 'nationaldirectory' ,
'ask jeeves' , 'tecnoseek' , 'infoseek' , 'webfindbot' , 'girafabot' ,
'crawl' , 'www.galaxy.com' , 'scooter' , 'appie' , 'fast' , 'webbug' , 'spade' , 'zyborg' , 'rabaz' ,
'baiduspider' , 'feedfetcher-google' , 'technoratisnoop' , 'rankivabot' ,
'mediapartners-google' , 'crawler' , 'spider' , 'robot' , 'bot/' , 'bot-' , 'voila' );
if ( ! isset ( $_SERVER [ 'HTTP_USER_AGENT' ])) {
return false ;
2014-03-23 16:03:30 -04:00
}
$ua = strtolower ( $_SERVER [ 'HTTP_USER_AGENT' ]);
2015-09-12 00:46:46 -04:00
foreach ( $botlist as $bot ) {
if ( strpos ( $ua , $bot ) !== false ) {
return true ;
2014-03-23 16:03:30 -04:00
}
}
2015-09-12 00:46:46 -04:00
return false ;
2014-03-23 16:03:30 -04:00
} // END hesk_detect_bots()