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';
45$langs->loadLangs(array(
'other',
'admin'));
50$action =
GETPOST(
'action',
'aZ09');
51$confirm =
GETPOST(
'confirm',
'alpha');
52$cancel =
GETPOST(
'cancel',
'aZ09');
53$contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'targetcard';
54$backtopage =
GETPOST(
'backtopage',
'alpha');
55$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
61$diroutputmassaction =
$conf->webhook->dir_output.
'/temp/massgeneration/'.$user->id;
62$hookmanager->initHooks(array(
'targetcard',
'globalcard'));
65$extrafields->fetch_name_optionals_label(
$object->table_element);
67$search_array_options = $extrafields->getOptionalsFromPost(
$object->table_element,
'',
'search_');
70$search_all =
GETPOST(
"search_all",
'alpha');
72foreach (
$object->fields as $key => $val) {
73 if (
GETPOST(
'search_'.$key,
'alpha')) {
74 $search[$key] =
GETPOST(
'search_'.$key,
'alpha');
78if (empty($action) && empty($id) && empty($ref)) {
83include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
88$enablepermissioncheck = 0;
89if ($enablepermissioncheck) {
90 $permissiontoread = $user->hasRight(
'webhook',
'target',
'read');
91 $permissiontoadd = $user->hasRight(
'webhook',
'target',
'write');
92 $permissiontodelete = $user->hasRight(
'webhook',
'target',
'delete') || ($permissiontoadd && isset(
$object->status) &&
$object->status == $object::STATUS_DRAFT);
93 $permissionnote = $user->hasRight(
'webhook',
'target',
'write');
94 $permissiondellink = $user->hasRight(
'webhook',
'target',
'write');
96 $permissiontoread = 1;
98 $permissiontodelete = 1;
100 $permissiondellink = 1;
103$upload_dir =
$conf->webhook->multidir_output[isset(
$object->entity) ?
$object->entity : 1].
'/target';
110if (!isModEnabled(
'webhook')) {
113if (!$permissiontoread) {
122$parameters = array();
123$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
128if (empty($reshook)) {
131 $backurlforlist =
dol_buildpath(
'/webhook/target_list.php?mode=modulesetup', 1);
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;
138 $backtopage =
dol_buildpath(
'/webhook/target_card.php', 1).
'?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
143 $triggermodname =
'WEBHOOK_TARGET_MODIFY';
146 include DOL_DOCUMENT_ROOT.
'/core/actions_addupdatedelete.inc.php';
149 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
152 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
158 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
160 if ($action ==
'set_thirdparty' && $permissiontoadd) {
161 $object->setValueFrom(
'fk_soc',
GETPOSTINT(
'fk_soc'),
'',
'',
'date',
'', $user, $triggermodname);
163 if ($action ==
'classin' && $permissiontoadd) {
167 if ($action ==
'testsendtourl' && $permissiontoadd) {
168 $triggercode =
GETPOST(
"triggercode");
170 $jsondata =
GETPOST(
"jsondata",
"restricthtml");
173 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Url")),
null,
'errors');
175 if (empty($jsondata)) {
177 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"DataToSendTrigger")),
null,
'errors');
181 'Content-Type: application/json'
185 $method =
'POSTALREADYFORMATED';
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) {
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'] :
"");
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';
214$form =
new Form($db);
221 '/includes/ace/src/ace.js',
222 '/includes/ace/src/ext-statusbar.js',
223 '/includes/ace/src/ext-language_tools.js',
227$arrayofcss = array();
229$title = $langs->trans(
"Target");
232llxHeader(
'', $title, $help_url,
'', 0, 0, $arrayofjs, $arrayofcss,
'',
'mod-webhook page-target_card');
235if ($action ==
'create') {
236 if (empty($permissiontoadd)) {
240 print
load_fiche_titre($langs->trans(
"NewObject", $langs->transnoentitiesnoconv(
"Target")),
'',
'object_'.$object->picto);
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">';
246 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
248 if ($backtopageforcancel) {
249 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
255 print
'<table class="border centpercent tableforfieldcreate">'.
"\n";
258 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_add.tpl.php';
261 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_add.tpl.php';
263 print
'</table>'.
"\n";
267 print $form->buttonsSaveCancel(
"Create");
275if (($id || $ref) && $action ==
'edit') {
276 print
load_fiche_titre($langs->trans(
"Target"),
'',
'object_'.$object->picto);
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.
'">';
283 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
285 if ($backtopageforcancel) {
286 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
291 print
'<table class="border centpercent tableforfieldedit">'.
"\n";
294 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_edit.tpl.php';
297 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_edit.tpl.php';
303 print $form->buttonsSaveCancel();
309if (
$object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create'))) {
310 $res =
$object->fetch_optionals();
318 if ($action ==
'delete') {
319 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'DeleteTarget'), $langs->trans(
'ConfirmDeleteObject'),
'confirm_delete',
'', 0, 1);
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);
327 if ($action ==
'clone') {
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);
334 if ($action ==
'xxx') {
335 $text = $langs->trans(
'ConfirmActionTarget',
$object->ref);
344 $formquestion = array();
355 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'XXX'), $text,
'confirm_xxx', $formquestion, 0, 1, 220);
359 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
360 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
361 if (empty($reshook)) {
362 $formconfirm .= $hookmanager->resPrint;
363 } elseif ($reshook > 0) {
364 $formconfirm = $hookmanager->resPrint;
373 $linkback =
'<a href="'.dol_buildpath(
'/webhook/target_list.php', 1).
'?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
375 $morehtmlref =
'<div class="refidno">';
410 $morehtmlref .=
'</div>';
413 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
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";
426 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_view.tpl.php';
429 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
435 print
'<div class="clearboth"></div>';
444 if (!empty(
$object->table_element_line)) {
446 $result =
$object->getLinesArray();
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.
'">
456 if (!empty(
$conf->use_javascript_ajax) &&
$object->status == 0) {
457 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
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%">';
470 if (
$object->status == 0 && $permissiontoadd && $action !=
'selectlines') {
471 if ($action !=
'editline') {
474 $parameters = array();
475 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
479 if (empty($reshook)) {
480 $object->formAddObjectLine(1, $mysoc, $soc);
485 if (!empty(
$object->lines) || (
$object->status == $object::STATUS_DRAFT && $permissiontoadd && $action !=
'selectlines' && $action !=
'editline')) {
496 if ($action !=
'presend' && $action !=
'editline') {
497 print
'<div class="tabsAction">'.
"\n";
498 $parameters = array();
499 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
504 if (empty($reshook)) {
510 print
dolGetButtonAction(
'', $langs->trans(
'Modify'),
'default', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=edit&token='.
newToken(),
'', $permissiontoadd);
513 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=clone&token='.
newToken(),
'', $permissiontoadd);
516 print
dolGetButtonAction($langs->trans(
'TestWebhookTarget'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=test&token='.
newToken(),
'', $permissiontoadd);
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);
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);
545 print
dolGetButtonAction($langs->trans(
'Delete'),
'',
'delete', $_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=delete&token='.
newToken(),
'', $permissiontodelete);
551if ($action ==
"test") {
552 print
'<div id="formtesttarget" name="formtesttarget"></div>';
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">';
561 print
'<table class="tableforemailform boxtablenotop centpercent">';
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);
568 if (in_array(
GETPOST(
"triggercodes"), $arraytriggercodes)) {
569 $idtriggercode = array_search(
GETPOST(
"triggercodes"), $arraytriggercodes);
571 print $form->selectarray(
"triggercode", $arraytriggercodes, $idtriggercode, 0, 0, 1);
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).
'" />';
581 print
'<tr><td class="titlefieldcreate fieldrequired minwidth200">';
582 print $langs->trans(
"DataToSendTrigger");
586 $json->triggercode =
"TEST_TRIGGER_CODE";
588 $json->object->field1 =
'field1';
589 $json->object->field2 =
'field2';
590 $json->object->field3 =
'field3';
592 $datatosend = json_encode($json);
600 print
'<textarea id="jsondata" class="flat minwidth100" style="margin-top: 5px; width: 95%" rows="8" name="jsondata">';
607 print
'<div class="center">';
608 print $form->buttonsSaveCancel(
"SendToUrl");
612 if (
$conf->use_javascript_ajax) {
614 $("#triggercode").change(function(){
615 console.log("We change trigger code");
616 triggercode = $(this).val();
617 getDatatToSendTriggerCode(triggercode);
620 function getDatatToSendTriggerCode(triggercode){
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);
632 $(document).ready(function () {
633 triggercode = $("#triggercode").val();
634 getDatatToSendTriggerCode(triggercode);
640 print
"\n".
'<!-- END form test target -->';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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.
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...
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.