dolibarr 24.0.0-beta
target_card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
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';
37require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
39require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
40require_once DOL_DOCUMENT_ROOT.'/webhook/class/target.class.php';
41require_once DOL_DOCUMENT_ROOT.'/webhook/lib/webhook_target.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
43
44// Load translation files required by the page
45$langs->loadLangs(array('other','admin'));
46
47// Get parameters
48$id = GETPOSTINT('id');
49$ref = GETPOST('ref', 'alpha');
50$action = GETPOST('action', 'aZ09');
51$confirm = GETPOST('confirm', 'alpha');
52$cancel = GETPOST('cancel');
53$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'targetcard'; // To manage different context of search
54$backtopage = GETPOST('backtopage', 'alpha');
55$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
56$lineid = GETPOSTINT('lineid');
57
58// Initialize a technical objects
59$object = new Target($db);
60$diroutputmassaction = $conf->webhook->dir_output.'/temp/massgeneration/'.$user->id;
61$hookmanager->initHooks(array('targetcard', 'globalcard')); // Note that conf->hooks_modules contains array
62
63// Fetch optionals attributes and labels
64$extrafields->fetch_name_optionals_label($object->table_element);
65
66$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
67
68// Initialize array of search criteria
69$search_all = GETPOST("search_all", 'alpha');
70$search = array();
71foreach ($object->fields as $key => $val) {
72 if (GETPOST('search_'.$key, 'alpha')) {
73 $search[$key] = GETPOST('search_'.$key, 'alpha');
74 }
75}
76
77if (empty($action) && empty($id) && empty($ref)) {
78 $action = 'view';
79}
80
81// Load object
82include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'.
83
84// Permissions
85// There is several ways to check permission.
86// Set $enablepermissioncheck to 1 to enable a minimum low level of checks
87$permissiontoread = $permissiontoadd = $permissiontodelete = $permissionnote = $permissiondellink = (!empty($user->admin) ? 1 : 0);
88
89$upload_dir = $conf->webhook->multidir_output[isset($object->entity) ? $object->entity : 1].'/target';
90
91// Security check (enable the most restrictive one)
92//if ($user->socid > 0) accessforbidden();
93//if ($user->socid > 0) $socid = $user->socid;
94//$isdraft = (isset($object->status) && ($object->status == $object::STATUS_DRAFT) ? 1 : 0);
95//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
96if (!isModEnabled('webhook')) {
98}
99if (!$permissiontoread) {
101}
102
103
104/*
105 * Actions
106 */
107
108$parameters = array();
109$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
110if ($reshook < 0) {
111 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
112}
113
114if (empty($reshook)) {
115 $error = 0;
116
117 $backurlforlist = dolBuildUrl('/webhook/target_list.php', ['mode' => 'modulesetup']);
118
119 if (empty($backtopage) || ($cancel && empty($id))) {
120 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
121 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
122 $backtopage = $backurlforlist;
123 } else {
124 $backtopage = dolBuildUrl('/webhook/target_card.php', ['id' => ((!empty($id) && $id > 0) ? $id : '__ID__')]);
125 }
126 }
127 }
128
129 $triggermodname = 'WEBHOOK_TARGET_MODIFY'; // Name of trigger action code to execute when we modify record
130
131 // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
132 include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
133
134 // Actions when linking object each other
135 include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
136
137 // Actions when printing a doc from card
138 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
139
140 // Action to move up and down lines of object
141 //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
142
143 // Action to build doc
144 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
145
146 if ($action == 'set_thirdparty' && $permissiontoadd) {
147 $object->setValueFrom('fk_soc', GETPOSTINT('fk_soc'), '', null, 'date', '', $user, $triggermodname);
148 }
149 if ($action == 'classin' && $permissiontoadd) {
150 $object->setProject(GETPOSTINT('projectid'));
151 }
152 if ($action == 'confirm_statusmanual' && $confirm == "yes" && $permissiontoadd) {
153 $object->setStatusCommon($user, $object::STATUS_MANUAL_TRIGGER, 0, 'TARGET_REOPEN');
154 }
155 if ($action == 'confirm_statusautomatic' && $confirm == "yes" && $permissiontoadd) {
156 $object->setStatusCommon($user, $object::STATUS_AUTOMATIC_TRIGGER, 0, 'TARGET_REOPEN');
157 }
158 if ($action == 'testsendtourl' && $permissiontoadd) {
159 $triggercode = GETPOST("triggercode");
160 $url = GETPOST("url");
161 $jsondata = GETPOST("jsondata", "restricthtml");
162 if (empty($url)) {
163 $error++;
164 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Url")), null, 'errors');
165 }
166 if (empty($jsondata)) {
167 $error++;
168 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DataToSendTrigger")), null, 'errors');
169 }
170
171 $headers = array(
172 'Content-Type: application/json'
173 //'Accept: application/json'
174 );
175
176 $method = 'POSTALREADYFORMATED';
177 if (getDolGlobalString('WEBHOOK_POST_SEND_DATA_AS_PARAM_STRING')) { // For compatibility with v20- versions
178 $method = 'POST';
179 }
180
181 // TODO Replace this by a call of trigger...
182 global $dolibarr_allow_localurl_for_webhooks;
183 $localurl = empty($dolibarr_allow_localurl_for_webhooks) ? 0 : 2;
184 $response = getURLContent($url, $method, $jsondata, 1, $headers, array('http', 'https'), $localurl, -1);
185 if (empty($response['curl_error_no']) && $response['http_code'] >= 200 && $response['http_code'] < 300) {
186 setEventMessages($langs->trans("Success"), null);
187 } else {
188 $errormsg = "The WebHook for triggercode: ".$triggercode." failed to do the GET of URL ".$url." with httpcode=".(!empty($response['http_code']) ? $response['http_code'] : "")." curl_error_no=".(!empty($response['curl_error_no']) ? $response['curl_error_no'] : "");
189 setEventMessages($langs->trans($errormsg), null, 'errors');
190 }
191 }
192
193 // Actions to send emails
194 $triggersendname = 'WEBHOOK_TARGET_SENTBYMAIL';
195 $autocopy = 'MAIN_MAIL_AUTOCOPY_TARGET_TO';
196 $trackid = 'target'.$object->id;
197 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
198}
199
200
201
202
203/*
204 * View
205 */
206
207$form = new Form($db);
208$formfile = new FormFile($db);
209$formproject = new FormProjets($db);
210
211$object->initListOfTriggers();
212
213$arrayofjs = array(
214 '/includes/ace/src/ace.js',
215 '/includes/ace/src/ext-statusbar.js',
216 '/includes/ace/src/ext-language_tools.js',
217 //'/public/includes/ace/src/ext-chromevox.js'
218 //'/public/includes/jquery/plugins/jqueryscoped/jquery.scoped.js',
219);
220$arrayofcss = array();
221
222$title = $langs->trans("Target");
223$help_url = '';
224
225llxHeader('', $title, $help_url, '', 0, 0, $arrayofjs, $arrayofcss, '', 'mod-webhook page-target_card');
226
227// Part to create
228if ($action == 'create') {
229 if (empty($permissiontoadd)) {
230 accessforbidden('NotEnoughPermissions', 0, 1);
231 }
232
233 print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("Target")), '', 'object_'.$object->picto);
234
235 print '<form method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
236 print '<input type="hidden" name="token" value="'.newToken().'">';
237 print '<input type="hidden" name="action" value="add">';
238 if ($backtopage) {
239 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
240 }
241 if ($backtopageforcancel) {
242 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
243 }
244
245 print dol_get_fiche_head(array(), '');
246
247
248 print '<table class="border centpercent tableforfieldcreate">'."\n";
249
250 // Common attributes
251 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
252
253 // Other attributes
254 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
255
256 print '</table>'."\n";
257
258 print dol_get_fiche_end();
259
260 print $form->buttonsSaveCancel("Create");
261
262 print '</form>';
263
264 //dol_set_focus('input[name="ref"]');
265}
266
267// Part to edit record
268if (($id || $ref) && $action == 'edit') {
269 print load_fiche_titre($langs->trans("Target"), '', 'object_'.$object->picto);
270
271 print '<form method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
272 print '<input type="hidden" name="token" value="'.newToken().'">';
273 print '<input type="hidden" name="action" value="update">';
274 print '<input type="hidden" name="id" value="'.$object->id.'">';
275 if ($backtopage) {
276 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
277 }
278 if ($backtopageforcancel) {
279 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
280 }
281
282 print dol_get_fiche_head();
283
284 print '<table class="border centpercent tableforfieldedit">'."\n";
285
286 // Common attributes
287 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
288
289 // Other attributes
290 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
291
292 print '</table>';
293
294 print dol_get_fiche_end();
295
296 print $form->buttonsSaveCancel();
297
298 print '</form>';
299}
300
301// Part to show record
302if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
303 $res = $object->fetch_optionals();
304
305 $head = targetPrepareHead($object);
306 print dol_get_fiche_head($head, 'card', $langs->trans("Target"), -1, $object->picto);
307
308 $formconfirm = '';
309
310 // Confirmation to delete
311 if ($action == 'delete') {
312 $formconfirm = $form->formconfirm(dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $object->id]), $langs->trans('DeleteTarget'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
313 }
314 // Confirmation to delete line
315 if ($action == 'deleteline') {
316 $formconfirm = $form->formconfirm(dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $object->id, 'lineid' => $lineid]), $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
317 }
318
319 // Clone confirmation
320 if ($action == 'clone') {
321 // Create an array for form
322 $formquestion = array();
323 $formconfirm = $form->formconfirm(dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $object->id]), $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
324 }
325
326 // Confirmation of action xxxx (You can use it for xxx = 'close', xxx = 'reopen', ...)
327
328 // Call Hook formConfirm
329 $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
330 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
331 if (empty($reshook)) {
332 $formconfirm .= $hookmanager->resPrint;
333 } elseif ($reshook > 0) {
334 $formconfirm = $hookmanager->resPrint;
335 }
336
337 // Print form confirm
338 print $formconfirm;
339
340
341 // Object card
342 // ------------------------------------------------------------
343 $linkback = '<a href="'.dolBuildUrl(DOL_DOCUMENT_ROOT.'/webhook/target_list.php', ['restore_lastsearch_values' => 1]).'">'.$langs->trans("BackToList").'</a>';
344
345 $morehtmlref = '<div class="refidno">';
346 /*
347 // Ref customer
348 $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
349 $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
350 // Thirdparty
351 $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
352 // Project
353 if (isModEnabled('projet')) {
354 $langs->load("projects");
355 $morehtmlref .= '<br>'.$langs->trans('Project') . ' ';
356 if ($permissiontoadd) {
357 //if ($action != 'classify') $morehtmlref.='<a class="editfielda" href="' . dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true) . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
358 $morehtmlref .= ' : ';
359 if ($action == 'classify') {
360 //$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 0, 1, '', 'maxwidth300');
361 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
362 $morehtmlref .= '<input type="hidden" name="action" value="classin">';
363 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
364 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
365 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
366 $morehtmlref .= '</form>';
367 } else {
368 $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
369 }
370 } else {
371 if (!empty($object->fk_project)) {
372 $proj = new Project($db);
373 $proj->fetch($object->fk_project);
374 $morehtmlref .= ': '.$proj->getNomUrl();
375 } else {
376 $morehtmlref .= '';
377 }
378 }
379 }*/
380 $morehtmlref .= '</div>';
381
382
383 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
384
385
386 print '<div class="fichecenter">';
387 print '<div class="fichehalfleft">';
388 print '<div class="underbanner clearboth"></div>';
389 print '<table class="border centpercent tableforfield">'."\n";
390
391 // Common attributes
392 //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
393 //unset($object->fields['fk_project']); // Hide field already shown in banner
394 //unset($object->fields['fk_soc']); // Hide field already shown in banner
395
396 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
397
398 // Other attributes. Fields from hook formObjectOptions and Extrafields.
399 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
400
401 print '</table>';
402 print '</div>';
403 print '</div>';
404
405 print '<div class="clearboth"></div>';
406
407 print dol_get_fiche_end();
408
409
410 /*
411 * Lines
412 */
413
414 if (!empty($object->table_element_line)) {
415 // Show object lines
416 $result = $object->getLinesArray();
417 $anchor = (($action == 'editline') ? '' : '#line_'.GETPOSTINT('lineid'));
418 print '<form name="addproduct" id="addproduct" action="'.dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $object->id], false, $anchor).'" method="POST">
419 <input type="hidden" name="token" value="' . newToken().'">
420 <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
421 <input type="hidden" name="mode" value="">
422 <input type="hidden" name="page_y" value="">
423 <input type="hidden" name="id" value="' . $object->id.'">
424 ';
425
426 if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
427 include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
428 }
429
430 print '<div class="div-table-responsive-no-min">';
431 if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
432 print '<table id="tablelines" class="noborder noshadow" width="100%">';
433 }
434
435 if (!empty($object->lines)) {
436 $object->printObjectLines($action, $mysoc, null, GETPOSTINT('lineid'), 1);
437 }
438
439 // Form to add new line
440 if ($object->status == 0 && $permissiontoadd && $action != 'selectlines') {
441 if ($action != 'editline') {
442 // Add products/services form
443
444 $parameters = array();
445 $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
446 if ($reshook < 0) {
447 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
448 }
449 if (empty($reshook)) {
450 $object->formAddObjectLine(1, $mysoc, $soc);
451 }
452 }
453 }
454
455 if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
456 print '</table>';
457 }
458 print '</div>';
459
460 print "</form>\n";
461 }
462
463
464 // Buttons for actions
465
466 if ($action != 'presend' && $action != 'editline') {
467 print '<div class="tabsAction">'."\n";
468 $parameters = array();
469 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
470 if ($reshook < 0) {
471 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
472 }
473
474 if (empty($reshook)) {
475 // Send
476 /*if (empty($user->socid)) {
477 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init&token='.newToken().'#formmailbeforetitle');
478 }*/
479
480 print dolGetButtonAction('', $langs->trans('Modify'), 'default', dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $object->id, 'action' => 'edit'], true), '', $permissiontoadd);
481
482 // Clone
483 print dolGetButtonAction($langs->trans('ToClone'), '', 'clone', dolBuildUrl($_SERVER['PHP_SELF'], ['id' => $object->id, 'action' => 'clone'], true), '', $permissiontoadd);
484
485 // Webhook send test
486 print dolGetButtonAction($langs->trans('TestWebhookTarget'), '', 'default', dolBuildUrl($_SERVER['PHP_SELF'], ['id' => $object->id, 'action' => 'test'], true), '', $permissiontoadd);
487 /*
488 if ($permissiontoadd) {
489 if ($object->status == $object::STATUS_ENABLED) {
490 print dolGetButtonAction($langs->trans('Disable'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=disable&token='.newToken(), '', $permissiontoadd);
491 } else {
492 print dolGetButtonAction($langs->trans('Enable'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=enable&token='.newToken(), '', $permissiontoadd);
493 }
494 }
495 if ($permissiontoadd) {
496 if ($object->status == $object::STATUS_VALIDATED) {
497 print dolGetButtonAction($langs->trans('Cancel'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=close&token='.newToken(), '', $permissiontoadd);
498 } else {
499 print dolGetButtonAction($langs->trans('Re-Open'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=reopen&token='.newToken(), '', $permissiontoadd);
500 }
501 }
502 */
503
504 // Enable
505 if ($object->status == $object::STATUS_DRAFT) {
506 $arrayforbutactivate = array();
507 $arrayforbutactivate[] = array(
508 'url' => dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $object->id, 'action' => 'confirm_statusautomatic', 'confirm' => 'yes'], true),
509 'label' => 'AutomaticTrigger',
510 'lang' => 'admin',
511 'perm' => true,
512 'enabled' => true,
513 );
514 $arrayforbutactivate[] = array(
515 'url' => dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $object->id, 'action' => 'confirm_statusmanual', 'confirm' => 'yes'], true),
516 'label' => 'ManualTrigger',
517 'lang' => 'admin',
518 'perm' => true,
519 'enabled' => true,
520 );
521 print dolGetButtonAction('', $langs->trans('Enable'), 'default', $arrayforbutactivate, '', $permissiontoadd);
522 }
523
524 // Disable
525 if (in_array($object->status, array($object::STATUS_AUTOMATIC_TRIGGER, $object::STATUS_MANUAL_TRIGGER))) {
526 print dolGetButtonAction('', $langs->trans('Disable'), 'delete', dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $object->id, 'action' => 'confirm_setdraft', 'confirm' => 'yes'], true), '', $permissiontoadd);
527 }
528
529 // Delete (need delete permission, or if draft, just need create/modify permission)
530 print dolGetButtonAction($langs->trans('Delete'), '', 'delete', dolBuildUrl($_SERVER['PHP_SELF'], ['id' => $object->id, 'action' => 'delete'], true), '', $permissiontodelete);
531 }
532 print '</div>'."\n";
533 }
534}
535
536if ($action == "test") {
537 print '<div id="formtesttarget" name="formtesttarget"></div>';
538 print load_fiche_titre($langs->trans("TestWebhookTarget"));
539 print dol_get_fiche_head(array(), '', '', -1);
540
541 print "\n".'<!-- Begin form test target --><div id="targettestform"></div>'."\n";
542 print '<form method="POST" name="testtargetform" id="testtargetform" enctype="multipart/form-data" action="'.dolBuildUrl($_SERVER['PHP_SELF'], ['id' => $object->id]).'">';
543 print '<input type="hidden" name="token" value="'.newToken().'">';
544 print '<input type="hidden" name="action" value="testsendtourl">';
545
546 print '<table class="tableforemailform boxtablenotop centpercent">';
547
548 print '<tr><td class="titlefieldcreate fieldrequired minwidth200">';
549 print $langs->trans("TriggerCodes");
550 print '</td><td class="valuefieldcreate">';
551 $arraytriggercodes = explode(",", $object->trigger_codes);
552 $idtriggercode = '';
553 if (in_array(GETPOST("triggercodes"), $arraytriggercodes)) {
554 $idtriggercode = array_search(GETPOST("triggercodes"), $arraytriggercodes);
555 }
556 print $form->selectarray("triggercode", $arraytriggercodes, $idtriggercode, 0, 0, 1);
557 print '</td></tr>';
558
559 print '<tr><td class="titlefieldcreate fieldrequired minwidth200">';
560 print $langs->trans("Url");
561 print '</td><td class="valuefieldcreate">';
562 print '<input class="flat minwidth400" name="url" value="'.(GETPOSTISSET("url") ? GETPOST("url") : $object->url).'" />';
563 print '</td></tr>';
564
565 // Json sample to send
566 print '<tr><td class="titlefieldcreate fieldrequired minwidth200">';
567 print $langs->trans("DataToSendTrigger");
568 print '</td><td>';
569
570 $json = new stdClass();
571 $json->triggercode = "TEST_TRIGGER_CODE";
572 $json->object = new stdClass();
573 $json->object->field1 = 'field1';
574 $json->object->field2 = 'field2';
575 $json->object->field3 = 'field3';
576
577 $datatosend = json_encode($json);
578 //$datatosend = preg_replace('/\,/', ",\n", $datatosend);
579
580 /*
581 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
582 $doleditor = new DolEditor("jsondata", $datatosend, 0, 200, 'dolibarr_details', 'In', true, true, 'ace');
583 print $doleditor->Create(0, '', true, '', 'json');
584 */
585 print '<textarea id="jsondata" class="flat minwidth100" style="margin-top: 5px; width: 95%" rows="8" name="jsondata">';
586 print $datatosend;
587 print '</textarea>';
588
589 print '</td></tr>';
590 print '</table>';
591
592 print '<div class="center">';
593 print $form->buttonsSaveCancel("SendToUrl");
594 print '</div>';
595 print '</form>';
596
597 if ($conf->use_javascript_ajax) {
598 print '<script>
599 $("#triggercode").change(function(){
600 console.log("We change trigger code");
601 triggercode = $(this).val();
602 getDatatToSendTriggerCode(triggercode);
603 });
604
605 function getDatatToSendTriggerCode(triggercode){
606 $.ajax({
607 method: \'GET\',
608 url: \''.DOL_URL_ROOT.'/webhook/ajax/webhook.php\',
609 data: { action: "getjsonformtrigger", triggercode: triggercode , token:"'.currentToken().'"},
610 success: function(response) {
611 obj = JSON.stringify(response);
612 $("#jsondata").val(obj);
613 }
614 })
615 };
616
617 $(document).ready(function () {
618 triggercode = $("#triggercode").val();
619 getDatatToSendTriggerCode(triggercode);
620 });
621 ';
622 print '</script>';
623 }
624
625 print "\n".'<!-- END form test target -->';
626}
627
628// End of page
629llxFooter();
630$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage building of HTML components.
Class for Target.
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1, $timeoutconnect=0, $timeoutresponse=0, $otherCurlOptions=array(), $morelogsuffix='')
Function to get a content from an URL (use proxy if proxy defined).
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
targetPrepareHead($object)
Prepare array of tabs for Target.