Clean code

This commit is contained in:
Laurent Destailleur 2020-10-16 20:17:54 +02:00
parent f737e01a31
commit e3552e7e02
6 changed files with 62 additions and 43 deletions

View File

@ -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[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[30] = array('code'=>$langs->trans("EnterAnyCode"), 'name'=>$langs->trans("LabelName"), 'paper_size'=>$langs->trans("LabelPaperSize"));
//$tabhelp[31] = array('pcg_version'=>$langs->trans("EnterAnyCode")); //$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).<br>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).<br>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[33] = array('code'=>$langs->trans("EnterAnyCode"));
$tabhelp[34] = array('code'=>$langs->trans("EnterAnyCode")); $tabhelp[34] = array('code'=>$langs->trans("EnterAnyCode"));
$tabhelp[35] = array(); $tabhelp[35] = array();
@ -1066,11 +1066,7 @@ if ($id)
{ {
// If sort order is "country", we use country_code instead // If sort order is "country", we use country_code instead
if ($sortfield == 'country') $sortfield = 'country_code'; if ($sortfield == 'country') $sortfield = 'country_code';
$sql .= " ORDER BY ".$db->escape($sortfield); $sql .= $db->order($sortfield, $sortorder);
if ($sortorder)
{
$sql .= " ".strtoupper($db->escape($sortorder));
}
$sql .= ", "; $sql .= ", ";
// Clear the required sort criteria for the tabsqlsort to be able to force it with selected value // 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]); $tabsqlsort[$id] = preg_replace('/([a-z]+\.)?'.$sortfield.' '.$sortorder.',/i', '', $tabsqlsort[$id]);
@ -1111,7 +1107,7 @@ if ($id)
print '<table class="noborder centpercent">'; print '<table class="noborder centpercent">';
// Line for title // Line for title
print '<tr class="liste_titre">'; $tdsoffields = '<tr class="liste_titre">';
foreach ($fieldlist as $field => $value) foreach ($fieldlist as $field => $value)
{ {
if ($fieldlist[$field] == 'entity') { if ($fieldlist[$field] == 'entity') {
@ -1192,7 +1188,8 @@ if ($id)
if ($fieldlist[$field] == 'range_ik') { $valuetoshow = $langs->trans("RangeIk"); } if ($fieldlist[$field] == 'range_ik') { $valuetoshow = $langs->trans("RangeIk"); }
if ($fieldlist[$field] == 'fk_c_exp_tax_cat') { $valuetoshow = $langs->trans("CarCategory"); } if ($fieldlist[$field] == 'fk_c_exp_tax_cat') { $valuetoshow = $langs->trans("CarCategory"); }
if ($fieldlist[$field] == 'revenuestamp_type') { $valuetoshow = $langs->trans('TypeOfRevenueStamp'); } 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 if ($id == 2) // Special case for state page
{ {
@ -1202,28 +1199,27 @@ if ($id)
if ($valuetoshow != '') if ($valuetoshow != '')
{ {
print '<td'.($class ? ' class="'.$class.'"' : '').'>'; $tdsoffields .= '<td'.($class ? ' class="'.$class.'"' : '').'>';
if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) print '<a href="'.$tabhelp[$id][$value].'" target="_blank">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>'; if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) $tdsoffields .= '<a href="'.$tabhelp[$id][$value].'" target="_blank">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
elseif (!empty($tabhelp[$id][$value])) print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]); elseif (!empty($tabhelp[$id][$value])) $tdsoffields .= $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
else print $valuetoshow; else $tdsoffields .= $valuetoshow;
print '</td>'; $tdsoffields .= '</td>';
} }
if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') $alabelisused = 1; if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') $alabelisused = 1;
} }
if ($id == 4) print '<td></td>'; if ($id == 4) $tdsoffields .= '<td></td>';
print '<td>'; $tdsoffields .= '<td>';
print '<input type="hidden" name="id" value="'.$id.'">'; $tdsoffields .= '<input type="hidden" name="id" value="'.$id.'">';
if (!is_null($withentity)) if (!is_null($withentity))
print '<input type="hidden" name="entity" value="'.$withentity.'">'; $tdsoffields .= '<input type="hidden" name="entity" value="'.$withentity.'">';
print '</td>'; $tdsoffields .= '</td>';
print '<td style="min-width: 26px;"></td>'; $tdsoffields .= '<td style="min-width: 26px;"></td>';
print '<td style="min-width: 26px;"></td>'; $tdsoffields .= '<td style="min-width: 26px;"></td>';
print '</tr>'; $tdsoffields .= '</tr>';
print $tdsoffields;
// Line to enter new values
print '<!-- line to add new entry -->';
print '<tr class="oddeven nodrag nodrop nohover">';
$obj = new stdClass(); $obj = new stdClass();
// If data was already input, we define them in obj to populate input fields. // 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 if ($id == 3) unset($fieldlist[2]); // Remove field ??? if dictionary Regions
// Line to enter new values
print '<!-- line to add new entry -->';
print '<tr class="oddeven nodrag nodrop nohover">';
if (empty($reshook)) if (empty($reshook))
{ {
fieldList($fieldlist, $obj, $tabname[$id], 'add'); fieldList($fieldlist, $obj, $tabname[$id], 'add');
@ -1255,10 +1255,8 @@ if ($id)
print '<input type="submit" class="button" name="actionadd" value="'.$langs->trans("Add").'">'; print '<input type="submit" class="button" name="actionadd" value="'.$langs->trans("Add").'">';
} }
print '</td>'; print '</td>';
print "</tr>";
$colspan = count($fieldlist) + 3; print "</tr>";
if ($id == 4) $colspan++;
print '</table>'; print '</table>';
print '</div>'; print '</div>';
@ -1341,6 +1339,10 @@ if ($id)
{ {
if ($fieldlist[$field] == 'entity') continue; 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 // Determines the name of the field in relation to the possible names
// in data dictionaries // in data dictionaries
$showfield = 1; // By defaut $showfield = 1; // By defaut
@ -1365,7 +1367,8 @@ if ($id)
if ($fieldlist[$field] == 'lang') { $valuetoshow = $langs->trans("Language"); } if ($fieldlist[$field] == 'lang') { $valuetoshow = $langs->trans("Language"); }
if ($fieldlist[$field] == 'type') { $valuetoshow = $langs->trans("Type"); } if ($fieldlist[$field] == 'type') { $valuetoshow = $langs->trans("Type"); }
if ($fieldlist[$field] == 'code') { $valuetoshow = $langs->trans("Code"); } 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' || $fieldlist[$field] == 'label') { $valuetoshow = $langs->trans("Label"); }
if ($fieldlist[$field] == 'libelle_facture') { $valuetoshow = $langs->trans("LabelOnDocuments"); } if ($fieldlist[$field] == 'libelle_facture') { $valuetoshow = $langs->trans("LabelOnDocuments"); }
if ($fieldlist[$field] == 'country') { $valuetoshow = $langs->trans("Country"); } 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] == 'range_ik') { $valuetoshow = $langs->trans("RangeIk"); }
if ($fieldlist[$field] == 'fk_c_exp_tax_cat') { $valuetoshow = $langs->trans("CarCategory"); } if ($fieldlist[$field] == 'fk_c_exp_tax_cat') { $valuetoshow = $langs->trans("CarCategory"); }
if ($fieldlist[$field] == 'revenuestamp_type') { $valuetoshow = $langs->trans('TypeOfRevenueStamp'); } 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; } if ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') { $showfield = 0; }
// Show field title // Show field title
if ($showfield) 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 = '<a href="'.$tabhelp[$id][$value].'" target="_blank">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
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 // Favorite - Only activated on country dictionary
@ -1635,6 +1643,8 @@ if ($id)
if ($fieldlist[$field] == 'position') $class .= ' right'; if ($fieldlist[$field] == 'position') $class .= ' right';
if ($fieldlist[$field] == 'localtax1_type') $class .= ' nowrap'; if ($fieldlist[$field] == 'localtax1_type') $class .= ' nowrap';
if ($fieldlist[$field] == 'localtax2_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 // Show value for field
if ($showfield) print '<!-- '.$fieldlist[$field].' --><td class="'.$class.'">'.$valuetoshow.'</td>'; if ($showfield) print '<!-- '.$fieldlist[$field].' --><td class="'.$class.'">'.$valuetoshow.'</td>';
} }
@ -1981,7 +1991,12 @@ function fieldList($fieldlist, $obj = '', $tabname = '', $context = '')
$classtd = ''; $class = ''; $classtd = ''; $class = '';
if ($fieldlist[$field] == 'code') $class = 'maxwidth100'; 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'; if (in_array($fieldlist[$field], array('libelle', 'label', 'tracking'))) $class = 'quatrevingtpercent';
print '<td class="'.$classtd.'">'; print '<td class="'.$classtd.'">';
$transfound = 0; $transfound = 0;

