dolibarr  9.0.0
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 <http://www.gnu.org/licenses/>.
21  */
22 
29 require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
30 
31 
36 {
37  public $family = 'agenda';
38  public $description = "Triggers of this module add actions in agenda according to setup made in agenda setup.";
39 
44  public $version = self::VERSION_DOLIBARR;
45 
49  public $picto = 'action';
50 
72  public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
73  {
74  if (empty($conf->agenda->enabled)) return 0; // Module not active, we do nothing
75 
76  $key = 'MAIN_AGENDA_ACTIONAUTO_'.$action;
77 
78  // Do not log events not enabled for this action
79  if (empty($conf->global->$key)) {
80  return 0;
81  }
82 
83  $langs->load("agenda");
84 
85  if (empty($object->actiontypecode)) $object->actiontypecode='AC_OTH_AUTO';
86 
87  // Actions
88  if ($action == 'COMPANY_CREATE')
89  {
90  // Load translation files required by the page
91  $langs->loadLangs(array("agenda","other","companies"));
92 
93  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("NewCompanyToDolibarr",$object->name);
94  $object->actionmsg=$langs->transnoentities("NewCompanyToDolibarr",$object->name);
95  if (! empty($object->prefix)) $object->actionmsg.=" (".$object->prefix.")";
96 
97  $object->sendtoid=0;
98  $object->socid=$object->id;
99  }
100  elseif ($action == 'COMPANY_SENTBYMAIL')
101  {
102  // Load translation files required by the page
103  $langs->loadLangs(array("agenda","other","orders"));
104 
105  if (empty($object->actionmsg2)) dol_syslog('Trigger called with property actionmsg2 on object not defined', LOG_ERR);
106 
107  // Parameters $object->sendtoid defined by caller
108  //$object->sendtoid=0;
109  }
110  elseif ($action == 'CONTRACT_VALIDATE')
111  {
112  // Load translation files required by the page
113  $langs->loadLangs(array("agenda","other","contracts"));
114 
115  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ContractValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
116  $object->actionmsg=$langs->transnoentities("ContractValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
117 
118  $object->sendtoid=0;
119  }
120  elseif ($action == 'CONTRACT_SENTBYMAIL')
121  {
122  // Load translation files required by the page
123  $langs->loadLangs(array("agenda","other","contracts"));
124 
125  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ContractSentByEMail",$object->ref);
126  if (empty($object->actionmsg))
127  {
128  $object->actionmsg=$langs->transnoentities("ContractSentByEMail",$object->ref);
129  }
130 
131  // Parameters $object->sendtoid defined by caller
132  //$object->sendtoid=0;
133  }
134  elseif ($action == 'PROPAL_VALIDATE')
135  {
136  // Load translation files required by the page
137  $langs->loadLangs(array("agenda","other","propal"));
138 
139  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
140  $object->actionmsg=$langs->transnoentities("PropalValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
141 
142  $object->sendtoid=0;
143  }
144  elseif ($action == 'PROPAL_SENTBYMAIL')
145  {
146  // Load translation files required by the page
147  $langs->loadLangs(array("agenda","other","propal"));
148 
149  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProposalSentByEMail",$object->ref);
150  if (empty($object->actionmsg))
151  {
152  $object->actionmsg=$langs->transnoentities("ProposalSentByEMail",$object->ref);
153  }
154 
155  // Parameters $object->sendtoid defined by caller
156  //$object->sendtoid=0;
157  }
158  elseif ($action == 'PROPAL_CLOSE_SIGNED')
159  {
160  // Load translation files required by the page
161  $langs->loadLangs(array("agenda","other","propal"));
162 
163  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref);
164  $object->actionmsg=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref);
165 
166  $object->sendtoid=0;
167  }
168  elseif ($action == 'PROPAL_CLASSIFY_BILLED')
169  {
170  // Load translation files required by the page
171  $langs->loadLangs(array("agenda","other","propal"));
172 
173  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClassifiedBilledInDolibarr",$object->ref);
174  $object->actionmsg=$langs->transnoentities("PropalClassifiedBilledInDolibarr",$object->ref);
175 
176  $object->sendtoid=0;
177  }
178  elseif ($action == 'PROPAL_CLOSE_REFUSED')
179  {
180  // Load translation files required by the page
181  $langs->loadLangs(array("agenda","other","propal"));
182 
183  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref);
184  $object->actionmsg=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref);
185 
186  $object->sendtoid=0;
187  }
188  elseif ($action == 'ORDER_VALIDATE')
189  {
190  // Load translation files required by the page
191  $langs->loadLangs(array("agenda","orders"));
192 
193  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
194  $object->actionmsg=$langs->transnoentities("OrderValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
195 
196  $object->sendtoid=0;
197  }
198  elseif ($action == 'ORDER_CLOSE')
199  {
200  // Load translation files required by the page
201  $langs->loadLangs(array("agenda","other","orders"));
202 
203  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderDeliveredInDolibarr",$object->ref);
204  $object->actionmsg=$langs->transnoentities("OrderDeliveredInDolibarr",$object->ref);
205 
206  $object->sendtoid=0;
207  }
208  elseif ($action == 'ORDER_CLASSIFY_BILLED')
209  {
210  // Load translation files required by the page
211  $langs->loadLangs(array("agenda","other","orders"));
212 
213  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderBilledInDolibarr",$object->ref);
214  $object->actionmsg=$langs->transnoentities("OrderBilledInDolibarr",$object->ref);
215 
216  $object->sendtoid=0;
217  }
218  elseif ($action == 'ORDER_CANCEL')
219  {
220  // Load translation files required by the page
221  $langs->loadLangs(array("agenda","other","orders"));
222 
223  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderCanceledInDolibarr",$object->ref);
224  $object->actionmsg=$langs->transnoentities("OrderCanceledInDolibarr",$object->ref);
225 
226  $object->sendtoid=0;
227  }
228  elseif ($action == 'ORDER_SENTBYMAIL')
229  {
230  // Load translation files required by the page
231  $langs->loadLangs(array("agenda","other","orders"));
232 
233  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderSentByEMail",$object->ref);
234  if (empty($object->actionmsg))
235  {
236  $object->actionmsg=$langs->transnoentities("OrderSentByEMail",$object->ref);
237  }
238 
239  // Parameters $object->sendtoid defined by caller
240  //$object->sendtoid=0;
241  }
242  elseif ($action == 'BILL_VALIDATE')
243  {
244  // Load translation files required by the page
245  $langs->loadLangs(array("agenda","other","bills"));
246 
247  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
248  $object->actionmsg=$langs->transnoentities("InvoiceValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
249 
250  $object->sendtoid=0;
251  }
252  elseif ($action == 'BILL_UNVALIDATE')
253  {
254  // Load translation files required by the page
255  $langs->loadLangs(array("agenda","other","bills"));
256 
257  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceBackToDraftInDolibarr",$object->ref);
258  $object->actionmsg=$langs->transnoentities("InvoiceBackToDraftInDolibarr",$object->ref);
259 
260  $object->sendtoid=0;
261  }
262  elseif ($action == 'BILL_SENTBYMAIL')
263  {
264  // Load translation files required by the page
265  $langs->loadLangs(array("agenda","other","bills"));
266 
267  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceSentByEMail",$object->ref);
268  if (empty($object->actionmsg))
269  {
270  $object->actionmsg=$langs->transnoentities("InvoiceSentByEMail",$object->ref);
271  }
272 
273  // Parameters $object->sendtoid defined by caller
274  //$object->sendtoid=0;
275  }
276  elseif ($action == 'BILL_PAYED')
277  {
278  // Load translation files required by the page
279  $langs->loadLangs(array("agenda","other","bills"));
280 
281  // Values for this action can't be defined by caller.
282  $object->actionmsg2=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref);
283  $object->actionmsg=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref);
284 
285  $object->sendtoid=0;
286  }
287  elseif ($action == 'BILL_CANCEL')
288  {
289  // Load translation files required by the page
290  $langs->loadLangs(array("agenda","other","bills"));
291 
292  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref);
293  $object->actionmsg=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref);
294 
295  $object->sendtoid=0;
296  }
297  elseif ($action == 'FICHINTER_CREATE')
298  {
299  // Load translation files required by the page
300  $langs->loadLangs(array("agenda","other","interventions"));
301 
302  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionCreatedInDolibarr",$object->ref);
303  $object->actionmsg=$langs->transnoentities("InterventionCreatedInDolibarr",$object->ref);
304 
305  $object->sendtoid=0;
306  $object->fk_element=0;
307  $object->elementtype='';
308  }
309  elseif ($action == 'FICHINTER_VALIDATE')
310  {
311  // Load translation files required by the page
312  $langs->loadLangs(array("agenda","other","interventions"));
313 
314  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
315  $object->actionmsg=$langs->transnoentities("InterventionValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
316 
317  $object->sendtoid=0;
318  $object->fk_element=0;
319  $object->elementtype='';
320  }
321  elseif ($action == 'FICHINTER_MODIFY')
322  {
323  // Load translation files required by the page
324  $langs->loadLangs(array("agenda","other","interventions"));
325 
326  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionModifiedInDolibarr",$object->ref);
327  $object->actionmsg=$langs->transnoentities("InterventionModifiedInDolibarr",$object->ref);
328 
329  $object->sendtoid=0;
330  $object->fk_element=0;
331  $object->elementtype='';
332  }
333  elseif ($action == 'FICHINTER_SENTBYMAIL')
334  {
335  // Load translation files required by the page
336  $langs->loadLangs(array("agenda","other","interventions"));
337 
338  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionSentByEMail",$object->ref);
339  if (empty($object->actionmsg))
340  {
341  $object->actionmsg=$langs->transnoentities("InterventionSentByEMail",$object->ref);
342  }
343 
344  // Parameters $object->sendtoid defined by caller
345  //$object->sendtoid=0;
346  }
347  elseif ($action == 'FICHINTER_CLASSIFY_BILLED')
348  {
349  // Load translation files required by the page
350  $langs->loadLangs(array("agenda","other","interventions"));
351 
352  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionClassifiedBilledInDolibarr",$object->ref);
353  $object->actionmsg=$langs->transnoentities("InterventionClassifiedBilledInDolibarr",$object->ref);
354 
355  $object->sendtoid=0;
356  }
357  elseif ($action == 'FICHINTER_CLASSIFY_UNBILLED')
358  {
359  // Load translation files required by the page
360  $langs->loadLangs(array("agenda","other","interventions"));
361 
362  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionClassifiedUnbilledInDolibarr",$object->ref);
363  $object->actionmsg=$langs->transnoentities("InterventionClassifiedUnbilledInDolibarr",$object->ref);
364 
365  $object->sendtoid=0;
366  }
367  elseif ($action == 'FICHINTER_DELETE')
368  {
369  // Load translation files required by the page
370  $langs->loadLangs(array("agenda","other","interventions"));
371 
372  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionDeletedInDolibarr",$object->ref);
373  $object->actionmsg=$langs->transnoentities("InterventionDeletedInDolibarr",$object->ref);
374 
375  $object->sendtoid=0;
376  $object->fk_element=0;
377  $object->elementtype='';
378  }
379  elseif ($action == 'SHIPPING_VALIDATE')
380  {
381  // Load translation files required by the page
382  $langs->loadLangs(array("agenda","other","sendings"));
383 
384  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ShippingValidated",($object->newref?$object->newref:$object->ref));
385  if (empty($object->actionmsg))
386  {
387  $object->actionmsg=$langs->transnoentities("ShippingValidated",($object->newref?$object->newref:$object->ref));
388  }
389 
390  // Parameters $object->sendtoid defined by caller
391  //$object->sendtoid=0;
392  }
393  elseif ($action == 'SHIPPING_SENTBYMAIL')
394  {
395  // Load translation files required by the page
396  $langs->loadLangs(array("agenda","other","sendings"));
397 
398  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ShippingSentByEMail",$object->ref);
399  if (empty($object->actionmsg))
400  {
401  $object->actionmsg=$langs->transnoentities("ShippingSentByEMail",$object->ref);
402  }
403 
404  // Parameters $object->sendtoid defined by caller
405  //$object->sendtoid=0;
406  }
407  elseif ($action == 'PROPOSAL_SUPPLIER_VALIDATE')
408  {
409  // Load translation files required by the page
410  $langs->loadLangs(array("agenda","other","propal"));
411 
412  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
413  $object->actionmsg=$langs->transnoentities("PropalValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
414 
415  $object->sendtoid=0;
416  }
417  elseif ($action == 'PROPOSAL_SUPPLIER_SENTBYMAIL')
418  {
419  // Load translation files required by the page
420  $langs->loadLangs(array("agenda","other","propal"));
421 
422  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProposalSentByEMail",$object->ref);
423  if (empty($object->actionmsg))
424  {
425  $object->actionmsg=$langs->transnoentities("ProposalSentByEMail",$object->ref);
426  }
427 
428  // Parameters $object->sendtoid defined by caller
429  //$object->sendtoid=0;
430  }
431  elseif ($action == 'PROPOSAL_SUPPLIER_CLOSE_SIGNED')
432  {
433  // Load translation files required by the page
434  $langs->loadLangs(array("agenda","other","propal"));
435 
436  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref);
437  $object->actionmsg=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref);
438 
439  $object->sendtoid=0;
440  }
441  elseif ($action == 'PROPOSAL_SUPPLIER_CLOSE_REFUSED')
442  {
443  // Load translation files required by the page
444  $langs->loadLangs(array("agenda","other","propal"));
445 
446  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref);
447  $object->actionmsg=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref);
448 
449  $object->sendtoid=0;
450  }
451  elseif ($action == 'ORDER_SUPPLIER_CREATE')
452  {
453  // Load translation files required by the page
454  $langs->loadLangs(array("agenda","other","orders"));
455 
456  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderCreatedInDolibarr",($object->newref?$object->newref:$object->ref));
457  $object->actionmsg=$langs->transnoentities("OrderCreatedInDolibarr",($object->newref?$object->newref:$object->ref));
458 
459  $object->sendtoid=0;
460  }
461  elseif ($action == 'ORDER_SUPPLIER_VALIDATE')
462  {
463  // Load translation files required by the page
464  $langs->loadLangs(array("agenda","other","orders"));
465 
466  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
467  $object->actionmsg=$langs->transnoentities("OrderValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
468 
469  $object->sendtoid=0;
470  }
471  elseif ($action == 'ORDER_SUPPLIER_APPROVE')
472  {
473  // Load translation files required by the page
474  $langs->loadLangs(array("agenda","other","orders"));
475 
476  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderApprovedInDolibarr",$object->ref);
477  $object->actionmsg=$langs->transnoentities("OrderApprovedInDolibarr",$object->ref);
478 
479  $object->sendtoid=0;
480  }
481  elseif ($action == 'ORDER_SUPPLIER_REFUSE')
482  {
483  // Load translation files required by the page
484  $langs->loadLangs(array("agenda","other","orders"));
485 
486  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderRefusedInDolibarr",$object->ref);
487  $object->actionmsg=$langs->transnoentities("OrderRefusedInDolibarr",$object->ref);
488 
489  $object->sendtoid=0;
490  }
491  elseif ($action == 'ORDER_SUPPLIER_SUBMIT')
492  {
493  // Load translation files required by the page
494  $langs->loadLangs(array("agenda","other","orders"));
495 
496  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("SupplierOrderSubmitedInDolibarr",($object->newref?$object->newref:$object->ref));
497  $object->actionmsg=$langs->transnoentities("SupplierOrderSubmitedInDolibarr",($object->newref?$object->newref:$object->ref));
498 
499  $object->sendtoid=0;
500  }
501  elseif ($action == 'ORDER_SUPPLIER_RECEIVE')
502  {
503  // Load translation files required by the page
504  $langs->loadLangs(array("agenda","other","orders"));
505 
506  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("SupplierOrderReceivedInDolibarr",($object->newref?$object->newref:$object->ref));
507  $object->actionmsg=$langs->transnoentities("SupplierOrderReceivedInDolibarr",($object->newref?$object->newref:$object->ref));
508 
509  $object->sendtoid=0;
510  }
511  elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL')
512  {
513  // Load translation files required by the page
514  $langs->loadLangs(array("agenda","other","bills","orders"));
515 
516  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("SupplierOrderSentByEMail",$object->ref);
517  if (empty($object->actionmsg))
518  {
519  $object->actionmsg=$langs->transnoentities("SupplierOrderSentByEMail",$object->ref);
520  }
521 
522  // Parameters $object->sendtoid defined by caller
523  //$object->sendtoid=0;
524  }
525  elseif ($action == 'ORDER_SUPPLIER_CLASSIFY_BILLED')
526  {
527  // Load translation files required by the page
528  $langs->loadLangs(array("agenda","other","bills","orders"));
529 
530  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("SupplierOrderClassifiedBilled",$object->ref);
531  if (empty($object->actionmsg))
532  {
533  $object->actionmsg=$langs->transnoentities("SupplierOrderClassifiedBilled",$object->ref);
534  }
535 
536  $object->sendtoid=0;
537  }
538  elseif ($action == 'BILL_SUPPLIER_VALIDATE')
539  {
540  // Load translation files required by the page
541  $langs->loadLangs(array("agenda","other","bills"));
542 
543  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
544  $object->actionmsg=$langs->transnoentities("InvoiceValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
545 
546  $object->sendtoid=0;
547  }
548  elseif ($action == 'BILL_SUPPLIER_UNVALIDATE')
549  {
550  // Load translation files required by the page
551  $langs->loadLangs(array("agenda","other","bills"));
552 
553  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceBackToDraftInDolibarr",$object->ref);
554  $object->actionmsg=$langs->transnoentities("InvoiceBackToDraftInDolibarr",$object->ref);
555 
556  $object->sendtoid=0;
557  }
558  elseif ($action == 'BILL_SUPPLIER_SENTBYMAIL')
559  {
560  // Load translation files required by the page
561  $langs->loadLangs(array("agenda","other","bills","orders"));
562 
563  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("SupplierInvoiceSentByEMail",$object->ref);
564  if (empty($object->actionmsg))
565  {
566  $object->actionmsg=$langs->transnoentities("SupplierInvoiceSentByEMail",$object->ref);
567  }
568 
569  // Parameters $object->sendtoid defined by caller
570  //$object->sendtoid=0;
571  }
572  elseif ($action == 'BILL_SUPPLIER_PAYED')
573  {
574  // Load translation files required by the page
575  $langs->loadLangs(array("agenda","other","bills"));
576 
577  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref);
578  $object->actionmsg=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref);
579 
580  $object->sendtoid=0;
581  }
582  elseif ($action == 'BILL_SUPPLIER_CANCELED')
583  {
584  // Load translation files required by the page
585  $langs->loadLangs(array("agenda","other","bills"));
586 
587  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref);
588  $object->actionmsg=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref);
589 
590  $object->sendtoid=0;
591  }
592 
593  // Members
594  elseif ($action == 'MEMBER_VALIDATE')
595  {
596  // Load translation files required by the page
597  $langs->loadLangs(array("agenda","other","members"));
598 
599  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberValidatedInDolibarr",$object->getFullName($langs));
600  $object->actionmsg=$langs->transnoentities("MemberValidatedInDolibarr",$object->getFullName($langs));
601  $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
602  $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
603 
604  $object->sendtoid=0;
605  }
606  elseif ($action == 'MEMBER_MODIFY')
607  {
608  // Load translation files required by the page
609  $langs->loadLangs(array("agenda","other","members"));
610 
611  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberModifiedInDolibarr",$object->getFullName($langs));
612  $object->actionmsg=$langs->transnoentities("MemberModifiedInDolibarr",$object->getFullName($langs));
613  $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
614  $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
615 
616  $object->sendtoid=0;
617  }
618  elseif ($action == 'MEMBER_SUBSCRIPTION_CREATE')
619  {
620  // Load translation files required by the page
621  $langs->loadLangs(array("agenda","other","members"));
622 
623  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberSubscriptionAddedInDolibarr",$object->ref,$object->getFullName($langs));
624  $object->actionmsg=$langs->transnoentities("MemberSubscriptionAddedInDolibarr",$object->ref,$object->getFullName($langs));
625  $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
626  $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
627  $object->actionmsg.="\n".$langs->transnoentities("Amount").': '.$object->last_subscription_amount;
628  $object->actionmsg.="\n".$langs->transnoentities("Period").': '.dol_print_date($object->last_subscription_date_start,'day').' - '.dol_print_date($object->last_subscription_date_end,'day');
629 
630  $object->sendtoid=0;
631  if ($object->fk_soc > 0) $object->socid=$object->fk_soc;
632  }
633  elseif ($action == 'MEMBER_SUBSCRIPTION_MODIFY')
634  {
635  // Load translation files required by the page
636  $langs->loadLangs(array("agenda","other","members"));
637 
638  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberSubscriptionModifiedInDolibarr",$object->ref,$object->getFullName($langs));
639  $object->actionmsg=$langs->transnoentities("MemberSubscriptionModifiedInDolibarr",$object->ref,$object->getFullName($langs));
640  $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
641  $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
642  $object->actionmsg.="\n".$langs->transnoentities("Amount").': '.$object->last_subscription_amount;
643  $object->actionmsg.="\n".$langs->transnoentities("Period").': '.dol_print_date($object->last_subscription_date_start,'day').' - '.dol_print_date($object->last_subscription_date_end,'day');
644 
645  $object->sendtoid=0;
646  if ($object->fk_soc > 0) $object->socid=$object->fk_soc;
647  }
648  elseif ($action == 'MEMBER_SUBSCRIPTION_DELETE')
649  {
650  // Load translation files required by the page
651  $langs->loadLangs(array("agenda","other","members"));
652 
653  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberSubscriptionDeletedInDolibarr",$object->ref,$object->getFullName($langs));
654  $object->actionmsg=$langs->transnoentities("MemberSubscriptionDeletedInDolibarr",$object->ref,$object->getFullName($langs));
655  $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
656  $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
657  $object->actionmsg.="\n".$langs->transnoentities("Amount").': '.$object->last_subscription_amount;
658  $object->actionmsg.="\n".$langs->transnoentities("Period").': '.dol_print_date($object->last_subscription_date_start,'day').' - '.dol_print_date($object->last_subscription_date_end,'day');
659 
660  $object->sendtoid=0;
661  if ($object->fk_soc > 0) $object->socid=$object->fk_soc;
662  }
663  elseif ($action == 'MEMBER_RESILIATE')
664  {
665  // Load translation files required by the page
666  $langs->loadLangs(array("agenda","other","members"));
667 
668  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberResiliatedInDolibarr",$object->getFullName($langs));
669  $object->actionmsg=$langs->transnoentities("MemberResiliatedInDolibarr",$object->getFullName($langs));
670  $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
671  $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
672 
673  $object->sendtoid=0;
674  }
675  elseif ($action == 'MEMBER_DELETE')
676  {
677  // Load translation files required by the page
678  $langs->loadLangs(array("agenda","other","members"));
679 
680  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberDeletedInDolibarr",$object->getFullName($langs));
681  $object->actionmsg=$langs->transnoentities("MemberDeletedInDolibarr",$object->getFullName($langs));
682  $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
683  $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
684 
685  $object->sendtoid=0;
686  }
687 
688  // Projects
689  elseif ($action == 'PROJECT_CREATE')
690  {
691  // Load translation files required by the page
692  $langs->loadLangs(array("agenda","other","projects"));
693 
694  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProjectCreatedInDolibarr",$object->ref);
695  $object->actionmsg=$langs->transnoentities("ProjectCreatedInDolibarr",$object->ref);
696  $object->actionmsg.="\n".$langs->transnoentities("Project").': '.$object->ref;
697 
698  $object->sendtoid=0;
699  }
700  elseif($action == 'PROJECT_VALIDATE')
701  {
702  // Load translation files required by the page
703  $langs->loadLangs(array("agenda","other","projects"));
704 
705  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProjectValidatedInDolibarr",$object->ref);
706  $object->actionmsg=$langs->transnoentities("ProjectValidatedInDolibarr",$object->ref);
707  $object->actionmsg.="\n".$langs->transnoentities("Project").': '.$object->ref;
708 
709  $object->sendtoid=0;
710  }
711  elseif($action == 'PROJECT_MODIFY')
712  {
713  // Load translation files required by the page
714  $langs->loadLangs(array("agenda","other","projects"));
715 
716  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProjectModifiedInDolibarr",$object->ref);
717  $object->actionmsg=$langs->transnoentities("ProjectModifiedInDolibarr",$object->ref);
718  $object->actionmsg.="\n".$langs->transnoentities("Task").': '.$object->ref;
719 
720  $object->sendtoid=0;
721  }
722 
723  // Project tasks
724  elseif($action == 'TASK_CREATE')
725  {
726  // Load translation files required by the page
727  $langs->loadLangs(array("agenda","other","projects"));
728 
729  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("TaskCreatedInDolibarr",$object->ref);
730  $object->actionmsg=$langs->transnoentities("TaskCreatedInDolibarr",$object->ref);
731  $object->actionmsg.="\n".$langs->transnoentities("Task").': '.$object->ref;
732 
733  $object->sendtoid=0;
734  }
735 
736  elseif($action == 'TASK_MODIFY')
737  {
738  // Load translation files required by the page
739  $langs->loadLangs(array("agenda","other","projects"));
740 
741  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("TaskModifiedInDolibarr",$object->ref);
742  $object->actionmsg=$langs->transnoentities("TaskModifieddInDolibarr",$object->ref);
743  $object->actionmsg.="\n".$langs->transnoentities("Task").': '.$object->ref;
744 
745  $object->sendtoid=0;
746  }
747 
748  elseif($action == 'TASK_DELETE')
749  {
750  // Load translation files required by the page
751  $langs->loadLangs(array("agenda","other","projects"));
752 
753  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("TaskDeletedInDolibarr",$object->ref);
754  $object->actionmsg=$langs->transnoentities("TaskDeletedInDolibarr",$object->ref);
755  $object->actionmsg.="\n".$langs->transnoentities("Task").': '.$object->ref;
756 
757  $object->sendtoid=0;
758  }
759  // TODO Merge all previous cases into this generic one
760  else // $action = TICKET_CREATE, TICKET_MODIFY, TICKET_DELETE, ...
761  {
762  // Note: We are here only if $conf->global->MAIN_AGENDA_ACTIONAUTO_action is on (tested at begining of this function)
763  // Load translation files required by the page
764  $langs->loadLangs(array("agenda","other"));
765 
766  if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities($action."InDolibarr",$object->ref);
767  if (empty($object->actionmsg)) $object->actionmsg=$langs->transnoentities($action."InDolibarr",$object->ref);
768 
769  $object->sendtoid=0;
770  }
771 
772  $object->actionmsg = $langs->transnoentities("Author").': '.$user->login."\n".$object->actionmsg;
773 
774  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
775 
776  // Add entry in event table
777  $now=dol_now();
778 
779  if (isset($_SESSION['listofnames-'.$object->trackid]))
780  {
781  $attachs=$_SESSION['listofnames-'.$object->trackid];
782  if ($attachs && strpos($action,'SENTBYMAIL'))
783  {
784  $object->actionmsg=dol_concatdesc($object->actionmsg, "\n".$langs->transnoentities("AttachedFiles").': '.$attachs);
785  }
786  }
787 
788  require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
789  require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
790  $contactforaction=new Contact($this->db);
791  $societeforaction=new Societe($this->db);
792  // Set contactforaction if there is only 1 contact.
793  if (is_array($object->sendtoid))
794  {
795  if (count($object->sendtoid) == 1) $contactforaction->fetch(reset($object->sendtoid));
796  }
797  else
798  {
799  if ($object->sendtoid > 0) $contactforaction->fetch($object->sendtoid);
800  }
801  // Set societeforaction.
802  if ($object->socid > 0) $societeforaction->fetch($object->socid);
803  elseif ($object->fk_soc > 0) $societeforaction->fetch($object->fk_soc);
804 
805  $projectid = isset($object->fk_project)?$object->fk_project:0;
806  if ($object->element == 'project') $projectid = $object->id;
807 
808  $elementid = $object->id;
809  $elementtype = $object->element;
810  if ($object->element == 'subscription')
811  {
812  $elementid = $object->fk_adherent;
813  $elementtype = 'member';
814  }
815 
816  // Insertion action
817  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
818  $actioncomm = new ActionComm($this->db);
819  $actioncomm->type_code = $object->actiontypecode; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...)
820  $actioncomm->code = 'AC_'.$action;
821  $actioncomm->label = $object->actionmsg2;
822  $actioncomm->note = $object->actionmsg; // TODO Replace with ($actioncomm->email_msgid ? $object->email_content : $object->actionmsg)
823  $actioncomm->fk_project = $projectid;
824  $actioncomm->datep = $now;
825  $actioncomm->datef = $now;
826  $actioncomm->durationp = 0;
827  $actioncomm->punctual = 1;
828  $actioncomm->percentage = -1; // Not applicable
829  $actioncomm->societe = $societeforaction;
830  $actioncomm->contact = $contactforaction;
831  $actioncomm->socid = $societeforaction->id;
832  $actioncomm->contactid = $contactforaction->id;
833  $actioncomm->authorid = $user->id; // User saving action
834  $actioncomm->userownerid = $user->id; // Owner of action
835  // Fields defined when action is an email (content should be into object->actionmsg to be added into note, subject into object->actionms2 to be added into label)
836  $actioncomm->email_msgid = $object->email_msgid;
837  $actioncomm->email_from = $object->email_from;
838  $actioncomm->email_sender = $object->email_sender;
839  $actioncomm->email_to = $object->email_to;
840  $actioncomm->email_tocc = $object->email_tocc;
841  $actioncomm->email_tobcc = $object->email_tobcc;
842  $actioncomm->email_subject = $object->email_subject;
843  $actioncomm->errors_to = $object->errors_to;
844 
845  // Object linked (if link is for thirdparty, contact, project it is a recording error. We should not have links in link table
846  // for such objects because there is already a dedicated field into table llx_actioncomm.
847  if (! in_array($elementtype, array('societe','contact','project')))
848  {
849  $actioncomm->fk_element = $elementid;
850  $actioncomm->elementtype = $elementtype;
851  }
852 
853  if (property_exists($object,'attachedfiles') && is_array($object->attachedfiles) && count($object->attachedfiles)>0) {
854  $actioncomm->attachedfiles=$object->attachedfiles;
855  }
856  if (property_exists($object,'sendtouserid') && is_array($object->sendtouserid) && count($object->sendtouserid)>0) {
857  $actioncomm->userassigned=$object->sendtouserid;
858  }
859 
860  $ret=$actioncomm->create($user); // User creating action
861 
862  if ($ret > 0 && $conf->global->MAIN_COPY_FILE_IN_EVENT_AUTO)
863  {
864  if (is_array($object->attachedfiles) && array_key_exists('paths',$object->attachedfiles) && count($object->attachedfiles['paths'])>0) {
865  foreach($object->attachedfiles['paths'] as $key=>$filespath) {
866  $srcfile = $filespath;
867  $destdir = $conf->agenda->dir_output . '/' . $ret;
868  $destfile = $destdir . '/' . $object->attachedfiles['names'][$key];
869  if (dol_mkdir($destdir) >= 0) {
870  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
871  dol_copy($srcfile, $destfile);
872  }
873  }
874  }
875  }
876 
877  unset($object->actionmsg); unset($object->actionmsg2); unset($object->actiontypecode); // When several action are called on same object, we must be sure to not reuse value of first action.
878 
879  if ($ret > 0)
880  {
881  $_SESSION['LAST_ACTION_CREATED'] = $ret;
882  return 1;
883  }
884  else
885  {
886  $error ="Failed to insert event : ".$actioncomm->error." ".join(',',$actioncomm->errors);
887  $this->error=$error;
888  $this->errors=$actioncomm->errors;
889 
890  dol_syslog("interface_modAgenda_ActionsAuto.class.php: ".$this->error, LOG_ERR);
891  return -1;
892  }
893  }
894 }
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:666
transnoentities($key, $param1='', $param2='', $param3='', $param4='', $param5='')
Return translated value of a text string Si il n&#39;y a pas de correspondance pour ce texte...
Class to stock current configuration.
Definition: conf.class.php:33
Class to manage agenda events (actions)
Class to manage contact/addresses.
Class to manage Dolibarr users.
Definition: user.class.php:41
dol_concatdesc($text1, $text2, $forxml=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
load($domain, $alt=0, $stopafterdirection=0, $forcelangdir='', $loadfromfileonly=0)
Load translation key-value for a particular file, into a memory array.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class of triggered functions for agenda module.
dol_now($mode='gmt')
Return date for now.
Class that all the triggers must extend.
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called when a Dolibarrr business event is done.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
loadLangs($domains)
Load translation files.