27require
'../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/webhook/class/target.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/webhook/lib/webhook_target.lib.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
44$langs->loadLangs(array(
'other',
'admin'));
49$action =
GETPOST(
'action',
'aZ09');
50$confirm =
GETPOST(
'confirm',
'alpha');
52$contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'targetcard';
53$backtopage =
GETPOST(
'backtopage',
'alpha');
54$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
60$diroutputmassaction =
$conf->webhook->dir_output.
'/temp/massgeneration/'.$user->id;
61$hookmanager->initHooks(array(
'targetcard',
'globalcard'));
64$extrafields->fetch_name_optionals_label(
$object->table_element);
66$search_array_options = $extrafields->getOptionalsFromPost(
$object->table_element,
'',
'search_');
69$search_all =
GETPOST(
"search_all",
'alpha');
71foreach (
$object->fields as $key => $val) {
72 if (
GETPOST(
'search_'.$key,
'alpha')) {
73 $search[$key] =
GETPOST(
'search_'.$key,
'alpha');
77if (empty($action) && empty($id) && empty($ref)) {
82include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
88if ($enablepermissioncheck) {
89 $permissiontoread = (bool) $user->hasRight(
'webhook',
'target',
'read');
90 $permissiontoadd = (bool) $user->hasRight(
'webhook',
'target',
'write');
91 $permissiontodelete = (bool) $user->hasRight(
'webhook',
'target',
'delete') || ((bool) $permissiontoadd && isset(
$object->status) &&
$object->status == $object::STATUS_DRAFT);
92 $permissionnote = (bool) $user->hasRight(
'webhook',
'target',
'write');
93 $permissiondellink = (bool) $user->hasRight(
'webhook',
'target',
'write');
95 $permissiontoread =
true;
96 $permissiontoadd =
true;
97 $permissiontodelete =
true;
98 $permissionnote =
true;
99 $permissiondellink =
true;
102$upload_dir =
$conf->webhook->multidir_output[isset(
$object->entity) ?
$object->entity : 1].
'/target';
109if (!isModEnabled(
'webhook')) {
112if (!$permissiontoread) {
121$parameters = array();
122$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
127if (empty($reshook)) {
130 $backurlforlist =
dol_buildpath(
'/webhook/target_list.php?mode=modulesetup', 1);
132 if (empty($backtopage) || ($cancel && empty($id))) {
133 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
134 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
135 $backtopage = $backurlforlist;
137 $backtopage =
dol_buildpath(
'/webhook/target_card.php', 1).
'?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
142 $triggermodname =
'WEBHOOK_TARGET_MODIFY';
145 include DOL_DOCUMENT_ROOT.
'/core/actions_addupdatedelete.inc.php';
148 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
151 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
157 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
159 if ($action ==
'set_thirdparty' && $permissiontoadd) {
160 $object->setValueFrom(
'fk_soc',
GETPOSTINT(
'fk_soc'),
'',
null,
'date',
'', $user, $triggermodname);
162 if ($action ==
'classin' && $permissiontoadd) {
165 if ($action ==
'confirm_statusmanual' && $confirm ==
"yes" && $permissiontoadd) {
166 $object->setStatusCommon($user, $object::STATUS_MANUAL_TRIGGER, 0,
'TARGET_REOPEN');
168 if ($action ==
'confirm_statusautomatic' && $confirm ==
"yes" && $permissiontoadd) {
169 $object->setStatusCommon($user, $object::STATUS_AUTOMATIC_TRIGGER, 0,
'TARGET_REOPEN');
171 if ($action ==
'testsendtourl' && $permissiontoadd) {
172 $triggercode =
GETPOST(
"triggercode");
174 $jsondata =
GETPOST(
"jsondata",
"restricthtml");
177 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Url")),
null,
'errors');
179 if (empty($jsondata)) {
181 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"DataToSendTrigger")),
null,
'errors');
185 'Content-Type: application/json'
189 $method =
'POSTALREADYFORMATED';
195 global $dolibarr_allow_localurl_for_webhooks;
196 $localurl = empty($dolibarr_allow_localurl_for_webhooks) ? 0 : 2;
197 $response =
getURLContent($url, $method, $jsondata, 1, $headers, array(
'http',
'https'), $localurl, -1);
198 if (empty($response[
'curl_error_no']) && $response[
'http_code'] >= 200 && $response[
'http_code'] < 300) {
201 $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'] :
"");
207 $triggersendname =
'WEBHOOK_TARGET_SENTBYMAIL';
208 $autocopy =
'MAIN_MAIL_AUTOCOPY_TARGET_TO';
209 $trackid =
'target'.$object->id;
210 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
220$form =
new Form($db);
227 '/includes/ace/src/ace.js',
228 '/includes/ace/src/ext-statusbar.js',
229 '/includes/ace/src/ext-language_tools.js',
233$arrayofcss = array();
235$title = $langs->trans(
"Target");
238llxHeader(
'', $title, $help_url,
'', 0, 0, $arrayofjs, $arrayofcss,
'',
'mod-webhook page-target_card');
241if ($action ==
'create') {
242 if (empty($permissiontoadd)) {
246 print
load_fiche_titre($langs->trans(
"NewObject", $langs->transnoentitiesnoconv(
"Target")),
'',
'object_'.$object->picto);
248 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
249 print
'<input type="hidden" name="token" value="'.newToken().
'">';
250 print
'<input type="hidden" name="action" value="add">';
252 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
254 if ($backtopageforcancel) {
255 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
261 print
'<table class="border centpercent tableforfieldcreate">'.
"\n";
264 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_add.tpl.php';
267 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_add.tpl.php';
269 print
'</table>'.
"\n";
273 print $form->buttonsSaveCancel(
"Create");
281if (($id || $ref) && $action ==
'edit') {
282 print
load_fiche_titre($langs->trans(
"Target"),
'',
'object_'.$object->picto);
284 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
285 print
'<input type="hidden" name="token" value="'.newToken().
'">';
286 print
'<input type="hidden" name="action" value="update">';
287 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
289 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
291 if ($backtopageforcancel) {
292 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
297 print
'<table class="border centpercent tableforfieldedit">'.
"\n";
300 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_edit.tpl.php';
303 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_edit.tpl.php';
309 print $form->buttonsSaveCancel();
315if (
$object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create'))) {
316 $res =
$object->fetch_optionals();
324 if ($action ==
'delete') {
325 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'DeleteTarget'), $langs->trans(
'ConfirmDeleteObject'),
'confirm_delete',
'', 0, 1);
328 if ($action ==
'deleteline') {
329 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteLine'), $langs->trans(
'ConfirmDeleteLine'),
'confirm_deleteline',
'', 0, 1);
333 if ($action ==
'clone') {
335 $formquestion = array();
336 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneAsk',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1);
342 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
343 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
344 if (empty($reshook)) {
345 $formconfirm .= $hookmanager->resPrint;
346 } elseif ($reshook > 0) {
347 $formconfirm = $hookmanager->resPrint;
356 $linkback =
'<a href="'.dol_buildpath(
'/webhook/target_list.php', 1).
'?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
358 $morehtmlref =
'<div class="refidno">';
393 $morehtmlref .=
'</div>';
396 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
399 print
'<div class="fichecenter">';
400 print
'<div class="fichehalfleft">';
401 print
'<div class="underbanner clearboth"></div>';
402 print
'<table class="border centpercent tableforfield">'.
"\n";
409 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_view.tpl.php';
412 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
418 print
'<div class="clearboth"></div>';
427 if (!empty(
$object->table_element_line)) {
429 $result =
$object->getLinesArray();
431 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOSTINT(
'lineid')).
'" method="POST">
432 <input type="hidden" name="token" value="' .
newToken().
'">
433 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
434 <input type="hidden" name="mode" value="">
435 <input type="hidden" name="page_y" value="">
436 <input type="hidden" name="id" value="' .
$object->id.
'">
439 if (!empty(
$conf->use_javascript_ajax) &&
$object->status == 0) {
440 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
443 print
'<div class="div-table-responsive-no-min">';
444 if (!empty(
$object->lines) || (
$object->status == $object::STATUS_DRAFT && $permissiontoadd && $action !=
'selectlines' && $action !=
'editline')) {
445 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
453 if (
$object->status == 0 && $permissiontoadd && $action !=
'selectlines') {
454 if ($action !=
'editline') {
457 $parameters = array();
458 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
462 if (empty($reshook)) {
463 $object->formAddObjectLine(1, $mysoc, $soc);
468 if (!empty(
$object->lines) || (
$object->status == $object::STATUS_DRAFT && $permissiontoadd && $action !=
'selectlines' && $action !=
'editline')) {
479 if ($action !=
'presend' && $action !=
'editline') {
480 print
'<div class="tabsAction">'.
"\n";
481 $parameters = array();
482 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
487 if (empty($reshook)) {
493 print
dolGetButtonAction(
'', $langs->trans(
'Modify'),
'default', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=edit&token='.
newToken(),
'', $permissiontoadd);
496 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=clone&token='.
newToken(),
'', $permissiontoadd);
499 print
dolGetButtonAction($langs->trans(
'TestWebhookTarget'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=test&token='.
newToken(),
'', $permissiontoadd);
518 if (
$object->status == $object::STATUS_DRAFT) {
519 $arrayforbutactivate = array();
520 $arrayforbutactivate[] = array(
521 'url' => $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=confirm_statusautomatic&confirm=yes&token='.
newToken(),
522 'label' =>
'AutomaticTrigger',
527 $arrayforbutactivate[] = array(
528 'url' => $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=confirm_statusmanual&confirm=yes&token='.
newToken(),
529 'label' =>
'ManualTrigger',
534 print
dolGetButtonAction(
'', $langs->trans(
'Enable'),
'default', $arrayforbutactivate,
'', $permissiontoadd);
538 if (in_array(
$object->status, array($object::STATUS_AUTOMATIC_TRIGGER, $object::STATUS_MANUAL_TRIGGER))) {
539 print
dolGetButtonAction(
'', $langs->trans(
'Disable'),
'delete', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=confirm_setdraft&confirm=yes&token='.
newToken(),
'', $permissiontoadd);
543 print
dolGetButtonAction($langs->trans(
'Delete'),
'',
'delete', $_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=delete&token='.
newToken(),
'', $permissiontodelete);
549if ($action ==
"test") {
550 print
'<div id="formtesttarget" name="formtesttarget"></div>';
554 print
"\n".
'<!-- Begin form test target --><div id="targettestform"></div>'.
"\n";
555 print
'<form method="POST" name="testtargetform" id="testtargetform" enctype="multipart/form-data" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'">';
556 print
'<input type="hidden" name="token" value="'.newToken().
'">';
557 print
'<input type="hidden" name="action" value="testsendtourl">';
559 print
'<table class="tableforemailform boxtablenotop centpercent">';
561 print
'<tr><td class="titlefieldcreate fieldrequired minwidth200">';
562 print $langs->trans(
"TriggerCodes");
563 print
'</td><td class="valuefieldcreate">';
564 $arraytriggercodes = explode(
",",
$object->trigger_codes);
566 if (in_array(
GETPOST(
"triggercodes"), $arraytriggercodes)) {
567 $idtriggercode = array_search(
GETPOST(
"triggercodes"), $arraytriggercodes);
569 print $form->selectarray(
"triggercode", $arraytriggercodes, $idtriggercode, 0, 0, 1);
572 print
'<tr><td class="titlefieldcreate fieldrequired minwidth200">';
573 print $langs->trans(
"Url");
574 print
'</td><td class="valuefieldcreate">';
575 print
'<input class="flat minwidth400" name="url" value="'.(GETPOSTISSET(
"url") ?
GETPOST(
"url") :
$object->url).
'" />';
579 print
'<tr><td class="titlefieldcreate fieldrequired minwidth200">';
580 print $langs->trans(
"DataToSendTrigger");
584 $json->triggercode =
"TEST_TRIGGER_CODE";
586 $json->object->field1 =
'field1';
587 $json->object->field2 =
'field2';
588 $json->object->field3 =
'field3';
590 $datatosend = json_encode($json);
598 print
'<textarea id="jsondata" class="flat minwidth100" style="margin-top: 5px; width: 95%" rows="8" name="jsondata">';
605 print
'<div class="center">';
606 print $form->buttonsSaveCancel(
"SendToUrl");
610 if (
$conf->use_javascript_ajax) {
612 $("#triggercode").change(function(){
613 console.log("We change trigger code");
614 triggercode = $(this).val();
615 getDatatToSendTriggerCode(triggercode);
618 function getDatatToSendTriggerCode(triggercode){
621 url: \''.DOL_URL_ROOT.
'/webhook/ajax/webhook.php\',
622 data: { action: "getjsonformtrigger", triggercode: triggercode , token:"'.
currentToken().
'"},
623 success: function(response) {
624 obj = JSON.stringify(response);
625 $("#jsondata").val(obj);
630 $(document).ready(function () {
631 triggercode = $("#triggercode").val();
632 getDatatToSendTriggerCode(triggercode);
638 print
"\n".
'<!-- END form test target -->';
$id
Support class for third parties, contacts, members, users or resources.
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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, $morecssdiv='')
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.
getDolGlobalBool($key, $default=false)
Return a Dolibarr global constant boolean value.
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, $timeoutconnect=0, $timeoutresponse=0)
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.