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';
31require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetdepreciationoptions.class.php';
32require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetaccountancycodes.class.php';
35$langs->loadLangs(array(
"assets",
"other"));
40$action =
GETPOST(
'action',
'aZ09');
41$confirm =
GETPOST(
'confirm',
'alpha');
42$cancel =
GETPOST(
'cancel',
'aZ09');
43$contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'assetmodelcard';
44$backtopage =
GETPOST(
'backtopage',
'alpha');
45$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
52$diroutputmassaction = $conf->asset->dir_output .
'/temp/massgeneration/' . $user->id;
53$hookmanager->initHooks(array(
'assetmodelcard',
'globalcard'));
56$extrafields->fetch_name_optionals_label(
$object->table_element);
58$search_array_options = $extrafields->getOptionalsFromPost(
$object->table_element,
'',
'search_');
61$search_all =
GETPOST(
"search_all",
'alpha');
63foreach (
$object->fields as $key => $val) {
64 if (
GETPOST(
'search_' . $key,
'alpha')) {
65 $search[$key] =
GETPOST(
'search_' . $key,
'alpha');
69if (empty($action) && empty($id) && empty($ref)) {
74include DOL_DOCUMENT_ROOT .
'/core/actions_fetchobject.inc.php';
76$permissiontoread = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'asset',
'read')) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'asset',
'model_advance',
'read')));
77$permissiontoadd = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'asset',
'write')) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'asset',
'model_advance',
'write')));
78$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);
79$permissionnote = $permissiontoadd;
80$permissiondellink = $permissiontoadd;
81$upload_dir = $conf->asset->multidir_output[isset(
$object->entity) ?
$object->entity : 1];
84if ($user->socid > 0) {
87if ($user->socid > 0) {
88 $socid = $user->socid;
90$isdraft = ((
$object->status == $object::STATUS_DRAFT) ? 1 : 0);
92if (!isModEnabled(
'asset')) {
95if (!$permissiontoread) {
100$object->asset_depreciation_options = &$assetdepreciationoptions;
101$object->asset_accountancy_codes = &$assetaccountancycodes;
103 $depreciationoptionserrors = $assetdepreciationoptions->fetchDeprecationOptions(0,
$object->id);
104 $accountancycodeserrors = $assetaccountancycodes->fetchAccountancyCodes(0,
$object->id);
106 if ($depreciationoptionserrors < 0) {
107 setEventMessages($assetdepreciationoptions->error, $assetdepreciationoptions->errors,
'errors');
109 if ($accountancycodeserrors < 0) {
110 setEventMessages($assetaccountancycodes->error, $assetaccountancycodes->errors,
'errors');
118$parameters = array();
119$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
124if (empty($reshook)) {
127 $backurlforlist = DOL_URL_ROOT .
'/asset/model/list.php';
129 if (empty($backtopage) || ($cancel && empty($id))) {
130 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
131 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
132 $backtopage = $backurlforlist;
134 $backtopage = DOL_URL_ROOT .
'/asset/model/card.php?id=' . ((!empty($id) &&
$id > 0) ? $id :
'__ID__');
139 $triggermodname =
'ASSETMODEL_MODIFY';
141 if (($action ==
'edit' && !($permissiontoadd &&
$object->status == $object::STATUS_DRAFT)) ||
142 ($action ==
'confirm_setdraft' && !($permissiontoadd &&
$object->status != $object::STATUS_DRAFT)) ||
143 ($action ==
'confirm_validate' && !($permissiontoadd &&
$object->status != $object::STATUS_VALIDATED)) ||
144 ($action ==
'confirm_close' && !($permissiontoadd &&
$object->status != $object::STATUS_CANCELED))
150 include DOL_DOCUMENT_ROOT .
'/core/actions_addupdatedelete.inc.php';
160$form =
new Form($db);
163$title = $langs->trans(
"AssetModel") .
' - ' . $langs->trans(
"Card");
165llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-asset page-model-card');
168if ($action ==
'create') {
169 print
load_fiche_titre($langs->trans(
"NewObject", $langs->transnoentitiesnoconv(
"AssetModel")),
'',
'object_' .
$object->picto);
171 print
'<form method="POST" action="' . $_SERVER[
"PHP_SELF"] .
'">';
172 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
173 print
'<input type="hidden" name="action" value="add">';
175 print
'<input type="hidden" name="backtopage" value="' . $backtopage .
'">';
177 if ($backtopageforcancel) {
178 print
'<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel .
'">';
184 print
'<table class="border centpercent tableforfieldcreate">' .
"\n";
187 include DOL_DOCUMENT_ROOT .
'/core/tpl/commonfields_add.tpl.php';
190 include DOL_DOCUMENT_ROOT .
'/core/tpl/extrafields_add.tpl.php';
193 include DOL_DOCUMENT_ROOT .
'/asset/tpl/depreciation_options_edit.tpl.php';
196 print
'<div class="clearboth"></div>';
198 include DOL_DOCUMENT_ROOT .
'/asset/tpl/accountancy_codes_edit.tpl.php';
200 print
'</table>' .
"\n";
204 print $form->buttonsSaveCancel(
"Create");
212if (($id || $ref) && $action ==
'edit') {
215 print
'<form method="POST" action="' . $_SERVER[
"PHP_SELF"] .
'">';
216 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
217 print
'<input type="hidden" name="action" value="update">';
218 print
'<input type="hidden" name="id" value="' .
$object->id .
'">';
220 print
'<input type="hidden" name="backtopage" value="' . $backtopage .
'">';
222 if ($backtopageforcancel) {
223 print
'<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel .
'">';
228 print
'<table class="border centpercent tableforfieldedit">' .
"\n";
231 include DOL_DOCUMENT_ROOT .
'/core/tpl/commonfields_edit.tpl.php';
234 include DOL_DOCUMENT_ROOT .
'/core/tpl/extrafields_edit.tpl.php';
237 include DOL_DOCUMENT_ROOT .
'/asset/tpl/depreciation_options_edit.tpl.php';
240 print
'<div class="clearboth"></div>';
242 include DOL_DOCUMENT_ROOT .
'/asset/tpl/accountancy_codes_edit.tpl.php';
248 print $form->buttonsSaveCancel();
254if (
$object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create'))) {
255 $res =
$object->fetch_optionals();
263 if ($action ==
'delete') {
264 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id, $langs->trans(
'DeleteAssetModel'), $langs->trans(
'ConfirmDeleteObject'),
'confirm_delete',
'', 0, 1);
265 } elseif ($action ==
'clone') {
268 $formquestion = array();
269 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneAsk',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1);
273 $parameters = array(
'formConfirm' => $formconfirm);
274 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters,
$object, $action);
275 if (empty($reshook)) {
276 $formconfirm .= $hookmanager->resPrint;
277 } elseif ($reshook > 0) {
278 $formconfirm = $hookmanager->resPrint;
287 $linkback =
'<a href="' . DOL_URL_ROOT .
'/asset/model/list.php?restore_lastsearch_values=1' . (!empty($socid) ?
'&socid=' . $socid :
'') .
'">' . $langs->trans(
"BackToList") .
'</a>';
289 $morehtmlref =
'<div class="refidno">';
290 $morehtmlref .=
'</div>';
293 dol_banner_tab(
$object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
296 print
'<div class="fichecenter">';
297 print
'<div class="underbanner clearboth"></div>';
298 print
'<table class="border centpercent tableforfield">' .
"\n";
303 foreach (
$object->fields as $key => $val) {
304 if (!empty($keyforbreak) && $key == $keyforbreak) {
309 if (abs($val[
'visible']) != 1 && abs($val[
'visible']) != 3 && abs($val[
'visible']) != 4 && abs($val[
'visible']) != 5) {
313 if (array_key_exists(
'enabled', $val) && isset($val[
'enabled']) && !
verifCond($val[
'enabled'])) {
316 if (in_array($key, array(
'ref',
'status'))) {
322 print
'<tr class="field_'.$key.
'"><td';
323 print
' class="'.(empty($val[
'tdcss']) ?
'titlefield' : $val[
'tdcss']).
' fieldname_'.$key;
325 if ($val[
'type'] ==
'text' || $val[
'type'] ==
'html') {
331 if (!empty($val[
'help'])) {
332 $labeltoshow .= $form->textwithpicto($langs->trans($val[
'label']), $langs->trans($val[
'help']));
334 if (isset($val[
'copytoclipboard']) && $val[
'copytoclipboard'] == 1) {
337 $labeltoshow .= $langs->trans($val[
'label']);
340 if (empty($val[
'alwayseditable'])) {
343 print $form->editfieldkey($labeltoshow, $key, $value,
$object, 1, $val[
'type']);
347 print
'<td class="valuefield fieldname_'.$key;
348 if ($val[
'type'] ==
'text') {
351 if (!empty($val[
'cssview'])) {
352 print
' '.$val[
'cssview'];
355 if (empty($val[
'alwayseditable'])) {
356 if (preg_match(
'/^(text|html)/', $val[
'type'])) {
357 print
'<div class="longmessagecut">';
359 if ($key ==
'lang') {
360 $langs->load(
"languages");
361 $labellang = ($value ? $langs->trans(
'Language_'.$value) :
'');
365 if (isset($val[
'copytoclipboard']) && $val[
'copytoclipboard'] == 2) {
366 $out =
$object->showOutputField($val, $key, $value,
'',
'',
'', 0);
369 print
$object->showOutputField($val, $key, $value,
'',
'',
'', 0);
373 if (preg_match(
'/^(text|html)/', $val[
'type'])) {
377 print $form->editfieldval($labeltoshow, $key, $value,
$object, 1, $val[
'type']);
384 include DOL_DOCUMENT_ROOT .
'/core/tpl/extrafields_view.tpl.php';
388 print
'<div class="fichehalfleft">';
389 print
'<table class="border centpercent tableforfield">';
390 include DOL_DOCUMENT_ROOT .
'/asset/tpl/depreciation_options_view.tpl.php';
395 print
'<div class="fichehalfright">';
396 print
'<table class="border centpercent tableforfield">';
397 include DOL_DOCUMENT_ROOT .
'/asset/tpl/accountancy_codes_view.tpl.php';
402 print
'<div class="clearboth"></div>';
408 if ($action !=
'editline') {
409 print
'<div class="tabsAction">' .
"\n";
410 $parameters = array();
411 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters,
$object, $action);
416 if (empty($reshook)) {
417 if (
$object->status == $object::STATUS_DRAFT) {
418 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=edit&token=' .
newToken(),
'', $permissiontoadd);
422 if (
$object->status != $object::STATUS_DRAFT) {
423 print
dolGetButtonAction($langs->trans(
'SetToDraft'),
'',
'default', $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=confirm_setdraft&confirm=yes&token=' .
newToken(),
'', $permissiontoadd);
426 if (
$object->status != $object::STATUS_VALIDATED) {
427 print
dolGetButtonAction($langs->trans(
'Enable'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?id=' .
$object->id .
'&action=confirm_validate&confirm=yes&token=' .
newToken(),
'', $permissiontoadd);
430 if (
$object->status != $object::STATUS_CANCELED) {
431 print
dolGetButtonAction($langs->trans(
'Disable'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=confirm_close&confirm=yes&token='.
newToken(),
'', $permissiontoadd);
435 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?id=' .
$object->id . (!empty($socid) ?
'&socid=' . $socid :
'') .
'&action=clone&token=' .
newToken(),
'', $permissiontoadd);
438 print
dolGetButtonAction($langs->trans(
'Delete'),
'',
'delete', $_SERVER[
'PHP_SELF'] .
'?id=' .
$object->id .
'&action=delete&token=' .
newToken(),
'', $permissiontodelete || (
$object->status == $object::STATUS_DRAFT && $permissiontoadd));
440 print
'</div>' .
"\n";
443 print
'<div class="fichecenter"><div class="fichehalfleft">';
444 print
'<a name="builddoc"></a>';
446 print
'</div><div class="fichehalfright">';
457 print
'</div></div>';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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.
Class for AssetAccountancyCodes.
Class for AssetDepreciationOptions.
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.
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.