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'); $entity = GETPOST('entity', 'int');
$code = GETPOST('code', 'alpha'); $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; $allowed = $user->admin;
if ($id == 7 && $user->hasRight('accounting', 'chartofaccount')) { if ($id == 7 && $user->hasRight('accounting', 'chartofaccount')) {
$allowed = 1; // Tax page allowed to manager of chart account $allowed = 1; // Tax page allowed to manager of chart account
@@ -68,35 +100,8 @@ if (!$allowed) {
accessforbidden(); accessforbidden();
} }
$acts = array(); $actl = array(); $permissiontoadd = $allowed;
$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"');
$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 // This page is a generic page to edit dictionaries
// Put here declaration of dictionaries properties // Put here declaration of dictionaries properties
@@ -671,6 +676,7 @@ $localtax_typeList = array(
); );
/* /*
* Actions * 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 && ($id != 10 || ($value != 'code' && $value != 'note')) // Field code and note is not mandatory for dictionary table 10
) )
) { ) {
$ok = 0; $ok = 0;
$fieldnamekey = $value; $fieldnamekey = $value;
// We take translate key of field // We take translate key of field
if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) { if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) {
$fieldnamekey = 'Label'; $fieldnamekey = 'Label';
} }
@@ -1000,6 +1006,13 @@ if (empty($reshook)) {
setEventMessages($db->error(), null, 'errors'); setEventMessages($db->error(), null, 'errors');
} }
} }
if (!$ok && GETPOST('actionadd')) {
$action = 'create';
}
if (!$ok && GETPOST('actionmodify')) {
$action = 'edit';
}
} }
if ($action == 'confirm_delete' && $confirm == 'yes') { // delete if ($action == 'confirm_delete' && $confirm == 'yes') { // delete
@@ -1170,7 +1183,6 @@ if (empty($reshook)) {
*/ */
$form = new Form($db); $form = new Form($db);
$formadmin = new FormAdmin($db);
$title = $langs->trans("DictionarySetup"); $title = $langs->trans("DictionarySetup");
@@ -1191,22 +1203,16 @@ if ($id == 7 && GETPOST('from') == 'accountancy') {
$titlepicto = '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); $param = '&id='.urlencode($id);
if ($search_country_id > 0) { 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); $param .= '&search_country_id='.urlencode($search_country_id ? $search_country_id : -1);
} }
if ($search_code != '') { if ($search_code != '') {
$param .= '&search_code='.urlencode($search_code); $param .= '&search_code='.urlencode($search_code);
} }
if ($search_active != '') {
$param .= '&search_active='.urlencode($search_active);
}
if ($entity != '') { if ($entity != '') {
$param .= '&entity='.(int) $entity; $param .= '&entity='.(int) $entity;
} }
@@ -1230,14 +1236,17 @@ if ($action == 'delete') {
// Show a dictionary // Show a dictionary
if ($id > 0) { if ($id > 0) {
// Complete search values request with sort criteria // Complete search values request with sort criteria
$sql = $tabsql[$id]; $sqlfields = $tabsql[$id];
$tablecode = '';
$tableprefix = ''; $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])) { if (!empty($tableprefixarray[$id])) {
$tableprefix = $tableprefixarray[$id]; $tablecode = $tableprefixarray[$id];
$tableprefix = preg_replace('/\..*$/', '.', $tablecode);
} }
$sql = $sqlfields;
if (!preg_match('/ WHERE /', $sql)) { if (!preg_match('/ WHERE /', $sql)) {
$sql .= " WHERE 1 = 1"; $sql .= " WHERE 1 = 1";
} }
@@ -1245,13 +1254,35 @@ if ($id > 0) {
$sql .= " AND c.rowid = ".((int) $search_country_id); $sql .= " AND c.rowid = ".((int) $search_country_id);
} }
if ($search_code != '') { if ($search_code != '') {
$sql .= natural_search($tableprefix."code_iso", $search_code); $sql .= natural_search($tablecode, $search_code);
} }
if ($search_active == 'yes') { if ($search_active == 'yes') {
$sql .= " AND ".$tableprefix."active = 1"; $sql .= " AND ".$tableprefix."active = 1";
} elseif ($search_active == 'no') { } elseif ($search_active == 'no') {
$sql .= " AND ".$tableprefix."active = 0"; $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 ($sortfield) {
// If sort order is "country", we use country_code instead // If sort order is "country", we use country_code instead
@@ -1267,7 +1298,16 @@ if ($id > 0) {
$sql .= " ORDER BY "; $sql .= " ORDER BY ";
} }
$sql .= $tabsqlsort[$id]; $sql .= $tabsqlsort[$id];
$sql .= $db->plimit($listlimit + 1, $offset); $sql .= $db->plimit($listlimit + 1, $offset);
$resql = $db->query($sql);
if (!$resql) {
dol_print_error($db);
exit;
}
$num = $db->num_rows($resql);
//print $sql; //print $sql;
if (empty($tabfield[$id])) { if (empty($tabfield[$id])) {
@@ -1280,330 +1320,12 @@ if ($id > 0) {
print '<input type="hidden" name="token" value="'.newToken().'">'; print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">'; 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)) { if ($id == 10 && empty($conf->global->FACTURE_TVAOPTION)) {
print info_admin($langs->trans("VATIsUsedIsOff", $langs->transnoentities("Setup"), $langs->transnoentities("CompanyFoundation"))); print info_admin($langs->trans("VATIsUsedIsOff", $langs->transnoentities("Setup"), $langs->transnoentities("CompanyFoundation")));
print "<br>\n"; print "<br>\n";
} }
// Form to add a new line
if ($tabname[$id]) {
$withentity = null;
$fieldlist = explode(',', $tabfield[$id]);
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
// Line for title
print '<!-- line title to add new entry -->';
$tdsoffields = '<tr class="liste_titre">';
foreach ($fieldlist as $field => $value) {
if ($value == 'entity') {
$withentity = getEntity($tabname[$id]);
continue;
}
// Define field friendly name from its technical name
$valuetoshow = ucfirst($value); // Par defaut
$valuetoshow = $langs->trans($valuetoshow); // try to translate
$class = '';
if ($value == 'pos') {
$valuetoshow = $langs->trans("Position"); $class = 'right';
}
if ($value == 'source') {
$valuetoshow = $langs->trans("Contact");
}
if ($value == 'price') {
$valuetoshow = $langs->trans("PriceUHT");
}
if ($value == 'taux') {
if ($tabname[$id] != "c_revenuestamp") {
$valuetoshow = $langs->trans("Rate");
} else {
$valuetoshow = $langs->trans("Amount");
}
$class = 'center';
}
if ($value == 'localtax1_type') {
$valuetoshow = $langs->trans("UseLocalTax")." 2"; $class = "center"; $sortable = 0;
}
if ($value == 'localtax1') {
$valuetoshow = $langs->trans("RateOfTaxN", '2'); $class = "center";
}
if ($value == 'localtax2_type') {
$valuetoshow = $langs->trans("UseLocalTax")." 3"; $class = "center"; $sortable = 0;
}
if ($value == 'localtax2') {
$valuetoshow = $langs->trans("RateOfTaxN", '3'); $class = "center";
}
if ($value == 'organization') {
$valuetoshow = $langs->trans("Organization");
}
if ($value == 'lang') {
$valuetoshow = $langs->trans("Language");
}
if ($value == 'type') {
if ($tabname[$id] == "c_paiement") {
$valuetoshow = $form->textwithtooltip($langs->trans("Type"), $langs->trans("TypePaymentDesc"), 2, 1, img_help(1, ''));
} else {
$valuetoshow = $langs->trans("Type");
}
}
if ($value == 'code') {
$valuetoshow = $langs->trans("Code"); $class = 'maxwidth100';
}
if ($value == 'libelle' || $value == 'label') {
$valuetoshow = $form->textwithtooltip($langs->trans("Label"), $langs->trans("LabelUsedByDefault"), 2, 1, img_help(1, ''));
}
if ($value == 'libelle_facture') {
$valuetoshow = $form->textwithtooltip($langs->trans("LabelOnDocuments"), $langs->trans("LabelUsedByDefault"), 2, 1, img_help(1, ''));
}
if ($value == 'deposit_percent') {
$valuetoshow = $langs->trans('DepositPercent');
$class = 'right';
}
if ($value == 'country') {
if (in_array('region_id', $fieldlist)) {
//print '<td>&nbsp;</td>';
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 = '&nbsp;';
$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 .= '<th'.($class ? ' class="'.$class.'"' : '').'>';
if ($tooltiphelp && preg_match('/^http(s*):/i', $tooltiphelp)) {
$tdsoffields .= '<a href="'.$tooltiphelp.'" target="_blank">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
} elseif ($tooltiphelp) {
$tdsoffields .= $form->textwithpicto($valuetoshow, $tooltiphelp);
} else {
$tdsoffields .= $valuetoshow;
}
$tdsoffields .= '</th>';
}
}
if ($id == 4) {
$tdsoffields .= '<th></th>';
$tdsoffields .= '<th></th>';
}
$tdsoffields .= '<th>';
$tdsoffields .= '<input type="hidden" name="id" value="'.$id.'">';
if (!is_null($withentity)) {
$tdsoffields .= '<input type="hidden" name="entity" value="'.$withentity.'">';
}
$tdsoffields .= '</th>';
$tdsoffields .= '<th style="min-width: 26px;"></th>';
$tdsoffields .= '<th style="min-width: 26px;"></th>';
$tdsoffields .= '</tr>';
print $tdsoffields;
// Line to enter new values
print '<!-- line input to add new entry -->';
print '<tr class="oddeven nodrag nodrop nohover">';
$obj = new stdClass();
// If data was already input, we define them in obj to populate input fields.
if (GETPOST('actionadd')) {
foreach ($fieldlist as $key => $val) {
if (GETPOST($val) != '') {
$obj->$val = GETPOST($val);
}
}
}
$tmpaction = 'create';
$parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
$reshook = $hookmanager->executeHooks('createDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
$error = $hookmanager->error; $errors = $hookmanager->errors;
if ($id == 3) {
unset($fieldlist[2]); // Remove field ??? if dictionary Regions
}
if (empty($reshook)) {
fieldList($fieldlist, $obj, $tabname[$id], 'add');
}
if ($id == 4) {
print '<td></td>';
print '<td></td>';
}
print '<td colspan="3" class="center">';
if ($action != 'edit') {
print '<input type="submit" class="button button-add small" name="actionadd" value="'.$langs->trans("Add").'">';
} else {
print '<input type="submit" class="button button-add small disabled" name="actionadd" value="'.$langs->trans("Add").'">';
}
print '</td>';
print "</tr>";
print '</table>';
print '</div>';
}
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 // List of available record in database
dol_syslog("htdocs/admin/dict", LOG_DEBUG); dol_syslog("htdocs/admin/dict", LOG_DEBUG);
@@ -1612,12 +1334,336 @@ if ($id > 0) {
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$i = 0; $i = 0;
// There is several pages $massactionbutton = $linkback;
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>'); $newcardbutton = '';
print '<div class="clearboth"></div>'; /*$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;
$fieldlist = explode(',', $tabfield[$id]);
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
// Line for title
print '<!-- line title to add new entry -->';
$tdsoffields = '<tr class="liste_titre">';
foreach ($fieldlist as $field => $value) {
if ($value == 'entity') {
$withentity = getEntity($tabname[$id]);
continue;
}
// Define field friendly name from its technical name
$valuetoshow = ucfirst($value); // Par defaut
$valuetoshow = $langs->trans($valuetoshow); // try to translate
$class = '';
if ($value == 'pos') {
$valuetoshow = $langs->trans("Position"); $class = 'right';
}
if ($value == 'source') {
$valuetoshow = $langs->trans("Contact");
}
if ($value == 'price') {
$valuetoshow = $langs->trans("PriceUHT");
}
if ($value == 'taux') {
if ($tabname[$id] != "c_revenuestamp") {
$valuetoshow = $langs->trans("Rate");
} else {
$valuetoshow = $langs->trans("Amount");
}
$class = 'center';
}
if ($value == 'localtax1_type') {
$valuetoshow = $langs->trans("UseLocalTax")." 2"; $class = "center"; $sortable = 0;
}
if ($value == 'localtax1') {
$valuetoshow = $langs->trans("RateOfTaxN", '2'); $class = "center";
}
if ($value == 'localtax2_type') {
$valuetoshow = $langs->trans("UseLocalTax")." 3"; $class = "center"; $sortable = 0;
}
if ($value == 'localtax2') {
$valuetoshow = $langs->trans("RateOfTaxN", '3'); $class = "center";
}
if ($value == 'organization') {
$valuetoshow = $langs->trans("Organization");
}
if ($value == 'lang') {
$valuetoshow = $langs->trans("Language");
}
if ($value == 'type') {
if ($tabname[$id] == "c_paiement") {
$valuetoshow = $form->textwithtooltip($langs->trans("Type"), $langs->trans("TypePaymentDesc"), 2, 1, img_help(1, ''));
} else {
$valuetoshow = $langs->trans("Type");
}
}
if ($value == 'code') {
$valuetoshow = $langs->trans("Code"); $class = 'maxwidth100';
}
if ($value == 'libelle' || $value == 'label') {
$valuetoshow = $form->textwithtooltip($langs->trans("Label"), $langs->trans("LabelUsedByDefault"), 2, 1, img_help(1, ''));
}
if ($value == 'libelle_facture') {
$valuetoshow = $form->textwithtooltip($langs->trans("LabelOnDocuments"), $langs->trans("LabelUsedByDefault"), 2, 1, img_help(1, ''));
}
if ($value == 'deposit_percent') {
$valuetoshow = $langs->trans('DepositPercent');
$class = 'right';
}
if ($value == 'country') {
if (in_array('region_id', $fieldlist)) {
//print '<td>&nbsp;</td>';
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 = '&nbsp;';
$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 .= '<th'.($class ? ' class="'.$class.'"' : '').'>';
if ($tooltiphelp && preg_match('/^http(s*):/i', $tooltiphelp)) {
$tdsoffields .= '<a href="'.$tooltiphelp.'" target="_blank">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
} elseif ($tooltiphelp) {
$tdsoffields .= $form->textwithpicto($valuetoshow, $tooltiphelp);
} else {
$tdsoffields .= $valuetoshow;
}
$tdsoffields .= '</th>';
}
}
if ($id == 4) {
$tdsoffields .= '<th></th>';
$tdsoffields .= '<th></th>';
}
$tdsoffields .= '<th>';
$tdsoffields .= '<input type="hidden" name="id" value="'.$id.'">';
if (!is_null($withentity)) {
$tdsoffields .= '<input type="hidden" name="entity" value="'.$withentity.'">';
}
$tdsoffields .= '</th>';
$tdsoffields .= '<th style="min-width: 26px;"></th>';
$tdsoffields .= '<th style="min-width: 26px;"></th>';
$tdsoffields .= '</tr>';
print $tdsoffields;
// Line to enter new values
print '<!-- line input to add new entry -->';
print '<tr class="oddeven nodrag nodrop nohover">';
$obj = new stdClass();
// If data was already input, we define them in obj to populate input fields.
if (GETPOST('actionadd')) {
foreach ($fieldlist as $key => $val) {
if (GETPOST($val) != '') {
$obj->$val = GETPOST($val);
}
}
}
$tmpaction = 'create';
$parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
$reshook = $hookmanager->executeHooks('createDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
$error = $hookmanager->error; $errors = $hookmanager->errors;
if ($id == 3) {
unset($fieldlist[2]); // Remove field ??? if dictionary Regions
}
if (empty($reshook)) {
fieldList($fieldlist, $obj, $tabname[$id], 'add');
}
if ($id == 4) {
print '<td></td>';
print '<td></td>';
}
print '<td colspan="3" class="center">';
if ($action != 'edit') {
print '<input type="submit" class="button button-add small" name="actionadd" value="'.$langs->trans("Add").'">';
} else {
print '<input type="submit" class="button button-add small disabled" name="actionadd" value="'.$langs->trans("Add").'">';
}
print '</td>';
print "</tr>";
print '</table>';
print '</div>';
}
print '</form>';
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')).'">';
} }
$filterfound = 0; $filterfound = 0;
foreach ($fieldlist as $field => $value) { foreach ($fieldlist as $field => $value) {
if ($value == 'entity') { if ($value == 'entity') {
@@ -1671,7 +1717,7 @@ if ($id > 0) {
if ($showfield) { if ($showfield) {
if ($value == 'country') { if ($value == 'country') {
print '<td class="liste_titre">'; 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>'; print '</td>';
$colspan++; $colspan++;
} elseif ($value == 'code') { } elseif ($value == 'code') {
@@ -2348,6 +2394,11 @@ if ($id > 0) {
/* /*
* Show list of dictionary to show * 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; $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 = '') 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; $savlimit = $limit;
$savtotalnboflines = $totalnboflines; $savtotalnboflines = $totalnboflines;