|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* Copyright (C) 2013-2016 Jean-François FERRY <[email protected]> |
|
4
|
|
|
* Copyright (C) 2016 Christophe Battarel <[email protected]> |
|
5
|
|
|
* Copyright (C) 2018-2023 Frédéric France <[email protected]> |
|
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
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* \file htdocs/core/boxes/box_last_modified_knowledgerecord.php |
|
23
|
|
|
* \ingroup knowledgerecord |
|
24
|
|
|
* \brief This box shows latest created knowledgerecords |
|
25
|
|
|
*/ |
|
26
|
|
|
require_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php"; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Class to manage the box |
|
30
|
|
|
*/ |
|
31
|
|
|
class box_last_modified_knowledgerecord extends ModeleBoxes |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* @var string boxcode |
|
35
|
|
|
*/ |
|
36
|
|
|
public $boxcode = "box_last_modified_knowledgerecord"; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var string box img |
|
40
|
|
|
*/ |
|
41
|
|
|
public $boximg = "knowledgemanagement"; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var string boc label |
|
45
|
|
|
*/ |
|
46
|
|
|
public $boxlabel; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var array box dependancies |
|
50
|
|
|
*/ |
|
51
|
|
|
public $depends = array("knowledgemanagement"); |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var DoliDB Database handler. |
|
55
|
|
|
*/ |
|
56
|
|
|
public $db; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @var string param |
|
60
|
|
|
*/ |
|
61
|
|
|
public $param; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @var array box info heads |
|
65
|
|
|
*/ |
|
66
|
|
|
public $info_box_head = array(); |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @var array box info content |
|
70
|
|
|
*/ |
|
71
|
|
|
public $info_box_contents = array(); |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Constructor |
|
75
|
|
|
* @param DoliDB $db Database handler |
|
76
|
|
|
* @param string $param More parameters |
|
77
|
|
|
*/ |
|
78
|
|
|
public function __construct($db, $param = '') |
|
79
|
|
|
{ |
|
80
|
|
|
global $langs; |
|
81
|
|
|
$langs->load("boxes", "knowledgemanagement", "languages"); |
|
82
|
|
|
$this->db = $db; |
|
83
|
|
|
|
|
84
|
|
|
$this->boxlabel = $langs->transnoentitiesnoconv("BoxLastModifiedKnowledgerecord"); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Load data into info_box_contents array to show array later. |
|
89
|
|
|
* |
|
90
|
|
|
* @param int $max Maximum number of records to load |
|
91
|
|
|
* @return void |
|
92
|
|
|
*/ |
|
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("BoxLastModifiedKnowledgerecordDescription", $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.tms 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
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* Method to show box |
|
207
|
|
|
* |
|
208
|
|
|
* @param array $head Array with properties of box title |
|
209
|
|
|
* @param array $contents Array with properties of box lines |
|
210
|
|
|
* @param int $nooutput No print, only return string |
|
211
|
|
|
* @return string |
|
212
|
|
|
*/ |
|
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
|
|
|
} |
|
218
|
|
|
|