dolibarr 21.0.0-beta
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
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
26// Load Dolibarr environment
27require '../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT . '/core/lib/asset.lib.php';
29require_once DOL_DOCUMENT_ROOT . '/asset/class/assetmodel.class.php';
30require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
31require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
32require_once DOL_DOCUMENT_ROOT . '/asset/class/assetdepreciationoptions.class.php';
33require_once DOL_DOCUMENT_ROOT . '/asset/class/assetaccountancycodes.class.php';
34
43// Load translation files required by the page
44$langs->loadLangs(array("assets", "other"));
45
46// Get parameters
47$id = GETPOSTINT('id');
48$ref = GETPOST('ref', 'alpha');
49$action = GETPOST('action', 'aZ09');
50$confirm = GETPOST('confirm', 'alpha');
51$cancel = GETPOST('cancel', 'aZ09');
52$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'assetmodelcard'; // To manage different context of search
53$backtopage = GETPOST('backtopage', 'alpha');
54$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
55
56// Initialize a technical objects
57$object = new AssetModel($db);
58$assetdepreciationoptions = new AssetDepreciationOptions($db);
59$assetaccountancycodes = new AssetAccountancyCodes($db);
60$extrafields = new ExtraFields($db);
61$diroutputmassaction = $conf->asset->dir_output . '/temp/massgeneration/' . $user->id;
62$hookmanager->initHooks(array('assetmodelcard', 'globalcard')); // Note that conf->hooks_modules contains array
63
64// Fetch optionals attributes and labels
65$extrafields->fetch_name_optionals_label($object->table_element);
66
67$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
68
69// Initialize array of search criteria
70$search_all = GETPOST("search_all", 'alpha');
71$search = array();
72foreach ($object->fields as $key => $val) {
73 if (GETPOST('search_' . $key, 'alpha')) {
74 $search[$key] = GETPOST('search_' . $key, 'alpha');
75 }
76}
77
78if (empty($action) && empty($id) && empty($ref)) {
79 $action = 'view';
80}
81
82// Load object
83include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'.
84
85$permissiontoread = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('asset', 'read')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('asset', 'model_advance', 'read')));
86$permissiontoadd = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('asset', 'write')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('asset', 'model_advance', 'write'))); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
87$permissiontodelete = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('asset', 'delete')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('asset', 'model_advance', 'delete'))) || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
88$permissionnote = $permissiontoadd; // Used by the include of actions_setnotes.inc.php
89$permissiondellink = $permissiontoadd; // Used by the include of actions_dellink.inc.php
90$upload_dir = $conf->asset->multidir_output[isset($object->entity) ? $object->entity : 1];
91
92// Security check (enable the most restrictive one)
93if ($user->socid > 0) {
95}
96if ($user->socid > 0) {
97 $socid = $user->socid;
98}
99$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
100restrictedArea($user, 'asset', $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
101if (!isModEnabled('asset')) {
103}
104if (!$permissiontoread) {
106}
107
108// Model depreciation options and accountancy codes
109$object->asset_depreciation_options = &$assetdepreciationoptions;
110$object->asset_accountancy_codes = &$assetaccountancycodes;
111if (!empty($id)) {
112 $depreciationoptionserrors = $assetdepreciationoptions->fetchDeprecationOptions(0, $object->id);
113 $accountancycodeserrors = $assetaccountancycodes->fetchAccountancyCodes(0, $object->id);
114
115 if ($depreciationoptionserrors < 0) {
116 setEventMessages($assetdepreciationoptions->error, $assetdepreciationoptions->errors, 'errors');
117 }
118 if ($accountancycodeserrors < 0) {
119 setEventMessages($assetaccountancycodes->error, $assetaccountancycodes->errors, 'errors');
120 }
121}
122
123/*
124 * Actions
125 */
126
127$parameters = array();
128$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
129if ($reshook < 0) {
130 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
131}
132
133if (empty($reshook)) {
134 $error = 0;
135
136 $backurlforlist = DOL_URL_ROOT . '/asset/model/list.php';
137
138 if (empty($backtopage) || ($cancel && empty($id))) {
139 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
140 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
141 $backtopage = $backurlforlist;
142 } else {
143 $backtopage = DOL_URL_ROOT . '/asset/model/card.php?id=' . ((!empty($id) && $id > 0) ? $id : '__ID__');
144 }
145 }
146 }
147
148 $triggermodname = 'ASSETMODEL_MODIFY'; // Name of trigger action code to execute when we modify record
149
150 if (($action == 'edit' && !($permissiontoadd && $object->status == $object::STATUS_DRAFT)) ||
151 ($action == 'confirm_setdraft' && !($permissiontoadd && $object->status != $object::STATUS_DRAFT)) ||
152 ($action == 'confirm_validate' && !($permissiontoadd && $object->status != $object::STATUS_VALIDATED)) ||
153 ($action == 'confirm_close' && !($permissiontoadd && $object->status != $object::STATUS_CANCELED))
154 ) {
155 $action = "";
156 }
157
158 // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
159 include DOL_DOCUMENT_ROOT . '/core/actions_addupdatedelete.inc.php';
160}
161
162
163/*
164 * View
165 *
166 * Put here all code to build page
167 */
168
169$form = new Form($db);
170$formfile = new FormFile($db);
171
172$title = $langs->trans("AssetModel") . ' - ' . $langs->trans("Card");
173$help_url = '';
174llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-asset page-model-card');
175
176// Part to create
177if ($action == 'create') {
178 print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("AssetModel")), '', 'object_' . $object->picto);
179
180 print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
181 print '<input type="hidden" name="token" value="' . newToken() . '">';
182 print '<input type="hidden" name="action" value="add">';
183 if ($backtopage) {
184 print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
185 }
186 if ($backtopageforcancel) {
187 print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
188 }
189
190 print dol_get_fiche_head(array(), '');
191
192
193 print '<table class="border centpercent tableforfieldcreate">' . "\n";
194
195 // Common attributes
196 include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_add.tpl.php';
197
198 // Other attributes
199 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php';
200
201 // Depreciation options
202 include DOL_DOCUMENT_ROOT . '/asset/tpl/depreciation_options_edit.tpl.php';
203
204 // Accountancy codes
205 print '<div class="clearboth"></div>';
206 print '<hr>';
207 include DOL_DOCUMENT_ROOT . '/asset/tpl/accountancy_codes_edit.tpl.php';
208
209 print '</table>' . "\n";
210
211 print dol_get_fiche_end();
212
213 print $form->buttonsSaveCancel("Create");
214
215 print '</form>';
216
217 //dol_set_focus('input[name="ref"]');
218}
219
220// Part to edit record
221if (($id || $ref) && $action == 'edit') {
222 print load_fiche_titre($langs->trans("AssetModel"), '', 'object_' . $object->picto);
223
224 print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
225 print '<input type="hidden" name="token" value="' . newToken() . '">';
226 print '<input type="hidden" name="action" value="update">';
227 print '<input type="hidden" name="id" value="' . $object->id . '">';
228 if ($backtopage) {
229 print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
230 }
231 if ($backtopageforcancel) {
232 print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
233 }
234
235 print dol_get_fiche_head();
236
237 print '<table class="border centpercent tableforfieldedit">' . "\n";
238
239 // Common attributes
240 include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_edit.tpl.php';
241
242 // Other attributes
243 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_edit.tpl.php';
244
245 // Depreciation options
246 include DOL_DOCUMENT_ROOT . '/asset/tpl/depreciation_options_edit.tpl.php';
247
248 // Accountancy codes
249 print '<div class="clearboth"></div>';
250 print '<hr>';
251 include DOL_DOCUMENT_ROOT . '/asset/tpl/accountancy_codes_edit.tpl.php';
252
253 print '</table>';
254
255 print dol_get_fiche_end();
256
257 print $form->buttonsSaveCancel();
258
259 print '</form>';
260}
261
262// Part to show record
263if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
264 $res = $object->fetch_optionals();
265
267 print dol_get_fiche_head($head, 'card', $langs->trans("AssetModel"), -1, $object->picto);
268
269 $formconfirm = '';
270
271 // Confirmation to delete
272 if ($action == 'delete') {
273 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteAssetModel'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
274 } elseif ($action == 'clone') {
275 // Clone confirmation
276 // Create an array for form
277 $formquestion = array();
278 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
279 }
280
281 // Call Hook formConfirm
282 $parameters = array('formConfirm' => $formconfirm);
283 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
284 if (empty($reshook)) {
285 $formconfirm .= $hookmanager->resPrint;
286 } elseif ($reshook > 0) {
287 $formconfirm = $hookmanager->resPrint;
288 }
289
290 // Print form confirm
291 print $formconfirm;
292
293
294 // Object card
295 // ------------------------------------------------------------
296 $linkback = '<a href="' . DOL_URL_ROOT . '/asset/model/list.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
297
298 $morehtmlref = '<div class="refidno">';
299 $morehtmlref .= '</div>';
300
301
302 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
303
304
305 print '<div class="fichecenter">';
306 print '<div class="underbanner clearboth"></div>';
307 print '<table class="border centpercent tableforfield">' . "\n";
308
309 // Common attributes
310 $object->fields = dol_sort_array($object->fields, 'position');
311
312 foreach ($object->fields as $key => $val) {
313 if (!empty($keyforbreak) && $key == $keyforbreak) {
314 break; // key used for break on second column
315 }
316
317 // Discard if extrafield is a hidden field on form
318 if (abs($val['visible']) != 1 && abs($val['visible']) != 3 && abs($val['visible']) != 4 && abs($val['visible']) != 5) {
319 continue;
320 }
321
322 if (array_key_exists('enabled', $val) && isset($val['enabled']) && !verifCond($val['enabled'])) {
323 continue; // We don't want this field
324 }
325 if (in_array($key, array('ref', 'status'))) {
326 continue; // Ref and status are already in dol_banner
327 }
328
329 $value = $object->$key;
330
331 print '<tr class="field_'.$key.'"><td';
332 print ' class="'.(empty($val['tdcss']) ? 'titlefield' : $val['tdcss']).' fieldname_'.$key;
333 //if ($val['notnull'] > 0) print ' fieldrequired'; // No fieldrequired on the view output
334 if ($val['type'] == 'text' || $val['type'] == 'html') {
335 print ' tdtop';
336 }
337 print '">';
338
339 $labeltoshow = '';
340 if (!empty($val['help'])) {
341 $labeltoshow .= $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
342 } else {
343 if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 1) {
344 $labeltoshow .= showValueWithClipboardCPButton($value, 0, $langs->transnoentitiesnoconv($val['label']));
345 } else {
346 $labeltoshow .= $langs->trans($val['label']);
347 }
348 }
349 if (empty($val['alwayseditable'])) {
350 print $labeltoshow;
351 } else {
352 print $form->editfieldkey($labeltoshow, $key, $value, $object, 1, $val['type']);
353 }
354
355 print '</td>';
356 print '<td class="valuefield fieldname_'.$key;
357 if ($val['type'] == 'text') {
358 print ' wordbreak';
359 }
360 if (!empty($val['cssview'])) {
361 print ' '.$val['cssview'];
362 }
363 print '">';
364 if (empty($val['alwayseditable'])) {
365 if (preg_match('/^(text|html)/', $val['type'])) {
366 print '<div class="longmessagecut">';
367 }
368 if ($key == 'lang') {
369 $langs->load("languages");
370 $labellang = ($value ? $langs->trans('Language_'.$value) : '');
371 print picto_from_langcode($value, 'class="paddingrightonly saturatemedium opacitylow"');
372 print $labellang;
373 } else {
374 if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 2) {
375 $out = $object->showOutputField($val, $key, $value, '', '', '', 0);
376 print showValueWithClipboardCPButton($out, 0, $out);
377 } else {
378 print $object->showOutputField($val, $key, $value, '', '', '', 0);
379 }
380 }
381 //print dol_escape_htmltag($object->$key, 1, 1);
382 if (preg_match('/^(text|html)/', $val['type'])) {
383 print '</div>';
384 }
385 } else {
386 print $form->editfieldval($labeltoshow, $key, $value, $object, 1, $val['type']);
387 }
388 print '</td>';
389 print '</tr>';
390 }
391
392 // Other attributes. Fields from hook formObjectOptions and Extrafields.
393 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
394 print '</table>';
395
396 // Depreciation options attributes
397 print '<div class="fichehalfleft">';
398 print '<table class="border centpercent tableforfield">';
399 include DOL_DOCUMENT_ROOT . '/asset/tpl/depreciation_options_view.tpl.php';
400 print '</table>';
401 print '</div>';
402
403 // Accountancy codes attributes
404 print '<div class="fichehalfright">';
405 print '<table class="border centpercent tableforfield">';
406 include DOL_DOCUMENT_ROOT . '/asset/tpl/accountancy_codes_view.tpl.php';
407 print '</table>';
408 print '</div>';
409
410 print '</div>';
411 print '<div class="clearboth"></div>';
412
413 print dol_get_fiche_end();
414
415
416 // Buttons for actions
417 if ($action != 'editline') {
418 print '<div class="tabsAction">' . "\n";
419 $parameters = array();
420 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
421 if ($reshook < 0) {
422 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
423 }
424
425 if (empty($reshook)) {
426 if ($object->status == $object::STATUS_DRAFT) {
427 print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=edit&token=' . newToken(), '', $permissiontoadd);
428 }
429
430 // Back to draft
431 if ($object->status != $object::STATUS_DRAFT) {
432 print dolGetButtonAction($langs->trans('SetToDraft'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=confirm_setdraft&confirm=yes&token=' . newToken(), '', $permissiontoadd);
433 }
434
435 if ($object->status != $object::STATUS_VALIDATED) {
436 print dolGetButtonAction($langs->trans('Enable'), '', 'default', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=confirm_validate&confirm=yes&token=' . newToken(), '', $permissiontoadd);
437 }
438
439 if ($object->status != $object::STATUS_CANCELED) {
440 print dolGetButtonAction($langs->trans('Disable'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_close&confirm=yes&token='.newToken(), '', $permissiontoadd);
441 }
442
443 // Clone
444 print dolGetButtonAction($langs->trans('ToClone'), '', 'default', $_SERVER['PHP_SELF'] . '?id=' . $object->id . (!empty($socid) ? '&socid=' . $socid : '') . '&action=clone&token=' . newToken(), '', $permissiontoadd);
445
446 // Delete (need delete permission, or if draft, just need create/modify permission)
447 print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=delete&token=' . newToken(), '', $permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd));
448 }
449 print '</div>' . "\n";
450 }
451
452 print '<div class="fichecenter"><div class="fichehalfleft">';
453 print '<a name="builddoc"></a>'; // ancre
454
455 print '</div><div class="fichehalfright">';
456
457 // $MAXEVENT = 10;
458 //
459 // $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT . '/asset/model/agenda.php?id=' . $object->id);
460 //
461 // // List of actions on element
462 // include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
463 // $formactions = new FormActions($db);
464 // $somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, 0, 1, '', $MAXEVENT, '', $morehtmlright);
465
466 print '</div></div>';
467}
468
469// End of page
470llxFooter();
471$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
assetModelPrepareHead($object)
Prepare array of tabs for AssetModel.
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:71
Class for AssetAccountancyCodes.
Class for AssetDepreciationOptions.
Class for AssetModel.
Class to manage standard extra fields.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
verifCond($strToEvaluate, $onlysimplestring='1')
Verify if condition in string is ok or not.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
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)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.