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");
172 $sql =
"SELECT id, code, libelle as label, module, type, color, picto";
173 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_actioncomm";
174 $sql .=
" WHERE 1=1";
176 $sql .=
" AND active=".(int) $active;
178 if (!empty($excludetype)) {
179 $sql .=
" AND type <> '".$this->db->escape($excludetype).
"'";
182 $sql .=
" AND ".$morefilter;
187 $sql .=
" ORDER BY position, type, module";
189 $sql .=
" ORDER BY type, position, module";
192 dol_syslog(get_class($this).
"::liste_array", LOG_DEBUG);
193 $resql = $this->db->query($sql);
195 $nump = $this->db->num_rows($resql);
197 $idforallfornewmodule = 96;
203 $TSystemAuto = array(
215 $obj = $this->db->fetch_object($resql);
223 if ($qualified && $onlyautoornot > 0 && preg_match(
'/^system/', $obj->type) && !preg_match(
'/^AC_OTH/', $obj->code)) {
227 if ($qualified && !empty($obj->module)) {
231 if ($obj->module ==
'invoice' && isModEnabled(
'invoice') && $user->hasRight(
'facture',
'lire')) {
234 if ($obj->module ==
'order' && isModEnabled(
'order') && !$user->hasRight(
'commande',
'lire')) {
237 if ($obj->module ==
'propal' && isModEnabled(
"propal") && $user->hasRight(
'propal',
'lire')) {
240 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 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 if ($obj->module ==
'shipping' && isModEnabled(
"shipping") && $user->hasRight(
'expedition',
'lire')) {
250 $tmparray = explode(
"@", $obj->module);
251 if (count($tmparray) > 1 && $tmparray[1] ==
'eventorganization' && isModEnabled(
'eventorganization')) {
256 if (preg_match(
'/^module/', $obj->type)) {
257 if (preg_match(
'/^(.+)@(.+)$/', $obj->module, $regs)) {
258 $tmpobject = $regs[1];
259 $tmpmodule = $regs[2];
261 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'))) {
267 if (! in_array($obj->type, array(
'system',
'systemauto',
'module',
'moduleauto'))) {
268 $tmpmodule = $obj->module;
270 if ($tmpmodule && isset($conf->$tmpmodule) && isModEnabled($tmpmodule)) {
280 $typecalendar = $obj->type;
282 if ($onlyautoornot > 0 && $typecalendar ==
'system') {
284 } elseif ($onlyautoornot > 0 && $typecalendar ==
'systemauto') {
286 } elseif ($onlyautoornot > 0) {
287 $code =
'AC_'.strtoupper($obj->module);
291 $keyfortrans =
"Action".$code.
'Short';
292 $transcode = $langs->trans($keyfortrans);
294 if (empty($keyfortrans) || $keyfortrans == $transcode) {
295 $keyfortrans =
"Action".$code;
296 $transcode = $langs->trans($keyfortrans);
299 $label = (($transcode != $keyfortrans) ? $transcode : $langs->trans($obj->label));
308 if (($onlyautoornot == -1 || $onlyautoornot == -2) &&
getDolGlobalString(
'AGENDA_USE_EVENT_TYPE')) {
310 if ($typecalendar ==
'system' || $typecalendar ==
'user') {
312 $TSystem[
'id'][-99] = $langs->trans(
"ActionAC_MANUAL");
313 $TSystem[
'code'][
'AC_NON_AUTO'] =
'<span class="smallincombo">-- '.$langs->trans(
"ActionAC_MANUAL").
'</span>';
315 if ($typecalendar ==
'systemauto') {
317 $TSystemAuto[
'id'][-98] = $langs->trans(
"ActionAC_AUTO");
318 $TSystemAuto[
'code'][
'AC_ALL_AUTO'] =
'<span class="smallincombo">-- '.$langs->trans(
"ActionAC_AUTO").
'</span>';
321 if ($typecalendar ==
'module') {
322 $module = preg_replace(
'/^[^@]+@/',
'', $obj->module);
324 if (!isset($TModule[
'id'][-1 * $idforallfornewmodule])) {
325 $idforallfornewmodule--;
327 $TModule[
'id'][-1 * $idforallfornewmodule] = $langs->trans(
"ActionAC_ALL_".strtoupper($module));
328 $TModule[
'code'][
'AC_ALL_'.strtoupper($module)] =
'<span class="smallincombo">-- '.$langs->trans(
"Module").
' '.ucfirst($module).
'</span>';
332 if ($typecalendar ==
'system' || $typecalendar ==
'user') {
333 $TSystem[
'id'][$obj->id] = $label;
334 $TSystem[
'code'][$obj->code] = $label;
335 $TSystem[
'all'][$obj->code] = array(
'id' => $label,
'label' => $label,
'type' => $typecalendar,
'color' => $obj->color,
'picto' => $obj->picto);
336 } elseif ($typecalendar ==
'systemauto') {
337 $TSystemAuto[
'id'][$obj->id] = $label;
338 $TSystemAuto[
'code'][$obj->code] = $label;
339 $TSystemAuto[
'all'][$obj->code] = array(
'id' => $label,
'label' => $label,
'type' => $typecalendar,
'color' => $obj->color,
'picto' => $obj->picto);
340 } elseif ($typecalendar ==
'module') {
341 $module = preg_replace(
'/^[^@]+@/',
'', $obj->module);
342 $TModule[
'id'][$obj->id] = $label;
343 $TModule[
'code'][$obj->code] = $label;
344 $TModule[
'all'][$obj->code] = array(
'id' => $label,
'label' => $langs->trans(
"Module").
' '.ucfirst($module).
' - '.$label,
'type' => $typecalendar,
'color' => $obj->color,
'picto' => $obj->picto);
347 if ($onlyautoornot > 0 && preg_match(
'/^module/', $obj->type) && $obj->module) {
348 $moduletoshow = ucfirst(preg_replace(
'/^[^@]+@/',
'', $obj->module));
351 $TModule[
'code'][$obj->code] = $moduletoshow.
' - '.$label;
352 $TModule[
'all'][$obj->code][
'label'] = $moduletoshow.
' - '.$label;
359 if (empty($idorcode)) {
362 $TType = $TSystem[$idorcode];
363 if (! empty($TSystemAuto[$idorcode])) {
364 $TType = array_merge($TType, $TSystemAuto[$idorcode]);
366 if (! empty($TModule[$idorcode])) {
367 $TType = array_merge($TType, $TModule[$idorcode]);
371 return $this->liste_array;
373 $this->error = $this->db->lasterror();