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