View File

@ -1158,7 +1158,7 @@ if ($action == 'create')
print '<tr><td class="titlefieldcreate">'.$langs->trans("Project").'</td><td id="project-input-container" >'; print '<tr><td class="titlefieldcreate">'.$langs->trans("Project").'</td><td id="project-input-container" >';
print img_picto('', 'project', 'class="paddingrightonly"'); 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 ' <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$societe->id.'&action=create"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddProject").'"></span></a>'; print ' <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$societe->id.'&action=create"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddProject").'"></span></a>';
$urloption = '?action=create&donotclearsession=1'; $urloption = '?action=create&donotclearsession=1';
@ -1194,10 +1194,10 @@ if ($action == 'create')
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
print '<tr><td class="titlefieldcreate">'.$langs->trans("LinkedObject").'</td>'; print '<tr><td class="titlefieldcreate">'.$langs->trans("LinkedObject").'</td>';
print '<td colspan="3">'.dolGetElementUrl($originid, $origin, 1).'</td></tr>'; print '<td colspan="3">'.dolGetElementUrl($originid, $origin, 1).'</td></tr>';
print '<input type="hidden" name="fk_element" size="10" value="'.GETPOST('originid').'">'; print '<input type="hidden" name="fk_element" value="'.GETPOST('originid', 'int').'">';
print '<input type="hidden" name="elementtype" size="10" value="'.GETPOST('origin').'">'; print '<input type="hidden" name="elementtype" value="'.GETPOST('origin').'">';
print '<input type="hidden" name="originid" size="10" value="'.GETPOST('originid').'">'; print '<input type="hidden" name="originid" value="'.GETPOST('originid', 'int').'">';
print '<input type="hidden" name="origin" size="10" value="'.GETPOST('origin').'">'; print '<input type="hidden" name="origin" value="'.GETPOST('origin').'">';
} }
$reg = array(); $reg = array();

