27require
'../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT .
'/core/lib/asset.lib.php';
29require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetmodel.class.php';
30require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formcompany.class.php';
31require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formfile.class.php';
32require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetdepreciationoptions.class.php';
33require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetaccountancycodes.class.php';
44$langs->loadLangs(array(
"assets",
"other"));
49$action =
GETPOST(
'action',
'aZ09');
50$confirm =
GETPOST(
'confirm',
'alpha');
51$cancel =
GETPOST(
'cancel',
'aZ09');
52$contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'assetmodelcard';
53$backtopage =
GETPOST(
'backtopage',
'alpha');
54$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
61$diroutputmassaction =
$conf->asset->dir_output .
'/temp/massgeneration/' . $user->id;
62$hookmanager->initHooks(array(
'assetmodelcard',
'globalcard'));
65$extrafields->fetch_name_optionals_label(
$object->table_element);
67$search_array_options = $extrafields->getOptionalsFromPost(
$object->table_element,
'',
'search_');
70$search_all =
GETPOST(
"search_all",
'alpha');
72foreach (
$object->fields as $key => $val) {
73 if (
GETPOST(
'search_' . $key,
'alpha')) {
74 $search[$key] =
GETPOST(
'search_' . $key,
'alpha');
78if (empty($action) && empty($id) && empty($ref)) {
83include DOL_DOCUMENT_ROOT .
'/core/actions_fetchobject.inc.php';
85$permissiontoread = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'asset',
'read')) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'asset',
'model_advance',
'read')));
86$permissiontoadd = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'asset',
'write')) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'asset',
'model_advance',
'write')));
87$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);
88$permissionnote = $permissiontoadd;
89$permissiondellink = $permissiontoadd;
93if ($user->socid > 0) {
96if ($user->socid > 0) {
97 $socid = $user->socid;
99$isdraft = ((
$object->status == $object::STATUS_DRAFT) ? 1 : 0);
101if (!isModEnabled(
'asset')) {
104if (!$permissiontoread) {
109$object->asset_depreciation_options = &$assetdepreciationoptions;
110$object->asset_accountancy_codes = &$assetaccountancycodes;
112 $depreciationoptionserrors = $assetdepreciationoptions->fetchDeprecationOptions(0,
$object->id);
113 $accountancycodeserrors = $assetaccountancycodes->fetchAccountancyCodes(0,
$object->id);
115 if ($depreciationoptionserrors < 0) {
116 setEventMessages($assetdepreciationoptions->error, $assetdepreciationoptions->errors,
'errors');
118 if ($accountancycodeserrors < 0) {
119 setEventMessages($assetaccountancycodes->error, $assetaccountancycodes->errors,
'errors');
127$parameters = array();
128$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
133if (empty($reshook)) {
136 $backurlforlist = DOL_URL_ROOT .
'/asset/model/list.php';
138 if (empty($backtopage) || ($cancel && empty($id))) {
139 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
140 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
141 $backtopage = $backurlforlist;
143 $backtopage = DOL_URL_ROOT .
'/asset/model/card.php?id=' . ((!empty($id) &&
$id > 0) ? $id :
'__ID__');
148 $triggermodname =
'ASSETMODEL_MODIFY';
150 if (($action ==
'edit' && !($permissiontoadd &&
$object->status == $object::STATUS_DRAFT)) ||
151 ($action ==
'confirm_setdraft' && !($permissiontoadd &&
$object->status != $object::STATUS_DRAFT)) ||
152 ($action ==
'confirm_validate' && !($permissiontoadd &&
$object->status != $object::STATUS_VALIDATED)) ||
153 ($action ==
'confirm_close' && !($permissiontoadd &&
$object->status != $object::STATUS_CANCELED))
159 include DOL_DOCUMENT_ROOT .
'/core/actions_addupdatedelete.inc.php';
169$form =
new Form($db);
172$title = $langs->trans(
"AssetModel") .
' - ' . $langs->trans(
"Card");
174llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-asset page-model-card');
177if ($action ==
'create') {
178 print
load_fiche_titre($langs->trans(
"NewObject", $langs->transnoentitiesnoconv(
"AssetModel")),
'',
'object_' .
$object->picto);
180 print
'<form method="POST" action="' . $_SERVER[
"PHP_SELF"] .
'">';
181 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
182 print
'<input type="hidden" name="action" value="add">';
184 print
'<input type="hidden" name="backtopage" value="' . $backtopage .
'">';
186 if ($backtopageforcancel) {
187 print
'<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel .
'">';
193 print
'<table class="border centpercent tableforfieldcreate">' .
"\n";
196 include DOL_DOCUMENT_ROOT .
'/core/tpl/commonfields_add.tpl.php';
199 include DOL_DOCUMENT_ROOT .
'/core/tpl/extrafields_add.tpl.php';
202 include DOL_DOCUMENT_ROOT .
'/asset/tpl/depreciation_options_edit.tpl.php';
205 print
'<div class="clearboth"></div>';
207 include DOL_DOCUMENT_ROOT .
'/asset/tpl/accountancy_codes_edit.tpl.php';
209 print
'</table>' .
"\n";
213 print $form->buttonsSaveCancel(
"Create");
221if (($id || $ref) && $action ==
'edit') {
224 print
'<form method="POST" action="' . $_SERVER[
"PHP_SELF"] .
'">';
225 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
226 print
'<input type="hidden" name="action" value="update">';
227 print
'<input type="hidden" name="id" value="' .
$object->id .
'">';
229 print
'<input type="hidden" name="backtopage" value="' . $backtopage .
'">';
231 if ($backtopageforcancel) {
232 print
'<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel .
'">';
237 print
'<table class="border centpercent tableforfieldedit">' .
"\n";
240 include DOL_DOCUMENT_ROOT .
'/core/tpl/commonfields_edit.tpl.php';
243 include DOL_DOCUMENT_ROOT .
'/core/tpl/extrafields_edit.tpl.php';
246 include DOL_DOCUMENT_ROOT .
'/asset/tpl/depreciation_options_edit.tpl.php';
249 print
'<div class="clearboth"></div>';
251 include DOL_DOCUMENT_ROOT .
'/asset/tpl/accountancy_codes_edit.tpl.php';
257 print $form->buttonsSaveCancel();
263if (
$object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create'))) {
264 $res =
$object->fetch_optionals();
272 if ($action ==
'delete') {
273 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id, $langs->trans(
'DeleteAssetModel'), $langs->trans(
'ConfirmDeleteObject'),
'confirm_delete',
'', 0, 1);
274 } elseif ($action ==
'clone') {
277 $formquestion = array();
278 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneAsk',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1);
282 $parameters = array(
'formConfirm' => $formconfirm);
283 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters,
$object, $action);
284 if (empty($reshook)) {
285 $formconfirm .= $hookmanager->resPrint;
286 } elseif ($reshook > 0) {
287 $formconfirm = $hookmanager->resPrint;
296 $linkback =
'<a href="' . DOL_URL_ROOT .
'/asset/model/list.php?restore_lastsearch_values=1' . (!empty($socid) ?
'&socid=' . $socid :
'') .
'">' . $langs->trans(
"BackToList") .
'</a>';
298 $morehtmlref =
'<div class="refidno">';
299 $morehtmlref .=
'</div>';
302 dol_banner_tab(
$object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
305 print
'<div class="fichecenter">';
306 print
'<div class="underbanner clearboth"></div>';
307 print
'<table class="border centpercent tableforfield">' .
"\n";
312 foreach (
$object->fields as $key => $val) {
313 if (!empty($keyforbreak) && $key == $keyforbreak) {
318 if (abs($val[
'visible']) != 1 && abs($val[
'visible']) != 3 && abs($val[
'visible']) != 4 && abs($val[
'visible']) != 5) {
322 if (array_key_exists(
'enabled', $val) && isset($val[
'enabled']) && !
verifCond($val[
'enabled'])) {
325 if (in_array($key, array(
'ref',
'status'))) {
331 print
'<tr class="field_'.$key.
'"><td';
332 print
' class="'.(empty($val[
'tdcss']) ?
'titlefield' : $val[
'tdcss']).
' fieldname_'.$key;
334 if ($val[
'type'] ==
'text' || $val[
'type'] ==
'html') {
340 if (!empty($val[
'help'])) {
341 $labeltoshow .= $form->textwithpicto($langs->trans($val[
'label']), $langs->trans($val[
'help']));
343 if (isset($val[
'copytoclipboard']) && $val[
'copytoclipboard'] == 1) {
346 $labeltoshow .= $langs->trans($val[
'label']);
349 if (empty($val[
'alwayseditable'])) {
352 print $form->editfieldkey($labeltoshow, $key, $value,
$object, 1, $val[
'type']);
356 print
'<td class="valuefield fieldname_'.$key;
357 if ($val[
'type'] ==
'text') {
360 if (!empty($val[
'cssview'])) {
361 print
' '.$val[
'cssview'];
364 if (empty($val[
'alwayseditable'])) {
365 if (preg_match(
'/^(text|html)/', $val[
'type'])) {
366 print
'<div class="longmessagecut">';
368 if ($key ==
'lang') {
369 $langs->load(
"languages");
370 $labellang = ($value ? $langs->trans(
'Language_'.$value) :
'');
374 if (isset($val[
'copytoclipboard']) && $val[
'copytoclipboard'] == 2) {
375 $out =
$object->showOutputField($val, $key, $value,
'',
'',
'', 0);
378 print
$object->showOutputField($val, $key, $value,
'',
'',
'', 0);
382 if (preg_match(
'/^(text|html)/', $val[
'type'])) {
386 print $form->editfieldval($labeltoshow, $key, $value,
$object, 1, $val[
'type']);
393 include DOL_DOCUMENT_ROOT .
'/core/tpl/extrafields_view.tpl.php';
397 print
'<div class="fichehalfleft">';
398 print
'<table class="border centpercent tableforfield">';
399 include DOL_DOCUMENT_ROOT .
'/asset/tpl/depreciation_options_view.tpl.php';
404 print
'<div class="fichehalfright">';
405 print
'<table class="border centpercent tableforfield">';
406 include DOL_DOCUMENT_ROOT .
'/asset/tpl/accountancy_codes_view.tpl.php';
411 print
'<div class="clearboth"></div>';
417 if ($action !=
'editline') {
418 print
'<div class="tabsAction">' .
"\n";
419 $parameters = array();
420 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters,
$object, $action);
425 if (empty($reshook)) {
426 if (
$object->status == $object::STATUS_DRAFT) {
427 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=edit&token=' .
newToken(),
'', $permissiontoadd);
431 if (
$object->status != $object::STATUS_DRAFT) {
432 print
dolGetButtonAction($langs->trans(
'SetToDraft'),
'',
'default', $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=confirm_setdraft&confirm=yes&token=' .
newToken(),
'', $permissiontoadd);
435 if (
$object->status != $object::STATUS_VALIDATED) {
436 print
dolGetButtonAction($langs->trans(
'Enable'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?id=' .
$object->id .
'&action=confirm_validate&confirm=yes&token=' .
newToken(),
'', $permissiontoadd);
439 if (
$object->status != $object::STATUS_CANCELED) {
440 print
dolGetButtonAction($langs->trans(
'Disable'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=confirm_close&confirm=yes&token='.
newToken(),
'', $permissiontoadd);
444 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?id=' .
$object->id . (!empty($socid) ?
'&socid=' . $socid :
'') .
'&action=clone&token=' .
newToken(),
'', $permissiontoadd);
447 print
dolGetButtonAction($langs->trans(
'Delete'),
'',
'delete', $_SERVER[
'PHP_SELF'] .
'?id=' .
$object->id .
'&action=delete&token=' .
newToken(),
'', $permissiontodelete || (
$object->status == $object::STATUS_DRAFT && $permissiontoadd));
449 print
'</div>' .
"\n";
452 print
'<div class="fichecenter"><div class="fichehalfleft">';
453 print
'<a name="builddoc"></a>';
455 print
'</div><div class="fichehalfright">';
466 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.