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