dolibarr  13.0.2
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/asset.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("asset"));
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') : 'assetcard'; // To manage different context of search
41 $backtopage = GETPOST('backtopage', 'alpha');
42 $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
43 
44 // Initialize technical objects
45 $object = new Asset($db);
46 $extrafields = new ExtraFields($db);
47 $diroutputmassaction = $conf->asset->dir_output.'/temp/massgeneration/'.$user->id;
48 $hookmanager->initHooks(array('assetcard', '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 {
60  if (GETPOST('search_'.$key, 'alpha')) $search[$key] = GETPOST('search_'.$key, 'alpha');
61 }
62 
63 if (empty($action) && empty($id) && empty($ref)) $action = 'view';
64 
65 // Load object
66 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
67 
68 // Security check
69 if (!empty($user->socid)) $socid = $user->socid;
70 $result = restrictedArea($user, 'asset', $id);
71 
72 $permissiontoread = $user->rights->asset->read;
73 $permissiontoadd = $user->rights->asset->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
74 $permissiontodelete = $user->rights->asset->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
75 $permissionnote = $user->rights->asset->write; // Used by the include of actions_setnotes.inc.php
76 $permissiondellink = $user->rights->asset->write; // Used by the include of actions_dellink.inc.php
77 $upload_dir = $conf->mymodule->multidir_output[isset($object->entity) ? $object->entity : 1];
78 
79 
80 /*
81  * Actions
82  */
83 
84 $parameters = array();
85 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
86 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
87 
88 if (empty($reshook))
89 {
90  $error = 0;
91 
92  $backurlforlist = dol_buildpath('/asset/list.php', 1);
93 
94  // Actions cancel, add, update or delete
95  include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
96 
97  // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
98  include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
99 
100  // Actions when linking object each other
101  include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
102 
103  // Actions when printing a doc from card
104  include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
105 
106  // Action to move up and down lines of object
107  //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
108 
109  // Action to build doc
110  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
111 
112  if ($action == 'set_thirdparty' && $permissiontoadd)
113  {
114  $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, 'MYOBJECT_MODIFY');
115  }
116  if ($action == 'classin' && $permissiontoadd)
117  {
118  $object->setProject(GETPOST('projectid', 'int'));
119  }
120 
121  // Actions to send emails
122  $triggersendname = 'ASSET_SENTBYMAIL';
123  $autocopy = 'MAIN_MAIL_AUTOCOPY_ASSET_TO';
124  $trackid = 'asset'.$object->id;
125  include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
126 }
127 
128 /*
129  * View
130  *
131  */
132 
133 $form = new Form($db);
134 $formfile = new FormFile($db);
135 
136 $title = $langs->trans("Asset").' - '.$langs->trans("Card");
137 $help_url = '';
138 llxHeader('', $title, $help_url);
139 
140 // Part to create
141 if ($action == 'create')
142 {
143  print load_fiche_titre($langs->trans("NewAsset"), '', 'accountancy');
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) print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
149  if ($backtopageforcancel) print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
150 
151  print dol_get_fiche_head(array(), '');
152 
153  print '<table class="border centpercent tableforfieldcreate">'."\n";
154 
155  // Common attributes
156  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
157 
158  // Other attributes
159  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
160 
161  print '</table>'."\n";
162 
164 
165  print '<div class="center">';
166  print '<input type="submit" class="button" name="add" value="'.dol_escape_htmltag($langs->trans("Create")).'">';
167  print '&nbsp; ';
168  print '<input type="'.($backtopage ? "submit" : "button").'" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'"'.($backtopage ? '' : ' onclick="javascript:history.go(-1)"').'>'; // Cancel for create does not post form if we don't know the backtopage
169  print '</div>';
170 
171  print '</form>';
172 
173  //dol_set_focus('input[name="ref"]');
174 }
175 
176 // Part to edit record
177 if (($id || $ref) && $action == 'edit')
178 {
179  print load_fiche_titre($langs->trans("Assets"));
180 
181  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
182  print '<input type="hidden" name="token" value="'.newToken().'">';
183  print '<input type="hidden" name="action" value="update">';
184  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
185  print '<input type="hidden" name="id" value="'.$object->id.'">';
186  if ($backtopage) print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
187  if ($backtopageforcancel) print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
188 
190 
191  print '<table class="border centpercent tableforfieldedit">'."\n";
192 
193  // Common attributes
194  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
195 
196  // Other attributes
197  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
198 
199  print '</table>';
200 
202 
203  print '<div class="center"><input type="submit" class="button button-save" name="save" value="'.$langs->trans("Save").'">';
204  print ' &nbsp; <input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
205  print '</div>';
206 
207  print '</form>';
208 }
209 
210 // Part to show record
211 if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create')))
212 {
213  $res = $object->fetch_optionals();
214 
215  $head = asset_prepare_head($object);
216  print dol_get_fiche_head($head, 'card', $langs->trans("Asset"), -1, $object->picto);
217 
218  $formconfirm = '';
219 
220  // Confirmation to delete
221  if ($action == 'delete')
222  {
223  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteAssets'), $langs->trans('ConfirmDeleteAsset'), 'confirm_delete', '', 0, 1);
224  }
225 
226  // Call Hook formConfirm
227  $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
228  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
229  if (empty($reshook)) $formconfirm .= $hookmanager->resPrint;
230  elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint;
231 
232  // Print form confirm
233  print $formconfirm;
234 
235 
236  // Object card
237  // ------------------------------------------------------------
238  $linkback = '<a href="'.dol_buildpath('/asset/list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
239 
240  $morehtmlref = '<div class="refidno">';
241  /*
242  // Ref bis
243  $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->asset->creer, 'string', '', 0, 1);
244  $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->asset->creer, 'string', '', null, null, '', 1);
245  // Thirdparty
246  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
247  */
248  $morehtmlref .= '</div>';
249 
250  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
251 
252  print '<div class="fichecenter">';
253  print '<div class="fichehalfleft">';
254  print '<div class="underbanner clearboth"></div>';
255  print '<table class="border centpercent">'."\n";
256 
257  // Common attributes
258  //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just after this field
259  //unset($object->fields['fk_project']); // Hide field already shown in banner
260  //unset($object->fields['fk_soc']); // Hide field already shown in banner
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 
269  print '<div class="clearboth"></div>';
270 
272 
273 
274  /*
275  * Buttons
276  */
277  if ($user->socid == 0)
278  {
279  print '<div class="tabsAction">';
280 
281  $parameters = array();
282  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
283 
284  if (empty($reshook))
285  {
286  if ($user->rights->asset->write)
287  {
288  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a>'."\n";
289  } else {
290  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n";
291  }
292 
293  if ($user->rights->asset->delete)
294  {
295  print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete&token='.newToken().'">'.$langs->trans('Delete').'</a>'."\n";
296  } else {
297  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Delete').'</a>'."\n";
298  }
299  }
300  print "</div>";
301  }
302 
303  if ($action != 'presend')
304  {
305  print '<div class="fichecenter"><div class="fichehalfleft">';
306  print '<a name="builddoc"></a>'; // ancre
307 
308  // Documents
309  $filename = dol_sanitizeFileName($object->ref);
310  $filedir = $conf->contrat->dir_output."/".dol_sanitizeFileName($object->ref);
311  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
312  $genallowed = $user->rights->asset->read; // If you can read, you can build the PDF to read content
313  $delallowed = $user->rights->asset->write; // If you can create/edit, you can remove a file on card
314 
315  print $formfile->showdocuments('asset', $filename, $filedir, $urlsource, 0, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
316 
317  // Show links to link elements
318  $linktoelem = $form->showLinkToObjectBlock($object, null, array('asset'));
319  $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
320 
321  print '</div><div class="fichehalfright"><div class="ficheaddleft">';
322 
323  $MAXEVENT = 10;
324 
325  $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-list-alt imgforviewmode', DOL_URL_ROOT.'/asset/info.php?id='.$object->id);
326 
327  // List of actions on element
328  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
329  $formactions = new FormActions($db);
330  $somethingshown = $formactions->showactions($object, 'asset', $socid, 1, '', $MAXEVENT, '', $morehtmlright);
331 
332  print '</div></div></div>';
333  }
334 }
335 
336 
337 // End of page
338 llxFooter();
339 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action== 'set') elseif($action== 'specimen') elseif($action== 'setmodel') elseif($action== 'del') elseif($action== 'setdoc') $formactions
View.
Class to manage building of HTML components.
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_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
asset_prepare_head(Asset $object)
Prepare admin pages header.
Definition: asset.lib.php:74
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
Class to offer components to list and upload files.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
Class for Asset.
Definition: asset.class.php:30
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
print $_SERVER["PHP_SELF"] n
Edit parameters.
Definition: categories.php:101
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...