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.

2538 lines
107 KiB

5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. /*******************************************************************************
  3. * Title: Help Desk Software HESK
  4. * Version: 2.6.8 from 10th August 2016
  5. * Author: Klemen Stirn
  6. * Website: https://www.hesk.com
  7. ********************************************************************************
  8. * COPYRIGHT AND TRADEMARK NOTICE
  9. * Copyright 2005-2015 Klemen Stirn. All Rights Reserved.
  10. * HESK is a registered trademark of Klemen Stirn.
  11. * The HESK may be used and modified free of charge by anyone
  12. * AS LONG AS COPYRIGHT NOTICES AND ALL THE COMMENTS REMAIN INTACT.
  13. * By using this code you agree to indemnify Klemen Stirn from any
  14. * liability that might arise from it's use.
  15. * Selling the code for this program, in part or full, without prior
  16. * written consent is expressly forbidden.
  17. * Using this code, in part or full, to create derivate work,
  18. * new scripts or products is expressly forbidden. Obtain permission
  19. * before redistributing this software over the Internet or in
  20. * any other medium. In all cases copyright and header must remain intact.
  21. * This Copyright is in full effect in any country that has International
  22. * Trade Agreements with the United States of America or
  23. * with the European Union.
  24. * Removing any of the copyright notices without purchasing a license
  25. * is expressly forbidden. To remove HESK copyright notice you must purchase
  26. * a license for this script. For more information on how to obtain
  27. * a license please visit the page below:
  28. * https://www.hesk.com/buy.php
  29. *******************************************************************************/
  30. define('IN_SCRIPT',1);
  31. define('HESK_PATH','../');
  32. define('VALIDATOR', 1);
  33. define('PAGE_TITLE', 'ADMIN_KB');
  34. /* Get all the required files and functions */
  35. require(HESK_PATH . 'hesk_settings.inc.php');
  36. require(HESK_PATH . 'inc/common.inc.php');
  37. require(HESK_PATH . 'inc/admin_functions.inc.php');
  38. require(HESK_PATH . 'inc/view_attachment_functions.inc.php');
  39. require(HESK_PATH . 'inc/mail_functions.inc.php');
  40. hesk_load_database_functions();
  41. // Check for POST requests larger than what the server can handle
  42. if ( $_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST) && ! empty($_SERVER['CONTENT_LENGTH']) )
  43. {
  44. hesk_error($hesklang['maxpost']);
  45. }
  46. // For convenience allow adding at least 3 attachments at once in the KB
  47. if ($hesk_settings['attachments']['max_number'] < 3)
  48. {
  49. $hesk_settings['attachments']['max_number'] = 3;
  50. }
  51. hesk_session_start();
  52. hesk_dbConnect();
  53. hesk_isLoggedIn();
  54. $modsForHesk_settings = mfh_getSettings();
  55. /* Check permissions for this feature */
  56. if ( ! hesk_checkPermission('can_man_kb',0))
  57. {
  58. /* This person can't manage the knowledgebase, but can read it */
  59. header('Location: knowledgebase_private.php');
  60. exit();
  61. }
  62. /* Is Knowledgebase enabled? */
  63. if ( ! $hesk_settings['kb_enable'])
  64. {
  65. hesk_error($hesklang['kbdis']);
  66. }
  67. /* This will tell the header to include WYSIWYG editor Javascript */
  68. define('WYSIWYG',1);
  69. /* What should we do? */
  70. if ( $action = hesk_REQUEST('a') )
  71. {
  72. if ($action == 'add_article') {add_article();}
  73. elseif ($action == 'add_category') {add_category();}
  74. elseif ($action == 'manage_cat') {manage_category();}
  75. elseif ($action == 'edit_article') {edit_article();}
  76. elseif ($action == 'import_article') {import_article();}
  77. elseif ($action == 'list_private') {list_private();}
  78. elseif ($action == 'list_draft') {list_draft();}
  79. elseif ( defined('HESK_DEMO') ) {hesk_process_messages($hesklang['ddemo'], 'manage_knowledgebase.php', 'NOTICE');}
  80. elseif ($action == 'new_article') {new_article();}
  81. elseif ($action == 'new_category') {new_category();}
  82. elseif ($action == 'remove_article') {remove_article();}
  83. elseif ($action == 'save_article') {save_article();}
  84. elseif ($action == 'order_article') {order_article();}
  85. elseif ($action == 'order_cat') {order_category();}
  86. elseif ($action == 'edit_category') {edit_category();}
  87. elseif ($action == 'remove_kb_att') {remove_kb_att();}
  88. elseif ($action == 'sticky') {toggle_sticky();}
  89. elseif ($action == 'update_count') {update_count(1);}
  90. }
  91. // Part of a trick to prevent duplicate article submissions by reloading pages
  92. hesk_cleanSessionVars('article_submitted');
  93. /* Print header */
  94. require_once(HESK_PATH . 'inc/headerAdmin.inc.php');
  95. /* Print main manage users page */
  96. require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
  97. ?>
  98. <?php
  99. /* This will handle error, success and notice messages */
  100. #hesk_handle_messages();
  101. // Total number of KB articles
  102. $total_articles = 0;
  103. // Get number of sub-categories for each parent category
  104. $parent = array(0 => 1);
  105. $result = hesk_dbQuery('SELECT `parent`, COUNT(*) AS `num` FROM `'.hesk_dbEscape($hesk_settings['db_pfix']).'kb_categories` GROUP BY `parent`');
  106. while ($row = hesk_dbFetchAssoc($result))
  107. {
  108. $parent[$row['parent']] = $row['num'];
  109. }
  110. $parent_copy = $parent;
  111. //print_r($parent);
  112. // Get Knowledgebase structure
  113. $kb_cat = array();
  114. $result = hesk_dbQuery('SELECT * FROM `'.hesk_dbEscape($hesk_settings['db_pfix']).'kb_categories` ORDER BY `parent` ASC, `cat_order` ASC');
  115. while ($cat = hesk_dbFetchAssoc($result))
  116. {
  117. // Can this category be moved at all?
  118. if (
  119. $cat['id'] == 1 || // Main category cannot be moved
  120. ! isset($parent[$cat['parent']]) || // if the parent category isn't set
  121. $parent[$cat['parent']] < 2 // Less than 2 articles in category
  122. )
  123. {
  124. $cat['move_up'] = false;
  125. $cat['move_down'] = false;
  126. }
  127. else
  128. {
  129. $cat['move_up'] = true;
  130. $cat['move_down'] = true;
  131. }
  132. $kb_cat[] = $cat;
  133. }
  134. //print_r($kb_cat);
  135. /* Translate main category "Knowledgebase" if needed */
  136. $kb_cat[0]['name'] = $hesklang['kb_text'];
  137. require(HESK_PATH . 'inc/treemenu/TreeMenu.php');
  138. $icon = 'folder.gif';
  139. $expandedIcon = 'fa-folder-open" style="font-size:17px';
  140. $menu = new HTML_TreeMenu();
  141. $thislevel = array('0');
  142. $nextlevel = array();
  143. $i = 1;
  144. $j = 1;
  145. if (isset($_SESSION['KB_CATEGORY']))
  146. {
  147. $selected_catid = intval($_SESSION['KB_CATEGORY']);
  148. }
  149. else
  150. {
  151. $selected_catid = 0;
  152. }
  153. while (count($kb_cat) > 0)
  154. {
  155. foreach ($kb_cat as $k=>$cat)
  156. {
  157. if (in_array($cat['parent'],$thislevel))
  158. {
  159. $arrow = ($i - 2) % 10;
  160. $arrow = $arrow == 0 ? '' : $arrow;
  161. $up = $cat['parent'];
  162. $my = $cat['id'];
  163. $type = $cat['type'] ? '*' : '';
  164. $selected = ($selected_catid == $my) ? 1 : 0;
  165. $cls = (isset($_SESSION['newcat']) && $_SESSION['newcat'] == $my) ? ' class="kbCatListON"' : '';
  166. $text = str_replace('\\','\\\\','<span id="c_'.$my.'"'.$cls.'><a href="manage_knowledgebase.php?a=manage_cat&catid='.$my.'">'.$cat['name'].'</a>').$type.'</span> (<span class="kb_published">'.$cat['articles'].'</span>, <span class="kb_private">'.$cat['articles_private'].'</span>, <span class="kb_draft">'.$cat['articles_draft'].'</span>) '; /* ' */
  167. $text_short = $cat['name'].$type.' ('.$cat['articles'].', '.$cat['articles_private'].', '.$cat['articles_draft'].')';
  168. $total_articles += $cat['articles'];
  169. // Generate KB menu icons
  170. $menu_icons =
  171. '<a href="manage_knowledgebase.php?a=add_article&amp;catid='.$my.'" onclick="document.getElementById(\'option'.$j.'\').selected=true;return true;"><i class="fa fa-plus font-size-16p green" ></i></a> '
  172. .'<a href="manage_knowledgebase.php?a=add_category&amp;parent='.$my.'" onclick="document.getElementById(\'option'.$j.'_2\').selected=true;return true;"><i class="fa fa-caret-right font-size-16p blue"></i></a> '
  173. .'<a href="manage_knowledgebase.php?a=manage_cat&amp;catid='.$my.'"><i class="fa fa-gear font-size-16p gray"></i></a> '
  174. ;
  175. // Can this category be moved up?
  176. if ($cat['move_up'] == false || ($cat['move_up'] && $parent_copy[$cat['parent']] == $parent[$cat['parent']]) )
  177. {
  178. $menu_icons .= '<img src="../img/blank.gif" width="16" height="16" alt="" class="optionWhiteNbOFF" /> ';
  179. }
  180. else
  181. {
  182. $menu_icons .= '<a href="manage_knowledgebase.php?a=order_cat&amp;catid='.$my.'&amp;move=-15&amp;token=' . hesk_token_echo(0) . '"><i class="fa fa-arrow-up font-size-16p green"></i></a> ';
  183. }
  184. // Can this category be moved down?
  185. if ($cat['move_down'] == false || ($cat['move_down'] && $parent_copy[$cat['parent']] == 1) )
  186. {
  187. $menu_icons .= '<img src="../img/blank.gif" width="16" height="16" alt="" class="optionWhiteNbOFF" /> ';
  188. }
  189. else
  190. {
  191. $menu_icons .= '<a href="manage_knowledgebase.php?a=order_cat&amp;catid='.$my.'&amp;move=15&amp;token=' . hesk_token_echo(0) . '"><i class="fa fa-arrow-down font-size-16p green"></i></a> ';
  192. }
  193. if (isset($node[$up]))
  194. {
  195. $node[$my] = &$node[$up]->addItem(new HTML_TreeNode(array('hesk_selected' => $selected, 'text' => $text, 'text_short' => $text_short, 'menu_icons' => $menu_icons, 'hesk_catid' => $cat['id'], 'hesk_select' => 'option'.$j, 'icon' => $icon, 'expandedIcon' => $expandedIcon, 'expanded' => true)));
  196. }
  197. else
  198. {
  199. $node[$my] = new HTML_TreeNode(array('hesk_selected' => $selected, 'text' => $text, 'text_short' => $text_short, 'menu_icons' => $menu_icons, 'hesk_catid' => $cat['id'], 'hesk_select' => 'option'.$j, 'icon' => $icon, 'expandedIcon' => $expandedIcon, 'expanded' => true));
  200. }
  201. $nextlevel[] = $cat['id'];
  202. $parent_copy[$cat['parent']]--;
  203. $j++;
  204. unset($kb_cat[$k]);
  205. }
  206. }
  207. $thislevel = $nextlevel;
  208. $nextlevel = array();
  209. /* Break after 20 recursions to avoid hang-ups in case of any problems */
  210. if ($i > 20)
  211. {
  212. break;
  213. }
  214. $i++;
  215. }
  216. $menu->addItem($node[1]);
  217. // Create the presentation class
  218. $treeMenu = & ref_new(new HTML_TreeMenu_DHTML($menu, array('images' => '../img', 'defaultClass' => 'treeMenuDefault', 'isDynamic' => true)));
  219. $listBox = & ref_new(new HTML_TreeMenu_Listbox($menu));
  220. /* Hide new article and new category forms by default */
  221. if (!isset($_SESSION['hide']))
  222. {
  223. $_SESSION['hide'] = array(
  224. //'treemenu' => 1,
  225. 'new_article' => 1,
  226. 'new_category' => 1,
  227. );
  228. }
  229. echo '';
  230. /* Hide tree menu? */
  231. if (!isset($_SESSION['hide']['treemenu']))
  232. {
  233. ?>
  234. <section class="content">
  235. <h2>
  236. <?php echo $hesklang['kb']; ?>
  237. <a href="javascript:void(0)" onclick="javascript:alert('<?php echo hesk_makeJsString($hesklang['kb_intro']); ?>')">
  238. <i class="fa fa-question-circle settingsquestionmark"></i>
  239. </a>
  240. </h2>
  241. <?php
  242. show_subnav();
  243. // Show a notice if total public articles is less than 5
  244. if ($total_articles < 5)
  245. {
  246. hesk_show_notice($hesklang['nkba']);
  247. }
  248. ?>
  249. <div class="row">
  250. <div class="col-md-8">
  251. <?php show_treeMenu(); ?>
  252. </div>
  253. <div class="col-md-4">
  254. <div class="box">
  255. <div class="box-header with-border">
  256. <h1 class="box-title">
  257. <?php echo $hesklang['ktool']; ?>
  258. </h1>
  259. <div class="box-tools pull-right">
  260. <button type="button" class="btn btn-box-tool" data-widget="collapse">
  261. <i class="fa fa-minus"></i>
  262. </button>
  263. </div>
  264. </div>
  265. <div class="box-body">
  266. <ul class="list-unstyled">
  267. <li><i class="fa fa-search"></i> <a href="manage_knowledgebase.php?a=list_private"><?php echo $hesklang['listp']; ?></a></li>
  268. <li><i class="fa fa-search"></i> <a href="manage_knowledgebase.php?a=list_draft"><?php echo $hesklang['listd']; ?></a></li>
  269. <li><i class="fa fa-gear font-size-16p gray"></i> <a href="manage_knowledgebase.php?a=update_count"><?php echo $hesklang['uac']; ?></a></li>
  270. <li><i class="fa fa-globe font-size-16p"></i> <a href="http://support.mozilla.com/en-US/kb/how-to-write-knowledge-base-articles" rel="nofollow" target="_blank"><?php echo $hesklang['goodkb']; ?></a></li>
  271. </ul>
  272. </div>
  273. </div>
  274. </div>
  275. </div>
  276. </section>
  277. <?php
  278. } // END hide treemenu
  279. /* Hide article form? */
  280. if (!isset($_SESSION['hide']['new_article']))
  281. {
  282. if (isset($_SESSION['new_article']))
  283. {
  284. $_SESSION['new_article'] = hesk_stripArray($_SESSION['new_article']);
  285. }
  286. elseif ( isset($_GET['type']) )
  287. {
  288. $_SESSION['new_article']['type'] = intval( hesk_GET('type') );
  289. if ($_SESSION['new_article']['type'] != 1 && $_SESSION['new_article']['type'] != 2)
  290. {
  291. $_SESSION['new_article']['type'] = 0;
  292. }
  293. }
  294. ?>
  295. <ol class="breadcrumb">
  296. <li><a href="manage_knowledgebase.php"><?php echo $hesklang['kb']; ?></a></li>
  297. <li class="active"><?php echo $hesklang['new_kb_art']; ?></li>
  298. </ol>
  299. <?php
  300. if ($hesk_settings['kb_wysiwyg'])
  301. {
  302. ?>
  303. <script type="text/javascript">
  304. tinyMCE.init({
  305. mode : "exact",
  306. elements : "content",
  307. theme : "advanced",
  308. convert_urls : false,
  309. gecko_spellcheck: true,
  310. theme_advanced_buttons1 : "cut,copy,paste,|,undo,redo,|,formatselect,fontselect,fontsizeselect,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull",
  311. theme_advanced_buttons2 : "sub,sup,|,charmap,|,bullist,numlist,|,outdent,indent,insertdate,inserttime,preview,|,forecolor,backcolor,|,hr,removeformat,visualaid,|,link,unlink,anchor,image,cleanup,code",
  312. theme_advanced_buttons3 : "",
  313. theme_advanced_toolbar_location : "top",
  314. theme_advanced_toolbar_align : "left",
  315. theme_advanced_statusbar_location : "bottom",
  316. theme_advanced_resizing : true
  317. });
  318. </script>
  319. <?php
  320. }
  321. ?>
  322. <section class="content">
  323. <?php
  324. $catid = show_subnav('newa');
  325. $onsubmit = '';
  326. if ($hesk_settings['kb_wysiwyg']) {
  327. $onsubmit = 'onsubmit="return validateRichText(\'content-help-block\', \'content-group\', \'content\', \''.addslashes($hesklang['kb_e_cont']).'\')"';
  328. }
  329. ?>
  330. <form action="manage_knowledgebase.php" role="form" method="post" name="form1" enctype="multipart/form-data" data-toggle="validator" <?php echo $onsubmit; ?>>
  331. <div class="box">
  332. <div class="box-header with-border">
  333. <h1 class="box-title">
  334. <a name="new_article"></a><?php echo $hesklang['new_kb_art']; ?>
  335. </h1>
  336. <div class="box-tools pull-right">
  337. <button type="button" class="btn btn-box-tool" data-widget="collapse">
  338. <i class="fa fa-minus"></i>
  339. </button>
  340. </div>
  341. </div>
  342. <div class="box-body">
  343. <?php
  344. $displayType = $hesk_settings['kb_wysiwyg'] ? 'none' : 'block';
  345. $displayWarn = 'none';
  346. ?>
  347. <span id="contentType" style="display:<?php echo $displayType; ?>">
  348. <label><input type="radio" name="html" value="0" <?php if (!isset($_SESSION['new_article']['html']) || (isset($_SESSION['new_article']['html']) && $_SESSION['new_article']['html'] == 0) ) {echo 'checked="checked"';} ?> onclick="javascript:document.getElementById('kblinks').style.display = 'none'" /> <?php echo $hesklang['kb_dhtml']; ?></label><br />
  349. <label><input type="radio" name="html" value="1" <?php $display = 'none'; if (isset($_SESSION['new_article']['html']) && $_SESSION['new_article']['html'] == 1) {echo 'checked="checked"'; $displayWarn = 'block';} ?> onclick="javascript:document.getElementById('kblinks').style.display = 'block'" /> <?php echo $hesklang['kb_ehtml']; ?></label><br />
  350. <span id="kblinks" style="display:<?php echo $displayWarn; ?>"><i><?php echo $hesklang['kb_links']; ?></i></span>
  351. </span>
  352. <div class="form-group">
  353. <label for="subject" class="control-label"><?php echo $hesklang['kb_subject']; ?></label>
  354. <input type="text" class="form-control" placeholder="<?php echo htmlspecialchars($hesklang['kb_subject']); ?>" data-error="<?php echo htmlspecialchars($hesklang['kb_e_subj']); ?>"
  355. name="subject" size="70" maxlength="255" <?php if (isset($_SESSION['new_article']['subject'])) {echo 'value="'.$_SESSION['new_article']['subject'].'"';} ?> required>
  356. <div class="help-block with-errors"></div>
  357. </div>
  358. <div class="form-group" id="content-group">
  359. <textarea class="form-control" id="content" name="content" rows="25" cols="70" data-error="<?php echo htmlspecialchars($hesklang['kb_e_cont']); ?>" id="content" required><?php if (isset($_SESSION['new_article']['content'])) {echo $_SESSION['new_article']['content'];} ?></textarea>
  360. <div class="help-block with-errors" id="content-help-block"></div>
  361. </div>
  362. </div>
  363. </div>
  364. <div class="box">
  365. <div class="box-header with-border">
  366. <h1 class="box-title">
  367. <?php echo $hesklang['information']; ?>
  368. </h1>
  369. <div class="box-tools pull-right">
  370. <button type="button" class="btn btn-box-tool" data-widget="collapse">
  371. <i class="fa fa-minus"></i>
  372. </button>
  373. </div>
  374. </div>
  375. <div class="box-body">
  376. <div class="row">
  377. <div class="col-md-6">
  378. <div class="form-group">
  379. <label for="catid" class="control-label"><?php echo $hesklang['kb_cat']; ?></label>
  380. <select name="catid" class="form-control"><?php $listBox->printMenu(); ?></select>
  381. </div>
  382. <div class="form-group">
  383. <label for="type" class="control-label"><?php echo $hesklang['kb_type']; ?></label>
  384. <?php
  385. if (isset($_SESSION['new_article']['type']))
  386. {
  387. $selectedIndex = -1;
  388. } else
  389. {
  390. $modsForHesk_settings = mfh_getSettings();
  391. $selectedIndex = $modsForHesk_settings['new_kb_article_visibility'];
  392. }
  393. ?>
  394. <div class="radio">
  395. <label><input type="radio" name="type" value="0" <?php if ((isset($_SESSION['new_article']['type']) && $_SESSION['new_article']['type'] == 0) || $selectedIndex == 0) {echo 'checked="checked"';} ?> /> <?php echo $hesklang['kb_published']; ?> &nbsp;<a href="javascript:void(0)" onclick="javascript:alert('<?php echo $hesklang['kb_published2']; ?>')"><i class="fa fa-question-circle settingsquestionmark"></i></a></label>
  396. </div>
  397. <div class="radio">
  398. <label><input type="radio" name="type" value="1" <?php if ((isset($_SESSION['new_article']['type']) && $_SESSION['new_article']['type'] == 1) || $selectedIndex == 1) {echo 'checked="checked"';} ?> /> <?php echo $hesklang['kb_private']; ?>&nbsp;<a href="javascript:void(0)" onclick="javascript:alert('<?php echo $hesklang['kb_private2']; ?>')"><i class="fa fa-question-circle settingsquestionmark"></i></a></label>
  399. </div>
  400. <div class="radio">
  401. <label><input type="radio" name="type" value="2" <?php if ((isset($_SESSION['new_article']['type']) && $_SESSION['new_article']['type'] == 2) || $selectedIndex == 2) {echo 'checked="checked"';} ?> /> <?php echo $hesklang['kb_draft']; ?>&nbsp;<a href="javascript:void(0)" onclick="javascript:alert('<?php echo $hesklang['kb_draft2']; ?>')"><i class="fa fa-question-circle settingsquestionmark"></i></a></label>
  402. </div>
  403. </div>
  404. <div class="form-group">
  405. <label for="sticky" class="control-label"><?php echo $hesklang['opt']; ?></label>
  406. <div class="checkbox">
  407. <label><input type="checkbox" name="sticky" value="Y" <?php if ( ! empty($_SESSION['new_article']['sticky'])) {echo 'checked="checked"';} ?> /> <?php echo $hesklang['sticky']; ?> <a href="javascript:void(0)" onclick="javascript:alert('<?php echo hesk_makeJsString($hesklang['saa']); ?>')"><i class="fa fa-question-circle settingsquestionmark"></i></a></label>
  408. </div>
  409. </div>
  410. </div>
  411. <div class="col-md-6">
  412. <div class="form-group">
  413. <label for="keywords" class="control-label"><?php echo $hesklang['kw']; ?></label>
  414. <p class="font-size-90 form-control-static"><?php echo $hesklang['kw1']; ?></p><br/>
  415. <textarea name="keywords" class="form-control" rows="3" cols="70" id="keywords"><?php if (isset($_SESSION['new_article']['keywords'])) {echo $_SESSION['new_article']['keywords'];} ?></textarea>
  416. </div>
  417. <?php if ($hesk_settings['attachments']['use']): ?>
  418. <div class="form-group">
  419. <label for="attachments" class="control-label"><?php echo $hesklang['attachments']; ?> (<a href="Javascript:void(0)" onclick="Javascript:hesk_window('../file_limits.php',250,500);return false;"><?php echo $hesklang['ful']; ?></a>)</label>
  420. <?php build_dropzone_markup(true); ?>
  421. </div>
  422. <?php
  423. display_dropzone_field($hesk_settings['hesk_url'] . '/internal-api/admin/knowledgebase/upload-attachment.php');
  424. endif; // End attachments
  425. // Redirect to the correct page
  426. switch ($from)
  427. {
  428. case 'draft':
  429. $redirect_action = 'a=list_draft';
  430. break;
  431. case 'private':
  432. $redirect_action = 'a=list_private';
  433. break;
  434. default:
  435. $redirect_action = 'a=manage_cat&amp;catid='.$catid;
  436. break;
  437. }
  438. ?>
  439. </div>
  440. </div>
  441. </div>
  442. <div class="box-footer">
  443. <div class="form-group">
  444. <input type="hidden" name="a" value="new_article">
  445. <input type="hidden" name="token" value="<?php hesk_token_echo(); ?>">
  446. <input type="hidden" name="from" value="<?php echo $from; ?>">
  447. <div class="btn-group">
  448. <input type="submit" value="<?php echo $hesklang['kb_save']; ?>" class="btn btn-primary">
  449. <a class="btn btn-default" href="manage_knowledgebase.php?<?php echo $redirect_action; ?>"><?php echo $hesklang['cancel']; ?></a>
  450. </div>
  451. </div>
  452. </div>
  453. </div>
  454. </form>
  455. </section>
  456. <?php
  457. } // END hide article
  458. /* Hide new category form? */
  459. if (!isset($_SESSION['hide']['new_category']))
  460. {
  461. if (isset($_SESSION['new_category']))
  462. {
  463. $_SESSION['new_category'] = hesk_stripArray($_SESSION['new_category']);
  464. }
  465. ?>
  466. <ol class="breadcrumb">
  467. <li><a href="manage_knowledgebase.php"><?php echo $hesklang['kb']; ?></a></li>
  468. <li class="active"><?php echo $hesklang['kb_cat_new']; ?></li>
  469. </ol>
  470. <section class="content">
  471. <?php show_subnav('newc'); ?>
  472. <div class="row">
  473. <div class="col-md-5">
  474. <?php
  475. /* Show the treemenu? */
  476. if (isset($_SESSION['hide']['cat_treemenu']))
  477. {
  478. show_treeMenu();
  479. }
  480. ?>
  481. </div>
  482. <div class="col-md-7">
  483. <form action="manage_knowledgebase.php" class="form-horizontal" method="post" role="form" name="form2" data-toggle="validator">
  484. <div class="box">
  485. <div class="box-header with-border">
  486. <h1 class="box-title">
  487. <a name="new_category"></a><?php echo $hesklang['kb_cat_new']; ?>
  488. </h1>
  489. <div class="box-tools pull-right">
  490. <button type="button" class="btn btn-box-tool" data-widget="collapse">
  491. <i class="fa fa-minus"></i>
  492. </button>
  493. </div>
  494. </div>
  495. <div class="box-body">
  496. <div class="form-group">
  497. <label for="title" class="col-sm-3 control-label"><?php echo $hesklang['kb_cat_title']; ?></label>
  498. <div class="col-sm-9">
  499. <input type="text" class="form-control" name="title" size="70" maxlength="255" data-error="<?php echo htmlspecialchars($hesklang['kb_cat_e_title']); ?>" required>
  500. <div class="help-block with-errors"></div>
  501. </div>
  502. </div>
  503. <div class="form-group">
  504. <label for="parent" class="col-sm-3 control-label"><?php echo $hesklang['kb_cat_parent']; ?>:</label>
  505. <div class="col-sm-9">
  506. <select class="form-control" name="parent"><?php $listBox->printMenu()?></select>
  507. </div>
  508. </div>
  509. <div class="form-group">
  510. <label for="type" class="col-sm-3 control-label"><?php echo $hesklang['kb_type']; ?>:</label>
  511. <div class="col-sm-9">
  512. <div class="radio">
  513. <label><input type="radio" name="type" value="0" <?php if (!isset($_SESSION['new_category']['type']) || (isset($_SESSION['new_category']['type']) && $_SESSION['new_category']['type'] == 0) ) {echo 'checked="checked"';} ?> /> <b><i><?php echo $hesklang['kb_published']; ?></i></b></label>
  514. <p class="form-static-content"><?php echo $hesklang['kb_cat_published']; ?></p>
  515. </div>
  516. <div class="radio">
  517. <label><input type="radio" name="type" value="1" <?php if (isset($_SESSION['new_category']['type']) && $_SESSION['new_category']['type'] == 1) {echo 'checked="checked"';} ?> /> <b><i><?php echo $hesklang['kb_private']; ?></i></b></label>
  518. <p class="form-static-content"><?php echo $hesklang['kb_cat_private']; ?></p>
  519. </div>
  520. </div>
  521. </div>
  522. <div class="form-group">
  523. <div class="col-sm-9 col-sm-offset-3">
  524. <input type="hidden" name="a" value="new_category" />
  525. <input type="hidden" name="token" value="<?php hesk_token_echo(); ?>" />
  526. <div class="btn-group">
  527. <input type="submit" value="<?php echo $hesklang['kb_cat_add']; ?>" class="btn btn-primary" />
  528. <a class="btn btn-default" href="manage_knowledgebase.php"><?php echo $hesklang['cancel']; ?></a>
  529. </div>
  530. </div>
  531. </div>
  532. </div>
  533. </div>
  534. </form>
  535. </div>
  536. </div>
  537. </section>
  538. <?php
  539. } // END hide new category form
  540. /* Clean unneeded session variables */
  541. hesk_cleanSessionVars(array('hide','new_article','new_category','KB_CATEGORY','manage_cat','edit_article','newcat'));
  542. ?>
  543. <?php
  544. require_once(HESK_PATH . 'inc/footer.inc.php');
  545. exit();
  546. /*** START FUNCTIONS ***/
  547. function list_draft() {
  548. global $hesk_settings, $hesklang;
  549. $catid = 1;
  550. $kb_cat = hesk_getCategoriesArray(1);
  551. /* Translate main category "Knowledgebase" if needed */
  552. $kb_cat[0]['name'] = $hesklang['kb_text'];
  553. /* Print header */
  554. require_once(HESK_PATH . 'inc/headerAdmin.inc.php');
  555. /* Print main manage users page */
  556. require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
  557. ?>
  558. <ol class="breadcrumb">
  559. <li><a href="manage_knowledgebase.php"><?php echo $hesklang['kb']; ?></a></li>
  560. <li class="active"><?php echo $hesklang['kb_cat_man']; ?></li>
  561. </ol>
  562. <section class="content">
  563. <?php
  564. show_subnav('',$catid);
  565. $res = hesk_dbQuery("SELECT * FROM `". hesk_dbEscape($hesk_settings['db_pfix'])."kb_articles` WHERE `type`='2' ORDER BY `catid` ASC, `id` ASC");
  566. $num = hesk_dbNumRows($res);
  567. ?>
  568. <div class="box">
  569. <div class="box-header with-border">
  570. <h1 class="box-title">
  571. <?php echo $hesklang['artd']; ?>
  572. </h1>
  573. <div class="box-tools pull-right">
  574. <button type="button" class="btn btn-box-tool" data-widget="collapse">
  575. <i class="fa fa-minus"></i>
  576. </button>
  577. </div>
  578. </div>
  579. <div class="box-body">
  580. <?php
  581. if ($num == 0)
  582. {
  583. echo $hesklang['kb_no_dart'];
  584. }
  585. else
  586. {
  587. ?>
  588. <table class="table table-striped">
  589. <thead>
  590. <tr>
  591. <th>&nbsp;</th>
  592. <th><?php echo $hesklang['kb_subject']; ?></th>
  593. <th><?php echo $hesklang['kb_cat']; ?></th>
  594. <th><?php echo $hesklang['opt']; ?></th>
  595. </tr>
  596. </thead>
  597. <?php
  598. $j=1;
  599. while ($article = hesk_dbFetchAssoc($res))
  600. {
  601. if (isset($_SESSION['artord']) && $article['id'] == $_SESSION['artord'])
  602. {
  603. unset($_SESSION['artord']);
  604. }
  605. // Check for articles with no existing parent category
  606. if ( ! isset($kb_cat[$article['catid']]) )
  607. {
  608. $article['catid'] = hesk_stray_article($article['id']);
  609. }
  610. ?>
  611. <tr>
  612. <td><?php echo $j; ?>.</td>
  613. <td><?php echo $article['subject']; ?></td>
  614. <td><?php echo $kb_cat[$article['catid']]; ?></td>
  615. <td style="white-space:nowrap;">
  616. <a href="knowledgebase_private.php?article=<?php echo $article['id']; ?>&amp;back=1<?php if ($article['type'] == 2) {echo '&amp;draft=1';} ?>" target="_blank"><i class="fa fa-file-o" data-toggle="tooltip" title="<?php echo $hesklang['viewart']; ?>"></i></a>
  617. <a href="manage_knowledgebase.php?a=edit_article&amp;id=<?php echo $article['id']; ?>&amp;from=draft"><i class="fa fa-pencil icon-link orange" data-toggle="tooltip" title="<?php echo $hesklang['edit']; ?>"></i></a>
  618. <a href="manage_knowledgebase.php?a=remove_article&amp;id=<?php echo $article['id']; ?>&amp;token=<?php hesk_token_echo(); ?>&amp;from=draft" onclick="return hesk_confirmExecute('<?php echo hesk_makeJsString($hesklang['del_art']); ?>');"><i class="fa fa-times icon-link red" data-toggle="tooltip" title="<?php echo $hesklang['delete']; ?>"></i></a></td>
  619. </tr>
  620. <?php
  621. $j++;
  622. } // End while
  623. ?>
  624. </table>
  625. <?php
  626. }
  627. ?>
  628. </div>
  629. <div class="box-footer">
  630. <a class="btn btn-success" href="manage_knowledgebase.php?a=add_article&amp;catid=<?php echo $catid; ?>&amp;type=2">
  631. <i class="fa fa-plus"></i>
  632. <?php echo $hesklang['kb_i_art2']; ?>
  633. </a>
  634. </div>
  635. </div>
  636. </section>
  637. <?php
  638. echo '&nbsp;<br />&nbsp;';
  639. /* Clean unneeded session variables */
  640. hesk_cleanSessionVars(array('hide','manage_cat','edit_article'));
  641. require_once(HESK_PATH . 'inc/footer.inc.php');
  642. exit();
  643. } // END list_draft()
  644. function list_private() {
  645. global $hesk_settings, $hesklang;
  646. $catid = 1;
  647. $kb_cat = hesk_getCategoriesArray(1);
  648. /* Translate main category "Knowledgebase" if needed */
  649. $kb_cat[0]['name'] = $hesklang['kb_text'];
  650. /* Get list of private categories */
  651. $private_categories = array();
  652. $res = hesk_dbQuery("SELECT `id` FROM `". hesk_dbEscape($hesk_settings['db_pfix'])."kb_categories` WHERE `type`='1'");
  653. $num = hesk_dbNumRows($res);
  654. if ($num)
  655. {
  656. while ($row = hesk_dbFetchAssoc($res))
  657. {
  658. $private_categories[] = intval($row['id']);
  659. }
  660. }
  661. /* Print header */
  662. require_once(HESK_PATH . 'inc/headerAdmin.inc.php');
  663. /* Print main manage users page */
  664. require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
  665. $res = hesk_dbQuery("SELECT * FROM `". hesk_dbEscape($hesk_settings['db_pfix'])."kb_articles` WHERE `type`='1' " . (count($private_categories) ? " OR `catid` IN('" . implode("','", $private_categories) . "') " : '') . " ORDER BY `catid` ASC, `id` ASC");
  666. $num = hesk_dbNumRows($res);
  667. ?>
  668. <ol class="breadcrumb">
  669. <li><a href="manage_knowledgebase.php"><?php echo $hesklang['kb']; ?></a></li>
  670. <li class="active"><?php echo $hesklang['kb_cat_man']; ?></li>
  671. </ol>
  672. <section class="content">
  673. <?php show_subnav('',$catid); ?>
  674. <div class="box">
  675. <div class="box-header with-border">
  676. <h1 class="box-title">
  677. <?php echo $hesklang['artp']; ?>
  678. </h1>
  679. <div class="box-tools pull-right">
  680. <button type="button" class="btn btn-box-tool" data-widget="collapse">
  681. <i class="fa fa-minus"></i>
  682. </button>
  683. </div>
  684. </div>
  685. <div class="box-body">
  686. <?php
  687. if ($num == 0)
  688. {
  689. echo '<p>'.$hesklang['kb_no_part'].'</p>';
  690. }
  691. else
  692. {
  693. ?>
  694. <table class="table table-striped">
  695. <thead>
  696. <tr>
  697. <th>&nbsp;</th>
  698. <th><?php echo $hesklang['kb_subject']; ?></th>
  699. <th><?php echo $hesklang['kb_cat']; ?></th>
  700. <th><?php echo $hesklang['views']; ?></th>
  701. <?php
  702. if ($hesk_settings['kb_rating'])
  703. {
  704. ?>
  705. <th style="white-space:nowrap" nowrap="nowrap" width="130"><?php echo $hesklang['rating'].' ('.$hesklang['votes'].')'; ?></th>
  706. <?php
  707. }
  708. ?>
  709. <th style="width:120px"><?php echo $hesklang['opt']; ?></th>
  710. </tr>
  711. </thead>
  712. <?php
  713. $i=1;
  714. $j=1;
  715. while ($article = hesk_dbFetchAssoc($res))
  716. {
  717. if (isset($_SESSION['artord']) && $article['id'] == $_SESSION['artord'])
  718. {
  719. unset($_SESSION['artord']);
  720. }
  721. // Check for articles with no existing parent category
  722. if ( ! isset($kb_cat[$article['catid']]) )
  723. {
  724. $article['catid'] = hesk_stray_article($article['id']);
  725. }
  726. $tmp = $i ? 'White' : 'Blue';
  727. $i = $i ? 0 : 1;
  728. if ($hesk_settings['kb_rating'])
  729. {
  730. $alt = $article['rating'] ? sprintf($hesklang['kb_rated'], sprintf("%01.1f", $article['rating'])) : $hesklang['kb_not_rated'];
  731. $rat = '<td><span data-toggle="tooltip" title="' . $alt . '">' . mfh_get_stars(hesk_round_to_half($article['rating'])) . '</span> (' . $article['votes'] . ')</td>';
  732. }
  733. else
  734. {
  735. $rat = '';
  736. }
  737. ?>
  738. <tr>
  739. <td><?php echo $j; ?>.</td>
  740. <td><?php echo $article['subject']; ?></td>
  741. <td><?php echo $kb_cat[$article['catid']]; ?></td>
  742. <td><?php echo $article['views']; ?></td>
  743. <?php echo $rat; ?>
  744. <td class="text-center">
  745. <a href="knowledgebase_private.php?article=<?php echo $article['id']; ?>&amp;back=1<?php if ($article['type'] == 2) {echo '&amp;draft=1';} ?>" target="_blank"><i class="fa fa-file-o icon-link" data-toggle="tooltip" title="<?php echo $hesklang['viewart']; ?>"></i></a>
  746. <a href="manage_knowledgebase.php?a=edit_article&amp;id=<?php echo $article['id']; ?>&amp;from=private"><i class="fa fa-pencil icon-link orange" data-toggle="tooltip" title="<?php echo $hesklang['edit']; ?>"></i></a>
  747. <a href="manage_knowledgebase.php?a=remove_article&amp;id=<?php echo $article['id']; ?>&amp;token=<?php hesk_token_echo(); ?>&amp;from=private" onclick="return hesk_confirmExecute('<?php echo hesk_makeJsString($hesklang['del_art']); ?>');"><i class="fa fa-times red icon-link" data-toggle="tooltip" title="<?php echo $hesklang['delete']; ?>"></i></a>&nbsp;</td>
  748. </tr>
  749. <?php
  750. $j++;
  751. } // End while
  752. ?>
  753. </table>
  754. <?php
  755. }
  756. ?>
  757. </div>
  758. <div class="box-footer">
  759. <a class="btn btn-success" href="manage_knowledgebase.php?a=add_article&amp;catid=<?php echo $catid; ?>&amp;type=1">
  760. <i class="fa fa-plus"></i>
  761. <?php echo $hesklang['kb_i_art2']; ?>
  762. </a>
  763. </div>
  764. </div>
  765. </section>
  766. <?php
  767. echo '&nbsp;<br />&nbsp;';
  768. /* Clean unneeded session variables */
  769. hesk_cleanSessionVars(array('hide','manage_cat','edit_article'));
  770. require_once(HESK_PATH . 'inc/footer.inc.php');
  771. exit();
  772. } // END list_private()
  773. function import_article()
  774. {
  775. global $hesk_settings, $hesklang, $listBox;
  776. $_SESSION['hide'] = array(
  777. 'treemenu' => 1,
  778. //'new_article' => 1,
  779. 'new_category' => 1,
  780. );
  781. $_SESSION['KB_CATEGORY'] = 1;
  782. // Get ticket ID
  783. $trackingID = hesk_cleanID();
  784. if (empty($trackingID))
  785. {
  786. return false;
  787. }
  788. // Get ticket info
  789. $res = hesk_dbQuery("SELECT `id`,`category`,`subject`,`message`,`owner` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` WHERE `trackid`='".hesk_dbEscape($trackingID)."' LIMIT 1");
  790. if (hesk_dbNumRows($res) != 1)
  791. {
  792. return false;
  793. }
  794. $ticket = hesk_dbFetchAssoc($res);
  795. // Permission to view this ticket?
  796. if ($ticket['owner'] && $ticket['owner'] != $_SESSION['id'] && ! hesk_checkPermission('can_view_ass_others',0))
  797. {
  798. return false;
  799. }
  800. if ( ! $ticket['owner'] && ! hesk_checkPermission('can_view_unassigned',0))
  801. {
  802. return false;
  803. }
  804. // Is this user allowed to view tickets inside this category?
  805. if ( ! hesk_okCategory($ticket['category'],0))
  806. {
  807. return false;
  808. }
  809. // Set article contents
  810. if ($hesk_settings['kb_wysiwyg'])
  811. {
  812. // With WYSIWYG editor
  813. $_SESSION['new_article'] = array(
  814. 'html' => 1,
  815. 'subject' => $ticket['subject'],
  816. 'content' => hesk_htmlspecialchars($ticket['message']),
  817. );
  818. }
  819. else
  820. {
  821. // Without WYSIWYG editor *
  822. $_SESSION['new_article'] = array(
  823. 'html' => 0,
  824. 'subject' => $ticket['subject'],
  825. 'content' => hesk_msgToPlain($ticket['message']),
  826. );
  827. }
  828. // Get messages from replies to the ticket
  829. $res = hesk_dbQuery("SELECT `message` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."replies` WHERE `replyto`='".intval($ticket['id'])."' ORDER BY `id` ASC");
  830. while ($reply=hesk_dbFetchAssoc($res))
  831. {
  832. if ($hesk_settings['kb_wysiwyg'])
  833. {
  834. $_SESSION['new_article']['content'] .= "<br /><br />" . hesk_htmlspecialchars($reply['message']);
  835. }
  836. else
  837. {
  838. $_SESSION['new_article']['content'] .= "\n\n" . hesk_msgToPlain($reply['message']);
  839. }
  840. }
  841. hesk_process_messages($hesklang['import'],'NOREDIRECT','NOTICE');
  842. } // END add_article()
  843. function add_article()
  844. {
  845. global $hesk_settings, $hesklang;
  846. $_SESSION['hide'] = array(
  847. 'treemenu' => 1,
  848. //'new_article' => 1,
  849. 'new_category' => 1,
  850. );
  851. $_SESSION['KB_CATEGORY'] = intval( hesk_GET('catid', 1) );
  852. } // END add_article()
  853. function add_category()
  854. {
  855. global $hesk_settings, $hesklang;
  856. $_SESSION['hide'] = array(
  857. 'treemenu' => 1,
  858. 'new_article' => 1,
  859. //'new_category' => 1,
  860. 'cat_treemenu' => 1,
  861. );
  862. $_SESSION['KB_CATEGORY'] = intval( hesk_GET('parent', 1) );
  863. } // END add_category()
  864. function remove_kb_att()
  865. {
  866. global $hesk_settings, $hesklang;
  867. // A security check
  868. hesk_token_check();
  869. $att_id = intval( hesk_GET('kb_att') ) or hesk_error($hesklang['inv_att_id']);
  870. $id = intval( hesk_GET('id', 1) );
  871. // Get attachment details
  872. $res = hesk_dbQuery("SELECT * FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_attachments` WHERE `att_id`='".intval($att_id)."'");
  873. // Does the attachment exist?
  874. if ( hesk_dbNumRows($res) != 1 )
  875. {
  876. hesk_process_messages($hesklang['inv_att_id'], 'manage_knowledgebase.php');
  877. }
  878. $att = hesk_dbFetchAssoc($res);
  879. // Delete the file if it exists
  880. hesk_unlink(HESK_PATH.$hesk_settings['attach_dir'].'/'.$att['saved_name']);
  881. hesk_dbQuery("DELETE FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_attachments` WHERE `att_id`='".intval($att_id)."'");
  882. $res = hesk_dbQuery("SELECT * FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_articles` WHERE `id`='".intval($id)."'");
  883. $art = hesk_dbFetchAssoc($res);
  884. // Make log entry
  885. $revision = sprintf($hesklang['thist12'],hesk_date(),$att['real_name'],$_SESSION['name'].' ('.$_SESSION['user'].')');
  886. // Remove attachment from article
  887. $art['attachments'] = str_replace($att_id.'#'.$att['real_name'].',','',$art['attachments']);
  888. hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_articles` SET `attachments`='".hesk_dbEscape($art['attachments'])."', `history`=CONCAT(`history`,'".hesk_dbEscape($revision)."') WHERE `id`='".intval($id)."'");
  889. hesk_process_messages($hesklang['kb_att_rem'],'manage_knowledgebase.php?a=edit_article&id='.$id,'SUCCESS');
  890. } // END remove_kb_att()
  891. function edit_category()
  892. {
  893. global $hesk_settings, $hesklang;
  894. /* A security check */
  895. hesk_token_check('POST');
  896. $_SESSION['hide'] = array(
  897. 'article_list' => 1,
  898. );
  899. $hesk_error_buffer = array();
  900. $catid = intval( hesk_POST('catid') ) or hesk_error($hesklang['kb_cat_inv']);
  901. $title = hesk_input( hesk_POST('title') ) or $hesk_error_buffer[] = $hesklang['kb_cat_e_title'];
  902. $parent = intval( hesk_POST('parent', 1) );
  903. $type = empty($_POST['type']) ? 0 : 1;
  904. /* Category can't be it's own parent */
  905. if ($parent == $catid)
  906. {
  907. $hesk_error_buffer[] = $hesklang['kb_spar'];
  908. }
  909. /* Any errors? */
  910. if (count($hesk_error_buffer))
  911. {
  912. $_SESSION['manage_cat'] = array(
  913. 'type' => $type,
  914. 'parent' => $parent,
  915. 'title' => $title,
  916. );
  917. $tmp = '';
  918. foreach ($hesk_error_buffer as $error)
  919. {
  920. $tmp .= "<li>$error</li>\n";
  921. }
  922. $hesk_error_buffer = $tmp;
  923. $hesk_error_buffer = $hesklang['rfm'].'<br /><br /><ul>'.$hesk_error_buffer.'</ul>';
  924. hesk_process_messages($hesk_error_buffer,'./manage_knowledgebase.php?a=manage_cat&catid='.$catid);
  925. }
  926. /* Delete category or just update it? */
  927. if ( hesk_POST('dodelete')=='Y')
  928. {
  929. // Delete contents
  930. if ( hesk_POST('movearticles') == 'N')
  931. {
  932. // Delete all articles and all subcategories
  933. delete_category_recursive($catid);
  934. }
  935. // Move contents
  936. else
  937. {
  938. // -> Update category of articles in the category we are deleting
  939. hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_articles` SET `catid`=".intval($parent)." WHERE `catid`='".intval($catid)."'");
  940. // -> Update parent category of subcategories
  941. hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_categories` SET `parent`=".intval($parent)." WHERE `parent`='".intval($catid)."'");
  942. // -> Update article counts to make sure they are correct
  943. update_count();
  944. }
  945. // Now delete the category
  946. hesk_dbQuery("DELETE FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_categories` WHERE `id`='".intval($catid)."'");
  947. $_SESSION['hide'] = array(
  948. //'treemenu' => 1,
  949. 'new_article' => 1,
  950. 'new_category' => 1,
  951. );
  952. hesk_process_messages($hesklang['kb_cat_dlt'],'./manage_knowledgebase.php','SUCCESS');
  953. }
  954. hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_categories` SET `name`='".hesk_dbEscape($title)."',`parent`=".intval($parent).",`type`='".intval($type)."' WHERE `id`='".intval($catid)."'");
  955. unset($_SESSION['hide']);
  956. hesk_process_messages($hesklang['your_cat_mod'],'./manage_knowledgebase.php?a=manage_cat&catid='.$catid,'SUCCESS');
  957. } // END edit_category()
  958. function save_article()
  959. {
  960. global $hesk_settings, $hesklang, $hesk_error_buffer;
  961. /* A security check */
  962. hesk_token_check('POST');
  963. $hesk_error_buffer = array();
  964. $id = intval( hesk_POST('id') ) or hesk_error($hesklang['kb_art_id']);
  965. $catid = intval( hesk_POST('catid', 1) );
  966. $type = intval( hesk_POST('type') );
  967. $type = ($type < 0 || $type > 2) ? 0 : $type;
  968. $html = $hesk_settings['kb_wysiwyg'] ? 1 : (empty($_POST['html']) ? 0 : 1);
  969. $now = hesk_date();
  970. $old_catid = intval( hesk_POST('old_catid') );
  971. $old_type = intval( hesk_POST('old_type') );
  972. $old_type = ($old_type < 0 || $old_type > 2) ? 0 : $old_type;
  973. $from = hesk_POST('from');
  974. $subject = hesk_input( hesk_POST('subject') ) or $hesk_error_buffer[] = $hesklang['kb_e_subj'];
  975. if ($html)
  976. {
  977. if (empty($_POST['content']))
  978. {
  979. $hesk_error_buffer[] = $hesklang['kb_e_cont'];
  980. }
  981. $content = hesk_getHTML( hesk_POST('content') );
  982. // Clean the HTML code
  983. require(HESK_PATH . 'inc/htmlpurifier/HeskHTMLPurifier.php');
  984. $purifier = new HeskHTMLPurifier($hesk_settings['cache_dir']);
  985. $content = $purifier->heskPurify($content);
  986. }
  987. else
  988. {
  989. $content = hesk_input( hesk_POST('content') ) or $hesk_error_buffer[] = $hesklang['kb_e_cont'];
  990. $content = nl2br($content);
  991. $content = hesk_makeURL($content);
  992. }
  993. $sticky = isset($_POST['sticky']) ? 1 : 0;
  994. $keywords = hesk_input( hesk_POST('keywords') );
  995. $extra_sql = '';
  996. if ( hesk_POST('resetviews')=='Y')
  997. {
  998. $extra_sql .= ',`views`=0 ';
  999. }
  1000. if (hesk_POST('resetvotes')=='Y')
  1001. {
  1002. $extra_sql .= ',`votes`=0, `rating`=0 ';
  1003. }
  1004. /* Article attachments */
  1005. define('KB',1);
  1006. require_once(HESK_PATH . 'inc/posting_functions.inc.php');
  1007. $attachments = array();
  1008. $use_legacy_attachments = hesk_POST('use-legacy-attachments', 0);
  1009. $myattachments='';
  1010. if ($hesk_settings['attachments']['use']) {
  1011. require_once(HESK_PATH . 'inc/attachments.inc.php');
  1012. if ($use_legacy_attachments) {
  1013. for ($i=1; $i<=$hesk_settings['attachments']['max_number']; $i++)
  1014. {
  1015. $att = hesk_uploadFile($i);
  1016. if ( ! empty($att))
  1017. {
  1018. $attachments[$i] = $att;
  1019. }
  1020. }
  1021. } else {
  1022. // The user used the new drag-and-drop system.
  1023. $temp_attachment_ids = hesk_POST_array('attachment-ids');
  1024. foreach ($temp_attachment_ids as $temp_attachment_id) {
  1025. // Simply get the temp info and move it to the attachments table
  1026. $temp_attachment = mfh_getTemporaryAttachment($temp_attachment_id);
  1027. $attachments[] = $temp_attachment;
  1028. mfh_deleteTemporaryAttachment($temp_attachment_id);
  1029. }
  1030. }
  1031. }
  1032. /* Any errors? */
  1033. if (count($hesk_error_buffer))
  1034. {
  1035. // Remove any successfully uploaded attachments
  1036. if ($hesk_settings['attachments']['use'])
  1037. {
  1038. hesk_removeAttachments($attachments);
  1039. }
  1040. $_SESSION['edit_article'] = array(
  1041. 'type' => $type,
  1042. 'html' => $html,
  1043. 'subject' => $subject,
  1044. 'content' => hesk_input( hesk_POST('content') ),
  1045. 'keywords' => $keywords,
  1046. 'catid' => $catid,
  1047. 'sticky' => $sticky,
  1048. 'resetviews' => (isset($_POST['resetviews']) ? 'Y' : 0),
  1049. 'resetvotes' => (isset($_POST['resetvotes']) ? 'Y' : 0),
  1050. );
  1051. $tmp = '';
  1052. foreach ($hesk_error_buffer as $error)
  1053. {
  1054. $tmp .= "<li>$error</li>\n";
  1055. }
  1056. $hesk_error_buffer = $tmp;
  1057. $hesk_error_buffer = $hesklang['rfm'].'<br /><br /><ul>'.$hesk_error_buffer.'</ul>';
  1058. hesk_process_messages($hesk_error_buffer,'./manage_knowledgebase.php?a=edit_article&id='.$id.'&from='.$from);
  1059. }
  1060. /* Add to database */
  1061. if (!empty($attachments))
  1062. {
  1063. foreach ($attachments as $myatt)
  1064. {
  1065. hesk_dbQuery("INSERT INTO `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_attachments` (`saved_name`,`real_name`,`size`) VALUES ('".hesk_dbEscape($myatt['saved_name'])."', '".hesk_dbEscape($myatt['real_name'])."', '".intval($myatt['size'])."')");
  1066. $myattachments .= hesk_dbInsertID() . '#' . $myatt['real_name'] .',';
  1067. }
  1068. $extra_sql .= ", `attachments` = CONCAT(`attachments`, '".$myattachments."') ";
  1069. }
  1070. /* Update article in the database */
  1071. $revision = sprintf($hesklang['revision2'],$now,$_SESSION['name'].' ('.$_SESSION['user'].')');
  1072. hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_articles` SET
  1073. `catid`=".intval($catid).",
  1074. `subject`='".hesk_dbEscape($subject)."',
  1075. `content`='".hesk_dbEscape($content)."',
  1076. `keywords`='".hesk_dbEscape($keywords)."' $extra_sql ,
  1077. `type`='".intval($type)."',
  1078. `html`='".intval($html)."',
  1079. `sticky`='".intval($sticky)."',
  1080. `history`=CONCAT(`history`,'".hesk_dbEscape($revision)."')
  1081. WHERE `id`='".intval($id)."'");
  1082. $_SESSION['artord'] = $id;
  1083. // Update proper category article count
  1084. // (just do them all to be sure, don't compliate...)
  1085. update_count();
  1086. // Update article order
  1087. update_article_order($catid);
  1088. // Redirect to the correct page
  1089. switch ($from) {
  1090. case 'draft':
  1091. $redirect_action = 'a=list_draft';
  1092. break;
  1093. case 'private':
  1094. $redirect_action = 'a=list_private';
  1095. break;
  1096. default:
  1097. $redirect_action = 'a=manage_cat&catid='.$catid;
  1098. break;
  1099. }
  1100. hesk_process_messages($hesklang['your_kb_mod'],'./manage_knowledgebase.php?'.$redirect_action,'SUCCESS');
  1101. } // END save_article()
  1102. function edit_article()
  1103. {
  1104. global $hesk_settings, $hesklang, $listBox;
  1105. $hesk_error_buffer = array();
  1106. $id = intval( hesk_GET('id') ) or hesk_process_messages($hesklang['kb_art_id'],'./manage_knowledgebase.php');
  1107. /* Get article details */
  1108. $result = hesk_dbQuery("SELECT * FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_articles` WHERE `id`='".intval($id)."' LIMIT 1");
  1109. if (hesk_dbNumRows($result) != 1)
  1110. {
  1111. hesk_process_messages($hesklang['kb_art_id'],'./manage_knowledgebase.php');
  1112. }
  1113. $article = hesk_dbFetchAssoc($result);
  1114. if ($hesk_settings['kb_wysiwyg'] || $article['html'])
  1115. {
  1116. $article['content'] = hesk_htmlspecialchars($article['content']);
  1117. }
  1118. else
  1119. {
  1120. $article['content'] = hesk_msgToPlain($article['content']);
  1121. }
  1122. $catid = $article['catid'];
  1123. $from = hesk_GET('from');
  1124. if (isset($_SESSION['edit_article']))
  1125. {
  1126. $_SESSION['edit_article'] = hesk_stripArray($_SESSION['edit_article']);
  1127. $article['type'] = $_SESSION['edit_article']['type'];
  1128. $article['html'] = $_SESSION['edit_article']['html'];
  1129. $article['subject'] = $_SESSION['edit_article']['subject'];
  1130. $article['content'] = $_SESSION['edit_article']['content'];
  1131. $article['keywords'] = $_SESSION['edit_article']['keywords'];
  1132. $article['catid'] = $_SESSION['edit_article']['catid'];
  1133. $article['sticky'] = $_SESSION['edit_article']['sticky'];
  1134. }
  1135. /* Get categories */
  1136. $result = hesk_dbQuery('SELECT * FROM `'.hesk_dbEscape($hesk_settings['db_pfix']).'kb_categories` ORDER BY `parent` ASC, `cat_order` ASC');
  1137. $kb_cat = array();
  1138. while ($cat = hesk_dbFetchAssoc($result))
  1139. {
  1140. $kb_cat[] = $cat;
  1141. if ($cat['id'] == $article['catid'])
  1142. {
  1143. $this_cat = $cat;
  1144. $this_cat['parent'] = $article['catid'];
  1145. }
  1146. }
  1147. /* Translate main category "Knowledgebase" if needed */
  1148. $kb_cat[0]['name'] = $hesklang['kb_text'];
  1149. require(HESK_PATH . 'inc/treemenu/TreeMenu.php');
  1150. $icon = HESK_PATH . 'img/folder.gif';
  1151. $expandedIcon = 'fa-folder-open" style="font-size:17px';
  1152. $menu = new HTML_TreeMenu();
  1153. $thislevel = array('0');
  1154. $nextlevel = array();
  1155. $i = 1;
  1156. $j = 1;
  1157. while (count($kb_cat) > 0)
  1158. {
  1159. foreach ($kb_cat as $k=>$cat)
  1160. {
  1161. if (in_array($cat['parent'],$thislevel))
  1162. {
  1163. $up = $cat['parent'];
  1164. $my = $cat['id'];
  1165. $type = $cat['type'] ? '*' : '';
  1166. $text_short = $cat['name'].$type.' ('.$cat['articles'].', '.$cat['articles_private'].', '.$cat['articles_draft'].')';
  1167. if (isset($node[$up]))
  1168. {
  1169. $node[$my] = &$node[$up]->addItem(new HTML_TreeNode(array('hesk_parent' => $this_cat['parent'], 'text' => 'Text', 'text_short' => $text_short, 'hesk_catid' => $cat['id'], 'hesk_select' => 'option'.$j, 'icon' => $icon, 'expandedIcon' => $expandedIcon, 'expanded' => true)));
  1170. }
  1171. else
  1172. {
  1173. $node[$my] = new HTML_TreeNode(array('hesk_parent' => $this_cat['parent'], 'text' => 'Text', 'text_short' => $text_short, 'hesk_catid' => $cat['id'], 'hesk_select' => 'option'.$j, 'icon' => $icon, 'expandedIcon' => $expandedIcon, 'expanded' => true));
  1174. }
  1175. $nextlevel[] = $cat['id'];
  1176. $j++;
  1177. unset($kb_cat[$k]);
  1178. }
  1179. }
  1180. $thislevel = $nextlevel;
  1181. $nextlevel = array();
  1182. /* Break after 20 recursions to avoid hang-ups in case of any problems */
  1183. if ($i > 20)
  1184. {
  1185. break;
  1186. }
  1187. $i++;
  1188. }
  1189. $menu->addItem($node[1]);
  1190. // Create the presentation class
  1191. $listBox = & ref_new(new HTML_TreeMenu_Listbox($menu));
  1192. /* Print header */
  1193. require_once(HESK_PATH . 'inc/headerAdmin.inc.php');
  1194. /* Print main manage users page */
  1195. require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
  1196. ?>
  1197. <ol class="breadcrumb">
  1198. <li><a href="manage_knowledgebase.php"><?php echo $hesklang['kb']; ?></a></li>
  1199. <li><a href="manage_knowledgebase.php?a=manage_cat&amp;catid=<?php echo $catid; ?>"><?php echo $hesklang['kb_cat_man']; ?></a></li>
  1200. <li class="active"><?php echo $hesklang['kb_art_edit']; ?></li>
  1201. </ol>
  1202. <h3 class="move-right-10"><?php echo $hesklang['kb_art_edit']; ?></h3>
  1203. <div class="footerWithBorder blankSpace move-right-10 move-left-10"></div>
  1204. <?php
  1205. $onsubmit = '';
  1206. if ($hesk_settings['kb_wysiwyg']) {
  1207. $onsubmit = 'onsubmit="return validateRichText(\'content-help-block\', \'content-group\', \'content\', \''.addslashes($hesklang['kb_e_cont']).'\')"';
  1208. }
  1209. ?>
  1210. <form action="manage_knowledgebase.php" role="form" method="post" name="form1" enctype="multipart/form-data" data-toggle="validator" <?php echo $onsubmit; ?>>
  1211. <div class="row">
  1212. <div class="col-md-3">
  1213. <div class="panel panel-default move-right-10">
  1214. <div class="panel-heading"><?php echo $hesklang['information']; ?></div>
  1215. <div class="panel-body">
  1216. <div class="form-group">
  1217. <label for="catid" class="control-label"><?php echo $hesklang['kb_cat']; ?></label>
  1218. <select class="form-control" name="catid"><?php $listBox->printMenu()?></select>
  1219. </div>
  1220. <div class="form-group">
  1221. <label for="type" class="control-label"><?php echo $hesklang['kb_type']; ?></label>
  1222. <div class="radio">
  1223. <label><input type="radio" name="type" value="0" <?php if ($article['type']==0) {echo 'checked="checked"';} ?> /> <?php echo $hesklang['kb_published']; ?><a href="javascript:void(0)" onclick="javascript:alert('<?php echo $hesklang['kb_published2']; ?>')">&nbsp;<i class="fa fa-question-circle settingsquestionmark"></i></a></label>
  1224. </div>
  1225. <div class="radio">
  1226. <label><input type="radio" name="type" value="1" <?php if ($article['type']==1) {echo 'checked="checked"';} ?> /> <?php echo $hesklang['kb_private']; ?><a href="javascript:void(0)" onclick="javascript:alert('<?php echo $hesklang['kb_private2']; ?>')">&nbsp;<i class="fa fa-question-circle settingsquestionmark"></i></a></label>
  1227. </div>
  1228. <div class="radio">
  1229. <label><input type="radio" name="type" value="2" <?php if ($article['type']==2) {echo 'checked="checked"';} ?> /> <?php echo $hesklang['kb_draft']; ?><a href="javascript:void(0)" onclick="javascript:alert('<?php echo $hesklang['kb_draft2']; ?>')">&nbsp;<i class="fa fa-question-circle settingsquestionmark"></i></a></label>
  1230. </div>
  1231. </div>
  1232. <div class="form-group">
  1233. <label for="options" class="control-label"><?php echo $hesklang['opt']; ?></label>
  1234. <div class="checkbox">
  1235. <label><input type="checkbox" name="sticky" value="Y" <?php if ($article['sticky']) {echo 'checked="checked"';} ?> /> <?php echo $hesklang['sticky']; ?> <a href="javascript:void(0)" onclick="javascript:alert('<?php echo hesk_makeJsString($hesklang['saa']); ?>')"><i class="fa fa-question-circle settingsquestionmark"></i></a></label>
  1236. </div>
  1237. <div class="checkbox">
  1238. <label><input type="checkbox" name="resetviews" value="Y" <?php if (isset($_SESSION['edit_article']['resetviews']) && $_SESSION['edit_article']['resetviews'] == 'Y') {echo 'checked="checked"';} ?> /> <?php echo $hesklang['rv']; ?></label>
  1239. </div>
  1240. <div class="checkbox">
  1241. <label><input type="checkbox" name="resetvotes" value="Y" <?php if (isset($_SESSION['edit_article']['resetvotes']) && $_SESSION['edit_article']['resetvotes'] == 'Y') {echo 'checked="checked"';} ?> /> <?php echo $hesklang['rr']; ?></label>
  1242. </div>
  1243. </div>
  1244. </div>
  1245. </div>
  1246. </div>
  1247. <div class="col-md-6">
  1248. <?php
  1249. /* This will handle error, success and notice messages */
  1250. hesk_handle_messages();
  1251. if ($hesk_settings['kb_wysiwyg'])
  1252. {
  1253. ?>
  1254. <script type="text/javascript">
  1255. tinyMCE.init({
  1256. mode : "exact",
  1257. elements : "content",
  1258. theme : "advanced",
  1259. convert_urls : false,
  1260. gecko_spellcheck: true,
  1261. theme_advanced_buttons1 : "cut,copy,paste,|,undo,redo,|,formatselect,fontselect,fontsizeselect,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull",
  1262. theme_advanced_buttons2 : "sub,sup,|,charmap,|,bullist,numlist,|,outdent,indent,insertdate,inserttime,preview,|,forecolor,backcolor,|,hr,removeformat,visualaid,|,link,unlink,anchor,image,cleanup,code",
  1263. theme_advanced_buttons3 : "",
  1264. theme_advanced_toolbar_location : "top",
  1265. theme_advanced_toolbar_align : "left",
  1266. theme_advanced_statusbar_location : "bottom",
  1267. theme_advanced_resizing : true
  1268. });
  1269. </script>
  1270. <?php
  1271. }
  1272. $displayType = $hesk_settings['kb_wysiwyg'] ? 'none' : 'block';
  1273. $displayWarn = $article['html'] ? 'block' : 'none';
  1274. ?>
  1275. <span id="contentType" style="display:<?php echo $displayType; ?>">
  1276. <label><input type="radio" name="html" value="0" <?php if (!$article['html']) {echo 'checked="checked"';} ?> onclick="javascript:document.getElementById('kblinks').style.display = 'none'" /> <?php echo $hesklang['kb_dhtml']; ?></label><br />
  1277. <label><input type="radio" name="html" value="1" <?php if ($article['html']) {echo 'checked="checked"';} ?> onclick="javascript:document.getElementById('kblinks').style.display = 'block'" /> <?php echo $hesklang['kb_ehtml']; ?></label>
  1278. <span id="kblinks" style="display:<?php echo $displayWarn; ?>"><i><?php echo $hesklang['kb_links']; ?></i></span>
  1279. </span>
  1280. <div class="form-group">
  1281. <label for="subject" class="control-label"><?php echo $hesklang['kb_subject']; ?></label>
  1282. <input type="text" data-error="<?php echo htmlspecialchars($hesklang['kb_e_subj']); ?>" class="form-control"
  1283. placeholder="<?php echo htmlspecialchars($hesklang['kb_subject']); ?>" name="subject" size="70" maxlength="255" value="<?php echo $article['subject']; ?>" required>
  1284. <div class="help-block with-errors"></div>
  1285. </div>
  1286. <div class="form-group" id="content-group">
  1287. <textarea name="content" class="form-control" data-error="<?php echo htmlspecialchars($hesklang['kb_e_cont']); ?>" id="content"
  1288. placeholder="<?php echo htmlspecialchars($hesklang['kb_content']); ?>" rows="25" cols="70" id="content" required><?php echo $article['content']; ?></textarea>
  1289. <div class="help-block with-errors" id="content-help-block"></div>
  1290. </div>
  1291. </div>
  1292. <div class="col-md-3">
  1293. <div class="panel panel-default move-left-10">
  1294. <div class="panel-body">
  1295. <div class="form-group">
  1296. <label for="keywords" class="control-label"><?php echo $hesklang['kw']; ?></label>
  1297. <p class="font-size-90 form-control-static"><?php echo $hesklang['kw1']; ?></p><br>
  1298. <textarea name="keywords" class="form-control" placeholder="<?php echo htmlspecialchars($hesklang['kw']); ?>" rows="3" cols="70" id="keywords"><?php echo $article['keywords']; ?></textarea>
  1299. </div>
  1300. <?php if ( ! empty($article['attachments']) || $hesk_settings['attachments']['use']): ?>
  1301. <div class="form-group">
  1302. <label for="attachments" class="control-label"><?php echo $hesklang['attachments']; ?> (<a href="Javascript:void(0)" onclick="Javascript:hesk_window('../file_limits.php',250,500);return false;"><?php echo $hesklang['ful']; ?></a>)</label>
  1303. <?php
  1304. if ( ! empty($article['attachments']) )
  1305. {
  1306. $att=explode(',',substr($article['attachments'], 0, -1));
  1307. foreach ($att as $myatt)
  1308. {
  1309. list($att_id, $att_name) = explode('#', $myatt);
  1310. $tmp = 'White';
  1311. $style = 'class="option'.$tmp.'OFF" onmouseover="this.className=\'option'.$tmp.'ON\'" onmouseout="this.className=\'option'.$tmp.'OFF\'"';
  1312. echo '<a href="manage_knowledgebase.php?a=remove_kb_att&amp;id='.$id.'&amp;kb_att='.$att_id.'&amp;token='.hesk_token_echo(0).'" onclick="return hesk_confirmExecute(\''.hesk_makeJsString($hesklang['delatt']).'\');"><img src="../img/delete.png" width="16" height="16" alt="'.$hesklang['dela'].'" title="'.$hesklang['dela'].'" '.$style.' /></a> ';
  1313. echo '<a href="../download_attachment.php?kb_att='.$att_id.'"><img src="../img/clip.png" width="16" height="16" alt="'.$hesklang['dnl'].' '.$att_name.'" title="'.$hesklang['dnl'].' '.$att_name.'" '.$style.' /></a> ';
  1314. echo '<a href="../download_attachment.php?kb_att='.$att_id.'">'.$att_name.'</a><br />';
  1315. }
  1316. echo '<br />';
  1317. }
  1318. ?>
  1319. <?php
  1320. build_dropzone_markup(true);
  1321. display_dropzone_field($hesk_settings['hesk_url'] . '/internal-api/admin/knowledgebase/upload-attachment.php');
  1322. ?>
  1323. </div>
  1324. <?php endif; //End attachments ?>
  1325. <div class="form-group">
  1326. <input type="hidden" name="a" value="save_article">
  1327. <input type="hidden" name="id" value="<?php echo $id; ?>">
  1328. <input type="hidden" name="old_type" value="<?php echo $article['type']; ?>">
  1329. <input type="hidden" name="old_catid" value="<?php echo $catid; ?>">
  1330. <input type="hidden" name="token" value="<?php hesk_token_echo(); ?>">
  1331. <div class="btn-group-vertical full-width">
  1332. <input type="submit" value="<?php echo $hesklang['kb_save']; ?>" class="btn btn-primary" />
  1333. <a class="btn btn-default" href="manage_knowledgebase.php?a=manage_cat&amp;catid=<?php echo $catid; ?>"><?php echo $hesklang['cancel']; ?></a>
  1334. <a class="btn btn-danger" href="manage_knowledgebase.php?a=remove_article&amp;id=<?php echo $article['id']; ?>&amp;token=<?php hesk_token_echo(); ?>" onclick="return hesk_confirmExecute('<?php echo hesk_makeJsString($hesklang['del_art']); ?>');"><?php echo $hesklang['del_kbaa']; ?></a>
  1335. </div>
  1336. </div>
  1337. </div>
  1338. </div>
  1339. </div>
  1340. </div>
  1341. </form>
  1342. <div class="row">
  1343. <div class="col-md-12 move-left-10 move-right-10">
  1344. <h3><?php echo $hesklang['revhist']; ?></h3>
  1345. <div class="footerWithBorder blankSpace"></div>
  1346. <ul><?php echo $article['history']; ?></ul>
  1347. </div>
  1348. </div>
  1349. <?php
  1350. /* Clean unneeded session variables */
  1351. hesk_cleanSessionVars('edit_article');
  1352. require_once(HESK_PATH . 'inc/footer.inc.php');
  1353. exit();
  1354. } // END edit_article()
  1355. function manage_category() {
  1356. global $hesk_settings, $hesklang;
  1357. $catid = intval( hesk_GET('catid') ) or hesk_error($hesklang['kb_cat_inv']);
  1358. $result = hesk_dbQuery('SELECT * FROM `'.hesk_dbEscape($hesk_settings['db_pfix']).'kb_categories` ORDER BY `parent` ASC, `cat_order` ASC');
  1359. $kb_cat = array();
  1360. while ($cat = hesk_dbFetchAssoc($result))
  1361. {
  1362. $kb_cat[] = $cat;
  1363. if ($cat['id'] == $catid)
  1364. {
  1365. $this_cat = $cat;
  1366. }
  1367. }
  1368. if (isset($_SESSION['manage_cat']))
  1369. {
  1370. $_SESSION['manage_cat'] = hesk_stripArray($_SESSION['manage_cat']);
  1371. $this_cat['type'] = $_SESSION['manage_cat']['type'];
  1372. $this_cat['parent'] = $_SESSION['manage_cat']['parent'];
  1373. $this_cat['name'] = $_SESSION['manage_cat']['title'];
  1374. }
  1375. /* Translate main category "Knowledgebase" if needed */
  1376. $kb_cat[0]['name'] = $hesklang['kb_text'];
  1377. require(HESK_PATH . 'inc/treemenu/TreeMenu.php');
  1378. $icon = HESK_PATH . 'img/folder.gif';
  1379. $expandedIcon = 'fa-folder-open style="color:orange;font-size:17px';
  1380. $menu = new HTML_TreeMenu();
  1381. $thislevel = array('0');
  1382. $nextlevel = array();
  1383. $i = 1;
  1384. $j = 1;
  1385. while (count($kb_cat) > 0)
  1386. {
  1387. foreach ($kb_cat as $k=>$cat)
  1388. {
  1389. if (in_array($cat['parent'],$thislevel))
  1390. {
  1391. $up = $cat['parent'];
  1392. $my = $cat['id'];
  1393. $type = $cat['type'] ? '*' : '';
  1394. $text_short = $cat['name'].$type.' ('.$cat['articles'].', '.$cat['articles_private'].', '.$cat['articles_draft'].')';
  1395. if (isset($node[$up]))
  1396. {
  1397. $node[$my] = &$node[$up]->addItem(new HTML_TreeNode(array('hesk_parent' => $this_cat['parent'], 'text' => 'Text', 'text_short' => $text_short, 'hesk_catid' => $cat['id'], 'hesk_select' => 'option'.$j, 'icon' => $icon, 'expandedIcon' => $expandedIcon, 'expanded' => true)));
  1398. }
  1399. else
  1400. {
  1401. $node[$my] = new HTML_TreeNode(array('hesk_parent' => $this_cat['parent'], 'text' => 'Text', 'text_short' => $text_short, 'hesk_catid' => $cat['id'], 'hesk_select' => 'option'.$j, 'icon' => $icon, 'expandedIcon' => $expandedIcon, 'expanded' => true));
  1402. }
  1403. $nextlevel[] = $cat['id'];
  1404. $j++;
  1405. unset($kb_cat[$k]);
  1406. }
  1407. }
  1408. $thislevel = $nextlevel;
  1409. $nextlevel = array();
  1410. /* Break after 20 recursions to avoid hang-ups in case of any problems */
  1411. if ($i > 20)
  1412. {
  1413. break;
  1414. }
  1415. $i++;
  1416. }
  1417. $menu->addItem($node[1]);
  1418. // Create the presentation class
  1419. $listBox = & ref_new(new HTML_TreeMenu_Listbox($menu));
  1420. /* Print header */
  1421. require_once(HESK_PATH . 'inc/headerAdmin.inc.php');
  1422. /* Print main manage users page */
  1423. require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
  1424. ?>
  1425. <ol class="breadcrumb">
  1426. <li><a href="manage_knowledgebase.php"><?php echo $hesklang['kb']; ?></a></li>
  1427. <li class="active"><?php echo $hesklang['kb_cat_man']; ?></li>
  1428. </ol>
  1429. <section class="content">
  1430. <?php
  1431. show_subnav('',$catid);
  1432. $result = hesk_dbQuery("SELECT * FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_articles` WHERE `catid`='{$catid}' ORDER BY `sticky` DESC, `art_order` ASC");
  1433. $num = hesk_dbNumRows($result);
  1434. $secondCol = $catid == 1 ? 'col-md-12' : 'col-md-8';
  1435. if ( ! isset($_SESSION['hide']['article_list'])):
  1436. ?>
  1437. <div class="row">
  1438. <?php if ($catid != 1): ?>
  1439. <div class="col-md-4">
  1440. <div class="box">
  1441. <div class="box-header with-border">
  1442. <h1 class="box-title">
  1443. <?php echo $hesklang['catset']; ?>
  1444. </h1>
  1445. <div class="box-tools pull-right">
  1446. <button type="button" class="btn btn-box-tool" data-widget="collapse">
  1447. <i class="fa fa-minus"></i>
  1448. </button>
  1449. </div>
  1450. </div>
  1451. <div class="box-body">
  1452. <form action="manage_knowledgebase.php" method="post" role="form" name="form1" data-toggle="validator"
  1453. onsubmit="Javascript:return hesk_deleteIfSelected('dodelete','<?php echo hesk_makeJsString($hesklang['kb_delcat']); ?>')">
  1454. <div class="form-group">
  1455. <label for="title" class="control-label"><?php echo $hesklang['kb_cat_title']; ?></label>
  1456. <input type="text" class="form-control" name="title" size="70" maxlength="255" value="<?php echo $this_cat['name']; ?>"
  1457. data-error="<?php echo htmlspecialchars($hesklang['kb_cat_e_title']); ?>" required>
  1458. <div class="help-block with-errors"></div>
  1459. </div>
  1460. <div class="form-group">
  1461. <label for="parent" class="control-label"><?php echo $hesklang['kb_cat_parent']; ?></label>
  1462. <select name="parent" class="form-control"><?php $listBox->printMenu(); ?></select>
  1463. </div>
  1464. <div class="form-group">
  1465. <label for="type" class="control-label"><?php echo $hesklang['kb_type']; ?></label>
  1466. <div class="radio">
  1467. <label><input type="radio" name="type" value="0" <?php if (!$this_cat['type']) {echo 'checked="checked"';} ?> /> <b><i><?php echo $hesklang['kb_published']; ?></i></b></label>
  1468. <p class="form-static-content"><?php echo $hesklang['kb_cat_published']; ?></p>
  1469. </div>
  1470. <div class="radio">
  1471. <label><input type="radio" name="type" value="1" <?php if ($this_cat['type']) {echo 'checked="checked"';} ?> /> <b><i><?php echo $hesklang['kb_private']; ?></i></b></label>
  1472. <p class="form-static-content"><?php echo $hesklang['kb_cat_private']; ?></p>
  1473. </div>
  1474. </div>
  1475. <div class="form-group">
  1476. <label for="dodelete" class="control-label"><?php echo $hesklang['opt']; ?></label>
  1477. <div class="checkbox">
  1478. <label><input type="checkbox" name="dodelete" id="dodelete" value="Y" onclick="Javascript:hesk_toggleLayerDisplay('deleteoptions')" /><?php echo $hesklang['delcat']; ?></label>
  1479. </div>
  1480. </div>
  1481. <div id="deleteoptions" style="display: none;">
  1482. <div class="form-group">
  1483. <div class="radio">
  1484. <label><input type="radio" name="movearticles" value="Y" checked="checked" /> <?php echo $hesklang['move1']; ?></label>
  1485. </div>
  1486. <div class="radio">
  1487. <label><input type="radio" name="movearticles" value="N" /> <?php echo $hesklang['move2']; ?></label>
  1488. </div>
  1489. </div>
  1490. </div>
  1491. <div class="form-group">
  1492. <input type="hidden" name="a" value="edit_category" />
  1493. <input type="hidden" name="token" value="<?php hesk_token_echo(); ?>" />
  1494. <input type="hidden" name="catid" value="<?php echo $catid; ?>" />
  1495. <div class="btn-group">
  1496. <input type="submit" value="<?php echo $hesklang['save_changes']; ?>" class="btn btn-primary" />
  1497. <a class="btn btn-default" href="manage_knowledgebase.php?a=add_category&amp;parent='.$catid.'"><?php echo $hesklang['kb_i_cat2']; ?></a>
  1498. </div>
  1499. </div>
  1500. </form>
  1501. </div>
  1502. </div>
  1503. </div>
  1504. <?php endif; ?>
  1505. <div class="<?php echo $secondCol; ?>">
  1506. <div class="box">
  1507. <div class="box-header with-border">
  1508. <h1 class="box-title">
  1509. <?php echo sprintf($hesklang['articles_in_category_x'], '<strong>'.$this_cat['name']).'</strong>'; ?>
  1510. </h1>
  1511. <div class="box-tools pull-right">
  1512. <button type="button" class="btn btn-box-tool" data-widget="collapse">
  1513. <i class="fa fa-minus"></i>
  1514. </button>
  1515. </div>
  1516. </div>
  1517. <div class="box-body">
  1518. <?php
  1519. if ($num == 0)
  1520. {
  1521. echo '<p>'.$hesklang['kb_no_art'].'</p>';
  1522. }
  1523. else
  1524. {
  1525. /* Get number of sticky articles */
  1526. $res2 = hesk_dbQuery("SELECT COUNT(*) FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_articles` WHERE `catid`='{$catid}' AND `sticky` = '1' ");
  1527. $num_sticky = hesk_dbResult($res2);
  1528. $num_nosticky = $num - $num_sticky;
  1529. ?>
  1530. <table class="table table-striped">
  1531. <thead>
  1532. <tr>
  1533. <th>&nbsp;</th>
  1534. <th><?php echo $hesklang['kb_subject']; ?></th>
  1535. <th><?php echo $hesklang['kb_type']; ?></th>
  1536. <th><?php echo $hesklang['views']; ?></th>
  1537. <?php
  1538. if ($hesk_settings['kb_rating'])
  1539. {
  1540. ?>
  1541. <th><?php echo $hesklang['rating'].' ('.$hesklang['votes'].')'; ?></th>
  1542. <?php
  1543. }
  1544. ?>
  1545. <th>&nbsp;<?php echo $hesklang['opt']; ?>&nbsp;</th>
  1546. </tr>
  1547. </thead>
  1548. <?php
  1549. $i=1;
  1550. $j=1;
  1551. $k=1;
  1552. $previous_sticky=1;
  1553. $num = $num_sticky;
  1554. while ($article=hesk_dbFetchAssoc($result))
  1555. {
  1556. if ($previous_sticky != $article['sticky'])
  1557. {
  1558. $k = 1;
  1559. $num = $num_nosticky;
  1560. $previous_sticky = $article['sticky'];
  1561. }
  1562. if (isset($_SESSION['artord']) && $article['id'] == $_SESSION['artord'])
  1563. {
  1564. unset($_SESSION['artord']);
  1565. }
  1566. $tmp = $i ? 'White' : 'Blue';
  1567. $i = $i ? 0 : 1;
  1568. switch ($article['type'])
  1569. {
  1570. case '1':
  1571. $type = '<span class="kb_private">' . $hesklang['kb_private'] . '</span>';
  1572. break;
  1573. case '2':
  1574. $type = '<span class="kb_draft">' . $hesklang['kb_draft'] . '</span>';
  1575. break;
  1576. default:
  1577. $type = '<span class="kb_published">' . $hesklang['kb_published'] . '</span>';
  1578. }
  1579. if ($hesk_settings['kb_rating'])
  1580. {
  1581. $alt = $article['rating'] ? sprintf($hesklang['kb_rated'], sprintf("%01.1f", $article['rating'])) : $hesklang['kb_not_rated'];
  1582. $rat = '<td><span data-toggle="tooltip" title="' . $alt . '">' . mfh_get_stars(hesk_round_to_half($article['rating'])) . '</span> (' . $article['votes'] . ')</td>';
  1583. }
  1584. else
  1585. {
  1586. $rat = '';
  1587. }
  1588. ?>
  1589. <tr>
  1590. <td><?php echo $j; ?>.</td>
  1591. <td><?php echo $article['subject']; ?></td>
  1592. <td><?php echo $type; ?></td>
  1593. <td><?php echo $article['views']; ?></td>
  1594. <?php echo $rat; ?>
  1595. <td>
  1596. <?php
  1597. if ($num > 1)
  1598. {
  1599. if ($k == 1)
  1600. {
  1601. ?>
  1602. <img src="../img/blank.gif" width="16" height="16" alt="" style="padding:3px;border:none;" />
  1603. <a href="manage_knowledgebase.php?a=order_article&amp;id=<?php echo $article['id']; ?>&amp;catid=<?php echo $catid; ?>&amp;move=15&amp;token=<?php hesk_token_echo(); ?>"><i class="fa fa-arrow-down icon-link green" data-toggle="tooltip" data-placement="top" title="<?php echo $hesklang['move_dn']; ?>"></i></a>
  1604. <?php
  1605. }
  1606. elseif ($k == $num)
  1607. {
  1608. ?>
  1609. <a href="manage_knowledgebase.php?a=order_article&amp;id=<?php echo $article['id']; ?>&amp;catid=<?php echo $catid; ?>&amp;move=-15&amp;token=<?php hesk_token_echo(); ?>"><i class="fa fa-arrow-up icon-link green" data-toggle="tooltip" data-placement="top" title="<?php echo $hesklang['move_up']; ?>"></i></a>
  1610. <img src="../img/blank.gif" width="16" height="16" alt="" style="padding:3px;border:none;" />
  1611. <?php
  1612. }
  1613. else
  1614. {
  1615. ?>
  1616. <a href="manage_knowledgebase.php?a=order_article&amp;id=<?php echo $article['id']; ?>&amp;catid=<?php echo $catid; ?>&amp;move=-15&amp;token=<?php hesk_token_echo(); ?>"><i class="fa fa-arrow-up icon-link green" data-toggle="tooltip" data-placement="top" title="<?php echo $hesklang['move_up']; ?>"></i></a>
  1617. <a href="manage_knowledgebase.php?a=order_article&amp;id=<?php echo $article['id']; ?>&amp;catid=<?php echo $catid; ?>&amp;move=15&amp;token=<?php hesk_token_echo(); ?>"><i class="fa fa-arrow-down icon-link green" data-toggle="tooltip" data-placement="top" title="<?php echo $hesklang['move_dn'] ?>"></i></a>
  1618. <?php
  1619. }
  1620. }
  1621. elseif ( $num_sticky > 1 || $num_nosticky > 1 )
  1622. {
  1623. echo '<img src="../img/blank.gif" width="16" height="16" alt="" style="padding:3px;border:none;vertical-align:text-bottom;" /> <img src="../img/blank.gif" width="16" height="16" alt="" style="padding:3px;border:none;vertical-align:text-bottom;" />';
  1624. }
  1625. ?>
  1626. <a href="manage_knowledgebase.php?a=sticky&amp;s=<?php echo $article['sticky'] ? 0 : 1 ?>&amp;id=<?php echo $article['id']; ?>&amp;catid=<?php echo $catid; ?>&amp;token=<?php hesk_token_echo(); ?>"><i class="glyphicon glyphicon-pushpin icon-link" style="color:<?php if ( ! $article['sticky']) {echo 'gray';} else {echo 'red';} ?>" data-toggle="tooltip" data-placement="top" title="<?php if (!$article['sticky']) {echo $hesklang['stickyon'];} else {echo $hesklang['stickyoff'];} ?>"></i></a>
  1627. <a href="knowledgebase_private.php?article=<?php echo $article['id']; ?>&amp;back=1<?php if ($article['type'] == 2) {echo '&amp;draft=1';} ?>" target="_blank"><i class="fa fa-file-o icon-link" data-toggle="tooltip" data-placement="top" title="<?php echo $hesklang['viewart'] ?>"></i></a>
  1628. <a href="manage_knowledgebase.php?a=edit_article&amp;id=<?php echo $article['id']; ?>"><i class="fa fa-pencil" style="color:orange;font-size:16px" data-toggle="tooltip" data-placement="top" title="<?php echo $hesklang['edit'] ?>"></i></a>
  1629. <a href="manage_knowledgebase.php?a=remove_article&amp;id=<?php echo $article['id']; ?>&amp;token=<?php hesk_token_echo(); ?>" onclick="return hesk_confirmExecute('<?php echo hesk_makeJsString($hesklang['del_art']); ?>');"><i class="fa fa-times icon-link red" data-toggle="tooltip" data-placement="top" title="<?php echo $hesklang['delete'] ?>"></i></a>&nbsp;</td>
  1630. </tr>
  1631. <?php
  1632. $j++;
  1633. $k++;
  1634. } // End while
  1635. ?>
  1636. </table>
  1637. <?php
  1638. } ?>
  1639. </div>
  1640. <div class="box-footer">
  1641. <a href="manage_knowledgebase.php?a=add_article&amp;catid=<?php echo $catid; ?>" class="btn btn-success">
  1642. <i class="fa fa-plus"></i>
  1643. <?php echo $hesklang['kb_i_art2']; ?>
  1644. </a>
  1645. </div>
  1646. </div>
  1647. </div>
  1648. </div>
  1649. <?php endif; ?>
  1650. </section>
  1651. <?php
  1652. /* Clean unneeded session variables */
  1653. hesk_cleanSessionVars(array('hide','manage_cat','edit_article'));
  1654. require_once(HESK_PATH . 'inc/footer.inc.php');
  1655. exit();
  1656. } // END manage_category()
  1657. function new_category() {
  1658. global $hesk_settings, $hesklang;
  1659. /* A security check */
  1660. hesk_token_check('POST');
  1661. $_SESSION['hide'] = array(
  1662. 'treemenu' => 1,
  1663. 'new_article' => 1,
  1664. //'new_category' => 1,
  1665. );
  1666. $parent = intval( hesk_POST('parent', 1) );
  1667. $type = empty($_POST['type']) ? 0 : 1;
  1668. $_SESSION['KB_CATEGORY'] = $parent;
  1669. $_SERVER['PHP_SELF'] = 'manage_knowledgebase.php';
  1670. /* Check that title is valid */
  1671. $title = hesk_input( hesk_POST('title') );
  1672. if (!strlen($title))
  1673. {
  1674. $_SESSION['new_category'] = array(
  1675. 'type' => $type,
  1676. );
  1677. hesk_process_messages($hesklang['kb_cat_e_title'],$_SERVER['PHP_SELF']);
  1678. }
  1679. /* Get the latest reply_order */
  1680. $res = hesk_dbQuery('SELECT `cat_order` FROM `'.hesk_dbEscape($hesk_settings['db_pfix']).'kb_categories` ORDER BY `cat_order` DESC LIMIT 1');
  1681. $row = hesk_dbFetchRow($res);
  1682. $my_order = $row[0]+10;
  1683. $result = hesk_dbQuery("INSERT INTO `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_categories` (`name`,`parent`,`cat_order`,`type`) VALUES ('".hesk_dbEscape($title)."','".intval($parent)."','".intval($my_order)."','".intval($type)."')");
  1684. $_SESSION['newcat'] = hesk_dbInsertID();
  1685. $_SESSION['hide'] = array(
  1686. 'treemenu' => 1,
  1687. 'new_article' => 1,
  1688. //'new_category' => 1,
  1689. 'cat_treemenu' => 1,
  1690. );
  1691. hesk_process_messages($hesklang['kb_cat_added2'],$_SERVER['PHP_SELF'],'SUCCESS');
  1692. } // End new_category()
  1693. function new_article()
  1694. {
  1695. global $hesk_settings, $hesklang, $listBox;
  1696. global $hesk_error_buffer;
  1697. /* A security check */
  1698. # hesk_token_check('POST');
  1699. $_SESSION['hide'] = array(
  1700. 'treemenu' => 1,
  1701. //'new_article' => 1,
  1702. 'new_category' => 1,
  1703. );
  1704. $hesk_error_buffer = array();
  1705. $catid = intval( hesk_POST('catid', 1) );
  1706. $type = empty($_POST['type']) ? 0 : (hesk_POST('type') == 2 ? 2 : 1);
  1707. $html = $hesk_settings['kb_wysiwyg'] ? 1 : (empty($_POST['html']) ? 0 : 1);
  1708. $now = hesk_date();
  1709. // Prevent submitting duplicate articles by reloading manage_knowledgebase.php page
  1710. if (isset($_SESSION['article_submitted']))
  1711. {
  1712. header('Location:manage_knowledgebase.php?a=manage_cat&catid=' . $catid);
  1713. exit();
  1714. }
  1715. $_SESSION['KB_CATEGORY'] = $catid;
  1716. $subject = hesk_input( hesk_POST('subject') ) or $hesk_error_buffer[] = $hesklang['kb_e_subj'];
  1717. if ($html)
  1718. {
  1719. if (empty($_POST['content']))
  1720. {
  1721. $hesk_error_buffer[] = $hesklang['kb_e_cont'];
  1722. }
  1723. $content = hesk_getHTML( hesk_POST('content') );
  1724. // Clean the HTML code
  1725. require(HESK_PATH . 'inc/htmlpurifier/HeskHTMLPurifier.php');
  1726. $purifier = new HeskHTMLPurifier($hesk_settings['cache_dir']);
  1727. $content = $purifier->heskPurify($content);
  1728. }
  1729. else
  1730. {
  1731. $content = hesk_input( hesk_POST('content') ) or $hesk_error_buffer[] = $hesklang['kb_e_cont'];
  1732. $content = nl2br($content);
  1733. $content = hesk_makeURL($content);
  1734. }
  1735. $sticky = isset($_POST['sticky']) ? 1 : 0;
  1736. $keywords = hesk_input( hesk_POST('keywords') );
  1737. /* Article attachments */
  1738. define('KB',1);
  1739. require_once(HESK_PATH . 'inc/posting_functions.inc.php');
  1740. $attachments = array();
  1741. $use_legacy_attachments = hesk_POST('use-legacy-attachments', 0);
  1742. $myattachments='';
  1743. if ($hesk_settings['attachments']['use']) {
  1744. require_once(HESK_PATH . 'inc/attachments.inc.php');
  1745. if ($use_legacy_attachments) {
  1746. for ($i=1; $i<=$hesk_settings['attachments']['max_number']; $i++)
  1747. {
  1748. $att = hesk_uploadFile($i);
  1749. if ( ! empty($att))
  1750. {
  1751. $attachments[$i] = $att;
  1752. }
  1753. }
  1754. } else {
  1755. // The user used the new drag-and-drop system.
  1756. $temp_attachment_ids = hesk_POST_array('attachment-ids');
  1757. foreach ($temp_attachment_ids as $temp_attachment_id) {
  1758. // Simply get the temp info and move it to the attachments table
  1759. $temp_attachment = mfh_getTemporaryAttachment($temp_attachment_id);
  1760. $attachments[] = $temp_attachment;
  1761. mfh_deleteTemporaryAttachment($temp_attachment_id);
  1762. }
  1763. }
  1764. }
  1765. /* Any errors? */
  1766. if (count($hesk_error_buffer))
  1767. {
  1768. // Remove any successfully uploaded attachments
  1769. if ($hesk_settings['attachments']['use'])
  1770. {
  1771. hesk_removeAttachments($attachments);
  1772. }
  1773. $_SESSION['new_article'] = array(
  1774. 'type' => $type,
  1775. 'html' => $html,
  1776. 'subject' => $subject,
  1777. 'content' => hesk_input( hesk_POST('content') ),
  1778. 'keywords' => $keywords,
  1779. 'sticky' => $sticky,
  1780. );
  1781. $tmp = '';
  1782. foreach ($hesk_error_buffer as $error)
  1783. {
  1784. $tmp .= "<li>$error</li>\n";
  1785. }
  1786. $hesk_error_buffer = $tmp;
  1787. $hesk_error_buffer = $hesklang['rfm'].'<br /><br /><ul>'.$hesk_error_buffer.'</ul>';
  1788. hesk_process_messages($hesk_error_buffer,'manage_knowledgebase.php');
  1789. }
  1790. $revision = sprintf($hesklang['revision1'],$now,$_SESSION['name'].' ('.$_SESSION['user'].')');
  1791. /* Add to database */
  1792. if ( ! empty($attachments))
  1793. {
  1794. foreach ($attachments as $myatt)
  1795. {
  1796. hesk_dbQuery("INSERT INTO `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_attachments` (`saved_name`,`real_name`,`size`) VALUES ('".hesk_dbEscape($myatt['saved_name'])."','".hesk_dbEscape($myatt['real_name'])."','".intval($myatt['size'])."')");
  1797. $myattachments .= hesk_dbInsertID() . '#' . $myatt['real_name'] .',';
  1798. }
  1799. }
  1800. /* Get the latest reply_order */
  1801. $res = hesk_dbQuery("SELECT `art_order` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_articles` WHERE `catid`='".intval($catid)."' AND `sticky` = '" . intval($sticky) . "' ORDER BY `art_order` DESC LIMIT 1");
  1802. $row = hesk_dbFetchRow($res);
  1803. $my_order = $row[0]+10;
  1804. /* Insert article into database */
  1805. hesk_dbQuery("INSERT INTO `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_articles` (`catid`,`dt`,`author`,`subject`,`content`,`keywords`,`type`,`html`,`sticky`,`art_order`,`history`,`attachments`) VALUES (
  1806. '".intval($catid)."',
  1807. NOW(),
  1808. '".intval($_SESSION['id'])."',
  1809. '".hesk_dbEscape($subject)."',
  1810. '".hesk_dbEscape($content)."',
  1811. '".hesk_dbEscape($keywords)."',
  1812. '".intval($type)."',
  1813. '".intval($html)."',
  1814. '".intval($sticky)."',
  1815. '".intval($my_order)."',
  1816. '".hesk_dbEscape($revision)."',
  1817. '".hesk_dbEscape($myattachments)."'
  1818. )");
  1819. $_SESSION['artord'] = hesk_dbInsertID();
  1820. // Update category article count
  1821. if ($type == 0)
  1822. {
  1823. hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_categories` SET `articles`=`articles`+1 WHERE `id`='".intval($catid)."'");
  1824. }
  1825. else if ($type == 1)
  1826. {
  1827. hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_categories` SET `articles_private`=`articles_private`+1 WHERE `id`='".intval($catid)."'");
  1828. }
  1829. else
  1830. {
  1831. hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_categories` SET `articles_draft`=`articles_draft`+1 WHERE `id`='".intval($catid)."'");
  1832. }
  1833. unset($_SESSION['hide']);
  1834. $_SESSION['article_submitted']=1;
  1835. hesk_process_messages($hesklang['your_kb_added'],'NOREDIRECT','SUCCESS');
  1836. $_GET['catid'] = $catid;
  1837. manage_category();
  1838. } // End new_article()
  1839. function remove_article()
  1840. {
  1841. global $hesk_settings, $hesklang;
  1842. /* A security check */
  1843. hesk_token_check();
  1844. $id = intval( hesk_GET('id') ) or hesk_error($hesklang['kb_art_id']);
  1845. /* Get article details */
  1846. $result = hesk_dbQuery("SELECT `catid`, `type`, `attachments` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_articles` WHERE `id`='".intval($id)."' LIMIT 1");
  1847. if (hesk_dbNumRows($result) != 1)
  1848. {
  1849. hesk_error($hesklang['kb_art_id']);
  1850. }
  1851. $article = hesk_dbFetchAssoc($result);
  1852. $catid = intval($article['catid']);
  1853. $from = hesk_GET('from');
  1854. $result = hesk_dbQuery("DELETE FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_articles` WHERE `id`='".intval($id)."'");
  1855. // Remove any attachments
  1856. delete_kb_attachments($article['attachments']);
  1857. // Update category article count
  1858. if ($article['type'] == 0)
  1859. {
  1860. hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_categories` SET `articles`=`articles`-1 WHERE `id`='{$catid}'");
  1861. }
  1862. else if ($article['type'] == 1)
  1863. {
  1864. hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_categories` SET `articles_private`=`articles_private`-1 WHERE `id`='{$catid}'");
  1865. }
  1866. else
  1867. {
  1868. hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_categories` SET `articles_draft`=`articles_draft`-1 WHERE `id`='{$catid}'");
  1869. }
  1870. // Redirect to the correct page
  1871. switch ($from) {
  1872. case 'draft':
  1873. $redirect_action = 'a=list_draft';
  1874. break;
  1875. case 'private':
  1876. $redirect_action = 'a=list_private';
  1877. break;
  1878. default:
  1879. $redirect_action = 'a=manage_cat&catid='.$catid;
  1880. break;
  1881. }
  1882. hesk_process_messages($hesklang['your_kb_deleted'],'./manage_knowledgebase.php?'.$redirect_action,'SUCCESS');
  1883. } // End remove_article()
  1884. function order_category()
  1885. {
  1886. global $hesk_settings, $hesklang;
  1887. /* A security check */
  1888. hesk_token_check();
  1889. $catid = intval( hesk_GET('catid') ) or hesk_error($hesklang['kb_cat_inv']);
  1890. $move = intval( hesk_GET('move') );
  1891. $_SESSION['newcat'] = $catid;
  1892. $result = hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_categories` SET `cat_order`=`cat_order`+".intval($move)." WHERE `id`='".intval($catid)."'");
  1893. if (hesk_dbAffectedRows() != 1)
  1894. {
  1895. hesk_error($hesklang['kb_cat_inv']);
  1896. }
  1897. update_category_order();
  1898. header('Location: manage_knowledgebase.php');
  1899. exit();
  1900. } // End order_category()
  1901. function order_article()
  1902. {
  1903. global $hesk_settings, $hesklang;
  1904. /* A security check */
  1905. hesk_token_check();
  1906. $id = intval( hesk_GET('id') ) or hesk_error($hesklang['kb_art_id']);
  1907. $catid = intval( hesk_GET('catid') ) or hesk_error($hesklang['kb_cat_inv']);
  1908. $move = intval( hesk_GET('move') );
  1909. $_SESSION['artord'] = $id;
  1910. $result = hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_articles` SET `art_order`=`art_order`+".intval($move)." WHERE `id`='".intval($id)."'");
  1911. if (hesk_dbAffectedRows() != 1)
  1912. {
  1913. hesk_error($hesklang['kb_art_id']);
  1914. }
  1915. /* Update article order */
  1916. update_article_order($catid);
  1917. header('Location: manage_knowledgebase.php?a=manage_cat&catid='.$catid);
  1918. exit();
  1919. } // End order_article()
  1920. function show_treeMenu() {
  1921. global $hesk_settings, $hesklang, $treeMenu;
  1922. ?>
  1923. <script src="<?php echo HESK_PATH; ?>inc/treemenu/TreeMenu_v25.js" language="JavaScript" type="text/javascript"></script>
  1924. <div class="box">
  1925. <div class="box-header with-border">
  1926. <h1 class="box-title">
  1927. <?php echo $hesklang['kbstruct']; ?>
  1928. </h1>
  1929. <div class="box-tools pull-right">
  1930. <button type="button" class="btn btn-box-tool" data-widget="collapse">
  1931. <i class="fa fa-minus"></i>
  1932. </button>
  1933. </div>
  1934. </div>
  1935. <div class="box-body">
  1936. <?php $treeMenu->printMenu(); ?>
  1937. <i class="fa fa-plus icon-link green"></i> = <?php echo $hesklang['kb_p_art2']; ?><br />
  1938. <i class="fa fa-caret-right blue" style="font-size:18px"></i> = <?php echo $hesklang['kb_p_cat2']; ?><br />
  1939. <i class="fa fa-gear icon-link gray"></i> = <?php echo $hesklang['kb_p_man2']; ?><br />
  1940. <img src="../img/blank.gif" width="1" height="16" alt="" style="padding:1px" class="optionWhiteNbOFF" />(<span class="kb_published">1</span>, <span class="kb_private">2</span>, <span class="kb_draft">3</span>) = <?php echo $hesklang['xyz']; ?><br />
  1941. </div>
  1942. </div>
  1943. <?php
  1944. }
  1945. function show_subnav($hide='',$catid=1)
  1946. {
  1947. global $hesk_settings, $hesklang;
  1948. // If a category is selected, use it as default for articles and parents
  1949. if (isset($_SESSION['KB_CATEGORY']))
  1950. {
  1951. $catid = intval($_SESSION['KB_CATEGORY']);
  1952. }
  1953. $link['view'] = '<a href="knowledgebase_private.php"><i class="fa fa-search icon-link"></i></a> <a href="knowledgebase_private.php">'.$hesklang['gopr'].'</a> | ';
  1954. $link['newa'] = '<a href="manage_knowledgebase.php?a=add_article&amp;catid='.$catid.'"><i class="fa fa-plus icon-link green"></i></a> <a href="manage_knowledgebase.php?a=add_article&amp;catid='.$catid.'">'.$hesklang['kb_i_art'].'</a> | ';
  1955. $link['newc'] = '<a href="manage_knowledgebase.php?a=add_category&amp;parent='.$catid.'"><i class="fa fa-caret-right blue" style="font-size:18px"></i></a> <a href="manage_knowledgebase.php?a=add_category&amp;parent='.$catid.'">'.$hesklang['kb_i_cat'].'</a> | ';
  1956. if ($hide && isset($link[$hide]))
  1957. {
  1958. $link[$hide] = preg_replace('#<a([^<]*)>#', '', $link[$hide]);
  1959. $link[$hide] = str_replace('</a>','',$link[$hide]);
  1960. }
  1961. ?>
  1962. <form class="move-right-40" style="padding:0px;" method="get" action="manage_knowledgebase.php">
  1963. <p>
  1964. <?php
  1965. echo $link['view'];
  1966. echo $link['newa'];
  1967. echo $link['newc'];
  1968. ?>
  1969. <i class="fa fa-pencil icon-link orange"></i></a> <input type="hidden" name="a" value="edit_article" /><?php echo $hesklang['aid']; ?>: <input type="text" name="id" size="3" /> <input type="submit" value="<?php echo $hesklang['edit']; ?>" class="btn btn-default btn-xs" />
  1970. </p>
  1971. </form>
  1972. &nbsp;<br />
  1973. <div class="move-right-40 move-left-20">
  1974. <?php
  1975. /* This will handle error, success and notice messages */
  1976. hesk_handle_messages(); ?>
  1977. </div>
  1978. <?php
  1979. return $catid;
  1980. } // End show_subnav()
  1981. function toggle_sticky()
  1982. {
  1983. global $hesk_settings, $hesklang;
  1984. /* A security check */
  1985. hesk_token_check();
  1986. $id = intval( hesk_GET('id') ) or hesk_error($hesklang['kb_art_id']);
  1987. $catid = intval( hesk_GET('catid') ) or hesk_error($hesklang['kb_cat_inv']);
  1988. $sticky = empty($_GET['s']) ? 0 : 1;
  1989. $_SESSION['artord'] = $id;
  1990. /* Update article "sticky" status */
  1991. hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_articles` SET `sticky`='" . intval($sticky) . " ' WHERE `id`='" . intval($id) . "'");
  1992. /* Update article order */
  1993. update_article_order($catid);
  1994. $tmp = $sticky ? $hesklang['ason'] : $hesklang['asoff'];
  1995. hesk_process_messages($tmp, './manage_knowledgebase.php?a=manage_cat&catid='.$catid,'SUCCESS');
  1996. } // END toggle_sticky()
  1997. function update_article_order($catid)
  1998. {
  1999. global $hesk_settings, $hesklang;
  2000. /* Get list of current articles ordered by sticky and article order */
  2001. $res = hesk_dbQuery("SELECT `id`, `sticky` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_articles` WHERE `catid`='".intval($catid)."' ORDER BY `sticky` DESC, `art_order` ASC");
  2002. $i = 10;
  2003. $previous_sticky = 1;
  2004. while ( $article = hesk_dbFetchAssoc($res) )
  2005. {
  2006. /* Different count for sticky and non-sticky articles */
  2007. if ($previous_sticky != $article['sticky'])
  2008. {
  2009. $i = 10;
  2010. $previous_sticky = $article['sticky'];
  2011. }
  2012. hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_articles` SET `art_order`=".intval($i)." WHERE `id`='".intval($article['id'])."'");
  2013. $i += 10;
  2014. }
  2015. return true;
  2016. } // END update_article_order()
  2017. function update_category_order()
  2018. {
  2019. global $hesk_settings, $hesklang;
  2020. /* Get list of current articles ordered by sticky and article order */
  2021. $res = hesk_dbQuery('SELECT `id`, `parent` FROM `'.hesk_dbEscape($hesk_settings['db_pfix']).'kb_categories` ORDER BY `parent` ASC, `cat_order` ASC');
  2022. $i = 10;
  2023. while ( $category = hesk_dbFetchAssoc($res) )
  2024. {
  2025. hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_categories` SET `cat_order`=".intval($i)." WHERE `id`='".intval($category['id'])."'");
  2026. $i += 10;
  2027. }
  2028. return true;
  2029. } // END update_category_order()
  2030. function update_count($show_success=0)
  2031. {
  2032. global $hesk_settings, $hesklang;
  2033. $update_these = array();
  2034. // Get a count of all articles grouped by category and type
  2035. $res = hesk_dbQuery('SELECT `catid`, `type`, COUNT(*) AS `num` FROM `'.hesk_dbEscape($hesk_settings['db_pfix']).'kb_articles` GROUP BY `catid`, `type`');
  2036. while ( $row = hesk_dbFetchAssoc($res) )
  2037. {
  2038. switch ($row['type'])
  2039. {
  2040. case 0:
  2041. $update_these[$row['catid']]['articles'] = $row['num'];
  2042. break;
  2043. case 1:
  2044. $update_these[$row['catid']]['articles_private'] = $row['num'];
  2045. break;
  2046. default:
  2047. $update_these[$row['catid']]['articles_draft'] = $row['num'];
  2048. }
  2049. }
  2050. // Set all article counts to 0
  2051. hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_categories` SET `articles`=0, `articles_private`=0, `articles_draft`=0");
  2052. // Now update categories that have articles with correct values
  2053. foreach ($update_these as $catid => $value)
  2054. {
  2055. $value['articles'] = isset($value['articles']) ? $value['articles'] : 0;
  2056. $value['articles_private'] = isset($value['articles_private']) ? $value['articles_private'] : 0;
  2057. $value['articles_draft'] = isset($value['articles_draft']) ? $value['articles_draft'] : 0;
  2058. hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_categories` SET `articles`={$value['articles']}, `articles_private`={$value['articles_private']}, `articles_draft`={$value['articles_draft']} WHERE `id`='{$catid}'");
  2059. }
  2060. // Show a success message?
  2061. if ($show_success)
  2062. {
  2063. hesk_process_messages($hesklang['acv'], 'NOREDIRECT','SUCCESS');
  2064. }
  2065. return true;
  2066. } // END update_count()
  2067. function delete_category_recursive($catid)
  2068. {
  2069. global $hesk_settings, $hesklang;
  2070. $catid = intval($catid);
  2071. // Don't allow infinite loops... just in case
  2072. $hesk_settings['recursive_loop'] = isset($hesk_settings['recursive_loop']) ? $hesk_settings['recursive_loop'] + 1 :