From 592789c597b3db84ea5649607b395f17f24d12e6 Mon Sep 17 00:00:00 2001 From: Florian Mortgat Date: Tue, 22 Sep 2020 18:34:59 +0200 Subject: [PATCH] Exchange rate editor: +filters --- htdocs/langs/en_US/multicurrency.lang | 1 + htdocs/langs/fr_FR/multicurrency.lang | 1 + htdocs/multicurrency/multicurrency_rates.php | 286 +++++++++++-------- 3 files changed, 171 insertions(+), 117 deletions(-) diff --git a/htdocs/langs/en_US/multicurrency.lang b/htdocs/langs/en_US/multicurrency.lang index 8e4f1c24502..6cfb6d4c62b 100644 --- a/htdocs/langs/en_US/multicurrency.lang +++ b/htdocs/langs/en_US/multicurrency.lang @@ -26,3 +26,4 @@ MulticurrencyDateSync=Date MulticurrencyRate=Exchange rate MulticurrencyCode=Currency code MulticurrencyEntity=Entity +UnknownAction=Unknown action : "%s" diff --git a/htdocs/langs/fr_FR/multicurrency.lang b/htdocs/langs/fr_FR/multicurrency.lang index b1418c780ee..e445066e6d8 100644 --- a/htdocs/langs/fr_FR/multicurrency.lang +++ b/htdocs/langs/fr_FR/multicurrency.lang @@ -26,3 +26,4 @@ MulticurrencyDateSync=Date MulticurrencyRate=Taux de change MulticurrencyCode=Code devise MulticurrencyEntity=Entité +UnknownAction=Action non reconnue : "%s" diff --git a/htdocs/multicurrency/multicurrency_rates.php b/htdocs/multicurrency/multicurrency_rates.php index e41f6ddc48b..0e8b2ecdf58 100644 --- a/htdocs/multicurrency/multicurrency_rates.php +++ b/htdocs/multicurrency/multicurrency_rates.php @@ -53,80 +53,70 @@ $hookmanager->initHooks(array('multicurrency_rates')); // Load translation files required by the page $action = GETPOST('action', 'alpha') ?GETPOST('action', 'alpha') : 'view'; -$confirm = GETPOST('confirm', 'alpha'); -$id = GETPOST('id', 'int'); -$rowid = GETPOST('rowid', 'alpha'); -$entity = GETPOST('entity', 'int'); -$code = GETPOST('code', 'alpha'); - -$acts =array(); $actl =array(); -$acts[0] = "activate"; -$acts[1] = "disable"; -$actl[0] = img_picto($langs->trans("Disabled"), 'switch_off'); -$actl[1] = img_picto($langs->trans("Activated"), 'switch_on'); - -$listoffset = GETPOST('listoffset'); -$listlimit = GETPOST('listlimit') > 0 ?GETPOST('listlimit') : 1000; // To avoid too long dictionaries -$active = 1; - -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); -$page = GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 -$offset = $listlimit * $page; -$pageprev = $page - 1; -$pagenext = $page + 1; -// TODO: sorting, filtering, paginating +// column definition +$TVisibleColumn = array( + 'rate.date_sync' + => array('callback' => 'Date'), + 'rate.rate' + => array('callback' => 'Number'), + 'currency.code' + => array('callback' => 'CurrencyCode'), + // 'rate.entity' + // => array('callback' => 'Entity'), +); /* * Actions */ - -_handleActions($db); +_completeColumns($db, $TVisibleColumn); +_handleActions($db, $TVisibleColumn); exit; -function _handleActions($db) { +function _handleActions($db, $TVisibleColumn) { + global $langs; $action = GETPOST('action', 'alpha'); if (empty($action)) $action = 'view'; $callbackName = '_action' . _camel($action); if (!function_exists($callbackName)) { - setEventMessages('UnknownAction', array(), 'errors'); + setEventMessages($langs->trans('UnknownAction', $action), array(), 'errors'); header('Location: ' . $_SERVER['PHP_SELF']); exit; } - call_user_func($callbackName, $db); + call_user_func($callbackName, $db, $TVisibleColumn); } /** * @param DoliDB $db + * @param array $TVisibleColumn * @param string $mode * @param int|null $targetId ID of the row targeted for edition, deletion, etc. */ -function _mainView($db, $mode='view', $targetId=NULL) { +function _mainView($db, $TVisibleColumn, $mode='view', $targetId=NULL) { global $langs; $title = $langs->trans('CurrencyRateSetup'); $limit = 123; - // column definition - $TVisibleColumn = array( - 'rate.date_sync' - => array('callback' => 'Date'), - 'rate.rate' - => array('callback' => 'Number'), - 'currency.code' - => array('callback' => 'CurrencyCode'), -// 'rate.entity' -// => array('callback' => 'Entity'), - ); - foreach ($TVisibleColumn as $colSelect => &$colParam) { $colParam['name'] = _columnAlias($colSelect); } - unset($colParam); + $TSQLFilter = array(); + foreach ($TVisibleColumn as $colSelect => $colParam) { + if (isset($colParam['filter_value']) && !empty($colParam['filter_value'])) { + $cbName = '_getSQLFilter' . ucfirst($colParam['callback']); + if (function_exists($cbName)) { + $sqlFilter = call_user_func($cbName, $db, $colParam); + } else { + $sqlFilter = ' AND ' . $colParam['name'] . ' = ' + . '"' . $db->escape($colParam['filter_value']) . '"'; + } + $TSQLFilter[] = $sqlFilter; + } + } $sql = /** @lang SQL */ 'SELECT rate.rowid, ' . join(', ', array_keys($TVisibleColumn)) . ' FROM ' . MAIN_DB_PREFIX . 'multicurrency_rate rate' . ' LEFT JOIN ' . MAIN_DB_PREFIX . 'multicurrency currency ON rate.fk_multicurrency = currency.rowid' . ' WHERE rate.entity IN (' . getEntity('multicurrency') . ')' + . (count($TSQLFilter) ? join('', $TSQLFilter) : '') . ' ORDER BY rate.date_sync DESC' . ' LIMIT ' . intval($limit); $resql = $db->query($sql); @@ -159,32 +149,22 @@ function _mainView($db, $mode='view', $targetId=NULL) { . ''; - // En-têtes de colonnes - echo ''; - echo ''; - foreach ($TVisibleColumn as $colSelect => $colParam) { - echo ''; - echo $langs->trans('Multicurrency' . _camel(ucfirst($colParam['name']))); - echo ''; - } - echo ''; - echo ''; - // Formulaire des filtres de recherche - echo ''; + echo ''; + echo ''; foreach ($TVisibleColumn as $colSelect => $colParam) { - echo ''; + echo ''; echo _getCellContent( - GETPOST('search_' . $colParam['name']), + $colParam['filter_value'], $colParam, 'search', 'form-filter' ); echo ''; } - echo '' + echo '' . '
' - . '' . '