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;
119 $sql .=
" WHERE code='".$this->db->escape($id).
"'";
122 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
123 $resql = $this->db->query($sql);
125 if ($this->db->num_rows($resql)) {
126 $obj = $this->db->fetch_object($resql);
128 $this->
id = $obj->id;
129 $this->code = $obj->code;
130 $this->
type = $obj->type;
131 $this->libelle = $obj->label;
132 $this->label = $obj->label;
133 $this->active = $obj->active;
134 $this->color = $obj->color;
136 $this->db->free($resql);
139 $this->db->free($resql);
143 $this->error = $this->db->error();
160 public function liste_array($active =
'', $idorcode =
'id', $excludetype =
'', $onlyautoornot = 0, $morefilter =
'', $shortlabel = 0)
163 global $langs,
$conf, $user;
164 $langs->load(
"commercial");
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";
178 $sql .=
" AND active=".(int) $active;
180 if (!empty($excludetype)) {
181 $sql .=
" AND type <> '".$this->db->escape($excludetype).
"'";
184 $sql .=
" AND ".$morefilter;
189 $sql .=
" ORDER BY position, type, module";
191 $sql .=
" ORDER BY type, position, module";
194 dol_syslog(get_class($this).
"::liste_array", LOG_DEBUG);
195 $resql = $this->db->query($sql);
197 $nump = $this->db->num_rows($resql);
199 $idforallfornewmodule = 96;
205 $TSystemAuto = array(
217 $obj = $this->db->fetch_object($resql);
225 if ($qualified && $onlyautoornot > 0 && preg_match(
'/^system/', $obj->type) && !preg_match(
'/^AC_OTH/', $obj->code)) {
229 if ($qualified && !empty($obj->module)) {
233 if ($obj->module ==
'invoice' && isModEnabled(
'invoice') && $user->hasRight(
'facture',
'lire')) {
236 if ($obj->module ==
'order' && isModEnabled(
'order') && !$user->hasRight(
'commande',
'lire')) {
239 if ($obj->module ==
'propal' && isModEnabled(
"propal") && $user->hasRight(
'propal',
'lire')) {
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')))) {
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')))) {
248 if ($obj->module ==
'shipping' && isModEnabled(
"shipping") && $user->hasRight(
'expedition',
'lire')) {
252 $tmparray = explode(
"@", $obj->module);
253 if (count($tmparray) > 1 && $tmparray[1] ==
'eventorganization' && isModEnabled(
'eventorganization')) {
258 if (preg_match(
'/^module/', $obj->type)) {
259 if (preg_match(
'/^(.+)@(.+)$/', $obj->module, $regs)) {
260 $tmpobject = $regs[1];
261 $tmpmodule = $regs[2];
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'))) {
269 if (! in_array($obj->type, array(
'system',
'systemauto',
'module',
'moduleauto'))) {
270 $tmpmodule = $obj->module;
272 if ($tmpmodule && isset(
$conf->$tmpmodule) && isModEnabled($tmpmodule)) {
282 $typecalendar = $obj->type;
284 if ($onlyautoornot > 0 && $typecalendar ==
'system') {
286 } elseif ($onlyautoornot > 0 && $typecalendar ==
'systemauto') {
288 } elseif ($onlyautoornot > 0) {
289 $code =
'AC_'.strtoupper($obj->module);
293 $keyfortrans =
"Action".$code.
'Short';
294 $transcode = $langs->trans($keyfortrans);
296 if (empty($keyfortrans) || $keyfortrans == $transcode) {
297 $keyfortrans =
"Action".$code;
298 $transcode = $langs->trans($keyfortrans);
301 $label = (($transcode != $keyfortrans) ? $transcode : $langs->trans($obj->label));
310 if (($onlyautoornot == -1 || $onlyautoornot == -2) &&
getDolGlobalString(
'AGENDA_USE_EVENT_TYPE')) {
312 if ($typecalendar ==
'system' || $typecalendar ==
'user') {
314 $TSystem[
'id'][-99] = $langs->trans(
"ActionAC_MANUAL");
315 $TSystem[
'code'][
'AC_NON_AUTO'] =
'<span class="smallincombo">-- '.$langs->trans(
"ActionAC_MANUAL").
'</span>';
317 if ($typecalendar ==
'systemauto') {
319 $TSystemAuto[
'id'][-98] = $langs->trans(
"ActionAC_AUTO");
320 $TSystemAuto[
'code'][
'AC_ALL_AUTO'] =
'<span class="smallincombo">-- '.$langs->trans(
"ActionAC_AUTO").
'</span>';
323 if ($typecalendar ==
'module') {
324 $module = preg_replace(
'/^[^@]+@/',
'', $obj->module);
326 if (!isset($TModule[
'id'][-1 * $idforallfornewmodule])) {
327 $idforallfornewmodule--;
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>';
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') {
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);
349 if ($onlyautoornot > 0 && preg_match(
'/^module/', $obj->type) && $obj->module) {
350 $moduletoshow = ucfirst(preg_replace(
'/^[^@]+@/',
'', $obj->module));
353 $TModule[
'code'][$obj->code] = $moduletoshow.
' - '.$label;
354 $TModule[
'all'][$obj->code][
'label'] = $moduletoshow.
' - '.$label;
361 if (empty($idorcode)) {
364 $TType = $TSystem[$idorcode];
365 if (! empty($TSystemAuto[$idorcode])) {
366 $TType = array_merge($TType, $TSystemAuto[$idorcode]);
368 if (! empty($TModule[$idorcode])) {
369 $TType = array_merge($TType, $TModule[$idorcode]);
373 return $this->liste_array;
375 $this->error = $this->db->lasterror();