24 require_once DOL_DOCUMENT_ROOT.
'/core/triggers/dolibarrtriggers.class.php';
41 $this->
name = preg_replace(
'/^Interface/i',
'', get_class($this));
42 $this->family =
"technic";
45 $this->version = self::VERSION_DEVELOPMENT;
46 $this->picto =
'zapier';
63 if (empty($conf->zapier) || empty($conf->zapier->enabled)) {
68 $logtriggeraction =
false;
71 $actions = explode(
'_', $action);
72 $sql =
'SELECT rowid, url FROM '.MAIN_DB_PREFIX.
'zapier_hook';
73 $sql .=
' WHERE module="'.$this->db->escape(strtolower($actions[0])).
'" AND action="'.$this->
db->escape(strtolower($actions[1])).
'"';
84 $json = json_encode($cleaned);
88 $logtriggeraction =
true;
95 $json = json_encode($cleaned);
99 $logtriggeraction =
true;
109 case 'ACTION_MODIFY':
112 case 'ACTION_CREATE':
118 $json = json_encode($cleaned);
123 $logtriggeraction =
true;
125 case 'ACTION_DELETE':
141 case 'COMPANY_CREATE':
145 $json = json_encode($cleaned);
149 $logtriggeraction =
true;
151 case 'COMPANY_MODIFY':
155 $json = json_encode($cleaned);
159 $logtriggeraction =
true;
161 case 'COMPANY_DELETE':
166 case 'CONTACT_CREATE':
170 $json = json_encode($cleaned);
174 $logtriggeraction =
true;
176 case 'CONTACT_MODIFY':
180 $json = json_encode($cleaned);
184 $logtriggeraction =
true;
186 case 'CONTACT_DELETE':
188 case 'CONTACT_ENABLEDISABLE':
211 $json = json_encode($cleaned);
215 $logtriggeraction =
true;
219 case 'ORDER_VALIDATE':
223 case 'ORDER_SENTBYMAIL':
224 case 'ORDER_CLASSIFY_BILLED':
225 case 'ORDER_SETDRAFT':
226 case 'LINEORDER_INSERT':
227 case 'LINEORDER_UPDATE':
228 case 'LINEORDER_DELETE':
332 case 'MEMBER_CREATE':
336 $json = json_encode($cleaned);
340 $logtriggeraction =
true;
342 case 'MEMBER_MODIFY':
346 $json = json_encode($cleaned);
350 $logtriggeraction =
true;
372 case 'TICKET_CREATE':
377 $json = json_encode($cleaned);
381 $logtriggeraction =
true;
398 if ($logtriggeraction) {
399 dol_syslog(
"Trigger '".$this->
name.
"' for action '.$action.' launched by ".__FILE__.
" id=".$object->id);
413 $headers = array(
'Accept: application/json',
'Content-Type: application/json');
416 curl_setopt($ch, CURLOPT_URL, $url);
417 curl_setopt($ch, CURLOPT_RETURNTRANSFER,
true);
418 curl_setopt($ch, CURLOPT_TIMEOUT, 10);
419 curl_setopt($ch, CURLOPT_CUSTOMREQUEST,
'POST');
420 curl_setopt($ch, CURLOPT_POST, 1);
421 curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
422 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
423 $output = curl_exec($ch);
439 unset($toclean->linkedObjects);
441 unset($toclean->lines);
443 unset($toclean->fields);
445 unset($toclean->oldline);
447 unset($toclean->error);
448 unset($toclean->errors);
450 unset($toclean->ref_previous);
451 unset($toclean->ref_next);
452 unset($toclean->ref_int);
454 unset($toclean->projet);
455 unset($toclean->project);
456 unset($toclean->author);
457 unset($toclean->timespent_old_duration);
458 unset($toclean->timespent_id);
459 unset($toclean->timespent_duration);
460 unset($toclean->timespent_date);
461 unset($toclean->timespent_datehour);
462 unset($toclean->timespent_withhour);
463 unset($toclean->timespent_fk_user);
464 unset($toclean->timespent_note);
466 unset($toclean->statuts);
467 unset($toclean->statuts_short);
468 unset($toclean->statuts_logo);
469 unset($toclean->statuts_long);
471 unset($toclean->element);
472 unset($toclean->fk_element);
473 unset($toclean->table_element);
474 unset($toclean->table_element_line);
475 unset($toclean->picto);
477 unset($toclean->skip_update_total);
478 unset($toclean->context);
489 unset($toclean->oldcopy);
492 if (isset($toclean->lines) && count($toclean->lines) > 0) {
493 $nboflines = count($toclean->lines);
494 for ($i = 0; $i < $nboflines; $i++) {
520 unset($toclean->usermod);
521 unset($toclean->libelle);
523 unset($toclean->context);
524 unset($toclean->canvas);
525 unset($toclean->contact);
526 unset($toclean->contact_id);
527 unset($toclean->thirdparty);
528 unset($toclean->user);
529 unset($toclean->origin);
530 unset($toclean->origin_id);
531 unset($toclean->ref_ext);
532 unset($toclean->statut);
533 unset($toclean->country);
534 unset($toclean->country_id);
535 unset($toclean->country_code);
536 unset($toclean->barcode_type);
537 unset($toclean->barcode_type_code);
538 unset($toclean->barcode_type_label);
539 unset($toclean->barcode_type_coder);
540 unset($toclean->mode_reglement_id);
541 unset($toclean->cond_reglement_id);
542 unset($toclean->cond_reglement);
543 unset($toclean->fk_delivery_address);
544 unset($toclean->shipping_method_id);
545 unset($toclean->fk_account);
546 unset($toclean->total_ht);
547 unset($toclean->total_tva);
548 unset($toclean->total_localtax1);
549 unset($toclean->total_localtax2);
550 unset($toclean->total_ttc);
551 unset($toclean->fk_incoterms);
552 unset($toclean->libelle_incoterms);
553 unset($toclean->location_incoterms);
554 unset($toclean->name);
555 unset($toclean->lastname);
556 unset($toclean->firstname);
557 unset($toclean->civility_id);
558 unset($toclean->contact);
559 unset($toclean->societe);