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