diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php
index 89765c55941..1f072db3cbb 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,35 +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');
-$search_active = GETPOST('search_active', '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
@@ -671,6 +676,7 @@ $localtax_typeList = array(
);
+
/*
* Actions
*/
@@ -748,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';
}
@@ -1000,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
@@ -1170,7 +1183,6 @@ if (empty($reshook)) {
*/
$form = new Form($db);
-$formadmin = new FormAdmin($db);
$title = $langs->trans("DictionarySetup");
@@ -1191,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;
}
@@ -1230,14 +1236,17 @@ if ($action == 'delete') {
// Show a dictionary
if ($id > 0) {
// Complete search values request with sort criteria
- $sql = $tabsql[$id];
+ $sqlfields = $tabsql[$id];
+ $tablecode = '';
$tableprefix = '';
- $tableprefixarray = array(28 => 'h.', 7 => 'a.', 32 => 'a.', 3 => 'r.', 8 => 't.', 10 => 't.', 1 => 'f.', 2 => 'd.', 14 => 'd.');
+ $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])) {
- $tableprefix = $tableprefixarray[$id];
+ $tablecode = $tableprefixarray[$id];
+ $tableprefix = preg_replace('/\..*$/', '.', $tablecode);
}
+ $sql = $sqlfields;
if (!preg_match('/ WHERE /', $sql)) {
$sql .= " WHERE 1 = 1";
}
@@ -1245,13 +1254,35 @@ if ($id > 0) {
$sql .= " AND c.rowid = ".((int) $search_country_id);
}
if ($search_code != '') {
- $sql .= natural_search($tableprefix."code_iso", $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) {
// If sort order is "country", we use country_code instead
@@ -1267,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])) {
@@ -1280,330 +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 "||||