';
foreach ($object->fields as $key => $val) {
- $cssforfield = (empty($val['css']) ? '' : $val['css']);
+ $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') {
@@ -508,14 +571,17 @@ while ($i < ($limit ? min($num, $limit) : $num)) {
$cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
}
- if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'status') {
+ 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'])) {
print '';
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, '');
}
@@ -545,7 +611,7 @@ while ($i < ($limit ? min($num, $limit) : $num)) {
print $hookmanager->resPrint;
// Action column
print ' ';
- 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
$selected = 0;
if (in_array($object->id, $arrayofselected)) {
$selected = 1;
@@ -605,7 +671,7 @@ if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $n
$genallowed = $permissiontoread;
$delallowed = $permissiontoadd;
- print $formfile->showdocuments('massfilesarea_asset', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '');
+ print $formfile->showdocuments('massfilesarea_asset', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
}
// End of page
diff --git a/htdocs/asset/model/accountancy_codes.php b/htdocs/asset/model/accountancy_codes.php
new file mode 100644
index 00000000000..fd5999b20b0
--- /dev/null
+++ b/htdocs/asset/model/accountancy_codes.php
@@ -0,0 +1,191 @@
+
+ * Copyright (C) 2018 Alexandre Spangaro
+ *
+ * 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/model/accountancy_code.php
+ * \ingroup asset
+ * \brief Card with accountancy code on Asset Model
+ */
+
+require '../../main.inc.php';
+require_once DOL_DOCUMENT_ROOT . '/core/lib/asset.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/asset/class/assetmodel.class.php';
+require_once DOL_DOCUMENT_ROOT . '/asset/class/assetaccountancycodes.class.php';
+
+// Load translation files required by the page
+$langs->loadLangs(array("assets", "companies"));
+
+// Get parameters
+$id = GETPOST('id', 'int');
+$ref = GETPOST('ref', 'alpha');
+$action = GETPOST('action', 'aZ09');
+$cancel = GETPOST('cancel', 'aZ09');
+$backtopage = GETPOST('backtopage', 'alpha');
+
+// Initialize technical objects
+$object = new AssetModel($db);
+$assetaccountancycodes = new AssetAccountancyCodes($db);
+$extrafields = new ExtraFields($db);
+$diroutputmassaction = $conf->asset->dir_output . '/temp/massgeneration/' . $user->id;
+$hookmanager->initHooks(array('assetmodelaccountancycodes', 'globalcard')); // Note that conf->hooks_modules contains array
+// Fetch optionals attributes and labels
+$extrafields->fetch_name_optionals_label($object->table_element);
+
+// Load object
+include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
+if ($id > 0 || !empty($ref)) {
+ $upload_dir = $conf->asset->multidir_output[$object->entity] . "/" . $object->id;
+}
+
+$permissiontoread = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->asset->read) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->asset->setup_advance->read)));
+$permissiontoadd = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->asset->write) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->asset->setup_advance->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, 'asset', $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
+if (empty($conf->asset->enabled)) accessforbidden();
+if (!$permissiontoread) accessforbidden();
+
+$result = $assetaccountancycodes->fetchAccountancyCodes(0, $object->id);
+if ($result < 0) {
+ setEventMessages($assetaccountancycodes->error, $assetaccountancycodes->errors, 'errors');
+}
+
+
+/*
+ * Actions
+ */
+
+$reshook = $hookmanager->executeHooks('doActions', array(), $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)) {
+ $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/model/accountancy_codes.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
+ }
+ }
+ }
+
+ if ($cancel) {
+ /*var_dump($cancel);var_dump($backtopage);var_dump($backtopageforcancel);exit;*/
+ if (!empty($backtopageforcancel)) {
+ header("Location: ".$backtopageforcancel);
+ exit;
+ } elseif (!empty($backtopage)) {
+ header("Location: ".$backtopage);
+ exit;
+ }
+ $action = '';
+ }
+
+ if ($action == "update") {
+ $assetaccountancycodes->setAccountancyCodesFromPost();
+
+ $result = $assetaccountancycodes->updateAccountancyCodes($user, 0, $object->id);
+ if ($result < 0) {
+ setEventMessages($assetaccountancycodes->error, $assetaccountancycodes->errors, 'errors');
+ $action = 'edit';
+ } else {
+ setEventMessage($langs->trans('RecordSaved'));
+ header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
+ exit;
+ }
+ }
+}
+
+
+/*
+ * View
+ */
+
+$form = new Form($db);
+
+$help_url = '';
+llxHeader('', $langs->trans('AssetModel'), $help_url);
+
+if ($id > 0 || !empty($ref)) {
+ $head = assetModelPrepareHead($object);
+ print dol_get_fiche_head($head, 'accountancy_codes', $langs->trans("AssetModel"), -1, $object->picto);
+
+ // Object card
+ // ------------------------------------------------------------
+ $linkback = '' . $langs->trans("BackToList") . ' ';
+
+ $morehtmlref = '';
+ $morehtmlref .= '
';
+
+ dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
+
+ print '';
+
+ if ($action == 'edit') {
+ print '';
+ } else {
+ include DOL_DOCUMENT_ROOT . '/asset/tpl/accountancy_codes_view.tpl.php';
+ }
+
+ print dol_get_fiche_end();
+
+ if ($action != 'edit') {
+ print '' . "\n";
+ $parameters = array();
+ $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
+ if ($reshook < 0) {
+ setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+ }
+
+ if (empty($reshook)) {
+ if ($object->status == $object::STATUS_DRAFT/* && !empty($object->enabled_modes)*/) {
+ print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=edit&token=' . newToken(), '', $permissiontoadd);
+ }
+ }
+ print '
' . "\n";
+ }
+}
+
+// End of page
+llxFooter();
+$db->close();
diff --git a/htdocs/asset/model/agenda.php b/htdocs/asset/model/agenda.php
new file mode 100644
index 00000000000..cd0365a1418
--- /dev/null
+++ b/htdocs/asset/model/agenda.php
@@ -0,0 +1,217 @@
+
+ * Copyright (C) ---Put here your own copyright and developer email---
+ *
+ * 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/model/agenda.php
+ * \ingroup asset
+ * \brief Tab of events on Asset Model
+ */
+
+require '../../main.inc.php';
+require_once DOL_DOCUMENT_ROOT . '/core/lib/asset.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/asset/class/assetmodel.class.php';
+require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
+
+// Load translation files required by the page
+$langs->loadLangs(array("assets", "other"));
+
+// Get parameters
+$id = GETPOST('id', 'int');
+$ref = GETPOST('ref', 'alpha');
+$action = GETPOST('action', 'aZ09');
+$cancel = GETPOST('cancel', 'aZ09');
+$backtopage = GETPOST('backtopage', 'alpha');
+
+if (GETPOST('actioncode', 'array')) {
+ $actioncode = GETPOST('actioncode', 'array', 3);
+ if (!count($actioncode)) {
+ $actioncode = '0';
+ }
+} else {
+ $actioncode = GETPOST("actioncode", "alpha", 3) ? GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT));
+}
+$search_agenda_label = GETPOST('search_agenda_label');
+
+$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 (!$sortfield) {
+ $sortfield = 'a.datep,a.id';
+}
+if (!$sortorder) {
+ $sortorder = 'DESC,DESC';
+}
+
+// Initialize technical objects
+$object = new AssetModel($db);
+$extrafields = new ExtraFields($db);
+$diroutputmassaction = $conf->asset->dir_output . '/temp/massgeneration/' . $user->id;
+$hookmanager->initHooks(array('assetmodelagenda', 'globalcard')); // Note that conf->hooks_modules contains array
+// Fetch optionals attributes and labels
+$extrafields->fetch_name_optionals_label($object->table_element);
+
+// Load object
+include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
+if ($id > 0 || !empty($ref)) {
+ $upload_dir = $conf->asset->multidir_output[$object->entity] . "/model/" . $object->id;
+}
+
+$permissiontoread = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->asset->read) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->asset->setup_advance->read)));
+$permissiontoadd = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->asset->write) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->asset->setup_advance->write))); // Used by the include of actions_addupdatedelete.inc.php
+
+// 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, 'asset', $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
+if (empty($conf->asset->enabled)) accessforbidden();
+if (!$permissiontoread) accessforbidden();
+
+
+/*
+ * Actions
+ */
+
+$parameters = array('id' => $id);
+$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)) {
+ // Cancel
+ if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
+ header("Location: " . $backtopage);
+ exit;
+ }
+
+ // Purge search criteria
+ 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
+ $actioncode = '';
+ $search_agenda_label = '';
+ }
+}
+
+
+/*
+ * View
+ */
+
+$form = new Form($db);
+
+if ($object->id > 0) {
+ $title = $langs->trans("Agenda");
+ //if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title;
+ $help_url = 'EN:Module_Agenda_En';
+ llxHeader('', $title, $help_url);
+
+ if (!empty($conf->notification->enabled)) {
+ $langs->load("mails");
+ }
+ $head = assetModelPrepareHead($object);
+
+
+ print dol_get_fiche_head($head, 'agenda', $langs->trans("AssetModel"), -1, $object->picto);
+
+ // Object card
+ // ------------------------------------------------------------
+ $linkback = '' . $langs->trans("BackToList") . ' ';
+
+ $morehtmlref = '';
+ $morehtmlref .= '
';
+
+
+ dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
+
+ print '';
+ print '
';
+
+ $object->info($object->id);
+ dol_print_object_info($object, 1);
+
+ print '
';
+
+ print dol_get_fiche_end();
+
+
+ // Actions buttons
+
+ $objthirdparty = $object;
+ $objcon = new stdClass();
+
+ $out = '&origin=' . urlencode($object->element . '@' . $object->module) . '&originid=' . urlencode($object->id);
+ $urlbacktopage = $_SERVER['PHP_SELF'] . '?id=' . $object->id;
+ $out .= '&backtopage=' . urlencode($urlbacktopage);
+ $permok = $user->rights->agenda->myactions->create;
+ if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
+ //$out.='trans("AddAnAction"),'filenew');
+ //$out.=" ";
+ }
+
+
+ print '';
+
+ // if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
+ // $param = '&id=' . $object->id . '&socid=' . $socid;
+ // if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
+ // $param .= '&contextpage=' . urlencode($contextpage);
+ // }
+ // if ($limit > 0 && $limit != $conf->liste_limit) {
+ // $param .= '&limit=' . urlencode($limit);
+ // }
+ //
+ //
+ // print load_fiche_titre($langs->trans("ActionsOnAssetModel"), '', '');
+ //
+ // // List of all actions
+ // $filters = array();
+ // $filters['search_agenda_label'] = $search_agenda_label;
+ //
+ // // TODO Replace this with same code than into list.php
+ // show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder, $object->module);
+ // }
+}
+
+// End of page
+llxFooter();
+$db->close();
diff --git a/htdocs/asset/model/card.php b/htdocs/asset/model/card.php
new file mode 100644
index 00000000000..3e0858da55e
--- /dev/null
+++ b/htdocs/asset/model/card.php
@@ -0,0 +1,330 @@
+
+ * Copyright (C) 2018 Alexandre Spangaro
+ *
+ * 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/model/card.php
+ * \ingroup asset
+ * \brief Page to create/edit/view asset Model
+ */
+
+require '../../main.inc.php';
+require_once DOL_DOCUMENT_ROOT . '/core/lib/asset.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/asset/class/assetmodel.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
+
+// Load translation files required by the page
+$langs->loadLangs(array("assets", "other"));
+
+// Get parameters
+$id = GETPOST('id', 'int');
+$ref = GETPOST('ref', 'alpha');
+$action = GETPOST('action', 'aZ09');
+$confirm = GETPOST('confirm', 'alpha');
+$cancel = GETPOST('cancel', 'aZ09');
+$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'assetmodelcard'; // To manage different context of search
+$backtopage = GETPOST('backtopage', 'alpha');
+$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
+
+// Initialize technical objects
+$object = new AssetModel($db);
+$extrafields = new ExtraFields($db);
+$diroutputmassaction = $conf->asset->dir_output . '/temp/massgeneration/' . $user->id;
+$hookmanager->initHooks(array('assetmodelcard', 'globalcard')); // Note that conf->hooks_modules contains array
+
+// Fetch optionals attributes and labels
+$extrafields->fetch_name_optionals_label($object->table_element);
+
+$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
+
+// Initialize array of search criterias
+$search_all = GETPOST("search_all", 'alpha');
+$search = array();
+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';
+}
+
+// Load object
+include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
+
+$permissiontoread = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->asset->read) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->asset->setup_advance->read)));
+$permissiontoadd = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->asset->write) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->asset->setup_advance->write))); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
+$permissiontodelete = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->asset->delete) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->asset->setup_advance->delete))) || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
+$permissionnote = $permissiontoadd; // Used by the include of actions_setnotes.inc.php
+$permissiondellink = $permissiontoadd; // 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, 'asset', $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
+if (empty($conf->asset->enabled)) accessforbidden();
+if (!$permissiontoread) accessforbidden();
+
+
+/*
+ * Actions
+ */
+
+$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)) {
+ $error = 0;
+
+ $backurlforlist = DOL_URL_ROOT . '/asset/model/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/model/card.php?id=' . ((!empty($id) && $id > 0) ? $id : '__ID__');
+ }
+ }
+ }
+
+ $triggermodname = 'ASSETMODEL_MODIFY'; // Name of trigger action code to execute when we modify record
+
+ if (($action == 'edit' && !($permissiontoadd && $object->status == $object::STATUS_DRAFT)) ||
+ ($action == 'confirm_setdraft' && !($permissiontoadd && $object->status != $object::STATUS_DRAFT)) ||
+ ($action == 'confirm_validate' && !($permissiontoadd && $object->status != $object::STATUS_VALIDATED)) ||
+ ($action == 'confirm_close' && !($permissiontoadd && $object->status != $object::STATUS_CANCELED))
+ ) {
+ $action = "";
+ }
+
+ // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
+ include DOL_DOCUMENT_ROOT . '/core/actions_addupdatedelete.inc.php';
+}
+
+
+/*
+ * View
+ *
+ * Put here all code to build page
+ */
+
+$form = new Form($db);
+$formfile = new FormFile($db);
+
+$title = $langs->trans("AssetModel") . ' - ' . $langs->trans("Card");
+$help_url = '';
+llxHeader('', $title, $help_url);
+
+// Part to create
+if ($action == 'create') {
+ print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("AssetModel")), '', 'object_' . $object->picto);
+
+ print '';
+
+ //dol_set_focus('input[name="ref"]');
+}
+
+// Part to edit record
+if (($id || $ref) && $action == 'edit') {
+ print load_fiche_titre($langs->trans("AssetModel"), '', 'object_' . $object->picto);
+
+ print '';
+}
+
+// Part to show record
+if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
+ $res = $object->fetch_optionals();
+
+ $head = assetModelPrepareHead($object);
+ print dol_get_fiche_head($head, 'card', $langs->trans("AssetModel"), -1, $object->picto);
+
+ $formconfirm = '';
+
+ // Confirmation to delete
+ if ($action == 'delete') {
+ $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteAssetModel'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
+ } elseif ($action == 'clone') {
+ // Clone confirmation
+ // 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);
+ }
+
+ // Call Hook formConfirm
+ $parameters = array('formConfirm' => $formconfirm);
+ $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
+ if (empty($reshook)) {
+ $formconfirm .= $hookmanager->resPrint;
+ } elseif ($reshook > 0) {
+ $formconfirm = $hookmanager->resPrint;
+ }
+
+ // Print form confirm
+ print $formconfirm;
+
+
+ // Object card
+ // ------------------------------------------------------------
+ $linkback = '' . $langs->trans("BackToList") . ' ';
+
+ $morehtmlref = '';
+ $morehtmlref .= '
';
+
+
+ dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
+
+
+ print '';
+ print '
';
+ print '
';
+ print '
' . "\n";
+
+ // Common attributes
+ include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php';
+
+ // Other attributes. Fields from hook formObjectOptions and Extrafields.
+ include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
+
+ print '
';
+ print '
';
+ print '
';
+
+ print '
';
+
+ print dol_get_fiche_end();
+
+
+ // Buttons for actions
+ if ($action != 'editline') {
+ print '' . "\n";
+ $parameters = array();
+ $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
+ if ($reshook < 0) {
+ setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+ }
+
+ if (empty($reshook)) {
+ if ($object->status == $object::STATUS_DRAFT) {
+ print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=edit&token=' . newToken(), '', $permissiontoadd);
+ }
+
+ // Back to draft
+ if ($object->status != $object::STATUS_DRAFT) {
+ print dolGetButtonAction($langs->trans('SetToDraft'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=confirm_setdraft&confirm=yes&token=' . newToken(), '', $permissiontoadd);
+ }
+
+ if ($object->status != $object::STATUS_VALIDATED) {
+ print dolGetButtonAction($langs->trans('Enable'), '', 'default', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=confirm_validate&confirm=yes&token=' . newToken(), '', $permissiontoadd);
+ }
+
+ if ($object->status != $object::STATUS_CANCELED) {
+ print dolGetButtonAction($langs->trans('Disable'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_close&confirm=yes&token='.newToken(), '', $permissiontoadd);
+ }
+
+ // Clone
+ print dolGetButtonAction($langs->trans('ToClone'), '', 'default', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&socid=' . $object->socid . '&action=clone&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 '
' . "\n";
+ }
+
+ print '';
+ print '
'; // ancre
+
+ print '
';
+
+ // $MAXEVENT = 10;
+ //
+ // $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-list-alt imgforviewmode', DOL_URL_ROOT . '/asset/model/agenda.php?id=' . $object->id);
+ //
+ // // List of actions on element
+ // include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
+ // $formactions = new FormActions($db);
+ // $somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, 0, 1, '', $MAXEVENT, '', $morehtmlright);
+
+ print '
';
+}
+
+// End of page
+llxFooter();
+$db->close();
diff --git a/htdocs/asset/model/depreciation_options.php b/htdocs/asset/model/depreciation_options.php
new file mode 100644
index 00000000000..f5bc751663b
--- /dev/null
+++ b/htdocs/asset/model/depreciation_options.php
@@ -0,0 +1,191 @@
+
+ * Copyright (C) 2018 Alexandre Spangaro
+ *
+ * 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/model/depreciation_options.php
+ * \ingroup asset
+ * \brief Card with depreciation options on Asset Model
+ */
+
+require '../../main.inc.php';
+require_once DOL_DOCUMENT_ROOT . '/core/lib/asset.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/asset/class/assetmodel.class.php';
+require_once DOL_DOCUMENT_ROOT . '/asset/class/assetdepreciationoptions.class.php';
+
+// Load translation files required by the page
+$langs->loadLangs(array("assets", "companies"));
+
+// Get parameters
+$id = GETPOST('id', 'int');
+$ref = GETPOST('ref', 'alpha');
+$action = GETPOST('action', 'aZ09');
+$cancel = GETPOST('cancel', 'aZ09');
+$backtopage = GETPOST('backtopage', 'alpha');
+
+// Initialize technical objects
+$object = new AssetModel($db);
+$assetdepreciationoptions = new AssetDepreciationOptions($db);
+$extrafields = new ExtraFields($db);
+$diroutputmassaction = $conf->asset->dir_output . '/temp/massgeneration/' . $user->id;
+$hookmanager->initHooks(array('assetmodeldeprectationoptions', 'globalcard')); // Note that conf->hooks_modules contains array
+// Fetch optionals attributes and labels
+$extrafields->fetch_name_optionals_label($object->table_element);
+
+// Load object
+include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
+if ($id > 0 || !empty($ref)) {
+ $upload_dir = $conf->asset->multidir_output[$object->entity] . "/" . $object->id;
+}
+
+$permissiontoread = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->asset->read) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->asset->setup_advance->read)));
+$permissiontoadd = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->asset->write) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->asset->setup_advance->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, 'asset', $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
+if (empty($conf->asset->enabled)) accessforbidden();
+if (!$permissiontoread) accessforbidden();
+
+$object->asset_depreciation_options = &$assetdepreciationoptions;
+$result = $assetdepreciationoptions->fetchDeprecationOptions(0, $object->id);
+if ($result < 0) {
+ setEventMessages($assetdepreciationoptions->error, $assetdepreciationoptions->errors, 'errors');
+}
+
+
+/*
+ * Actions
+ */
+
+$reshook = $hookmanager->executeHooks('doActions', array(), $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)) {
+ $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/model/depreciation_options.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
+ }
+ }
+ }
+
+ if ($cancel) {
+ /*var_dump($cancel);var_dump($backtopage);var_dump($backtopageforcancel);exit;*/
+ if (!empty($backtopageforcancel)) {
+ header("Location: ".$backtopageforcancel);
+ exit;
+ } elseif (!empty($backtopage)) {
+ header("Location: ".$backtopage);
+ exit;
+ }
+ $action = '';
+ }
+
+ if ($action == "update") {
+ $result = $assetdepreciationoptions->setDeprecationOptionsFromPost(1);
+ if ($result > 0) $result = $assetdepreciationoptions->updateDeprecationOptions($user, 0, $object->id);
+ if ($result < 0) {
+ setEventMessages($assetdepreciationoptions->error, $assetdepreciationoptions->errors, 'errors');
+ $action = 'edit';
+ } else {
+ setEventMessage($langs->trans('RecordSaved'));
+ header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
+ exit;
+ }
+ }
+}
+
+
+/*
+ * View
+ */
+
+$form = new Form($db);
+
+$help_url = '';
+llxHeader('', $langs->trans('AssetModel'), $help_url);
+
+if ($id > 0 || !empty($ref)) {
+ $head = assetModelPrepareHead($object);
+ print dol_get_fiche_head($head, 'depreciation_options', $langs->trans("AssetModel"), -1, $object->picto);
+
+ // Object card
+ // ------------------------------------------------------------
+ $linkback = '' . $langs->trans("BackToList") . ' ';
+
+ $morehtmlref = '';
+ $morehtmlref .= '
';
+
+ dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
+
+ print '';
+
+ if ($action == 'edit') {
+ print '';
+ } else {
+ include DOL_DOCUMENT_ROOT . '/asset/tpl/depreciation_options_view.tpl.php';
+ }
+
+ print dol_get_fiche_end();
+
+ if ($action != 'edit') {
+ print '' . "\n";
+ $parameters = array();
+ $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
+ if ($reshook < 0) {
+ setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+ }
+
+ if (empty($reshook)) {
+ if ($object->status == $object::STATUS_DRAFT/* && !empty($object->enabled_modes)*/) {
+ print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=edit&token=' . newToken(), '', $permissiontoadd);
+ }
+ }
+ print '
' . "\n";
+ }
+}
+
+// End of page
+llxFooter();
+$db->close();
diff --git a/htdocs/asset/model/list.php b/htdocs/asset/model/list.php
new file mode 100644
index 00000000000..a6423bb3a73
--- /dev/null
+++ b/htdocs/asset/model/list.php
@@ -0,0 +1,681 @@
+
+ * Copyright (C) 2018 Alexandre Spangaro
+ *
+ * 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/model/list.php
+ * \ingroup asset
+ * \brief List page for asset model
+ */
+
+// Load Dolibarr environment
+require '../../main.inc.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/asset/class/assetmodel.class.php';
+
+// Load translation files required by the page
+$langs->loadLangs(array("assets", "other"));
+
+$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') : 'assetmodellist'; // 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');
+
+// Load variable for pagination
+$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
+$sortfield = GETPOST('sortfield', 'aZ09comma');
+$sortorder = GETPOST('sortorder', 'aZ09comma');
+$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
+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
+$offset = $limit * $page;
+$pageprev = $page - 1;
+$pagenext = $page + 1;
+
+// Initialize technical objects
+$object = new AssetModel($db);
+$extrafields = new ExtraFields($db);
+$diroutputmassaction = $conf->asset->dir_output.'/temp/massgeneration/'.$user->id;
+$hookmanager->initHooks(array('assetmodellist')); // Note that conf->hooks_modules contains array
+
+// Fetch optionals attributes and labels
+$extrafields->fetch_name_optionals_label($object->table_element);
+//$extrafields->fetch_name_optionals_label($object->table_element_line);
+
+$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
+
+// Default sort order (if not yet defined by previous GETPOST)
+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";
+}
+
+// Initialize array of search criterias
+$search_all = GETPOST('search_all', 'alphanohtml');
+$search = array();
+foreach ($object->fields as $key => $val) {
+ if ($key == 'fk_pays' && !GETPOSTISSET('search_'.$key)) {
+ $search[$key] = $mysoc->country_id;
+ } elseif (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'));
+ }
+}
+
+// List of fields to search into when doing a "search in all"
+$fieldstosearchall = array();
+foreach ($object->fields as $key => $val) {
+ if (!empty($val['searchall'])) {
+ $fieldstosearchall['t.'.$key] = $val['label'];
+ }
+}
+
+// Definition of array of fields for columns
+$arrayfields = array();
+foreach ($object->fields as $key => $val) {
+ // If $val['visible']==0, then we never show the field
+ 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'] : ''
+ );
+ }
+}
+// Extra fields
+include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
+
+$object->fields = dol_sort_array($object->fields, 'position');
+$arrayfields = dol_sort_array($arrayfields, 'position');
+
+$permissiontoread = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->asset->read) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->asset->setup_advance->read)));
+$permissiontoadd = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->asset->write) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->asset->setup_advance->write)));
+$permissiontodelete = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->asset->delete) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->asset->setup_advance->delete)));
+
+// Security check
+if (empty($conf->asset->enabled)) {
+ 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, 'asset', $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
+if (empty($conf->asset->enabled)) accessforbidden();
+if (!$permissiontoread) accessforbidden();
+
+
+
+/*
+ * Actions
+ */
+
+if (GETPOST('cancel', 'alpha')) {
+ $action = 'list';
+ $massaction = '';
+}
+if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
+ $massaction = '';
+}
+
+$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)) {
+ // Selection of new fields
+ include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
+
+ // Purge search criteria
+ 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) {
+ $search[$key] = '';
+ if ($key == 'fk_pays') $search[$key] = $mysoc->country_id;
+ if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
+ $search[$key.'_dtstart'] = '';
+ $search[$key.'_dtend'] = '';
+ }
+ }
+ $toselect = array();
+ $search_array_options = array();
+ }
+ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
+ || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
+ $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
+ }
+
+ // Mass actions
+ $objectclass = 'AssetModel';
+ $objectlabel = 'AssetModel';
+ $uploaddir = $conf->asset->dir_output;
+ include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
+}
+
+
+
+/*
+ * View
+ */
+
+$form = new Form($db);
+
+$now = dol_now();
+
+$help_url = '';
+$title = $langs->trans('ListOf', $langs->transnoentitiesnoconv("AssetModels"));
+$morejs = array();
+$morecss = array();
+
+
+// Build and execute select
+// --------------------------------------------------------------------
+$sql = 'SELECT ';
+$sql .= $object->getFieldList('t');
+// Add fields from extrafields
+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." as options_".$key : '');
+ }
+}
+// Add fields from hooks
+$parameters = array();
+$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
+$sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
+$sql = preg_replace('/,\s*$/', '', $sql);
+$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
+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);
+}
+//$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
+// Add where from extra fields
+include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
+// Add where from hooks
+$parameters = array();
+$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
+$sql .= $hookmanager->resPrint;
+
+/* If a group by is required
+$sql .= " GROUP BY ";
+foreach($object->fields as $key => $val) {
+ $sql .= "t.".$key.", ";
+}
+// Add fields from extrafields
+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.', ' : '');
+ }
+}
+// Add where from hooks
+$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);
+*/
+
+// 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) : "";
+*/
+
+// Count total nb of records
+$nbtotalofrecords = '';
+if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
+ /* This old and fast method to get and count full list returns all record so use a high amount of memory.
+ $resql = $db->query($sql);
+ $nbtotalofrecords = $db->num_rows($resql);
+ */
+ /* The slow method does not consume memory on mysql (not tested on pgsql) */
+ /*$resql = $db->query($sql, 0, 'auto', 1);
+ while ($db->fetch_object($resql)) {
+ $nbtotalofrecords++;
+ }*/
+ /* The fast and low memory method to get and count full list converts the sql into a sql count */
+ $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),]+FROM/i', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
+ $resql = $db->query($sqlforcount);
+ $objforcount = $db->fetch_object($resql);
+ $nbtotalofrecords = $objforcount->nbtotalofrecords;
+ if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
+ $page = 0;
+ $offset = 0;
+ }
+ $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);
+
+
+// Direct jump if only one record found
+if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
+ $obj = $db->fetch_object($resql);
+ $id = $obj->rowid;
+ header("Location: ".DOL_URL_ROOT.'/asset/model/card.php?id='.$id);
+ exit;
+}
+
+
+// Output page
+// --------------------------------------------------------------------
+
+llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
+
+$arrayofselected = is_array($toselect) ? $toselect : array();
+
+$param = '';
+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) {
+ if ($skey != '') {
+ $param .= '&search_'.$key.'[]='.urlencode($skey);
+ }
+ }
+ } elseif ($search[$key] != '') {
+ $param .= '&search_'.$key.'='.urlencode($search[$key]);
+ }
+}
+if ($optioncss != '') {
+ $param .= '&optioncss='.urlencode($optioncss);
+}
+// Add $param from extra fields
+include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
+// Add $param from hooks
+$parameters = array();
+$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
+$param .= $hookmanager->resPrint;
+
+// List of mass actions available
+$arrayofmassactions = array(
+ //'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"),
+);
+if ($permissiontodelete) {
+ $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
+}
+if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
+ $arrayofmassactions = array();
+}
+$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
+
+print ''."\n";
+
+if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
+ $hidegeneratedfilelistifempty = 1;
+ if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
+ $hidegeneratedfilelistifempty = 0;
+ }
+
+ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
+ $formfile = new FormFile($db);
+
+ // Show list of available documents
+ $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
+ $urlsource .= str_replace('&', '&', $param);
+
+ $filedir = $diroutputmassaction;
+ $genallowed = $permissiontoread;
+ $delallowed = $permissiontoadd;
+
+ print $formfile->showdocuments('massfilesarea_asset', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
+}
+
+// End of page
+llxFooter();
+$db->close();
diff --git a/htdocs/asset/model/note.php b/htdocs/asset/model/note.php
new file mode 100644
index 00000000000..4af8407976f
--- /dev/null
+++ b/htdocs/asset/model/note.php
@@ -0,0 +1,120 @@
+
+ * Copyright (C) 2018 Alexandre Spangaro
+ *
+ * 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/model/note.php
+ * \ingroup asset
+ * \brief Card with notes on Asset Model
+ */
+
+require '../../main.inc.php';
+require_once DOL_DOCUMENT_ROOT . '/core/lib/asset.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/asset/class/assetmodel.class.php';
+
+// Load translation files required by the page
+$langs->loadLangs(array("assets", "companies"));
+
+// Get parameters
+$id = GETPOST('id', 'int');
+$ref = GETPOST('ref', 'alpha');
+$action = GETPOST('action', 'aZ09');
+$cancel = GETPOST('cancel', 'aZ09');
+$backtopage = GETPOST('backtopage', 'alpha');
+
+// Initialize technical objects
+$object = new AssetModel($db);
+$extrafields = new ExtraFields($db);
+$diroutputmassaction = $conf->asset->dir_output . '/temp/massgeneration/' . $user->id;
+$hookmanager->initHooks(array('assetmodelnote', 'globalcard')); // Note that conf->hooks_modules contains array
+// Fetch optionals attributes and labels
+$extrafields->fetch_name_optionals_label($object->table_element);
+
+// Load object
+include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
+if ($id > 0 || !empty($ref)) {
+ $upload_dir = $conf->asset->multidir_output[$object->entity] . "/" . $object->id;
+}
+
+$permissiontoread = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->asset->read) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->asset->setup_advance->read)));
+$permissiontoadd = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->asset->write) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->asset->setup_advance->write))); // Used by the include of actions_addupdatedelete.inc.php
+$permissionnote = $permissiontoadd; // Used by the include of actions_setnotes.inc.php
+
+// 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, 'asset', $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
+if (empty($conf->asset->enabled)) accessforbidden();
+if (!$permissiontoread) accessforbidden();
+
+
+/*
+ * Actions
+ */
+
+$reshook = $hookmanager->executeHooks('doActions', array(), $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
+}
+
+
+/*
+ * View
+ */
+
+$form = new Form($db);
+
+$help_url = '';
+llxHeader('', $langs->trans('AssetModel'), $help_url);
+
+if ($id > 0 || !empty($ref)) {
+ $object->fetch_thirdparty();
+
+ $head = assetModelPrepareHead($object);
+
+ print dol_get_fiche_head($head, 'note', $langs->trans("AssetModel"), -1, $object->picto);
+
+ // Object card
+ // ------------------------------------------------------------
+ $linkback = '' . $langs->trans("BackToList") . ' ';
+
+ $morehtmlref = '';
+ $morehtmlref .= '
';
+
+
+ dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
+
+
+ print '';
+ print '
';
+
+
+ $cssclass = "titlefield";
+ include DOL_DOCUMENT_ROOT . '/core/tpl/notes.tpl.php';
+
+ print '
';
+
+ print dol_get_fiche_end();
+}
+
+// End of page
+llxFooter();
+$db->close();
diff --git a/htdocs/asset/note.php b/htdocs/asset/note.php
index ebd340e393d..8de86d49bb7 100644
--- a/htdocs/asset/note.php
+++ b/htdocs/asset/note.php
@@ -27,7 +27,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/asset.lib.php';
require_once DOL_DOCUMENT_ROOT.'/asset/class/asset.class.php';
// Load translation files required by the page
-$langs->loadLangs(array("asset", "companies"));
+$langs->loadLangs(array("assets", "companies"));
// Get parameters
$id = GETPOST('id', 'int');
@@ -40,30 +40,24 @@ $backtopage = GETPOST('backtopage', 'alpha');
$object = new Asset($db);
$extrafields = new ExtraFields($db);
$diroutputmassaction = $conf->asset->dir_output.'/temp/massgeneration/'.$user->id;
-$hookmanager->initHooks(array('assetnote')); // Note that conf->hooks_modules contains array
-
+$hookmanager->initHooks(array('assetnote', 'globalcard')); // Note that conf->hooks_modules contains array
// Fetch optionals attributes and labels
$extrafields->fetch_name_optionals_label($object->table_element);
-// Security check - Protection if external user
-//if ($user->socid > 0) accessforbidden();
-//if ($user->socid > 0) $socid = $user->socid;
-//$result = restrictedArea($user, 'asset', $id);
-
// Load object
include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
if ($id > 0 || !empty($ref)) {
$upload_dir = $conf->asset->multidir_output[$object->entity]."/".$object->id;
}
-// Security check
-if (!empty($user->socid)) {
- $socid = $user->socid;
-}
-$result = restrictedArea($user, 'asset', $id);
+$permissionnote = $user->rights->asset->write; // Used by the include of actions_setnotes.inc.php
+$permissiontoadd = $user->rights->asset->write; // Used by the include of actions_addupdatedelete.inc.php
-$permissionnote = 1;
-//$permissionnote=$user->rights->asset->creer; // Used by the include of actions_setnotes.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 (empty($conf->asset->enabled)) accessforbidden();
/*
@@ -78,67 +72,28 @@ if (empty($reshook)) {
include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
}
+
/*
* View
*/
$form = new Form($db);
-//$help_url='EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes';
$help_url = '';
-llxHeader('', $langs->trans('Assets'), $help_url);
+llxHeader('', $langs->trans('Asset'), $help_url);
if ($id > 0 || !empty($ref)) {
$object->fetch_thirdparty();
- $head = asset_prepare_head($object);
+ $head = assetPrepareHead($object);
- print dol_get_fiche_head($head, 'note', $langs->trans("Asset"), -1, 'generic');
+ print dol_get_fiche_head($head, 'note', $langs->trans("Asset"), -1, $object->picto);
// Object card
// ------------------------------------------------------------
- $linkback = ''.$langs->trans("BackToList").' ';
+ $linkback = '' . $langs->trans("BackToList") . ' ';
$morehtmlref = '';
- /*
- // 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.='
';
- } 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.='';
- }
- }
- }*/
$morehtmlref .= '
';
@@ -150,7 +105,7 @@ if ($id > 0 || !empty($ref)) {
$cssclass = "titlefield";
- include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php';
+ include DOL_DOCUMENT_ROOT . '/core/tpl/notes.tpl.php';
print '';
diff --git a/htdocs/asset/tpl/accountancy_codes_edit.tpl.php b/htdocs/asset/tpl/accountancy_codes_edit.tpl.php
new file mode 100644
index 00000000000..bbd2b3d797c
--- /dev/null
+++ b/htdocs/asset/tpl/accountancy_codes_edit.tpl.php
@@ -0,0 +1,81 @@
+
+ *
+ * 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 .
+ *
+ * Show extrafields. It also show fields from hook formAssetAccountancyCode. Need to have following variables defined:
+ * $object (asset, assetmodel, ...)
+ * $assetaccountancycodes
+ * $action
+ * $conf
+ * $langs
+ *
+ * $parameters
+ */
+
+// Protection to avoid direct call of template
+if (empty($object) || !is_object($object)) {
+ print "Error, template page can't be called as URL";
+ exit;
+}
+
+if (!is_object($form)) {
+ $form = new Form($db);
+}
+
+if (!empty($conf->accounting->enabled) && !is_object($formaccounting)) {
+ require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
+ $formaccounting = new FormAccounting($db);
+}
+
+
+?>
+
+executeHooks('formAssetAccountancyCodes', $parameters, $object, $action);
+print $hookmanager->resPrint;
+if ($reshook < 0) {
+ setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+}
+
+if (empty($reshook)) {
+ foreach ($assetaccountancycodes->accountancy_codes_fields as $mode_key => $mode_info) {
+ //if (empty($object->enabled_modes[$mode_key])) continue;
+
+ print load_fiche_titre($langs->trans($mode_info['label']), '', '');
+ print '';
+ print '
';
+ print '
';
+ print '
';
+ }
+}
+?>
+
diff --git a/htdocs/asset/tpl/accountancy_codes_view.tpl.php b/htdocs/asset/tpl/accountancy_codes_view.tpl.php
new file mode 100644
index 00000000000..0d92ad8eb37
--- /dev/null
+++ b/htdocs/asset/tpl/accountancy_codes_view.tpl.php
@@ -0,0 +1,82 @@
+
+ *
+ * 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 .
+ *
+ * Show extrafields. It also show fields from hook formAssetAccountancyCode. Need to have following variables defined:
+ * $object (asset, assetmodel, ...)
+ * $assetaccountancycodes
+ * $action
+ * $conf
+ * $langs
+ *
+ * $parameters
+ */
+
+// Protection to avoid direct call of template
+if (empty($object) || !is_object($object)) {
+ print "Error, template page can't be called as URL";
+ exit;
+}
+
+if (!is_object($form)) {
+ $form = new Form($db);
+}
+
+
+?>
+
+executeHooks('formAssetAccountancyCodes', $parameters, $object, $action);
+print $hookmanager->resPrint;
+if ($reshook < 0) {
+ setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+}
+
+if (empty($reshook)) {
+ if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
+
+ foreach ($assetaccountancycodes->accountancy_codes_fields as $mode_key => $mode_info) {
+ //if (empty($object->enabled_modes[$mode_key])) continue;
+
+ print load_fiche_titre($langs->trans($mode_info['label']), '', '');
+ print '';
+ print '
';
+ print '
';
+ foreach ($mode_info['fields'] as $field_key => $field_info) {
+ print '' . $langs->trans($field_info['label']) . ' ';
+ if (!empty($assetaccountancycodes->accountancy_codes[$mode_key][$field_key])) {
+ $accountancy_code = $assetaccountancycodes->accountancy_codes[$mode_key][$field_key];
+ if (!empty($conf->accounting->enabled)) {
+ $accountingaccount = new AccountingAccount($db);
+ $accountingaccount->fetch('', $accountancy_code, 1);
+
+ print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
+ } else {
+ print $accountancy_code;
+ }
+ }
+ print ' ';
+ }
+ print '
';
+ print '
';
+ }
+}
+?>
+
diff --git a/htdocs/asset/tpl/depreciation_options_edit.tpl.php b/htdocs/asset/tpl/depreciation_options_edit.tpl.php
new file mode 100644
index 00000000000..cef22936260
--- /dev/null
+++ b/htdocs/asset/tpl/depreciation_options_edit.tpl.php
@@ -0,0 +1,228 @@
+
+ *
+ * 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 .
+ *
+ * Show extrafields. It also show fields from hook formAssetAccountancyCode. Need to have following variables defined:
+ * $object (asset, assetmodel, ...)
+ * $assetaccountancycodes
+ * $action
+ * $conf
+ * $langs
+ *
+ * $parameters
+ */
+
+// Protection to avoid direct call of template
+if (empty($object) || !is_object($object)) {
+ print "Error, template page can't be called as URL";
+ exit;
+}
+
+if (!is_object($form)) {
+ $form = new Form($db);
+}
+
+if (!is_object($formadmin)) {
+ require_once DOL_DOCUMENT_ROOT . '/core/class/html.formadmin.class.php';
+ $formadmin = new FormAdmin($db);
+}
+
+
+?>
+
+executeHooks('formAssetDeprecationOptions', $parameters, $object, $action);
+print $hookmanager->resPrint;
+if ($reshook < 0) {
+ setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+}
+
+if (empty($reshook)) {
+ $class_type = get_class($object) == 'Asset' ? 0 : 1;
+ foreach ($assetdepreciationoptions->deprecation_options_fields as $mode_key => $mode_info) {
+ if (!empty($mode_info['enabled_field'])) {
+ $info = explode(':', $mode_info['enabled_field']);
+ $enabled_field_info[] = array(
+ 'mode_key' => $info[0],
+ 'field_key' => $info[1],
+ 'value' => $info[2],
+ 'target' => 'block_' . $mode_key,
+ );
+ }
+
+ $assetdepreciationoptions->setInfosForMode($mode_key, $class_type, true);
+ $prefix_html_name = $mode_key . '_';
+
+ print '';
+ print load_fiche_titre($langs->trans($mode_info['label']), '', '');
+ print '
';
+ print '
';
+ print '
';
+ print '
' . "\n";
+ $mode_info['fields'] = dol_sort_array($mode_info['fields'], 'position');
+ foreach ($mode_info['fields'] as $field_key => $field_info) {
+ // Discard if extrafield is a hidden field on form
+ if (abs($field_info['visible']) != 1 && abs($field_info['visible']) != 3 && abs($field_info['visible']) != 4) {
+ continue;
+ }
+ if (array_key_exists('enabled', $field_info) && isset($field_info['enabled']) && !verifCond($field_info['enabled'])) {
+ continue; // We don't want this field
+ }
+ if (!empty($field_info['column_break'])) {
+ print '
';
+
+ // We close div and reopen for second column
+ print '
';
+ print '
';
+
+ print '
';
+ print '
';
+ }
+
+ $html_name = $prefix_html_name . $field_key;
+ if (!empty($field_info['enabled_field'])) {
+ $info = explode(':', $field_info['enabled_field']);
+ $enabled_field_info[] = array(
+ 'mode_key' => $info[0],
+ 'field_key' => $info[1],
+ 'value' => $info[2],
+ 'target' => 'field_' . $html_name,
+ );
+ }
+
+ $more_class = '';
+ if (!empty($field_info['required']) || (isset($field_info['notnull']) && $field_info['notnull'] > 0)) {
+ $more_class .= ' fieldrequired';
+ }
+ if (preg_match('/^(text|html)/', $val['type'])) {
+ $more_class .= ' tdtop';
+ }
+
+ print '';
+ if (!empty($field_info['help'])) {
+ print $form->textwithpicto($langs->trans($field_info['label']), $langs->trans($field_info['help']));
+ } else {
+ print $langs->trans($field_info['label']);
+ }
+ print ' ';
+ print '';
+ if (!empty($field_info['picto'])) {
+ print img_picto('', $field_info['picto'], '', false, 0, 0, '', 'pictofixedwidth');
+ }
+ if (in_array($field_info['type'], array('int', 'integer'))) {
+ $value = GETPOSTISSET($html_name) ?GETPOST($html_name, 'int') : $assetdepreciationoptions->$field_key;
+ } elseif ($field_info['type'] == 'double') {
+ $value = GETPOSTISSET($html_name) ? price2num(GETPOST($html_name, 'alphanohtml')) : $assetdepreciationoptions->$field_key;
+ } elseif (preg_match('/^(text|html)/', $field_info['type'])) {
+ $tmparray = explode(':', $field_info['type']);
+ if (!empty($tmparray[1])) {
+ $check = $tmparray[1];
+ } else {
+ $check = 'restricthtml';
+ }
+ $value = GETPOSTISSET($html_name) ? GETPOST($html_name, $check) : $assetdepreciationoptions->$field_key;
+ } elseif ($field_info['type'] == 'price') {
+ $value = GETPOSTISSET($html_name) ? price2num(GETPOST($html_name)) : ($assetdepreciationoptions->$field_key ? price2num($assetdepreciationoptions->$field_key) : (!empty($field_info['default']) ? dol_eval($field_info['default'], 1) : 0));
+ } elseif ($field_key == 'lang') {
+ $value = GETPOSTISSET($html_name) ? GETPOST($html_name, 'aZ09') : $assetdepreciationoptions->lang;
+ } else {
+ $value = GETPOSTISSET($html_name) ? GETPOST($html_name, 'alpha') : $assetdepreciationoptions->$field_key;
+ }
+ if (!empty($field_info['noteditable'])) {
+ print $assetdepreciationoptions->showOutputField($field_info, $field_key, $value, '', '', $prefix_html_name, 0);
+ } else {
+ if ($field_key == 'lang') {
+ print img_picto('', 'language', 'class="pictofixedwidth"');
+ print $formadmin->select_language($value, $html_name, 0, null, 1, 0, 0, 'minwidth300', 2);
+ } else {
+ print $assetdepreciationoptions->showInputField($field_info, $field_key, $value, '', '', $prefix_html_name, 0);
+ }
+ }
+ print ' ';
+ print ' ';
+ }
+ print '
';
+ print '
';
+ print '
';
+ print '
';
+ print '
';
+ }
+}
+
+if (!empty($enabled_field_info)) {
+ $enabled_field_info = json_encode($enabled_field_info);
+ print <<
+SCRIPT;
+}
+
+?>
+
diff --git a/htdocs/asset/tpl/depreciation_options_view.tpl.php b/htdocs/asset/tpl/depreciation_options_view.tpl.php
new file mode 100644
index 00000000000..2660fbbaee7
--- /dev/null
+++ b/htdocs/asset/tpl/depreciation_options_view.tpl.php
@@ -0,0 +1,154 @@
+
+ *
+ * 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 .
+ *
+ * Show extrafields. It also show fields from hook formAssetAccountancyCode. Need to have following variables defined:
+ * $object (asset, assetmodel, ...)
+ * $assetaccountancycodes
+ * $action
+ * $conf
+ * $langs
+ *
+ * $parameters
+ */
+
+// Protection to avoid direct call of template
+if (empty($object) || !is_object($object)) {
+ print "Error, template page can't be called as URL";
+ exit;
+}
+
+if (!is_object($form)) {
+ $form = new Form($db);
+}
+
+
+?>
+
+executeHooks('formAssetDeprecationOptions', $parameters, $object, $action);
+print $hookmanager->resPrint;
+if ($reshook < 0) {
+ setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+}
+
+if (empty($reshook)) {
+ $class_type = get_class($object) == 'Asset' ? 0 : 1;
+ foreach ($assetdepreciationoptions->deprecation_options_fields as $mode_key => $mode_info) {
+ if (!empty($mode_info['enabled_field'])) {
+ $info = explode(':', $mode_info['enabled_field']);
+ if ($assetdepreciationoptions->deprecation_options[$info[0]][$info[1]] != $info[2]) {
+ continue;
+ }
+ }
+
+ $assetdepreciationoptions->setInfosForMode($mode_key, $class_type, true);
+
+ print load_fiche_titre($langs->trans($mode_info['label']), '', '');
+ print '';
+ print '
';
+ print '
';
+ print '
' . "\n";
+ $mode_info['fields'] = dol_sort_array($mode_info['fields'], 'position');
+ foreach ($mode_info['fields'] as $field_key => $field_info) {
+ if (!empty($field_info['enabled_field'])) {
+ $info = explode(':', $field_info['enabled_field']);
+ if ($assetdepreciationoptions->deprecation_options[$info[0]][$info[1]] != $info[2]) {
+ continue;
+ }
+ }
+ // Discard if extrafield is a hidden field on form
+ if (abs($field_info['visible']) != 1 && abs($field_info['visible']) != 3 && abs($field_info['visible']) != 4 && abs($field_info['visible']) != 5) {
+ continue;
+ }
+ if (array_key_exists('enabled', $field_info) && isset($field_info['enabled']) && !verifCond($field_info['enabled'])) {
+ continue; // We don't want this field
+ }
+ if (!empty($field_info['column_break'])) {
+ print '
';
+
+ // We close div and reopen for second column
+ print '
';
+ print '
';
+
+ print '
';
+ print '
';
+ }
+
+ $key = $mode_key . '_' . $field_key;
+ $value = $assetdepreciationoptions->deprecation_options[$mode_key][$field_key];
+
+ print '';
+ if (!empty($field_info['help'])) {
+ print $form->textwithpicto($langs->trans($field_info['label']), $langs->trans($field_info['help']));
+ } else {
+ if (isset($field_info['copytoclipboard']) && $field_info['copytoclipboard'] == 1) {
+ print showValueWithClipboardCPButton($value, 0, $langs->transnoentitiesnoconv($field_info['label']));
+ } else {
+ print $langs->trans($field_info['label']);
+ }
+ }
+ print ' ';
+ print '';
+ if (in_array($field_info['type'], array('text', 'html'))) {
+ print '';
+ }
+ if ($field_key == 'lang') {
+ $langs->load("languages");
+ $labellang = ($value ? $langs->trans('Language_' . $value) : '');
+ print picto_from_langcode($value, 'class="paddingrightonly saturatemedium opacitylow"');
+ print $labellang;
+ } else {
+ if (isset($field_info['copytoclipboard']) && $field_info['copytoclipboard'] == 2) {
+ $out = $assetdepreciationoptions->showOutputField($field_info, $field_key, $value, '', '', $mode_key . '_', 0);
+ print showValueWithClipboardCPButton($out, 0, $out);
+ } else {
+ print $assetdepreciationoptions->showOutputField($field_info, $field_key, $value, '', '', $mode_key . '_', 0);
+ }
+ }
+ if (in_array($field_info['type'], array('text', 'html'))) {
+ print '
';
+ }
+ print ' ';
+ print ' ';
+ }
+ print '
';
+ print '
';
+ print '
';
+ print '
';
+ }
+}
+
+?>
+
diff --git a/htdocs/asset/tpl/depreciation_view.tpl.php b/htdocs/asset/tpl/depreciation_view.tpl.php
new file mode 100644
index 00000000000..2660fbbaee7
--- /dev/null
+++ b/htdocs/asset/tpl/depreciation_view.tpl.php
@@ -0,0 +1,154 @@
+
+ *
+ * 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 .
+ *
+ * Show extrafields. It also show fields from hook formAssetAccountancyCode. Need to have following variables defined:
+ * $object (asset, assetmodel, ...)
+ * $assetaccountancycodes
+ * $action
+ * $conf
+ * $langs
+ *
+ * $parameters
+ */
+
+// Protection to avoid direct call of template
+if (empty($object) || !is_object($object)) {
+ print "Error, template page can't be called as URL";
+ exit;
+}
+
+if (!is_object($form)) {
+ $form = new Form($db);
+}
+
+
+?>
+
+executeHooks('formAssetDeprecationOptions', $parameters, $object, $action);
+print $hookmanager->resPrint;
+if ($reshook < 0) {
+ setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+}
+
+if (empty($reshook)) {
+ $class_type = get_class($object) == 'Asset' ? 0 : 1;
+ foreach ($assetdepreciationoptions->deprecation_options_fields as $mode_key => $mode_info) {
+ if (!empty($mode_info['enabled_field'])) {
+ $info = explode(':', $mode_info['enabled_field']);
+ if ($assetdepreciationoptions->deprecation_options[$info[0]][$info[1]] != $info[2]) {
+ continue;
+ }
+ }
+
+ $assetdepreciationoptions->setInfosForMode($mode_key, $class_type, true);
+
+ print load_fiche_titre($langs->trans($mode_info['label']), '', '');
+ print '';
+ print '
';
+ print '
';
+ print '
' . "\n";
+ $mode_info['fields'] = dol_sort_array($mode_info['fields'], 'position');
+ foreach ($mode_info['fields'] as $field_key => $field_info) {
+ if (!empty($field_info['enabled_field'])) {
+ $info = explode(':', $field_info['enabled_field']);
+ if ($assetdepreciationoptions->deprecation_options[$info[0]][$info[1]] != $info[2]) {
+ continue;
+ }
+ }
+ // Discard if extrafield is a hidden field on form
+ if (abs($field_info['visible']) != 1 && abs($field_info['visible']) != 3 && abs($field_info['visible']) != 4 && abs($field_info['visible']) != 5) {
+ continue;
+ }
+ if (array_key_exists('enabled', $field_info) && isset($field_info['enabled']) && !verifCond($field_info['enabled'])) {
+ continue; // We don't want this field
+ }
+ if (!empty($field_info['column_break'])) {
+ print '
';
+
+ // We close div and reopen for second column
+ print '
';
+ print '
';
+
+ print '
';
+ print '
';
+ }
+
+ $key = $mode_key . '_' . $field_key;
+ $value = $assetdepreciationoptions->deprecation_options[$mode_key][$field_key];
+
+ print '';
+ if (!empty($field_info['help'])) {
+ print $form->textwithpicto($langs->trans($field_info['label']), $langs->trans($field_info['help']));
+ } else {
+ if (isset($field_info['copytoclipboard']) && $field_info['copytoclipboard'] == 1) {
+ print showValueWithClipboardCPButton($value, 0, $langs->transnoentitiesnoconv($field_info['label']));
+ } else {
+ print $langs->trans($field_info['label']);
+ }
+ }
+ print ' ';
+ print '';
+ if (in_array($field_info['type'], array('text', 'html'))) {
+ print '';
+ }
+ if ($field_key == 'lang') {
+ $langs->load("languages");
+ $labellang = ($value ? $langs->trans('Language_' . $value) : '');
+ print picto_from_langcode($value, 'class="paddingrightonly saturatemedium opacitylow"');
+ print $labellang;
+ } else {
+ if (isset($field_info['copytoclipboard']) && $field_info['copytoclipboard'] == 2) {
+ $out = $assetdepreciationoptions->showOutputField($field_info, $field_key, $value, '', '', $mode_key . '_', 0);
+ print showValueWithClipboardCPButton($out, 0, $out);
+ } else {
+ print $assetdepreciationoptions->showOutputField($field_info, $field_key, $value, '', '', $mode_key . '_', 0);
+ }
+ }
+ if (in_array($field_info['type'], array('text', 'html'))) {
+ print '
';
+ }
+ print ' ';
+ print ' ';
+ }
+ print '
';
+ print '
';
+ print '
';
+ print '
';
+ }
+}
+
+?>
+
diff --git a/htdocs/asset/tpl/linkedobjectblock.tpl.php b/htdocs/asset/tpl/linkedobjectblock.tpl.php
new file mode 100644
index 00000000000..59df306c829
--- /dev/null
+++ b/htdocs/asset/tpl/linkedobjectblock.tpl.php
@@ -0,0 +1,81 @@
+
+ * Copyright (C) 2013 Juanjo Menent
+ * Copyright (C) 2014 Marcos García
+ *
+ * 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 .
+ */
+
+// Protection to avoid direct call of template
+if (empty($conf) || !is_object($conf)) {
+ print "Error, template page can't be called as URL";
+ exit;
+}
+
+print "\n";
+
+global $user;
+global $noMoreLinkedObjectBlockAfter;
+
+$langs = $GLOBALS['langs'];
+$linkedObjectBlock = $GLOBALS['linkedObjectBlock'];
+
+// Load translation files required by the page
+$langs->load("assets");
+
+$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date', 'desc', 0, 0, 1);
+
+$total = 0;
+$ilink = 0;
+foreach ($linkedObjectBlock as $key => $objectlink) {
+ $ilink++;
+
+ $trclass = 'oddeven';
+ if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) {
+ $trclass .= ' liste_sub_total';
+ }
+ echo '';
+ echo ''.$langs->trans("Asset");
+ if (!empty($showImportButton) && !empty($conf->global->MAIN_ENABLE_IMPORT_LINKED_OBJECT_LINES)) {
+ print ' ';
+ echo ' '.$objectlink->getNomUrl(1).' ';
+ echo ''.$objectlink->label.' ';
+ echo ''.dol_print_date($objectlink->date_start, 'day').' ';
+ echo '';
+ if ($user->rights->asset->read) {
+ $total = $total + $objectlink->acquisition_value_ht;
+ echo price($objectlink->acquisition_value_ht);
+ }
+ echo ' ';
+ echo ''.$objectlink->getLibStatut(3).' ';
+ echo '';
+ echo 'id.'&action=dellink&token='.newToken().'&dellinkid='.$key.'">'.img_picto($langs->transnoentitiesnoconv("RemoveLink"), 'unlink').' ';
+ echo ' ';
+ echo " \n";
+}
+if (count($linkedObjectBlock) > 1) {
+ echo '';
+ echo ''.$langs->trans("Total").' ';
+ echo ' ';
+ echo ' ';
+ echo ' ';
+ echo ''.price($total).' ';
+ echo ' ';
+ echo ' ';
+ echo " \n";
+}
+
+echo "\n";
diff --git a/htdocs/asset/type.php b/htdocs/asset/type.php
deleted file mode 100644
index cd802c1c4fd..00000000000
--- a/htdocs/asset/type.php
+++ /dev/null
@@ -1,608 +0,0 @@
-
- *
- * 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', 'aZ09');
-$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', 'aZ09comma');
-$sortorder = GETPOST('sortorder', 'aZ09comma');
-$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'));
-
-$permissiontoadd = $user->rights->asset->setup_advance;
-
-
-/*
- * 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, '@GETPOSTISSET');
- if ($ret < 0) {
- $error++;
- }
-
- $ret = $object->update($user);
-
- if ($ret >= 0 && !count($object->errors)) {
- setEventMessages($langs->trans("AssetTypeModified"), 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);
-
-$help_url = '';
-
-llxHeader('', $langs->trans("AssetsTypeSetup"), $help_url);
-
-
-// List of asset type
-if (!$rowid && $action != 'create' && $action != 'edit') {
- //print dol_get_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 = '';
-
- 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"), '', $object->picto);
-
- 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);
-
- print dol_get_fiche_head($head, 'card', $langs->trans("AssetType"), -1, 'asset');
-
- $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 $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 ' ';
-
- print '';
- 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 ' ';
-
- print '';
- 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 ' ';
- print ' ';
-
- print ''.$langs->trans("Description").' ';
- print nl2br($object->note)." ";
-
- // Other attributes
- include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
-
- print '
';
- print '
';
-
- print dol_get_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 'id.'">';
- print ' ';
- print ' ';
- print ' ';
-
- print dol_get_fiche_head($head, 'card', $langs->trans("AssetsType"), -1, 'setup');
-
- print '';
-
- print ''.$langs->trans("Ref").' '.$object->id.' ';
-
- print ''.$langs->trans("Label").' ';
-
- if (!empty($conf->accounting->enabled)) {
- // Accountancy_code_asset
- print ''.$langs->trans("AccountancyCodeAsset").' ';
- print '';
- print $formaccounting->select_account($object->accountancy_code_asset, 'accountancy_code_asset', 1, '', 1, 1);
- print ' ';
-
- // Accountancy_code_depreciation_expense
- print ''.$langs->trans("AccountancyCodeDepreciationAsset").' ';
- print '';
- print $formaccounting->select_account($object->accountancy_code_depreciation_asset, 'accountancy_code_depreciation_asset', 1, '', 1, 1);
- print ' ';
-
- // Accountancy_code_depreciation_expense
- print ''.$langs->trans("AccountancyCodeDepreciationExpense").' ';
- print '';
- print $formaccounting->select_account($object->accountancy_code_depreciation_expense, 'accountancy_code_depreciation_expense', 1, '', 1, 1);
- print ' ';
- } else // For external software
- {
- // Accountancy_code_asset
- print ''.$langs->trans("AccountancyCodeAsset").' ';
- print ' ';
- print ' ';
-
- // Accountancy_code_depreciation_asset
- print ''.$langs->trans("AccountancyCodeDepreciationAsset").' ';
- print ' ';
- print ' ';
-
- // Accountancy_code_depreciation_expense
- print ''.$langs->trans("AccountancyCodeDepreciationExpense").' ';
- print ' ';
- print ' ';
- }
-
- print ''.$langs->trans("Description").' ';
- print ''.$object->note.' ';
-
- // 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 '
';
-
- print dol_get_fiche_end();
-
- print $form->buttonsSaveCancel();
-
- print " ";
- }
-}
-
-// End of page
-llxFooter();
-$db->close();
diff --git a/htdocs/compta/facture/card-rec.php b/htdocs/compta/facture/card-rec.php
index a30abcc9ca1..1266232a46e 100644
--- a/htdocs/compta/facture/card-rec.php
+++ b/htdocs/compta/facture/card-rec.php
@@ -765,8 +765,8 @@ if (empty($reshook)) {
// Define special_code for special lines
$special_code = GETPOST('special_code', 'int');
- if (!GETPOST('qty', 'alpha')) {
- $special_code = 3;
+ if ($special_code == 3) {
+ $special_code = 0; // Options should not exists on invoices
}
/*$line = new FactureLigne($db);
diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php
index 278a7837374..a4d85c257f8 100644
--- a/htdocs/compta/facture/card.php
+++ b/htdocs/compta/facture/card.php
@@ -743,7 +743,7 @@ if (empty($reshook)) {
}
if (!$error) {
- // On verifie si la facture a des paiements
+ // We check if invoice has payments
$sql = 'SELECT pf.amount';
$sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
$sql .= ' WHERE pf.fk_facture = '.((int) $object->id);
@@ -993,7 +993,7 @@ if (empty($reshook)) {
$db->rollback();
}
}
- } elseif ($action == 'confirm_delete_paiement' && $confirm == 'yes' && $usercancreate) {
+ } elseif ($action == 'confirm_delete_paiement' && $confirm == 'yes' && $usercanissuepayment) {
// Delete payment
$object->fetch($id);
if ($object->statut == Facture::STATUS_VALIDATED && $object->paye == 0) {
@@ -2397,9 +2397,9 @@ if (empty($reshook)) {
}
// Define special_code for special lines
- $special_code = GETPOST('special_code');
- if (!GETPOST('qty')) {
- $special_code = 3;
+ $special_code = GETPOST('special_code', 'int');
+ if ($special_code == 3) {
+ $special_code = 0; // Options should not exists on invoices
}
$line = new FactureLigne($db);
@@ -2925,6 +2925,9 @@ if ($action == 'create') {
if (empty($mode_reglement_id)) {
$mode_reglement_id = $soc->mode_reglement_id;
}
+ if (empty($fk_account)) {
+ $fk_account = $soc->fk_account;
+ }
if (!$remise_percent) {
$remise_percent = $soc->remise_percent;
}
@@ -3032,6 +3035,9 @@ if ($action == 'create') {
$mode_reglement_id = GETPOST("mode_reglement_id", 'int');
}
+ // when bank account is empty (means not override by payment mode form a other object, like third-party), try to use default value
+ $fk_account = GETPOSTISSET("fk_account") ? GETPOST("fk_account", 'int') : $fk_account;
+
if (!empty($soc->id)) {
$absolute_discount = $soc->getAvailableDiscounts();
}
@@ -3638,8 +3644,8 @@ if ($action == 'create') {
// Bank Account
if (!empty($conf->banque->enabled)) {
print ''.$langs->trans('BankAccount').' ';
- $fk_account = GETPOSTISSET('fk_account') ? GETPOST('fk_account', 'int') : $fk_account;
- print img_picto('', 'bank_account', 'class="pictofixedwidth"').$form->select_comptes(($fk_account < 0 ? '' : $fk_account), 'fk_account', 0, '', 1, '', 0, 'maxwidth200 widthcentpercentminusx', 1);
+ print img_picto('', 'bank_account', 'class="pictofixedwidth"');
+ print $form->select_comptes(($fk_account < 0 ? '' : $fk_account), 'fk_account', 0, '', 1, '', 0, 'maxwidth200 widthcentpercentminusx', 1);
print ' ';
}
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index 33720b8345e..70aebe6932c 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -2643,6 +2643,7 @@ class Facture extends CommonInvoice
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
$productStatic = new Product($this->db);
$warehouseStatic = new Entrepot($this->db);
+ $productbatch = new ProductBatch($this->db);
}
$now = dol_now();
@@ -2785,7 +2786,7 @@ class Facture extends CommonInvoice
$sortorder = 'ASC,ASC,ASC,ASC';
}
- $resBatchList = Productbatch::findAllForProduct($this->db, $productStatic->id, $idwarehouse, (!empty($conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER) ? null : 0), $sortfield, $sortorder);
+ $resBatchList = $productbatch->findAllForProduct($productStatic->id, $idwarehouse, (!empty($conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER) ? null : 0), $sortfield, $sortorder);
if (!is_array($resBatchList)) {
$error++;
$this->error = $this->db->lasterror();
diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php
index 5039507e3f5..9f40d2daa88 100644
--- a/htdocs/compta/paiement.php
+++ b/htdocs/compta/paiement.php
@@ -75,6 +75,12 @@ $hookmanager->initHooks(array('paiementcard', 'globalcard'));
$formquestion = array();
+$usercanissuepayment = !empty($user->rights->facture->paiement);
+
+$fieldid = 'rowid';
+$isdraft = (($object->statut == Facture::STATUS_DRAFT) ? 1 : 0);
+$result = restrictedArea($user, 'facture', $object->id, '', '', 'fk_soc', $fieldid, $isdraft);
+
/*
* Actions
@@ -87,7 +93,7 @@ if ($reshook < 0) {
}
if (empty($reshook)) {
- if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm == 'yes')) {
+ if (($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm == 'yes')) && $usercanissuepayment) {
$error = 0;
$datepaye = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
@@ -202,7 +208,7 @@ if (empty($reshook)) {
/*
* Action confirm_paiement
*/
- if ($action == 'confirm_paiement' && $confirm == 'yes') {
+ if ($action == 'confirm_paiement' && $confirm == 'yes' && $usercanissuepayment) {
$error = 0;
$datepaye = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
@@ -486,7 +492,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
print ''.$langs->trans('AccountToDebit').' ';
}
print '';
- $form->select_comptes($accountid, 'accountid', 0, '', 2);
+ print $form->select_comptes($accountid, 'accountid', 0, '', 2, '', 0, '', 1);
print ' ';
} else {
print ' ';
diff --git a/htdocs/compta/paiement/card.php b/htdocs/compta/paiement/card.php
index 33558ddf38a..7d3025475e7 100644
--- a/htdocs/compta/paiement/card.php
+++ b/htdocs/compta/paiement/card.php
@@ -64,6 +64,8 @@ if ($socid && $socid != $object->thirdparty->id) {
accessforbidden();
}
+$error = 0;
+
/*
* Actions
@@ -191,6 +193,39 @@ if ($action == 'setdatep' && GETPOST('datepday')) {
setEventMessages($langs->trans('PaymentDateUpdateFailed'), null, 'errors');
}
}
+if ($action == 'createbankpayment' && !empty($user->rights->facture->paiement)) {
+ $db->begin();
+
+ // Create the record into bank for the amount of payment $object
+ if (!$error) {
+ $label = '(CustomerInvoicePayment)';
+ if (GETPOST('type') == Facture::TYPE_CREDIT_NOTE) {
+ $label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note
+ }
+
+ $bankaccountid = GETPOST('accountid', 'int');
+ if ($bankaccountid > 0) {
+ $object->paiementcode = $object->type_code;
+ $object->amounts = $object->getAmountsArray();
+
+ $result = $object->addPaymentToBank($user, 'payment', $label, $bankaccountid, '', '');
+ if ($result < 0) {
+ setEventMessages($object->error, $object->errors, 'errors');
+ $error++;
+ }
+ } else {
+ setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors');
+ $error++;
+ }
+ }
+
+
+ if (!$error) {
+ $db->commit();
+ } else {
+ $db->rollback();
+ }
+}
/*
@@ -315,7 +350,37 @@ if (!empty($conf->banque->enabled)) {
print $bankline->getNomUrl(1, 0, 'showconciliatedandaccounted');
} else {
$langs->load("admin");
- print ''.$langs->trans("NoRecordFoundIBankcAccount", $langs->transnoentitiesnoconv("Module85Name")).' ';
+ print '';
+ print $langs->trans("NoRecordFoundIBankcAccount", $langs->transnoentitiesnoconv("Module85Name"));
+ print ' ';
+ if (!empty($user->rights->facture->paiement)) {
+ // Try to guess $bankaccountidofinvoices that is ID of bank account defined on invoice.
+ // Return null if not found, return 0 if it has different value for at least 2 invoices, return the value if same on all invoices where a bank is defined.
+ $amountofpayments = $object->getAmountsArray();
+ $bankaccountidofinvoices = null;
+ foreach ($amountofpayments as $idinvoice => $amountofpayment) {
+ $tmpinvoice = new Facture($db);
+ $tmpinvoice->fetch($idinvoice);
+ if ($tmpinvoice->fk_account > 0 && $bankaccountidofinvoices !== 0) {
+ if (is_null($bankaccountidofinvoices)) {
+ $bankaccountidofinvoices = $tmpinvoice->fk_account;
+ } elseif ($bankaccountidofinvoices != $tmpinvoice->fk_account) {
+ $bankaccountidofinvoices = 0;
+ }
+ }
+ }
+
+ print '';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' '.$langs->trans("ToCreateRelatedRecordIntoBank").': ';
+ print $form->select_comptes($bankaccountidofinvoices, 'accountid', 0, '', 2, '', 0, '', 1);
+ //print '';
+ print ' ';
+ //print ' ';
+ print ' ';
+ }
}
print ' ';
print ' ';
diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php
index 84d1b007e09..32edc0629bd 100644
--- a/htdocs/compta/paiement/class/paiement.class.php
+++ b/htdocs/compta/paiement/class/paiement.class.php
@@ -82,12 +82,12 @@ class Paiement extends CommonObject
public $paiementcode; // Code of payment.
/**
- * @var string type libelle
+ * @var string Type of payment label
*/
public $type_label;
/**
- * @var string type code
+ * @var string Type of payment code (seems duplicate with $paiementcode);
*/
public $type_code;
@@ -585,16 +585,19 @@ class Paiement extends CommonObject
return -1;
}
- $this->db->begin();
-
$this->fk_account = $accountid;
+ dol_syslog("addPaymentToBank ".$user->id.", ".$mode.", ".$label.", ".$this->fk_account.", ".$emetteur_nom.", ".$emetteur_banque);
+
include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
-
- dol_syslog("$user->id, $mode, $label, $this->fk_account, $emetteur_nom, $emetteur_banque");
-
$acc = new Account($this->db);
$result = $acc->fetch($this->fk_account);
+ if ($result < 0) {
+ $error++;
+ return -1;
+ }
+
+ $this->db->begin();
$totalamount = $this->amount;
if (empty($totalamount)) {
@@ -951,6 +954,7 @@ class Paiement extends CommonObject
*
* @param string $filter Filter
* @return int|array <0 if KO or array of invoice id
+ * @see getAmountsArray()
*/
public function getBillsArray($filter = '')
{
@@ -984,6 +988,7 @@ class Paiement extends CommonObject
* Return list of amounts of payments.
*
* @return int|array Array of amount of payments
+ * @see getBillsArray()
*/
public function getAmountsArray()
{
diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php
index a8986475095..8030c2f58ec 100644
--- a/htdocs/core/class/CMailFile.class.php
+++ b/htdocs/core/class/CMailFile.class.php
@@ -149,31 +149,7 @@ class CMailFile
}
}
- // Add autocopy to if not already in $to (Note: Adding bcc for specific modules are also done from pages)
- if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_TO) && !preg_match('/'.preg_quote($conf->global->MAIN_MAIL_AUTOCOPY_TO, '/').'/i', $to)) {
- $addr_bcc .= ($addr_bcc ? ', ' : '').$conf->global->MAIN_MAIL_AUTOCOPY_TO;
- }
-
- $this->subject = $subject;
- $this->addr_to = $to;
- $this->addr_from = $from;
- $this->msg = $msg;
- $this->filename_list = $filename_list;
- $this->mimetype_list = $mimetype_list;
- $this->mimefilename_list = $mimefilename_list;
- $this->addr_cc = $addr_cc;
- $this->addr_bcc = $addr_bcc;
- $this->deliveryreceipt = $deliveryreceipt;
- if (empty($replyto)) {
- $replyto = $from;
- }
- $this->reply_to = $replyto;
- $this->errors_to = $errors_to;
- $this->trackid = $trackid;
$this->sendcontext = $sendcontext;
- $this->filename_list = $filename_list;
- $this->mimetype_list = $mimetype_list;
- $this->mimefilename_list = $mimefilename_list;
// Define this->sendmode
$this->sendmode = '';
@@ -186,10 +162,7 @@ class CMailFile
}
}
if (empty($this->sendmode)) {
- $this->sendmode = $conf->global->MAIN_MAIL_SENDMODE;
- }
- if (empty($this->sendmode)) {
- $this->sendmode = 'mail';
+ $this->sendmode = (!empty($conf->global->MAIN_MAIL_SENDMODE) ? $conf->global->MAIN_MAIL_SENDMODE : 'mail');
}
// We define end of line (RFC 821).
@@ -283,15 +256,25 @@ class CMailFile
$addr_bcc .= ($addr_bcc ? ', ' : '').$conf->global->MAIN_MAIL_AUTOCOPY_TO;
}
+ $this->subject = $subject;
$this->addr_to = $to;
+ $this->addr_from = $from;
+ $this->msg = $msg;
+ $this->filename_list = $filename_list;
+ $this->mimetype_list = $mimetype_list;
+ $this->mimefilename_list = $mimefilename_list;
$this->addr_cc = $addr_cc;
$this->addr_bcc = $addr_bcc;
- $this->reply_to = $replyto;
- $this->addr_from = $from;
- $this->subject = $subject;
- $this->errors_to = $errors_to;
$this->deliveryreceipt = $deliveryreceipt;
+ if (empty($replyto)) {
+ $replyto = $from;
+ }
+ $this->reply_to = $replyto;
+ $this->errors_to = $errors_to;
$this->trackid = $trackid;
+ $this->filename_list = $filename_list;
+ $this->mimetype_list = $mimetype_list;
+ $this->mimefilename_list = $mimefilename_list;
if (!empty($conf->global->MAIN_MAIL_FORCE_SENDTO)) {
$this->addr_to = $conf->global->MAIN_MAIL_FORCE_SENDTO;
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index aaa3aa6a766..4c7a1496064 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -7,7 +7,7 @@
* Copyright (C) 2012-2015 Marcos García