dolibarr 22.0.5
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 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
31{
35 public $error = '';
36
40 public $db;
41
45 public $id;
46
50 public $code;
51
55 public $type;
56
62 public $libelle;
63
67 public $label;
68
72 public $active;
73
77 public $color;
78
82 public $picto;
83
87 public $liste_array;
88
89
95 public function __construct($db)
96 {
97 $this->db = $db;
98 }
99
106 public function fetch($id)
107 {
108 $sql = "SELECT id, code, type, libelle as label, color, active, picto";
109 $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm";
110 if (is_numeric($id)) {
111 $sql .= " WHERE id=".(int) $id;
112 } else {
113 $sql .= " WHERE code='".$this->db->escape($id)."'";
114 }
115
116 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
117 $resql = $this->db->query($sql);
118 if ($resql) {
119 if ($this->db->num_rows($resql)) {
120 $obj = $this->db->fetch_object($resql);
121
122 $this->id = $obj->id;
123 $this->code = $obj->code;
124 $this->type = $obj->type;
125 $this->libelle = $obj->label; // deprecated
126 $this->label = $obj->label;
127 $this->active = $obj->active;
128 $this->color = $obj->color;
129
130 $this->db->free($resql);
131 return 1;
132 } else {
133 $this->db->free($resql);
134 return 0;
135 }
136 } else {
137 $this->error = $this->db->error();
138 return -1;
139 }
140 }
141
142 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
154 public function liste_array($active = '', $idorcode = 'id', $excludetype = '', $onlyautoornot = 0, $morefilter = '', $shortlabel = 0)
155 {
156 // phpcs:enable
157 global $langs, $conf, $user;
158 $langs->load("commercial");
159
160 /*
161 $actionstatic = new ActionComm($this->db);
162
163 $rep_id = array();
164 $rep_code = array();
165 $rep_all = array();
166 */
167
168 $sql = "SELECT id, code, libelle as label, module, type, color, picto";
169 $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm";
170 $sql .= " WHERE 1=1";
171 if ($active != '') {
172 $sql .= " AND active=".(int) $active;
173 }
174 if (!empty($excludetype)) {
175 $sql .= " AND type <> '".$this->db->escape($excludetype)."'";
176 }
177 if ($morefilter) {
178 $sql .= " AND ".$morefilter;
179 }
180 // If AGENDA_SORT_EVENT_TYPE_BY_POSITION_FIRST is defined, we use position as main sort criterion
181 // otherwise we use type as main sort criterion
182 if (getDolGlobalString('AGENDA_SORT_EVENT_TYPE_BY_POSITION_FIRST')) {
183 $sql .= " ORDER BY position, type, module";
184 } else {
185 $sql .= " ORDER BY type, position, module";
186 }
187
188 dol_syslog(get_class($this)."::liste_array", LOG_DEBUG);
189 $resql = $this->db->query($sql);
190 if ($resql) {
191 $nump = $this->db->num_rows($resql);
192 if ($nump) {
193 $idforallfornewmodule = 96;
194 $TSystem = array(
195 'id' => [],
196 'code' => [],
197 'all' => []
198 );
199 $TSystemAuto = array(
200 'id' => [],
201 'code' => [],
202 'all' => []
203 );
204 $TModule = array(
205 'id' => [],
206 'code' => [],
207 'all' => []
208 );
209 $i = 0;
210 while ($i < $nump) {
211 $obj = $this->db->fetch_object($resql);
212
213 $qualified = 1;
214
215 // $obj->type into c_actioncomm can be 'system', 'systemauto', 'module', 'moduleauto', 'xxx', 'xxxauto'
216 // Note: type = system... than type of event is added among other standard events.
217 // type = module... then type of event is grouped into module defined into module = myobject@mymodule. Example: Event organization or external modules
218 // type = xxx... then type of event is added into list as a new flat value (not grouped). Example: Agefod external module
219 if ($qualified && $onlyautoornot > 0 && preg_match('/^system/', $obj->type) && !preg_match('/^AC_OTH/', $obj->code)) {
220 $qualified = 0; // We discard detailed system events. We keep only the 2 generic lines (AC_OTH and AC_OTH_AUTO)
221 }
222
223 if ($qualified && !empty($obj->module)) {
224 //var_dump($obj->type.' '.$obj->module.' '); var_dump($user->hasRight('facture', 'lire'));
225 $qualified = 0;
226 // Special cases
227 if ($obj->module == 'invoice' && isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
228 $qualified = 1;
229 }
230 if ($obj->module == 'order' && isModEnabled('order') && !$user->hasRight('commande', 'lire')) {
231 $qualified = 1;
232 }
233 if ($obj->module == 'propal' && isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
234 $qualified = 1;
235 }
236 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')))) {
237 $qualified = 1;
238 }
239 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')))) {
240 $qualified = 1;
241 }
242 if ($obj->module == 'shipping' && isModEnabled("shipping") && $user->hasRight('expedition', 'lire')) {
243 $qualified = 1;
244 }
245 // For case module = 'myobject@eventorganization'
246 $tmparray = explode("@", $obj->module);
247 if (count($tmparray) > 1 && $tmparray[1] == 'eventorganization' && isModEnabled('eventorganization')) {
248 $qualified = 1;
249 }
250 // For the generic case with type = 'module...' and module = 'myobject@mymodule'
251 $regs = array();
252 if (preg_match('/^module/', $obj->type)) {
253 if (preg_match('/^(.+)@(.+)$/', $obj->module, $regs)) {
254 $tmpobject = $regs[1];
255 $tmpmodule = $regs[2];
256 //var_dump($user->$tmpmodule);
257 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'))) {
258 $qualified = 1;
259 }
260 }
261 }
262 // For the case type is not 'system...' neither 'module', we just check module is on
263 if (! in_array($obj->type, array('system', 'systemauto', 'module', 'moduleauto'))) {
264 $tmpmodule = $obj->module;
265 //var_dump($tmpmodule);
266 if ($tmpmodule && isset($conf->$tmpmodule) && isModEnabled($tmpmodule)) {
267 $qualified = 1;
268 }
269 }
270 }
271
272 if ($qualified) {
273 $keyfortrans = '';
274 $transcode = '';
275 $code = $obj->code;
276 $typecalendar = $obj->type;
277
278 if ($onlyautoornot > 0 && $typecalendar == 'system') {
279 $code = 'AC_MANUAL';
280 } elseif ($onlyautoornot > 0 && $typecalendar == 'systemauto') {
281 $code = 'AC_AUTO';
282 } elseif ($onlyautoornot > 0) {
283 $code = 'AC_'.strtoupper($obj->module);
284 }
285
286 if ($shortlabel) {
287 $keyfortrans = "Action".$code.'Short';
288 $transcode = $langs->trans($keyfortrans);
289 }
290 if (empty($keyfortrans) || $keyfortrans == $transcode) {
291 $keyfortrans = "Action".$code;
292 $transcode = $langs->trans($keyfortrans);
293 }
294
295 $label = (($transcode != $keyfortrans) ? $transcode : $langs->trans($obj->label));
296 /*
297 $actionstatic->type_color = $obj->type_color;
298 $actionstatic->type_picto = $obj->type_picto;
299 $actionstatic->type = $obj->type;
300 $picto = $actionstatic->getTypePicto();
301 $label = $picto.$label;
302 */
303
304 if (($onlyautoornot == -1 || $onlyautoornot == -2) && getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
305 // Add a group of elements
306 if ($typecalendar == 'system' || $typecalendar == 'user') {
307 //$label = '&nbsp;&nbsp; '.$label;
308 $TSystem['id'][-99] = $langs->trans("ActionAC_MANUAL");
309 $TSystem['code']['AC_NON_AUTO'] = '<span class="smallincombo">-- '.$langs->trans("ActionAC_MANUAL").'</span>';
310 }
311 if ($typecalendar == 'systemauto') {
312 //$label = '&nbsp;&nbsp; '.$label;
313 $TSystemAuto['id'][-98] = $langs->trans("ActionAC_AUTO");
314 $TSystemAuto['code']['AC_ALL_AUTO'] = '<span class="smallincombo">-- '.$langs->trans("ActionAC_AUTO").'</span>';
315 }
316
317 if ($typecalendar == 'module') {
318 $module = preg_replace('/^[^@]+@/', '', $obj->module);
319 //$label = '&nbsp;&nbsp; '.$label;
320 if (!isset($TModule['id'][-1 * $idforallfornewmodule])) { // If first time for this module
321 $idforallfornewmodule--;
322 }
323 $TModule['id'][-1 * $idforallfornewmodule] = $langs->trans("ActionAC_ALL_".strtoupper($module));
324 $TModule['code']['AC_ALL_'.strtoupper($module)] = '<span class="smallincombo">-- '.$langs->trans("Module").' '.ucfirst($module).'</span>';
325 }
326 }
327 // Add element
328 if ($typecalendar == 'system' || $typecalendar == 'user') {
329 $TSystem['id'][$obj->id] = $label;
330 $TSystem['code'][$obj->code] = $label;
331 $TSystem['all'][$obj->code] = array('id' => $label, 'label' => $label, 'type' => $typecalendar, 'color' => $obj->color, 'picto' => $obj->picto);
332 } elseif ($typecalendar == 'systemauto') {
333 $TSystemAuto['id'][$obj->id] = $label;
334 $TSystemAuto['code'][$obj->code] = $label;
335 $TSystemAuto['all'][$obj->code] = array('id' => $label, 'label' => $label, 'type' => $typecalendar, 'color' => $obj->color, 'picto' => $obj->picto);
336 } elseif ($typecalendar == 'module') { // Can be automatic or manual
337 $module = preg_replace('/^[^@]+@/', '', $obj->module);
338 $TModule['id'][$obj->id] = $label;
339 $TModule['code'][$obj->code] = $label;
340 $TModule['all'][$obj->code] = array('id' => $label, 'label' => $langs->trans("Module").' '.ucfirst($module).' - '.$label, 'type' => $typecalendar, 'color' => $obj->color, 'picto' => $obj->picto);
341 }
342
343 if ($onlyautoornot > 0 && preg_match('/^module/', $obj->type) && $obj->module) {
344 $moduletoshow = ucfirst(preg_replace('/^[^@]+@/', '', $obj->module));
345 //array_key_exists($obj->code, $TModule['code']) ? ($TModule['code'][$obj->code] .= $langs->trans("Module").': '.$moduletoshow.' - '.$label) : ($TModule['code'][$obj->code] = $langs->trans("Module").': '.$moduletoshow.' - '.$label);
346 //array_key_exists($obj->code, $TModule['all']) ? ($TModule['all'][$obj->code]['label'] .= $langs->trans("Module").': '.$moduletoshow.' - '.$label) : ($TModule['all'][$obj->code]['label'] = $langs->trans("Module").': '.$moduletoshow.' - '.$label);
347 $TModule['code'][$obj->code] = $moduletoshow.' - '.$label;
348 $TModule['all'][$obj->code]['label'] = $moduletoshow.' - '.$label;
349 }
350 }
351 $i++;
352 }
353 }
354
355 if (empty($idorcode)) {
356 $idorcode = 'all';
357 }
358 $TType = $TSystem[$idorcode];
359 if (! empty($TSystemAuto[$idorcode])) {
360 $TType = array_merge($TType, $TSystemAuto[$idorcode]);
361 }
362 if (! empty($TModule[$idorcode])) {
363 $TType = array_merge($TType, $TModule[$idorcode]);
364 }
365 $this->liste_array = $TType;
366
367 return $this->liste_array;
368 } else {
369 $this->error = $this->db->lasterror();
370 return -1;
371 }
372 }
373
374
381 public function getNomUrl($withpicto = 0)
382 {
383 global $langs;
384
385 // Check if translation available
386 $transcode = $langs->trans("Action".$this->code);
387 if ($transcode != "Action".$this->code) {
388 return $transcode;
389 }
390 return -1;
391 }
392}
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 a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:158