dolibarr  x.y.z
interface_50_modAgenda_ActionsAuto.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2009-2017 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2011-2014 Juanjo Menent <jmenent@2byte.es>
5  * Copyright (C) 2013 Cedric GROSS <c.gross@kreiz-it.fr>
6  * Copyright (C) 2014 Marcos GarcĂ­a <marcosgdf@gmail.com>
7  * Copyright (C) 2015 Bahfir Abbes <bafbes@gmail.com>
8  * Copyright (C) 2022 Ferran Marcet <fmarcet@2byte.es>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
30 require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
31 
32 
37 {
43  public function __construct($db)
44  {
45  $this->db = $db;
46 
47  $this->name = preg_replace('/^Interface/i', '', get_class($this));
48  $this->family = "agenda";
49  $this->description = "Triggers of this module add actions in agenda according to setup made in agenda setup.";
50  // 'development', 'experimental', 'dolibarr' or version
51  $this->version = self::VERSION_DOLIBARR;
52  $this->picto = 'action';
53  }
54 
77  public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
78  {
79  if (empty($conf->agenda) || empty($conf->agenda->enabled)) {
80  return 0; // Module not active, we do nothing
81  }
82 
83  // Do not log events when trigger is for creating event (infinite loop)
84  if (preg_match('/^ACTION_/', $action)) {
85  return 0;
86  }
87 
88  $key = 'MAIN_AGENDA_ACTIONAUTO_'.$action;
89  //var_dump($action.' - '.$conf->global->$key);exit;
90 
91  // Do not log events not enabled for this action
92  // GUI allow to set this option only if entry exists into table llx_c_action_trigger
93  if (empty($conf->global->$key)) {
94  return 0;
95  }
96 
97  $langs->load("agenda");
98 
99  if (empty($object->actiontypecode)) {
100  $object->actiontypecode = 'AC_OTH_AUTO';
101  }
102 
103  // Actions
104  if ($action == 'COMPANY_CREATE') {
105  // Load translation files required by the page
106  $langs->loadLangs(array("agenda", "other", "companies"));
107 
108  if (empty($object->actionmsg2)) {
109  $object->actionmsg2 = $langs->transnoentities("NewCompanyToDolibarr", $object->name);
110  }
111  $object->actionmsg = $langs->transnoentities("NewCompanyToDolibarr", $object->name);
112 
113  $object->sendtoid = 0;
114  $object->socid = $object->id;
115  } elseif ($action == 'COMPANY_MODIFY') {
116  // Load translation files required by the page
117  $langs->loadLangs(array("agenda", "other", "companies"));
118 
119  if (empty($object->actionmsg2)) {
120  $object->actionmsg2 = $langs->transnoentities("COMPANY_MODIFYInDolibarr", $object->name);
121  }
122  $object->actionmsg = $langs->transnoentities("COMPANY_MODIFYInDolibarr", $object->name);
123 
124  $object->sendtoid = 0;
125  $object->socid = $object->id;
126  } elseif ($action == 'COMPANY_SENTBYMAIL') {
127  // Load translation files required by the page
128  $langs->loadLangs(array("agenda", "other", "orders"));
129 
130  if (empty($object->actionmsg2)) {
131  dol_syslog('Trigger called with property actionmsg2 on object not defined', LOG_ERR);
132  }
133 
134  // Parameters $object->sendtoid defined by caller
135  //$object->sendtoid=0;
136  } elseif ($action == 'CONTACT_CREATE') {
137  // Load translation files required by the page
138  $langs->loadLangs(array("agenda", "other", "companies"));
139 
140  if (empty($object->actionmsg2)) {
141  $object->actionmsg2 = $langs->transnoentities("CONTACT_CREATEInDolibarr", $object->getFullName($langs));
142  }
143  $object->actionmsg = $langs->transnoentities("CONTACT_CREATEInDolibarr", $object->getFullName($langs));
144 
145  $object->sendtoid = array($object->id => $object->id);
146  $object->socid = $object->socid;
147  } elseif ($action == 'CONTACT_MODIFY') {
148  // Load translation files required by the page
149  $langs->loadLangs(array("agenda", "other", "companies"));
150 
151  if (empty($object->actionmsg2)) {
152  $object->actionmsg2 = $langs->transnoentities("CONTACT_MODIFYInDolibarr", $object->name);
153  }
154  $object->actionmsg = $langs->transnoentities("CONTACT_MODIFYInDolibarr", $object->name);
155 
156  $object->sendtoid = array($object->id => $object->id);
157  $object->socid = $object->socid;
158  } elseif ($action == 'CONTRACT_VALIDATE') {
159  // Load translation files required by the page
160  $langs->loadLangs(array("agenda", "other", "contracts"));
161 
162  if (empty($object->actionmsg2)) {
163  $object->actionmsg2 = $langs->transnoentities("ContractValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
164  }
165  $object->actionmsg = $langs->transnoentities("ContractValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
166 
167  $object->sendtoid = 0;
168  } elseif ($action == 'CONTRACT_SENTBYMAIL') {
169  // Load translation files required by the page
170  $langs->loadLangs(array("agenda", "other", "contracts"));
171 
172  if (empty($object->actionmsg2)) {
173  $object->actionmsg2 = $langs->transnoentities("ContractSentByEMail", $object->ref);
174  }
175  if (empty($object->actionmsg)) {
176  $object->actionmsg = $langs->transnoentities("ContractSentByEMail", $object->ref);
177  }
178 
179  // Parameters $object->sendtoid defined by caller
180  //$object->sendtoid=0;
181  } elseif ($action == 'PROPAL_VALIDATE') {
182  // Load translation files required by the page
183  $langs->loadLangs(array("agenda", "other", "propal"));
184 
185  if (empty($object->actionmsg2)) {
186  $object->actionmsg2 = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
187  }
188  $object->actionmsg = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
189 
190  $object->sendtoid = 0;
191  } elseif ($action == 'PROPAL_MODIFY') {
192  // Load translation files required by the page
193  $langs->loadLangs(array("agenda", "other", "propal"));
194 
195  if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("PropalBackToDraftInDolibarr", ($object->newref ? $object->newref : $object->ref));
196  $object->actionmsg = $langs->transnoentities("PropalBackToDraftInDolibarr", ($object->newref ? $object->newref : $object->ref));
197 
198  $object->sendtoid = 0;
199  } elseif ($action == 'PROPAL_SENTBYMAIL') {
200  // Load translation files required by the page
201  $langs->loadLangs(array("agenda", "other", "propal"));
202 
203  if (empty($object->actionmsg2)) {
204  $object->actionmsg2 = $langs->transnoentities("ProposalSentByEMail", $object->ref);
205  }
206  if (empty($object->actionmsg)) {
207  $object->actionmsg = $langs->transnoentities("ProposalSentByEMail", $object->ref);
208  }
209 
210  // Parameters $object->sendtoid defined by caller
211  //$object->sendtoid=0;
212  } elseif ($action == 'PROPAL_CLOSE_SIGNED') {
213  // Load translation files required by the page
214  $langs->loadLangs(array("agenda", "other", "propal"));
215 
216  if (empty($object->actionmsg2)) {
217  $object->actionmsg2 = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref);
218  }
219  $object->actionmsg = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref);
220 
221  $object->sendtoid = 0;
222  } elseif ($action == 'PROPAL_CLASSIFY_BILLED') {
223  // Load translation files required by the page
224  $langs->loadLangs(array("agenda", "other", "propal"));
225 
226  if (empty($object->actionmsg2)) {
227  $object->actionmsg2 = $langs->transnoentities("PropalClassifiedBilledInDolibarr", $object->ref);
228  }
229  $object->actionmsg = $langs->transnoentities("PropalClassifiedBilledInDolibarr", $object->ref);
230 
231  $object->sendtoid = 0;
232  } elseif ($action == 'PROPAL_CLOSE_REFUSED') {
233  // Load translation files required by the page
234  $langs->loadLangs(array("agenda", "other", "propal"));
235 
236  if (empty($object->actionmsg2)) {
237  $object->actionmsg2 = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref);
238  }
239  $object->actionmsg = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref);
240 
241  $object->sendtoid = 0;
242  } elseif ($action == 'ORDER_VALIDATE') {
243  // Load translation files required by the page
244  $langs->loadLangs(array("agenda", "orders"));
245 
246  if (empty($object->actionmsg2)) {
247  $object->actionmsg2 = $langs->transnoentities("OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
248  }
249  $object->actionmsg = $langs->transnoentities("OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
250 
251  $object->sendtoid = 0;
252  } elseif ($action == 'ORDER_CLOSE') {
253  // Load translation files required by the page
254  $langs->loadLangs(array("agenda", "other", "orders"));
255 
256  if (empty($object->actionmsg2)) {
257  $object->actionmsg2 = $langs->transnoentities("OrderDeliveredInDolibarr", $object->ref);
258  }
259  $object->actionmsg = $langs->transnoentities("OrderDeliveredInDolibarr", $object->ref);
260 
261  $object->sendtoid = 0;
262  } elseif ($action == 'ORDER_CLASSIFY_BILLED') {
263  // Load translation files required by the page
264  $langs->loadLangs(array("agenda", "other", "orders"));
265 
266  if (empty($object->actionmsg2)) {
267  $object->actionmsg2 = $langs->transnoentities("OrderBilledInDolibarr", $object->ref);
268  }
269  $object->actionmsg = $langs->transnoentities("OrderBilledInDolibarr", $object->ref);
270 
271  $object->sendtoid = 0;
272  } elseif ($action == 'ORDER_CANCEL') {
273  // Load translation files required by the page
274  $langs->loadLangs(array("agenda", "other", "orders"));
275 
276  if (empty($object->actionmsg2)) {
277  $object->actionmsg2 = $langs->transnoentities("OrderCanceledInDolibarr", $object->ref);
278  }
279  $object->actionmsg = $langs->transnoentities("OrderCanceledInDolibarr", $object->ref);
280 
281  $object->sendtoid = 0;
282  } elseif ($action == 'ORDER_SENTBYMAIL') {
283  // Load translation files required by the page
284  $langs->loadLangs(array("agenda", "other", "orders"));
285 
286  if (empty($object->actionmsg2)) {
287  $object->actionmsg2 = $langs->transnoentities("OrderSentByEMail", $object->ref);
288  }
289  if (empty($object->actionmsg)) {
290  $object->actionmsg = $langs->transnoentities("OrderSentByEMail", $object->ref);
291  }
292 
293  // Parameters $object->sendtoid defined by caller
294  //$object->sendtoid=0;
295  } elseif ($action == 'BILL_VALIDATE') {
296  // Load translation files required by the page
297  $langs->loadLangs(array("agenda", "other", "bills"));
298 
299  if (empty($object->actionmsg2)) {
300  $object->actionmsg2 = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
301  }
302  $object->actionmsg = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
303 
304  $object->sendtoid = 0;
305  } elseif ($action == 'BILL_UNVALIDATE') {
306  // Load translation files required by the page
307  $langs->loadLangs(array("agenda", "other", "bills"));
308 
309  if (empty($object->actionmsg2)) {
310  $object->actionmsg2 = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref);
311  }
312  $object->actionmsg = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref);
313 
314  $object->sendtoid = 0;
315  } elseif ($action == 'BILL_SENTBYMAIL') {
316  // Load translation files required by the page
317  $langs->loadLangs(array("agenda", "other", "bills"));
318 
319  if (empty($object->actionmsg2)) {
320  $object->actionmsg2 = $langs->transnoentities("InvoiceSentByEMail", $object->ref);
321  }
322  if (empty($object->actionmsg)) {
323  $object->actionmsg = $langs->transnoentities("InvoiceSentByEMail", $object->ref);
324  }
325 
326  // Parameters $object->sendtoid defined by caller
327  //$object->sendtoid=0;
328  } elseif ($action == 'BILL_PAYED') {
329  // Load translation files required by the page
330  $langs->loadLangs(array("agenda", "other", "bills"));
331 
332  // Values for this action can't be defined by caller.
333  $object->actionmsg2 = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
334  $object->actionmsg = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
335 
336  $object->sendtoid = 0;
337  } elseif ($action == 'BILL_CANCEL') {
338  // Load translation files required by the page
339  $langs->loadLangs(array("agenda", "other", "bills"));
340 
341  if (empty($object->actionmsg2)) {
342  $object->actionmsg2 = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
343  }
344  $object->actionmsg = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
345 
346  $object->sendtoid = 0;
347  } elseif ($action == 'FICHINTER_CREATE') {
348  // Load translation files required by the page
349  $langs->loadLangs(array("agenda", "other", "interventions"));
350 
351  if (empty($object->actionmsg2)) {
352  $object->actionmsg2 = $langs->transnoentities("InterventionCreatedInDolibarr", $object->ref);
353  }
354  $object->actionmsg = $langs->transnoentities("InterventionCreatedInDolibarr", $object->ref);
355 
356  $object->sendtoid = 0;
357  $object->fk_element = 0;
358  $object->elementtype = '';
359  } elseif ($action == 'FICHINTER_VALIDATE') {
360  // Load translation files required by the page
361  $langs->loadLangs(array("agenda", "other", "interventions"));
362 
363  if (empty($object->actionmsg2)) {
364  $object->actionmsg2 = $langs->transnoentities("InterventionValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
365  }
366  $object->actionmsg = $langs->transnoentities("InterventionValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
367 
368  $object->sendtoid = 0;
369  $object->fk_element = 0;
370  $object->elementtype = '';
371  } elseif ($action == 'FICHINTER_MODIFY') {
372  // Load translation files required by the page
373  $langs->loadLangs(array("agenda", "other", "interventions"));
374 
375  if (empty($object->actionmsg2)) {
376  $object->actionmsg2 = $langs->transnoentities("InterventionModifiedInDolibarr", $object->ref);
377  }
378  $object->actionmsg = $langs->transnoentities("InterventionModifiedInDolibarr", $object->ref);
379 
380  $object->sendtoid = 0;
381  $object->fk_element = 0;
382  $object->elementtype = '';
383  } elseif ($action == 'FICHINTER_SENTBYMAIL') {
384  // Load translation files required by the page
385  $langs->loadLangs(array("agenda", "other", "interventions"));
386 
387  if (empty($object->actionmsg2)) {
388  $object->actionmsg2 = $langs->transnoentities("InterventionSentByEMail", $object->ref);
389  }
390  if (empty($object->actionmsg)) {
391  $object->actionmsg = $langs->transnoentities("InterventionSentByEMail", $object->ref);
392  }
393 
394  // Parameters $object->sendtoid defined by caller
395  //$object->sendtoid=0;
396  } elseif ($action == 'FICHINTER_CLASSIFY_BILLED') {
397  // Load translation files required by the page
398  $langs->loadLangs(array("agenda", "other", "interventions"));
399 
400  if (empty($object->actionmsg2)) {
401  $object->actionmsg2 = $langs->transnoentities("InterventionClassifiedBilledInDolibarr", $object->ref);
402  }
403  $object->actionmsg = $langs->transnoentities("InterventionClassifiedBilledInDolibarr", $object->ref);
404 
405  $object->sendtoid = 0;
406  } elseif ($action == 'FICHINTER_CLASSIFY_UNBILLED') {
407  // Load translation files required by the page
408  $langs->loadLangs(array("agenda", "other", "interventions"));
409 
410  if (empty($object->actionmsg2)) {
411  $object->actionmsg2 = $langs->transnoentities("InterventionClassifiedUnbilledInDolibarr", $object->ref);
412  }
413  $object->actionmsg = $langs->transnoentities("InterventionClassifiedUnbilledInDolibarr", $object->ref);
414 
415  $object->sendtoid = 0;
416  } elseif ($action == 'FICHINTER_DELETE') {
417  // Load translation files required by the page
418  $langs->loadLangs(array("agenda", "other", "interventions"));
419 
420  if (empty($object->actionmsg2)) {
421  $object->actionmsg2 = $langs->transnoentities("InterventionDeletedInDolibarr", $object->ref);
422  }
423  $object->actionmsg = $langs->transnoentities("InterventionDeletedInDolibarr", $object->ref);
424 
425  $object->sendtoid = 0;
426  $object->fk_element = 0;
427  $object->elementtype = '';
428  } elseif ($action == 'SHIPPING_VALIDATE') {
429  // Load translation files required by the page
430  $langs->loadLangs(array("agenda", "other", "sendings"));
431 
432  if (empty($object->actionmsg2)) {
433  $object->actionmsg2 = $langs->transnoentities("ShippingValidated", ($object->newref ? $object->newref : $object->ref));
434  }
435  if (empty($object->actionmsg)) {
436  $object->actionmsg = $langs->transnoentities("ShippingValidated", ($object->newref ? $object->newref : $object->ref));
437  }
438 
439  // Parameters $object->sendtoid defined by caller
440  //$object->sendtoid=0;
441  } elseif ($action == 'SHIPPING_SENTBYMAIL') {
442  // Load translation files required by the page
443  $langs->loadLangs(array("agenda", "other", "sendings"));
444 
445  if (empty($object->actionmsg2)) {
446  $object->actionmsg2 = $langs->transnoentities("ShippingSentByEMail", $object->ref);
447  }
448  if (empty($object->actionmsg)) {
449  $object->actionmsg = $langs->transnoentities("ShippingSentByEMail", $object->ref);
450  }
451 
452  // Parameters $object->sendtoid defined by caller
453  //$object->sendtoid=0;
454  } elseif ($action == 'RECEPTION_VALIDATE') {
455  $langs->load("agenda");
456  $langs->load("other");
457  $langs->load("receptions");
458 
459  if (empty($object->actionmsg2)) {
460  $object->actionmsg2 = $langs->transnoentities("ReceptionValidated", ($object->newref ? $object->newref : $object->ref));
461  }
462  if (empty($object->actionmsg)) {
463  $object->actionmsg = $langs->transnoentities("ReceptionValidated", ($object->newref ? $object->newref : $object->ref));
464  }
465 
466  // Parameters $object->sendtoid defined by caller
467  //$object->sendtoid=0;
468  } elseif ($action == 'RECEPTION_SENTBYMAIL') {
469  $langs->load("agenda");
470  $langs->load("other");
471  $langs->load("receptions");
472 
473  if (empty($object->actionmsg2)) {
474  $object->actionmsg2 = $langs->transnoentities("ReceptionSentByEMail", $object->ref);
475  }
476  if (empty($object->actionmsg)) {
477  $object->actionmsg = $langs->transnoentities("ReceptionSentByEMail", $object->ref);
478  }
479 
480  // Parameters $object->sendtoid defined by caller
481  //$object->sendtoid=0;
482  } elseif ($action == 'PROPOSAL_SUPPLIER_VALIDATE') {
483  // Load translation files required by the page
484  $langs->loadLangs(array("agenda", "other", "propal"));
485 
486  if (empty($object->actionmsg2)) {
487  $object->actionmsg2 = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
488  }
489  $object->actionmsg = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
490 
491  $object->sendtoid = 0;
492  } elseif ($action == 'PROPOSAL_SUPPLIER_SENTBYMAIL') {
493  // Load translation files required by the page
494  $langs->loadLangs(array("agenda", "other", "propal"));
495 
496  if (empty($object->actionmsg2)) {
497  $object->actionmsg2 = $langs->transnoentities("ProposalSentByEMail", $object->ref);
498  }
499  if (empty($object->actionmsg)) {
500  $object->actionmsg = $langs->transnoentities("ProposalSentByEMail", $object->ref);
501  }
502 
503  // Parameters $object->sendtoid defined by caller
504  //$object->sendtoid=0;
505  } elseif ($action == 'PROPOSAL_SUPPLIER_CLOSE_SIGNED') {
506  // Load translation files required by the page
507  $langs->loadLangs(array("agenda", "other", "propal"));
508 
509  if (empty($object->actionmsg2)) {
510  $object->actionmsg2 = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref);
511  }
512  $object->actionmsg = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref);
513 
514  $object->sendtoid = 0;
515  } elseif ($action == 'PROPOSAL_SUPPLIER_CLOSE_REFUSED') {
516  // Load translation files required by the page
517  $langs->loadLangs(array("agenda", "other", "propal"));
518 
519  if (empty($object->actionmsg2)) {
520  $object->actionmsg2 = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref);
521  }
522  $object->actionmsg = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref);
523 
524  $object->sendtoid = 0;
525  } elseif ($action == 'ORDER_SUPPLIER_CREATE') {
526  // Load translation files required by the page
527  $langs->loadLangs(array("agenda", "other", "orders"));
528 
529  if (empty($object->actionmsg2)) {
530  $object->actionmsg2 = $langs->transnoentities("OrderCreatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
531  }
532  $object->actionmsg = $langs->transnoentities("OrderCreatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
533 
534  $object->sendtoid = 0;
535  } elseif ($action == 'ORDER_SUPPLIER_VALIDATE') {
536  // Load translation files required by the page
537  $langs->loadLangs(array("agenda", "other", "orders"));
538 
539  if (empty($object->actionmsg2)) {
540  $object->actionmsg2 = $langs->transnoentities("OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
541  }
542  $object->actionmsg = $langs->transnoentities("OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
543 
544  $object->sendtoid = 0;
545  } elseif ($action == 'ORDER_SUPPLIER_APPROVE') {
546  // Load translation files required by the page
547  $langs->loadLangs(array("agenda", "other", "orders"));
548 
549  if (empty($object->actionmsg2)) {
550  $object->actionmsg2 = $langs->transnoentities("OrderApprovedInDolibarr", $object->ref);
551  }
552  $object->actionmsg = $langs->transnoentities("OrderApprovedInDolibarr", $object->ref);
553 
554  $object->sendtoid = 0;
555  } elseif ($action == 'ORDER_SUPPLIER_REFUSE') {
556  // Load translation files required by the page
557  $langs->loadLangs(array("agenda", "other", "orders", "main"));
558 
559  if (empty($object->actionmsg2)) {
560  $object->actionmsg2 = $langs->transnoentities("OrderRefusedInDolibarr", $object->ref);
561  }
562  $object->actionmsg = $langs->transnoentities("OrderRefusedInDolibarr", $object->ref);
563 
564  if (!empty($object->refuse_note)) {
565  $object->actionmsg .= '<br>';
566  $object->actionmsg .= $langs->trans("Reason") . ': '.$object->refuse_note;
567  }
568 
569  $object->sendtoid = 0;
570  } elseif ($action == 'ORDER_SUPPLIER_CANCEL') {
571  // Load translation files required by the page
572  $langs->loadLangs(array("agenda", "other", "orders", "main"));
573 
574  if (empty($object->actionmsg2)) {
575  $object->actionmsg2 = $langs->transnoentities("OrderCanceledInDolibarr", $object->ref);
576  }
577  $object->actionmsg = $langs->transnoentities("OrderCanceledInDolibarr", $object->ref);
578 
579  if (!empty($object->cancel_note)) {
580  $object->actionmsg .= '<br>';
581  $object->actionmsg .= $langs->trans("Reason") . ': '.$object->cancel_note;
582  }
583 
584  $object->sendtoid = 0;
585  } elseif ($action == 'ORDER_SUPPLIER_SUBMIT') {
586  // Load translation files required by the page
587  $langs->loadLangs(array("agenda", "other", "orders"));
588 
589  if (empty($object->actionmsg2)) {
590  $object->actionmsg2 = $langs->transnoentities("SupplierOrderSubmitedInDolibarr", ($object->newref ? $object->newref : $object->ref));
591  }
592  $object->actionmsg = $langs->transnoentities("SupplierOrderSubmitedInDolibarr", ($object->newref ? $object->newref : $object->ref));
593 
594  if (!empty($object->context['comments'])) {
595  $object->actionmsg .= '<br>';
596  $object->actionmsg .= $langs->trans("Comment") . ': '.$object->context['comments'];
597  }
598 
599  $object->sendtoid = 0;
600  } elseif ($action == 'ORDER_SUPPLIER_RECEIVE') {
601  // Load translation files required by the page
602  $langs->loadLangs(array("agenda", "other", "orders"));
603 
604  if (empty($object->actionmsg2)) {
605  $object->actionmsg2 = $langs->transnoentities("SupplierOrderReceivedInDolibarr", ($object->newref ? $object->newref : $object->ref));
606  }
607  $object->actionmsg = $langs->transnoentities("SupplierOrderReceivedInDolibarr", ($object->newref ? $object->newref : $object->ref));
608 
609  $object->sendtoid = 0;
610  } elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL') {
611  // Load translation files required by the page
612  $langs->loadLangs(array("agenda", "other", "bills", "orders"));
613 
614  if (empty($object->actionmsg2)) {
615  $object->actionmsg2 = $langs->transnoentities("SupplierOrderSentByEMail", $object->ref);
616  }
617  if (empty($object->actionmsg)) {
618  $object->actionmsg = $langs->transnoentities("SupplierOrderSentByEMail", $object->ref);
619  }
620 
621  // Parameters $object->sendtoid defined by caller
622  //$object->sendtoid=0;
623  } elseif ($action == 'ORDER_SUPPLIER_CLASSIFY_BILLED') {
624  // Load translation files required by the page
625  $langs->loadLangs(array("agenda", "other", "bills", "orders"));
626 
627  if (empty($object->actionmsg2)) {
628  $object->actionmsg2 = $langs->transnoentities("SupplierOrderClassifiedBilled", $object->ref);
629  }
630  if (empty($object->actionmsg)) {
631  $object->actionmsg = $langs->transnoentities("SupplierOrderClassifiedBilled", $object->ref);
632  }
633 
634  $object->sendtoid = 0;
635  } elseif ($action == 'BILL_SUPPLIER_VALIDATE') {
636  // Load translation files required by the page
637  $langs->loadLangs(array("agenda", "other", "bills"));
638 
639  if (empty($object->actionmsg2)) {
640  $object->actionmsg2 = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
641  }
642  $object->actionmsg = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
643 
644  $object->sendtoid = 0;
645  } elseif ($action == 'BILL_SUPPLIER_UNVALIDATE') {
646  // Load translation files required by the page
647  $langs->loadLangs(array("agenda", "other", "bills"));
648 
649  if (empty($object->actionmsg2)) {
650  $object->actionmsg2 = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref);
651  }
652  $object->actionmsg = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref);
653 
654  $object->sendtoid = 0;
655  } elseif ($action == 'BILL_SUPPLIER_SENTBYMAIL') {
656  // Load translation files required by the page
657  $langs->loadLangs(array("agenda", "other", "bills", "orders"));
658 
659  if (empty($object->actionmsg2)) {
660  $object->actionmsg2 = $langs->transnoentities("SupplierInvoiceSentByEMail", $object->ref);
661  }
662  if (empty($object->actionmsg)) {
663  $object->actionmsg = $langs->transnoentities("SupplierInvoiceSentByEMail", $object->ref);
664  }
665 
666  // Parameters $object->sendtoid defined by caller
667  //$object->sendtoid=0;
668  } elseif ($action == 'BILL_SUPPLIER_PAYED') {
669  // Load translation files required by the page
670  $langs->loadLangs(array("agenda", "other", "bills"));
671 
672  if (empty($object->actionmsg2)) {
673  $object->actionmsg2 = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
674  }
675  $object->actionmsg = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
676 
677  $object->sendtoid = 0;
678  } elseif ($action == 'BILL_SUPPLIER_CANCELED') {
679  // Load translation files required by the page
680  $langs->loadLangs(array("agenda", "other", "bills"));
681 
682  if (empty($object->actionmsg2)) {
683  $object->actionmsg2 = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
684  }
685  $object->actionmsg = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
686 
687  $object->sendtoid = 0;
688  } elseif ($action == 'MEMBER_VALIDATE') {
689  // Members
690  // Load translation files required by the page
691  $langs->loadLangs(array("agenda", "other", "members"));
692 
693  if (empty($object->actionmsg2)) {
694  $object->actionmsg2 = $langs->transnoentities("MemberValidatedInDolibarr", $object->getFullName($langs));
695  }
696  $object->actionmsg = $langs->transnoentities("MemberValidatedInDolibarr", $object->getFullName($langs));
697  $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
698  $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type;
699 
700  $object->sendtoid = 0;
701  } elseif ($action == 'MEMBER_MODIFY') {
702  // Load translation files required by the page
703  $langs->loadLangs(array("agenda", "other", "members"));
704 
705  if (empty($object->actionmsg2)) {
706  $object->actionmsg2 = $langs->transnoentities("MemberModifiedInDolibarr", $object->getFullName($langs));
707  }
708  $object->actionmsg = $langs->transnoentities("MemberModifiedInDolibarr", $object->getFullName($langs));
709  $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
710  $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type;
711 
712  $object->sendtoid = 0;
713  } elseif ($action == 'MEMBER_SUBSCRIPTION_CREATE') {
714  // Load translation files required by the page
715  $langs->loadLangs(array("agenda", "other", "members"));
716 
717  $member = (isset($this->context['member']) ? $this->context['member'] : null);
718  if (!is_object($member)) { // This should not happen
719  dol_syslog("Execute a trigger MEMBER_SUBSCRIPTION_CREATE with context key 'member' not an object");
720  include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
721  $member = new Adherent($this->db);
722  $member->fetch($object->fk_adherent);
723  }
724 
725  if (empty($object->actionmsg2)) {
726  $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionAddedInDolibarr", $object->id, $member->getFullName($langs));
727  }
728  $object->actionmsg = $langs->transnoentities("MemberSubscriptionAddedInDolibarr", $object->id, $member->getFullName($langs));
729  $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$member->getFullName($langs);
730  $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->fk_type;
731  $object->actionmsg .= "\n".$langs->transnoentities("Amount").': '.$object->amount;
732  $object->actionmsg .= "\n".$langs->transnoentities("Period").': '.dol_print_date($object->dateh, 'day').' - '.dol_print_date($object->datef, 'day');
733 
734  $object->sendtoid = 0;
735  if (isset($object->fk_soc) && $object->fk_soc > 0) {
736  $object->socid = $object->fk_soc;
737  }
738  } elseif ($action == 'MEMBER_SUBSCRIPTION_MODIFY') {
739  // Load translation files required by the page
740  $langs->loadLangs(array("agenda", "other", "members"));
741 
742  $member = $this->context['member'];
743  if (!is_object($member)) { // This should not happen
744  include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
745  $member = new Adherent($this->db);
746  $member->fetch($object->fk_adherent);
747  }
748 
749  if (empty($object->actionmsg2)) {
750  $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionModifiedInDolibarr", $object->id, $member->getFullName($langs));
751  }
752  $object->actionmsg = $langs->transnoentities("MemberSubscriptionModifiedInDolibarr", $object->id, $member->getFullName($langs));
753  $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$member->getFullName($langs);
754  $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->fk_type;
755  $object->actionmsg .= "\n".$langs->transnoentities("Amount").': '.$object->amount;
756  $object->actionmsg .= "\n".$langs->transnoentities("Period").': '.dol_print_date($object->dateh, 'day').' - '.dol_print_date($object->datef, 'day');
757 
758  $object->sendtoid = 0;
759  if ($object->fk_soc > 0) {
760  $object->socid = $object->fk_soc;
761  }
762  } elseif ($action == 'MEMBER_SUBSCRIPTION_DELETE') {
763  // Load translation files required by the page
764  $langs->loadLangs(array("agenda", "other", "members"));
765 
766  if (empty($object->actionmsg2)) {
767  $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionDeletedInDolibarr", $object->ref, $object->getFullName($langs));
768  }
769  $object->actionmsg = $langs->transnoentities("MemberSubscriptionDeletedInDolibarr", $object->ref, $object->getFullName($langs));
770  $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
771  $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->fk_type;
772  $object->actionmsg .= "\n".$langs->transnoentities("Amount").': '.$object->amount;
773  $object->actionmsg .= "\n".$langs->transnoentities("Period").': '.dol_print_date($object->dateh, 'day').' - '.dol_print_date($object->datef, 'day');
774 
775  $object->sendtoid = 0;
776  if (isset($object->fk_soc) && $object->fk_soc > 0) {
777  $object->socid = $object->fk_soc;
778  }
779  } elseif ($action == 'MEMBER_RESILIATE') {
780  // Load translation files required by the page
781  $langs->loadLangs(array("agenda", "other", "members"));
782 
783  if (empty($object->actionmsg2)) {
784  $object->actionmsg2 = $langs->transnoentities("MemberResiliatedInDolibarr", $object->getFullName($langs));
785  }
786  $object->actionmsg = $langs->transnoentities("MemberResiliatedInDolibarr", $object->getFullName($langs));
787  $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
788  $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type;
789 
790  $object->sendtoid = 0;
791  } elseif ($action == 'MEMBER_DELETE') {
792  // Load translation files required by the page
793  $langs->loadLangs(array("agenda", "other", "members"));
794 
795  if (empty($object->actionmsg2)) {
796  $object->actionmsg2 = $langs->transnoentities("MemberDeletedInDolibarr", $object->getFullName($langs));
797  }
798  $object->actionmsg = $langs->transnoentities("MemberDeletedInDolibarr", $object->getFullName($langs));
799  $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
800  $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type;
801 
802  $object->sendtoid = 0;
803  } elseif ($action == 'MEMBER_EXCLUDE') {
804  // Load translation files required by the page
805  $langs->loadLangs(array("agenda", "other", "members"));
806 
807  if (empty($object->actionmsg2)) {
808  $object->actionmsg2 = $langs->transnoentities("MemberExcludedInDolibarr", $object->getFullName($langs));
809  }
810  $object->actionmsg = $langs->transnoentities("MemberExcludedInDolibarr", $object->getFullName($langs));
811  $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
812  $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type;
813 
814  $object->sendtoid = 0;
815  } elseif ($action == 'PROJECT_CREATE') {
816  // Projects
817  // Load translation files required by the page
818  $langs->loadLangs(array("agenda", "other", "projects"));
819 
820  if (empty($object->actionmsg2)) {
821  $object->actionmsg2 = $langs->transnoentities("ProjectCreatedInDolibarr", $object->ref);
822  }
823  $object->actionmsg = $langs->transnoentities("ProjectCreatedInDolibarr", $object->ref);
824  $object->actionmsg .= "\n".$langs->transnoentities("Project").': '.$object->ref;
825 
826  $object->sendtoid = 0;
827  } elseif ($action == 'PROJECT_VALIDATE') {
828  // Load translation files required by the page
829  $langs->loadLangs(array("agenda", "other", "projects"));
830 
831  if (empty($object->actionmsg2)) {
832  $object->actionmsg2 = $langs->transnoentities("ProjectValidatedInDolibarr", $object->ref);
833  }
834  $object->actionmsg = $langs->transnoentities("ProjectValidatedInDolibarr", $object->ref);
835  $object->actionmsg .= "\n".$langs->transnoentities("Project").': '.$object->ref;
836 
837  $object->sendtoid = 0;
838  } elseif ($action == 'PROJECT_MODIFY') {
839  // Load translation files required by the page
840  $langs->loadLangs(array("agenda", "other", "projects"));
841 
842  if (empty($object->actionmsg2)) {
843  $object->actionmsg2 = $langs->transnoentities("ProjectModifiedInDolibarr", $object->ref);
844  }
845  $object->actionmsg = $langs->transnoentities("ProjectModifiedInDolibarr", $object->ref);
846  //$object->actionmsg .= "\n".$langs->transnoentities("Task").': ???';
847  if (!empty($object->usage_opportunity) && is_object($object->oldcopy) && $object->opp_status != $object->oldcopy->opp_status) {
848  $object->actionmsg .= "\n".$langs->transnoentitiesnoconv("OpportunityStatus").': '.$object->oldcopy->opp_status.' -> '.$object->opp_status;
849  }
850 
851  $object->sendtoid = 0;
852  } elseif ($action == 'PROJECT_SENTBYMAIL') {
853  // Load translation files required by the page
854  $langs->loadLangs(array("agenda", "other", "projects"));
855 
856  if (empty($object->actionmsg2)) {
857  $object->actionmsg2 = $langs->transnoentities("ProjectSentByEMail", $object->ref);
858  }
859  if (empty($object->actionmsg)) {
860  $object->actionmsg = $langs->transnoentities("ProjectSentByEMail", $object->ref);
861  }
862 
863  // Parameters $object->sendtoid defined by caller
864  //$object->sendtoid=0;
865  } elseif ($action == 'PROJECT_CLOSE') {
866  // Load translation files required by the page
867  $langs->loadLangs(array("agenda", "other", "projects"));
868 
869  if (empty($object->actionmsg2)) {
870  $object->actionmsg2 = $langs->transnoentities("ProjectClosedInDolibarr", $object->ref);
871  }
872  $object->actionmsg = $langs->transnoentities("ProjectClosedInDolibarr", $object->ref);
873 
874  $object->sendtoid = 0;
875  } elseif ($action == 'TASK_CREATE') {
876  // Project tasks
877  // Load translation files required by the page
878  $langs->loadLangs(array("agenda", "other", "projects"));
879 
880  if (empty($object->actionmsg2)) {
881  $object->actionmsg2 = $langs->transnoentities("TaskCreatedInDolibarr", $object->ref);
882  }
883  $object->actionmsg = $langs->transnoentities("TaskCreatedInDolibarr", $object->ref);
884  $object->actionmsg .= "\n".$langs->transnoentities("Task").': '.$object->ref;
885 
886  $object->sendtoid = 0;
887  } elseif ($action == 'TASK_MODIFY') {
888  // Load translation files required by the page
889  $langs->loadLangs(array("agenda", "other", "projects"));
890 
891  if (empty($object->actionmsg2)) {
892  $object->actionmsg2 = $langs->transnoentities("TaskModifiedInDolibarr", $object->ref);
893  }
894  $object->actionmsg = $langs->transnoentities("TaskModifieddInDolibarr", $object->ref);
895  $object->actionmsg .= "\n".$langs->transnoentities("Task").': '.$object->ref;
896 
897  $object->sendtoid = 0;
898  } elseif ($action == 'TASK_DELETE') {
899  // Load translation files required by the page
900  $langs->loadLangs(array("agenda", "other", "projects"));
901 
902  if (empty($object->actionmsg2)) {
903  $object->actionmsg2 = $langs->transnoentities("TaskDeletedInDolibarr", $object->ref);
904  }
905  $object->actionmsg = $langs->transnoentities("TaskDeletedInDolibarr", $object->ref);
906  $object->actionmsg .= "\n".$langs->transnoentities("Task").': '.$object->ref;
907 
908  $object->sendtoid = 0;
909  } elseif ($action == 'TICKET_ASSIGNED') {
910  // Load translation files required by the page
911  $langs->loadLangs(array("agenda", "other", "projects"));
912 
913  if (empty($object->actionmsg2)) {
914  $object->actionmsg2 = $langs->transnoentities("TICKET_ASSIGNEDInDolibarr", $object->ref);
915  }
916  $object->actionmsg = $langs->transnoentities("TICKET_ASSIGNEDInDolibarr", $object->ref);
917  if ($object->oldcopy->fk_user_assign > 0) {
918  $tmpuser = new User($this->db);
919  $tmpuser->fetch($object->oldcopy->fk_user_assign);
920  $object->actionmsg .= "\n".$langs->transnoentities("OldUser").': '.$tmpuser->getFullName($langs);
921  } else {
922  $object->actionmsg .= "\n".$langs->transnoentities("OldUser").': '.$langs->trans("None");
923  }
924  if ($object->fk_user_assign > 0) {
925  $tmpuser = new User($this->db);
926  $tmpuser->fetch($object->fk_user_assign);
927  $object->actionmsg .= "\n".$langs->transnoentities("NewUser").': '.$tmpuser->getFullName($langs);
928  } else {
929  $object->actionmsg .= "\n".$langs->transnoentities("NewUser").': '.$langs->trans("None");
930  }
931  $object->sendtoid = 0;
932  } else {
933  // TODO Merge all previous cases into this generic one
934  // $action = BILL_DELETE, TICKET_CREATE, TICKET_MODIFY, TICKET_DELETE, CONTACT_SENTBYMAIL, RECRUITMENTCANDIDATURE_MODIFY, ...
935  // Can also be a value defined by an external module like SENTBYSMS, COMPANY_SENTBYSMS, MEMBER_SENTBYSMS, ...
936  // Note: We are here only if $conf->global->MAIN_AGENDA_ACTIONAUTO_action is on (tested at begining of this function).
937  // Note that these key can be set in agenda setup, only if defined into llx_c_action_trigger
938  // Load translation files required by the page
939  if (empty($object->actionmsg2)) {
940  $langs->loadLangs(array("agenda", "other"));
941  if ($langs->transnoentities($action."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref)) != $action."InDolibarr") { // specific translation key
942  $object->actionmsg2 = $langs->transnoentities($action."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref));
943  } else { // generic translation key
944  $tmp = explode('_', $action);
945  $object->actionmsg2 = $langs->transnoentities($tmp[count($tmp) - 1]."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref));
946  }
947  }
948  if (empty($object->actionmsg)) {
949  $langs->loadLangs(array("agenda", "other"));
950  if ($langs->transnoentities($action."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref)) != $action."InDolibarr") { // specific translation key
951  $object->actionmsg = $langs->transnoentities($action."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref));
952  } else { // generic translation key
953  $tmp = explode('_', $action);
954  $object->actionmsg = $langs->transnoentities($tmp[count($tmp) - 1]."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref));
955  }
956  }
957 
958  if (!isset($object->sendtoid) || !is_array($object->sendtoid)) {
959  $object->sendtoid = 0;
960  }
961  }
962 
963  // If trackid is not defined, we set it.
964  // Note that it should be set by caller. This is for compatibility purpose only.
965  if (empty($object->trackid)) {
966  // See also similar list into emailcollector.class.php
967  if (preg_match('/^COMPANY_/', $action)) {
968  $object->trackid = 'thi'.$object->id;
969  } elseif (preg_match('/^CONTACT_/', $action)) {
970  $object->trackid = 'ctc'.$object->id;
971  } elseif (preg_match('/^CONTRACT_/', $action)) {
972  $object->trackid = 'con'.$object->id;
973  } elseif (preg_match('/^PROPAL_/', $action)) {
974  $object->trackid = 'pro'.$object->id;
975  } elseif (preg_match('/^ORDER_/', $action)) {
976  $object->trackid = 'ord'.$object->id;
977  } elseif (preg_match('/^BILL_/', $action)) {
978  $object->trackid = 'inv'.$object->id;
979  } elseif (preg_match('/^FICHINTER_/', $action)) {
980  $object->trackid = 'int'.$object->id;
981  } elseif (preg_match('/^SHIPPING_/', $action)) {
982  $object->trackid = 'shi'.$object->id;
983  } elseif (preg_match('/^RECEPTION_/', $action)) {
984  $object->trackid = 'rec'.$object->id;
985  } elseif (preg_match('/^PROPOSAL_SUPPLIER/', $action)) {
986  $object->trackid = 'spr'.$object->id;
987  } elseif (preg_match('/^ORDER_SUPPLIER_/', $action)) {
988  $object->trackid = 'sor'.$object->id;
989  } elseif (preg_match('/^BILL_SUPPLIER_/', $action)) {
990  $object->trackid = 'sin'.$object->id;
991  } elseif (preg_match('/^MEMBER_SUBSCRIPTION_/', $action)) {
992  $object->trackid = 'sub'.$object->id;
993  } elseif (preg_match('/^MEMBER_/', $action)) {
994  $object->trackid = 'mem'.$object->id;
995  } elseif (preg_match('/^PROJECT_/', $action)) {
996  $object->trackid = 'proj'.$object->id;
997  } elseif (preg_match('/^TASK_/', $action)) {
998  $object->trackid = 'tas'.$object->id;
999  } elseif (preg_match('/^TICKET_/', $action)) {
1000  $object->trackid = 'tic'.$object->id;
1001  } elseif (preg_match('/^USER_/', $action)) {
1002  $object->trackid = 'use'.$object->id;
1003  } else {
1004  $object->trackid = '';
1005  }
1006  }
1007 
1008  /* Seems no more required: We have the data in dedicated field now.
1009  if (!empty($user->login)) {
1010  $object->actionmsg = dol_concatdesc($langs->transnoentities("Author").': '.$user->login, $object->actionmsg);
1011  } elseif (isset($object->origin_email)) {
1012  $object->actionmsg = dol_concatdesc($langs->transnoentities("Author").': '.$object->origin_email, $object->actionmsg);
1013  }
1014  */
1015 
1016  dol_syslog("Trigger '".$this->name."' for action '".$action."' launched by ".__FILE__.". id=".$object->id);
1017 
1018  // Add entry in event table
1019  $now = dol_now();
1020 
1021  if (isset($_SESSION['listofnames-'.$object->trackid])) {
1022  $attachs = $_SESSION['listofnames-'.$object->trackid];
1023  if ($attachs && strpos($action, 'SENTBYMAIL')) {
1024  $object->actionmsg = dol_concatdesc($object->actionmsg, "\n".$langs->transnoentities("AttachedFiles").': '.$attachs);
1025  }
1026  }
1027  require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
1028  require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
1029  $contactforaction = new Contact($this->db);
1030  $societeforaction = new Societe($this->db);
1031  // Set contactforaction if there is only 1 contact.
1032 
1033  if (is_array($object->sendtoid)) {
1034  if (count($object->sendtoid) == 1) {
1035  $contactforaction->fetch(reset($object->sendtoid));
1036  }
1037  } else {
1038  if ($object->sendtoid > 0) {
1039  $contactforaction->fetch($object->sendtoid);
1040  }
1041  }
1042  // Set societeforaction.
1043  if (isset($object->socid) && $object->socid > 0) {
1044  $societeforaction->fetch($object->socid);
1045  } elseif (isset($object->fk_soc) && $object->fk_soc > 0) {
1046  $societeforaction->fetch($object->fk_soc);
1047  } elseif (isset($object->thirdparty) && isset($object->thirdparty->id) && $object->thirdparty->id > 0) {
1048  $societeforaction = $object->thirdparty;
1049  }
1050 
1051  $projectid = isset($object->fk_project) ? $object->fk_project : 0;
1052  if ($object->element == 'project') {
1053  $projectid = $object->id;
1054  }
1055 
1056  $elementid = $object->id; // id of object
1057  $elementtype = $object->element;
1058  $elementmodule = (empty($object->module) ? '' : $object->module);
1059  if ($object->element == 'subscription') {
1060  $elementid = $object->fk_adherent;
1061  $elementtype = 'member';
1062  }
1063  //var_dump($societeforaction);var_dump($contactforaction);var_dump($elementid);var_dump($elementtype);exit;
1064 
1065  // Insertion action
1066  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
1067  $actioncomm = new ActionComm($this->db);
1068  $actioncomm->type_code = $object->actiontypecode; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...)
1069  $actioncomm->code = 'AC_'.$action;
1070  $actioncomm->label = $object->actionmsg2;
1071  $actioncomm->note_private = $object->actionmsg;
1072  $actioncomm->fk_project = $projectid;
1073  $actioncomm->datep = $now;
1074  $actioncomm->datef = $now;
1075  $actioncomm->durationp = 0;
1076  $actioncomm->percentage = -1; // Not applicable
1077  $actioncomm->socid = $societeforaction->id;
1078  $actioncomm->contact_id = $contactforaction->id; // deprecated, use ->socpeopleassigned instead
1079  $actioncomm->authorid = $user->id; // User saving action
1080  $actioncomm->userownerid = $user->id; // Owner of action
1081  // Fields defined when action is an email (content should be into object->actionmsg to be added into event note, subject should be into object->actionms2 to be added into event label)
1082  if (!property_exists($object, 'email_fields_no_propagate_in_actioncomm') || empty($object->email_fields_no_propagate_in_actioncomm)) {
1083  $actioncomm->email_msgid = empty($object->email_msgid) ? null : $object->email_msgid;
1084  $actioncomm->email_from = empty($object->email_from) ? null : $object->email_from;
1085  $actioncomm->email_sender = empty($object->email_sender) ? null : $object->email_sender;
1086  $actioncomm->email_to = empty($object->email_to) ? null : $object->email_to;
1087  $actioncomm->email_tocc = empty($object->email_tocc) ? null : $object->email_tocc;
1088  $actioncomm->email_tobcc = empty($object->email_tobcc) ? null : $object->email_tobcc;
1089  $actioncomm->email_subject = empty($object->email_subject) ? null : $object->email_subject;
1090  $actioncomm->errors_to = empty($object->errors_to) ? null : $object->errors_to;
1091  }
1092 
1093  // Object linked (if link is for thirdparty, contact, project it is a recording error. We should not have links in link table
1094  // for such objects because there is already a dedicated field into table llx_actioncomm or llx_actioncomm_resources.
1095  if (!in_array($elementtype, array('societe', 'contact', 'project'))) {
1096  $actioncomm->fk_element = $elementid;
1097  $actioncomm->elementtype = $elementtype.($elementmodule ? '@'.$elementmodule : '');
1098  }
1099 
1100  if (property_exists($object, 'attachedfiles') && is_array($object->attachedfiles) && count($object->attachedfiles) > 0) {
1101  $actioncomm->attachedfiles = $object->attachedfiles;
1102  }
1103  if (property_exists($object, 'sendtouserid') && is_array($object->sendtouserid) && count($object->sendtouserid) > 0) {
1104  $actioncomm->userassigned = $object->sendtouserid;
1105  }
1106  if (property_exists($object, 'sendtoid') && is_array($object->sendtoid) && count($object->sendtoid) > 0) {
1107  foreach ($object->sendtoid as $val) {
1108  $actioncomm->socpeopleassigned[$val] = $val;
1109  }
1110  }
1111 
1112  $ret = $actioncomm->create($user); // User creating action
1113 
1114  if ($ret > 0 && !empty($conf->global->MAIN_COPY_FILE_IN_EVENT_AUTO)) {
1115  if (is_array($object->attachedfiles) && array_key_exists('paths', $object->attachedfiles) && count($object->attachedfiles['paths']) > 0) {
1116  foreach ($object->attachedfiles['paths'] as $key => $filespath) {
1117  $srcfile = $filespath;
1118  $destdir = $conf->agenda->dir_output.'/'.$ret;
1119  $destfile = $destdir.'/'.$object->attachedfiles['names'][$key];
1120  if (dol_mkdir($destdir) >= 0) {
1121  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1122  dol_copy($srcfile, $destfile);
1123  }
1124  }
1125  }
1126  }
1127 
1128  unset($object->actionmsg);
1129  unset($object->actionmsg2);
1130  unset($object->actiontypecode); // When several action are called on same object, we must be sure to not reuse value of first action.
1131 
1132  if ($ret > 0) {
1133  $_SESSION['LAST_ACTION_CREATED'] = $ret;
1134  return 1;
1135  } else {
1136  $this->error = "Failed to insert event : ".$actioncomm->error." ".join(',', $actioncomm->errors);
1137  $this->errors = $actioncomm->errors;
1138 
1139  dol_syslog("interface_modAgenda_ActionsAuto.class.php: ".$this->error, LOG_ERR);
1140  return -1;
1141  }
1142  }
1143 }
Class to manage agenda events (actions)
Class to manage members of a foundation.
Class to stock current configuration.
Definition: conf.class.php:34
Class to manage contact/addresses.
Class that all the triggers must extend.
Class of triggered functions for agenda module.
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called when a Dolibarrr business event is done.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
Definition: user.class.php:45
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:712
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:122
$conf db
API class for accounts.
Definition: inc.php:41