--- /tmp/dsg/dolibarr/htdocs/asset/github_19.0.3_card.php +++ /tmp/dsg/dolibarr/htdocs/asset/client_card.php @@ -2,2 +2,2 @@ -/* Copyright (C) 2017 Laurent Destailleur - * Copyright (C) 2018 Alexandre Spangaro +/* Copyright (C) 2017 Laurent Destailleur + * Copyright (C) 2018 Alexandre Spangaro @@ -25 +24,0 @@ -// Load Dolibarr environment @@ -33 +32 @@ -$langs->loadLangs(array("assets", "other")); +$langs->loadLangs(array("asset")); @@ -41 +40 @@ -$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'assetcard'; // To manage different context of search +$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'myobjectcard'; // To manage different context of search @@ -57 +56 @@ -$search_all = GETPOST("search_all", 'alpha'); +$search_all = trim(GETPOST("search_all", 'alpha')); @@ -59,9 +58,6 @@ -foreach ($object->fields as $key => $val) { - if (GETPOST('search_'.$key, 'alpha')) { - $search[$key] = GETPOST('search_'.$key, 'alpha'); - } -} - -if (empty($action) && empty($id) && empty($ref)) { - $action = 'view'; -} +foreach ($object->fields as $key => $val) +{ + if (GETPOST('search_'.$key, 'alpha')) $search[$key] = GETPOST('search_'.$key, 'alpha'); +} + +if (empty($action) && empty($id) && empty($ref)) $action = 'view'; @@ -72,22 +68,7 @@ -$permissiontoread = $user->hasRight('asset', 'read'); -$permissiontoadd = $user->hasRight('asset', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php -$permissiontodelete = $user->hasRight('asset', 'delete') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT); -$permissionnote = $user->hasRight('asset', 'write'); // Used by the include of actions_setnotes.inc.php -$permissiondellink = $user->hasRight('asset', 'write'); // Used by the include of actions_dellink.inc.php -$upload_dir = $conf->asset->multidir_output[isset($object->entity) ? $object->entity : 1]; - -// Security check (enable the most restrictive one) -if ($user->socid > 0) { - accessforbidden(); -} -if ($user->socid > 0) { - $socid = $user->socid; -} -$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0); -restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft); -if (!isModEnabled('asset')) { - accessforbidden(); -} -if (!$permissiontoread) { - accessforbidden(); -} + +$permissiontoread = $user->rights->asset->read; +$permissiontoadd = $user->rights->asset->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php +$permissiontodelete = $user->rights->asset->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT); +$permissionnote = $user->rights->asset->write; // Used by the include of actions_setnotes.inc.php +$permissiondellink = $user->rights->asset->write; // Used by the include of actions_dellink.inc.php +$upload_dir = $conf->mymodule->multidir_output[isset($object->entity) ? $object->entity : 1]; @@ -102,5 +83,4 @@ -if ($reshook < 0) { - setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -} - -if (empty($reshook)) { +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + +if (empty($reshook)) +{ @@ -109,32 +89,4 @@ - $backurlforlist = DOL_URL_ROOT.'/asset/list.php'; - - if (empty($backtopage) || ($cancel && empty($id))) { - if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) { - if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) { - $backtopage = $backurlforlist; - } else { - $backtopage = DOL_URL_ROOT.'/asset/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__'); - } - } - } - - $object->oldcopy = dol_clone($object, 2); - $triggermodname = 'ASSET_MODIFY'; // Name of trigger action code to execute when we modify record - - // Action dispose object - if ($action == 'confirm_disposal' && $confirm == 'yes' && $permissiontoadd) { - $object->disposal_date = dol_mktime(12, 0, 0, GETPOST('disposal_datemonth', 'int'), GETPOST('disposal_dateday', 'int'), GETPOST('disposal_dateyear', 'int')); // for date without hour, we use gmt - $object->disposal_amount_ht = GETPOST('disposal_amount', 'int'); - $object->fk_disposal_type = GETPOST('fk_disposal_type', 'int'); - $disposal_invoice_id = GETPOST('disposal_invoice_id', 'int'); - $object->disposal_depreciated = ((GETPOST('disposal_depreciated') == '1' || GETPOST('disposal_depreciated') == 'on') ? 1 : 0); - $object->disposal_subject_to_vat = ((GETPOST('disposal_subject_to_vat') == '1' || GETPOST('disposal_subject_to_vat') == 'on') ? 1 : 0); - - $result = $object->dispose($user, $disposal_invoice_id); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } - $action = ''; - } elseif ($action == "add") { - $object->supplier_invoice_id = GETPOST('supplier_invoice_id', 'int'); - } + $backurlforlist = dol_buildpath('/asset/list.php', 1); + + // Actions cancel, add, update or delete + include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php'; @@ -155,0 +108,9 @@ + + if ($action == 'set_thirdparty' && $permissiontoadd) + { + $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, 'MYOBJECT_MODIFY'); + } + if ($action == 'classin' && $permissiontoadd) + { + $object->setProject(GETPOST('projectid', 'int')); + } @@ -164,0 +126,2 @@ + + @@ -167,0 +131 @@ + * Put here all code to build page @@ -173 +137 @@ -$title = $langs->trans("Asset").' - '.$langs->trans("Card"); +$title = $langs->trans("Assets").' - '.$langs->trans("Card"); @@ -176,0 +141,16 @@ +// Example : Adding jquery code +print ''; + + @@ -178,2 +158,3 @@ -if ($action == 'create') { - print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("Asset")), '', 'object_'.$object->picto); +if ($action == 'create') +{ + print load_fiche_titre($langs->trans("NewAsset"), '', 'accountancy'); @@ -184,15 +165,4 @@ - if ($backtopage) { - print ''; - } - if ($backtopageforcancel) { - print ''; - } - if (GETPOSTISSET('supplier_invoice_id')) { - $object->fields['supplier_invoice_id'] = array('type' => 'integer:FactureFournisseur:fourn/class/fournisseur.facture.class.php:1:entity IN (__SHARED_ENTITIES__)', 'label' => 'SupplierInvoice', 'enabled' => '1', 'noteditable' => '1', 'position' => 280, 'notnull' => 0, 'visible' => 1, 'index' => 1, 'validate' => '1',); - print ''; - } - - print dol_get_fiche_head(array(), ''); - - // Set some default values - //if (! GETPOSTISSET('fieldname')) $_POST['fieldname'] = 'myvalue'; + if ($backtopage) print ''; + if ($backtopageforcancel) print ''; + + dol_fiche_head(array(), ''); @@ -210,3 +180,7 @@ - print dol_get_fiche_end(); - - print $form->buttonsSaveCancel("Create"); + dol_fiche_end(); + + print '
'; + print ''; + print '  '; + print ''; // Cancel for create does not post form if we don't know the backtopage + print '
'; @@ -220,2 +194,3 @@ -if (($id || $ref) && $action == 'edit') { - print load_fiche_titre($langs->trans("Asset"), '', 'object_'.$object->picto); +if (($id || $ref) && $action == 'edit') +{ + print load_fiche_titre($langs->trans("Assets")); @@ -225,0 +201 @@ + print ''; @@ -227,8 +203,4 @@ - if ($backtopage) { - print ''; - } - if ($backtopageforcancel) { - print ''; - } - - print dol_get_fiche_head(); + if ($backtopage) print ''; + if ($backtopageforcancel) print ''; + + dol_fiche_head(); @@ -246,3 +218,5 @@ - print dol_get_fiche_end(); - - print $form->buttonsSaveCancel(); + dol_fiche_end(); + + print '
'; + print '   '; + print '
'; @@ -254 +228,2 @@ -if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) { +if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) +{ @@ -257,2 +232,2 @@ - $head = assetPrepareHead($object); - print dol_get_fiche_head($head, 'card', $langs->trans("Asset"), -1, $object->picto); + $head = asset_prepare_head($object); + dol_fiche_head($head, 'card', $langs->trans("Asset"), -1, $object->picto); @@ -263,36 +238,8 @@ - if ($action == 'delete') { - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteAsset'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1); - } elseif ($action == 'disposal') { - // Disposal - $langs->load('bills'); - - $disposal_date = dol_mktime(12, 0, 0, GETPOST('disposal_datemonth', 'int'), GETPOST('disposal_dateday', 'int'), GETPOST('disposal_dateyear', 'int')); // for date without hour, we use gmt - $disposal_amount = GETPOST('disposal_amount', 'int'); - $fk_disposal_type = GETPOST('fk_disposal_type', 'int'); - $disposal_invoice_id = GETPOST('disposal_invoice_id', 'int'); - $disposal_depreciated = GETPOSTISSET('disposal_depreciated') ? GETPOST('disposal_depreciated') : 1; - $disposal_depreciated = !empty($disposal_depreciated) ? 1 : 0; - $disposal_subject_to_vat = GETPOSTISSET('disposal_subject_to_vat') ? GETPOST('disposal_subject_to_vat') : 1; - $disposal_subject_to_vat = !empty($disposal_subject_to_vat) ? 1 : 0; - - $object->fields['fk_disposal_type']['visible'] = 1; - $disposal_type_form = $object->showInputField(null, 'fk_disposal_type', $fk_disposal_type, '', '', '', 0); - $object->fields['fk_disposal_type']['visible'] = -2; - - $object->fields['disposal_invoice_id'] = array('type' => 'integer:Facture:compta/facture/class/facture.class.php::entity IN (__SHARED_ENTITIES__)', 'enabled' => '1', 'notnull' => 1, 'visible' => 1, 'index' => 1, 'validate' => '1',); - $disposal_invoice_form = $object->showInputField(null, 'disposal_invoice_id', $disposal_invoice_id, '', '', '', 0); - unset($object->fields['disposal_invoice_id']); - - // Create an array for form - $formquestion = array( - array('type' => 'date', 'name' => 'disposal_date', 'tdclass' => 'fieldrequired', 'label' => $langs->trans("AssetDisposalDate"), 'value' => $disposal_date), - array('type' => 'text', 'name' => 'disposal_amount', 'tdclass' => 'fieldrequired', 'label' => $langs->trans("AssetDisposalAmount"), 'value' => $disposal_amount), - array('type' => 'other', 'name' => 'fk_disposal_type', 'tdclass' => 'fieldrequired', 'label' => $langs->trans("AssetDisposalType"), 'value' => $disposal_type_form), - array('type' => 'other', 'name' => 'disposal_invoice_id', 'label' => $langs->trans("InvoiceCustomer"), 'value' => $disposal_invoice_form), - array('type' => 'checkbox', 'name' => 'disposal_depreciated', 'label' => $langs->trans("AssetDisposalDepreciated"), 'value' => $disposal_depreciated), - array('type' => 'checkbox', 'name' => 'disposal_subject_to_vat', 'label' => $langs->trans("AssetDisposalSubjectToVat"), 'value' => $disposal_subject_to_vat), - ); - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('AssetDisposal'), $langs->trans('AssetConfirmDisposalAsk', $object->ref . ' - ' . $object->label), 'confirm_disposal', $formquestion, 'yes', 1); - } elseif ($action == 'reopen') { - // Re-open - // Create an array for form + if ($action == 'delete') + { + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteAssets'), $langs->trans('ConfirmDeleteAssets'), 'confirm_delete', '', 0, 1); + } + + // Confirmation of action xxxx + if ($action == 'xxx') + { @@ -300,8 +247,2 @@ - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReOpen'), $langs->trans('AssetConfirmReOpenAsk', $object->ref), 'confirm_reopen', $formquestion, 'yes', 1); - } - // Clone confirmation - /* elseif ($action == 'clone') { - // Create an array for form - $formquestion = array(); - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1); - }*/ + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220); + } @@ -310 +251 @@ - $parameters = array('formConfirm' => $formconfirm); + $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid); @@ -312,5 +253,2 @@ - if (empty($reshook)) { - $formconfirm .= $hookmanager->resPrint; - } elseif ($reshook > 0) { - $formconfirm = $hookmanager->resPrint; - } + if (empty($reshook)) $formconfirm .= $hookmanager->resPrint; + elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint; @@ -324 +262 @@ - $linkback = ''.$langs->trans("BackToList").''; + $linkback = ''.$langs->trans("BackToList").''; @@ -326,0 +265,7 @@ + /* + // Ref bis + $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->asset->creer, 'string', '', 0, 1); + $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->asset->creer, 'string', '', null, null, '', 1); + // Thirdparty + $morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1); + */ @@ -329 +273,0 @@ - @@ -331 +274,0 @@ - @@ -336 +279 @@ - print ''."\n"; + print '
'."\n"; @@ -339 +282 @@ - $keyforbreak='date_acquisition'; // We change column just before this field + //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just after this field @@ -349,0 +293 @@ + print ''; @@ -353 +297,2 @@ - print dol_get_fiche_end(); + dol_fiche_end(); + @@ -357 +302 @@ - print '
' . "\n"; + print '
'."\n"; @@ -360,5 +305,4 @@ - if ($reshook < 0) { - setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - } - - if (empty($reshook)) { + if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + + if (empty($reshook)) + { @@ -367,18 +311,20 @@ - print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=presend&mode=init&token=' . newToken() . '#formmailbeforetitle'); - } - - if ($object->status == $object::STATUS_DRAFT) { - print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=edit&token=' . newToken(), '', $permissiontoadd); - } - - // Clone - //print dolGetButtonAction($langs->trans('ToClone'), '', 'default', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=clone&token=' . newToken(), '', false && $permissiontoadd); - - if ($object->status == $object::STATUS_DRAFT) { - print dolGetButtonAction($langs->trans('AssetDisposal'), '', 'default', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=disposal&token=' . newToken(), '', $permissiontoadd); - } else { - print dolGetButtonAction($langs->trans('ReOpen'), '', 'default', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=reopen&token=' . newToken(), '', $permissiontoadd); - } - - // Delete (need delete permission, or if draft, just need create/modify permission) - print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=delete&token=' . newToken(), '', $permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd)); + print ''.$langs->trans('SendMail').''."\n"; + } + + if ($user->rights->asset->write) + { + print ''.$langs->trans("Modify").''."\n"; + } + else + { + print ''.$langs->trans('Modify').''."\n"; + } + + if ($user->rights->asset->delete) + { + print ''.$langs->trans('Delete').''."\n"; + } + else + { + print ''.$langs->trans('Delete').''."\n"; + } @@ -386,2 +332,3 @@ - print '
' . "\n"; - } + print '
'."\n"; + } + @@ -394 +341,2 @@ - if ($action != 'presend') { + if ($action != 'presend') + { @@ -398,2 +345,0 @@ - $includedocgeneration = 0; - @@ -401,9 +347,8 @@ - if ($includedocgeneration) { - $objref = dol_sanitizeFileName($object->ref); - $relativepath = $objref.'/'.$objref.'.pdf'; - $filedir = $conf->asset->dir_output.'/'.$objref; - $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id; - $genallowed = $user->hasRight('asset', 'read'); // If you can read, you can build the PDF to read content - $delallowed = $user->hasRight('asset', 'write'); // If you can create/edit, you can remove a file on card - print $formfile->showdocuments('asset:Asset', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang); - } + /*$objref = dol_sanitizeFileName($object->ref); + $relativepath = $comref . '/' . $comref . '.pdf'; + $filedir = $conf->asset->dir_output . '/' . $objref; + $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id; + $genallowed = $user->rights->asset->read; // If you can read, you can build the PDF to read content + $delallowed = $user->rights->asset->create; // If you can create/edit, you can remove a file on card + print $formfile->showdocuments('asset', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang); + */ @@ -416,3 +361,2 @@ - print '
'; - - $morehtmlcenter = ''; + print '
'; + @@ -421 +365,3 @@ - $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/asset/agenda.php?id='.$object->id); + $morehtmlright = ''; + $morehtmlright .= $langs->trans("SeeAll"); + $morehtmlright .= ''; @@ -426,3 +372,3 @@ - $somethingshown = $formactions->showactions($object, $object->element, 0, 1, '', $MAXEVENT, '', $morehtmlcenter); - - print '
'; + $somethingshown = $formactions->showactions($object, 'asset', $socid, 1, '', $MAXEVENT, '', $morehtmlright); + + print ''; @@ -432,12 +378,13 @@ - if (GETPOST('modelselected')) { - $action = 'presend'; - } - - // Presend form - $modelmail = 'asset'; - $defaulttopic = 'InformationMessage'; - $diroutput = $conf->asset->dir_output; - $trackid = 'asset'.$object->id; - - include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; -} + if (GETPOST('modelselected')) $action = 'presend'; + + // Presend form + /* + $modelmail='asset'; + $defaulttopic='InformationMessage'; + $diroutput = $conf->asset->dir_output.'/asset'; + $trackid = 'asset'.$object->id; + + include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; + */ +} + --- /tmp/dsg/dolibarr/htdocs/asset/github_19.0.3_document.php +++ /tmp/dsg/dolibarr/htdocs/asset/client_document.php @@ -3 +3 @@ - * Copyright (C) 2018-2021 Alexandre Spangaro + * Copyright (C) 2018 Alexandre Spangaro @@ -22 +22 @@ - * \brief Page for attached files on assets + * \brief Tab for documents linked to Assets @@ -25 +24,0 @@ -// Load Dolibarr environment @@ -35 +34 @@ -$langs->loadLangs(array('assets', 'companies', 'other', 'mails')); +$langs->loadLangs(array("assets", "companies")); @@ -39,2 +38,2 @@ -$confirm = GETPOST('confirm', 'alpha'); -$id = GETPOST('id', 'int'); +$confirm = GETPOST('confirm'); +$id = (GETPOST('socid', 'int') ? GETPOST('socid', 'int') : GETPOST('id', 'int')); @@ -41,0 +41,5 @@ + +// Security check - Protection if external user +//if ($user->socid > 0) accessforbidden(); +//if ($user->socid > 0) $socid = $user->socid; +//$result = restrictedArea($user, 'asset', $id); @@ -48,3 +52 @@ -if (empty($page) || $page == -1) { - $page = 0; -} // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 @@ -54,6 +56,2 @@ -if (!$sortorder) { - $sortorder = "ASC"; -} -if (!$sortfield) { - $sortfield = "name"; -} +if (!$sortorder) $sortorder = "ASC"; +if (!$sortfield) $sortfield = "name"; @@ -64,2 +62,3 @@ -$diroutputmassaction = $conf->asset->dir_output.'/temp/massgeneration/'.$user->id; -$hookmanager->initHooks(array('assetdocument', 'globalcard')); // Note that conf->hooks_modules contains array +$diroutputmassaction = $conf->assets->dir_output.'/temp/massgeneration/'.$user->id; +$hookmanager->initHooks(array('assetdocument')); // Note that conf->hooks_modules contains array + @@ -72,3 +71,2 @@ -if ($id > 0 || !empty($ref)) { - $upload_dir = $conf->asset->multidir_output[$object->entity ? $object->entity : $conf->entity]."/".get_exdir(0, 0, 0, 1, $object); -} +//if ($id > 0 || ! empty($ref)) $upload_dir = $conf->sellyoursaas->multidir_output[$object->entity] . "/packages/" . dol_sanitizeFileName($object->id); +if ($id > 0 || !empty($ref)) $upload_dir = $conf->sellyoursaas->multidir_output[$object->entity]."/packages/".dol_sanitizeFileName($object->ref); @@ -76,11 +73,0 @@ -$permissiontoadd = $user->rights->asset->write; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles.inc.php - -// Security check (enable the most restrictive one) -if ($user->socid > 0) { - accessforbidden(); -} -$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0); -restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft); -if (!isModEnabled('asset')) { - accessforbidden(); -} @@ -93 +80 @@ -include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php'; +include_once DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php'; @@ -102 +89 @@ -$title = $langs->trans("Asset").' - '.$langs->trans("Files"); +$title = $langs->trans("Assets").' - '.$langs->trans("Files"); @@ -103,0 +91 @@ +//$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; @@ -106 +94,2 @@ -if ($object->id) { +if ($object->id) +{ @@ -110 +99,2 @@ - $head = assetPrepareHead($object); + if (!empty($conf->notification->enabled)) $langs->load("mails"); + $head = asset_prepare_head($object); @@ -112 +102 @@ - print dol_get_fiche_head($head, 'document', $langs->trans("Asset"), -1, $object->picto); + dol_fiche_head($head, 'document', $langs->trans("Asset"), -1, 'generic'); @@ -116 +106 @@ - $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1); + $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); @@ -118 +108,2 @@ - foreach ($filearray as $key => $file) { + foreach ($filearray as $key => $file) + { @@ -124,4 +115 @@ - $linkback = '' . $langs->trans("BackToList") . ''; - - $morehtmlref = '
'; - $morehtmlref .= '
'; + $linkback = ''.$langs->trans("BackToList").''; @@ -134 +122 @@ - print '
'; + print '
'; @@ -137 +125 @@ - print ''; + print ''; @@ -140 +128 @@ - print ''; + print ''; @@ -146 +134 @@ - print dol_get_fiche_end(); + dol_fiche_end(); @@ -149,5 +137,5 @@ - $permissiontoadd = $user->hasRight('asset', 'write'); - // $permissiontoadd = 1; - $permtoedit = $user->hasRight('asset', 'write'); - // $permtoedit = 1; - $param = '&id=' . $object->id; + //$permission = $user->rights->asset->create; + $permission = 1; + //$permtoedit = $user->rights->asset->create; + $permtoedit = 1; + $param = '&id='.$object->id; @@ -156 +144 @@ - $relativepathwithnofile = dol_sanitizeFileName($object->ref) . '/'; + $relativepathwithnofile = 'asset/'.dol_sanitizeFileName($object->ref).'/'; @@ -158,2 +146,4 @@ - include DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; -} else { + include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php'; +} +else +{ --- /tmp/dsg/dolibarr/htdocs/asset/github_19.0.3_info.php +++ /tmp/dsg/dolibarr/htdocs/asset/client_info.php @@ -0,0 +1,87 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/asset/info.php + * \ingroup asset + * \brief Page to show an asset information + */ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/asset.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/asset/class/asset.class.php'; + +// Load translation files required by the page +$langs->loadLangs(array("asset")); + +$id = GETPOST('id', 'int'); +$ref = GETPOST('ref', 'alpha'); +$action = GETPOST('action', 'alpha'); + +// Security check +if ($user->socid) $socid = $user->socid; +$result = restrictedArea($user, 'asset', $id, ''); + +$object = new Asset($db); +$object->fetch($id); + +/* + * Actions + */ + + + +/* + * View + */ + +$form = new Form($db); + +$title = $langs->trans('Asset')." - ".$langs->trans('Info'); +$helpurl = ""; +llxHeader('', $title, $helpurl); + +$object->info($id); + +$head = asset_prepare_head($object); + +dol_fiche_head($head, 'info', $langs->trans("Asset"), -1, 'generic'); + +$linkback = ''.$langs->trans("BackToList").''; + +$morehtmlref = '
'; +$morehtmlref .= '
'; + +dol_banner_tab($object, 'rowid', $linkback, 1, 'rowid', 'ref', $morehtmlref); + +print '
'; +print '
'; + +print '
'; + +print '
' . $langs->trans("NbOfAttachedFiles") . '' . count($filearray) . '
'.$langs->trans("NbOfAttachedFiles").''.count($filearray).'
' . $langs->trans("TotalSizeOfAttachedFiles") . '' . $totalsize . ' ' . $langs->trans("bytes") . '
'.$langs->trans("TotalSizeOfAttachedFiles").''.$totalsize.' '.$langs->trans("bytes").'
'; +dol_print_object_info($object); +print '
'; + +print ''; + +dol_fiche_end(); + +// End of page +llxFooter(); +$db->close(); --- /tmp/dsg/dolibarr/htdocs/asset/github_19.0.3_list.php +++ /tmp/dsg/dolibarr/htdocs/asset/client_list.php @@ -34,14 +34,13 @@ -$langs->loadLangs(array("assets", "other")); - -// Get parameters -$action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ... -$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists) -$show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ? -$confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation -$cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button -$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list -$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'assetlist'; // To manage different context of search -$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page -$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') -$mode = GETPOST('mode', 'alpha'); // mode view (kanban or common) -$id = GETPOST('id', 'int'); +$langs->loadLangs(array("assets")); + +$action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ... +$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists) +$show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ? +$confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation +$cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button +$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list +$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'assetslist'; // To manage different context of search +$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page +$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') + +$id = GETPOST('id', 'int'); @@ -50,3 +49,3 @@ -$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST('sortfield', 'aZ09comma'); -$sortorder = GETPOST('sortorder', 'aZ09comma'); +$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; +$sortfield = GETPOST('sortfield', 'alpha'); +$sortorder = GETPOST('sortorder', 'alpha'); @@ -54,3 +53 @@ -if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) { - $page = 0; -} // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action +if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action @@ -74,7 +71,11 @@ -if (!$sortfield) { - reset($object->fields); // Reset is required to avoid key() to return null. - $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition. -} -if (!$sortorder) { - $sortorder = "ASC"; -} +if (!$sortfield) $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition. +if (!$sortorder) $sortorder = "ASC"; + +// Security check +$socid = 0; +if ($user->socid > 0) // Protection if external user +{ + //$socid = $user->socid; + accessforbidden(); +} +//$result = restrictedArea($user, 'asset', $id,''); @@ -83 +84 @@ -$search_all = GETPOST('search_all', 'alphanohtml'); +$search_all = trim(GETPOST("search_all", 'alpha')); @@ -85,8 +86,3 @@ -foreach ($object->fields as $key => $val) { - if (GETPOST('search_'.$key, 'alpha') !== '') { - $search[$key] = GETPOST('search_'.$key, 'alpha'); - } - if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) { - $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int')); - $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int')); - } +foreach ($object->fields as $key => $val) +{ + if (GETPOST('search_'.$key, 'alpha') !== '') $search[$key] = GETPOST('search_'.$key, 'alpha'); @@ -97,7 +93,6 @@ -foreach ($object->fields as $key => $val) { - if (!empty($val['searchall'])) { - $fieldstosearchall['t.'.$key] = $val['label']; - } -} - -// Definition of array of fields for columns +foreach ($object->fields as $key => $val) +{ + if ($val['searchall']) $fieldstosearchall['t.'.$key] = $val['label']; +} + +// Definition of fields for list @@ -105 +100,2 @@ -foreach ($object->fields as $key => $val) { +foreach ($object->fields as $key => $val) +{ @@ -107,10 +103 @@ - if (!empty($val['visible'])) { - $visible = (int) dol_eval($val['visible'], 1); - $arrayfields['t.'.$key] = array( - 'label'=>$val['label'], - 'checked'=>(($visible < 0) ? 0 : 1), - 'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1)), - 'position'=>$val['position'], - 'help'=> isset($val['help']) ? $val['help'] : '' - ); - } + if (!empty($val['visible'])) $arrayfields['t.'.$key] = array('label'=>$val['label'], 'checked'=>(($val['visible'] < 0) ? 0 : 1), 'enabled'=>($val['enabled'] && ($val['visible'] != 3)), 'position'=>$val['position']); @@ -119,2 +106,14 @@ -include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php'; - +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0) +{ + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) + { + if (!empty($extrafields->attributes[$object->table_element]['list'][$key])) { + $arrayfields["ef.".$key] = array( + 'label'=>$extrafields->attributes[$object->table_element]['label'][$key], + 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key] < 0) ? 0 : 1), + 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key], + 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3 && $extrafields->attributes[$object->table_element]['perms'][$key]) + ); + } + } +} @@ -124,25 +123,3 @@ -$permissiontoread = $user->hasRight('asset', 'read'); -$permissiontoadd = $user->hasRight('asset', 'write'); -$permissiontodelete = $user->hasRight('asset', 'delete'); - -// Security check -if (!isModEnabled('asset')) { - accessforbidden('Module not enabled'); -} - -// Security check (enable the most restrictive one) -if ($user->socid > 0) { - accessforbidden(); -} -$socid = 0; if ($user->socid > 0) { - $socid = $user->socid; -} -$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0); -restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft); -if (!isModEnabled('asset')) { - accessforbidden(); -} -if (!$permissiontoread) { - accessforbidden(); -} - +$permissiontoread = $user->rights->asset->read; +$permissiontoadd = $user->rights->asset->write; +$permissiontodelete = $user->rights->asset->delete; @@ -155,7 +132,2 @@ -if (GETPOST('cancel', 'alpha')) { - $action = 'list'; - $massaction = ''; -} -if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { - $massaction = ''; -} +if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; } +if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; } @@ -165,5 +137,4 @@ -if ($reshook < 0) { - setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -} - -if (empty($reshook)) { +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + +if (empty($reshook)) +{ @@ -174,2 +145,4 @@ - if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers - foreach ($object->fields as $key => $val) { + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers + { + foreach ($object->fields as $key => $val) + { @@ -177,4 +149,0 @@ - if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) { - $search[$key.'_dtstart'] = ''; - $search[$key.'_dtend'] = ''; - } @@ -182 +151 @@ - $toselect = array(); + $toselect = ''; @@ -186 +155,2 @@ - || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) { + || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) + { @@ -206,0 +177 @@ +//$help_url="EN:Module_Asset|FR:Module_Asset_FR|ES:Módulo_Asset"; @@ -209,2 +179,0 @@ -$morejs = array(); -$morecss = array(); @@ -216 +185,4 @@ -$sql .= $object->getFieldList('t'); +foreach ($object->fields as $key => $val) +{ + $sql .= 't.'.$key.', '; +} @@ -219,3 +191 @@ - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { - $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : ''); - } + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.' as options_'.$key.', ' : ''); @@ -226 +196 @@ -$sql .= $hookmanager->resPrint; +$sql .= preg_replace('/^,/', '', $hookmanager->resPrint); @@ -228,3 +197,0 @@ - -$sqlfields = $sql; // $sql fields to remove for count total - @@ -232,44 +199,14 @@ -if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)"; -} -// Add table from hooks -$parameters = array(); -$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook -$sql .= $hookmanager->resPrint; -if ($object->ismultientitymanaged == 1) { - $sql .= " WHERE t.entity IN (".getEntity($object->element).")"; -} else { - $sql .= " WHERE 1 = 1"; -} -foreach ($search as $key => $val) { - if (array_key_exists($key, $object->fields)) { - if ($key == 'status' && $search[$key] == -1) { - continue; - } - $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0); - if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) { - if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) { - $search[$key] = ''; - } - $mode_search = 2; - } - if ($search[$key] != '') { - $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search)); - } - } else { - if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') { - $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key); - if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) { - if (preg_match('/_dtstart$/', $key)) { - $sql .= " AND t.".$columnName." >= '".$db->idate($search[$key])."'"; - } - if (preg_match('/_dtend$/', $key)) { - $sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'"; - } - } - } - } -} -if ($search_all) { - $sql .= natural_search(array_keys($fieldstosearchall), $search_all); -} +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)"; +if ($object->ismultientitymanaged == 1) $sql .= " WHERE t.entity IN (".getEntity($object->element).")"; +else $sql .= " WHERE 1 = 1"; +foreach ($search as $key => $val) +{ + if ($key == 'status' && $search[$key] == -1) continue; + $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0); + if (strpos($object->fields[$key]['type'], 'integer:') === 0) { + if ($search[$key] == '-1') $search[$key] = ''; + $mode_search = 2; + } + if ($search[$key] != '') $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search)); +} +if ($search_all) $sql .= natural_search(array_keys($fieldstosearchall), $search_all); @@ -285,3 +222,4 @@ -$sql .= " GROUP BY "; -foreach($object->fields as $key => $val) { - $sql .= "t.".$key.", "; +$sql.= " GROUP BY " +foreach($object->fields as $key => $val) +{ + $sql.='t.'.$key.', '; @@ -290,4 +228,2 @@ -if (!empty($extrafields->attributes[$object->table_element]['label'])) { - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { - $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : ''); - } +if (! empty($extrafields->attributes[$object->table_element]['label'])) { + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : ''); @@ -296,4 +232,4 @@ -$parameters = array(); -$reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook -$sql .= $hookmanager->resPrint; -$sql = preg_replace('/,\s*$/', '', $sql); +$parameters=array(); +$reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook +$sql.=$hookmanager->resPrint; +$sql=preg_replace('/,\s*$/','', $sql); @@ -302,6 +238 @@ -// Add HAVING from hooks -/* -$parameters = array(); -$reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook -$sql .= !empty($hookmanager->resPrint) ? (" HAVING 1=1 " . $hookmanager->resPrint) : ""; -*/ +$sql .= $db->order($sortfield, $sortorder); @@ -311,13 +242,6 @@ -if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) { - /* The fast and low memory method to get and count full list converts the sql into a sql count */ - $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql); - $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount); - $resql = $db->query($sqlforcount); - if ($resql) { - $objforcount = $db->fetch_object($resql); - $nbtotalofrecords = $objforcount->nbtotalofrecords; - } else { - dol_print_error($db); - } - - if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) +{ + $resql = $db->query($sql); + $nbtotalofrecords = $db->num_rows($resql); + if (($page * $limit) > $nbtotalofrecords) // if total of record found is smaller than page * limit, goto and load page 0 + { @@ -327,17 +251,19 @@ - $db->free($resql); -} - -// Complete request and execute it with limit -$sql .= $db->order($sortfield, $sortorder); -if ($limit) { - $sql .= $db->plimit($limit + 1, $offset); -} - -$resql = $db->query($sql); -if (!$resql) { - dol_print_error($db); - exit; -} - -$num = $db->num_rows($resql); - +} +// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set. +if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) +{ + $num = $nbtotalofrecords; +} +else +{ + if ($limit) $sql .= $db->plimit($limit + 1, $offset); + + $resql = $db->query($sql); + if (!$resql) + { + dol_print_error($db); + exit; + } + + $num = $db->num_rows($resql); +} @@ -346 +272,2 @@ -if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) { +if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) +{ @@ -349 +276 @@ - header("Location: ".DOL_URL_ROOT.'/asset/card.php?id='.$id); + header("Location: ".DOL_URL_ROOT.'/assets/card.php?id='.$id); @@ -357 +284,16 @@ -llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', ''); +llxHeader('', $title, $help_url); + +// Example : Adding jquery code +print ''; @@ -362,20 +304,8 @@ -if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { - $param .= '&contextpage='.urlencode($contextpage); -} -if ($limit > 0 && $limit != $conf->liste_limit) { - $param .= '&limit='.((int) $limit); -} -foreach ($search as $key => $val) { - if (is_array($search[$key]) && count($search[$key])) { - foreach ($search[$key] as $skey) { - if ($skey != '') { - $param .= '&search_'.$key.'[]='.urlencode($skey); - } - } - } elseif ($search[$key] != '') { - $param .= '&search_'.$key.'='.urlencode($search[$key]); - } -} -if ($optioncss != '') { - $param .= '&optioncss='.urlencode($optioncss); -} +if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); +if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); +foreach ($search as $key => $val) +{ + if (is_array($search[$key]) && count($search[$key])) foreach ($search[$key] as $skey) $param .= '&search_'.$key.'[]='.urlencode($skey); + else $param .= '&search_'.$key.'='.urlencode($search[$key]); +} +if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss); @@ -384,4 +313,0 @@ -// Add $param from hooks -$parameters = array('param' => &$param); -$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook -$param .= $hookmanager->resPrint; @@ -391,4 +317,2 @@ - //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"), - //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"), - //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"), - //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"), + //'presend'=>$langs->trans("SendByMail"), + //'builddoc'=>$langs->trans("PDFMerge"), @@ -396,6 +320,2 @@ -if ($permissiontodelete) { - $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete"); -} -if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) { - $arrayofmassactions = array(); -} +if ($permissiontodelete) $arrayofmassactions['predelete'] = ''.$langs->trans("Delete"); +if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); @@ -405,3 +325 @@ -if ($optioncss != '') { - print ''; -} +if ($optioncss != '') print ''; @@ -413 +330,0 @@ -print ''; @@ -416,4 +333,3 @@ -$newcardbutton = ''; -$newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/asset/card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd); - -print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1); +$newcardbutton = dolGetButtonTitle($langs->trans('NewAsset'), '', 'fa fa-plus-circle', dol_buildpath('/asset/card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd); + +print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'accountancy', 0, $newcardbutton, '', $limit, 0, 0, 1); @@ -422 +338 @@ -$topicmail = "SendAssetRef"; +$topicmail = "SendAssetsRef"; @@ -425 +341 @@ -$trackid = 'asset'.$object->id; +$trackid = 'xxxx'.$object->id; @@ -428,5 +344,4 @@ -if ($search_all) { - foreach ($fieldstosearchall as $key => $val) { - $fieldstosearchall[$key] = $langs->trans($val); - } - print '
'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'
'; +if ($sall) +{ + foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val); + print '
'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'
'; @@ -442,7 +357,5 @@ -if (empty($reshook)) { - $moreforfilter .= $hookmanager->resPrint; -} else { - $moreforfilter = $hookmanager->resPrint; -} - -if (!empty($moreforfilter)) { +if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; +else $moreforfilter = $hookmanager->resPrint; + +if (!empty($moreforfilter)) +{ @@ -459 +372 @@ -print ''."\n"; +print '
'."\n"; @@ -465,12 +378,9 @@ -foreach ($object->fields as $key => $val) { - $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']); - if ($key == 'status') { - $cssforfield .= ($cssforfield ? ' ' : '').'center'; - } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) { - $cssforfield .= ($cssforfield ? ' ' : '').'center'; - } elseif (in_array($val['type'], array('timestamp'))) { - $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; - } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) { - $cssforfield .= ($cssforfield ? ' ' : '').'right'; - } - if (!empty($arrayfields['t.'.$key]['checked'])) { +foreach ($object->fields as $key => $val) +{ + $cssforfield = (empty($val['css']) ? '' : $val['css']); + if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center'; + elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center'; + elseif (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; + elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right'; + if (!empty($arrayfields['t.'.$key]['checked'])) + { @@ -478,17 +388,3 @@ - if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) { - print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1); - } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) { - print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1); - } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) { - print '
'; - print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From')); - print '
'; - print '
'; - print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to')); - print '
'; - } elseif ($key == 'lang') { - require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php'; - $formadmin = new FormAdmin($db); - print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2); - } else { - print ''; + if (is_array($val['arrayofkeyval'])) print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth75'); + elseif (strpos($val['type'], 'integer:') === 0) { + print $object->showInputField($val, $key, $search[$key], '', '', 'search_', 'maxwidth150', 1); @@ -495,0 +392 @@ + elseif (!preg_match('/^(date|timestamp)/', $val['type'])) print ''; @@ -517,12 +414,9 @@ -foreach ($object->fields as $key => $val) { - $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']); - if ($key == 'status') { - $cssforfield .= ($cssforfield ? ' ' : '').'center'; - } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) { - $cssforfield .= ($cssforfield ? ' ' : '').'center'; - } elseif (in_array($val['type'], array('timestamp'))) { - $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; - } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) { - $cssforfield .= ($cssforfield ? ' ' : '').'right'; - } - if (!empty($arrayfields['t.'.$key]['checked'])) { +foreach ($object->fields as $key => $val) +{ + $cssforfield = (empty($val['css']) ? '' : $val['css']); + if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center'; + elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center'; + elseif (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; + elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right'; + if (!empty($arrayfields['t.'.$key]['checked'])) + { @@ -539 +433 @@ -print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n"; +print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ')."\n"; @@ -545,5 +439,5 @@ -if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) { - foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) { - if (!is_null($val) && preg_match('/\$object/', $val)) { - $needToFetchEachLine++; // There is at least one compute field that use $object - } +if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) +{ + foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) + { + if (preg_match('/\$object/', $val)) $needToFetchEachLine++; // There is at least one compute field that use $object @@ -558,2 +452,2 @@ -$totalarray['nbfield'] = 0; -while ($i < ($limit ? min($num, $limit) : $num)) { +while ($i < ($limit ? min($num, $limit) : $num)) +{ @@ -561,3 +455 @@ - if (empty($obj)) { - break; // Should not happen - } + if (empty($obj)) break; // Should not happen @@ -570,20 +462,13 @@ - foreach ($object->fields as $key => $val) { - $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']); - if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) { - $cssforfield .= ($cssforfield ? ' ' : '').'center'; - } elseif ($key == 'status') { - $cssforfield .= ($cssforfield ? ' ' : '').'center'; - } - - if (in_array($val['type'], array('timestamp'))) { - $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; - } elseif ($key == 'ref') { - $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; - } - - if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) { - $cssforfield .= ($cssforfield ? ' ' : '').'right'; - } - //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100'; - - if (!empty($arrayfields['t.'.$key]['checked'])) { + foreach ($object->fields as $key => $val) + { + $cssforfield = (empty($val['css']) ? '' : $val['css']); + if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center'; + elseif ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center'; + + if (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; + elseif ($key == 'ref') $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; + + if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'status') $cssforfield .= ($cssforfield ? ' ' : '').'right'; + + if (!empty($arrayfields['t.'.$key]['checked'])) + { @@ -591,7 +476,2 @@ - if ($key == 'status') { - print $object->getLibStatut(5); - } elseif ($key == 'rowid') { - print $object->showOutputField($val, $key, $object->id, ''); - } else { - print $object->showOutputField($val, $key, $object->$key, ''); - } + if ($key == 'status') print $object->getLibStatut(5); + else print $object->showOutputField($val, $key, $object->$key, ''); @@ -599,13 +479,4 @@ - if (!$i) { - $totalarray['nbfield']++; - } - if (!empty($val['isameasure']) && $val['isameasure'] == 1) { - if (!$i) { - $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key; - } - if (!isset($totalarray['val'])) { - $totalarray['val'] = array(); - } - if (!isset($totalarray['val']['t.'.$key])) { - $totalarray['val']['t.'.$key] = 0; - } + if (!$i) $totalarray['nbfield']++; + if (!empty($val['isameasure'])) + { + if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key; @@ -624 +495,2 @@ - if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined + if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined + { @@ -626,3 +498 @@ - if (in_array($object->id, $arrayofselected)) { - $selected = 1; - } + if (in_array($object->id, $arrayofselected)) $selected = 1; @@ -632,3 +502 @@ - if (!$i) { - $totalarray['nbfield']++; - } + if (!$i) $totalarray['nbfield']++; @@ -645 +513,2 @@ -if ($num == 0) { +if ($num == 0) +{ @@ -647,6 +516,2 @@ - foreach ($arrayfields as $key => $val) { - if (!empty($val['checked'])) { - $colspan++; - } - } - print ''; + foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; } + print ''; @@ -667 +532,2 @@ -if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) { +if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) +{ @@ -669,3 +535 @@ - if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) { - $hidegeneratedfilelistifempty = 0; - } + if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0; @@ -684 +548 @@ - print $formfile->showdocuments('massfilesarea_asset', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty); + print $formfile->showdocuments('massfilesarea_asset', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, ''); --- /tmp/dsg/dolibarr/htdocs/asset/github_19.0.3_note.php +++ /tmp/dsg/dolibarr/htdocs/asset/client_note.php @@ -25 +24,0 @@ -// Load Dolibarr environment @@ -31 +30 @@ -$langs->loadLangs(array("assets", "companies")); +$langs->loadLangs(array("asset", "companies")); @@ -36 +35 @@ -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); @@ -44 +43,2 @@ -$hookmanager->initHooks(array('assetnote', 'globalcard')); // Note that conf->hooks_modules contains array +$hookmanager->initHooks(array('assetnote')); // Note that conf->hooks_modules contains array + @@ -47,0 +48,5 @@ +// Security check - Protection if external user +//if ($user->socid > 0) accessforbidden(); +//if ($user->socid > 0) $socid = $user->socid; +//$result = restrictedArea($user, 'asset', $id); + @@ -50,3 +55 @@ -if ($id > 0 || !empty($ref)) { - $upload_dir = $conf->asset->multidir_output[$object->entity]."/".$object->id; -} +if ($id > 0 || !empty($ref)) $upload_dir = $conf->asset->multidir_output[$object->entity]."/".$object->id; @@ -54,12 +57,2 @@ -$permissionnote = $user->hasRight('asset', 'write'); // Used by the include of actions_setnotes.inc.php -$permissiontoadd = $user->hasRight('asset', 'write'); // Used by the include of actions_addupdatedelete.inc.php - -// Security check (enable the most restrictive one) -if ($user->socid > 0) { - accessforbidden(); -} -$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0); -restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft); -if (!isModEnabled('asset')) { - accessforbidden(); -} +$permissionnote = 1; +//$permissionnote=$user->rights->asset->creer; // Used by the include of actions_setnotes.inc.php @@ -72,8 +65 @@ -$parameters = array(); -$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) { - setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -} -if (empty($reshook)) { - include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once -} +include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once @@ -87,0 +74 @@ +//$help_url='EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes'; @@ -89 +76 @@ -llxHeader('', $langs->trans('Asset'), $help_url); +llxHeader('', $langs->trans('Assets'), $help_url); @@ -91 +78,2 @@ -if ($id > 0 || !empty($ref)) { +if ($id > 0 || !empty($ref)) +{ @@ -94 +82 @@ - $head = assetPrepareHead($object); + $head = asset_prepare_head($object); @@ -96 +84 @@ - print dol_get_fiche_head($head, 'note', $langs->trans("Asset"), -1, $object->picto); + dol_fiche_head($head, 'note', $langs->trans("Asset"), -1, 'generic'); @@ -100 +88 @@ - $linkback = '' . $langs->trans("BackToList") . ''; + $linkback = ''.$langs->trans("BackToList").''; @@ -102,0 +91,39 @@ + /* + // Ref customer + $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1); + $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1); + // Thirdparty + $morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1); + // Project + if (! empty($conf->projet->enabled)) + { + $langs->load("projects"); + $morehtmlref.='
'.$langs->trans('Project') . ' '; + if ($user->rights->asset->creer) + { + if ($action != 'classify') + //$morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; + $morehtmlref.=' : '; + if ($action == 'classify') { + //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); + $morehtmlref.=''; + $morehtmlref.=''; + $morehtmlref.=''; + $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); + $morehtmlref.=''; + $morehtmlref.=''; + } else { + $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); + } + } else { + if (! empty($object->fk_project)) { + $proj = new Project($db); + $proj->fetch($object->fk_project); + $morehtmlref.=''; + $morehtmlref.=$proj->ref; + $morehtmlref.=''; + } else { + $morehtmlref.=''; + } + } + }*/ @@ -114 +141 @@ - include DOL_DOCUMENT_ROOT . '/core/tpl/notes.tpl.php'; + include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php'; @@ -118 +145 @@ - print dol_get_fiche_end(); + dol_fiche_end(); --- /tmp/dsg/dolibarr/htdocs/asset/github_19.0.3_type.php +++ /tmp/dsg/dolibarr/htdocs/asset/client_type.php @@ -0,0 +1,629 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/asset/type.php + * \ingroup asset + * \brief Asset's type setup + */ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/asset.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/asset/class/asset.class.php'; +require_once DOL_DOCUMENT_ROOT.'/asset/class/asset_type.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; +if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; +if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php'; +if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php'; + +// Load translation files required by the page +$langs->load("assets"); + +$rowid = GETPOST('rowid', 'int'); +$action = GETPOST('action', 'alpha'); +$cancel = GETPOST('cancel', 'alpha'); +$backtopage = GETPOST('backtopage', 'alpha'); + +$type = GETPOST('type', 'alpha'); + +$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; +$sortfield = GETPOST("sortfield", 'alpha'); +$sortorder = GETPOST("sortorder", 'alpha'); +$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +$offset = $limit * $page; +$pageprev = $page - 1; +$pagenext = $page + 1; +if (!$sortorder) { $sortorder = "DESC"; } +if (!$sortfield) { $sortfield = "a.label"; } + +$label = GETPOST("label", "alpha"); +$accountancy_code_asset = GETPOST('accountancy_code_asset', 'string'); +$accountancy_code_depreciation_asset = GETPOST('accountancy_code_depreciation_asset', 'string'); +$accountancy_code_depreciation_expense = GETPOST('accountancy_code_depreciation_expense', 'string'); +$comment = GETPOST('comment', 'string'); + +// Security check +$result = restrictedArea($user, 'asset', $rowid, 'asset_type'); + +$object = new AssetType($db); + +$extrafields = new ExtraFields($db); + +// fetch optionals attributes and labels +$extrafields->fetch_name_optionals_label($object->table_element); + +if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers +{ + $type = ""; + $sall = ""; +} + + +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context +$hookmanager->initHooks(array('assettypecard', 'globalcard')); + + +/* + * Actions + */ + +if ($cancel) { + $action = ''; + + if (!empty($backtopage)) + { + header("Location: ".$backtopage); + exit; + } +} + +if ($action == 'add' && $user->rights->asset->write) +{ + $object->label = trim($label); + $object->accountancy_code_asset = trim($accountancy_code_asset); + $object->accountancy_code_depreciation_asset = trim($accountancy_code_depreciation_asset); + $object->accountancy_code_depreciation_expense = trim($accountancy_code_depreciation_expense); + $object->note = trim($comment); + + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost(null, $object); + if ($ret < 0) $error++; + + if (empty($object->label)) { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors'); + } + else { + $sql = "SELECT label FROM ".MAIN_DB_PREFIX."asset_type WHERE label='".$db->escape($object->label)."'"; + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows($result); + } + if ($num) { + $error++; + $langs->load("errors"); + setEventMessages($langs->trans("ErrorLabelAlreadyExists", $login), null, 'errors'); + } + } + + if (!$error) + { + $id = $object->create($user); + if ($id > 0) + { + header("Location: ".$_SERVER["PHP_SELF"]); + exit; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + $action = 'create'; + } + } + else + { + $action = 'create'; + } +} + +if ($action == 'update' && $user->rights->asset->write) +{ + $object->fetch($rowid); + + $object->oldcopy = clone $object; + + $object->label = trim($label); + $object->accountancy_code_asset = trim($accountancy_code_asset); + $object->accountancy_code_depreciation_asset = trim($accountancy_code_depreciation_asset); + $object->accountancy_code_depreciation_expense = trim($accountancy_code_depreciation_expense); + $object->note = trim($comment); + + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost(null, $object); + if ($ret < 0) $error++; + + $ret = $object->update($user); + + if ($ret >= 0 && !count($object->errors)) + { + setEventMessages($langs->trans("AssetsTypeModified"), null, 'mesgs'); + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } + + header("Location: ".$_SERVER["PHP_SELF"]."?rowid=".$object->id); + exit; +} + +if ($action == 'confirm_delete' && $user->rights->asset->write) +{ + $object->fetch($rowid); + $res = $object->delete(); + + if ($res > 0) + { + setEventMessages($langs->trans("AssetsTypeDeleted"), null, 'mesgs'); + header("Location: ".$_SERVER["PHP_SELF"]); + exit; + } + else + { + setEventMessages($langs->trans("AssetsTypeCanNotBeDeleted"), null, 'errors'); + $action = ''; + } +} + + +/* + * View + */ + +$form = new Form($db); + +$helpurl = ''; +llxHeader('', $langs->trans("AssetsTypeSetup"), $helpurl); + + +// List of asset type +if (!$rowid && $action != 'create' && $action != 'edit') +{ + //dol_fiche_head(''); + + $sql = "SELECT d.rowid, d.label as label, d.accountancy_code_asset, d.accountancy_code_depreciation_asset, d.accountancy_code_depreciation_expense, d.note"; + $sql .= " FROM ".MAIN_DB_PREFIX."asset_type as d"; + $sql .= " WHERE d.entity IN (".getEntity('asset_type').")"; + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + $nbtotalofrecords = $num; + + $i = 0; + + $param = ''; + + $newcardbutton = ''; + if ($user->rights->asset->configurer) + { + $newcardbutton = ''.$langs->trans('NewAssetType').''; + $newcardbutton .= ''; + $newcardbutton .= ''; + } + + print '
'; + if ($optioncss != '') print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print_barre_liste($langs->trans("AssetsTypes"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'accountancy', 0, $newcardbutton, '', $limit); + + $moreforfilter = ''; + + print '
'; + print '
'.$langs->trans("NoRecordFound").'
'.$langs->trans("NoRecordFound").'
'."\n"; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + $assettype = new AssetType($db); + + while ($i < $num) + { + $objp = $db->fetch_object($result); + + $assettype->id = $objp->rowid; + $assettype->ref = $objp->rowid; + $assettype->label = $objp->rowid; + + print ''; + print ''; + print ''; + + print ''; + + print ''; + + print ''; + + if ($user->rights->asset->write) + print ''; + else + print ''; + print ""; + $i++; + } + print "
'.$langs->trans("Ref").''.$langs->trans("Label").''.$langs->trans("AccountancyCodeAsset").''.$langs->trans("AccountancyCodeDepreciationAsset").''.$langs->trans("AccountancyCodeDepreciationExpense").' 
'; + print $assettype->getNomUrl(1); + //'.img_object($langs->trans("ShowType"),'group').' '.$objp->rowid.' + print ''.dol_escape_htmltag($objp->label).''; + if (!empty($conf->accounting->enabled)) + { + $accountingaccount = new AccountingAccount($db); + $accountingaccount->fetch('', $objp->accountancy_code_asset, 1); + + print $accountingaccount->getNomUrl(0, 0, 0, '', 0); + } else { + print $objp->accountancy_code_asset; + } + print ''; + if (!empty($conf->accounting->enabled)) + { + $accountingaccount2 = new AccountingAccount($db); + $accountingaccount2->fetch('', $objp->accountancy_code_depreciation_asset, 1); + + print $accountingaccount2->getNomUrl(0, 0, 0, '', 0); + } else { + print $objp->accountancy_code_depreciation_asset; + } + print ''; + if (!empty($conf->accounting->enabled)) + { + $accountingaccount3 = new AccountingAccount($db); + $accountingaccount3->fetch('', $objp->accountancy_code_depreciation_expense, 1); + + print $accountingaccount3->getNomUrl(0, 0, 0, '', 0); + } else { + print $objp->accountancy_code_depreciation_expense; + } + print 'rowid.'">'.img_edit().' 
"; + print ''; + + print ''; + } + else + { + dol_print_error($db); + } +} + + +/* ************************************************************************** */ +/* */ +/* Creation mode */ +/* */ +/* ************************************************************************** */ +if ($action == 'create') +{ + $object = new AssetType($db); + if (!empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db); + + print load_fiche_titre($langs->trans("NewAssetType")); + + print '
'; + print ''; + print ''; + + dol_fiche_head(''); + + print ''; + print ''; + + print ''; + + if (!empty($conf->accounting->enabled)) + { + // Accountancy_code_asset + print ''; + print ''; + + // Accountancy_code_depreciation_expense + print ''; + print ''; + + // Accountancy_code_depreciation_expense + print ''; + print ''; + } + else // For external software + { + // Accountancy_code_asset + print ''; + print ''; + + // Accountancy_code_depreciation_asset + print ''; + print ''; + + // Accountancy_code_depreciation_expense + print ''; + print ''; + } + + print ''; + + // Other attributes + $parameters = array(); + $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + if (empty($reshook)) + { + print $object->showOptionals($extrafields, 'edit', $parameters); + } + print ''; + print "
'.$langs->trans("Label").'
'.$langs->trans("AccountancyCodeAsset").''; + print $formaccounting->select_account($object->accountancy_code_asset, 'accountancy_code_asset', 1, '', 1, 1); + print '
'.$langs->trans("AccountancyCodeDepreciationAsset").''; + print $formaccounting->select_account($object->accountancy_code_depreciation_asset, 'accountancy_code_depreciation_asset', 1, '', 1, 1); + print '
'.$langs->trans("AccountancyCodeDepreciationExpense").''; + print $formaccounting->select_account($object->accountancy_code_depreciation_expense, 'accountancy_code_depreciation_expense', 1, '', 1, 1); + print '
'.$langs->trans("AccountancyCodeAsset").''; + print '
'.$langs->trans("AccountancyCodeDepreciationAsset").''; + print '
'.$langs->trans("AccountancyCodeDepreciationExpense").''; + print '
'.$langs->trans("Description").''; + print '
\n"; + + dol_fiche_end(); + + print '
'; + print ''; + print '     '; + print ''; + print '
'; + + print "
\n"; +} + +/* ************************************************************************** */ +/* */ +/* View mode */ +/* */ +/* ************************************************************************** */ +if ($rowid > 0) +{ + if ($action != 'edit') + { + $object = new AssetType($db); + $object->fetch($rowid); + $object->fetch_optionals(); + + /* + * Confirmation suppression + */ + if ($action == 'delete') + { + print $form->formconfirm($_SERVER['PHP_SELF']."?rowid=".$object->id, $langs->trans("DeleteAnAssetType"), $langs->trans("ConfirmDeleteAssetType", $object->label), "confirm_delete", '', 0, 1); + } + + $head = asset_type_prepare_head($object); + + dol_fiche_head($head, 'card', $langs->trans("AssetType"), -1, 'setup'); + + $linkback = ''.$langs->trans("BackToList").''; + + $morehtmlref = '
'; + // Ref asset type + $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, $user->rights->asset->write, 'string', '', 0, 1); + $morehtmlref .= $form->editfieldval("Label", 'label', $object->label, $object, $user->rights->asset->write, 'string', '', null, null, '', 1); + $morehtmlref .= '
'; + + dol_banner_tab($object, 'rowid', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright); + + print '
'; + print '
'; + + print ''; + + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + + print '"; + + // Other attributes + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; + + print '
'; + print $langs->trans("AccountancyCodeAsset"); + print ''; + if (!empty($conf->accounting->enabled)) + { + $accountingaccount = new AccountingAccount($db); + $accountingaccount->fetch('', $object->accountancy_code_asset, 1); + + print $accountingaccount->getNomUrl(0, 1, 1, '', 1); + } else { + print $object->accountancy_code_asset; + } + print '
'; + print $langs->trans("AccountancyCodeDepreciationAsset"); + print ''; + if (!empty($conf->accounting->enabled)) + { + $accountingaccount2 = new AccountingAccount($db); + $accountingaccount2->fetch('', $object->accountancy_code_depreciation_asset, 1); + + print $accountingaccount2->getNomUrl(0, 1, 1, '', 1); + } else { + print $object->accountancy_code_depreciation_asset; + } + print '
'; + print $langs->trans("AccountancyCodeDepreciationExpense"); + print ''; + if (!empty($conf->accounting->enabled)) + { + $accountingaccount3 = new AccountingAccount($db); + $accountingaccount3->fetch('', $object->accountancy_code_depreciation_expense, 1); + + print $accountingaccount3->getNomUrl(0, 1, 1, '', 1); + } else { + print $object->accountancy_code_depreciation_expense; + } + print '
'.$langs->trans("Description").''; + print nl2br($object->note)."
'; + print '
'; + + dol_fiche_end(); + + /* + * Buttons + */ + + print '
'; + + // Edit + if ($user->rights->asset->write) + { + print ''; + } + + // Delete + if ($user->rights->asset->write) + { + print ''; + } + + print "
"; + } + + /* ************************************************************************** */ + /* */ + /* Edition mode */ + /* */ + /* ************************************************************************** */ + + if ($action == 'edit') + { + $object = new AssetType($db); + $object->fetch($rowid); + $object->fetch_optionals(); + if (!empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db); + + $head = asset_type_prepare_head($object); + + print '
'; + print ''; + print ''; + print ''; + + dol_fiche_head($head, 'card', $langs->trans("AssetsType"), -1, 'setup'); + + print ''; + + print ''; + + print ''; + + if (!empty($conf->accounting->enabled)) + { + // Accountancy_code_asset + print ''; + print ''; + + // Accountancy_code_depreciation_expense + print ''; + print ''; + + // Accountancy_code_depreciation_expense + print ''; + print ''; + } + else // For external software + { + // Accountancy_code_asset + print ''; + print ''; + + // Accountancy_code_depreciation_asset + print ''; + print ''; + + // Accountancy_code_depreciation_expense + print ''; + print ''; + } + + print ''; + + // Other attributes + $parameters = array(); + $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $act, $action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + if (empty($reshook)) + { + print $object->showOptionals($extrafields, 'edit', $parameters); + } + + // Other attributes + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php'; + + print '
'.$langs->trans("Ref").''.$object->id.'
'.$langs->trans("Label").'
'.$langs->trans("AccountancyCodeAsset").''; + print $formaccounting->select_account($object->accountancy_code_asset, 'accountancy_code_asset', 1, '', 1, 1); + print '
'.$langs->trans("AccountancyCodeDepreciationAsset").''; + print $formaccounting->select_account($object->accountancy_code_depreciation_asset, 'accountancy_code_depreciation_asset', 1, '', 1, 1); + print '
'.$langs->trans("AccountancyCodeDepreciationExpense").''; + print $formaccounting->select_account($object->accountancy_code_depreciation_expense, 'accountancy_code_depreciation_expense', 1, '', 1, 1); + print '
'.$langs->trans("AccountancyCodeAsset").''; + print '
'.$langs->trans("AccountancyCodeDepreciationAsset").''; + print '
'.$langs->trans("AccountancyCodeDepreciationExpense").''; + print '
'.$langs->trans("Description").''; + print '
'; + + dol_fiche_end(); + + print '
'; + print '   '; + print '
'; + + print "
"; + } +} + +// End of page +llxFooter(); +$db->close();