dolibarr 20.0.0
webhook.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
23if (!defined('NOTOKENRENEWAL')) {
24 define('NOTOKENRENEWAL', '1'); // Disables token renewal
25}
26if (!defined('NOREQUIREHTML')) {
27 define('NOREQUIREHTML', '1');
28}
29if (!defined('NOREQUIREAJAX')) {
30 define('NOREQUIREAJAX', '1');
31}
32if (!defined('NOREQUIRESOC')) {
33 define('NOREQUIRESOC', '1');
34}
35// Do not check anti CSRF attack test
36if (!defined('NOREQUIREMENU')) {
37 define('NOREQUIREMENU', '1');
38}
39// If we need access without being logged.
40if (!empty($_GET['public'])) { // Keep $_GET here. GETPOST() is not yet defined so we use $_GET
41 if (!defined("NOLOGIN")) {
42 define("NOLOGIN", '1');
43 }
44}
45if (!defined('NOIPCHECK')) {
46 define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
47}
48if (!defined('NOBROWSERNOTIF')) {
49 define('NOBROWSERNOTIF', '1');
50}
51include '../../main.inc.php';
52require_once DOL_DOCUMENT_ROOT.'/webhook/class/target.class.php';
53
54$action = GETPOST('action', 'aZ09');
55$triggercode = GETPOST('triggercode');
56
57// Security check
58if (empty($user->admin)) {
60}
61
62
63/*
64 * Actions
65 */
66
67// None
68
69
70/*
71 * View
72 */
73
74top_httphead('application/json');
75
76if ($action == "getjsonformtrigger") {
77 $response = '';
78 $objnotfound = 0;
79
80 $json = new stdClass();
81
82 if (!empty($triggercode)) {
83 // Clean triggercode to removes keep only Object trigger name
84 $objecttriggername = array();
85 preg_match('#\‍((.*?)\‍)#', $triggercode, $objecttriggername);
86
87 $json->triggercode = empty($objecttriggername[1]) ? $triggercode : $objecttriggername[1];
88
89 if (!empty($objecttriggername[1])) {
90 $objtype = explode("_", $objecttriggername[1])[0];
91 $obj = findobjecttosend($objtype);
92 if (is_object($obj)) {
93 //TODO: Case if obj is an object
94 } else {
95 $objnotfound ++;
96 }
97 } else {
98 $objnotfound ++;
99 }
100
101 if ($objnotfound) {
102 $json->object = new stdClass();
103 //$json->object->initAsSpecimen();
104 $json->object->field1 = 'field1';
105 $json->object->field2 = 'field2';
106 $json->object->field3 = 'field3';
107 }
108 }
109
110 $response = json_encode($json);
111 echo $response;
112}
113
120function findobjecttosend($objecttype)
121{
122 // TODO: Find right object from objecttype and initAsSpecimen
123
124 // You can use fetchObjectByElement()
125
126 return false;
127}
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
if( $action=="getjsonformtrigger") findobjecttosend($objecttype)
Find and init a specimen for the given object type.
Definition webhook.php:120