dolibarr 21.0.0-beta
fetchKnowledgeRecord.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
3 */
4/*
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
24if (!defined('NOTOKENRENEWAL')) {
25 define('NOTOKENRENEWAL', '1'); // Disables token renewal
26}
27if (!defined('NOREQUIREHTML')) {
28 define('NOREQUIREHTML', '1');
29}
30if (!defined('NOREQUIREAJAX')) {
31 define('NOREQUIREAJAX', '1');
32}
33if (!defined('NOREQUIRESOC')) {
34 define('NOREQUIRESOC', '1');
35}
36// Do not check anti CSRF attack test
37if (!defined('NOREQUIREMENU')) {
38 define('NOREQUIREMENU', '1');
39}
40// If we need access without being logged.
41if (!empty($_GET['public'])) { // Keep $_GET here. GETPOST() is not yet defined so we use $_GET
42 if (!defined("NOLOGIN")) {
43 define("NOLOGIN", '1');
44 }
45}
46if (!defined('NOIPCHECK')) {
47 define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
48}
49if (!defined('NOBROWSERNOTIF')) {
50 define('NOBROWSERNOTIF', '1');
51}
52include '../../main.inc.php';
53
62$action = GETPOST('action', 'aZ09');
63$idticketgroup = GETPOST('idticketgroup', 'aZ09');
64$idticketgroup = GETPOST('idticketgroup', 'aZ09');
65$lang = GETPOST('lang', 'aZ09');
66
67// Security check
68if (!defined("NOLOGIN")) { // No need of restrictedArea if not logged: Later the select will filter on public articles only if not logged.
69 restrictedArea($user, 'knowledgemanagement', 0, 'knowledgemanagement_knowledgerecord', 'knowledgerecord');
70}
71
72
73/*
74 * Actions
75 */
76
77// None
78
79
80/*
81 * View
82 */
83
84top_httphead('application/json');
85
86if ($action == "getKnowledgeRecord") {
87 $response = '';
88 $sql = "SELECT kr.rowid, kr.ref, kr.question, kr.answer,kr.url,ctc.code";
89 $sql .= " FROM ".MAIN_DB_PREFIX."knowledgemanagement_knowledgerecord as kr ";
90 $sql .= " JOIN ".MAIN_DB_PREFIX."c_ticket_category as ctc ON ctc.rowid = kr.fk_c_ticket_category";
91 $sql .= " WHERE ctc.code = '".$db->escape($idticketgroup)."'";
92 $sql .= " AND ctc.active = 1";
93 if (defined("NOLOGIN")) {
94 $sql .= " AND ctc.public = 1";
95 }
96 $sql .= " AND (kr.lang = '".$db->escape($lang)."' OR kr.lang = 0 OR kr.lang IS NULL)";
97 $sql .= " AND kr.status = 1 AND (kr.answer IS NOT NULL AND kr.answer <> '')";
98
99 $resql = $db->query($sql);
100 if ($resql) {
101 $num = $db->num_rows($resql);
102 $i = 0;
103 $response = array();
104 while ($i < $num) {
105 $obj = $db->fetch_object($resql);
106 $response[] = array('title'=>$obj->question,'ref'=>$obj->ref,'answer'=>dol_escape_htmltag(preg_replace('/\\r|\\r\\n|\\n/', "", $obj->answer)),'url'=>$obj->url);
107 $i++;
108 }
109 } else {
110 dol_print_error($db);
111 }
112 $response =json_encode($response);
113 echo $response;
114}
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.