From e3552e7e023b0d8bdc581692da3635bd3b376b82 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 16 Oct 2020 20:17:54 +0200 Subject: [PATCH] Clean code --- htdocs/admin/dict.php | 77 ++++++++++++-------- htdocs/comm/action/card.php | 12 +-- htdocs/core/class/html.formcompany.class.php | 3 +- htdocs/core/class/html.formprojet.class.php | 5 +- htdocs/core/modules/modTicket.class.php | 6 +- htdocs/langs/en_US/admin.lang | 2 + 6 files changed, 62 insertions(+), 43 deletions(-) diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index 803ba1823f1..0ee07aad230 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -534,7 +534,7 @@ $tabhelp[28] = array('affect'=>$langs->trans("FollowedByACounter"), 'delay'=>$la $tabhelp[29] = array('code'=>$langs->trans("EnterAnyCode"), 'percent'=>$langs->trans("OpportunityPercent"), 'position'=>$langs->trans("PositionIntoComboList")); $tabhelp[30] = array('code'=>$langs->trans("EnterAnyCode"), 'name'=>$langs->trans("LabelName"), 'paper_size'=>$langs->trans("LabelPaperSize")); //$tabhelp[31] = array('pcg_version'=>$langs->trans("EnterAnyCode")); -$tabhelp[32] = array('code'=>$langs->trans("EnterAnyCode"), 'dayrule'=>"Keep empty for a date defined with month and day (most common case).
Use a keyword like 'easter', 'eastermonday', ... for a date predefined by complex rules.", 'country'=>$langs->trans("EnterACountryOnlyIfSpecificToOneCountry"), 'year'=>$langs->trans("ZeroMeansEveryYear")); +$tabhelp[32] = array('code'=>$langs->trans("EnterAnyCode"), 'dayrule'=>"Keep empty for a date defined with month and day (most common case).
Use a keyword like 'easter', 'eastermonday', ... for a date predefined by complex rules.", 'country'=>$langs->trans("CountryIfSpecificToOneCountry"), 'year'=>$langs->trans("ZeroMeansEveryYear")); $tabhelp[33] = array('code'=>$langs->trans("EnterAnyCode")); $tabhelp[34] = array('code'=>$langs->trans("EnterAnyCode")); $tabhelp[35] = array(); @@ -1066,11 +1066,7 @@ if ($id) { // If sort order is "country", we use country_code instead if ($sortfield == 'country') $sortfield = 'country_code'; - $sql .= " ORDER BY ".$db->escape($sortfield); - if ($sortorder) - { - $sql .= " ".strtoupper($db->escape($sortorder)); - } + $sql .= $db->order($sortfield, $sortorder); $sql .= ", "; // Clear the required sort criteria for the tabsqlsort to be able to force it with selected value $tabsqlsort[$id] = preg_replace('/([a-z]+\.)?'.$sortfield.' '.$sortorder.',/i', '', $tabsqlsort[$id]); @@ -1111,7 +1107,7 @@ if ($id) print ''; // Line for title - print ''; + $tdsoffields = ''; foreach ($fieldlist as $field => $value) { if ($fieldlist[$field] == 'entity') { @@ -1192,7 +1188,8 @@ if ($id) if ($fieldlist[$field] == 'range_ik') { $valuetoshow = $langs->trans("RangeIk"); } if ($fieldlist[$field] == 'fk_c_exp_tax_cat') { $valuetoshow = $langs->trans("CarCategory"); } if ($fieldlist[$field] == 'revenuestamp_type') { $valuetoshow = $langs->trans('TypeOfRevenueStamp'); } - if ($fieldlist[$field] == 'use_default') { $valuetoshow = $langs->trans('Default'); } + if ($fieldlist[$field] == 'use_default') { $valuetoshow = $langs->trans('Default'); $class = 'center'; } + if ($fieldlist[$field] == 'unit_type') { $valuetoshow = $langs->trans('TypeOfUnit'); } if ($id == 2) // Special case for state page { @@ -1202,28 +1199,27 @@ if ($id) if ($valuetoshow != '') { - print ''; - if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) print ''.$valuetoshow.' '.img_help(1, $valuetoshow).''; - elseif (!empty($tabhelp[$id][$value])) print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]); - else print $valuetoshow; - print ''; + $tdsoffields .= ''; + if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) $tdsoffields .= ''.$valuetoshow.' '.img_help(1, $valuetoshow).''; + elseif (!empty($tabhelp[$id][$value])) $tdsoffields .= $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]); + else $tdsoffields .= $valuetoshow; + $tdsoffields .= ''; } if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') $alabelisused = 1; } - if ($id == 4) print ''; - print ''; + $tdsoffields .= ''; - print ''; - print ''; - print ''; + $tdsoffields .= ''; + $tdsoffields .= ''; + $tdsoffields .= ''; + $tdsoffields .= ''; + $tdsoffields .= ''; + + print $tdsoffields; - // Line to enter new values - print ''; - print ''; $obj = new stdClass(); // If data was already input, we define them in obj to populate input fields. @@ -1243,6 +1239,10 @@ if ($id) if ($id == 3) unset($fieldlist[2]); // Remove field ??? if dictionary Regions + // Line to enter new values + print ''; + print ''; + if (empty($reshook)) { fieldList($fieldlist, $obj, $tabname[$id], 'add'); @@ -1255,10 +1255,8 @@ if ($id) print ''; } print ''; - print ""; - $colspan = count($fieldlist) + 3; - if ($id == 4) $colspan++; + print ""; print '
'; - print ''; + if ($id == 4) $tdsoffields .= ''; + $tdsoffields .= ''; if (!is_null($withentity)) - print ''; - print '
'; print ''; @@ -1341,6 +1339,10 @@ if ($id) { if ($fieldlist[$field] == 'entity') continue; + if (in_array($value, array('label', 'libelle', 'libelle_facture')) && empty($tabhelp[$id][$value])) { + $tabhelp[$id][$value] = $langs->trans('LabelUsedByDefault'); + } + // Determines the name of the field in relation to the possible names // in data dictionaries $showfield = 1; // By defaut @@ -1365,7 +1367,8 @@ if ($id) if ($fieldlist[$field] == 'lang') { $valuetoshow = $langs->trans("Language"); } if ($fieldlist[$field] == 'type') { $valuetoshow = $langs->trans("Type"); } if ($fieldlist[$field] == 'code') { $valuetoshow = $langs->trans("Code"); } - if ($fieldlist[$field] == 'position') { $cssprefix = 'right '; } + if ($fieldlist[$field] == 'pos') { $cssprefix = 'right '; $valuetoshow = $langs->trans("Position"); } + if ($fieldlist[$field] == 'position') { $cssprefix = 'right '; $valuetoshow = $langs->trans("Position"); } if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') { $valuetoshow = $langs->trans("Label"); } if ($fieldlist[$field] == 'libelle_facture') { $valuetoshow = $langs->trans("LabelOnDocuments"); } if ($fieldlist[$field] == 'country') { $valuetoshow = $langs->trans("Country"); } @@ -1406,14 +1409,19 @@ if ($id) if ($fieldlist[$field] == 'range_ik') { $valuetoshow = $langs->trans("RangeIk"); } if ($fieldlist[$field] == 'fk_c_exp_tax_cat') { $valuetoshow = $langs->trans("CarCategory"); } if ($fieldlist[$field] == 'revenuestamp_type') { $valuetoshow = $langs->trans('TypeOfRevenueStamp'); } - if ($fieldlist[$field] == 'use_default') { $valuetoshow = $langs->trans('Default'); } + if ($fieldlist[$field] == 'use_default') { $valuetoshow = $langs->trans('Default'); $cssprefix = 'center '; } + if ($fieldlist[$field] == 'unit_type') { $valuetoshow = $langs->trans('TypeOfUnit'); } if ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') { $showfield = 0; } // Show field title if ($showfield) { - print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable ? $fieldlist[$field] : ''), ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, $cssprefix); + if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) $newvaluetoshow = ''.$valuetoshow.' '.img_help(1, $valuetoshow).''; + elseif (!empty($tabhelp[$id][$value])) $newvaluetoshow = $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]); + else $newvaluetoshow = $valuetoshow; + + print getTitleFieldOfList($newvaluetoshow, 0, $_SERVER["PHP_SELF"], ($sortable ? $fieldlist[$field] : ''), ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, $cssprefix); } } // Favorite - Only activated on country dictionary @@ -1635,6 +1643,8 @@ if ($id) if ($fieldlist[$field] == 'position') $class .= ' right'; if ($fieldlist[$field] == 'localtax1_type') $class .= ' nowrap'; if ($fieldlist[$field] == 'localtax2_type') $class .= ' nowrap'; + if ($fieldlist[$field] == 'pos') $class .= ' right'; + if ($fieldlist[$field] == 'use_default') $class .= ' center'; // Show value for field if ($showfield) print ''.$valuetoshow.''; } @@ -1981,7 +1991,12 @@ function fieldList($fieldlist, $obj = '', $tabname = '', $context = '') $classtd = ''; $class = ''; if ($fieldlist[$field] == 'code') $class = 'maxwidth100'; - if (in_array($fieldlist[$field], array('dayrule', 'day', 'month', 'year', 'pos', 'use_default', 'affect', 'delay', 'position', 'sortorder', 'sens', 'category_type'))) $class = 'maxwidth50'; + if (in_array($fieldlist[$field], array('dayrule', 'day', 'month', 'year', 'pos', 'use_default', 'affect', 'delay', 'position', 'sortorder', 'sens', 'category_type'))) { + $class = 'maxwidth50 center'; + } + if (in_array($fieldlist[$field], array('use_default'))) { + $classtd = 'center'; + } if (in_array($fieldlist[$field], array('libelle', 'label', 'tracking'))) $class = 'quatrevingtpercent'; print ''; $transfound = 0; diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 4b88cc7797a..cf816db19a5 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -1158,7 +1158,7 @@ if ($action == 'create') print ''.$langs->trans("Project").''; print img_picto('', 'project', 'class="paddingrightonly"'); - $numproject = $formproject->select_projects((!empty($societe->id) ? $societe->id : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 0, 0, 'maxwidth500 widthcentpercentminusxx'); + print $formproject->select_projects((!empty($societe->id) ? $societe->id : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500 widthcentpercentminusxx'); print ' '; $urloption = '?action=create&donotclearsession=1'; @@ -1183,7 +1183,7 @@ if ($action == 'create') print img_picto('', 'projecttask', 'class="paddingrightonly"'); $projectsListId = false; if (!empty($projectid)) { $projectsListId = $projectid; } - $tid = GETPOST("projecttaskid") ?GETPOST("projecttaskid") : ''; + $tid = GETPOST("projecttaskid") ? GETPOST("projecttaskid") : ''; $formproject->selectTasks((!empty($societe->id) ? $societe->id : -1), $tid, 'taskid', 24, 0, '1', 1, 0, 0, 'maxwidth500', $projectsListId); print ''; } @@ -1194,10 +1194,10 @@ if ($action == 'create') include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; print ''.$langs->trans("LinkedObject").''; print ''.dolGetElementUrl($originid, $origin, 1).''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; } $reg = array(); diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php index 3d2a2e57e3c..f6e412e0958 100644 --- a/htdocs/core/class/html.formcompany.class.php +++ b/htdocs/core/class/html.formcompany.class.php @@ -375,7 +375,7 @@ class FormCompany extends Form $resql = $this->db->query($sql); if ($resql) { - print ''; $num = $this->db->num_rows($resql); $i = 0; if ($num) @@ -407,6 +407,7 @@ class FormCompany extends Form } } print ''; + print ajax_combobox($htmlname); } else { dol_print_error($this->db); } diff --git a/htdocs/core/class/html.formprojet.class.php b/htdocs/core/class/html.formprojet.class.php index eac04cfefc1..9be08e133a1 100644 --- a/htdocs/core/class/html.formprojet.class.php +++ b/htdocs/core/class/html.formprojet.class.php @@ -261,7 +261,8 @@ class FormProjets 'key' => (int) $obj->rowid, 'value' => $obj->ref, 'ref' => $obj->ref, - 'label' => $labeltoshow, + 'labelx' => $labeltoshow, + 'label' => ((bool) $disabled) ? ''.$labeltoshow.'' : $labeltoshow, 'disabled' => (bool) $disabled ); } @@ -297,7 +298,7 @@ class FormProjets * @param int $maxlength Maximum length of label * @param int $option_only Return only html options lines without the select tag * @param string $show_empty Add an empty line ('1' or string to show for empty line) - * @param int $discard_closed Discard closed projects (0=Keep,1=hide completely,2=Disable) + * @param int $discard_closed Discard closed projects (0=Keep, 1=hide completely, 2=Disable) * @param int $forcefocus Force focus on field (works with javascript only) * @param int $disabled Disabled * @param string $morecss More css added to the select component diff --git a/htdocs/core/modules/modTicket.class.php b/htdocs/core/modules/modTicket.class.php index 0b5e54e9637..68fe7f2eb22 100644 --- a/htdocs/core/modules/modTicket.class.php +++ b/htdocs/core/modules/modTicket.class.php @@ -129,9 +129,9 @@ class modTicket extends DolibarrModules 'SELECT f.rowid as rowid, f.code, f.pos, f.label, f.active, f.use_default FROM '.MAIN_DB_PREFIX.'c_ticket_resolution as f' ), 'tabsqlsort' => array("pos ASC", "pos ASC", "pos ASC", "pos ASC"), - 'tabfield' => array("pos,code,label,use_default", "pos,code,label,use_default", "pos,code,label,use_default", "pos,code,label,use_default"), - 'tabfieldvalue' => array("pos,code,label,use_default", "pos,code,label,use_default", "pos,code,label,use_default", "pos,code,label,use_default"), - 'tabfieldinsert' => array("pos,code,label,use_default", "pos,code,label,use_default", "pos,code,label,use_default", "pos,code,label,use_default"), + 'tabfield' => array("code,label,pos,use_default", "code,label,pos,use_default", "code,label,pos,use_default", "code,label,pos,use_default"), + 'tabfieldvalue' => array("code,label,pos,use_default", "code,label,pos,use_default", "code,label,pos,use_default", "code,label,pos,use_default"), + 'tabfieldinsert' => array("code,label,pos,use_default", "code,label,pos,use_default", "code,label,pos,use_default", "code,label,pos,use_default"), 'tabrowid' => array("rowid", "rowid", "rowid", "rowid"), 'tabcond' => array($conf->ticket->enabled, $conf->ticket->enabled, $conf->ticket->enabled, $conf->ticket->enabled), 'tabhelp' => array(array('code'=>$langs->trans("EnterAnyCode"), 'use_default'=>$langs->trans("Enter0or1")), array('code'=>$langs->trans("EnterAnyCode"), 'use_default'=>$langs->trans("Enter0or1")), array('code'=>$langs->trans("EnterAnyCode"), 'use_default'=>$langs->trans("Enter0or1")), array('code'=>$langs->trans("EnterAnyCode"), 'use_default'=>$langs->trans("Enter0or1"))), diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index b2fb44dca4d..a7103a99daa 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1028,6 +1028,7 @@ DictionaryOpportunityStatus=Lead status for project/lead DictionaryExpenseTaxCat=Expense report - Transportation categories DictionaryExpenseTaxRange=Expense report - Range by transportation category DictionaryTransportMode=Intracomm report - Transport mode +TypeOfUnit=Type of unit SetupSaved=Setup saved SetupNotSaved=Setup not saved BackToModuleList=Back to Module list @@ -2066,3 +2067,4 @@ TemplateDeleted=Template deleted MailToSendEventPush=Template for event reminder emails SwitchThisForABetterSecurity=Switching this value to %s is recommended for more security DictionaryProductNature= Nature of product +CountryIfSpecificToOneCountry=Country (if specific to a given country) \ No newline at end of file