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';
34global $conf, $db, $hookmanager, $langs, $user;
37$langs->loadLangs(array(
'other',
'admin'));
42$action =
GETPOST(
'action',
'aZ09');
43$confirm =
GETPOST(
'confirm',
'alpha');
44$cancel =
GETPOST(
'cancel',
'aZ09');
45$contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'targetcard';
46$backtopage =
GETPOST(
'backtopage',
'alpha');
47$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
53$diroutputmassaction = $conf->webhook->dir_output.
'/temp/massgeneration/'.$user->id;
54$hookmanager->initHooks(array(
'targetcard',
'globalcard'));
57$extrafields->fetch_name_optionals_label(
$object->table_element);
59$search_array_options = $extrafields->getOptionalsFromPost(
$object->table_element,
'',
'search_');
62$search_all =
GETPOST(
"search_all",
'alpha');
64foreach (
$object->fields as $key => $val) {
65 if (
GETPOST(
'search_'.$key,
'alpha')) {
66 $search[$key] =
GETPOST(
'search_'.$key,
'alpha');
70if (empty($action) && empty($id) && empty($ref)) {
75include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
80$enablepermissioncheck = 0;
81if ($enablepermissioncheck) {
82 $permissiontoread = $user->hasRight(
'webhook',
'target',
'read');
83 $permissiontoadd = $user->hasRight(
'webhook',
'target',
'write');
84 $permissiontodelete = $user->hasRight(
'webhook',
'target',
'delete') || ($permissiontoadd && isset(
$object->status) &&
$object->status == $object::STATUS_DRAFT);
85 $permissionnote = $user->hasRight(
'webhook',
'target',
'write');
86 $permissiondellink = $user->hasRight(
'webhook',
'target',
'write');
88 $permissiontoread = 1;
90 $permissiontodelete = 1;
92 $permissiondellink = 1;
95$upload_dir = $conf->webhook->multidir_output[isset(
$object->entity) ?
$object->entity : 1].
'/target';
102if (!isModEnabled(
'webhook')) {
105if (!$permissiontoread) {
114$parameters = array();
115$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
120if (empty($reshook)) {
123 $backurlforlist =
dol_buildpath(
'/webhook/target_list.php?mode=modulesetup', 1);
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;
130 $backtopage =
dol_buildpath(
'/webhook/target_card.php', 1).
'?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
135 $triggermodname =
'WEBHOOK_TARGET_MODIFY';
138 include DOL_DOCUMENT_ROOT.
'/core/actions_addupdatedelete.inc.php';
141 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
144 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
150 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
152 if ($action ==
'set_thirdparty' && $permissiontoadd) {
153 $object->setValueFrom(
'fk_soc',
GETPOSTINT(
'fk_soc'),
'',
'',
'date',
'', $user, $triggermodname);
155 if ($action ==
'classin' && $permissiontoadd) {
159 if ($action ==
'testsendtourl' && $permissiontoadd) {
160 $triggercode =
GETPOST(
"triggercode");
162 $jsondata =
GETPOST(
"jsondata",
"restricthtml");
165 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Url")),
null,
'errors');
167 if (empty($jsondata)) {
169 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"DataToSendTrigger")),
null,
'errors');
173 'Content-Type: application/json'
177 $method =
'POSTALREADYFORMATED';
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) {
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'] :
"");
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';
206$form =
new Form($db);
213 '/includes/ace/src/ace.js',
214 '/includes/ace/src/ext-statusbar.js',
215 '/includes/ace/src/ext-language_tools.js',
219$arrayofcss = array();
221$title = $langs->trans(
"Target");
224llxHeader(
'', $title, $help_url,
'', 0, 0, $arrayofjs, $arrayofcss,
'',
'mod-webhook page-target_card');
227if ($action ==
'create') {
228 if (empty($permissiontoadd)) {
233 print
load_fiche_titre($langs->trans(
"NewObject", $langs->transnoentitiesnoconv(
"Target")),
'',
'object_'.$object->picto);
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">';
239 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
241 if ($backtopageforcancel) {
242 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
248 print
'<table class="border centpercent tableforfieldcreate">'.
"\n";
251 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_add.tpl.php';
254 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_add.tpl.php';
256 print
'</table>'.
"\n";
260 print $form->buttonsSaveCancel(
"Create");
268if (($id || $ref) && $action ==
'edit') {
269 print
load_fiche_titre($langs->trans(
"Target"),
'',
'object_'.$object->picto);
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.
'">';
276 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
278 if ($backtopageforcancel) {
279 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
284 print
'<table class="border centpercent tableforfieldedit">'.
"\n";
287 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_edit.tpl.php';
290 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_edit.tpl.php';
296 print $form->buttonsSaveCancel();
302if (
$object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create'))) {
303 $res =
$object->fetch_optionals();
311 if ($action ==
'delete') {
312 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'DeleteTarget'), $langs->trans(
'ConfirmDeleteObject'),
'confirm_delete',
'', 0, 1);
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);
320 if ($action ==
'clone') {
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);
327 if ($action ==
'xxx') {
328 $text = $langs->trans(
'ConfirmActionTarget',
$object->ref);
337 $formquestion = array();
348 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'XXX'), $text,
'confirm_xxx', $formquestion, 0, 1, 220);
352 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
353 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
354 if (empty($reshook)) {
355 $formconfirm .= $hookmanager->resPrint;
356 } elseif ($reshook > 0) {
357 $formconfirm = $hookmanager->resPrint;
366 $linkback =
'<a href="'.dol_buildpath(
'/webhook/target_list.php', 1).
'?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
368 $morehtmlref =
'<div class="refidno">';
403 $morehtmlref .=
'</div>';
406 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
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";
419 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_view.tpl.php';
422 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
428 print
'<div class="clearboth"></div>';
437 if (!empty(
$object->table_element_line)) {
439 $result =
$object->getLinesArray();
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.
'">
449 if (!empty($conf->use_javascript_ajax) &&
$object->status == 0) {
450 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
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%">';
463 if (
$object->status == 0 && $permissiontoadd && $action !=
'selectlines') {
464 if ($action !=
'editline') {
467 $parameters = array();
468 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
472 if (empty($reshook)) {
473 $object->formAddObjectLine(1, $mysoc, $soc);
478 if (!empty(
$object->lines) || (
$object->status == $object::STATUS_DRAFT && $permissiontoadd && $action !=
'selectlines' && $action !=
'editline')) {
489 if ($action !=
'presend' && $action !=
'editline') {
490 print
'<div class="tabsAction">'.
"\n";
491 $parameters = array();
492 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
497 if (empty($reshook)) {
503 print
dolGetButtonAction(
'', $langs->trans(
'Modify'),
'default', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=edit&token='.
newToken(),
'', $permissiontoadd);
506 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=clone&token='.
newToken(),
'', $permissiontoadd);
509 print
dolGetButtonAction($langs->trans(
'TestWebhookTarget'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=test&token='.
newToken(),
'', $permissiontoadd);
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);
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);
538 print
dolGetButtonAction($langs->trans(
'Delete'),
'',
'delete', $_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=delete&token='.
newToken(),
'', $permissiontodelete);
544if ($action ==
"test") {
545 print
'<div id="formtesttarget" name="formtesttarget"></div>';
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">';
554 print
'<table class="tableforemailform boxtablenotop centpercent">';
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);
561 if (in_array(
GETPOST(
"triggercodes"), $arraytriggercodes)) {
562 $idtriggercode = array_search(
GETPOST(
"triggercodes"), $arraytriggercodes);
564 print $form->selectarray(
"triggercode", $arraytriggercodes, $idtriggercode, 0, 0, 1);
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).
'" />';
574 print
'<tr><td class="titlefieldcreate fieldrequired minwidth200">';
575 print $langs->trans(
"DataToSendTrigger");
579 $json->triggercode =
"TEST_TRIGGER_CODE";
581 $json->object->field1 =
'field1';
582 $json->object->field2 =
'field2';
583 $json->object->field3 =
'field3';
585 $datatosend = json_encode($json);
593 print
'<textarea id="jsondata" class="flat minwidth100" style="margin-top: 5px; width: 95%" rows="8" name="jsondata">';
600 print
'<div class="center">';
601 print $form->buttonsSaveCancel(
"SendToUrl");
605 if ($conf->use_javascript_ajax) {
607 $("#triggercode").change(function(){
608 console.log("We change trigger code");
609 triggercode = $(this).val();
610 getDatatToSendTriggerCode(triggercode);
613 function getDatatToSendTriggerCode(triggercode){
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);
625 $(document).ready(function () {
626 triggercode = $("#triggercode").val();
627 getDatatToSendTriggerCode(triggercode);
633 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).
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.