dolibarr 21.0.0-alpha
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 a 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
172 $headers = array(
173 'Content-Type: application/json'
174 //'Accept: application/json'
175 );
176
177 $method = 'POSTALREADYFORMATED';
178 if (getDolGlobalString('WEBHOOK_POST_SEND_DATA_AS_PARAM_STRING')) { // For compatibility with v20- versions
179 $method = 'POST';
180 }
181
182 // TODO Replace this by a call of trigger...
183 $response = getURLContent($url, $method, $jsondata, 1, $headers, array('http', 'https'), 2, -1);
184 if (empty($response['curl_error_no']) && $response['http_code'] >= 200 && $response['http_code'] < 300) {
185 setEventMessages($langs->trans("Success"), null);
186 } else {
187 $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'] : "");
188 setEventMessages($langs->trans($errormsg), null, 'errors');
189 }
190 }
191
192 // Actions to send emails
193 $triggersendname = 'WEBHOOK_TARGET_SENTBYMAIL';
194 $autocopy = 'MAIN_MAIL_AUTOCOPY_TARGET_TO';
195 $trackid = 'target'.$object->id;
196 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
197}
198
199
200
201
202/*
203 * View
204 */
205
206$form = new Form($db);
207$formfile = new FormFile($db);
208$formproject = new FormProjets($db);
209
210$object->initListOfTriggers();
211
212$arrayofjs = array(
213 '/includes/ace/src/ace.js',
214 '/includes/ace/src/ext-statusbar.js',
215 '/includes/ace/src/ext-language_tools.js',
216 //'/includes/ace/src/ext-chromevox.js'
217 //'/includes/jquery/plugins/jqueryscoped/jquery.scoped.js',
218);
219$arrayofcss = array();
220
221$title = $langs->trans("Target");
222$help_url = '';
223
224llxHeader('', $title, $help_url, '', 0, 0, $arrayofjs, $arrayofcss, '', 'mod-webhook page-target_card');
225
226// Part to create
227if ($action == 'create') {
228 if (empty($permissiontoadd)) {
229 accessforbidden('NotEnoughPermissions', 0, 1);
230 exit;
231 }
232
233 print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("Target")), '', 'object_'.$object->picto);
234
235 print '<form method="POST" action="'.$_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="'.$_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($_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($_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($_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 if ($action == 'xxx') {
328 $text = $langs->trans('ConfirmActionTarget', $object->ref);
329 /*if (isModEnabled('notification'))
330 {
331 require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
332 $notify = new Notify($db);
333 $text .= '<br>';
334 $text .= $notify->confirmMessage('TARGET_CLOSE', $object->socid, $object);
335 }*/
336
337 $formquestion = array();
338 /*
339 $forcecombo=0;
340 if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
341 $formquestion = array(
342 // 'text' => $langs->trans("ConfirmClone"),
343 // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
344 // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
345 // array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
346 );
347 */
348 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220);
349 }
350
351 // Call Hook formConfirm
352 $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
353 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
354 if (empty($reshook)) {
355 $formconfirm .= $hookmanager->resPrint;
356 } elseif ($reshook > 0) {
357 $formconfirm = $hookmanager->resPrint;
358 }
359
360 // Print form confirm
361 print $formconfirm;
362
363
364 // Object card
365 // ------------------------------------------------------------
366 $linkback = '<a href="'.dol_buildpath('/webhook/target_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
367
368 $morehtmlref = '<div class="refidno">';
369 /*
370 // Ref customer
371 $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
372 $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
373 // Thirdparty
374 $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
375 // Project
376 if (isModEnabled('projet')) {
377 $langs->load("projects");
378 $morehtmlref .= '<br>'.$langs->trans('Project') . ' ';
379 if ($permissiontoadd) {
380 //if ($action != 'classify') $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
381 $morehtmlref .= ' : ';
382 if ($action == 'classify') {
383 //$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 0, 1, '', 'maxwidth300');
384 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
385 $morehtmlref .= '<input type="hidden" name="action" value="classin">';
386 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
387 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
388 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
389 $morehtmlref .= '</form>';
390 } else {
391 $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
392 }
393 } else {
394 if (!empty($object->fk_project)) {
395 $proj = new Project($db);
396 $proj->fetch($object->fk_project);
397 $morehtmlref .= ': '.$proj->getNomUrl();
398 } else {
399 $morehtmlref .= '';
400 }
401 }
402 }*/
403 $morehtmlref .= '</div>';
404
405
406 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
407
408
409 print '<div class="fichecenter">';
410 print '<div class="fichehalfleft">';
411 print '<div class="underbanner clearboth"></div>';
412 print '<table class="border centpercent tableforfield">'."\n";
413
414 // Common attributes
415 //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
416 //unset($object->fields['fk_project']); // Hide field already shown in banner
417 //unset($object->fields['fk_soc']); // Hide field already shown in banner
418
419 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
420
421 // Other attributes. Fields from hook formObjectOptions and Extrafields.
422 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
423
424 print '</table>';
425 print '</div>';
426 print '</div>';
427
428 print '<div class="clearboth"></div>';
429
430 print dol_get_fiche_end();
431
432
433 /*
434 * Lines
435 */
436
437 if (!empty($object->table_element_line)) {
438 // Show object lines
439 $result = $object->getLinesArray();
440
441 print '<form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '' : '#line_'.GETPOSTINT('lineid')).'" method="POST">
442 <input type="hidden" name="token" value="' . newToken().'">
443 <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
444 <input type="hidden" name="mode" value="">
445 <input type="hidden" name="page_y" value="">
446 <input type="hidden" name="id" value="' . $object->id.'">
447 ';
448
449 if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
450 include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
451 }
452
453 print '<div class="div-table-responsive-no-min">';
454 if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
455 print '<table id="tablelines" class="noborder noshadow" width="100%">';
456 }
457
458 if (!empty($object->lines)) {
459 $object->printObjectLines($action, $mysoc, null, GETPOSTINT('lineid'), 1);
460 }
461
462 // Form to add new line
463 if ($object->status == 0 && $permissiontoadd && $action != 'selectlines') {
464 if ($action != 'editline') {
465 // Add products/services form
466
467 $parameters = array();
468 $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
469 if ($reshook < 0) {
470 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
471 }
472 if (empty($reshook)) {
473 $object->formAddObjectLine(1, $mysoc, $soc);
474 }
475 }
476 }
477
478 if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
479 print '</table>';
480 }
481 print '</div>';
482
483 print "</form>\n";
484 }
485
486
487 // Buttons for actions
488
489 if ($action != 'presend' && $action != 'editline') {
490 print '<div class="tabsAction">'."\n";
491 $parameters = array();
492 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
493 if ($reshook < 0) {
494 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
495 }
496
497 if (empty($reshook)) {
498 // Send
499 /*if (empty($user->socid)) {
500 print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init&token='.newToken().'#formmailbeforetitle');
501 }*/
502
503 print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken(), '', $permissiontoadd);
504
505 // Clone
506 print dolGetButtonAction($langs->trans('ToClone'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=clone&token='.newToken(), '', $permissiontoadd);
507
508 // Webhook send test
509 print dolGetButtonAction($langs->trans('TestWebhookTarget'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=test&token='.newToken(), '', $permissiontoadd);
510 /*
511 if ($permissiontoadd) {
512 if ($object->status == $object::STATUS_ENABLED) {
513 print dolGetButtonAction($langs->trans('Disable'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=disable&token='.newToken(), '', $permissiontoadd);
514 } else {
515 print dolGetButtonAction($langs->trans('Enable'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=enable&token='.newToken(), '', $permissiontoadd);
516 }
517 }
518 if ($permissiontoadd) {
519 if ($object->status == $object::STATUS_VALIDATED) {
520 print dolGetButtonAction($langs->trans('Cancel'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=close&token='.newToken(), '', $permissiontoadd);
521 } else {
522 print dolGetButtonAction($langs->trans('Re-Open'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=reopen&token='.newToken(), '', $permissiontoadd);
523 }
524 }
525 */
526
527 // Enable
528 if ($object->status == $object::STATUS_DRAFT) {
529 print dolGetButtonAction('', $langs->trans('Enable'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_validate&confirm=yes&token='.newToken(), '', $permissiontoadd);
530 }
531
532 // Disable
533 if ($object->status == $object::STATUS_VALIDATED) {
534 print dolGetButtonAction('', $langs->trans('Disable'), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes&token='.newToken(), '', $permissiontoadd);
535 }
536
537 // Delete (need delete permission, or if draft, just need create/modify permission)
538 print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken(), '', $permissiontodelete);
539 }
540 print '</div>'."\n";
541 }
542}
543
544if ($action == "test") {
545 print '<div id="formtesttarget" name="formtesttarget"></div>';
546 print load_fiche_titre($langs->trans("TestWebhookTarget"));
547 print dol_get_fiche_head(array(), '', '', -1);
548
549 print "\n".'<!-- Begin form test target --><div id="targettestform"></div>'."\n";
550 print '<form method="POST" name="testtargetform" id="testtargetform" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
551 print '<input type="hidden" name="token" value="'.newToken().'">';
552 print '<input type="hidden" name="action" value="testsendtourl">';
553
554 print '<table class="tableforemailform boxtablenotop centpercent">';
555
556 print '<tr><td class="titlefieldcreate fieldrequired minwidth200">';
557 print $langs->trans("TriggerCodes");
558 print '</td><td class="valuefieldcreate">';
559 $arraytriggercodes = explode(",", $object->trigger_codes);
560 $idtriggercode = '';
561 if (in_array(GETPOST("triggercodes"), $arraytriggercodes)) {
562 $idtriggercode = array_search(GETPOST("triggercodes"), $arraytriggercodes);
563 }
564 print $form->selectarray("triggercode", $arraytriggercodes, $idtriggercode, 0, 0, 1);
565 print '</td></tr>';
566
567 print '<tr><td class="titlefieldcreate fieldrequired minwidth200">';
568 print $langs->trans("Url");
569 print '</td><td class="valuefieldcreate">';
570 print '<input class="flat minwidth400" name="url" value="'.(GETPOSTISSET("url") ? GETPOST("url") : $object->url).'" />';
571 print '</td></tr>';
572
573 // Json sample to send
574 print '<tr><td class="titlefieldcreate fieldrequired minwidth200">';
575 print $langs->trans("DataToSendTrigger");
576 print '</td><td>';
577
578 $json = new stdClass();
579 $json->triggercode = "TEST_TRIGGER_CODE";
580 $json->object = new stdClass();
581 $json->object->field1 = 'field1';
582 $json->object->field2 = 'field2';
583 $json->object->field3 = 'field3';
584
585 $datatosend = json_encode($json);
586 //$datatosend = preg_replace('/\,/', ",\n", $datatosend);
587
588 /*
589 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
590 $doleditor = new DolEditor("jsondata", $datatosend, 0, 200, 'dolibarr_details', 'In', true, true, 'ace');
591 print $doleditor->Create(0, '', true, '', 'json');
592 */
593 print '<textarea id="jsondata" class="flat minwidth100" style="margin-top: 5px; width: 95%" rows="8" name="jsondata">';
594 print $datatosend;
595 print '</textarea>';
596
597 print '</td></tr>';
598 print '</table>';
599
600 print '<div class="center">';
601 print $form->buttonsSaveCancel("SendToUrl");
602 print '</div>';
603 print '</form>';
604
605 if ($conf->use_javascript_ajax) {
606 print '<script>
607 $("#triggercode").change(function(){
608 console.log("We change trigger code");
609 triggercode = $(this).val();
610 getDatatToSendTriggerCode(triggercode);
611 });
612
613 function getDatatToSendTriggerCode(triggercode){
614 $.ajax({
615 method: \'GET\',
616 url: \''.DOL_URL_ROOT.'/webhook/ajax/webhook.php\',
617 data: { action: "getjsonformtrigger", triggercode: triggercode , token:"'.currentToken().'"},
618 success: function(response) {
619 obj = JSON.stringify(response);
620 $("#jsondata").val(obj);
621 }
622 })
623 };
624
625 $(document).ready(function () {
626 triggercode = $("#triggercode").val();
627 getDatatToSendTriggerCode(triggercode);
628 });
629 ';
630 print '</script>';
631 }
632
633 print "\n".'<!-- END form test target -->';
634}
635
636// End of page
637llxFooter();
638$db->close();
$id
Definition account.php:39
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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
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).
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.