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