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