diff --git a/.github/workflows/phpcsfixer.yml.disabled b/.github/workflows/phpcsfixer.yml.disabled
index 89de2dc4539..959ba5ad801 100644
--- a/.github/workflows/phpcsfixer.yml.disabled
+++ b/.github/workflows/phpcsfixer.yml.disabled
@@ -60,3 +60,4 @@ jobs:
#committer_email: eldy@destailleur.fr
message: 'PHP CS fixer github action'
add: '*.php'
+
diff --git a/.travis.yml b/.travis.yml
index 54feb351933..0450f41de81 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -325,22 +325,24 @@ script:
echo
- |
- echo "Checking coding style (only for Pull Requests builds and 1 version to not overload travis and avoid duplicate tests)"
+ echo "Checking coding style (only for 1 version to not overload travis and avoid duplicate tests)"
# Ensure we catch errors
set -e
# Exclusions are defined in the ruleset.xml file
- if [ "$TRAVIS_PULL_REQUEST" = "false" ] && [ "$TRAVIS_PHP_VERSION" = "8.1" ]; then
+ #if [ "$TRAVIS_PULL_REQUEST" = "false" ] && [ "$TRAVIS_PHP_VERSION" = "8.1" ]; then
+ if [ "$TRAVIS_PHP_VERSION" = "8.1" ]; then
phpcs -s -p -d memory_limit=-1 --extensions=php --colors --tab-width=4 --standard=dev/setup/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true .;
fi
set +e
echo
- |
- echo "Checking missing debug"
+ echo "Checking missing debug (only for 1 version to not overload travis and avoid duplicate tests)"
# Ensure we catch errors
set -e
# Exclusions are defined in the ruleset.xml file
- if [ "$TRAVIS_PULL_REQUEST" = "false" ] && [ "$TRAVIS_PHP_VERSION" = "8.1" ]; then
+ #if [ "$TRAVIS_PULL_REQUEST" = "false" ] && [ "$TRAVIS_PHP_VERSION" = "8.1" ]; then
+ if [ "$TRAVIS_PHP_VERSION" = "8.1" ]; then
var-dump-check --extensions php --tracy --exclude htdocs/includes --exclude test/ --exclude htdocs/public/test/ --exclude htdocs/core/lib/functions.lib.php .
fi
set +e
diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php
index fb306b9b257..7dac8f9d440 100644
--- a/htdocs/admin/dict.php
+++ b/htdocs/admin/dict.php
@@ -54,6 +54,38 @@ $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', 'class="size15x"');
+$actl[1] = img_picto($langs->trans("Activated"), 'switch_on', 'class="size15x"');
+
+// Load variable for pagination
+$listoffset = GETPOST('listoffset');
+$listlimit = GETPOST('listlimit') > 0 ?GETPOST('listlimit') : 1000; // To avoid too long dictionaries
+$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')) {
+ // If $page is not defined, or '' or -1 or if we click on clear filters
+ $page = 0;
+}
+$offset = $listlimit * $page;
+$pageprev = $page - 1;
+$pagenext = $page + 1;
+
+$search_country_id = GETPOST('search_country_id', 'int');
+$search_code = GETPOST('search_code', 'alpha');
+$search_active = GETPOST('search_active', 'alpha');
+
+// Special case to set a default value for country according to dictionary
+if (!GETPOSTISSET('search_country_id') && $search_country_id == '' && ($id == 2 || $id == 3 || $id == 10)) { // Not a so good idea to force on current country for all dictionaries. Some tables have entries that are for all countries, we must be able to see them, so this is done for dedicated dictionaries only.
+ $search_country_id = $mysoc->country_id;
+}
+
+// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
+$hookmanager->initHooks(array('admin', 'dictionaryadmin'));
+
$allowed = $user->admin;
if ($id == 7 && $user->hasRight('accounting', 'chartofaccount')) {
$allowed = 1; // Tax page allowed to manager of chart account
@@ -68,34 +100,8 @@ if (!$allowed) {
accessforbidden();
}
-$acts = array(); $actl = array();
-$acts[0] = "activate";
-$acts[1] = "disable";
-$actl[0] = img_picto($langs->trans("Disabled"), 'switch_off', 'class="size15x"');
-$actl[1] = img_picto($langs->trans("Activated"), 'switch_on', 'class="size15x"');
+$permissiontoadd = $allowed;
-$listoffset = GETPOST('listoffset');
-$listlimit = GETPOST('listlimit') > 0 ?GETPOST('listlimit') : 1000; // To avoid too long dictionaries
-$active = 1;
-
-$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 = $listlimit * $page;
-$pageprev = $page - 1;
-$pagenext = $page + 1;
-
-$search_country_id = GETPOST('search_country_id', 'int');
-if (!GETPOSTISSET('search_country_id') && $search_country_id == '' && ($id == 2 || $id == 3 || $id == 10)) { // Not a so good idea to force on current country for all dictionaries. Some tables have entries that are for all countries, we must be able to see them, so this is done for dedicated dictionaries only.
- $search_country_id = $mysoc->country_id;
-}
-$search_code = GETPOST('search_code', 'alpha');
-
-// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
-$hookmanager->initHooks(array('admin', 'dictionaryadmin'));
// This page is a generic page to edit dictionaries
// Put here declaration of dictionaries properties
@@ -201,7 +207,7 @@ $tablib[44] = "DictionaryAssetDisposalType";
$tabsql = array();
$tabsql[1] = "SELECT f.rowid as rowid, f.code, f.libelle, c.code as country_code, c.label as country, f.active FROM ".MAIN_DB_PREFIX."c_forme_juridique as f, ".MAIN_DB_PREFIX."c_country as c WHERE f.fk_pays=c.rowid";
$tabsql[2] = "SELECT d.rowid as rowid, d.code_departement as code, d.nom as libelle, d.fk_region as region_id, r.nom as region, c.code as country_code, c.label as country, d.active FROM ".MAIN_DB_PREFIX."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_country as c WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid and r.active=1 and c.active=1";
-$tabsql[3] = "SELECT r.rowid as rowid, r.code_region as state_code, r.nom as libelle, r.fk_pays as country_id, c.code as country_code, c.label as country, r.active FROM ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_country as c WHERE r.fk_pays=c.rowid and c.active=1";
+$tabsql[3] = "SELECT r.rowid as rowid, r.code_region as code, r.nom as libelle, r.fk_pays as country_id, c.code as country_code, c.label as country, r.active FROM ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_country as c WHERE r.fk_pays=c.rowid and c.active=1";
$tabsql[4] = "SELECT c.rowid as rowid, c.code, c.label, c.active, c.favorite, c.eec FROM ".MAIN_DB_PREFIX."c_country AS c";
$tabsql[5] = "SELECT c.rowid as rowid, c.code as code, c.label, c.active FROM ".MAIN_DB_PREFIX."c_civility AS c";
$tabsql[6] = "SELECT a.id as rowid, a.code as code, a.libelle AS libelle, a.type, a.active, a.module, a.color, a.position FROM ".MAIN_DB_PREFIX."c_actioncomm AS a";
@@ -670,6 +676,7 @@ $localtax_typeList = array(
);
+
/*
* Actions
*/
@@ -702,6 +709,7 @@ if ($reshook < 0) {
if (GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter_x', 'alpha')) {
$search_country_id = '';
$search_code = '';
+ $search_active = '';
}
if (empty($reshook)) {
@@ -746,9 +754,9 @@ if (empty($reshook)) {
&& ($id != 10 || ($value != 'code' && $value != 'note')) // Field code and note is not mandatory for dictionary table 10
)
) {
- $ok = 0;
- $fieldnamekey = $value;
- // We take translate key of field
+ $ok = 0;
+ $fieldnamekey = $value;
+ // We take translate key of field
if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) {
$fieldnamekey = 'Label';
}
@@ -823,7 +831,7 @@ if (empty($reshook)) {
setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities("Country")), null, 'errors');
}
}
- if (($id == 3 || $id == 42) && !is_numeric(GETPOST("code"))) {
+ if (($id == 3 || $id == 42) && !is_numeric(GETPOST("code")) && GETPOST('actionadd')) {
$ok = 0;
setEventMessages($langs->transnoentities("ErrorFieldMustBeANumeric", $langs->transnoentities("Code")), null, 'errors');
}
@@ -998,6 +1006,13 @@ if (empty($reshook)) {
setEventMessages($db->error(), null, 'errors');
}
}
+
+ if (!$ok && GETPOST('actionadd')) {
+ $action = 'create';
+ }
+ if (!$ok && GETPOST('actionmodify')) {
+ $action = 'edit';
+ }
}
if ($action == 'confirm_delete' && $confirm == 'yes') { // delete
@@ -1168,7 +1183,6 @@ if (empty($reshook)) {
*/
$form = new Form($db);
-$formadmin = new FormAdmin($db);
$title = $langs->trans("DictionarySetup");
@@ -1189,22 +1203,16 @@ if ($id == 7 && GETPOST('from') == 'accountancy') {
$titlepicto = 'accountancy';
}
-print load_fiche_titre($title, $linkback, $titlepicto);
-
-if (empty($id)) {
- print ''.$langs->trans("DictionaryDesc");
- print " ".$langs->trans("OnlyActiveElementsAreShown")."
\n";
- print '
';
-}
-
-
$param = '&id='.urlencode($id);
-if ($search_country_id > 0) {
- $param .= '&search_country_id='.urlencode($search_country_id);
+if ($search_country_id || GETPOSTISSET('page') || GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter_x', 'alpha')) {
+ $param .= '&search_country_id='.urlencode($search_country_id ? $search_country_id : -1);
}
if ($search_code != '') {
$param .= '&search_code='.urlencode($search_code);
}
+if ($search_active != '') {
+ $param .= '&search_active='.urlencode($search_active);
+}
if ($entity != '') {
$param .= '&entity='.(int) $entity;
}
@@ -1225,37 +1233,55 @@ if ($action == 'delete') {
print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page ? 'page='.$page.'&' : '').'rowid='.urlencode($rowid).'&code='.urlencode($code).$paramwithsearch, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete', '', 0, 1);
}
-/*
- * Show a dictionary
- */
+// Show a dictionary
if ($id > 0) {
// Complete search values request with sort criteria
- $sql = $tabsql[$id];
+ $sqlfields = $tabsql[$id];
+ $tablecode = '';
+ $tableprefix = '';
+ $tableprefixarray = array(9 => 'code_iso', 28 => 'h.code', 7 => 'a.code', 32 => 'a.code', 3 => 'r.code_region', 8 => 't.code', 10 => 't.code', 1 => 'f.code', 2 => 'd.code_departement', 14 => 'e.code');
+ if (!empty($tableprefixarray[$id])) {
+ $tablecode = $tableprefixarray[$id];
+ $tableprefix = preg_replace('/\..*$/', '.', $tablecode);
+ }
+
+ $sql = $sqlfields;
if (!preg_match('/ WHERE /', $sql)) {
$sql .= " WHERE 1 = 1";
}
if ($search_country_id > 0) {
$sql .= " AND c.rowid = ".((int) $search_country_id);
}
- if ($search_code != '' && $id == 9) {
- $sql .= natural_search("code_iso", $search_code);
- } elseif ($search_code != '' && $id == 28) {
- $sql .= natural_search("h.code", $search_code);
- } elseif ($search_code != '' && ($id == 7 || $id == 32)) {
- $sql .= natural_search("a.code", $search_code);
- } elseif ($search_code != '' && $id == 3) {
- $sql .= natural_search("r.code_region", $search_code);
- } elseif ($search_code != '' && ($id == 8 || $id == 10)) {
- $sql .= natural_search("t.code", $search_code);
- } elseif ($search_code != '' && $id == 1) {
- $sql .= natural_search("f.code", $search_code);
- } elseif ($search_code != '' && $id == 2) {
- $sql .= natural_search("d.code_departement", $search_code);
- } elseif ($search_code != '' && $id == 14) {
- $sql .= natural_search("e.code", $search_code);
- } elseif ($search_code != '' && $id != 9) {
- $sql .= natural_search("code", $search_code);
+ if ($search_code != '') {
+ $sql .= natural_search($tablecode, $search_code);
+ }
+ if ($search_active == 'yes') {
+ $sql .= " AND ".$tableprefix."active = 1";
+ } elseif ($search_active == 'no') {
+ $sql .= " AND ".$tableprefix."active = 0";
+ }
+ //print $sql;
+
+ // Count total nb of records
+ $nbtotalofrecords = '';
+ if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
+ /* The fast and low memory method to get and count full list converts the sql into a sql count */
+ $sqlforcount = preg_replace('/^.*\sFROM\s/', 'SELECT COUNT(*) as nbtotalofrecords FROM ', $sql);
+ $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
+ $resql = $db->query($sqlforcount);
+ if ($resql) {
+ $objforcount = $db->fetch_object($resql);
+ $nbtotalofrecords = $objforcount->nbtotalofrecords;
+ } else {
+ dol_print_error($db);
+ }
+
+ if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
+ $page = 0;
+ $offset = 0;
+ }
+ $db->free($resql);
}
if ($sortfield) {
@@ -1272,7 +1298,16 @@ if ($id > 0) {
$sql .= " ORDER BY ";
}
$sql .= $tabsqlsort[$id];
+
$sql .= $db->plimit($listlimit + 1, $offset);
+
+ $resql = $db->query($sql);
+ if (!$resql) {
+ dol_print_error($db);
+ exit;
+ }
+ $num = $db->num_rows($resql);
+
//print $sql;
if (empty($tabfield[$id])) {
@@ -1285,327 +1320,12 @@ if ($id > 0) {
print '';
print '';
+ // Special warning for VAT dictionary
if ($id == 10 && empty($conf->global->FACTURE_TVAOPTION)) {
print info_admin($langs->trans("VATIsUsedIsOff", $langs->transnoentities("Setup"), $langs->transnoentities("CompanyFoundation")));
print "
\n";
}
- // Form to add a new line
- if ($tabname[$id]) {
- $withentity = null;
-
- $fieldlist = explode(',', $tabfield[$id]);
-
- print '
| '; continue; - } // For region page, we do not show the country input - $valuetoshow = $langs->trans("Country"); - } - if ($value == 'recuperableonly') { - $valuetoshow = $langs->trans("NPR"); $class = "center"; - } - if ($value == 'nbjour') { - $valuetoshow = $langs->trans("NbOfDays"); - $class = 'right'; - } - if ($value == 'type_cdr') { - $valuetoshow = $langs->trans("AtEndOfMonth"); $class = "center"; - } - if ($value == 'decalage') { - $valuetoshow = $langs->trans("Offset"); - $class = 'right'; - } - if ($value == 'width' || $value == 'nx') { - $valuetoshow = $langs->trans("Width"); - } - if ($value == 'height' || $value == 'ny') { - $valuetoshow = $langs->trans("Height"); - } - if ($value == 'unit' || $value == 'metric') { - $valuetoshow = $langs->trans("MeasuringUnit"); - } - if ($value == 'region_id' || $value == 'country_id') { - $valuetoshow = ''; - } - if ($value == 'accountancy_code') { - $valuetoshow = $langs->trans("AccountancyCode"); - } - if ($value == 'accountancy_code_sell') { - $valuetoshow = $langs->trans("AccountancyCodeSell"); - } - if ($value == 'accountancy_code_buy') { - $valuetoshow = $langs->trans("AccountancyCodeBuy"); - } - if ($value == 'pcg_version' || $value == 'fk_pcg_version') { - $valuetoshow = $langs->trans("Pcg_version"); - } - if ($value == 'account_parent') { - $valuetoshow = $langs->trans("Accountparent"); - } - if ($value == 'pcg_type') { - $valuetoshow = $langs->trans("Pcg_type"); - } - if ($value == 'pcg_subtype') { - $valuetoshow = $langs->trans("Pcg_subtype"); - } - if ($value == 'sortorder') { - $valuetoshow = $langs->trans("SortOrder"); - $class = 'center'; - } - if ($value == 'short_label') { - $valuetoshow = $langs->trans("ShortLabel"); - } - if ($value == 'fk_parent') { - $valuetoshow = $langs->trans("ParentID"); $class = 'center'; - } - if ($value == 'range_account') { - $valuetoshow = $langs->trans("Range"); - } - if ($value == 'sens') { - $valuetoshow = $langs->trans("Sens"); - } - if ($value == 'category_type') { - $valuetoshow = $langs->trans("Calculated"); - } - if ($value == 'formula') { - $valuetoshow = $langs->trans("Formula"); - } - if ($value == 'paper_size') { - $valuetoshow = $langs->trans("PaperSize"); - } - if ($value == 'orientation') { - $valuetoshow = $langs->trans("Orientation"); - } - if ($value == 'leftmargin') { - $valuetoshow = $langs->trans("LeftMargin"); - } - if ($value == 'topmargin') { - $valuetoshow = $langs->trans("TopMargin"); - } - if ($value == 'spacex') { - $valuetoshow = $langs->trans("SpaceX"); - } - if ($value == 'spacey') { - $valuetoshow = $langs->trans("SpaceY"); - } - if ($value == 'font_size') { - $valuetoshow = $langs->trans("FontSize"); - } - if ($value == 'custom_x') { - $valuetoshow = $langs->trans("CustomX"); - } - if ($value == 'custom_y') { - $valuetoshow = $langs->trans("CustomY"); - } - if ($value == 'percent') { - $valuetoshow = $langs->trans("Percentage"); - } - if ($value == 'affect') { - $valuetoshow = $langs->trans("WithCounter"); - } - if ($value == 'delay') { - $valuetoshow = $langs->trans("NoticePeriod"); - } - if ($value == 'newbymonth') { - $valuetoshow = $langs->trans("NewByMonth"); - } - if ($value == 'fk_tva') { - $valuetoshow = $langs->trans("VAT"); - } - if ($value == 'range_ik') { - $valuetoshow = $langs->trans("RangeIk"); - } - if ($value == 'fk_c_exp_tax_cat') { - $valuetoshow = $langs->trans("CarCategory"); - } - if ($value == 'revenuestamp_type') { - $valuetoshow = $langs->trans('TypeOfRevenueStamp'); - } - if ($value == 'use_default') { - $valuetoshow = $langs->trans('Default'); $class = 'center'; - } - if ($value == 'unit_type') { - $valuetoshow = $langs->trans('TypeOfUnit'); - } - if ($value == 'public' && $tablib[$id] == 'TicketDictCategory') { - $valuetoshow = $langs->trans('TicketGroupIsPublic'); $class = 'center'; - } - if ($value == 'block_if_negative') { - $valuetoshow = $langs->trans('BlockHolidayIfNegative'); - } - if ($value == 'type_duration') { - $valuetoshow = $langs->trans('Unit'); - } - - if ($id == 2) { // Special case for state page - if ($value == 'region_id') { - $valuetoshow = ' '; $showfield = 1; - } - if ($value == 'region') { - $valuetoshow = $langs->trans("Country").'/'.$langs->trans("Region"); $showfield = 1; - } - } - - if ($valuetoshow != '') { - $tooltiphelp = (isset($tabcomplete[$tabname[$id]]['help'][$value]) ? $tabcomplete[$tabname[$id]]['help'][$value] : ''); - - $tdsoffields .= ' | '; - if ($tooltiphelp && preg_match('/^http(s*):/i', $tooltiphelp)) { - $tdsoffields .= ''.$valuetoshow.' '.img_help(1, $valuetoshow).''; - } elseif ($tooltiphelp) { - $tdsoffields .= $form->textwithpicto($valuetoshow, $tooltiphelp); - } else { - $tdsoffields .= $valuetoshow; - } - $tdsoffields .= ' | '; - } - } - - if ($id == 4) { - $tdsoffields .= ''; - $tdsoffields .= ' | '; - } - $tdsoffields .= ' | '; - $tdsoffields .= ''; - if (!is_null($withentity)) { - $tdsoffields .= ''; - } - $tdsoffields .= ' | '; - $tdsoffields .= ''; - $tdsoffields .= ' | '; - $tdsoffields .= ' |
|---|---|---|---|---|---|---|
| '; - print ' | '; - } - print ' | '; - if ($action != 'edit') { - print ''; - } else { - print ''; - } - print ' | '; - - print "||||