dolibarr 19.0.3
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 *
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// Load Dolibarr environment
26require '../../main.inc.php';
27require_once DOL_DOCUMENT_ROOT . '/core/lib/asset.lib.php';
28require_once DOL_DOCUMENT_ROOT . '/asset/class/assetmodel.class.php';
29require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
30require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
31
32// Load translation files required by the page
33$langs->loadLangs(array("assets", "other"));
34
35// Get parameters
36$id = GETPOST('id', 'int');
37$ref = GETPOST('ref', 'alpha');
38$action = GETPOST('action', 'aZ09');
39$confirm = GETPOST('confirm', 'alpha');
40$cancel = GETPOST('cancel', 'aZ09');
41$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'assetmodelcard'; // To manage different context of search
42$backtopage = GETPOST('backtopage', 'alpha');
43$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
44
45// Initialize technical objects
46$object = new AssetModel($db);
47$extrafields = new ExtraFields($db);
48$diroutputmassaction = $conf->asset->dir_output . '/temp/massgeneration/' . $user->id;
49$hookmanager->initHooks(array('assetmodelcard', 'globalcard')); // Note that conf->hooks_modules contains array
50
51// Fetch optionals attributes and labels
52$extrafields->fetch_name_optionals_label($object->table_element);
53
54$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
55
56// Initialize array of search criterias
57$search_all = GETPOST("search_all", 'alpha');
58$search = array();
59foreach ($object->fields as $key => $val) {
60 if (GETPOST('search_' . $key, 'alpha')) {
61 $search[$key] = GETPOST('search_' . $key, 'alpha');
62 }
63}
64
65if (empty($action) && empty($id) && empty($ref)) {
66 $action = 'view';
67}
68
69// Load object
70include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
71
72$permissiontoread = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('asset', 'read')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('asset', 'model_advance', 'read')));
73$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
74$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);
75$permissionnote = $permissiontoadd; // Used by the include of actions_setnotes.inc.php
76$permissiondellink = $permissiontoadd; // Used by the include of actions_dellink.inc.php
77$upload_dir = $conf->asset->multidir_output[isset($object->entity) ? $object->entity : 1];
78
79// Security check (enable the most restrictive one)
80if ($user->socid > 0) {
82}
83if ($user->socid > 0) {
84 $socid = $user->socid;
85}
86$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
87restrictedArea($user, 'asset', $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
88if (!isModEnabled('asset')) {
90}
91if (!$permissiontoread) {
93}
94
95
96/*
97 * Actions
98 */
99
100$parameters = array();
101$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
102if ($reshook < 0) {
103 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
104}
105
106if (empty($reshook)) {
107 $error = 0;
108
109 $backurlforlist = DOL_URL_ROOT . '/asset/model/list.php';
110
111 if (empty($backtopage) || ($cancel && empty($id))) {
112 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
113 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
114 $backtopage = $backurlforlist;
115 } else {
116 $backtopage = DOL_URL_ROOT . '/asset/model/card.php?id=' . ((!empty($id) && $id > 0) ? $id : '__ID__');
117 }
118 }
119 }
120
121 $triggermodname = 'ASSETMODEL_MODIFY'; // Name of trigger action code to execute when we modify record
122
123 if (($action == 'edit' && !($permissiontoadd && $object->status == $object::STATUS_DRAFT)) ||
124 ($action == 'confirm_setdraft' && !($permissiontoadd && $object->status != $object::STATUS_DRAFT)) ||
125 ($action == 'confirm_validate' && !($permissiontoadd && $object->status != $object::STATUS_VALIDATED)) ||
126 ($action == 'confirm_close' && !($permissiontoadd && $object->status != $object::STATUS_CANCELED))
127 ) {
128 $action = "";
129 }
130
131 // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
132 include DOL_DOCUMENT_ROOT . '/core/actions_addupdatedelete.inc.php';
133}
134
135
136/*
137 * View
138 *
139 * Put here all code to build page
140 */
141
142$form = new Form($db);
143$formfile = new FormFile($db);
144
145$title = $langs->trans("AssetModel") . ' - ' . $langs->trans("Card");
146$help_url = '';
147llxHeader('', $title, $help_url);
148
149// Part to create
150if ($action == 'create') {
151 print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("AssetModel")), '', 'object_' . $object->picto);
152
153 print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
154 print '<input type="hidden" name="token" value="' . newToken() . '">';
155 print '<input type="hidden" name="action" value="add">';
156 if ($backtopage) {
157 print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
158 }
159 if ($backtopageforcancel) {
160 print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
161 }
162
163 print dol_get_fiche_head(array(), '');
164
165 // Set some default values
166 //if (! GETPOSTISSET('fieldname')) $_POST['fieldname'] = 'myvalue';
167
168 print '<table class="border centpercent tableforfieldcreate">' . "\n";
169
170 // Common attributes
171 include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_add.tpl.php';
172
173 // Other attributes
174 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php';
175
176 print '</table>' . "\n";
177
178 print dol_get_fiche_end();
179
180 print $form->buttonsSaveCancel("Create");
181
182 print '</form>';
183
184 //dol_set_focus('input[name="ref"]');
185}
186
187// Part to edit record
188if (($id || $ref) && $action == 'edit') {
189 print load_fiche_titre($langs->trans("AssetModel"), '', 'object_' . $object->picto);
190
191 print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
192 print '<input type="hidden" name="token" value="' . newToken() . '">';
193 print '<input type="hidden" name="action" value="update">';
194 print '<input type="hidden" name="id" value="' . $object->id . '">';
195 if ($backtopage) {
196 print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
197 }
198 if ($backtopageforcancel) {
199 print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
200 }
201
202 print dol_get_fiche_head();
203
204 print '<table class="border centpercent tableforfieldedit">' . "\n";
205
206 // Common attributes
207 include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_edit.tpl.php';
208
209 // Other attributes
210 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_edit.tpl.php';
211
212 print '</table>';
213
214 print dol_get_fiche_end();
215
216 print $form->buttonsSaveCancel();
217
218 print '</form>';
219}
220
221// Part to show record
222if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
223 $res = $object->fetch_optionals();
224
225 $head = assetModelPrepareHead($object);
226 print dol_get_fiche_head($head, 'card', $langs->trans("AssetModel"), -1, $object->picto);
227
228 $formconfirm = '';
229
230 // Confirmation to delete
231 if ($action == 'delete') {
232 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteAssetModel'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
233 } elseif ($action == 'clone') {
234 // Clone confirmation
235 // Create an array for form
236 $formquestion = array();
237 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
238 }
239
240 // Call Hook formConfirm
241 $parameters = array('formConfirm' => $formconfirm);
242 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
243 if (empty($reshook)) {
244 $formconfirm .= $hookmanager->resPrint;
245 } elseif ($reshook > 0) {
246 $formconfirm = $hookmanager->resPrint;
247 }
248
249 // Print form confirm
250 print $formconfirm;
251
252
253 // Object card
254 // ------------------------------------------------------------
255 $linkback = '<a href="' . DOL_URL_ROOT . '/asset/model/list.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
256
257 $morehtmlref = '<div class="refidno">';
258 $morehtmlref .= '</div>';
259
260
261 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
262
263
264 print '<div class="fichecenter">';
265 print '<div class="fichehalfleft">';
266 print '<div class="underbanner clearboth"></div>';
267 print '<table class="border centpercent tableforfield">' . "\n";
268
269 // Common attributes
270 include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php';
271
272 // Other attributes. Fields from hook formObjectOptions and Extrafields.
273 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
274
275 print '</table>';
276 print '</div>';
277 print '</div>';
278
279 print '<div class="clearboth"></div>';
280
281 print dol_get_fiche_end();
282
283
284 // Buttons for actions
285 if ($action != 'editline') {
286 print '<div class="tabsAction">' . "\n";
287 $parameters = array();
288 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
289 if ($reshook < 0) {
290 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
291 }
292
293 if (empty($reshook)) {
294 if ($object->status == $object::STATUS_DRAFT) {
295 print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=edit&token=' . newToken(), '', $permissiontoadd);
296 }
297
298 // Back to draft
299 if ($object->status != $object::STATUS_DRAFT) {
300 print dolGetButtonAction($langs->trans('SetToDraft'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=confirm_setdraft&confirm=yes&token=' . newToken(), '', $permissiontoadd);
301 }
302
303 if ($object->status != $object::STATUS_VALIDATED) {
304 print dolGetButtonAction($langs->trans('Enable'), '', 'default', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=confirm_validate&confirm=yes&token=' . newToken(), '', $permissiontoadd);
305 }
306
307 if ($object->status != $object::STATUS_CANCELED) {
308 print dolGetButtonAction($langs->trans('Disable'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_close&confirm=yes&token='.newToken(), '', $permissiontoadd);
309 }
310
311 // Clone
312 print dolGetButtonAction($langs->trans('ToClone'), '', 'default', $_SERVER['PHP_SELF'] . '?id=' . $object->id . (!empty($socid) ? '&socid=' . $socid : '') . '&action=clone&token=' . newToken(), '', $permissiontoadd);
313
314 // Delete (need delete permission, or if draft, just need create/modify permission)
315 print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=delete&token=' . newToken(), '', $permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd));
316 }
317 print '</div>' . "\n";
318 }
319
320 print '<div class="fichecenter"><div class="fichehalfleft">';
321 print '<a name="builddoc"></a>'; // ancre
322
323 print '</div><div class="fichehalfright">';
324
325 // $MAXEVENT = 10;
326 //
327 // $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT . '/asset/model/agenda.php?id=' . $object->id);
328 //
329 // // List of actions on element
330 // include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
331 // $formactions = new FormActions($db);
332 // $somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, 0, 1, '', $MAXEVENT, '', $morehtmlright);
333
334 print '</div></div>';
335}
336
337// End of page
338llxFooter();
339$db->close();
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()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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.
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.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.