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