diff --git a/htdocs/core/boxes/box_last_knowledgerecord.php b/htdocs/core/boxes/box_last_knowledgerecord.php new file mode 100644 index 00000000000..20510a5b3b0 --- /dev/null +++ b/htdocs/core/boxes/box_last_knowledgerecord.php @@ -0,0 +1,187 @@ + + * Copyright (C) 2016 Christophe Battarel + * Copyright (C) 2018-2023 Frédéric France + * + * 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 . + */ + +/** + * \file htdocs/core/boxes/box_last_knowledgerecord.php + * \ingroup knowledgerecord + * \brief This box shows latest created knowledgerecords + */ +require_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php"; + +/** + * Class to manage the box + */ +class box_last_knowledgerecord extends ModeleBoxes +{ + + public $boxcode = "box_last_knowledgerecord"; + public $boximg = "knowledgemanagement"; + public $boxlabel; + public $depends = array("knowledgemanagement"); + + /** + * @var DoliDB Database handler. + */ + public $db; + + public $param; + public $info_box_head = array(); + public $info_box_contents = array(); + + /** + * Constructor + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + public function __construct($db, $param = '') + { + global $langs; + $langs->load("boxes", "languages"); + $this->db = $db; + + $this->boxlabel = $langs->transnoentitiesnoconv("BoxLastKnowledgerecord"); + } + + /** + * Load data into info_box_contents array to show array later. + * + * @param int $max Maximum number of records to load + * @return void + */ + public function loadBox($max = 5) + { + global $conf, $user, $langs; + + $this->max = $max; + + require_once DOL_DOCUMENT_ROOT."/knowledgemanagement/class/knowledgerecord.class.php"; + + $text = $langs->trans("BoxLastKnowledgerecordDescription", $max); + $this->info_box_head = array( + 'text' => $text, + 'limit' => dol_strlen($text), + ); + + $this->info_box_contents[0][0] = array( + 'td' => 'class="left"', + 'text' => $langs->trans("BoxLastKnowledgerecordContent"), + ); + + if ($user->hasRight('knowledgemanagement', 'knowledgerecord', 'read')) { + $sql = 'SELECT k.rowid as id, k.date_creation, k.ref, k.lang, k.question, k.status as status'; + $sql .= " FROM ".MAIN_DB_PREFIX."knowledgemanagement_knowledgerecord as k"; + $sql .= " WHERE k.entity IN (".getEntity('knowledgemanagement').")"; + + if ($user->socid) { + $sql .= " AND k.fk_soc= ".((int) $user->socid); + } + + $sql.= " AND k.status > 0"; + + $sql .= " ORDER BY k.date_creation DESC, k.rowid DESC "; + $sql .= $this->db->plimit($max, 0); + + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + + $i = 0; + + while ($i < $num) { + $objp = $this->db->fetch_object($resql); + + $datec = $this->db->jdate($objp->date_creation); + + $knowledgerecord = new KnowledgeRecord($this->db); + $knowledgerecord->id = $objp->id; + $knowledgerecord->date_creation = $objp->date_creation; + $knowledgerecord->ref = $objp->ref; + $knowledgerecord->status = $objp->status; + $knowledgerecord->question = $objp->question; + + $r = 0; + + // Ticket + $this->info_box_contents[$i][$r] = array( + 'td' => 'class="nowraponall"', + 'text' => $knowledgerecord->getNomUrl(1), + 'asis' => 1 + ); + $r++; + + // Question + $this->info_box_contents[$i][$r] = array( + 'td' => 'class="tdoverflowmax200"', + 'text' => ''.dol_escape_htmltag($objp->question).'', + 'url' => DOL_URL_ROOT."/knowledgemanagement/knowledgerecord_card.php?id=".urlencode($objp->id), + ); + $r++; + + // Language + $labellang = ($objp->lang ? $langs->trans('Language_'.$objp->lang) : ''); + $this->info_box_contents[$i][$r] = array( + 'td' => 'class="tdoverflowmax100"', + 'text' => picto_from_langcode($objp->lang, 'class="paddingrightonly saturatemedium opacitylow"') . $labellang, + 'asis' => 1, + ); + $r++; + + // Date creation + $this->info_box_contents[$i][$r] = array( + 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateCreation").': '.dol_print_date($datec, 'dayhour', 'tzuserrel')).'"', + 'text' => dol_print_date($objp->datec, 'dayhour', 'tzuserrel'), + ); + $r++; + + // Statut + $this->info_box_contents[$i][$r] = array( + 'td' => 'class="right nowraponall"', + 'text' => $knowledgerecord->getLibStatut(3), + ); + $r++; + + $i++; + } + + if ($num == 0) { + $this->info_box_contents[$i][0] = array('td' => '', 'text' => ''.$langs->trans("BoxLastTicketNoRecordedTickets").''); + } + } else { + dol_print_error($this->db); + } + } else { + $this->info_box_contents[0][0] = array('td' => '', + 'text' => ''.$langs->trans("ReadPermissionNotAllowed").''); + } + } + + /** + * Method to show box + * + * @param array $head Array with properties of box title + * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string + * @return string + */ + public function showBox($head = null, $contents = null, $nooutput = 0) + { + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + } +} diff --git a/htdocs/core/boxes/box_last_modified_knowledgerecord.php b/htdocs/core/boxes/box_last_modified_knowledgerecord.php new file mode 100644 index 00000000000..5e23ee54602 --- /dev/null +++ b/htdocs/core/boxes/box_last_modified_knowledgerecord.php @@ -0,0 +1,187 @@ + + * Copyright (C) 2016 Christophe Battarel + * Copyright (C) 2018-2023 Frédéric France + * + * 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 . + */ + +/** + * \file htdocs/core/boxes/box_last_modified_knowledgerecord.php + * \ingroup knowledgerecord + * \brief This box shows latest created knowledgerecords + */ +require_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php"; + +/** + * Class to manage the box + */ +class box_last_modified_knowledgerecord extends ModeleBoxes +{ + + public $boxcode = "box_last_modified_knowledgerecord"; + public $boximg = "knowledgemanagement"; + public $boxlabel; + public $depends = array("knowledgemanagement"); + + /** + * @var DoliDB Database handler. + */ + public $db; + + public $param; + public $info_box_head = array(); + public $info_box_contents = array(); + + /** + * Constructor + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + public function __construct($db, $param = '') + { + global $langs; + $langs->load("boxes", "knowledgemanagement", "languages"); + $this->db = $db; + + $this->boxlabel = $langs->transnoentitiesnoconv("BoxLastModifiedKnowledgerecord"); + } + + /** + * Load data into info_box_contents array to show array later. + * + * @param int $max Maximum number of records to load + * @return void + */ + public function loadBox($max = 5) + { + global $conf, $user, $langs; + + $this->max = $max; + + require_once DOL_DOCUMENT_ROOT."/knowledgemanagement/class/knowledgerecord.class.php"; + + $text = $langs->trans("BoxLastModifiedKnowledgerecordDescription", $max); + $this->info_box_head = array( + 'text' => $text, + 'limit' => dol_strlen($text), + ); + + $this->info_box_contents[0][0] = array( + 'td' => 'class="left"', + 'text' => $langs->trans("BoxLastKnowledgerecordContent"), + ); + + if ($user->hasRight('knowledgemanagement', 'knowledgerecord', 'read')) { + $sql = 'SELECT k.rowid as id, k.date_creation, k.ref, k.lang, k.question, k.status as status'; + $sql .= " FROM ".MAIN_DB_PREFIX."knowledgemanagement_knowledgerecord as k"; + $sql .= " WHERE k.entity IN (".getEntity('knowledgemanagement').")"; + + if ($user->socid) { + $sql .= " AND k.fk_soc= ".((int) $user->socid); + } + + $sql.= " AND k.status > 0"; + + $sql .= " ORDER BY k.tms DESC, k.rowid DESC "; + $sql .= $this->db->plimit($max, 0); + + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + + $i = 0; + + while ($i < $num) { + $objp = $this->db->fetch_object($resql); + + $datec = $this->db->jdate($objp->date_creation); + + $knowledgerecord = new KnowledgeRecord($this->db); + $knowledgerecord->id = $objp->id; + $knowledgerecord->date_creation = $objp->date_creation; + $knowledgerecord->ref = $objp->ref; + $knowledgerecord->status = $objp->status; + $knowledgerecord->question = $objp->question; + + $r = 0; + + // Ticket + $this->info_box_contents[$i][$r] = array( + 'td' => 'class="nowraponall"', + 'text' => $knowledgerecord->getNomUrl(1), + 'asis' => 1 + ); + $r++; + + // Question + $this->info_box_contents[$i][$r] = array( + 'td' => 'class="tdoverflowmax200"', + 'text' => ''.dol_escape_htmltag($objp->question).'', + 'url' => DOL_URL_ROOT."/knowledgemanagement/knowledgerecord_card.php?id=".urlencode($objp->id), + ); + $r++; + + // Language + $labellang = ($objp->lang ? $langs->trans('Language_'.$objp->lang) : ''); + $this->info_box_contents[$i][$r] = array( + 'td' => 'class="tdoverflowmax100"', + 'text' => picto_from_langcode($objp->lang, 'class="paddingrightonly saturatemedium opacitylow"') . $labellang, + 'asis' => 1, + ); + $r++; + + // Date creation + $this->info_box_contents[$i][$r] = array( + 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateCreation").': '.dol_print_date($datec, 'dayhour', 'tzuserrel')).'"', + 'text' => dol_print_date($objp->datec, 'dayhour', 'tzuserrel'), + ); + $r++; + + // Statut + $this->info_box_contents[$i][$r] = array( + 'td' => 'class="right nowraponall"', + 'text' => $knowledgerecord->getLibStatut(3), + ); + $r++; + + $i++; + } + + if ($num == 0) { + $this->info_box_contents[$i][0] = array('td' => '', 'text' => ''.$langs->trans("BoxLastTicketNoRecordedTickets").''); + } + } else { + dol_print_error($this->db); + } + } else { + $this->info_box_contents[0][0] = array('td' => '', + 'text' => ''.$langs->trans("ReadPermissionNotAllowed").''); + } + } + + /** + * Method to show box + * + * @param array $head Array with properties of box title + * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string + * @return string + */ + public function showBox($head = null, $contents = null, $nooutput = 0) + { + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + } +} diff --git a/htdocs/core/modules/modKnowledgeManagement.class.php b/htdocs/core/modules/modKnowledgeManagement.class.php index 68754f530b3..c372f611c60 100644 --- a/htdocs/core/modules/modKnowledgeManagement.class.php +++ b/htdocs/core/modules/modKnowledgeManagement.class.php @@ -201,12 +201,14 @@ class modKnowledgeManagement extends DolibarrModules // Boxes/Widgets // Add here list of php file(s) stored in knowledgemanagement/core/boxes that contains a class to show a widget. $this->boxes = array( - // 0 => array( - // 'file' => 'knowledgemanagementwidget1.php@knowledgemanagement', - // 'note' => 'Widget provided by KnowledgeManagement', - // 'enabledbydefaulton' => 'Home', - // ), - // ... + 0 => array( + 'file' => 'box_last_knowledgerecord.php', + 'enabledbydefaulton' => 'ticketindex', + ), + 1 => array( + 'file' => 'box_last_modified_knowledgerecord.php', + 'enabledbydefaulton' => 'ticketindex', + ), ); // Cronjobs (List of cron jobs entries to add when module is enabled) diff --git a/htdocs/langs/en_US/knowledgemanagement.lang b/htdocs/langs/en_US/knowledgemanagement.lang index 38c1624afad..050ecbcc03a 100644 --- a/htdocs/langs/en_US/knowledgemanagement.lang +++ b/htdocs/langs/en_US/knowledgemanagement.lang @@ -51,4 +51,10 @@ SuggestedForTicketsInGroup=Suggested on ticket creation SetObsolete=Set as obsolete ConfirmCloseKM=Do you confirm the closing of this article as obsolete ? -ConfirmReopenKM=Do you want to restore this article to status "Validated" ? \ No newline at end of file +ConfirmReopenKM=Do you want to restore this article to status "Validated" ? +BoxLastKnowledgerecordDescription=Last %s articles +BoxLastKnowledgerecord=Last articles +BoxLastKnowledgerecordContent=Last articles +BoxLastKnowledgerecordModifiedContent=Last modified articles +BoxLastModifiedKnowledgerecordDescription=Last %s modified articles +BoxLastModifiedKnowledgerecord=Last modified articles