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