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