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');
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) {
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'] :
"");
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';
194$form =
new Form($db);
201 '/includes/ace/src/ace.js',
202 '/includes/ace/src/ext-statusbar.js',
203 '/includes/ace/src/ext-language_tools.js',
207$arrayofcss = array();
209$title = $langs->trans(
"Target");
212llxHeader(
'', $title, $help_url,
'', 0, 0, $arrayofjs, $arrayofcss,
'',
'mod-webhook page-target_card');
215if ($action ==
'create') {
216 if (empty($permissiontoadd)) {
221 print
load_fiche_titre($langs->trans(
"NewObject", $langs->transnoentitiesnoconv(
"Target")),
'',
'object_'.$object->picto);
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">';
227 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
229 if ($backtopageforcancel) {
230 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
236 print
'<table class="border centpercent tableforfieldcreate">'.
"\n";
239 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_add.tpl.php';
242 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_add.tpl.php';
244 print
'</table>'.
"\n";
248 print $form->buttonsSaveCancel(
"Create");
256if (($id || $ref) && $action ==
'edit') {
257 print
load_fiche_titre($langs->trans(
"Target"),
'',
'object_'.$object->picto);
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.
'">';
264 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
266 if ($backtopageforcancel) {
267 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
272 print
'<table class="border centpercent tableforfieldedit">'.
"\n";
275 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_edit.tpl.php';
278 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_edit.tpl.php';
284 print $form->buttonsSaveCancel();
290if (
$object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create'))) {
291 $res =
$object->fetch_optionals();
299 if ($action ==
'delete') {
300 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'DeleteTarget'), $langs->trans(
'ConfirmDeleteObject'),
'confirm_delete',
'', 0, 1);
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);
308 if ($action ==
'clone') {
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);
315 if ($action ==
'xxx') {
316 $text = $langs->trans(
'ConfirmActionTarget',
$object->ref);
325 $formquestion = array();
336 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'XXX'), $text,
'confirm_xxx', $formquestion, 0, 1, 220);
340 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
341 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
342 if (empty($reshook)) {
343 $formconfirm .= $hookmanager->resPrint;
344 } elseif ($reshook > 0) {
345 $formconfirm = $hookmanager->resPrint;
354 $linkback =
'<a href="'.dol_buildpath(
'/webhook/target_list.php', 1).
'?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
356 $morehtmlref =
'<div class="refidno">';
391 $morehtmlref .=
'</div>';
394 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
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";
407 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_view.tpl.php';
410 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
416 print
'<div class="clearboth"></div>';
425 if (!empty(
$object->table_element_line)) {
427 $result =
$object->getLinesArray();
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.
'">
437 if (!empty($conf->use_javascript_ajax) &&
$object->status == 0) {
438 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
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%">';
451 if (
$object->status == 0 && $permissiontoadd && $action !=
'selectlines') {
452 if ($action !=
'editline') {
455 $parameters = array();
456 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
460 if (empty($reshook)) {
461 $object->formAddObjectLine(1, $mysoc, $soc);
466 if (!empty(
$object->lines) || (
$object->status == $object::STATUS_DRAFT && $permissiontoadd && $action !=
'selectlines' && $action !=
'editline')) {
477 if ($action !=
'presend' && $action !=
'editline') {
478 print
'<div class="tabsAction">'.
"\n";
479 $parameters = array();
480 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
485 if (empty($reshook)) {
491 print
dolGetButtonAction(
'', $langs->trans(
'Modify'),
'default', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=edit&token='.
newToken(),
'', $permissiontoadd);
494 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=clone&token='.
newToken(),
'', $permissiontoadd);
497 print
dolGetButtonAction($langs->trans(
'TestWebhookTarget'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=test&token='.
newToken(),
'', $permissiontoadd);
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);
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);
526 print
dolGetButtonAction($langs->trans(
'Delete'),
'',
'delete', $_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=delete&token='.
newToken(),
'', $permissiontodelete);
532if ($action ==
"test") {
533 print
'<div id="formtesttarget" name="formtesttarget"></div>';
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">';
542 print
'<table class="tableforemailform boxtablenotop centpercent">';
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);
549 if (in_array(
GETPOST(
"triggercodes"), $arraytriggercodes)) {
550 $idtriggercode = array_search(
GETPOST(
"triggercodes"), $arraytriggercodes);
552 print $form->selectarray(
"triggercode", $arraytriggercodes, $idtriggercode, 0, 0, 1);
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).
'" />';
562 print
'<tr><td class="titlefieldcreate fieldrequired minwidth200">';
563 print $langs->trans(
"DataToSendTrigger");
567 $json->triggercode =
"TEST_TRIGGER_CODE";
569 $json->object->field1 =
'field1';
570 $json->object->field2 =
'field2';
571 $json->object->field3 =
'field3';
573 $datatosend = json_encode($json);
581 print
'<textarea id="jsondata" class="flat minwidth100" style="margin-top: 5px; width: 95%" rows="8" name="jsondata">';
588 print
'<div class="center">';
589 print $form->buttonsSaveCancel(
"SendToUrl");
593 if ($conf->use_javascript_ajax) {
595 $("#triggercode").change(function(){
596 console.log("We change trigger code");
597 triggercode = $(this).val();
598 getDatatToSendTriggerCode(triggercode);
601 function getDatatToSendTriggerCode(triggercode){
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);
613 $(document).ready(function () {
614 triggercode = $("#triggercode").val();
615 getDatatToSendTriggerCode(triggercode);
621 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()
Empty header.
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.