dolibarr 25.0.0-alpha
webhook.php
1<?php
2/* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../main.inc.php';
28require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
29require_once DOL_DOCUMENT_ROOT.'/webhook/lib/webhook.lib.php';
30
39// Translations
40$langs->loadLangs(array("admin", "webhook"));
41
42// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
43$hookmanager->initHooks(array('webhooksetup', 'globalsetup'));
44
45// Access control
46if (!$user->admin) {
48}
49
50// Parameters
51$action = GETPOST('action', 'aZ09');
52$backtopage = GETPOST('backtopage', 'alpha');
53$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
54
55$value = GETPOST('value', 'alpha');
56$label = GETPOST('label', 'alpha');
57$scandir = GETPOST('scan_dir', 'alpha');
58$type = 'myobject';
59
60
61$error = 0;
62$setupnotempty = 0;
63
64// Set this to 1 to use the factory to manage constants. Warning, the generated module will be compatible with version v15+ only
65$useFormSetup = 1;
66
67if (!class_exists('FormSetup')) {
68 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php';
69}
70
71$formSetup = new FormSetup($db);
72
73// Enable/Disable logging of webhook calls (trace of calls saved into the webhook history table)
74$item = $formSetup->newItem('WEBHOOK_ENABLE_CALL_LOGS');
75$item->setAsYesNo();
76
77$setupnotempty = count($formSetup->items);
78
79
80/*
81 * Actions
82 */
83
84include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
85
86if ($action == 'updateMask') {
87 $maskconst = GETPOST('maskconst', 'aZ09');
88 $maskvalue = GETPOST('maskvalue', 'alpha');
89
90 if ($maskconst && preg_match('/_MASK$/', $maskconst)) {
91 $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
92 if (!($res > 0)) {
93 $error++;
94 }
95 }
96
97 if (!$error) {
98 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
99 } else {
100 setEventMessages($langs->trans("Error"), null, 'errors');
101 }
102} elseif ($action == 'setmod') {
103 // TODO Check if numbering module chosen can be activated by calling method canBeActivated
104 $tmpobjectkey = GETPOST('object', 'aZ09');
105 if (!empty($tmpobjectkey)) {
106 $constforval = 'WEBHOOK_'.strtoupper($tmpobjectkey)."_ADDON";
107 dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
108 }
109} elseif ($action == 'set') {
110 // Activate a model
111 $ret = addDocumentModel($value, $type, $label, $scandir);
112} elseif ($action == 'del') {
113 $ret = delDocumentModel($value, $type);
114 if ($ret > 0) {
115 $tmpobjectkey = GETPOST('object', 'aZ09');
116 if (!empty($tmpobjectkey)) {
117 $constforval = 'WEBHOOK_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
118 if (getDolGlobalString($constforval) == "$value") {
119 dolibarr_del_const($db, $constforval, $conf->entity);
120 }
121 }
122 }
123} elseif ($action == 'setdoc') {
124 // Set or unset default model
125 $tmpobjectkey = GETPOST('object', 'aZ09');
126 if (!empty($tmpobjectkey)) {
127 $constforval = 'WEBHOOK_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
128 if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
129 // The constant that was read before the new set
130 // We therefore requires a variable to have a coherent view
131 $conf->global->$constforval = $value;
132 }
133 }
134} elseif ($action == 'unsetdoc') {
135 $tmpobjectkey = GETPOST('object', 'aZ09');
136 if (!empty($tmpobjectkey)) {
137 $constforval = 'WEBHOOK_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
138 dolibarr_del_const($db, $constforval, $conf->entity);
139 }
140}
141
142
143
144/*
145 * View
146 */
147
148$help_url = '';
149$page_name = "WebhookSetup";
150
151llxHeader('', $langs->trans($page_name), $help_url, '', 0, 0, '', '', '', 'mod-admin page-webhook');
152
153// Subheader
154$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
155
156print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
157
158// Configuration header
160print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "webhook");
161
162// Setup page goes here
163print '<div class="info">'.$langs->trans("WebhookSetupPage", $langs->transnoentitiesnoconv("Targets")).'...</div>';
164
165print '<br>';
166
167if ($action == 'edit') {
168 print $formSetup->generateOutput(true);
169 print '<br>';
170} else {
171 if (!empty($formSetup->items)) {
172 print $formSetup->generateOutput();
173 }
174}
175
176// Page end
177print dol_get_fiche_end();
178
179llxFooter();
180$db->close();
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
delDocumentModel($name, $type)
Delete document model used by doc generator.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
This class help you create setup render.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
webhookAdminPrepareHead()
Prepare admin pages header.