dolibarr 21.0.0-alpha
fetchKnowledgeRecord.php
Go to the documentation of this file.
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
22if (!defined('NOTOKENRENEWAL')) {
23 define('NOTOKENRENEWAL', '1'); // Disables token renewal
24}
25if (!defined('NOREQUIREHTML')) {
26 define('NOREQUIREHTML', '1');
27}
28if (!defined('NOREQUIREAJAX')) {
29 define('NOREQUIREAJAX', '1');
30}
31if (!defined('NOREQUIRESOC')) {
32 define('NOREQUIRESOC', '1');
33}
34// Do not check anti CSRF attack test
35if (!defined('NOREQUIREMENU')) {
36 define('NOREQUIREMENU', '1');
37}
38// If we need access without being logged.
39if (!empty($_GET['public'])) { // Keep $_GET here. GETPOST() is not yet defined so we use $_GET
40 if (!defined("NOLOGIN")) {
41 define("NOLOGIN", '1');
42 }
43}
44if (!defined('NOIPCHECK')) {
45 define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
46}
47if (!defined('NOBROWSERNOTIF')) {
48 define('NOBROWSERNOTIF', '1');
49}
50include '../../main.inc.php';
51
52$action = GETPOST('action', 'aZ09');
53$idticketgroup = GETPOST('idticketgroup', 'aZ09');
54$idticketgroup = GETPOST('idticketgroup', 'aZ09');
55$lang = GETPOST('lang', 'aZ09');
56
57// Security check
58if (!defined("NOLOGIN")) { // No need of restrictedArea if not logged: Later the select will filter on public articles only if not logged.
59 restrictedArea($user, 'knowledgemanagement', 0, 'knowledgemanagement_knowledgerecord', 'knowledgerecord');
60}
61
62
63/*
64 * Actions
65 */
66
67// None
68
69
70/*
71 * View
72 */
73
74top_httphead('application/json');
75
76if ($action == "getKnowledgeRecord") {
77 $response = '';
78 $sql = "SELECT kr.rowid, kr.ref, kr.question, kr.answer,kr.url,ctc.code";
79 $sql .= " FROM ".MAIN_DB_PREFIX."knowledgemanagement_knowledgerecord as kr ";
80 $sql .= " JOIN ".MAIN_DB_PREFIX."c_ticket_category as ctc ON ctc.rowid = kr.fk_c_ticket_category";
81 $sql .= " WHERE ctc.code = '".$db->escape($idticketgroup)."'";
82 $sql .= " AND ctc.active = 1";
83 if (defined("NOLOGIN")) {
84 $sql .= " AND ctc.public = 1";
85 }
86 $sql .= " AND (kr.lang = '".$db->escape($lang)."' OR kr.lang = 0 OR kr.lang IS NULL)";
87 $sql .= " AND kr.status = 1 AND (kr.answer IS NOT NULL AND kr.answer <> '')";
88
89 $resql = $db->query($sql);
90 if ($resql) {
91 $num = $db->num_rows($resql);
92 $i = 0;
93 $response = array();
94 while ($i < $num) {
95 $obj = $db->fetch_object($resql);
96 $response[] = array('title'=>$obj->question,'ref'=>$obj->ref,'answer'=>dol_escape_htmltag(preg_replace('/\\r|\\r\\n|\\n/', "", $obj->answer)),'url'=>$obj->url);
97 $i++;
98 }
99 } else {
100 dol_print_error($db);
101 }
102 $response =json_encode($response);
103 echo $response;
104}
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.