dolibarr 21.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 * Copyright (C) 2024 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 $type_actions = array();
88
89
93 public $liste_array;
94
95
101 public function __construct($db)
102 {
103 $this->db = $db;
104 }
105
112 public function fetch($id)
113 {
114 $sql = "SELECT id, code, type, libelle as label, color, active, picto";
115 $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm";
116 if (is_numeric($id)) {
117 $sql .= " WHERE id=".(int) $id;
118 } else {
119 $sql .= " WHERE code='".$this->db->escape($id)."'";
120 }
121
122 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
123 $resql = $this->db->query($sql);
124 if ($resql) {
125 if ($this->db->num_rows($resql)) {
126 $obj = $this->db->fetch_object($resql);
127
128 $this->id = $obj->id;
129 $this->code = $obj->code;
130 $this->type = $obj->type;
131 $this->libelle = $obj->label; // deprecated
132 $this->label = $obj->label;
133 $this->active = $obj->active;
134 $this->color = $obj->color;
135
136 $this->db->free($resql);
137 return 1;
138 } else {
139 $this->db->free($resql);
140 return 0;
141 }
142 } else {
143 $this->error = $this->db->error();
144 return -1;
145 }
146 }
147
148 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
160 public function liste_array($active = '', $idorcode = 'id', $excludetype = '', $onlyautoornot = 0, $morefilter = '', $shortlabel = 0)
161 {
162 // phpcs:enable
163 global $langs, $conf, $user;
164 $langs->load("commercial");
165
166 /*
167 $actionstatic = new ActionComm($this->db);
168
169 $rep_id = array();
170 $rep_code = array();
171 $rep_all = array();
172 */
173
174 $sql = "SELECT id, code, libelle as label, module, type, color, picto";
175 $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm";
176 $sql .= " WHERE 1=1";
177 if ($active != '') {
178 $sql .= " AND active=".(int) $active;
179 }
180 if (!empty($excludetype)) {
181 $sql .= " AND type <> '".$this->db->escape($excludetype)."'";
182 }
183 if ($morefilter) {
184 $sql .= " AND ".$morefilter;
185 }
186 // If AGENDA_SORT_EVENT_TYPE_BY_POSITION_FIRST is defined, we use position as main sort criterion
187 // otherwise we use type as main sort criterion
188 if (getDolGlobalString('AGENDA_SORT_EVENT_TYPE_BY_POSITION_FIRST')) {
189 $sql .= " ORDER BY position, type, module";
190 } else {
191 $sql .= " ORDER BY type, position, module";
192 }
193
194 dol_syslog(get_class($this)."::liste_array", LOG_DEBUG);
195 $resql = $this->db->query($sql);
196 if ($resql) {
197 $nump = $this->db->num_rows($resql);
198 if ($nump) {
199 $idforallfornewmodule = 96;
200 $TSystem = array(
201 'id' => [],
202 'code' => [],
203 'all' => []
204 );
205 $TSystemAuto = array(
206 'id' => [],
207 'code' => [],
208 'all' => []
209 );
210 $TModule = array(
211 'id' => [],
212 'code' => [],
213 'all' => []
214 );
215 $i = 0;
216 while ($i < $nump) {
217 $obj = $this->db->fetch_object($resql);
218
219 $qualified = 1;
220
221 // $obj->type into c_actioncomm can be 'system', 'systemauto', 'module', 'moduleauto', 'xxx', 'xxxauto'
222 // Note: type = system... than type of event is added among other standard events.
223 // type = module... then type of event is grouped into module defined into module = myobject@mymodule. Example: Event organization or external modules
224 // type = xxx... then type of event is added into list as a new flat value (not grouped). Example: Agefod external module
225 if ($qualified && $onlyautoornot > 0 && preg_match('/^system/', $obj->type) && !preg_match('/^AC_OTH/', $obj->code)) {
226 $qualified = 0; // We discard detailed system events. We keep only the 2 generic lines (AC_OTH and AC_OTH_AUTO)
227 }
228
229 if ($qualified && !empty($obj->module)) {
230 //var_dump($obj->type.' '.$obj->module.' '); var_dump($user->hasRight('facture', 'lire'));
231 $qualified = 0;
232 // Special cases
233 if ($obj->module == 'invoice' && isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
234 $qualified = 1;
235 }
236 if ($obj->module == 'order' && isModEnabled('order') && !$user->hasRight('commande', 'lire')) {
237 $qualified = 1;
238 }
239 if ($obj->module == 'propal' && isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
240 $qualified = 1;
241 }
242 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')))) {
243 $qualified = 1;
244 }
245 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')))) {
246 $qualified = 1;
247 }
248 if ($obj->module == 'shipping' && isModEnabled("shipping") && $user->hasRight('expedition', 'lire')) {
249 $qualified = 1;
250 }
251 // For case module = 'myobject@eventorganization'
252 $tmparray = explode("@", $obj->module);
253 if (count($tmparray) > 1 && $tmparray[1] == 'eventorganization' && isModEnabled('eventorganization')) {
254 $qualified = 1;
255 }
256 // For the generic case with type = 'module...' and module = 'myobject@mymodule'
257 $regs = array();
258 if (preg_match('/^module/', $obj->type)) {
259 if (preg_match('/^(.+)@(.+)$/', $obj->module, $regs)) {
260 $tmpobject = $regs[1];
261 $tmpmodule = $regs[2];
262 //var_dump($user->$tmpmodule);
263 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'))) {
264 $qualified = 1;
265 }
266 }
267 }
268 // For the case type is not 'system...' neither 'module', we just check module is on
269 if (! in_array($obj->type, array('system', 'systemauto', 'module', 'moduleauto'))) {
270 $tmpmodule = $obj->module;
271 //var_dump($tmpmodule);
272 if ($tmpmodule && isset($conf->$tmpmodule) && isModEnabled($tmpmodule)) {
273 $qualified = 1;
274 }
275 }
276 }
277
278 if ($qualified) {
279 $keyfortrans = '';
280 $transcode = '';
281 $code = $obj->code;
282 $typecalendar = $obj->type;
283
284 if ($onlyautoornot > 0 && $typecalendar == 'system') {
285 $code = 'AC_MANUAL';
286 } elseif ($onlyautoornot > 0 && $typecalendar == 'systemauto') {
287 $code = 'AC_AUTO';
288 } elseif ($onlyautoornot > 0) {
289 $code = 'AC_'.strtoupper($obj->module);
290 }
291
292 if ($shortlabel) {
293 $keyfortrans = "Action".$code.'Short';
294 $transcode = $langs->trans($keyfortrans);
295 }
296 if (empty($keyfortrans) || $keyfortrans == $transcode) {
297 $keyfortrans = "Action".$code;
298 $transcode = $langs->trans($keyfortrans);
299 }
300
301 $label = (($transcode != $keyfortrans) ? $transcode : $langs->trans($obj->label));
302 /*
303 $actionstatic->type_color = $obj->type_color;
304 $actionstatic->type_picto = $obj->type_picto;
305 $actionstatic->type = $obj->type;
306 $picto = $actionstatic->getTypePicto();
307 $label = $picto.$label;
308 */
309
310 if (($onlyautoornot == -1 || $onlyautoornot == -2) && getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
311 // Add a group of elements
312 if ($typecalendar == 'system' || $typecalendar == 'user') {
313 //$label = '&nbsp;&nbsp; '.$label;
314 $TSystem['id'][-99] = $langs->trans("ActionAC_MANUAL");
315 $TSystem['code']['AC_NON_AUTO'] = '<span class="smallincombo">-- '.$langs->trans("ActionAC_MANUAL").'</span>';
316 }
317 if ($typecalendar == 'systemauto') {
318 //$label = '&nbsp;&nbsp; '.$label;
319 $TSystemAuto['id'][-98] = $langs->trans("ActionAC_AUTO");
320 $TSystemAuto['code']['AC_ALL_AUTO'] = '<span class="smallincombo">-- '.$langs->trans("ActionAC_AUTO").'</span>';
321 }
322
323 if ($typecalendar == 'module') {
324 $module = preg_replace('/^[^@]+@/', '', $obj->module);
325 //$label = '&nbsp;&nbsp; '.$label;
326 if (!isset($TModule['id'][-1 * $idforallfornewmodule])) { // If first time for this module
327 $idforallfornewmodule--;
328 }
329 $TModule['id'][-1 * $idforallfornewmodule] = $langs->trans("ActionAC_ALL_".strtoupper($module));
330 $TModule['code']['AC_ALL_'.strtoupper($module)] = '<span class="smallincombo">-- '.$langs->trans("Module").' '.ucfirst($module).'</span>';
331 }
332 }
333 // Add element
334 if ($typecalendar == 'system' || $typecalendar == 'user') {
335 $TSystem['id'][$obj->id] = $label;
336 $TSystem['code'][$obj->code] = $label;
337 $TSystem['all'][$obj->code] = array('id' => $label, 'label' => $label, 'type' => $typecalendar, 'color' => $obj->color, 'picto' => $obj->picto);
338 } elseif ($typecalendar == 'systemauto') {
339 $TSystemAuto['id'][$obj->id] = $label;
340 $TSystemAuto['code'][$obj->code] = $label;
341 $TSystemAuto['all'][$obj->code] = array('id' => $label, 'label' => $label, 'type' => $typecalendar, 'color' => $obj->color, 'picto' => $obj->picto);
342 } elseif ($typecalendar == 'module') { // Can be automatic or manual
343 $module = preg_replace('/^[^@]+@/', '', $obj->module);
344 $TModule['id'][$obj->id] = $label;
345 $TModule['code'][$obj->code] = $label;
346 $TModule['all'][$obj->code] = array('id' => $label, 'label' => $langs->trans("Module").' '.ucfirst($module).' - '.$label, 'type' => $typecalendar, 'color' => $obj->color, 'picto' => $obj->picto);
347 }
348
349 if ($onlyautoornot > 0 && preg_match('/^module/', $obj->type) && $obj->module) {
350 $moduletoshow = ucfirst(preg_replace('/^[^@]+@/', '', $obj->module));
351 //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);
352 //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);
353 $TModule['code'][$obj->code] = $moduletoshow.' - '.$label;
354 $TModule['all'][$obj->code]['label'] = $moduletoshow.' - '.$label;
355 }
356 }
357 $i++;
358 }
359 }
360
361 if (empty($idorcode)) {
362 $idorcode = 'all';
363 }
364 $TType = $TSystem[$idorcode];
365 if (! empty($TSystemAuto[$idorcode])) {
366 $TType = array_merge($TType, $TSystemAuto[$idorcode]);
367 }
368 if (! empty($TModule[$idorcode])) {
369 $TType = array_merge($TType, $TModule[$idorcode]);
370 }
371 $this->liste_array = $TType;
372
373 return $this->liste_array;
374 } else {
375 $this->error = $this->db->lasterror();
376 return -1;
377 }
378 }
379
380
387 public function getNomUrl($withpicto = 0)
388 {
389 global $langs;
390
391 // Check if translation available
392 $transcode = $langs->trans("Action".$this->code);
393 if ($transcode != "Action".$this->code) {
394 return $transcode;
395 }
396 return -1;
397 }
398}
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:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:150