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';
87$permissiontoread = $permissiontoadd = $permissiontodelete = $permissionnote = $permissiondellink = (!empty($user->admin) ? 1 : 0);
89$upload_dir = $conf->webhook->multidir_output[isset(
$object->entity) ?
$object->entity : 1].
'/target';
99if (!$permissiontoread) {
108$parameters = array();
109$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
114if (empty($reshook)) {
117 $backurlforlist =
dol_buildpath(
'/webhook/target_list.php?mode=modulesetup', 1);
119 if (empty($backtopage) || ($cancel && empty($id))) {
120 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
121 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
122 $backtopage = $backurlforlist;
124 $backtopage =
dol_buildpath(
'/webhook/target_card.php', 1).
'?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
129 $triggermodname =
'WEBHOOK_TARGET_MODIFY';
132 include DOL_DOCUMENT_ROOT.
'/core/actions_addupdatedelete.inc.php';
135 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
138 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
144 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
146 if ($action ==
'set_thirdparty' && $permissiontoadd) {
147 $object->setValueFrom(
'fk_soc',
GETPOSTINT(
'fk_soc'),
'',
null,
'date',
'', $user, $triggermodname);
149 if ($action ==
'classin' && $permissiontoadd) {
152 if ($action ==
'confirm_statusmanual' && $confirm ==
"yes" && $permissiontoadd) {
153 $object->setStatusCommon($user, $object::STATUS_MANUAL_TRIGGER, 0,
'TARGET_REOPEN');
155 if ($action ==
'confirm_statusautomatic' && $confirm ==
"yes" && $permissiontoadd) {
156 $object->setStatusCommon($user, $object::STATUS_AUTOMATIC_TRIGGER, 0,
'TARGET_REOPEN');
158 if ($action ==
'testsendtourl' && $permissiontoadd) {
159 $triggercode =
GETPOST(
"triggercode");
161 $jsondata =
GETPOST(
"jsondata",
"restricthtml");
164 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Url")),
null,
'errors');
166 if (empty($jsondata)) {
168 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"DataToSendTrigger")),
null,
'errors');
172 'Content-Type: application/json'
176 $method =
'POSTALREADYFORMATED';
182 global $dolibarr_allow_localurl_for_webhooks;
183 $localurl = empty($dolibarr_allow_localurl_for_webhooks) ? 0 : 2;
184 $response =
getURLContent($url, $method, $jsondata, 1, $headers, array(
'http',
'https'), $localurl, -1);
185 if (empty($response[
'curl_error_no']) && $response[
'http_code'] >= 200 && $response[
'http_code'] < 300) {
188 $errormsg =
"The WebHook for triggercode: ".$triggercode.
" failed to do the GET of URL ".$url.
" with httpcode=".(!empty($response[
'http_code']) ? $response[
'http_code'] :
"").
" curl_error_no=".(!empty($response[
'curl_error_no']) ? $response[
'curl_error_no'] :
"");
194 $triggersendname =
'WEBHOOK_TARGET_SENTBYMAIL';
195 $autocopy =
'MAIN_MAIL_AUTOCOPY_TARGET_TO';
196 $trackid =
'target'.$object->id;
197 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
207$form =
new Form($db);
214 '/includes/ace/src/ace.js',
215 '/includes/ace/src/ext-statusbar.js',
216 '/includes/ace/src/ext-language_tools.js',
220$arrayofcss = array();
222$title = $langs->trans(
"Target");
225llxHeader(
'', $title, $help_url,
'', 0, 0, $arrayofjs, $arrayofcss,
'',
'mod-webhook page-target_card');
228if ($action ==
'create') {
229 if (empty($permissiontoadd)) {
233 print
load_fiche_titre($langs->trans(
"NewObject", $langs->transnoentitiesnoconv(
"Target")),
'',
'object_'.$object->picto);
235 print
'<form method="POST" action="'.dolBuildUrl($_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="'.dolBuildUrl($_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);
329 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
330 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
331 if (empty($reshook)) {
332 $formconfirm .= $hookmanager->resPrint;
333 } elseif ($reshook > 0) {
334 $formconfirm = $hookmanager->resPrint;
343 $linkback =
'<a href="'.dol_buildpath(
'/webhook/target_list.php', 1).
'?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
345 $morehtmlref =
'<div class="refidno">';
380 $morehtmlref .=
'</div>';
383 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
386 print
'<div class="fichecenter">';
387 print
'<div class="fichehalfleft">';
388 print
'<div class="underbanner clearboth"></div>';
389 print
'<table class="border centpercent tableforfield">'.
"\n";
396 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_view.tpl.php';
399 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
405 print
'<div class="clearboth"></div>';
414 if (!empty(
$object->table_element_line)) {
416 $result =
$object->getLinesArray();
418 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOSTINT(
'lineid')).
'" method="POST">
419 <input type="hidden" name="token" value="' .
newToken().
'">
420 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
421 <input type="hidden" name="mode" value="">
422 <input type="hidden" name="page_y" value="">
423 <input type="hidden" name="id" value="' .
$object->id.
'">
426 if (!empty($conf->use_javascript_ajax) &&
$object->status == 0) {
427 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
430 print
'<div class="div-table-responsive-no-min">';
431 if (!empty(
$object->lines) || (
$object->status == $object::STATUS_DRAFT && $permissiontoadd && $action !=
'selectlines' && $action !=
'editline')) {
432 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
440 if (
$object->status == 0 && $permissiontoadd && $action !=
'selectlines') {
441 if ($action !=
'editline') {
444 $parameters = array();
445 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
449 if (empty($reshook)) {
455 if (!empty(
$object->lines) || (
$object->status == $object::STATUS_DRAFT && $permissiontoadd && $action !=
'selectlines' && $action !=
'editline')) {
466 if ($action !=
'presend' && $action !=
'editline') {
467 print
'<div class="tabsAction">'.
"\n";
468 $parameters = array();
469 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
474 if (empty($reshook)) {
480 print
dolGetButtonAction(
'', $langs->trans(
'Modify'),
'default', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=edit&token='.
newToken(),
'', $permissiontoadd);
483 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=clone&token='.
newToken(),
'', $permissiontoadd);
486 print
dolGetButtonAction($langs->trans(
'TestWebhookTarget'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=test&token='.
newToken(),
'', $permissiontoadd);
505 if (
$object->status == $object::STATUS_DRAFT) {
506 $arrayforbutactivate = array();
507 $arrayforbutactivate[] = array(
508 'url' => $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=confirm_statusautomatic&confirm=yes&token='.
newToken(),
509 'label' =>
'AutomaticTrigger',
514 $arrayforbutactivate[] = array(
515 'url' => $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=confirm_statusmanual&confirm=yes&token='.
newToken(),
516 'label' =>
'ManualTrigger',
521 print
dolGetButtonAction(
'', $langs->trans(
'Enable'),
'default', $arrayforbutactivate,
'', $permissiontoadd);
525 if (in_array(
$object->status, array($object::STATUS_AUTOMATIC_TRIGGER, $object::STATUS_MANUAL_TRIGGER))) {
526 print
dolGetButtonAction(
'', $langs->trans(
'Disable'),
'delete', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=confirm_setdraft&confirm=yes&token='.
newToken(),
'', $permissiontoadd);
530 print
dolGetButtonAction($langs->trans(
'Delete'),
'',
'delete', $_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=delete&token='.
newToken(),
'', $permissiontodelete);
536if ($action ==
"test") {
537 print
'<div id="formtesttarget" name="formtesttarget"></div>';
541 print
"\n".
'<!-- Begin form test target --><div id="targettestform"></div>'.
"\n";
542 print
'<form method="POST" name="testtargetform" id="testtargetform" enctype="multipart/form-data" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'">';
543 print
'<input type="hidden" name="token" value="'.newToken().
'">';
544 print
'<input type="hidden" name="action" value="testsendtourl">';
546 print
'<table class="tableforemailform boxtablenotop centpercent">';
548 print
'<tr><td class="titlefieldcreate fieldrequired minwidth200">';
549 print $langs->trans(
"TriggerCodes");
550 print
'</td><td class="valuefieldcreate">';
551 $arraytriggercodes = explode(
",",
$object->trigger_codes);
553 if (in_array(
GETPOST(
"triggercodes"), $arraytriggercodes)) {
554 $idtriggercode = array_search(
GETPOST(
"triggercodes"), $arraytriggercodes);
556 print $form->selectarray(
"triggercode", $arraytriggercodes, $idtriggercode, 0, 0, 1);
559 print
'<tr><td class="titlefieldcreate fieldrequired minwidth200">';
560 print $langs->trans(
"Url");
561 print
'</td><td class="valuefieldcreate">';
562 print
'<input class="flat minwidth400" name="url" value="'.(GETPOSTISSET(
"url") ?
GETPOST(
"url") :
$object->url).
'" />';
566 print
'<tr><td class="titlefieldcreate fieldrequired minwidth200">';
567 print $langs->trans(
"DataToSendTrigger");
571 $json->triggercode =
"TEST_TRIGGER_CODE";
573 $json->object->field1 =
'field1';
574 $json->object->field2 =
'field2';
575 $json->object->field3 =
'field3';
577 $datatosend = json_encode($json);
585 print
'<textarea id="jsondata" class="flat minwidth100" style="margin-top: 5px; width: 95%" rows="8" name="jsondata">';
592 print
'<div class="center">';
593 print $form->buttonsSaveCancel(
"SendToUrl");
597 if ($conf->use_javascript_ajax) {
599 $("#triggercode").change(function(){
600 console.log("We change trigger code");
601 triggercode = $(this).val();
602 getDatatToSendTriggerCode(triggercode);
605 function getDatatToSendTriggerCode(triggercode){
608 url: \''.DOL_URL_ROOT.
'/webhook/ajax/webhook.php\',
609 data: { action: "getjsonformtrigger", triggercode: triggercode , token:"'.
currentToken().
'"},
610 success: function(response) {
611 obj = JSON.stringify(response);
612 $("#jsondata").val(obj);
617 $(document).ready(function () {
618 triggercode = $("#triggercode").val();
619 getDatatToSendTriggerCode(triggercode);
625 print
"\n".
'<!-- END form test target -->';
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $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.
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1, $timeoutconnect=0, $timeoutresponse=0, $otherCurlOptions=array())
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.