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