dolibarr 19.0.3
cactioncomm.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
30{
34 public $error = '';
35
39 public $db;
40
44 public $id;
45
49 public $code;
50
54 public $type;
55
61 public $libelle;
62
66 public $label;
67
71 public $active;
72
76 public $color;
77
81 public $picto;
82
86 public $type_actions = array();
87
88
92 public $liste_array;
93
94
100 public function __construct($db)
101 {
102 $this->db = $db;
103 }
104
111 public function fetch($id)
112 {
113 $sql = "SELECT id, code, type, libelle as label, color, active, picto";
114 $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm";
115 if (is_numeric($id)) {
116 $sql .= " WHERE id=".(int) $id;
117 } else {
118 $sql .= " WHERE code='".$this->db->escape($id)."'";
119 }
120
121 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
122 $resql = $this->db->query($sql);
123 if ($resql) {
124 if ($this->db->num_rows($resql)) {
125 $obj = $this->db->fetch_object($resql);
126
127 $this->id = $obj->id;
128 $this->code = $obj->code;
129 $this->type = $obj->type;
130 $this->libelle = $obj->label; // deprecated
131 $this->label = $obj->label;
132 $this->active = $obj->active;
133 $this->color = $obj->color;
134
135 $this->db->free($resql);
136 return 1;
137 } else {
138 $this->db->free($resql);
139 return 0;
140 }
141 } else {
142 $this->error = $this->db->error();
143 return -1;
144 }
145 }
146
147 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
159 public function liste_array($active = '', $idorcode = 'id', $excludetype = '', $onlyautoornot = 0, $morefilter = '', $shortlabel = 0)
160 {
161 // phpcs:enable
162 global $langs, $conf, $user;
163 $langs->load("commercial");
164
165 $repid = array();
166 $repcode = array();
167 $repall = array();
168
169 $sql = "SELECT id, code, libelle as label, module, type, color, picto";
170 $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm";
171 $sql .= " WHERE 1=1";
172 if ($active != '') {
173 $sql .= " AND active=".(int) $active;
174 }
175 if (!empty($excludetype)) {
176 $sql .= " AND type <> '".$this->db->escape($excludetype)."'";
177 }
178 if ($morefilter) {
179 $sql .= " AND ".$morefilter;
180 }
181 // If AGENDA_SORT_EVENT_TYPE_BY_POSITION_FIRST is defined, we use position as main sort criterion
182 // otherwise we use type as main sort criterion
183 if (getDolGlobalString('AGENDA_SORT_EVENT_TYPE_BY_POSITION_FIRST')) {
184 $sql .= " ORDER BY position, type, module";
185 } else {
186 $sql .= " ORDER BY type, position, module";
187 }
188
189 dol_syslog(get_class($this)."::liste_array", LOG_DEBUG);
190 $resql = $this->db->query($sql);
191 if ($resql) {
192 $nump = $this->db->num_rows($resql);
193 if ($nump) {
194 $idforallfornewmodule = 97;
195 $i = 0;
196 while ($i < $nump) {
197 $obj = $this->db->fetch_object($resql);
198
199 $qualified = 1;
200
201 // $obj->type can be 'system', 'systemauto', 'module', 'moduleauto', 'xxx', 'xxxauto'
202 // Note: type = system... than type of event is added among other standard events.
203 // type = module... then type of event is grouped into module defined into module = myobject@mymodule. Example: Event organization or external modules
204 // type = xxx... then type of event is added into list as a new flat value (not grouped). Example: Agefod external module
205 if ($qualified && $onlyautoornot > 0 && preg_match('/^system/', $obj->type) && !preg_match('/^AC_OTH/', $obj->code)) {
206 $qualified = 0; // We discard detailed system events. We keep only the 2 generic lines (AC_OTH and AC_OTH_AUTO)
207 }
208
209 if ($qualified && !empty($obj->module)) {
210 //var_dump($obj->type.' '.$obj->module.' '); var_dump($user->hasRight('facture', 'lire'));
211 $qualified = 0;
212 // Special cases
213 if ($obj->module == 'invoice' && isModEnabled('facture') && $user->hasRight('facture', 'lire')) {
214 $qualified = 1;
215 }
216 if ($obj->module == 'order' && isModEnabled('commande') && !$user->hasRight('commande', 'lire')) {
217 $qualified = 1;
218 }
219 if ($obj->module == 'propal' && isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
220 $qualified = 1;
221 }
222 if ($obj->module == 'invoice_supplier' && ((isModEnabled("fournisseur") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight('fournisseur', 'facture', 'lire')) || (isModEnabled('supplier_invoice') && $user->hasRight('supplier_invoice', 'lire')))) {
223 $qualified = 1;
224 }
225 if ($obj->module == 'order_supplier' && ((isModEnabled("fournisseur") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight('fournisseur', 'commande', 'lire')) || (!isModEnabled('supplier_order') && $user->hasRight('supplier_order', 'lire')))) {
226 $qualified = 1;
227 }
228 if ($obj->module == 'shipping' && isModEnabled("expedition") && $user->hasRight('expedition', 'lire')) {
229 $qualified = 1;
230 }
231 // For case module = 'myobject@eventorganization'
232 $tmparray = explode("@", $obj->module);
233 if (count($tmparray) > 1 && $tmparray[1] == 'eventorganization' && isModEnabled('eventorganization')) {
234 $qualified = 1;
235 }
236 // For the generic case with type = 'module...' and module = 'myobject@mymodule'
237 $regs = array();
238 if (preg_match('/^module/', $obj->type)) {
239 if (preg_match('/^(.+)@(.+)$/', $obj->module, $regs)) {
240 $tmpobject = $regs[1];
241 $tmpmodule = $regs[2];
242 //var_dump($user->$tmpmodule);
243 if ($tmpmodule && isset($conf->$tmpmodule) && isModEnabled($tmpmodule) && ($user->hasRight($tmpmodule, 'read') || $user->hasRight($tmpmodule, 'lire') || $user->hasRight($tmpmodule, $tmpobject, 'read') || $user->hasRight($tmpmodule, $tmpobject, 'lire'))) {
244 $qualified = 1;
245 }
246 }
247 }
248 // For the case type is not 'system...' neither 'module', we just check module is on
249 if (! in_array($obj->type, array('system', 'systemauto', 'module', 'moduleauto'))) {
250 $tmpmodule = $obj->module;
251 //var_dump($tmpmodule);
252 if ($tmpmodule && isset($conf->$tmpmodule) && isModEnabled($tmpmodule)) {
253 $qualified = 1;
254 }
255 }
256 }
257
258 if ($qualified) {
259 $keyfortrans = '';
260 $transcode = '';
261 $code = $obj->code;
262 $typecalendar = $obj->type;
263
264 if ($onlyautoornot > 0 && $typecalendar == 'system') {
265 $code = 'AC_MANUAL';
266 } elseif ($onlyautoornot > 0 && $typecalendar == 'systemauto') {
267 $code = 'AC_AUTO';
268 } elseif ($onlyautoornot > 0) {
269 $code = 'AC_'.strtoupper($obj->module);
270 }
271
272 if ($shortlabel) {
273 $keyfortrans = "Action".$code.'Short';
274 $transcode = $langs->trans($keyfortrans);
275 }
276 if (empty($keyfortrans) || $keyfortrans == $transcode) {
277 $keyfortrans = "Action".$code;
278 $transcode = $langs->trans($keyfortrans);
279 }
280 $label = (($transcode != $keyfortrans) ? $transcode : $langs->trans($obj->label));
281 if (($onlyautoornot == -1 || $onlyautoornot == -2) && getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
282 if ($typecalendar == 'system') {
283 $label = '&nbsp;&nbsp; '.$label;
284 $repid[-99] = $langs->trans("ActionAC_MANUAL");
285 $repcode['AC_NON_AUTO'] = '-- '.$langs->trans("ActionAC_MANUAL");
286 }
287 if ($typecalendar == 'systemauto') {
288 $label = '&nbsp;&nbsp; '.$label;
289 $repid[-98] = $langs->trans("ActionAC_AUTO");
290 $repcode['AC_ALL_AUTO'] = '-- '.$langs->trans("ActionAC_AUTO");
291 }
292 if ($typecalendar == 'module') {
293 //TODO check if possible to push it between system and systemauto
294 if (preg_match('/@/', $obj->module)) {
295 $module = explode('@', $obj->module)[1];
296 } else {
297 $module = $obj->module;
298 }
299 $label = '&nbsp;&nbsp; '.$label;
300 if (!isset($repcode['AC_ALL_'.strtoupper($module)])) { // If first time for this module
301 $idforallfornewmodule--;
302 }
303 $repid[$idforallfornewmodule] = $langs->trans("ActionAC_ALL_".strtoupper($module));
304 $repcode['AC_ALL_'.strtoupper($module)] = '-- '.$langs->trans("Module").' '.ucfirst($module);
305 }
306 }
307 $repid[$obj->id] = $label;
308 $repcode[$obj->code] = $label;
309 $repall[$obj->code] = array('id' => $label, 'label' => $label, 'type' => $typecalendar, 'color' => $obj->color, 'picto' => $obj->picto);
310 if ($onlyautoornot > 0 && preg_match('/^module/', $obj->type) && $obj->module) {
311 $repcode[$obj->code] .= ' ('.$langs->trans("Module").': '.$obj->module.')';
312 $repall[$obj->code]['label'] .= ' ('.$langs->trans("Module").': '.$obj->module.')';
313 }
314 }
315 $i++;
316 }
317 }
318
319 if ($idorcode == 'id') {
320 $this->liste_array = $repid;
321 } elseif ($idorcode == 'code') {
322 $this->liste_array = $repcode;
323 } else {
324 $this->liste_array = $repall;
325 }
326
327 return $this->liste_array;
328 } else {
329 $this->error = $this->db->lasterror();
330 return -1;
331 }
332 }
333
334
341 public function getNomUrl($withpicto = 0)
342 {
343 global $langs;
344
345 // Check if translation available
346 $transcode = $langs->trans("Action".$this->code);
347 if ($transcode != "Action".$this->code) {
348 return $transcode;
349 }
350 return -1;
351 }
352}
Class to manage different types of events.
liste_array($active='', $idorcode='id', $excludetype='', $onlyautoornot=0, $morefilter='', $shortlabel=0)
Return list of event types: array(id=>label) or array(code=>label)
fetch($id)
Load action type from database.
__construct($db)
Constructor.
getNomUrl($withpicto=0)
Return name of action type as a label translated.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:121