dolibarr  16.0.5
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 = $this->context['member'];
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 ($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($this->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  if (empty($object->actionmsg2)) {
774  $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionDeletedInDolibarr", $object->ref, $member->getFullName($langs));
775  }
776  $object->actionmsg = $langs->transnoentities("MemberSubscriptionDeletedInDolibarr", $object->ref, $member->getFullName($langs));
777  $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$member->getFullName($langs);
778  $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type;
779  $object->actionmsg .= "\n".$langs->transnoentities("Amount").': '.$object->last_subscription_amount;
780  $object->actionmsg .= "\n".$langs->transnoentities("Period").': '.dol_print_date($object->last_subscription_date_start, 'day').' - '.dol_print_date($object->last_subscription_date_end, 'day');
781 
782  $object->sendtoid = 0;
783  if ($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 == 'PROJECT_CREATE') {
811  // Projects
812  // Load translation files required by the page
813  $langs->loadLangs(array("agenda", "other", "projects"));
814 
815  if (empty($object->actionmsg2)) {
816  $object->actionmsg2 = $langs->transnoentities("ProjectCreatedInDolibarr", $object->ref);
817  }
818  $object->actionmsg = $langs->transnoentities("ProjectCreatedInDolibarr", $object->ref);
819  $object->actionmsg .= "\n".$langs->transnoentities("Project").': '.$object->ref;
820 
821  $object->sendtoid = 0;
822  } elseif ($action == 'PROJECT_VALIDATE') {
823  // Load translation files required by the page
824  $langs->loadLangs(array("agenda", "other", "projects"));
825 
826  if (empty($object->actionmsg2)) {
827  $object->actionmsg2 = $langs->transnoentities("ProjectValidatedInDolibarr", $object->ref);
828  }
829  $object->actionmsg = $langs->transnoentities("ProjectValidatedInDolibarr", $object->ref);
830  $object->actionmsg .= "\n".$langs->transnoentities("Project").': '.$object->ref;
831 
832  $object->sendtoid = 0;
833  } elseif ($action == 'PROJECT_MODIFY') {
834  // Load translation files required by the page
835  $langs->loadLangs(array("agenda", "other", "projects"));
836 
837  if (empty($object->actionmsg2)) {
838  $object->actionmsg2 = $langs->transnoentities("ProjectModifiedInDolibarr", $object->ref);
839  }
840  $object->actionmsg = $langs->transnoentities("ProjectModifiedInDolibarr", $object->ref);
841  //$object->actionmsg .= "\n".$langs->transnoentities("Task").': ???';
842  if (!empty($object->usage_opportunity) && is_object($object->oldcopy) && $object->opp_status != $object->oldcopy->opp_status) {
843  $object->actionmsg .= "\n".$langs->transnoentitiesnoconv("OpportunityStatus").': '.$object->oldcopy->opp_status.' -> '.$object->opp_status;
844  }
845 
846  $object->sendtoid = 0;
847  } elseif ($action == 'TASK_CREATE') {
848  // Project tasks
849  // Load translation files required by the page
850  $langs->loadLangs(array("agenda", "other", "projects"));
851 
852  if (empty($object->actionmsg2)) {
853  $object->actionmsg2 = $langs->transnoentities("TaskCreatedInDolibarr", $object->ref);
854  }
855  $object->actionmsg = $langs->transnoentities("TaskCreatedInDolibarr", $object->ref);
856  $object->actionmsg .= "\n".$langs->transnoentities("Task").': '.$object->ref;
857 
858  $object->sendtoid = 0;
859  } elseif ($action == 'TASK_MODIFY') {
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("TaskModifiedInDolibarr", $object->ref);
865  }
866  $object->actionmsg = $langs->transnoentities("TaskModifieddInDolibarr", $object->ref);
867  $object->actionmsg .= "\n".$langs->transnoentities("Task").': '.$object->ref;
868 
869  $object->sendtoid = 0;
870  } elseif ($action == 'TASK_DELETE') {
871  // Load translation files required by the page
872  $langs->loadLangs(array("agenda", "other", "projects"));
873 
874  if (empty($object->actionmsg2)) {
875  $object->actionmsg2 = $langs->transnoentities("TaskDeletedInDolibarr", $object->ref);
876  }
877  $object->actionmsg = $langs->transnoentities("TaskDeletedInDolibarr", $object->ref);
878  $object->actionmsg .= "\n".$langs->transnoentities("Task").': '.$object->ref;
879 
880  $object->sendtoid = 0;
881  } elseif ($action == 'TICKET_ASSIGNED') {
882  // Load translation files required by the page
883  $langs->loadLangs(array("agenda", "other", "projects"));
884 
885  if (empty($object->actionmsg2)) {
886  $object->actionmsg2 = $langs->transnoentities("TICKET_ASSIGNEDInDolibarr", $object->ref);
887  }
888  $object->actionmsg = $langs->transnoentities("TICKET_ASSIGNEDInDolibarr", $object->ref);
889  if ($object->oldcopy->fk_user_assign > 0) {
890  $tmpuser = new User($this->db);
891  $tmpuser->fetch($object->oldcopy->fk_user_assign);
892  $object->actionmsg .= "\n".$langs->transnoentities("OldUser").': '.$tmpuser->getFullName($langs);
893  } else {
894  $object->actionmsg .= "\n".$langs->transnoentities("OldUser").': '.$langs->trans("None");
895  }
896  if ($object->fk_user_assign > 0) {
897  $tmpuser = new User($this->db);
898  $tmpuser->fetch($object->fk_user_assign);
899  $object->actionmsg .= "\n".$langs->transnoentities("NewUser").': '.$tmpuser->getFullName($langs);
900  } else {
901  $object->actionmsg .= "\n".$langs->transnoentities("NewUser").': '.$langs->trans("None");
902  }
903  $object->sendtoid = 0;
904  } else {
905  // TODO Merge all previous cases into this generic one
906  // $action = BILL_DELETE, TICKET_CREATE, TICKET_MODIFY, TICKET_DELETE, CONTACT_SENTBYMAIL, RECRUITMENTCANDIDATURE_MODIFY, ...
907  // Can also be a value defined by an external module like SENTBYSMS, COMPANY_SENTBYSMS, MEMBER_SENTBYSMS, ...
908  // Note: We are here only if $conf->global->MAIN_AGENDA_ACTIONAUTO_action is on (tested at begining of this function).
909  // Note that these key can be set in agenda setup, only if defined into llx_c_action_trigger
910  // Load translation files required by the page
911  if (empty($object->actionmsg2)) {
912  $langs->loadLangs(array("agenda", "other"));
913  if ($langs->transnoentities($action."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref)) != $action."InDolibarr") { // specific translation key
914  $object->actionmsg2 = $langs->transnoentities($action."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref));
915  } else { // generic translation key
916  $tmp = explode('_', $action);
917  $object->actionmsg2 = $langs->transnoentities($tmp[count($tmp) - 1]."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref));
918  }
919  }
920  if (empty($object->actionmsg)) {
921  $langs->loadLangs(array("agenda", "other"));
922  if ($langs->transnoentities($action."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref)) != $action."InDolibarr") { // specific translation key
923  $object->actionmsg = $langs->transnoentities($action."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref));
924  } else { // generic translation key
925  $tmp = explode('_', $action);
926  $object->actionmsg = $langs->transnoentities($tmp[count($tmp) - 1]."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref));
927  }
928  }
929 
930  if (!isset($object->sendtoid) || !is_array($object->sendtoid)) {
931  $object->sendtoid = 0;
932  }
933  }
934 
935  // If trackid is not defined, we set it.
936  // Note that it should be set by caller. This is for compatibility purpose only.
937  if (empty($object->trackid)) {
938  // See also similar list into emailcollector.class.php
939  if (preg_match('/^COMPANY_/', $action)) {
940  $object->trackid = 'thi'.$object->id;
941  } elseif (preg_match('/^CONTACT_/', $action)) {
942  $object->trackid = 'ctc'.$object->id;
943  } elseif (preg_match('/^CONTRACT_/', $action)) {
944  $object->trackid = 'con'.$object->id;
945  } elseif (preg_match('/^PROPAL_/', $action)) {
946  $object->trackid = 'pro'.$object->id;
947  } elseif (preg_match('/^ORDER_/', $action)) {
948  $object->trackid = 'ord'.$object->id;
949  } elseif (preg_match('/^BILL_/', $action)) {
950  $object->trackid = 'inv'.$object->id;
951  } elseif (preg_match('/^FICHINTER_/', $action)) {
952  $object->trackid = 'int'.$object->id;
953  } elseif (preg_match('/^SHIPPING_/', $action)) {
954  $object->trackid = 'shi'.$object->id;
955  } elseif (preg_match('/^RECEPTION_/', $action)) {
956  $object->trackid = 'rec'.$object->id;
957  } elseif (preg_match('/^PROPOSAL_SUPPLIER/', $action)) {
958  $object->trackid = 'spr'.$object->id;
959  } elseif (preg_match('/^ORDER_SUPPLIER_/', $action)) {
960  $object->trackid = 'sor'.$object->id;
961  } elseif (preg_match('/^BILL_SUPPLIER_/', $action)) {
962  $object->trackid = 'sin'.$object->id;
963  } elseif (preg_match('/^MEMBER_SUBSCRIPTION_/', $action)) {
964  $object->trackid = 'sub'.$object->id;
965  } elseif (preg_match('/^MEMBER_/', $action)) {
966  $object->trackid = 'mem'.$object->id;
967  } elseif (preg_match('/^PROJECT_/', $action)) {
968  $object->trackid = 'proj'.$object->id;
969  } elseif (preg_match('/^TASK_/', $action)) {
970  $object->trackid = 'tas'.$object->id;
971  } elseif (preg_match('/^TICKET_/', $action)) {
972  $object->trackid = 'tic'.$object->id;
973  } elseif (preg_match('/^USER_/', $action)) {
974  $object->trackid = 'use'.$object->id;
975  } else {
976  $object->trackid = '';
977  }
978  }
979 
980  /* Seems no more required: We have the data in dedicated field now.
981  if (!empty($user->login)) {
982  $object->actionmsg = dol_concatdesc($langs->transnoentities("Author").': '.$user->login, $object->actionmsg);
983  } elseif (isset($object->origin_email)) {
984  $object->actionmsg = dol_concatdesc($langs->transnoentities("Author").': '.$object->origin_email, $object->actionmsg);
985  }
986  */
987 
988  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
989 
990  // Add entry in event table
991  $now = dol_now();
992 
993  if (isset($_SESSION['listofnames-'.$object->trackid])) {
994  $attachs = $_SESSION['listofnames-'.$object->trackid];
995  if ($attachs && strpos($action, 'SENTBYMAIL')) {
996  $object->actionmsg = dol_concatdesc($object->actionmsg, "\n".$langs->transnoentities("AttachedFiles").': '.$attachs);
997  }
998  }
999  require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
1000  require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
1001  $contactforaction = new Contact($this->db);
1002  $societeforaction = new Societe($this->db);
1003  // Set contactforaction if there is only 1 contact.
1004 
1005  if (is_array($object->sendtoid)) {
1006  if (count($object->sendtoid) == 1) {
1007  $contactforaction->fetch(reset($object->sendtoid));
1008  }
1009  } else {
1010  if ($object->sendtoid > 0) {
1011  $contactforaction->fetch($object->sendtoid);
1012  }
1013  }
1014  // Set societeforaction.
1015  if (isset($object->socid) && $object->socid > 0) {
1016  $societeforaction->fetch($object->socid);
1017  } elseif (isset($object->fk_soc) && $object->fk_soc > 0) {
1018  $societeforaction->fetch($object->fk_soc);
1019  } elseif (isset($object->thirdparty) && isset($object->thirdparty->id) && $object->thirdparty->id > 0) {
1020  $societeforaction = $object->thirdparty;
1021  }
1022 
1023  $projectid = isset($object->fk_project) ? $object->fk_project : 0;
1024  if ($object->element == 'project') {
1025  $projectid = $object->id;
1026  }
1027 
1028  $elementid = $object->id; // id of object
1029  $elementtype = $object->element;
1030  $elementmodule = (empty($object->module) ? '' : $object->module);
1031  if ($object->element == 'subscription') {
1032  $elementid = $object->fk_adherent;
1033  $elementtype = 'member';
1034  }
1035  //var_dump($societeforaction);var_dump($contactforaction);var_dump($elementid);var_dump($elementtype);exit;
1036 
1037  // Insertion action
1038  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
1039  $actioncomm = new ActionComm($this->db);
1040  $actioncomm->type_code = $object->actiontypecode; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...)
1041  $actioncomm->code = 'AC_'.$action;
1042  $actioncomm->label = $object->actionmsg2;
1043  $actioncomm->note_private = $object->actionmsg;
1044  $actioncomm->fk_project = $projectid;
1045  $actioncomm->datep = $now;
1046  $actioncomm->datef = $now;
1047  $actioncomm->durationp = 0;
1048  $actioncomm->percentage = -1; // Not applicable
1049  $actioncomm->socid = $societeforaction->id;
1050  $actioncomm->contact_id = $contactforaction->id; // deprecated, use ->socpeopleassigned instead
1051  $actioncomm->authorid = $user->id; // User saving action
1052  $actioncomm->userownerid = $user->id; // Owner of action
1053  // 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)
1054  if (!property_exists($object, 'email_fields_no_propagate_in_actioncomm') || empty($object->email_fields_no_propagate_in_actioncomm)) {
1055  $actioncomm->email_msgid = empty($object->email_msgid) ? null : $object->email_msgid;
1056  $actioncomm->email_from = empty($object->email_from) ? null : $object->email_from;
1057  $actioncomm->email_sender = empty($object->email_sender) ? null : $object->email_sender;
1058  $actioncomm->email_to = empty($object->email_to) ? null : $object->email_to;
1059  $actioncomm->email_tocc = empty($object->email_tocc) ? null : $object->email_tocc;
1060  $actioncomm->email_tobcc = empty($object->email_tobcc) ? null : $object->email_tobcc;
1061  $actioncomm->email_subject = empty($object->email_subject) ? null : $object->email_subject;
1062  $actioncomm->errors_to = empty($object->errors_to) ? null : $object->errors_to;
1063  }
1064 
1065  // Object linked (if link is for thirdparty, contact, project it is a recording error. We should not have links in link table
1066  // for such objects because there is already a dedicated field into table llx_actioncomm or llx_actioncomm_resources.
1067  if (!in_array($elementtype, array('societe', 'contact', 'project'))) {
1068  $actioncomm->fk_element = $elementid;
1069  $actioncomm->elementtype = $elementtype.($elementmodule ? '@'.$elementmodule : '');
1070  }
1071 
1072  if (property_exists($object, 'attachedfiles') && is_array($object->attachedfiles) && count($object->attachedfiles) > 0) {
1073  $actioncomm->attachedfiles = $object->attachedfiles;
1074  }
1075  if (property_exists($object, 'sendtouserid') && is_array($object->sendtouserid) && count($object->sendtouserid) > 0) {
1076  $actioncomm->userassigned = $object->sendtouserid;
1077  }
1078  if (property_exists($object, 'sendtoid') && is_array($object->sendtoid) && count($object->sendtoid) > 0) {
1079  foreach ($object->sendtoid as $val) {
1080  $actioncomm->socpeopleassigned[$val] = $val;
1081  }
1082  }
1083 
1084  $ret = $actioncomm->create($user); // User creating action
1085 
1086  if ($ret > 0 && !empty($conf->global->MAIN_COPY_FILE_IN_EVENT_AUTO)) {
1087  if (is_array($object->attachedfiles) && array_key_exists('paths', $object->attachedfiles) && count($object->attachedfiles['paths']) > 0) {
1088  foreach ($object->attachedfiles['paths'] as $key => $filespath) {
1089  $srcfile = $filespath;
1090  $destdir = $conf->agenda->dir_output.'/'.$ret;
1091  $destfile = $destdir.'/'.$object->attachedfiles['names'][$key];
1092  if (dol_mkdir($destdir) >= 0) {
1093  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1094  dol_copy($srcfile, $destfile);
1095  }
1096  }
1097  }
1098  }
1099 
1100  unset($object->actionmsg);
1101  unset($object->actionmsg2);
1102  unset($object->actiontypecode); // When several action are called on same object, we must be sure to not reuse value of first action.
1103 
1104  if ($ret > 0) {
1105  $_SESSION['LAST_ACTION_CREATED'] = $ret;
1106  return 1;
1107  } else {
1108  $this->error = "Failed to insert event : ".$actioncomm->error." ".join(',', $actioncomm->errors);
1109  $this->errors = $actioncomm->errors;
1110 
1111  dol_syslog("interface_modAgenda_ActionsAuto.class.php: ".$this->error, LOG_ERR);
1112  return -1;
1113  }
1114  }
1115 }
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:48
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:2514
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:7248
dol_copy
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:703
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
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:44
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:2845
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6603