dolibarr 22.0.5
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$setupnotempty = count($formSetup->items);
74
75
76/*
77 * Actions
78 */
79
80include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
81
82if ($action == 'updateMask') {
83 $maskconst = GETPOST('maskconst', 'aZ09');
84 $maskvalue = GETPOST('maskvalue', 'alpha');
85
86 if ($maskconst && preg_match('/_MASK$/', $maskconst)) {
87 $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
88 if (!($res > 0)) {
89 $error++;
90 }
91 }
92
93 if (!$error) {
94 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
95 } else {
96 setEventMessages($langs->trans("Error"), null, 'errors');
97 }
98} elseif ($action == 'setmod') {
99 // TODO Check if numbering module chosen can be activated by calling method canBeActivated
100 $tmpobjectkey = GETPOST('object', 'aZ09');
101 if (!empty($tmpobjectkey)) {
102 $constforval = 'WEBHOOK_'.strtoupper($tmpobjectkey)."_ADDON";
103 dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
104 }
105} elseif ($action == 'set') {
106 // Activate a model
107 $ret = addDocumentModel($value, $type, $label, $scandir);
108} elseif ($action == 'del') {
109 $ret = delDocumentModel($value, $type);
110 if ($ret > 0) {
111 $tmpobjectkey = GETPOST('object', 'aZ09');
112 if (!empty($tmpobjectkey)) {
113 $constforval = 'WEBHOOK_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
114 if (getDolGlobalString($constforval) == "$value") {
115 dolibarr_del_const($db, $constforval, $conf->entity);
116 }
117 }
118 }
119} elseif ($action == 'setdoc') {
120 // Set or unset default model
121 $tmpobjectkey = GETPOST('object', 'aZ09');
122 if (!empty($tmpobjectkey)) {
123 $constforval = 'WEBHOOK_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
124 if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
125 // The constant that was read before the new set
126 // We therefore requires a variable to have a coherent view
127 $conf->global->$constforval = $value;
128 }
129
130 // We disable/enable the document template (into llx_document_model table)
131 $ret = delDocumentModel($value, $type);
132 if ($ret > 0) {
133 $ret = addDocumentModel($value, $type, $label, $scandir);
134 }
135 }
136} elseif ($action == 'unsetdoc') {
137 $tmpobjectkey = GETPOST('object', 'aZ09');
138 if (!empty($tmpobjectkey)) {
139 $constforval = 'WEBHOOK_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
140 dolibarr_del_const($db, $constforval, $conf->entity);
141 }
142}
143
144
145
146/*
147 * View
148 */
149
150$help_url = '';
151$page_name = "WebhookSetup";
152
153llxHeader('', $langs->trans($page_name), $help_url, '', 0, 0, '', '', '', 'mod-admin page-webhook');
154
155// Subheader
156$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
157
158print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
159
160// Configuration header
162print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "webhook");
163
164print '<br>';
165
166// Setup page goes here
167print '<span class="opacitymedium">'.$langs->trans("WebhookSetupPage", $langs->transnoentitiesnoconv("Targets")).'...</span><br><br>';
168
169
170if ($action == 'edit') {
171 print $formSetup->generateOutput(true);
172 print '<br>';
173} else {
174 if (!empty($formSetup->items)) {
175 print $formSetup->generateOutput();
176 }
177}
178
179// Page end
180print dol_get_fiche_end();
181
182llxFooter();
183$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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.