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;
113 $sql .=
" WHERE code='".$this->db->escape($id).
"'";
116 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
117 $resql = $this->db->query($sql);
119 if ($this->db->num_rows($resql)) {
120 $obj = $this->db->fetch_object($resql);
122 $this->
id = $obj->id;
123 $this->code = $obj->code;
124 $this->
type = $obj->type;
125 $this->libelle = $obj->label;
126 $this->label = $obj->label;
127 $this->active = $obj->active;
128 $this->color = $obj->color;
130 $this->db->free($resql);
133 $this->db->free($resql);
137 $this->error = $this->db->error();
154 public function liste_array($active =
'', $idorcode =
'id', $excludetype =
'', $onlyautoornot = 0, $morefilter =
'', $shortlabel = 0)
157 global $langs,
$conf, $user;
158 $langs->load(
"commercial");
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";
172 $sql .=
" AND active=".(int) $active;
174 if (!empty($excludetype)) {
175 $sql .=
" AND type <> '".$this->db->escape($excludetype).
"'";
178 $sql .=
" AND ".$morefilter;
183 $sql .=
" ORDER BY position, type, module";
185 $sql .=
" ORDER BY type, position, module";
188 dol_syslog(get_class($this).
"::liste_array", LOG_DEBUG);
189 $resql = $this->db->query($sql);
191 $nump = $this->db->num_rows($resql);
193 $idforallfornewmodule = 96;
199 $TSystemAuto = array(
211 $obj = $this->db->fetch_object($resql);
219 if ($qualified && $onlyautoornot > 0 && preg_match(
'/^system/', $obj->type) && !preg_match(
'/^AC_OTH/', $obj->code)) {
223 if ($qualified && !empty($obj->module)) {
227 if ($obj->module ==
'invoice' && isModEnabled(
'invoice') && $user->hasRight(
'facture',
'lire')) {
230 if ($obj->module ==
'order' && isModEnabled(
'order') && !$user->hasRight(
'commande',
'lire')) {
233 if ($obj->module ==
'propal' && isModEnabled(
"propal") && $user->hasRight(
'propal',
'lire')) {
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')))) {
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')))) {
242 if ($obj->module ==
'shipping' && isModEnabled(
"shipping") && $user->hasRight(
'expedition',
'lire')) {
246 $tmparray = explode(
"@", $obj->module);
247 if (count($tmparray) > 1 && $tmparray[1] ==
'eventorganization' && isModEnabled(
'eventorganization')) {
252 if (preg_match(
'/^module/', $obj->type)) {
253 if (preg_match(
'/^(.+)@(.+)$/', $obj->module, $regs)) {
254 $tmpobject = $regs[1];
255 $tmpmodule = $regs[2];
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'))) {
263 if (! in_array($obj->type, array(
'system',
'systemauto',
'module',
'moduleauto'))) {
264 $tmpmodule = $obj->module;
266 if ($tmpmodule && isset(
$conf->$tmpmodule) && isModEnabled($tmpmodule)) {
276 $typecalendar = $obj->type;
278 if ($onlyautoornot > 0 && $typecalendar ==
'system') {
280 } elseif ($onlyautoornot > 0 && $typecalendar ==
'systemauto') {
282 } elseif ($onlyautoornot > 0) {
283 $code =
'AC_'.strtoupper($obj->module);
287 $keyfortrans =
"Action".$code.
'Short';
288 $transcode = $langs->trans($keyfortrans);
290 if (empty($keyfortrans) || $keyfortrans == $transcode) {
291 $keyfortrans =
"Action".$code;
292 $transcode = $langs->trans($keyfortrans);
295 $label = (($transcode != $keyfortrans) ? $transcode : $langs->trans($obj->label));
304 if (($onlyautoornot == -1 || $onlyautoornot == -2) &&
getDolGlobalString(
'AGENDA_USE_EVENT_TYPE')) {
306 if ($typecalendar ==
'system' || $typecalendar ==
'user') {
308 $TSystem[
'id'][-99] = $langs->trans(
"ActionAC_MANUAL");
309 $TSystem[
'code'][
'AC_NON_AUTO'] =
'<span class="smallincombo">-- '.$langs->trans(
"ActionAC_MANUAL").
'</span>';
311 if ($typecalendar ==
'systemauto') {
313 $TSystemAuto[
'id'][-98] = $langs->trans(
"ActionAC_AUTO");
314 $TSystemAuto[
'code'][
'AC_ALL_AUTO'] =
'<span class="smallincombo">-- '.$langs->trans(
"ActionAC_AUTO").
'</span>';
317 if ($typecalendar ==
'module') {
318 $module = preg_replace(
'/^[^@]+@/',
'', $obj->module);
320 if (!isset($TModule[
'id'][-1 * $idforallfornewmodule])) {
321 $idforallfornewmodule--;
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>';
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') {
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);
343 if ($onlyautoornot > 0 && preg_match(
'/^module/', $obj->type) && $obj->module) {
344 $moduletoshow = ucfirst(preg_replace(
'/^[^@]+@/',
'', $obj->module));
347 $TModule[
'code'][$obj->code] = $moduletoshow.
' - '.$label;
348 $TModule[
'all'][$obj->code][
'label'] = $moduletoshow.
' - '.$label;
355 if (empty($idorcode)) {
358 $TType = $TSystem[$idorcode];
359 if (! empty($TSystemAuto[$idorcode])) {
360 $TType = array_merge($TType, $TSystemAuto[$idorcode]);
362 if (! empty($TModule[$idorcode])) {
363 $TType = array_merge($TType, $TModule[$idorcode]);
367 return $this->liste_array;
369 $this->error = $this->db->lasterror();