dolibarr  19.0.0-dev
box_last_knowledgerecord.php
Go to the documentation of this file.
1 <?php
2 /*
3  * Copyright (C) 2013-2016 Jean-François FERRY <hello@librethic.io>
4  * Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
5  * Copyright (C) 2018-2023 Frédéric France <frederic.france@netlogic.fr>
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
26 require_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
27 
32 {
36  public $boxcode = "box_last_knowledgerecord";
37 
41  public $boximg = "knowledgemanagement";
42 
46  public $boxlabel;
47 
51  public $depends = array("knowledgemanagement");
52 
56  public $db;
57 
61  public $param;
62 
66  public $info_box_head = array();
67 
71  public $info_box_contents = array();
72 
78  public function __construct($db, $param = '')
79  {
80  global $langs;
81  $langs->load("boxes", "languages");
82  $this->db = $db;
83 
84  $this->boxlabel = $langs->transnoentitiesnoconv("BoxLastKnowledgerecord");
85  }
86 
93  public function loadBox($max = 5)
94  {
95  global $user, $langs;
96 
97  $this->max = $max;
98 
99  require_once DOL_DOCUMENT_ROOT."/knowledgemanagement/class/knowledgerecord.class.php";
100 
101  $text = $langs->trans("BoxLastKnowledgerecordDescription", $max);
102  $this->info_box_head = array(
103  'text' => $text,
104  'limit' => dol_strlen($text),
105  );
106 
107  $this->info_box_contents[0][0] = array(
108  'td' => 'class="left"',
109  'text' => $langs->trans("BoxLastKnowledgerecordContent"),
110  );
111 
112  if ($user->hasRight('knowledgemanagement', 'knowledgerecord', 'read')) {
113  $sql = 'SELECT k.rowid as id, k.date_creation, k.ref, k.lang, k.question, k.status as status';
114  $sql .= " FROM ".MAIN_DB_PREFIX."knowledgemanagement_knowledgerecord as k";
115  $sql .= " WHERE k.entity IN (".getEntity('knowledgemanagement').")";
116 
117  if ($user->socid) {
118  $sql .= " AND k.fk_soc= ".((int) $user->socid);
119  }
120 
121  $sql.= " AND k.status > 0";
122 
123  $sql .= " ORDER BY k.date_creation DESC, k.rowid DESC ";
124  $sql .= $this->db->plimit($max, 0);
125 
126  $resql = $this->db->query($sql);
127  if ($resql) {
128  $num = $this->db->num_rows($resql);
129 
130  $i = 0;
131 
132  while ($i < $num) {
133  $objp = $this->db->fetch_object($resql);
134 
135  $datec = $this->db->jdate($objp->date_creation);
136 
137  $knowledgerecord = new KnowledgeRecord($this->db);
138  $knowledgerecord->id = $objp->id;
139  $knowledgerecord->date_creation = $objp->date_creation;
140  $knowledgerecord->ref = $objp->ref;
141  $knowledgerecord->status = $objp->status;
142  $knowledgerecord->question = $objp->question;
143 
144  $r = 0;
145 
146  // Ticket
147  $this->info_box_contents[$i][$r] = array(
148  'td' => 'class="nowraponall"',
149  'text' => $knowledgerecord->getNomUrl(1),
150  'asis' => 1
151  );
152  $r++;
153 
154  // Question
155  $this->info_box_contents[$i][$r] = array(
156  'td' => 'class="tdoverflowmax200"',
157  'text' => '<span title="'.dol_escape_htmltag($objp->question).'">'.dol_escape_htmltag($objp->question).'</span>',
158  'url' => DOL_URL_ROOT."/knowledgemanagement/knowledgerecord_card.php?id=".urlencode($objp->id),
159  );
160  $r++;
161 
162  // Language
163  $labellang = ($objp->lang ? $langs->trans('Language_'.$objp->lang) : '');
164  $this->info_box_contents[$i][$r] = array(
165  'td' => 'class="tdoverflowmax100"',
166  'text' => picto_from_langcode($objp->lang, 'class="paddingrightonly saturatemedium opacitylow"') . $labellang,
167  'asis' => 1,
168  );
169  $r++;
170 
171  // Date creation
172  $this->info_box_contents[$i][$r] = array(
173  'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateCreation").': '.dol_print_date($datec, 'dayhour', 'tzuserrel')).'"',
174  'text' => dol_print_date($datec, 'dayhour', 'tzuserrel'),
175  );
176  $r++;
177 
178  // Statut
179  $this->info_box_contents[$i][$r] = array(
180  'td' => 'class="right nowraponall"',
181  'text' => $knowledgerecord->getLibStatut(3),
182  );
183  $r++;
184 
185  $i++;
186  }
187 
188  if ($num == 0) {
189  $this->info_box_contents[$i][0] = array(
190  'td' => '',
191  'text' => '<span class="opacitymedium">'.$langs->trans("BoxLastTicketNoRecordedTickets").'</span>',
192  );
193  }
194  } else {
195  dol_print_error($this->db);
196  }
197  } else {
198  $this->info_box_contents[0][0] = array(
199  'td' => '',
200  'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>',
201  );
202  }
203  }
204 
213  public function showBox($head = null, $contents = null, $nooutput = 0)
214  {
215  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
216  }
217 }
box_last_knowledgerecord
Class to manage the box.
Definition: box_last_knowledgerecord.php:31
box_last_knowledgerecord\loadBox
loadBox($max=5)
Load data into info_box_contents array to show array later.
Definition: box_last_knowledgerecord.php:93
dol_escape_htmltag
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...
Definition: functions.lib.php:1600
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:5107
KnowledgeRecord
Class for KnowledgeRecord.
Definition: knowledgerecord.class.php:32
picto_from_langcode
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
Definition: functions.lib.php:9305
box_last_knowledgerecord\__construct
__construct($db, $param='')
Constructor.
Definition: box_last_knowledgerecord.php:78
box_last_knowledgerecord\showBox
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Definition: box_last_knowledgerecord.php:213
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2675
$sql
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3997
ModeleBoxes
Class ModeleBoxes.
Definition: modules_boxes.php:34