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.

manage_knowledgebase.php 107KB

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