113 $sql =
"SELECT id, code, type, libelle as label, color, active, picto";
114 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_actioncomm";
115 if (is_numeric($id)) {
116 $sql .=
" WHERE id=".(int) $id;
118 $sql .=
" WHERE code='".$this->db->escape($id).
"'";
121 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
122 $resql = $this->db->query($sql);
124 if ($this->db->num_rows($resql)) {
125 $obj = $this->db->fetch_object($resql);
127 $this->
id = $obj->id;
128 $this->code = $obj->code;
129 $this->
type = $obj->type;
130 $this->libelle = $obj->label;
131 $this->label = $obj->label;
132 $this->active = $obj->active;
133 $this->color = $obj->color;
135 $this->db->free($resql);
138 $this->db->free($resql);
142 $this->error = $this->db->error();
159 public function liste_array($active =
'', $idorcode =
'id', $excludetype =
'', $onlyautoornot = 0, $morefilter =
'', $shortlabel = 0)
162 global $langs, $conf, $user;
163 $langs->load(
"commercial");
169 $sql =
"SELECT id, code, libelle as label, module, type, color, picto";
170 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_actioncomm";
171 $sql .=
" WHERE 1=1";
173 $sql .=
" AND active=".(int) $active;
175 if (!empty($excludetype)) {
176 $sql .=
" AND type <> '".$this->db->escape($excludetype).
"'";
179 $sql .=
" AND ".$morefilter;
184 $sql .=
" ORDER BY position, type, module";
186 $sql .=
" ORDER BY type, position, module";
189 dol_syslog(get_class($this).
"::liste_array", LOG_DEBUG);
190 $resql = $this->db->query($sql);
192 $nump = $this->db->num_rows($resql);
194 $idforallfornewmodule = 96;
200 $TSystemAuto = array(
212 $obj = $this->db->fetch_object($resql);
220 if ($qualified && $onlyautoornot > 0 && preg_match(
'/^system/', $obj->type) && !preg_match(
'/^AC_OTH/', $obj->code)) {
224 if ($qualified && !empty($obj->module)) {
228 if ($obj->module ==
'invoice' && isModEnabled(
'invoice') && $user->hasRight(
'facture',
'lire')) {
231 if ($obj->module ==
'order' && isModEnabled(
'order') && !$user->hasRight(
'commande',
'lire')) {
234 if ($obj->module ==
'propal' && isModEnabled(
"propal") && $user->hasRight(
'propal',
'lire')) {
237 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')))) {
240 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')))) {
243 if ($obj->module ==
'shipping' && isModEnabled(
"shipping") && $user->hasRight(
'expedition',
'lire')) {
247 $tmparray = explode(
"@", $obj->module);
248 if (count($tmparray) > 1 && $tmparray[1] ==
'eventorganization' && isModEnabled(
'eventorganization')) {
253 if (preg_match(
'/^module/', $obj->type)) {
254 if (preg_match(
'/^(.+)@(.+)$/', $obj->module, $regs)) {
255 $tmpobject = $regs[1];
256 $tmpmodule = $regs[2];
258 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 if (! in_array($obj->type, array(
'system',
'systemauto',
'module',
'moduleauto'))) {
265 $tmpmodule = $obj->module;
267 if ($tmpmodule && isset($conf->$tmpmodule) && isModEnabled($tmpmodule)) {
277 $typecalendar = $obj->type;
279 if ($onlyautoornot > 0 && $typecalendar ==
'system') {
281 } elseif ($onlyautoornot > 0 && $typecalendar ==
'systemauto') {
283 } elseif ($onlyautoornot > 0) {
284 $code =
'AC_'.strtoupper($obj->module);
288 $keyfortrans =
"Action".$code.
'Short';
289 $transcode = $langs->trans($keyfortrans);
291 if (empty($keyfortrans) || $keyfortrans == $transcode) {
292 $keyfortrans =
"Action".$code;
293 $transcode = $langs->trans($keyfortrans);
296 $label = (($transcode != $keyfortrans) ? $transcode : $langs->trans($obj->label));
297 if (($onlyautoornot == -1 || $onlyautoornot == -2) &&
getDolGlobalString(
'AGENDA_USE_EVENT_TYPE')) {
299 if ($typecalendar ==
'system' || $typecalendar ==
'user') {
300 $label =
' '.$label;
301 $TSystem[
'id'][-99] = $langs->trans(
"ActionAC_MANUAL");
302 $TSystem[
'code'][
'AC_NON_AUTO'] =
'-- '.$langs->trans(
"ActionAC_MANUAL");
304 if ($typecalendar ==
'systemauto') {
305 $label =
' '.$label;
306 $TSystemAuto[
'id'][-98] = $langs->trans(
"ActionAC_AUTO");
307 $TSystemAuto[
'code'][
'AC_ALL_AUTO'] =
'-- '.$langs->trans(
"ActionAC_AUTO");
310 if ($typecalendar ==
'module') {
311 $module = preg_replace(
'/^[^@]+@/',
'', $obj->module);
312 $label =
' '.$label;
313 if (!isset($rep_code[
'AC_ALL_'.strtoupper($module)])) {
314 $idforallfornewmodule--;
316 $TModule[
'id'][$idforallfornewmodule] = $langs->trans(
"ActionAC_ALL_".strtoupper($module));
317 $TModule[
'code'][
'AC_ALL_'.strtoupper($module)] =
'-- '.$langs->trans(
"Module").
' '.ucfirst($module);
321 if ($typecalendar ==
'system' || $typecalendar ==
'user') {
322 $TSystem[
'id'][$obj->id] = $label;
323 $TSystem[
'code'][$obj->code] = $label;
324 $TSystem[
'all'][$obj->code] = array(
'id' => $label,
'label' => $label,
'type' => $typecalendar,
'color' => $obj->color,
'picto' => $obj->picto);
325 } elseif ($typecalendar ==
'systemauto') {
326 $TSystemAuto[
'id'][$obj->id] = $label;
327 $TSystemAuto[
'code'][$obj->code] = $label;
328 $TSystemAuto[
'all'][$obj->code] = array(
'id' => $label,
'label' => $label,
'type' => $typecalendar,
'color' => $obj->color,
'picto' => $obj->picto);
329 } elseif ($typecalendar ==
'module') {
330 $module = preg_replace(
'/^[^@]+@/',
'', $obj->module);
331 $TModule[
'id'][$obj->id] = $label;
332 $TModule[
'code'][$obj->code] = $label;
333 $TModule[
'all'][$obj->code] = array(
'id' => $label,
'label' => $langs->trans(
"Module").
' '.ucfirst($module).
' - '.$label,
'type' => $typecalendar,
'color' => $obj->color,
'picto' => $obj->picto);
336 if ($onlyautoornot > 0 && preg_match(
'/^module/', $obj->type) && $obj->module) {
337 $moduletoshow = ucfirst(preg_replace(
'/^[^@]+@/',
'', $obj->module));
340 $TModule[
'code'][$obj->code] = $moduletoshow.
' - '.$label;
341 $TModule[
'all'][$obj->code][
'label'] = $moduletoshow.
' - '.$label;
348 if (empty($idorcode)) {
351 $TType = $TSystem[$idorcode];
352 if (! empty($TSystemAuto[$idorcode])) {
353 $TType = array_merge($TType, $TSystemAuto[$idorcode]);
355 if (! empty($TModule[$idorcode])) {
356 $TType = array_merge($TType, $TModule[$idorcode]);
361 return $this->liste_array;
363 $this->error = $this->db->lasterror();