View File

@ -375,7 +375,7 @@ class FormCompany extends Form
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
print '<select class="flat" name="'.$htmlname.'">'; print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
$i = 0; $i = 0;
if ($num) if ($num)
@ -407,6 +407,7 @@ class FormCompany extends Form
} }
} }
print '</select>'; print '</select>';
print ajax_combobox($htmlname);
} else { } else {
dol_print_error($this->db); dol_print_error($this->db);
} }

View File

@ -261,7 +261,8 @@ class FormProjets
'key' => (int) $obj->rowid, 'key' => (int) $obj->rowid,
'value' => $obj->ref, 'value' => $obj->ref,
'ref' => $obj->ref, 'ref' => $obj->ref,
'label' => $labeltoshow, 'labelx' => $labeltoshow,
'label' => ((bool) $disabled) ? '<span class="opacitymedium">'.$labeltoshow.'</span>' : $labeltoshow,
'disabled' => (bool) $disabled 'disabled' => (bool) $disabled
); );
} }

View File

@ -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' '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"), '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"), 'tabfield' => array("code,label,pos,use_default", "code,label,pos,use_default", "code,label,pos,use_default", "code,label,pos,use_default"),
'tabfieldvalue' => array("pos,code,label,use_default", "pos,code,label,use_default", "pos,code,label,use_default", "pos,code,label,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("pos,code,label,use_default", "pos,code,label,use_default", "pos,code,label,use_default", "pos,code,label,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"), 'tabrowid' => array("rowid", "rowid", "rowid", "rowid"),
'tabcond' => array($conf->ticket->enabled, $conf->ticket->enabled, $conf->ticket->enabled, $conf->ticket->enabled), '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"))), '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"))),

View File

@ -1028,6 +1028,7 @@ DictionaryOpportunityStatus=Lead status for project/lead
DictionaryExpenseTaxCat=Expense report - Transportation categories DictionaryExpenseTaxCat=Expense report - Transportation categories
DictionaryExpenseTaxRange=Expense report - Range by transportation category DictionaryExpenseTaxRange=Expense report - Range by transportation category
DictionaryTransportMode=Intracomm report - Transport mode DictionaryTransportMode=Intracomm report - Transport mode
TypeOfUnit=Type of unit
SetupSaved=Setup saved SetupSaved=Setup saved
SetupNotSaved=Setup not saved SetupNotSaved=Setup not saved
BackToModuleList=Back to Module list BackToModuleList=Back to Module list
@ -2066,3 +2067,4 @@ TemplateDeleted=Template deleted
MailToSendEventPush=Template for event reminder emails MailToSendEventPush=Template for event reminder emails
SwitchThisForABetterSecurity=Switching this value to %s is recommended for more security SwitchThisForABetterSecurity=Switching this value to %s is recommended for more security
DictionaryProductNature= Nature of product DictionaryProductNature= Nature of product
CountryIfSpecificToOneCountry=Country (if specific to a given country)