2
0
forked from Wavyzz/dolibarr

QUAL: Standardize code and look and feel for dictionaries

This commit is contained in:
Laurent Destailleur
2023-09-04 22:49:55 +02:00
parent 4f1f9ec455
commit f403558a8f
2 changed files with 423 additions and 372 deletions

View File

@@ -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
*/
@@ -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 '<span class="opacitymedium">'.$langs->trans("DictionaryDesc");
print " ".$langs->trans("OnlyActiveElementsAreShown")."<br>\n";
print '</span><br>';
}
$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,11 +1320,33 @@ if ($id > 0) {
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
// 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 "<br>\n";
}
// List of available record in database
dol_syslog("htdocs/admin/dict", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
$massactionbutton = $linkback;
$newcardbutton = '';
/*$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));
$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition'));
$newcardbutton .= dolGetButtonTitleSeparator();
*/
$newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/admin/dict.php?action=create'.$param.'&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'tools', 0, $newcardbutton, '', $listlimit, 1, 0, 1);
if ($action == 'create') {
// Form to add a new line
if ($tabname[$id]) {
$withentity = null;
@@ -1596,28 +1658,12 @@ if ($id > 0) {
print '</form>';
print '<br>';
print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
// List of available record in database
dol_syslog("htdocs/admin/dict", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
// There is several pages
if (($num > $listlimit) || $page) {
print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
print '<div class="clearboth"></div>';
}
$filterfound = 0;
foreach ($fieldlist as $field => $value) {
if ($value == 'entity') {
@@ -1671,7 +1717,7 @@ if ($id > 0) {
if ($showfield) {
if ($value == 'country') {
print '<td class="liste_titre">';
print $form->select_country($search_country_id, 'search_country_id', '', 28, 'minwidth100 maxwidth150 maxwidthonsmartphone');
print $form->select_country($search_country_id, 'search_country_id', '', 28, 'minwidth100 maxwidth150 maxwidthonsmartphone', '', '&nbsp;');
print '</td>';
$colspan++;
} elseif ($value == 'code') {
@@ -2348,6 +2394,11 @@ if ($id > 0) {
/*
* Show list of dictionary to show
*/
print load_fiche_titre($title, $linkback, $titlepicto);
print '<span class="opacitymedium">'.$langs->trans("DictionaryDesc");
print " ".$langs->trans("OnlyActiveElementsAreShown")."<br>\n";
print '</span><br>';
$lastlineisempty = false;

View File

@@ -5532,7 +5532,7 @@ function load_fiche_titre($titre, $morehtmlright = '', $picto = 'generic', $pict
*/
function print_barre_liste($titre, $page, $file, $options = '', $sortfield = '', $sortorder = '', $morehtmlcenter = '', $num = -1, $totalnboflines = '', $picto = 'generic', $pictoisfullpath = 0, $morehtmlright = '', $morecss = '', $limit = -1, $hideselectlimit = 0, $hidenavigation = 0, $pagenavastextinput = 0, $morehtmlrightbeforearrow = '')
{
global $conf, $langs;
global $conf;
$savlimit = $limit;
$savtotalnboflines = $totalnboflines;