From 6d4a90b54334370459cc7f097a1f92e6945ab7f5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 4 Dec 2020 14:53:52 +0100 Subject: [PATCH] Clean code --- htdocs/adherents/class/adherent.class.php | 14 ++++---- htdocs/core/class/html.formother.class.php | 30 ++++++++++------ htdocs/holiday/card.php | 4 +-- htdocs/holiday/common.inc.php | 42 ---------------------- htdocs/holiday/define_holiday.php | 17 +++++++-- htdocs/holiday/list.php | 13 +++++-- htdocs/holiday/month_report.php | 4 +-- htdocs/holiday/view_log.php | 18 +++++++--- test/phpunit/phpunittest.xml | 29 ++++++++------- 9 files changed, 85 insertions(+), 86 deletions(-) delete mode 100644 htdocs/holiday/common.inc.php diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 0e57b274258..5df6db52f3d 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -103,6 +103,7 @@ class Adherent extends CommonObject * @var int Thirdparty ID */ public $fk_soc; + public $socid; /** * @var string Address @@ -1262,14 +1263,15 @@ class Adherent extends CommonObject $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as dep ON d.state_id = dep.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON d.rowid = u.fk_member"; $sql .= " WHERE d.fk_adherent_type = t.rowid"; - if ($rowid) - $sql .= " AND d.rowid=".$rowid; - elseif ($ref || $fk_soc) { + if ($rowid) { + $sql .= " AND d.rowid=".((int) $rowid); + } elseif ($ref || $fk_soc) { $sql .= " AND d.entity IN (".getEntity('adherent').")"; - if ($ref) + if ($ref) { $sql .= " AND d.rowid='".$this->db->escape($ref)."'"; - elseif ($fk_soc > 0) - $sql .= " AND d.fk_soc=".$fk_soc; + } elseif ($fk_soc > 0) { + $sql .= " AND d.fk_soc=".((int) $fk_soc); + } } elseif ($ref_ext) { $sql .= " AND d.ref_ext='".$this->db->escape($ref_ext)."'"; } diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index f1e5ff9921c..3b9d9db2906 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -918,9 +918,10 @@ class FormOther * @param int $useempty Show empty in list * @param int $longlabel Show long label * @param string $morecss More Css + * @param bool $addjscombo Add js combo * @return string */ - public function select_month($selected = '', $htmlname = 'monthid', $useempty = 0, $longlabel = 0, $morecss = 'maxwidth50imp valignmiddle') + public function select_month($selected = '', $htmlname = 'monthid', $useempty = 0, $longlabel = 0, $morecss = 'minwidth50 maxwidth75imp valignmiddle', $addjscombo = false) { // phpcs:enable global $langs; @@ -947,6 +948,15 @@ class FormOther $select_month .= ''; } $select_month .= ''; + + // Add code for jquery to use multiselect + if ($addjscombo) + { + // Enhance with select2 + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; + $select_month .= ajax_combobox($htmlname); + } + return $select_month; } @@ -986,18 +996,10 @@ class FormOther * @param bool $addjscombo Add js combo * @return string */ - public function selectyear($selected = '', $htmlname = 'yearid', $useempty = 0, $min_year = 10, $max_year = 5, $offset = 0, $invert = 0, $option = '', $morecss = 'valignmiddle maxwidth75imp', $addjscombo = false) + public function selectyear($selected = '', $htmlname = 'yearid', $useempty = 0, $min_year = 10, $max_year = 5, $offset = 0, $invert = 0, $option = '', $morecss = 'valignmiddle width75', $addjscombo = false) { $out = ''; - // Add code for jquery to use multiselect - if ($addjscombo) - { - // Enhance with select2 - include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; - $out .= ajax_combobox($htmlname); - } - $currentyear = date("Y") + $offset; $max_year = $currentyear + $max_year; $min_year = $currentyear - $min_year; @@ -1028,6 +1030,14 @@ class FormOther } $out .= "\n"; + // Add code for jquery to use multiselect + if ($addjscombo) + { + // Enhance with select2 + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; + $out .= ajax_combobox($htmlname); + } + return $out; } diff --git a/htdocs/holiday/card.php b/htdocs/holiday/card.php index 7248f385994..4adecb20235 100644 --- a/htdocs/holiday/card.php +++ b/htdocs/holiday/card.php @@ -36,7 +36,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/holiday.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; // Get parameters @@ -49,7 +49,7 @@ $ref = GETPOST('ref', 'alpha'); $fuserid = (GETPOST('fuserid', 'int') ?GETPOST('fuserid', 'int') : $user->id); // Load translation files required by the page -$langs->loadLangs(array("holiday", "mails")); +$langs->loadLangs(array("other", "holiday", "mails")); $now = dol_now(); diff --git a/htdocs/holiday/common.inc.php b/htdocs/holiday/common.inc.php deleted file mode 100644 index f8a09e85ad5..00000000000 --- a/htdocs/holiday/common.inc.php +++ /dev/null @@ -1,42 +0,0 @@ - - * Copyright (C) 2011 Dimitri Mouillard - * Copyright (C) 2012 Regis Houssin - * - * 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/holiday/common.inc.php - * \ingroup holiday - * \brief Common load of data - */ - -require_once realpath(__DIR__).'/../main.inc.php'; -if (!class_exists('Holiday')) { - require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php'; -} - -// Load translation files required by the page -$langs->loadLangs(array('user', 'other', 'holiday')); - -if (empty($conf->holiday->enabled)) -{ - llxHeader('', $langs->trans('CPTitreMenu')); - print '
'; - print ''.$langs->trans('NotActiveModCP').''; - print '
'; - llxFooter(); - exit(); -} diff --git a/htdocs/holiday/define_holiday.php b/htdocs/holiday/define_holiday.php index 585c80e3e6d..45442e6170d 100644 --- a/htdocs/holiday/define_holiday.php +++ b/htdocs/holiday/define_holiday.php @@ -28,10 +28,10 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; -require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php'; // Load translation files required by the page -$langs->loadlangs(array('users', 'hrm')); +$langs->loadlangs(array('users', 'other', 'holiday', 'hrm')); $action = GETPOST('action', 'aZ09'); $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'defineholidaylist'; @@ -56,7 +56,7 @@ if (!$sortorder) $sortorder = "ASC"; if ($user->socid > 0) accessforbidden(); // If the user does not have perm to read the page -if (!$user->rights->holiday->read) accessforbidden(); +if (empty($user->rights->holiday->read)) accessforbidden(); // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array @@ -65,6 +65,17 @@ $extrafields = new ExtraFields($db); $holiday = new Holiday($db); +if (empty($conf->holiday->enabled)) +{ + llxHeader('', $langs->trans('CPTitreMenu')); + print '
'; + print ''.$langs->trans('NotActiveModCP').''; + print '
'; + llxFooter(); + exit(); +} + + /* * Actions diff --git a/htdocs/holiday/list.php b/htdocs/holiday/list.php index bfdef939be3..41ae8a6956f 100644 --- a/htdocs/holiday/list.php +++ b/htdocs/holiday/list.php @@ -32,12 +32,12 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php'; -require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php'; // Load translation files required by the page -$langs->loadLangs(array('users', 'holiday', 'hrm')); +$langs->loadLangs(array('users', 'other', 'holiday', 'hrm')); // Protection if external user if ($user->socid > 0) accessforbidden(); @@ -152,6 +152,15 @@ if (is_array($extrafields->attributes[$object->table_element]['label']) && count } } +if (empty($conf->holiday->enabled)) +{ + llxHeader('', $langs->trans('CPTitreMenu')); + print '
'; + print ''.$langs->trans('NotActiveModCP').''; + print '
'; + llxFooter(); + exit(); +} /* diff --git a/htdocs/holiday/month_report.php b/htdocs/holiday/month_report.php index 5108c97f54a..b83d957b27f 100644 --- a/htdocs/holiday/month_report.php +++ b/htdocs/holiday/month_report.php @@ -179,8 +179,8 @@ print load_fiche_titre($langs->trans('MenuReportMonth'), '', 'title_hrm'); // Selection filter print '
'; -print $formother->select_month($search_month, 'remonth'); -print $formother->select_year($search_year, 'reyear'); +print $formother->select_month($search_month, 'remonth', 0, 0, 'minwidth50 maxwidth75imp valignmiddle', true); +print $formother->selectyear($search_year, 'reyear', 0, 10, 5, 0, 0, '', 'valignmiddle width75', true); print ''; print '
'; print '
'; diff --git a/htdocs/holiday/view_log.php b/htdocs/holiday/view_log.php index 54049a201ea..2f2e223c87c 100644 --- a/htdocs/holiday/view_log.php +++ b/htdocs/holiday/view_log.php @@ -34,7 +34,7 @@ if (empty($user->rights->holiday->define_holiday) || $user->socid > 0) { require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; -require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php'; $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) @@ -72,7 +72,7 @@ if (!$sortorder) $sortorder = "DESC"; if (!$user->rights->holiday->readall) accessforbidden(); // Load translation files required by the page -$langs->load('users'); +$langs->loadLangs(array('users', 'other', 'holiday')); // Initialize technical objects $object = new Holiday($db); @@ -83,6 +83,16 @@ $hookmanager->initHooks(array('leavemovementlist')); // Note that conf->hooks_mo $arrayfields = array(); $arrayofmassactions = array(); +if (empty($conf->holiday->enabled)) +{ + llxHeader('', $langs->trans('CPTitreMenu')); + print '
'; + print ''.$langs->trans('NotActiveModCP').''; + print '
'; + llxFooter(); + exit(); +} + /* * Actions @@ -263,9 +273,9 @@ if (!empty($arrayfields['cpl.rowid']['checked'])) { // Filter: Date if (!empty($arrayfields['cpl.date_action']['checked'])) { - print ''; + print ''; print ''; - print $formother->selectyear($search_year, 'search_year', 1, 10, 5, 0, 0, '', 'maxwidth200', true); + print $formother->selectyear($search_year, 'search_year', 1, 10, 5, 0, 0, '', 'valignmiddle width75', true); print ''; } diff --git a/test/phpunit/phpunittest.xml b/test/phpunit/phpunittest.xml index d648edb6814..7e903daa16d 100644 --- a/test/phpunit/phpunittest.xml +++ b/test/phpunit/phpunittest.xml @@ -17,20 +17,6 @@ - - ../../build/ - ../../dev/ - ../../doc/ - ../../test/ - ../../documents/ - ../../htdocs/custom/ - ../../htdocs/documents/custom/ - ../../htdocs/nltechno/ - ../../htdocs/products/canvas/ - ../../htdocs/contact/canvas/ - ../../htdocs/societe/canvas/ - ../../htdocs/includes/ - ../../htdocs/ ../../htdocs/ @@ -54,8 +40,21 @@ ../../htdocs/contact/canvas/ ../../htdocs/societe/canvas/ ../../htdocs/includes/ - ../../htdocs/holiday/common.inc.php + + ../../build/ + ../../dev/ + ../../doc/ + ../../test/ + ../../documents/ + ../../htdocs/custom/ + ../../htdocs/documents/custom/ + ../../htdocs/nltechno/ + ../../htdocs/products/canvas/ + ../../htdocs/contact/canvas/ + ../../htdocs/societe/canvas/ + ../../htdocs/includes/ +