29 require_once DOL_DOCUMENT_ROOT.
'/core/triggers/dolibarrtriggers.class.php';
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.";
50 $this->version = self::VERSION_DOLIBARR;
51 $this->picto =
'action';
78 if (empty($conf->agenda) || empty($conf->agenda->enabled)) {
83 if (preg_match(
'/^ACTION_/', $action)) {
87 $key =
'MAIN_AGENDA_ACTIONAUTO_'.$action;
92 if (empty($conf->global->$key)) {
96 $langs->load(
"agenda");
98 if (empty($object->actiontypecode)) {
99 $object->actiontypecode =
'AC_OTH_AUTO';
103 if ($action ==
'COMPANY_CREATE') {
105 $langs->loadLangs(array(
"agenda",
"other",
"companies"));
107 if (empty($object->actionmsg2)) {
108 $object->actionmsg2 = $langs->transnoentities(
"NewCompanyToDolibarr", $object->name);
110 $object->actionmsg = $langs->transnoentities(
"NewCompanyToDolibarr", $object->name);
112 $object->sendtoid = 0;
113 $object->socid = $object->id;
114 } elseif ($action ==
'COMPANY_MODIFY') {
116 $langs->loadLangs(array(
"agenda",
"other",
"companies"));
118 if (empty($object->actionmsg2)) {
119 $object->actionmsg2 = $langs->transnoentities(
"COMPANY_MODIFYInDolibarr", $object->name);
121 $object->actionmsg = $langs->transnoentities(
"COMPANY_MODIFYInDolibarr", $object->name);
123 $object->sendtoid = 0;
124 $object->socid = $object->id;
125 } elseif ($action ==
'COMPANY_SENTBYMAIL') {
127 $langs->loadLangs(array(
"agenda",
"other",
"orders"));
129 if (empty($object->actionmsg2)) {
130 dol_syslog(
'Trigger called with property actionmsg2 on object not defined', LOG_ERR);
135 } elseif ($action ==
'CONTACT_CREATE') {
137 $langs->loadLangs(array(
"agenda",
"other",
"companies"));
139 if (empty($object->actionmsg2)) {
140 $object->actionmsg2 = $langs->transnoentities(
"CONTACT_CREATEInDolibarr", $object->getFullName($langs));
142 $object->actionmsg = $langs->transnoentities(
"CONTACT_CREATEInDolibarr", $object->getFullName($langs));
144 $object->sendtoid = array($object->id => $object->id);
145 $object->socid = $object->socid;
146 } elseif ($action ==
'CONTACT_MODIFY') {
148 $langs->loadLangs(array(
"agenda",
"other",
"companies"));
150 if (empty($object->actionmsg2)) {
151 $object->actionmsg2 = $langs->transnoentities(
"CONTACT_MODIFYInDolibarr", $object->name);
153 $object->actionmsg = $langs->transnoentities(
"CONTACT_MODIFYInDolibarr", $object->name);
155 $object->sendtoid = array($object->id => $object->id);
156 $object->socid = $object->socid;
157 } elseif ($action ==
'CONTRACT_VALIDATE') {
159 $langs->loadLangs(array(
"agenda",
"other",
"contracts"));
161 if (empty($object->actionmsg2)) {
162 $object->actionmsg2 = $langs->transnoentities(
"ContractValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
164 $object->actionmsg = $langs->transnoentities(
"ContractValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
166 $object->sendtoid = 0;
167 } elseif ($action ==
'CONTRACT_SENTBYMAIL') {
169 $langs->loadLangs(array(
"agenda",
"other",
"contracts"));
171 if (empty($object->actionmsg2)) {
172 $object->actionmsg2 = $langs->transnoentities(
"ContractSentByEMail", $object->ref);
174 if (empty($object->actionmsg)) {
175 $object->actionmsg = $langs->transnoentities(
"ContractSentByEMail", $object->ref);
180 } elseif ($action ==
'PROPAL_VALIDATE') {
182 $langs->loadLangs(array(
"agenda",
"other",
"propal"));
184 if (empty($object->actionmsg2)) {
185 $object->actionmsg2 = $langs->transnoentities(
"PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
187 $object->actionmsg = $langs->transnoentities(
"PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
189 $object->sendtoid = 0;
190 } elseif ($action ==
'PROPAL_MODIFY') {
192 $langs->loadLangs(array(
"agenda",
"other",
"propal"));
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));
197 $object->sendtoid = 0;
198 } elseif ($action ==
'PROPAL_SENTBYMAIL') {
200 $langs->loadLangs(array(
"agenda",
"other",
"propal"));
202 if (empty($object->actionmsg2)) {
203 $object->actionmsg2 = $langs->transnoentities(
"ProposalSentByEMail", $object->ref);
205 if (empty($object->actionmsg)) {
206 $object->actionmsg = $langs->transnoentities(
"ProposalSentByEMail", $object->ref);
211 } elseif ($action ==
'PROPAL_CLOSE_SIGNED') {
213 $langs->loadLangs(array(
"agenda",
"other",
"propal"));
215 if (empty($object->actionmsg2)) {
216 $object->actionmsg2 = $langs->transnoentities(
"PropalClosedSignedInDolibarr", $object->ref);
218 $object->actionmsg = $langs->transnoentities(
"PropalClosedSignedInDolibarr", $object->ref);
220 $object->sendtoid = 0;
221 } elseif ($action ==
'PROPAL_CLASSIFY_BILLED') {
223 $langs->loadLangs(array(
"agenda",
"other",
"propal"));
225 if (empty($object->actionmsg2)) {
226 $object->actionmsg2 = $langs->transnoentities(
"PropalClassifiedBilledInDolibarr", $object->ref);
228 $object->actionmsg = $langs->transnoentities(
"PropalClassifiedBilledInDolibarr", $object->ref);
230 $object->sendtoid = 0;
231 } elseif ($action ==
'PROPAL_CLOSE_REFUSED') {
233 $langs->loadLangs(array(
"agenda",
"other",
"propal"));
235 if (empty($object->actionmsg2)) {
236 $object->actionmsg2 = $langs->transnoentities(
"PropalClosedRefusedInDolibarr", $object->ref);
238 $object->actionmsg = $langs->transnoentities(
"PropalClosedRefusedInDolibarr", $object->ref);
240 $object->sendtoid = 0;
241 } elseif ($action ==
'ORDER_VALIDATE') {
243 $langs->loadLangs(array(
"agenda",
"orders"));
245 if (empty($object->actionmsg2)) {
246 $object->actionmsg2 = $langs->transnoentities(
"OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
248 $object->actionmsg = $langs->transnoentities(
"OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
250 $object->sendtoid = 0;
251 } elseif ($action ==
'ORDER_CLOSE') {
253 $langs->loadLangs(array(
"agenda",
"other",
"orders"));
255 if (empty($object->actionmsg2)) {
256 $object->actionmsg2 = $langs->transnoentities(
"OrderDeliveredInDolibarr", $object->ref);
258 $object->actionmsg = $langs->transnoentities(
"OrderDeliveredInDolibarr", $object->ref);
260 $object->sendtoid = 0;
261 } elseif ($action ==
'ORDER_CLASSIFY_BILLED') {
263 $langs->loadLangs(array(
"agenda",
"other",
"orders"));
265 if (empty($object->actionmsg2)) {
266 $object->actionmsg2 = $langs->transnoentities(
"OrderBilledInDolibarr", $object->ref);
268 $object->actionmsg = $langs->transnoentities(
"OrderBilledInDolibarr", $object->ref);
270 $object->sendtoid = 0;
271 } elseif ($action ==
'ORDER_CANCEL') {
273 $langs->loadLangs(array(
"agenda",
"other",
"orders"));
275 if (empty($object->actionmsg2)) {
276 $object->actionmsg2 = $langs->transnoentities(
"OrderCanceledInDolibarr", $object->ref);
278 $object->actionmsg = $langs->transnoentities(
"OrderCanceledInDolibarr", $object->ref);
280 $object->sendtoid = 0;
281 } elseif ($action ==
'ORDER_SENTBYMAIL') {
283 $langs->loadLangs(array(
"agenda",
"other",
"orders"));
285 if (empty($object->actionmsg2)) {
286 $object->actionmsg2 = $langs->transnoentities(
"OrderSentByEMail", $object->ref);
288 if (empty($object->actionmsg)) {
289 $object->actionmsg = $langs->transnoentities(
"OrderSentByEMail", $object->ref);
294 } elseif ($action ==
'BILL_VALIDATE') {
296 $langs->loadLangs(array(
"agenda",
"other",
"bills"));
298 if (empty($object->actionmsg2)) {
299 $object->actionmsg2 = $langs->transnoentities(
"InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
301 $object->actionmsg = $langs->transnoentities(
"InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
303 $object->sendtoid = 0;
304 } elseif ($action ==
'BILL_UNVALIDATE') {
306 $langs->loadLangs(array(
"agenda",
"other",
"bills"));
308 if (empty($object->actionmsg2)) {
309 $object->actionmsg2 = $langs->transnoentities(
"InvoiceBackToDraftInDolibarr", $object->ref);
311 $object->actionmsg = $langs->transnoentities(
"InvoiceBackToDraftInDolibarr", $object->ref);
313 $object->sendtoid = 0;
314 } elseif ($action ==
'BILL_SENTBYMAIL') {
316 $langs->loadLangs(array(
"agenda",
"other",
"bills"));
318 if (empty($object->actionmsg2)) {
319 $object->actionmsg2 = $langs->transnoentities(
"InvoiceSentByEMail", $object->ref);
321 if (empty($object->actionmsg)) {
322 $object->actionmsg = $langs->transnoentities(
"InvoiceSentByEMail", $object->ref);
327 } elseif ($action ==
'BILL_PAYED') {
329 $langs->loadLangs(array(
"agenda",
"other",
"bills"));
332 $object->actionmsg2 = $langs->transnoentities(
"InvoicePaidInDolibarr", $object->ref);
333 $object->actionmsg = $langs->transnoentities(
"InvoicePaidInDolibarr", $object->ref);
335 $object->sendtoid = 0;
336 } elseif ($action ==
'BILL_CANCEL') {
338 $langs->loadLangs(array(
"agenda",
"other",
"bills"));
340 if (empty($object->actionmsg2)) {
341 $object->actionmsg2 = $langs->transnoentities(
"InvoiceCanceledInDolibarr", $object->ref);
343 $object->actionmsg = $langs->transnoentities(
"InvoiceCanceledInDolibarr", $object->ref);
345 $object->sendtoid = 0;
346 } elseif ($action ==
'FICHINTER_CREATE') {
348 $langs->loadLangs(array(
"agenda",
"other",
"interventions"));
350 if (empty($object->actionmsg2)) {
351 $object->actionmsg2 = $langs->transnoentities(
"InterventionCreatedInDolibarr", $object->ref);
353 $object->actionmsg = $langs->transnoentities(
"InterventionCreatedInDolibarr", $object->ref);
355 $object->sendtoid = 0;
356 $object->fk_element = 0;
357 $object->elementtype =
'';
358 } elseif ($action ==
'FICHINTER_VALIDATE') {
360 $langs->loadLangs(array(
"agenda",
"other",
"interventions"));
362 if (empty($object->actionmsg2)) {
363 $object->actionmsg2 = $langs->transnoentities(
"InterventionValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
365 $object->actionmsg = $langs->transnoentities(
"InterventionValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
367 $object->sendtoid = 0;
368 $object->fk_element = 0;
369 $object->elementtype =
'';
370 } elseif ($action ==
'FICHINTER_MODIFY') {
372 $langs->loadLangs(array(
"agenda",
"other",
"interventions"));
374 if (empty($object->actionmsg2)) {
375 $object->actionmsg2 = $langs->transnoentities(
"InterventionModifiedInDolibarr", $object->ref);
377 $object->actionmsg = $langs->transnoentities(
"InterventionModifiedInDolibarr", $object->ref);
379 $object->sendtoid = 0;
380 $object->fk_element = 0;
381 $object->elementtype =
'';
382 } elseif ($action ==
'FICHINTER_SENTBYMAIL') {
384 $langs->loadLangs(array(
"agenda",
"other",
"interventions"));
386 if (empty($object->actionmsg2)) {
387 $object->actionmsg2 = $langs->transnoentities(
"InterventionSentByEMail", $object->ref);
389 if (empty($object->actionmsg)) {
390 $object->actionmsg = $langs->transnoentities(
"InterventionSentByEMail", $object->ref);
395 } elseif ($action ==
'FICHINTER_CLASSIFY_BILLED') {
397 $langs->loadLangs(array(
"agenda",
"other",
"interventions"));
399 if (empty($object->actionmsg2)) {
400 $object->actionmsg2 = $langs->transnoentities(
"InterventionClassifiedBilledInDolibarr", $object->ref);
402 $object->actionmsg = $langs->transnoentities(
"InterventionClassifiedBilledInDolibarr", $object->ref);
404 $object->sendtoid = 0;
405 } elseif ($action ==
'FICHINTER_CLASSIFY_UNBILLED') {
407 $langs->loadLangs(array(
"agenda",
"other",
"interventions"));
409 if (empty($object->actionmsg2)) {
410 $object->actionmsg2 = $langs->transnoentities(
"InterventionClassifiedUnbilledInDolibarr", $object->ref);
412 $object->actionmsg = $langs->transnoentities(
"InterventionClassifiedUnbilledInDolibarr", $object->ref);
414 $object->sendtoid = 0;
415 } elseif ($action ==
'FICHINTER_DELETE') {
417 $langs->loadLangs(array(
"agenda",
"other",
"interventions"));
419 if (empty($object->actionmsg2)) {
420 $object->actionmsg2 = $langs->transnoentities(
"InterventionDeletedInDolibarr", $object->ref);
422 $object->actionmsg = $langs->transnoentities(
"InterventionDeletedInDolibarr", $object->ref);
424 $object->sendtoid = 0;
425 $object->fk_element = 0;
426 $object->elementtype =
'';
427 } elseif ($action ==
'SHIPPING_VALIDATE') {
429 $langs->loadLangs(array(
"agenda",
"other",
"sendings"));
431 if (empty($object->actionmsg2)) {
432 $object->actionmsg2 = $langs->transnoentities(
"ShippingValidated", ($object->newref ? $object->newref : $object->ref));
434 if (empty($object->actionmsg)) {
435 $object->actionmsg = $langs->transnoentities(
"ShippingValidated", ($object->newref ? $object->newref : $object->ref));
440 } elseif ($action ==
'SHIPPING_SENTBYMAIL') {
442 $langs->loadLangs(array(
"agenda",
"other",
"sendings"));
444 if (empty($object->actionmsg2)) {
445 $object->actionmsg2 = $langs->transnoentities(
"ShippingSentByEMail", $object->ref);
447 if (empty($object->actionmsg)) {
448 $object->actionmsg = $langs->transnoentities(
"ShippingSentByEMail", $object->ref);
453 } elseif ($action ==
'RECEPTION_VALIDATE') {
454 $langs->load(
"agenda");
455 $langs->load(
"other");
456 $langs->load(
"receptions");
458 if (empty($object->actionmsg2)) {
459 $object->actionmsg2 = $langs->transnoentities(
"ReceptionValidated", ($object->newref ? $object->newref : $object->ref));
461 if (empty($object->actionmsg)) {
462 $object->actionmsg = $langs->transnoentities(
"ReceptionValidated", ($object->newref ? $object->newref : $object->ref));
467 } elseif ($action ==
'RECEPTION_SENTBYMAIL') {
468 $langs->load(
"agenda");
469 $langs->load(
"other");
470 $langs->load(
"receptions");
472 if (empty($object->actionmsg2)) {
473 $object->actionmsg2 = $langs->transnoentities(
"ReceptionSentByEMail", $object->ref);
475 if (empty($object->actionmsg)) {
476 $object->actionmsg = $langs->transnoentities(
"ReceptionSentByEMail", $object->ref);
481 } elseif ($action ==
'PROPOSAL_SUPPLIER_VALIDATE') {
483 $langs->loadLangs(array(
"agenda",
"other",
"propal"));
485 if (empty($object->actionmsg2)) {
486 $object->actionmsg2 = $langs->transnoentities(
"PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
488 $object->actionmsg = $langs->transnoentities(
"PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
490 $object->sendtoid = 0;
491 } elseif ($action ==
'PROPOSAL_SUPPLIER_SENTBYMAIL') {
493 $langs->loadLangs(array(
"agenda",
"other",
"propal"));
495 if (empty($object->actionmsg2)) {
496 $object->actionmsg2 = $langs->transnoentities(
"ProposalSentByEMail", $object->ref);
498 if (empty($object->actionmsg)) {
499 $object->actionmsg = $langs->transnoentities(
"ProposalSentByEMail", $object->ref);
504 } elseif ($action ==
'PROPOSAL_SUPPLIER_CLOSE_SIGNED') {
506 $langs->loadLangs(array(
"agenda",
"other",
"propal"));
508 if (empty($object->actionmsg2)) {
509 $object->actionmsg2 = $langs->transnoentities(
"PropalClosedSignedInDolibarr", $object->ref);
511 $object->actionmsg = $langs->transnoentities(
"PropalClosedSignedInDolibarr", $object->ref);
513 $object->sendtoid = 0;
514 } elseif ($action ==
'PROPOSAL_SUPPLIER_CLOSE_REFUSED') {
516 $langs->loadLangs(array(
"agenda",
"other",
"propal"));
518 if (empty($object->actionmsg2)) {
519 $object->actionmsg2 = $langs->transnoentities(
"PropalClosedRefusedInDolibarr", $object->ref);
521 $object->actionmsg = $langs->transnoentities(
"PropalClosedRefusedInDolibarr", $object->ref);
523 $object->sendtoid = 0;
524 } elseif ($action ==
'ORDER_SUPPLIER_CREATE') {
526 $langs->loadLangs(array(
"agenda",
"other",
"orders"));
528 if (empty($object->actionmsg2)) {
529 $object->actionmsg2 = $langs->transnoentities(
"OrderCreatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
531 $object->actionmsg = $langs->transnoentities(
"OrderCreatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
533 $object->sendtoid = 0;
534 } elseif ($action ==
'ORDER_SUPPLIER_VALIDATE') {
536 $langs->loadLangs(array(
"agenda",
"other",
"orders"));
538 if (empty($object->actionmsg2)) {
539 $object->actionmsg2 = $langs->transnoentities(
"OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
541 $object->actionmsg = $langs->transnoentities(
"OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
543 $object->sendtoid = 0;
544 } elseif ($action ==
'ORDER_SUPPLIER_APPROVE') {
546 $langs->loadLangs(array(
"agenda",
"other",
"orders"));
548 if (empty($object->actionmsg2)) {
549 $object->actionmsg2 = $langs->transnoentities(
"OrderApprovedInDolibarr", $object->ref);
551 $object->actionmsg = $langs->transnoentities(
"OrderApprovedInDolibarr", $object->ref);
553 $object->sendtoid = 0;
554 } elseif ($action ==
'ORDER_SUPPLIER_REFUSE') {
556 $langs->loadLangs(array(
"agenda",
"other",
"orders",
"main"));
558 if (empty($object->actionmsg2)) {
559 $object->actionmsg2 = $langs->transnoentities(
"OrderRefusedInDolibarr", $object->ref);
561 $object->actionmsg = $langs->transnoentities(
"OrderRefusedInDolibarr", $object->ref);
563 if (!empty($object->refuse_note)) {
564 $object->actionmsg .=
'<br>';
565 $object->actionmsg .= $langs->trans(
"Reason") .
': '.$object->refuse_note;
568 $object->sendtoid = 0;
569 } elseif ($action ==
'ORDER_SUPPLIER_CANCEL') {
571 $langs->loadLangs(array(
"agenda",
"other",
"orders",
"main"));
573 if (empty($object->actionmsg2)) {
574 $object->actionmsg2 = $langs->transnoentities(
"OrderCanceledInDolibarr", $object->ref);
576 $object->actionmsg = $langs->transnoentities(
"OrderCanceledInDolibarr", $object->ref);
578 if (!empty($object->cancel_note)) {
579 $object->actionmsg .=
'<br>';
580 $object->actionmsg .= $langs->trans(
"Reason") .
': '.$object->cancel_note;
583 $object->sendtoid = 0;
584 } elseif ($action ==
'ORDER_SUPPLIER_SUBMIT') {
586 $langs->loadLangs(array(
"agenda",
"other",
"orders"));
588 if (empty($object->actionmsg2)) {
589 $object->actionmsg2 = $langs->transnoentities(
"SupplierOrderSubmitedInDolibarr", ($object->newref ? $object->newref : $object->ref));
591 $object->actionmsg = $langs->transnoentities(
"SupplierOrderSubmitedInDolibarr", ($object->newref ? $object->newref : $object->ref));
593 if (!empty($object->context[
'comments'])) {
594 $object->actionmsg .=
'<br>';
595 $object->actionmsg .= $langs->trans(
"Comment") .
': '.$object->context[
'comments'];
598 $object->sendtoid = 0;
599 } elseif ($action ==
'ORDER_SUPPLIER_RECEIVE') {
601 $langs->loadLangs(array(
"agenda",
"other",
"orders"));
603 if (empty($object->actionmsg2)) {
604 $object->actionmsg2 = $langs->transnoentities(
"SupplierOrderReceivedInDolibarr", ($object->newref ? $object->newref : $object->ref));
606 $object->actionmsg = $langs->transnoentities(
"SupplierOrderReceivedInDolibarr", ($object->newref ? $object->newref : $object->ref));
608 $object->sendtoid = 0;
609 } elseif ($action ==
'ORDER_SUPPLIER_SENTBYMAIL') {
611 $langs->loadLangs(array(
"agenda",
"other",
"bills",
"orders"));
613 if (empty($object->actionmsg2)) {
614 $object->actionmsg2 = $langs->transnoentities(
"SupplierOrderSentByEMail", $object->ref);
616 if (empty($object->actionmsg)) {
617 $object->actionmsg = $langs->transnoentities(
"SupplierOrderSentByEMail", $object->ref);
622 } elseif ($action ==
'ORDER_SUPPLIER_CLASSIFY_BILLED') {
624 $langs->loadLangs(array(
"agenda",
"other",
"bills",
"orders"));
626 if (empty($object->actionmsg2)) {
627 $object->actionmsg2 = $langs->transnoentities(
"SupplierOrderClassifiedBilled", $object->ref);
629 if (empty($object->actionmsg)) {
630 $object->actionmsg = $langs->transnoentities(
"SupplierOrderClassifiedBilled", $object->ref);
633 $object->sendtoid = 0;
634 } elseif ($action ==
'BILL_SUPPLIER_VALIDATE') {
636 $langs->loadLangs(array(
"agenda",
"other",
"bills"));
638 if (empty($object->actionmsg2)) {
639 $object->actionmsg2 = $langs->transnoentities(
"InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
641 $object->actionmsg = $langs->transnoentities(
"InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
643 $object->sendtoid = 0;
644 } elseif ($action ==
'BILL_SUPPLIER_UNVALIDATE') {
646 $langs->loadLangs(array(
"agenda",
"other",
"bills"));
648 if (empty($object->actionmsg2)) {
649 $object->actionmsg2 = $langs->transnoentities(
"InvoiceBackToDraftInDolibarr", $object->ref);
651 $object->actionmsg = $langs->transnoentities(
"InvoiceBackToDraftInDolibarr", $object->ref);
653 $object->sendtoid = 0;
654 } elseif ($action ==
'BILL_SUPPLIER_SENTBYMAIL') {
656 $langs->loadLangs(array(
"agenda",
"other",
"bills",
"orders"));
658 if (empty($object->actionmsg2)) {
659 $object->actionmsg2 = $langs->transnoentities(
"SupplierInvoiceSentByEMail", $object->ref);
661 if (empty($object->actionmsg)) {
662 $object->actionmsg = $langs->transnoentities(
"SupplierInvoiceSentByEMail", $object->ref);
667 } elseif ($action ==
'BILL_SUPPLIER_PAYED') {
669 $langs->loadLangs(array(
"agenda",
"other",
"bills"));
671 if (empty($object->actionmsg2)) {
672 $object->actionmsg2 = $langs->transnoentities(
"InvoicePaidInDolibarr", $object->ref);
674 $object->actionmsg = $langs->transnoentities(
"InvoicePaidInDolibarr", $object->ref);
676 $object->sendtoid = 0;
677 } elseif ($action ==
'BILL_SUPPLIER_CANCELED') {
679 $langs->loadLangs(array(
"agenda",
"other",
"bills"));
681 if (empty($object->actionmsg2)) {
682 $object->actionmsg2 = $langs->transnoentities(
"InvoiceCanceledInDolibarr", $object->ref);
684 $object->actionmsg = $langs->transnoentities(
"InvoiceCanceledInDolibarr", $object->ref);
686 $object->sendtoid = 0;
687 } elseif ($action ==
'MEMBER_VALIDATE') {
690 $langs->loadLangs(array(
"agenda",
"other",
"members"));
692 if (empty($object->actionmsg2)) {
693 $object->actionmsg2 = $langs->transnoentities(
"MemberValidatedInDolibarr", $object->getFullName($langs));
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;
699 $object->sendtoid = 0;
700 } elseif ($action ==
'MEMBER_MODIFY') {
702 $langs->loadLangs(array(
"agenda",
"other",
"members"));
704 if (empty($object->actionmsg2)) {
705 $object->actionmsg2 = $langs->transnoentities(
"MemberModifiedInDolibarr", $object->getFullName($langs));
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;
711 $object->sendtoid = 0;
712 } elseif ($action ==
'MEMBER_SUBSCRIPTION_CREATE') {
714 $langs->loadLangs(array(
"agenda",
"other",
"members"));
716 $member = $this->context[
'member'];
717 if (!is_object($member)) {
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';
721 $member->fetch($object->fk_adherent);
724 if (empty($object->actionmsg2)) {
725 $object->actionmsg2 = $langs->transnoentities(
"MemberSubscriptionAddedInDolibarr", $object->id, $member->getFullName($langs));
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');
733 $object->sendtoid = 0;
734 if ($object->fk_soc > 0) {
735 $object->socid = $object->fk_soc;
737 } elseif ($action ==
'MEMBER_SUBSCRIPTION_MODIFY') {
739 $langs->loadLangs(array(
"agenda",
"other",
"members"));
741 $member = $this->context[
'member'];
742 if (!is_object($member)) {
743 include_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
745 $member->fetch($this->fk_adherent);
748 if (empty($object->actionmsg2)) {
749 $object->actionmsg2 = $langs->transnoentities(
"MemberSubscriptionModifiedInDolibarr", $object->id, $member->getFullName($langs));
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');
757 $object->sendtoid = 0;
758 if ($object->fk_soc > 0) {
759 $object->socid = $object->fk_soc;
761 } elseif ($action ==
'MEMBER_SUBSCRIPTION_DELETE') {
763 $langs->loadLangs(array(
"agenda",
"other",
"members"));
765 $member = $this->context[
'member'];
766 if (!is_object($member)) {
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';
770 $member->fetch($object->fk_adherent);
773 if (empty($object->actionmsg2)) {
774 $object->actionmsg2 = $langs->transnoentities(
"MemberSubscriptionDeletedInDolibarr", $object->ref, $member->getFullName($langs));
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');
782 $object->sendtoid = 0;
783 if ($object->fk_soc > 0) {
784 $object->socid = $object->fk_soc;
786 } elseif ($action ==
'MEMBER_RESILIATE') {
788 $langs->loadLangs(array(
"agenda",
"other",
"members"));
790 if (empty($object->actionmsg2)) {
791 $object->actionmsg2 = $langs->transnoentities(
"MemberResiliatedInDolibarr", $object->getFullName($langs));
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;
797 $object->sendtoid = 0;
798 } elseif ($action ==
'MEMBER_DELETE') {
800 $langs->loadLangs(array(
"agenda",
"other",
"members"));
802 if (empty($object->actionmsg2)) {
803 $object->actionmsg2 = $langs->transnoentities(
"MemberDeletedInDolibarr", $object->getFullName($langs));
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;
809 $object->sendtoid = 0;
810 } elseif ($action ==
'PROJECT_CREATE') {
813 $langs->loadLangs(array(
"agenda",
"other",
"projects"));
815 if (empty($object->actionmsg2)) {
816 $object->actionmsg2 = $langs->transnoentities(
"ProjectCreatedInDolibarr", $object->ref);
818 $object->actionmsg = $langs->transnoentities(
"ProjectCreatedInDolibarr", $object->ref);
819 $object->actionmsg .=
"\n".$langs->transnoentities(
"Project").
': '.$object->ref;
821 $object->sendtoid = 0;
822 } elseif ($action ==
'PROJECT_VALIDATE') {
824 $langs->loadLangs(array(
"agenda",
"other",
"projects"));
826 if (empty($object->actionmsg2)) {
827 $object->actionmsg2 = $langs->transnoentities(
"ProjectValidatedInDolibarr", $object->ref);
829 $object->actionmsg = $langs->transnoentities(
"ProjectValidatedInDolibarr", $object->ref);
830 $object->actionmsg .=
"\n".$langs->transnoentities(
"Project").
': '.$object->ref;
832 $object->sendtoid = 0;
833 } elseif ($action ==
'PROJECT_MODIFY') {
835 $langs->loadLangs(array(
"agenda",
"other",
"projects"));
837 if (empty($object->actionmsg2)) {
838 $object->actionmsg2 = $langs->transnoentities(
"ProjectModifiedInDolibarr", $object->ref);
840 $object->actionmsg = $langs->transnoentities(
"ProjectModifiedInDolibarr", $object->ref);
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;
846 $object->sendtoid = 0;
847 } elseif ($action ==
'TASK_CREATE') {
850 $langs->loadLangs(array(
"agenda",
"other",
"projects"));
852 if (empty($object->actionmsg2)) {
853 $object->actionmsg2 = $langs->transnoentities(
"TaskCreatedInDolibarr", $object->ref);
855 $object->actionmsg = $langs->transnoentities(
"TaskCreatedInDolibarr", $object->ref);
856 $object->actionmsg .=
"\n".$langs->transnoentities(
"Task").
': '.$object->ref;
858 $object->sendtoid = 0;
859 } elseif ($action ==
'TASK_MODIFY') {
861 $langs->loadLangs(array(
"agenda",
"other",
"projects"));
863 if (empty($object->actionmsg2)) {
864 $object->actionmsg2 = $langs->transnoentities(
"TaskModifiedInDolibarr", $object->ref);
866 $object->actionmsg = $langs->transnoentities(
"TaskModifieddInDolibarr", $object->ref);
867 $object->actionmsg .=
"\n".$langs->transnoentities(
"Task").
': '.$object->ref;
869 $object->sendtoid = 0;
870 } elseif ($action ==
'TASK_DELETE') {
872 $langs->loadLangs(array(
"agenda",
"other",
"projects"));
874 if (empty($object->actionmsg2)) {
875 $object->actionmsg2 = $langs->transnoentities(
"TaskDeletedInDolibarr", $object->ref);
877 $object->actionmsg = $langs->transnoentities(
"TaskDeletedInDolibarr", $object->ref);
878 $object->actionmsg .=
"\n".$langs->transnoentities(
"Task").
': '.$object->ref;
880 $object->sendtoid = 0;
881 } elseif ($action ==
'TICKET_ASSIGNED') {
883 $langs->loadLangs(array(
"agenda",
"other",
"projects"));
885 if (empty($object->actionmsg2)) {
886 $object->actionmsg2 = $langs->transnoentities(
"TICKET_ASSIGNEDInDolibarr", $object->ref);
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);
894 $object->actionmsg .=
"\n".$langs->transnoentities(
"OldUser").
': '.$langs->trans(
"None");
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);
901 $object->actionmsg .=
"\n".$langs->transnoentities(
"NewUser").
': '.$langs->trans(
"None");
903 $object->sendtoid = 0;
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") {
914 $object->actionmsg2 = $langs->transnoentities($action.
"InDolibarr", (empty($object->newref) ? $object->ref : $object->newref));
916 $tmp = explode(
'_', $action);
917 $object->actionmsg2 = $langs->transnoentities($tmp[count($tmp) - 1].
"InDolibarr", (empty($object->newref) ? $object->ref : $object->newref));
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") {
923 $object->actionmsg = $langs->transnoentities($action.
"InDolibarr", (empty($object->newref) ? $object->ref : $object->newref));
925 $tmp = explode(
'_', $action);
926 $object->actionmsg = $langs->transnoentities($tmp[count($tmp) - 1].
"InDolibarr", (empty($object->newref) ? $object->ref : $object->newref));
930 if (!isset($object->sendtoid) || !is_array($object->sendtoid)) {
931 $object->sendtoid = 0;
937 if (empty($object->trackid)) {
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;
976 $object->trackid =
'';
988 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
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);
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);
1005 if (is_array($object->sendtoid)) {
1006 if (count($object->sendtoid) == 1) {
1007 $contactforaction->fetch(reset($object->sendtoid));
1010 if ($object->sendtoid > 0) {
1011 $contactforaction->fetch($object->sendtoid);
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;
1023 $projectid = isset($object->fk_project) ? $object->fk_project : 0;
1024 if ($object->element ==
'project') {
1025 $projectid = $object->id;
1028 $elementid = $object->id;
1029 $elementtype = $object->element;
1030 $elementmodule = (empty($object->module) ?
'' : $object->module);
1031 if ($object->element ==
'subscription') {
1032 $elementid = $object->fk_adherent;
1033 $elementtype =
'member';
1038 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
1040 $actioncomm->type_code = $object->actiontypecode;
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;
1049 $actioncomm->socid = $societeforaction->id;
1050 $actioncomm->contact_id = $contactforaction->id;
1051 $actioncomm->authorid = $user->id;
1052 $actioncomm->userownerid = $user->id;
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;
1067 if (!in_array($elementtype, array(
'societe',
'contact',
'project'))) {
1068 $actioncomm->fk_element = $elementid;
1069 $actioncomm->elementtype = $elementtype.($elementmodule ?
'@'.$elementmodule :
'');
1072 if (property_exists($object,
'attachedfiles') && is_array($object->attachedfiles) && count($object->attachedfiles) > 0) {
1073 $actioncomm->attachedfiles = $object->attachedfiles;
1075 if (property_exists($object,
'sendtouserid') && is_array($object->sendtouserid) && count($object->sendtouserid) > 0) {
1076 $actioncomm->userassigned = $object->sendtouserid;
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;
1084 $ret = $actioncomm->create($user);
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];
1093 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1100 unset($object->actionmsg);
1101 unset($object->actionmsg2);
1102 unset($object->actiontypecode);
1105 $_SESSION[
'LAST_ACTION_CREATED'] = $ret;
1108 $this->error =
"Failed to insert event : ".$actioncomm->error.
" ".join(
',', $actioncomm->errors);
1109 $this->errors = $actioncomm->errors;
1111 dol_syslog(
"interface_modAgenda_ActionsAuto.class.php: ".$this->error, LOG_ERR);