dolibarr  19.0.0-dev
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.' - '.$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  // 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->context['actionmsg2'])) {
609  $object->actionmsg2 = $langs->transnoentities("SupplierOrderReceivedInDolibarr", ($object->newref ? $object->newref : $object->ref));
610  } else {
611  $object->actionmsg2 = $object->context['actionmsg2'];
612  }
613  $object->actionmsg = $langs->transnoentities("SupplierOrderReceivedInDolibarr", ($object->newref ? $object->newref : $object->ref));
614 
615  $object->sendtoid = 0;
616  } elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL') {
617  // Load translation files required by the page
618  $langs->loadLangs(array("agenda", "other", "bills", "orders"));
619 
620  if (empty($object->actionmsg2)) {
621  $object->actionmsg2 = $langs->transnoentities("SupplierOrderSentByEMail", $object->ref);
622  }
623  if (empty($object->actionmsg)) {
624  $object->actionmsg = $langs->transnoentities("SupplierOrderSentByEMail", $object->ref);
625  }
626 
627  // Parameters $object->sendtoid defined by caller
628  //$object->sendtoid=0;
629  } elseif ($action == 'ORDER_SUPPLIER_CLASSIFY_BILLED') {
630  // Load translation files required by the page
631  $langs->loadLangs(array("agenda", "other", "bills", "orders"));
632 
633  if (empty($object->actionmsg2)) {
634  $object->actionmsg2 = $langs->transnoentities("SupplierOrderClassifiedBilled", $object->ref);
635  }
636  if (empty($object->actionmsg)) {
637  $object->actionmsg = $langs->transnoentities("SupplierOrderClassifiedBilled", $object->ref);
638  }
639 
640  $object->sendtoid = 0;
641  } elseif ($action == 'BILL_SUPPLIER_VALIDATE') {
642  // Load translation files required by the page
643  $langs->loadLangs(array("agenda", "other", "bills"));
644 
645  if (empty($object->actionmsg2)) {
646  $object->actionmsg2 = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
647  }
648  $object->actionmsg = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
649 
650  $object->sendtoid = 0;
651  } elseif ($action == 'BILL_SUPPLIER_UNVALIDATE') {
652  // Load translation files required by the page
653  $langs->loadLangs(array("agenda", "other", "bills"));
654 
655  if (empty($object->actionmsg2)) {
656  $object->actionmsg2 = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref);
657  }
658  $object->actionmsg = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref);
659 
660  $object->sendtoid = 0;
661  } elseif ($action == 'BILL_SUPPLIER_SENTBYMAIL') {
662  // Load translation files required by the page
663  $langs->loadLangs(array("agenda", "other", "bills", "orders"));
664 
665  if (empty($object->actionmsg2)) {
666  $object->actionmsg2 = $langs->transnoentities("SupplierInvoiceSentByEMail", $object->ref);
667  }
668  if (empty($object->actionmsg)) {
669  $object->actionmsg = $langs->transnoentities("SupplierInvoiceSentByEMail", $object->ref);
670  }
671 
672  // Parameters $object->sendtoid defined by caller
673  //$object->sendtoid=0;
674  } elseif ($action == 'BILL_SUPPLIER_PAYED') {
675  // Load translation files required by the page
676  $langs->loadLangs(array("agenda", "other", "bills"));
677 
678  if (empty($object->actionmsg2)) {
679  $object->actionmsg2 = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
680  }
681  $object->actionmsg = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
682 
683  $object->sendtoid = 0;
684  } elseif ($action == 'BILL_SUPPLIER_CANCELED') {
685  // Load translation files required by the page
686  $langs->loadLangs(array("agenda", "other", "bills"));
687 
688  if (empty($object->actionmsg2)) {
689  $object->actionmsg2 = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
690  }
691  $object->actionmsg = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
692 
693  $object->sendtoid = 0;
694  } elseif ($action == 'MEMBER_VALIDATE') {
695  // Members
696  // Load translation files required by the page
697  $langs->loadLangs(array("agenda", "other", "members"));
698 
699  if (empty($object->actionmsg2)) {
700  $object->actionmsg2 = $langs->transnoentities("MemberValidatedInDolibarr", $object->getFullName($langs));
701  }
702  $object->actionmsg = $langs->transnoentities("MemberValidatedInDolibarr", $object->getFullName($langs));
703  $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
704  $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type;
705 
706  $object->sendtoid = 0;
707  } elseif ($action == 'MEMBER_MODIFY') {
708  // Load translation files required by the page
709  $langs->loadLangs(array("agenda", "other", "members"));
710 
711  if (empty($object->actionmsg2)) {
712  $object->actionmsg2 = $langs->transnoentities("MemberModifiedInDolibarr", $object->getFullName($langs));
713  }
714  $object->actionmsg = $langs->transnoentities("MemberModifiedInDolibarr", $object->getFullName($langs));
715  $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
716  $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type;
717 
718  $object->sendtoid = 0;
719  } elseif ($action == 'MEMBER_SUBSCRIPTION_CREATE') {
720  // Load translation files required by the page
721  $langs->loadLangs(array("agenda", "other", "members"));
722 
723  $member = (isset($this->context['member']) ? $this->context['member'] : null);
724  if (!is_object($member)) { // This should not happen
725  dol_syslog("Execute a trigger MEMBER_SUBSCRIPTION_CREATE with context key 'member' not an object");
726  include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
727  $member = new Adherent($this->db);
728  $member->fetch($object->fk_adherent);
729  }
730 
731  if (empty($object->actionmsg2)) {
732  $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionAddedInDolibarr", $object->id, $member->getFullName($langs));
733  }
734  $object->actionmsg = $langs->transnoentities("MemberSubscriptionAddedInDolibarr", $object->id, $member->getFullName($langs));
735  $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$member->getFullName($langs);
736  $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->fk_type;
737  $object->actionmsg .= "\n".$langs->transnoentities("Amount").': '.$object->amount;
738  $object->actionmsg .= "\n".$langs->transnoentities("Period").': '.dol_print_date($object->dateh, 'day').' - '.dol_print_date($object->datef, 'day');
739 
740  $object->sendtoid = 0;
741  if (isset($object->fk_soc) && $object->fk_soc > 0) {
742  $object->socid = $object->fk_soc;
743  }
744  } elseif ($action == 'MEMBER_SUBSCRIPTION_MODIFY') {
745  // Load translation files required by the page
746  $langs->loadLangs(array("agenda", "other", "members"));
747 
748  $member = $this->context['member'];
749  if (!is_object($member)) { // This should not happen
750  include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
751  $member = new Adherent($this->db);
752  $member->fetch($object->fk_adherent);
753  }
754 
755  if (empty($object->actionmsg2)) {
756  $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionModifiedInDolibarr", $object->id, $member->getFullName($langs));
757  }
758  $object->actionmsg = $langs->transnoentities("MemberSubscriptionModifiedInDolibarr", $object->id, $member->getFullName($langs));
759  $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$member->getFullName($langs);
760  $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->fk_type;
761  $object->actionmsg .= "\n".$langs->transnoentities("Amount").': '.$object->amount;
762  $object->actionmsg .= "\n".$langs->transnoentities("Period").': '.dol_print_date($object->dateh, 'day').' - '.dol_print_date($object->datef, 'day');
763 
764  $object->sendtoid = 0;
765  if ($object->fk_soc > 0) {
766  $object->socid = $object->fk_soc;
767  }
768  } elseif ($action == 'MEMBER_SUBSCRIPTION_DELETE') {
769  // Load translation files required by the page
770  $langs->loadLangs(array("agenda", "other", "members"));
771 
772  $member = $this->context['member'];
773  if (!is_object($member)) { // This should not happen but it happen when deleting a subscription from adherents/subscription/card.php
774  dol_syslog("Execute a trigger MEMBER_SUBSCRIPTION_CREATE with context key 'member' not an object");
775  include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
776  $member = new Adherent($this->db);
777  $member->fetch($object->fk_adherent);
778  }
779 
780  $object->actionmsg = $langs->transnoentities("MemberSubscriptionDeletedInDolibarr", $object->ref, $member->getFullName($langs));
781  $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$member->getFullName($langs);
782  $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->fk_type;
783  $object->actionmsg .= "\n".$langs->transnoentities("Amount").': '.$object->amount;
784  $object->actionmsg .= "\n".$langs->transnoentities("Period").': '.dol_print_date($object->dateh, 'day').' - '.dol_print_date($object->datef, 'day');
785  if (empty($object->actionmsg2)) {
786  $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionDeletedInDolibarr", $object->ref, $member->getFullName($langs));
787  }
788 
789  $object->sendtoid = 0;
790  if (isset($object->fk_soc) && $object->fk_soc > 0) {
791  $object->socid = $object->fk_soc;
792  }
793  } elseif ($action == 'MEMBER_RESILIATE') {
794  // Load translation files required by the page
795  $langs->loadLangs(array("agenda", "other", "members"));
796 
797  if (empty($object->actionmsg2)) {
798  $object->actionmsg2 = $langs->transnoentities("MemberResiliatedInDolibarr", $object->getFullName($langs));
799  }
800  $object->actionmsg = $langs->transnoentities("MemberResiliatedInDolibarr", $object->getFullName($langs));
801  $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
802  $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type;
803 
804  $object->sendtoid = 0;
805  } elseif ($action == 'MEMBER_DELETE') {
806  // Load translation files required by the page
807  $langs->loadLangs(array("agenda", "other", "members"));
808 
809  if (empty($object->actionmsg2)) {
810  $object->actionmsg2 = $langs->transnoentities("MemberDeletedInDolibarr", $object->getFullName($langs));
811  }
812  $object->actionmsg = $langs->transnoentities("MemberDeletedInDolibarr", $object->getFullName($langs));
813  $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
814  $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type;
815 
816  $object->sendtoid = 0;
817  } elseif ($action == 'MEMBER_EXCLUDE') {
818  // Load translation files required by the page
819  $langs->loadLangs(array("agenda", "other", "members"));
820 
821  if (empty($object->actionmsg2)) {
822  $object->actionmsg2 = $langs->transnoentities("MemberExcludedInDolibarr", $object->getFullName($langs));
823  }
824  $object->actionmsg = $langs->transnoentities("MemberExcludedInDolibarr", $object->getFullName($langs));
825  $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
826  $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type;
827 
828  $object->sendtoid = 0;
829  } elseif ($action == 'PROJECT_CREATE') {
830  // Projects
831  // Load translation files required by the page
832  $langs->loadLangs(array("agenda", "other", "projects"));
833 
834  if (empty($object->actionmsg2)) {
835  $object->actionmsg2 = $langs->transnoentities("ProjectCreatedInDolibarr", $object->ref);
836  }
837  $object->actionmsg = $langs->transnoentities("ProjectCreatedInDolibarr", $object->ref);
838  $object->actionmsg .= "\n".$langs->transnoentities("Project").': '.$object->ref;
839 
840  $object->sendtoid = 0;
841  } elseif ($action == 'PROJECT_VALIDATE') {
842  // Load translation files required by the page
843  $langs->loadLangs(array("agenda", "other", "projects"));
844 
845  if (empty($object->actionmsg2)) {
846  $object->actionmsg2 = $langs->transnoentities("ProjectValidatedInDolibarr", $object->ref);
847  }
848  $object->actionmsg = $langs->transnoentities("ProjectValidatedInDolibarr", $object->ref);
849  $object->actionmsg .= "\n".$langs->transnoentities("Project").': '.$object->ref;
850 
851  $object->sendtoid = 0;
852  } elseif ($action == 'PROJECT_MODIFY') {
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("ProjectModifiedInDolibarr", $object->ref);
858  }
859  $object->actionmsg = $langs->transnoentities("ProjectModifiedInDolibarr", $object->ref);
860  //$object->actionmsg .= "\n".$langs->transnoentities("Task").': ???';
861  if (!empty($object->usage_opportunity) && is_object($object->oldcopy) && $object->opp_status != $object->oldcopy->opp_status) {
862  $object->actionmsg .= "\n".$langs->transnoentitiesnoconv("OpportunityStatus").': '.$object->oldcopy->opp_status.' -> '.$object->opp_status;
863  }
864 
865  $object->sendtoid = 0;
866  } elseif ($action == 'PROJECT_SENTBYMAIL') {
867  // Load translation files required by the page
868  $langs->loadLangs(array("agenda", "other", "projects"));
869 
870  if (empty($object->actionmsg2)) {
871  $object->actionmsg2 = $langs->transnoentities("ProjectSentByEMail", $object->ref);
872  }
873  if (empty($object->actionmsg)) {
874  $object->actionmsg = $langs->transnoentities("ProjectSentByEMail", $object->ref);
875  }
876 
877  // Parameters $object->sendtoid defined by caller
878  //$object->sendtoid=0;
879  } elseif ($action == 'PROJECT_CLOSE') {
880  // Load translation files required by the page
881  $langs->loadLangs(array("agenda", "other", "projects"));
882 
883  if (empty($object->actionmsg2)) {
884  $object->actionmsg2 = $langs->transnoentities("ProjectClosedInDolibarr", $object->ref);
885  }
886  $object->actionmsg = $langs->transnoentities("ProjectClosedInDolibarr", $object->ref);
887 
888  $object->sendtoid = 0;
889  } elseif ($action == 'TASK_CREATE') {
890  // Project tasks
891  // Load translation files required by the page
892  $langs->loadLangs(array("agenda", "other", "projects"));
893 
894  if (empty($object->actionmsg2)) {
895  $object->actionmsg2 = $langs->transnoentities("TaskCreatedInDolibarr", $object->ref);
896  }
897  $object->actionmsg = $langs->transnoentities("TaskCreatedInDolibarr", $object->ref);
898  $object->actionmsg .= "\n".$langs->transnoentities("Task").': '.$object->ref;
899 
900  $object->sendtoid = 0;
901  } elseif ($action == 'TASK_MODIFY') {
902  // Load translation files required by the page
903  $langs->loadLangs(array("agenda", "other", "projects"));
904 
905  if (empty($object->actionmsg2)) {
906  $object->actionmsg2 = $langs->transnoentities("TaskModifiedInDolibarr", $object->ref);
907  }
908  $object->actionmsg = $langs->transnoentities("TaskModifieddInDolibarr", $object->ref);
909  $object->actionmsg .= "\n".$langs->transnoentities("Task").': '.$object->ref;
910 
911  $object->sendtoid = 0;
912  } elseif ($action == 'TASK_DELETE') {
913  // Load translation files required by the page
914  $langs->loadLangs(array("agenda", "other", "projects"));
915 
916  if (empty($object->actionmsg2)) {
917  $object->actionmsg2 = $langs->transnoentities("TaskDeletedInDolibarr", $object->ref);
918  }
919  $object->actionmsg = $langs->transnoentities("TaskDeletedInDolibarr", $object->ref);
920  $object->actionmsg .= "\n".$langs->transnoentities("Task").': '.$object->ref;
921 
922  $object->sendtoid = 0;
923  } elseif ($action == 'TICKET_ASSIGNED') {
924  // Load translation files required by the page
925  $langs->loadLangs(array("agenda", "other", "projects"));
926 
927  if (empty($object->actionmsg2)) {
928  $object->actionmsg2 = $langs->transnoentities("TICKET_ASSIGNEDInDolibarr", $object->ref);
929  }
930  $object->actionmsg = $langs->transnoentities("TICKET_ASSIGNEDInDolibarr", $object->ref);
931  if ($object->oldcopy->fk_user_assign > 0) {
932  $tmpuser = new User($this->db);
933  $tmpuser->fetch($object->oldcopy->fk_user_assign);
934  $object->actionmsg .= "\n".$langs->transnoentities("OldUser").': '.$tmpuser->getFullName($langs);
935  } else {
936  $object->actionmsg .= "\n".$langs->transnoentities("OldUser").': '.$langs->trans("None");
937  }
938  if ($object->fk_user_assign > 0) {
939  $tmpuser = new User($this->db);
940  $tmpuser->fetch($object->fk_user_assign);
941  $object->actionmsg .= "\n".$langs->transnoentities("NewUser").': '.$tmpuser->getFullName($langs);
942  } else {
943  $object->actionmsg .= "\n".$langs->transnoentities("NewUser").': '.$langs->trans("None");
944  }
945  $object->sendtoid = 0;
946  } else {
947  // TODO Merge all previous cases into this generic one
948  // $action = PASSWORD, BILL_DELETE, TICKET_CREATE, TICKET_MODIFY, TICKET_DELETE, CONTACT_SENTBYMAIL, RECRUITMENTCANDIDATURE_MODIFY, ...
949  // Can also be a value defined by an external module like SENTBYSMS, COMPANY_SENTBYSMS, MEMBER_SENTBYSMS, ...
950  // Note: We are here only if $conf->global->MAIN_AGENDA_ACTIONAUTO_action is on (tested at begining of this function).
951  // Note that these key can be set in agenda setup, only if defined into llx_c_action_trigger
952  if (!empty($object->context['actionmsg']) && empty($object->actionmsg)) {
953  $object->actionmsg = $object->context['actionmsg'];
954  }
955  if (!empty($object->context['actionmsg2']) && empty($object->actionmsg2)) {
956  $object->actionmsg2 = $object->context['actionmsg2'];
957  }
958 
959  if (empty($object->actionmsg2)) {
960  // Load translation files required by the page
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->actionmsg2 = $langs->transnoentities($action."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref));
964  } else { // generic translation key
965  $tmp = explode('_', $action);
966  $object->actionmsg2 = $langs->transnoentities($tmp[count($tmp) - 1]."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref));
967  }
968  }
969  if (empty($object->actionmsg)) {
970  // Load translation files required by the page
971  $langs->loadLangs(array("agenda", "other"));
972  if ($langs->transnoentities($action."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref)) != $action."InDolibarr") { // specific translation key
973  $object->actionmsg = $langs->transnoentities($action."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref));
974  } else { // generic translation key
975  $tmp = explode('_', $action);
976  $object->actionmsg = $langs->transnoentities($tmp[count($tmp) - 1]."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref));
977  }
978  }
979 
980  if (!isset($object->sendtoid) || !is_array($object->sendtoid)) {
981  $object->sendtoid = 0;
982  }
983  }
984 
985  // If trackid is not defined, we set it.
986  // Note that it should be set by caller. This is for compatibility purpose only.
987  if (empty($object->trackid)) {
988  // See also similar list into emailcollector.class.php
989  if (preg_match('/^COMPANY_/', $action)) {
990  $object->trackid = 'thi'.$object->id;
991  } elseif (preg_match('/^CONTACT_/', $action)) {
992  $object->trackid = 'ctc'.$object->id;
993  } elseif (preg_match('/^CONTRACT_/', $action)) {
994  $object->trackid = 'con'.$object->id;
995  } elseif (preg_match('/^PROPAL_/', $action)) {
996  $object->trackid = 'pro'.$object->id;
997  } elseif (preg_match('/^ORDER_/', $action)) {
998  $object->trackid = 'ord'.$object->id;
999  } elseif (preg_match('/^BILL_/', $action)) {
1000  $object->trackid = 'inv'.$object->id;
1001  } elseif (preg_match('/^FICHINTER_/', $action)) {
1002  $object->trackid = 'int'.$object->id;
1003  } elseif (preg_match('/^SHIPPING_/', $action)) {
1004  $object->trackid = 'shi'.$object->id;
1005  } elseif (preg_match('/^RECEPTION_/', $action)) {
1006  $object->trackid = 'rec'.$object->id;
1007  } elseif (preg_match('/^PROPOSAL_SUPPLIER/', $action)) {
1008  $object->trackid = 'spr'.$object->id;
1009  } elseif (preg_match('/^ORDER_SUPPLIER_/', $action)) {
1010  $object->trackid = 'sor'.$object->id;
1011  } elseif (preg_match('/^BILL_SUPPLIER_/', $action)) {
1012  $object->trackid = 'sin'.$object->id;
1013  } elseif (preg_match('/^MEMBER_SUBSCRIPTION_/', $action)) {
1014  $object->trackid = 'sub'.$object->id;
1015  } elseif (preg_match('/^MEMBER_/', $action)) {
1016  $object->trackid = 'mem'.$object->id;
1017  } elseif (preg_match('/^PARTNERSHIP_/', $action)) {
1018  $object->trackid = 'pship'.$object->id;
1019  } elseif (preg_match('/^PROJECT_/', $action)) {
1020  $object->trackid = 'proj'.$object->id;
1021  } elseif (preg_match('/^TASK_/', $action)) {
1022  $object->trackid = 'tas'.$object->id;
1023  } elseif (preg_match('/^TICKET_/', $action)) {
1024  $object->trackid = 'tic'.$object->id;
1025  } elseif (preg_match('/^USER_/', $action)) {
1026  $object->trackid = 'use'.$object->id;
1027  } else {
1028  $object->trackid = '';
1029  }
1030  }
1031 
1032  /* Seems no more required: We have the data in dedicated field now.
1033  if (!empty($user->login)) {
1034  $object->actionmsg = dol_concatdesc($langs->transnoentities("Author").': '.$user->login, $object->actionmsg);
1035  } elseif (isset($object->origin_email)) {
1036  $object->actionmsg = dol_concatdesc($langs->transnoentities("Author").': '.$object->origin_email, $object->actionmsg);
1037  }
1038  */
1039 
1040  dol_syslog("Trigger '".$this->name."' for action '".$action."' launched by ".__FILE__.". id=".$object->id);
1041 
1042  // Add entry in event table
1043  $now = dol_now();
1044 
1045  if (isset($_SESSION['listofnames-'.$object->trackid])) {
1046  $attachs = $_SESSION['listofnames-'.$object->trackid];
1047  if ($attachs && strpos($action, 'SENTBYMAIL')) {
1048  $object->actionmsg = dol_concatdesc($object->actionmsg, "\n".$langs->transnoentities("AttachedFiles").': '.$attachs);
1049  }
1050  }
1051  require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
1052  require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
1053  $contactforaction = new Contact($this->db);
1054  $societeforaction = new Societe($this->db);
1055  // Set contactforaction if there is only 1 contact.
1056 
1057  if (is_array($object->sendtoid)) {
1058  if (count($object->sendtoid) == 1) {
1059  $contactforaction->fetch(reset($object->sendtoid));
1060  }
1061  } else {
1062  if ($object->sendtoid > 0) {
1063  $contactforaction->fetch($object->sendtoid);
1064  }
1065  }
1066  // Set societeforaction.
1067  if (isset($object->socid) && $object->socid > 0) {
1068  $societeforaction->fetch($object->socid);
1069  } elseif (isset($object->fk_soc) && $object->fk_soc > 0) {
1070  $societeforaction->fetch($object->fk_soc);
1071  } elseif (isset($object->thirdparty) && isset($object->thirdparty->id) && $object->thirdparty->id > 0) {
1072  $societeforaction = $object->thirdparty;
1073  }
1074 
1075  $projectid = isset($object->fk_project) ? $object->fk_project : 0;
1076  if ($object->element == 'project') {
1077  $projectid = $object->id;
1078  }
1079 
1080  $elementid = $object->id; // id of object
1081  $elementtype = $object->element;
1082  $elementmodule = (empty($object->module) ? '' : $object->module);
1083  if ($object->element == 'subscription') {
1084  $elementid = $object->fk_adherent;
1085  $elementtype = 'member';
1086  }
1087  //var_dump($societeforaction);var_dump($contactforaction);var_dump($elementid);var_dump($elementtype);exit;
1088 
1089  // Insertion action
1090  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
1091  $actioncomm = new ActionComm($this->db);
1092  $actioncomm->type_code = $object->actiontypecode; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...)
1093  $actioncomm->code = 'AC_'.$action;
1094  $actioncomm->label = $object->actionmsg2; // Label of event
1095  $actioncomm->note_private = $object->actionmsg; // Description
1096  $actioncomm->fk_project = $projectid;
1097  $actioncomm->datep = $now;
1098  $actioncomm->datef = $now;
1099  $actioncomm->durationp = 0;
1100  $actioncomm->percentage = -1; // Not applicable
1101  $actioncomm->socid = $societeforaction->id;
1102  $actioncomm->contact_id = $contactforaction->id; // deprecated, use ->socpeopleassigned instead
1103  $actioncomm->authorid = $user->id; // User saving action
1104  $actioncomm->userownerid = $user->id; // Owner of action
1105  // 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)
1106  if (!property_exists($object, 'email_fields_no_propagate_in_actioncomm') || empty($object->email_fields_no_propagate_in_actioncomm)) {
1107  $actioncomm->email_msgid = empty($object->email_msgid) ? null : $object->email_msgid;
1108  $actioncomm->email_from = empty($object->email_from) ? null : $object->email_from;
1109  $actioncomm->email_sender = empty($object->email_sender) ? null : $object->email_sender;
1110  $actioncomm->email_to = empty($object->email_to) ? null : $object->email_to;
1111  $actioncomm->email_tocc = empty($object->email_tocc) ? null : $object->email_tocc;
1112  $actioncomm->email_tobcc = empty($object->email_tobcc) ? null : $object->email_tobcc;
1113  $actioncomm->email_subject = empty($object->email_subject) ? null : $object->email_subject;
1114  $actioncomm->errors_to = empty($object->errors_to) ? null : $object->errors_to;
1115  }
1116 
1117  // Object linked (if link is for thirdparty, contact or project, it is a recording error. We should not have links in link table
1118  // for such objects because there is already a dedicated field into table llx_actioncomm or llx_actioncomm_resources.
1119  if (!in_array($elementtype, array('societe', 'contact', 'project'))) {
1120  $actioncomm->fk_element = $elementid;
1121  $actioncomm->elementtype = $elementtype.($elementmodule ? '@'.$elementmodule : '');
1122  }
1123 
1124  if (property_exists($object, 'attachedfiles') && is_array($object->attachedfiles) && count($object->attachedfiles) > 0) {
1125  $actioncomm->attachedfiles = $object->attachedfiles;
1126  }
1127  if (property_exists($object, 'sendtouserid') && is_array($object->sendtouserid) && count($object->sendtouserid) > 0) {
1128  $actioncomm->userassigned = $object->sendtouserid;
1129  }
1130  if (property_exists($object, 'sendtoid') && is_array($object->sendtoid) && count($object->sendtoid) > 0) {
1131  foreach ($object->sendtoid as $val) {
1132  $actioncomm->socpeopleassigned[$val] = $val;
1133  }
1134  }
1135 
1136  $ret = $actioncomm->create($user); // User creating action
1137 
1138  if ($ret > 0 && !empty($conf->global->MAIN_COPY_FILE_IN_EVENT_AUTO)) {
1139  if (property_exists($object, 'attachedfiles') && is_array($object->attachedfiles) && array_key_exists('paths', $object->attachedfiles) && count($object->attachedfiles['paths']) > 0) {
1140  foreach ($object->attachedfiles['paths'] as $key => $filespath) {
1141  $srcfile = $filespath;
1142  $destdir = $conf->agenda->dir_output.'/'.$ret;
1143  $destfile = $destdir.'/'.$object->attachedfiles['names'][$key];
1144  if (dol_mkdir($destdir) >= 0) {
1145  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1146  dol_copy($srcfile, $destfile);
1147  }
1148  }
1149  }
1150  }
1151 
1152  unset($object->actionmsg);
1153  unset($object->actionmsg2);
1154  unset($object->actiontypecode); // When several action are called on same object, we must be sure to not reuse value of first action.
1155 
1156  if ($ret > 0) {
1157  $_SESSION['LAST_ACTION_CREATED'] = $ret;
1158  return 1;
1159  } else {
1160  $this->error = "Failed to insert event : ".$actioncomm->error." ".join(',', $actioncomm->errors);
1161  $this->errors = $actioncomm->errors;
1162 
1163  dol_syslog("interface_modAgenda_ActionsAuto.class.php: ".$this->error, LOG_ERR);
1164  return -1;
1165  }
1166  }
1167 }
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...
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