dolibarr  16.0.1
target_card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) ---Put here your own copyright and developer email---
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 //if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db
26 //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user
27 //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc
28 //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs
29 //if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters
30 //if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters
31 //if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); // Do not check CSRF attack (test on referer + on token).
32 //if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
33 //if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data
34 //if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
35 //if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
36 //if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
37 //if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too.
38 //if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
39 //if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value
40 //if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler
41 //if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN', 1); // The main.inc.php does not make a redirect if not logged, instead show simple error message
42 //if (! defined("FORCECSP")) define('FORCECSP', 'none'); // Disable all Content Security Policies
43 //if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
44 //if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification
45 //if (! defined('NOSESSION')) define('NOSESSION', '1'); // Disable session
46 
47 // Load Dolibarr environment
48 $res = 0;
49 // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
50 if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
51  $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
52 }
53 // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
54 $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
55 while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
56  $i--; $j--;
57 }
58 if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
59  $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
60 }
61 if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
62  $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
63 }
64 // Try main.inc.php using relative path
65 if (!$res && file_exists("../main.inc.php")) {
66  $res = @include "../main.inc.php";
67 }
68 if (!$res && file_exists("../../main.inc.php")) {
69  $res = @include "../../main.inc.php";
70 }
71 if (!$res && file_exists("../../../main.inc.php")) {
72  $res = @include "../../../main.inc.php";
73 }
74 if (!$res) {
75  die("Include of main fails");
76 }
77 
78 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
79 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
80 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
81 dol_include_once('/webhook/class/target.class.php');
82 dol_include_once('/webhook/lib/webhook_target.lib.php');
83 
84 // Load translation files required by the page
85 $langs->loadLangs(array("webhook@webhook", "other"));
86 
87 // Get parameters
88 $id = GETPOST('id', 'int');
89 $ref = GETPOST('ref', 'alpha');
90 $action = GETPOST('action', 'aZ09');
91 $confirm = GETPOST('confirm', 'alpha');
92 $cancel = GETPOST('cancel', 'aZ09');
93 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'targetcard'; // To manage different context of search
94 $backtopage = GETPOST('backtopage', 'alpha');
95 $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
96 $lineid = GETPOST('lineid', 'int');
97 
98 // Initialize technical objects
99 $object = new Target($db);
100 $extrafields = new ExtraFields($db);
101 $diroutputmassaction = $conf->webhook->dir_output.'/temp/massgeneration/'.$user->id;
102 $hookmanager->initHooks(array('targetcard', 'globalcard')); // Note that conf->hooks_modules contains array
103 
104 // Fetch optionals attributes and labels
105 $extrafields->fetch_name_optionals_label($object->table_element);
106 
107 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
108 
109 // Initialize array of search criterias
110 $search_all = GETPOST("search_all", 'alpha');
111 $search = array();
112 foreach ($object->fields as $key => $val) {
113  if (GETPOST('search_'.$key, 'alpha')) {
114  $search[$key] = GETPOST('search_'.$key, 'alpha');
115  }
116 }
117 
118 if (empty($action) && empty($id) && empty($ref)) {
119  $action = 'view';
120 }
121 
122 // Load object
123 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
124 
125 // There is several ways to check permission.
126 // Set $enablepermissioncheck to 1 to enable a minimum low level of checks
127 $enablepermissioncheck = 0;
128 if ($enablepermissioncheck) {
129  $permissiontoread = $user->rights->webhook->target->read;
130  $permissiontoadd = $user->rights->webhook->target->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
131  $permissiontodelete = $user->rights->webhook->target->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
132  $permissionnote = $user->rights->webhook->target->write; // Used by the include of actions_setnotes.inc.php
133  $permissiondellink = $user->rights->webhook->target->write; // Used by the include of actions_dellink.inc.php
134 } else {
135  $permissiontoread = 1;
136  $permissiontoadd = 1; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
137  $permissiontodelete = 1;
138  $permissionnote = 1;
139  $permissiondellink = 1;
140 }
141 
142 $upload_dir = $conf->webhook->multidir_output[isset($object->entity) ? $object->entity : 1].'/target';
143 
144 // Security check (enable the most restrictive one)
145 //if ($user->socid > 0) accessforbidden();
146 //if ($user->socid > 0) $socid = $user->socid;
147 //$isdraft = (isset($object->status) && ($object->status == $object::STATUS_DRAFT) ? 1 : 0);
148 //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
149 if (empty($conf->webhook->enabled)) accessforbidden();
150 if (!$permissiontoread) accessforbidden();
151 
152 
153 /*
154  * Actions
155  */
156 
157 $parameters = array();
158 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
159 if ($reshook < 0) {
160  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
161 }
162 
163 if (empty($reshook)) {
164  $error = 0;
165 
166  $backurlforlist = dol_buildpath('/webhook/target_list.php?mode=modulesetup', 1);
167 
168  if (empty($backtopage) || ($cancel && empty($id))) {
169  if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
170  if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
171  $backtopage = $backurlforlist;
172  } else {
173  $backtopage = dol_buildpath('/webhook/target_card.php', 1).'?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
174  }
175  }
176  }
177 
178  $triggermodname = 'WEBHOOK_TARGET_MODIFY'; // Name of trigger action code to execute when we modify record
179 
180  // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
181  include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
182 
183  // Actions when linking object each other
184  include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
185 
186  // Actions when printing a doc from card
187  include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
188 
189  // Action to move up and down lines of object
190  //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
191 
192  // Action to build doc
193  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
194 
195  if ($action == 'set_thirdparty' && $permissiontoadd) {
196  $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, $triggermodname);
197  }
198  if ($action == 'classin' && $permissiontoadd) {
199  $object->setProject(GETPOST('projectid', 'int'));
200  }
201 
202  // Actions to send emails
203  $triggersendname = 'WEBHOOK_TARGET_SENTBYMAIL';
204  $autocopy = 'MAIN_MAIL_AUTOCOPY_TARGET_TO';
205  $trackid = 'target'.$object->id;
206  include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
207 }
208 
209 
210 
211 
212 /*
213  * View
214  *
215  * Put here all code to build page
216  */
217 
218 $form = new Form($db);
219 $formfile = new FormFile($db);
220 $formproject = new FormProjets($db);
221 
222 $title = $langs->trans("Target");
223 $help_url = '';
224 llxHeader('', $title, $help_url);
225 
226 // Example : Adding jquery code
227 // print '<script type="text/javascript">
228 // jQuery(document).ready(function() {
229 // function init_myfunc()
230 // {
231 // jQuery("#myid").removeAttr(\'disabled\');
232 // jQuery("#myid").attr(\'disabled\',\'disabled\');
233 // }
234 // init_myfunc();
235 // jQuery("#mybutton").click(function() {
236 // init_myfunc();
237 // });
238 // });
239 // </script>';
240 
241 
242 // Part to create
243 if ($action == 'create') {
244  if (empty($permissiontoadd)) {
245  accessforbidden($langs->trans('NotEnoughPermissions'), 0, 1);
246  exit;
247  }
248 
249  print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("Target")), '', 'object_'.$object->picto);
250 
251  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
252  print '<input type="hidden" name="token" value="'.newToken().'">';
253  print '<input type="hidden" name="action" value="add">';
254  if ($backtopage) {
255  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
256  }
257  if ($backtopageforcancel) {
258  print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
259  }
260 
261  print dol_get_fiche_head(array(), '');
262 
263  // Set some default values
264  //if (! GETPOSTISSET('fieldname')) $_POST['fieldname'] = 'myvalue';
265 
266  print '<table class="border centpercent tableforfieldcreate">'."\n";
267 
268  // Common attributes
269  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
270 
271  // Other attributes
272  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
273 
274  print '</table>'."\n";
275 
276  print dol_get_fiche_end();
277 
278  print $form->buttonsSaveCancel("Create");
279 
280  print '</form>';
281 
282  //dol_set_focus('input[name="ref"]');
283 }
284 
285 // Part to edit record
286 if (($id || $ref) && $action == 'edit') {
287  print load_fiche_titre($langs->trans("Target"), '', 'object_'.$object->picto);
288 
289  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
290  print '<input type="hidden" name="token" value="'.newToken().'">';
291  print '<input type="hidden" name="action" value="update">';
292  print '<input type="hidden" name="id" value="'.$object->id.'">';
293  if ($backtopage) {
294  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
295  }
296  if ($backtopageforcancel) {
297  print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
298  }
299 
300  print dol_get_fiche_head();
301 
302  print '<table class="border centpercent tableforfieldedit">'."\n";
303 
304  // Common attributes
305  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
306 
307  // Other attributes
308  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
309 
310  print '</table>';
311 
312  print dol_get_fiche_end();
313 
314  print $form->buttonsSaveCancel();
315 
316  print '</form>';
317 }
318 
319 // Part to show record
320 if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
321  $res = $object->fetch_optionals();
322 
323  $head = targetPrepareHead($object);
324  print dol_get_fiche_head($head, 'card', $langs->trans("Target"), -1, $object->picto);
325 
326  $formconfirm = '';
327 
328  // Confirmation to delete
329  if ($action == 'delete') {
330  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteTarget'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
331  }
332  // Confirmation to delete line
333  if ($action == 'deleteline') {
334  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
335  }
336 
337  // Clone confirmation
338  if ($action == 'clone') {
339  // Create an array for form
340  $formquestion = array();
341  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
342  }
343 
344  // Confirmation of action xxxx (You can use it for xxx = 'close', xxx = 'reopen', ...)
345  if ($action == 'xxx') {
346  $text = $langs->trans('ConfirmActionTarget', $object->ref);
347  /*if (! empty($conf->notification->enabled))
348  {
349  require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
350  $notify = new Notify($db);
351  $text .= '<br>';
352  $text .= $notify->confirmMessage('TARGET_CLOSE', $object->socid, $object);
353  }*/
354 
355  $formquestion = array();
356  /*
357  $forcecombo=0;
358  if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
359  $formquestion = array(
360  // 'text' => $langs->trans("ConfirmClone"),
361  // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
362  // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
363  // array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
364  );
365  */
366  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220);
367  }
368 
369  // Call Hook formConfirm
370  $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
371  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
372  if (empty($reshook)) {
373  $formconfirm .= $hookmanager->resPrint;
374  } elseif ($reshook > 0) {
375  $formconfirm = $hookmanager->resPrint;
376  }
377 
378  // Print form confirm
379  print $formconfirm;
380 
381 
382  // Object card
383  // ------------------------------------------------------------
384  $linkback = '<a href="'.dol_buildpath('/webhook/target_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
385 
386  $morehtmlref = '<div class="refidno">';
387  /*
388  // Ref customer
389  $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
390  $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
391  // Thirdparty
392  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
393  // Project
394  if (! empty($conf->projet->enabled)) {
395  $langs->load("projects");
396  $morehtmlref .= '<br>'.$langs->trans('Project') . ' ';
397  if ($permissiontoadd) {
398  //if ($action != 'classify') $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
399  $morehtmlref .= ' : ';
400  if ($action == 'classify') {
401  //$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
402  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
403  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
404  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
405  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
406  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
407  $morehtmlref .= '</form>';
408  } else {
409  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
410  }
411  } else {
412  if (! empty($object->fk_project)) {
413  $proj = new Project($db);
414  $proj->fetch($object->fk_project);
415  $morehtmlref .= ': '.$proj->getNomUrl();
416  } else {
417  $morehtmlref .= '';
418  }
419  }
420  }*/
421  $morehtmlref .= '</div>';
422 
423 
424  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
425 
426 
427  print '<div class="fichecenter">';
428  print '<div class="fichehalfleft">';
429  print '<div class="underbanner clearboth"></div>';
430  print '<table class="border centpercent tableforfield">'."\n";
431 
432  // Common attributes
433  //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
434  //unset($object->fields['fk_project']); // Hide field already shown in banner
435  //unset($object->fields['fk_soc']); // Hide field already shown in banner
436  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
437 
438  // Other attributes. Fields from hook formObjectOptions and Extrafields.
439  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
440 
441  print '</table>';
442  print '</div>';
443  print '</div>';
444 
445  print '<div class="clearboth"></div>';
446 
447  print dol_get_fiche_end();
448 
449 
450  /*
451  * Lines
452  */
453 
454  if (!empty($object->table_element_line)) {
455  // Show object lines
456  $result = $object->getLinesArray();
457 
458  print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">
459  <input type="hidden" name="token" value="' . newToken().'">
460  <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
461  <input type="hidden" name="mode" value="">
462  <input type="hidden" name="page_y" value="">
463  <input type="hidden" name="id" value="' . $object->id.'">
464  ';
465 
466  if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
467  include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
468  }
469 
470  print '<div class="div-table-responsive-no-min">';
471  if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
472  print '<table id="tablelines" class="noborder noshadow" width="100%">';
473  }
474 
475  if (!empty($object->lines)) {
476  $object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1);
477  }
478 
479  // Form to add new line
480  if ($object->status == 0 && $permissiontoadd && $action != 'selectlines') {
481  if ($action != 'editline') {
482  // Add products/services form
483 
484  $parameters = array();
485  $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
486  if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
487  if (empty($reshook))
488  $object->formAddObjectLine(1, $mysoc, $soc);
489  }
490  }
491 
492  if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
493  print '</table>';
494  }
495  print '</div>';
496 
497  print "</form>\n";
498  }
499 
500 
501  // Buttons for actions
502 
503  if ($action != 'presend' && $action != 'editline') {
504  print '<div class="tabsAction">'."\n";
505  $parameters = array();
506  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
507  if ($reshook < 0) {
508  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
509  }
510 
511  if (empty($reshook)) {
512  // Send
513  if (empty($user->socid)) {
514  print dolGetButtonAction($langs->trans('SendMail'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init&token='.newToken().'#formmailbeforetitle');
515  }
516 
517  // Back to draft
518  if ($object->status == $object::STATUS_VALIDATED) {
519  print dolGetButtonAction($langs->trans('SetToDraft'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes&token='.newToken(), '', $permissiontoadd);
520  }
521 
522  print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken(), '', $permissiontoadd);
523 
524  // Validate
525  if ($object->status == $object::STATUS_DRAFT) {
526  if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
527  print dolGetButtonAction($langs->trans('Validate'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_validate&confirm=yes&token='.newToken(), '', $permissiontoadd);
528  } else {
529  $langs->load("errors");
530  print dolGetButtonAction($langs->trans("ErrorAddAtLeastOneLineFirst"), $langs->trans("Validate"), 'default', '#', '', 0);
531  }
532  }
533 
534  // Clone
535  print dolGetButtonAction($langs->trans('ToClone'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=clone&token='.newToken(), '', $permissiontoadd);
536 
537  /*
538  if ($permissiontoadd) {
539  if ($object->status == $object::STATUS_ENABLED) {
540  print dolGetButtonAction($langs->trans('Disable'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=disable&token='.newToken(), '', $permissiontoadd);
541  } else {
542  print dolGetButtonAction($langs->trans('Enable'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=enable&token='.newToken(), '', $permissiontoadd);
543  }
544  }
545  if ($permissiontoadd) {
546  if ($object->status == $object::STATUS_VALIDATED) {
547  print dolGetButtonAction($langs->trans('Cancel'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=close&token='.newToken(), '', $permissiontoadd);
548  } else {
549  print dolGetButtonAction($langs->trans('Re-Open'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=reopen&token='.newToken(), '', $permissiontoadd);
550  }
551  }
552  */
553 
554  // Delete (need delete permission, or if draft, just need create/modify permission)
555  print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken(), '', $permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd));
556  }
557  print '</div>'."\n";
558  }
559 
560 
561  // Select mail models is same action as presend
562  if (GETPOST('modelselected')) {
563  $action = 'presend';
564  }
565 
566  if ($action != 'presend') {
567  print '<div class="fichecenter"><div class="fichehalfleft">';
568  print '<a name="builddoc"></a>'; // ancre
569 
570  $includedocgeneration = 0;
571 
572  // Documents
573  if ($includedocgeneration) {
574  $objref = dol_sanitizeFileName($object->ref);
575  $relativepath = $objref.'/'.$objref.'.pdf';
576  $filedir = $conf->webhook->dir_output.'/'.$object->element.'/'.$objref;
577  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
578  $genallowed = $permissiontoread; // If you can read, you can build the PDF to read content
579  $delallowed = $permissiontoadd; // If you can create/edit, you can remove a file on card
580  print $formfile->showdocuments('webhook:Target', $object->element.'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
581  }
582 
583  // Show links to link elements
584  $linktoelem = $form->showLinkToObjectBlock($object, null, array('target'));
585  $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
586 
587 
588  print '</div><div class="fichehalfright">';
589 
590  $MAXEVENT = 10;
591 
592  $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-list-alt imgforviewmode', dol_buildpath('/webhook/target_agenda.php', 1).'?id='.$object->id);
593 
594  // List of actions on element
595  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
596  $formactions = new FormActions($db);
597  $somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
598 
599  print '</div></div>';
600  }
601 
602  //Select mail models is same action as presend
603  if (GETPOST('modelselected')) {
604  $action = 'presend';
605  }
606 
607  // Presend form
608  $modelmail = 'target';
609  $defaulttopic = 'InformationMessage';
610  $diroutput = $conf->webhook->dir_output;
611  $trackid = 'target'.$object->id;
612 
613  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
614 }
615 
616 // End of page
617 llxFooter();
618 $db->close();
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action== 'set') elseif($action== 'specimen') elseif($action== 'setmodel') elseif($action== 'del') elseif($action== 'setdoc') $formactions
View.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
Class to manage building of HTML components.
dolGetButtonTitle($label, $helpText= '', $iconClass= 'fa fa-file', $url= '', $id= '', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
targetPrepareHead($object)
Prepare array of tabs for Target.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
dolGetButtonAction($label, $html= '', $actionType= 'default', $url= '', $id= '', $userRight=1, $params=array())
Function dolGetButtonAction.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save"&&empty($cancel)) $help_url
View.
Definition: agenda.php:116
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
Class to manage building of HTML components.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
Class for Target.
Class to offer components to list and upload files.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:73
$formconfirm
if ($action == &#39;delbookkeepingyear&#39;) {