dolibarr  16.0.5
myobject_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('/mymodule/class/myobject.class.php');
82 dol_include_once('/mymodule/lib/mymodule_myobject.lib.php');
83 
84 // Load translation files required by the page
85 $langs->loadLangs(array("mymodule@mymodule", "other"));
86 
87 // Get parameters
88 $id = GETPOST('id', 'int');
89 $ref = GETPOST('ref', 'alpha');
90 $lineid = GETPOST('lineid', 'int');
91 
92 $action = GETPOST('action', 'aZ09');
93 $confirm = GETPOST('confirm', 'alpha');
94 $cancel = GETPOST('cancel', 'aZ09');
95 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
96 $backtopage = GETPOST('backtopage', 'alpha');
97 $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
98 $dol_openinpopup = GETPOST('dol_openinpopup', 'aZ09');
99 
100 // Initialize technical objects
101 $object = new MyObject($db);
102 $extrafields = new ExtraFields($db);
103 $diroutputmassaction = $conf->mymodule->dir_output.'/temp/massgeneration/'.$user->id;
104 $hookmanager->initHooks(array('myobjectcard', 'globalcard')); // Note that conf->hooks_modules contains array
105 
106 // Fetch optionals attributes and labels
107 $extrafields->fetch_name_optionals_label($object->table_element);
108 
109 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
110 
111 // Initialize array of search criterias
112 $search_all = GETPOST("search_all", 'alpha');
113 $search = array();
114 foreach ($object->fields as $key => $val) {
115  if (GETPOST('search_'.$key, 'alpha')) {
116  $search[$key] = GETPOST('search_'.$key, 'alpha');
117  }
118 }
119 
120 if (empty($action) && empty($id) && empty($ref)) {
121  $action = 'view';
122 }
123 
124 // Load object
125 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
126 
127 // There is several ways to check permission.
128 // Set $enablepermissioncheck to 1 to enable a minimum low level of checks
129 $enablepermissioncheck = 0;
130 if ($enablepermissioncheck) {
131  $permissiontoread = $user->rights->mymodule->myobject->read;
132  $permissiontoadd = $user->rights->mymodule->myobject->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
133  $permissiontodelete = $user->rights->mymodule->myobject->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
134  $permissionnote = $user->rights->mymodule->myobject->write; // Used by the include of actions_setnotes.inc.php
135  $permissiondellink = $user->rights->mymodule->myobject->write; // Used by the include of actions_dellink.inc.php
136 } else {
137  $permissiontoread = 1;
138  $permissiontoadd = 1; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
139  $permissiontodelete = 1;
140  $permissionnote = 1;
141  $permissiondellink = 1;
142 }
143 
144 $upload_dir = $conf->mymodule->multidir_output[isset($object->entity) ? $object->entity : 1].'/myobject';
145 
146 // Security check (enable the most restrictive one)
147 //if ($user->socid > 0) accessforbidden();
148 //if ($user->socid > 0) $socid = $user->socid;
149 //$isdraft = (isset($object->status) && ($object->status == $object::STATUS_DRAFT) ? 1 : 0);
150 //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
151 if (empty($conf->mymodule->enabled)) accessforbidden();
152 if (!$permissiontoread) accessforbidden();
153 
154 
155 /*
156  * Actions
157  */
158 
159 $parameters = array();
160 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
161 if ($reshook < 0) {
162  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
163 }
164 
165 if (empty($reshook)) {
166  $error = 0;
167 
168  $backurlforlist = dol_buildpath('/mymodule/myobject_list.php', 1);
169 
170  if (empty($backtopage) || ($cancel && empty($id))) {
171  if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
172  if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
173  $backtopage = $backurlforlist;
174  } else {
175  $backtopage = dol_buildpath('/mymodule/myobject_card.php', 1).'?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
176  }
177  }
178  }
179 
180  $triggermodname = 'MYMODULE_MYOBJECT_MODIFY'; // Name of trigger action code to execute when we modify record
181 
182  // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
183  include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
184 
185  // Actions when linking object each other
186  include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
187 
188  // Actions when printing a doc from card
189  include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
190 
191  // Action to move up and down lines of object
192  //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
193 
194  // Action to build doc
195  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
196 
197  if ($action == 'set_thirdparty' && $permissiontoadd) {
198  $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, $triggermodname);
199  }
200  if ($action == 'classin' && $permissiontoadd) {
201  $object->setProject(GETPOST('projectid', 'int'));
202  }
203 
204  // Actions to send emails
205  $triggersendname = 'MYMODULE_MYOBJECT_SENTBYMAIL';
206  $autocopy = 'MAIN_MAIL_AUTOCOPY_MYOBJECT_TO';
207  $trackid = 'myobject'.$object->id;
208  include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
209 }
210 
211 
212 
213 
214 /*
215  * View
216  *
217  * Put here all code to build page
218  */
219 
220 $form = new Form($db);
221 $formfile = new FormFile($db);
222 $formproject = new FormProjets($db);
223 
224 $title = $langs->trans("MyObject");
225 $help_url = '';
226 llxHeader('', $title, $help_url);
227 
228 // Example : Adding jquery code
229 // print '<script type="text/javascript">
230 // jQuery(document).ready(function() {
231 // function init_myfunc()
232 // {
233 // jQuery("#myid").removeAttr(\'disabled\');
234 // jQuery("#myid").attr(\'disabled\',\'disabled\');
235 // }
236 // init_myfunc();
237 // jQuery("#mybutton").click(function() {
238 // init_myfunc();
239 // });
240 // });
241 // </script>';
242 
243 
244 // Part to create
245 if ($action == 'create') {
246  if (empty($permissiontoadd)) {
247  accessforbidden($langs->trans('NotEnoughPermissions'), 0, 1);
248  exit;
249  }
250 
251  print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("MyObject")), '', 'object_'.$object->picto);
252 
253  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
254  print '<input type="hidden" name="token" value="'.newToken().'">';
255  print '<input type="hidden" name="action" value="add">';
256  if ($backtopage) {
257  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
258  }
259  if ($backtopageforcancel) {
260  print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
261  }
262 
263  print dol_get_fiche_head(array(), '');
264 
265  // Set some default values
266  //if (! GETPOSTISSET('fieldname')) $_POST['fieldname'] = 'myvalue';
267 
268  print '<table class="border centpercent tableforfieldcreate">'."\n";
269 
270  // Common attributes
271  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
272 
273  // Other attributes
274  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
275 
276  print '</table>'."\n";
277 
278  print dol_get_fiche_end();
279 
280  print $form->buttonsSaveCancel("Create");
281 
282  print '</form>';
283 
284  //dol_set_focus('input[name="ref"]');
285 }
286 
287 // Part to edit record
288 if (($id || $ref) && $action == 'edit') {
289  print load_fiche_titre($langs->trans("MyObject"), '', 'object_'.$object->picto);
290 
291  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
292  print '<input type="hidden" name="token" value="'.newToken().'">';
293  print '<input type="hidden" name="action" value="update">';
294  print '<input type="hidden" name="id" value="'.$object->id.'">';
295  if ($backtopage) {
296  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
297  }
298  if ($backtopageforcancel) {
299  print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
300  }
301 
302  print dol_get_fiche_head();
303 
304  print '<table class="border centpercent tableforfieldedit">'."\n";
305 
306  // Common attributes
307  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
308 
309  // Other attributes
310  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
311 
312  print '</table>';
313 
314  print dol_get_fiche_end();
315 
316  print $form->buttonsSaveCancel();
317 
318  print '</form>';
319 }
320 
321 // Part to show record
322 if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
323  $res = $object->fetch_optionals();
324 
325  $head = myobjectPrepareHead($object);
326  print dol_get_fiche_head($head, 'card', $langs->trans("MyObject"), -1, $object->picto);
327 
328  $formconfirm = '';
329 
330  // Confirmation to delete
331  if ($action == 'delete') {
332  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteMyObject'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
333  }
334  // Confirmation to delete line
335  if ($action == 'deleteline') {
336  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
337  }
338 
339  // Clone confirmation
340  if ($action == 'clone') {
341  // Create an array for form
342  $formquestion = array();
343  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
344  }
345 
346  // Confirmation of action xxxx (You can use it for xxx = 'close', xxx = 'reopen', ...)
347  if ($action == 'xxx') {
348  $text = $langs->trans('ConfirmActionMyObject', $object->ref);
349  /*if (! empty($conf->notification->enabled))
350  {
351  require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
352  $notify = new Notify($db);
353  $text .= '<br>';
354  $text .= $notify->confirmMessage('MYOBJECT_CLOSE', $object->socid, $object);
355  }*/
356 
357  $formquestion = array();
358  /*
359  $forcecombo=0;
360  if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
361  $formquestion = array(
362  // 'text' => $langs->trans("ConfirmClone"),
363  // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
364  // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
365  // array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
366  );
367  */
368  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220);
369  }
370 
371  // Call Hook formConfirm
372  $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
373  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
374  if (empty($reshook)) {
375  $formconfirm .= $hookmanager->resPrint;
376  } elseif ($reshook > 0) {
377  $formconfirm = $hookmanager->resPrint;
378  }
379 
380  // Print form confirm
381  print $formconfirm;
382 
383 
384  // Object card
385  // ------------------------------------------------------------
386  $linkback = '<a href="'.dol_buildpath('/mymodule/myobject_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
387 
388  $morehtmlref = '<div class="refidno">';
389  /*
390  // Ref customer
391  $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
392  $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
393  // Thirdparty
394  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
395  // Project
396  if (! empty($conf->project->enabled)) {
397  $langs->load("projects");
398  $morehtmlref .= '<br>'.$langs->trans('Project') . ' ';
399  if ($permissiontoadd) {
400  //if ($action != 'classify') $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
401  $morehtmlref .= ' : ';
402  if ($action == 'classify') {
403  //$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
404  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
405  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
406  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
407  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
408  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
409  $morehtmlref .= '</form>';
410  } else {
411  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
412  }
413  } else {
414  if (! empty($object->fk_project)) {
415  $proj = new Project($db);
416  $proj->fetch($object->fk_project);
417  $morehtmlref .= ': '.$proj->getNomUrl();
418  } else {
419  $morehtmlref .= '';
420  }
421  }
422  }*/
423  $morehtmlref .= '</div>';
424 
425 
426  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
427 
428 
429  print '<div class="fichecenter">';
430  print '<div class="fichehalfleft">';
431  print '<div class="underbanner clearboth"></div>';
432  print '<table class="border centpercent tableforfield">'."\n";
433 
434  // Common attributes
435  //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
436  //unset($object->fields['fk_project']); // Hide field already shown in banner
437  //unset($object->fields['fk_soc']); // Hide field already shown in banner
438  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
439 
440  // Other attributes. Fields from hook formObjectOptions and Extrafields.
441  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
442 
443  print '</table>';
444  print '</div>';
445  print '</div>';
446 
447  print '<div class="clearboth"></div>';
448 
449  print dol_get_fiche_end();
450 
451 
452  /*
453  * Lines
454  */
455 
456  if (!empty($object->table_element_line)) {
457  // Show object lines
458  $result = $object->getLinesArray();
459 
460  print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">
461  <input type="hidden" name="token" value="' . newToken().'">
462  <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
463  <input type="hidden" name="mode" value="">
464  <input type="hidden" name="page_y" value="">
465  <input type="hidden" name="id" value="' . $object->id.'">
466  ';
467 
468  if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
469  include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
470  }
471 
472  print '<div class="div-table-responsive-no-min">';
473  if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
474  print '<table id="tablelines" class="noborder noshadow" width="100%">';
475  }
476 
477  if (!empty($object->lines)) {
478  $object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1);
479  }
480 
481  // Form to add new line
482  if ($object->status == 0 && $permissiontoadd && $action != 'selectlines') {
483  if ($action != 'editline') {
484  // Add products/services form
485 
486  $parameters = array();
487  $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
488  if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
489  if (empty($reshook))
490  $object->formAddObjectLine(1, $mysoc, $soc);
491  }
492  }
493 
494  if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
495  print '</table>';
496  }
497  print '</div>';
498 
499  print "</form>\n";
500  }
501 
502 
503  // Buttons for actions
504 
505  if ($action != 'presend' && $action != 'editline') {
506  print '<div class="tabsAction">'."\n";
507  $parameters = array();
508  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
509  if ($reshook < 0) {
510  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
511  }
512 
513  if (empty($reshook)) {
514  // Send
515  if (empty($user->socid)) {
516  print dolGetButtonAction($langs->trans('SendMail'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init&token='.newToken().'#formmailbeforetitle');
517  }
518 
519  // Back to draft
520  if ($object->status == $object::STATUS_VALIDATED) {
521  print dolGetButtonAction($langs->trans('SetToDraft'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes&token='.newToken(), '', $permissiontoadd);
522  }
523 
524  print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken(), '', $permissiontoadd);
525 
526  // Validate
527  if ($object->status == $object::STATUS_DRAFT) {
528  if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
529  print dolGetButtonAction($langs->trans('Validate'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_validate&confirm=yes&token='.newToken(), '', $permissiontoadd);
530  } else {
531  $langs->load("errors");
532  print dolGetButtonAction($langs->trans("ErrorAddAtLeastOneLineFirst"), $langs->trans("Validate"), 'default', '#', '', 0);
533  }
534  }
535 
536  // Clone
537  print dolGetButtonAction($langs->trans('ToClone'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.(!empty($object->socid)?'&socid='.$object->socid:'').'&action=clone&token='.newToken(), '', $permissiontoadd);
538 
539  /*
540  if ($permissiontoadd) {
541  if ($object->status == $object::STATUS_ENABLED) {
542  print dolGetButtonAction($langs->trans('Disable'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=disable&token='.newToken(), '', $permissiontoadd);
543  } else {
544  print dolGetButtonAction($langs->trans('Enable'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=enable&token='.newToken(), '', $permissiontoadd);
545  }
546  }
547  if ($permissiontoadd) {
548  if ($object->status == $object::STATUS_VALIDATED) {
549  print dolGetButtonAction($langs->trans('Cancel'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=close&token='.newToken(), '', $permissiontoadd);
550  } else {
551  print dolGetButtonAction($langs->trans('Re-Open'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=reopen&token='.newToken(), '', $permissiontoadd);
552  }
553  }
554  */
555 
556  // Delete (need delete permission, or if draft, just need create/modify permission)
557  print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken(), '', $permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd));
558  }
559  print '</div>'."\n";
560  }
561 
562 
563  // Select mail models is same action as presend
564  if (GETPOST('modelselected')) {
565  $action = 'presend';
566  }
567 
568  if ($action != 'presend') {
569  print '<div class="fichecenter"><div class="fichehalfleft">';
570  print '<a name="builddoc"></a>'; // ancre
571 
572  $includedocgeneration = 0;
573 
574  // Documents
575  if ($includedocgeneration) {
576  $objref = dol_sanitizeFileName($object->ref);
577  $relativepath = $objref.'/'.$objref.'.pdf';
578  $filedir = $conf->mymodule->dir_output.'/'.$object->element.'/'.$objref;
579  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
580  $genallowed = $permissiontoread; // If you can read, you can build the PDF to read content
581  $delallowed = $permissiontoadd; // If you can create/edit, you can remove a file on card
582  print $formfile->showdocuments('mymodule:MyObject', $object->element.'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
583  }
584 
585  // Show links to link elements
586  $linktoelem = $form->showLinkToObjectBlock($object, null, array('myobject'));
587  $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
588 
589 
590  print '</div><div class="fichehalfright">';
591 
592  $MAXEVENT = 10;
593 
594  $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id);
595 
596  // List of actions on element
597  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
598  $formactions = new FormActions($db);
599  $somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
600 
601  print '</div></div>';
602  }
603 
604  //Select mail models is same action as presend
605  if (GETPOST('modelselected')) {
606  $action = 'presend';
607  }
608 
609  // Presend form
610  $modelmail = 'myobject';
611  $defaulttopic = 'InformationMessage';
612  $diroutput = $conf->mymodule->dir_output;
613  $trackid = 'myobject'.$object->id;
614 
615  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
616 }
617 
618 // End of page
619 llxFooter();
620 $db->close();
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
FormActions
Class to manage building of HTML components.
Definition: html.formactions.class.php:30
dol_include_once
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
Definition: functions.lib.php:1033
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
FormProjets
Class to manage building of HTML components.
Definition: html.formprojet.class.php:30
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dolGetButtonAction
dolGetButtonAction($label, $html='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
Definition: functions.lib.php:10450
dol_banner_tab
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.
Definition: functions.lib.php:2046
$help_url
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
$formactions
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.
Definition: agenda_other.php:178
$formconfirm
$formconfirm
if ($action == 'delbookkeepingyear') {
Definition: listbyaccount.php:576
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
dolGetButtonTitle
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.
Definition: functions.lib.php:10605
myobjectPrepareHead
myobjectPrepareHead($object)
Prepare array of tabs for MyObject.
Definition: mymodule_myobject.lib.php:30
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
MyObject
Class for MyObject.
Definition: myobject.class.php:33
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
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 ...
Definition: security.lib.php:933
llxHeader
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