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 106KB

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