fetchKnowledgeRecord.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /*
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. */
  16. /**
  17. * \file /htdocs/core/ajax/fetchKnowledgeRecord.php
  18. * \brief File to make Ajax action on Knowledge Management
  19. */
  20. if (!defined('NOTOKENRENEWAL')) {
  21. define('NOTOKENRENEWAL', '1'); // Disables token renewal
  22. }
  23. if (!defined('NOREQUIREHTML')) {
  24. define('NOREQUIREHTML', '1');
  25. }
  26. if (!defined('NOREQUIREAJAX')) {
  27. define('NOREQUIREAJAX', '1');
  28. }
  29. if (!defined('NOREQUIRESOC')) {
  30. define('NOREQUIRESOC', '1');
  31. }
  32. // Do not check anti CSRF attack test
  33. if (!defined('NOREQUIREMENU')) {
  34. define('NOREQUIREMENU', '1');
  35. }
  36. // If there is no need to load and show top and left menu
  37. if (!empty($_GET['public'])) {
  38. if (!defined("NOLOGIN")) {
  39. define("NOLOGIN", '1');
  40. }
  41. }
  42. if (!defined('NOIPCHECK')) {
  43. define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  44. }
  45. if (!defined('NOBROWSERNOTIF')) {
  46. define('NOBROWSERNOTIF', '1');
  47. }
  48. include '../../main.inc.php';
  49. $action = GETPOST('action', 'aZ09');
  50. $idticketgroup = GETPOST('idticketgroup', 'aZ09');
  51. $idticketgroup = GETPOST('idticketgroup', 'aZ09');
  52. $lang = GETPOST('lang', 'aZ09');
  53. /*if (defined("NOLOGIN") && !getDolGlobalString('TICKET_ENABLE_PUBLIC_INTERFACE')) {
  54. // If we ask public content (so without login), we block if option TICKET_ENABLE_PUBLIC_INTERFACE is not enabled
  55. httponly_accessforbidden('');
  56. }*/
  57. /*
  58. * Actions
  59. */
  60. // None
  61. /*
  62. * View
  63. */
  64. top_httphead('application/json');
  65. if ($action == "getKnowledgeRecord") {
  66. $response = '';
  67. $sql = "SELECT kr.rowid, kr.ref, kr.question, kr.answer,kr.url,ctc.code";
  68. $sql .= " FROM ".MAIN_DB_PREFIX."knowledgemanagement_knowledgerecord as kr ";
  69. $sql .= " JOIN ".MAIN_DB_PREFIX."c_ticket_category as ctc ON ctc.rowid = kr.fk_c_ticket_category";
  70. $sql .= " WHERE ctc.code = '".$db->escape($idticketgroup)."'";
  71. $sql .= " AND ctc.active = 1";
  72. if (defined("NOLOGIN")) {
  73. $sql .= " AND ctc.public = 1";
  74. }
  75. $sql .= " AND (kr.lang = '".$db->escape($lang)."' OR kr.lang = 0 OR kr.lang IS NULL)";
  76. $sql .= " AND kr.status = 1 AND (kr.answer IS NOT NULL AND kr.answer <> '')";
  77. $resql = $db->query($sql);
  78. if ($resql) {
  79. $num = $db->num_rows($resql);
  80. $i = 0;
  81. $response = array();
  82. while ($i < $num) {
  83. $obj = $db->fetch_object($resql);
  84. $response[] = array('title'=>$obj->question,'ref'=>$obj->ref,'answer'=>dol_escape_htmltag(preg_replace('/\\r|\\r\\n|\\n/', "", $obj->answer)),'url'=>$obj->url);
  85. $i++;
  86. }
  87. } else {
  88. dol_print_error($db);
  89. }
  90. $response =json_encode($response);
  91. echo $response;
  92. }