Merge pull request #18727 from Hystepik/develop#4

Close #18677 : new show articles of KM
This commit is contained in:
Laurent Destailleur 2021-09-17 10:51:38 +02:00 committed by GitHub
commit 775544d47d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 182 additions and 1 deletions

View File

@ -0,0 +1,120 @@
<?php
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file /htdocs/core/ajax/fetchKnowledgeRecord.php
* \brief File to make Ajax action on Knowledge Management
*/
if (!defined('NOTOKENRENEWAL')) {
define('NOTOKENRENEWAL', '1'); // Disables token renewal
}
if (!defined('NOREQUIREHTML')) {
define('NOREQUIREHTML', '1');
}
if (!defined('NOREQUIREAJAX')) {
define('NOREQUIREAJAX', '1');
}
if (!defined('NOREQUIRESOC')) {
define('NOREQUIRESOC', '1');
}
if (!defined('NOCSRFCHECK')) {
define('NOCSRFCHECK', '1');
}
// Do not check anti CSRF attack test
if (!defined('NOREQUIREMENU')) {
define('NOREQUIREMENU', '1');
}
// If there is no need to load and show top and left menu
if (!defined("NOLOGIN")) {
define("NOLOGIN", '1');
}
if (!defined('NOIPCHECK')) {
define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
}
if (!defined('NOBROWSERNOTIF')) {
define('NOBROWSERNOTIF', '1');
}
include '../../main.inc.php';
$action = GETPOST('action', 'aZ09');
$idticketgroup = GETPOST('idticketgroup', 'aZ09');
$idticketgroup = GETPOST('idticketgroup', 'aZ09');
$lang = GETPOST('lang', 'aZ09');
$popupurl = GETPOST('popupurl', 'bool');
/*
* Actions
*/
// None
/*
* View
*/
if ($action == "getKnowledgeRecord") {
$response = '';
$sql = "SELECT kr.rowid, kr.ref, kr.question, kr.answer,l.url,ctc.code";
$sql .= " FROM ".MAIN_DB_PREFIX."links as l";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."knowledgemanagement_knowledgerecord as kr ON kr.rowid = l.objectid";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."c_ticket_category as ctc ON ctc.rowid = kr.fk_c_ticket_category";
$sql .= " WHERE ctc.code = '".$db->escape($idticketgroup)."'";
$sql .= " AND ctc.active = 1 AND ctc.public = 1 AND (kr.lang = '".$db->escape($lang)."' OR kr.lang = 0)";
$sql .= " AND kr.status = 1";
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
$response = array();
while ($i < $num) {
$obj = $db->fetch_object($resql);
if ($popupurl == "false") {
$url = "<a href=\"".$obj->url. "\" target=\"_blank\">".$obj->url."</a></li>";
$response[] = array('title'=>$obj->question,'ref'=>$obj->url,'answer'=>$obj->answer,'url'=>$url);
} else {
$name = $obj->ref;
$buttonstring = $obj->url;
$url = $obj->url;
$urltoprint = '<a class="button_'.$name.'" style="cursor:pointer">'.$buttonstring.'</a>';
$urltoprint .= '<!-- Add js code to open dialog popup on dialog -->';
$urltoprint .= '<script language="javascript">
jQuery(document).ready(function () {
jQuery(".button_'.$name.'").click(function () {
console.log("Open popup with jQuery(...).dialog() on URL '.dol_escape_js($url).'")
var $dialog = $(\'<div></div>\').html(\'<iframe class="iframedialog" style="border: 0px;" src="'.$url.'" width="100%" height="98%"></iframe>\')
.dialog({
autoOpen: false,
modal: true,
height: (window.innerHeight - 150),
width: \'80%\',
title: "'.dol_escape_js($label).'"
});
$dialog.dialog(\'open\');
});
});
</script>';
$response[] = array('title'=>$obj->question,'ref'=>$obj->url,'answer'=>$obj->answer,'url'=>$urltoprint);
}
$i++;
}
} else {
dol_print_error($db);
}
$response =json_encode($response);
echo $response;
}

View File

@ -243,6 +243,65 @@ class FormTicket
}
}
if ($conf->knowledgemanagement->enabled) {
// KM Articles
print '<tr id="KWwithajax"></tr>';
print '<!-- Script to manage change of ticket group -->
<script>
jQuery(document).ready(function() {
function groupticketchange(){
console.log("We called groupticketchange, so we try to load list KM linked to event");
$("#KWwithajax").html("");
idgroupticket = $("#selectcategory_code").val();
console.log("We have selected id="+idgroupticket);
if (idgroupticket != "") {
$.ajax({ url: \''.DOL_URL_ROOT.'/core/ajax/fetchKnowledgeRecord.php\',
data: { action: \'getKnowledgeRecord\', idticketgroup: idgroupticket, token: \''.newToken().'\', lang:\''.$langs->defaultlang.'\', popupurl:false},
type: \'GET\',
success: function(response) {
var urllist = \'\';
console.log("We received response "+response);
response = JSON.parse(response)
for (key in response) {
console.log(response[key])
urllist += "<li>" + response[key].title + ": " +response[key].url+"</li>";
}
if (urllist != "") {
console.log(urllist)
$("#KWwithajax").html(\'<td>'.$langs->trans("KMFoundForTicketGroup").'</td><td><ul style="list-style:none;padding-left: 0;">\'+urllist+\'</ul></td>\');
$("#KWwithajax").show();
}
},
error : function(output) {
console.log("error");
},
});
}
};
$("#selectcategory_code").bind("change",function() { groupticketchange(); });
MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var trackChange = function(element) {
var observer = new MutationObserver(function(mutations, observer) {
if (mutations[0].attributeName == "value") {
$(element).trigger("change");
}
});
observer.observe(element, {
attributes: true
});
}
trackChange($("#selectcategory_code")[0]);
if ($("#selectcategory_code").val() != "") {
groupticketchange();
}
});
</script>'."\n";
}
// MESSAGE
$msg = GETPOSTISSET('message') ? GETPOST('message', 'restricthtml') : '';
print '<tr><td><label for="message"><span class="fieldrequired">'.$langs->trans("Message").'</span></label></td><td>';

View File

@ -320,4 +320,5 @@ BoxNoTicketLastXDays=No new tickets the last %s days
BoxNumberOfTicketByDay=Number of new tickets by day
BoxNewTicketVSClose=Number of today's new tickets versus today's closed tickets
TicketCreatedToday=Ticket created today
TicketClosedToday=Ticket closed today
TicketClosedToday=Ticket closed today
KMFoundForTicketGroup=We found topics and FAQs that may answers your question, thanks to check them before submitting the ticket

View File

@ -321,3 +321,4 @@ BoxNumberOfTicketByDay=Nombre de nouveaux tickets par jour
BoxNewTicketVSClose=Nombre de nouveaux tickets aujourdhui par rapport aux tickets fermés aujourdhui
TicketCreatedToday=Ticket créé aujourd'hui
TicketClosedToday=Ticket fermé aujourd'hui
KMFoundForTicketGroup=Nous avons trouvé des sujets et des FAQ susceptibles de répondre à votre question, merci de les vérifier avant de soumettre le ticket