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