Clean code

This commit is contained in:
Laurent Destailleur 2022-10-04 23:53:17 +02:00
parent 0bacd5bd32
commit 959aef914e
3 changed files with 48 additions and 38 deletions

View File

@ -56,7 +56,7 @@ if (isModEnabled('eventorganization')) {
$langs->loadLangs($langsArray);
$toselect = GETPOST('toselect', 'array');
$action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view';
$action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view';
$massaction = GETPOST('massaction', 'alpha');
$confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
$mode = GETPOST('mode', 'aZ09');
@ -350,7 +350,7 @@ if (empty($reshook)) {
}
setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
$action = 'add';
$action = 'create';
}
}
@ -424,7 +424,7 @@ if (empty($reshook)) {
} else {
dol_print_error($db);
}
$action = 'add';
$action = 'create';
}
}
@ -654,7 +654,7 @@ $linkback = '';
$titlepicto = 'title_setup';
$url = DOL_URL_ROOT.'/admin/mails_templates.php?action=add&token='.newToken();
$url = DOL_URL_ROOT.'/admin/mails_templates.php?action=create';
$newcardbutton = dolGetButtonTitle($langs->trans('NewEMailTemplate'), '', 'fa fa-plus-circle', $url, '', $permissiontoadd);
@ -685,10 +685,11 @@ if ($action == 'delete') {
$fieldlist = explode(',', $tabfield[$id]);
if ($action == 'add') {
if ($action == 'create') {
// Form to add a new line
print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
print '<div class="div-table-responsive-no-min">';
@ -739,7 +740,6 @@ if ($action == 'add') {
if ($fieldlist[$field] == 'content_lines') {
$valuetoshow = '';
}
if ($valuetoshow != '') {
print '<th class="'.$align.'">';
if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) {
@ -820,16 +820,15 @@ if ($action == 'add') {
// Input field
if ($tmpfieldlist == 'topic') {
print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '').'">';
print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'" value="'.(!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '').'">';
} elseif ($tmpfieldlist == 'joinfiles') {
print '<input type="text" class="flat maxwidth50" name="'.$tmpfieldlist.'" value="'.(isset($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '1').'">';
print $form->selectyesno($tmpfieldlist, (isset($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '0'), 1, false, 0, 1);
} else {
// print '<textarea cols="3" rows="'.ROWS_2.'" class="flat" name="'.$fieldlist[$field].'">'.(!empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'</textarea>';
$okforextended = true;
if (empty($conf->global->FCKEDITOR_ENABLE_MAIL)) {
$okforextended = false;
}
$doleditor = new DolEditor($tmpfieldlist, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 180, 'dolibarr_mailings', 'In', 0, true, $okforextended, ROWS_4, '90%');
$doleditor = new DolEditor($tmpfieldlist, (!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : ''), '', 180, 'dolibarr_mailings', 'In', 0, true, $okforextended, ROWS_4, '90%');
print $doleditor->Create(1);
}
print '</td>';
@ -917,7 +916,7 @@ foreach ($fieldlist as $field => $value) {
print '</td>';
} elseif ($value == 'fk_user') {
print '<td class="liste_titre">';
print $form->select_dolusers($search_fk_user, 'search_fk_user', 1, null, 0, ($user->admin ? '' : 'hierarchyme'), null, 0, 0, 0, '', 0, '', 'maxwidth150');
print $form->select_dolusers($search_fk_user, 'search_fk_user', 1, null, 0, ($user->admin ? '' : 'hierarchyme'), null, 0, 0, 0, '', 0, '', 'maxwidth150', 1);
print '</td>';
} elseif ($value == 'topic') {
print '<td class="liste_titre"><input type="text" name="search_topic" value="'.dol_escape_htmltag($search_topic).'"></td>';
@ -1024,7 +1023,7 @@ if ($num) {
$reshook = $hookmanager->executeHooks('editEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
$error = $hookmanager->error; $errors = $hookmanager->errors;
// Show fields
// Show main fields
if (empty($reshook)) {
fieldList($fieldlist, $obj, $tabname[$id], 'edit');
}
@ -1045,7 +1044,7 @@ if ($num) {
foreach ($fieldsforcontent as $tmpfieldlist) {
$showfield = 1;
$align = "left";
$valuetoshow = $obj->{$tmpfieldlist};
$valuetoshow = $obj->$tmpfieldlist;
$class = 'tddict';
// Show value for field
@ -1059,7 +1058,7 @@ if ($num) {
}
if ($tmpfieldlist == 'joinfiles') {
print '<strong>'.$form->textwithpicto($langs->trans("FilesAttachedToEmail"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
print '<input type="text" class="flat maxwidth50" name="'.$tmpfieldlist.'-'.$rowid.'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '').'">';
print $form->selectyesno($tmpfieldlist.'-'.$rowid, (isset($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '0'), 1, false, 0, 1);
}
// If $acceptlocallinktomedia is true, we can add link media files int email templates (we already can do this into HTML editor of an email).
@ -1204,7 +1203,7 @@ if ($num) {
if ($value == 'joinfiles') {
$align = "center";
if ($valuetoshow) {
$valuetoshow = 1;
$valuetoshow = yn(1);
} else {
$valuetoshow = '';
}
@ -1311,7 +1310,7 @@ function fieldList($fieldlist, $obj = '', $tabname = '', $context = '')
if ($value == 'fk_user') {
print '<td>';
if ($user->admin) {
print $form->select_dolusers(empty($obj->{$value}) ? '' : $obj->{$value}, 'fk_user', 1, null, 0, ($user->admin ? '' : 'hierarchyme'), null, 0, 0, 0, '', 0, '', 'minwidth150 maxwidth300');
print $form->select_dolusers(empty($obj->{$value}) ? '' : $obj->{$value}, 'fk_user', 1, null, 0, ($user->admin ? '' : 'hierarchyme'), null, 0, 0, 0, '', 0, '', 'minwidth150 maxwidth200');
} else {
if ($context == 'add') { // I am not admin and we show the add form
print $user->getNomUrl(1); // Me
@ -1335,29 +1334,29 @@ function fieldList($fieldlist, $obj = '', $tabname = '', $context = '')
if (getDolGlobalInt('MAIN_MULTILANGS')) {
$selectedlang = GETPOSTISSET('langcode') ?GETPOST('langcode', 'aZ09') : $langs->defaultlang;
if ($context == 'edit') {
$selectedlang = $obj->{$value};
$selectedlang = $obj->lang;
}
print $formadmin->select_language($selectedlang, 'langcode', 0, null, 1, 0, 0, 'maxwidth150');
} else {
if (!empty($obj->{$value})) {
print $obj->{$value}.' - '.$langs->trans('Language_'.$obj->{$value});
if (!empty($obj->lang)) {
print $obj->lang.' - '.$langs->trans('Language_'.$obj->lang);
}
$keyname = $value;
if ($keyname == 'lang') {
$keyname = 'langcode'; // Avoid conflict with lang param
}
print '<input type="hidden" value="'.(empty($obj->{$value}) ? '' : $obj->{$value}).'" name="'.$keyname.'">';
print '<input type="hidden" value="'.(empty($obj->lang) ? '' : $obj->lang).'" name="'.$keyname.'">';
}
print '</td>';
} elseif ($value == 'type_template') {
// Le type de template
print '<td class="center">';
if ($context == 'edit' && !empty($obj->{$value}) && !in_array($obj->{$value}, array_keys($elementList))) {
if ($context == 'edit' && !empty($obj->type_template) && !in_array($obj->type_template, array_keys($elementList))) {
// Current template type is an unknown type, so we must keep it as it is.
print '<input type="hidden" name="type_template" value="'.$obj->{$value}.'">';
print $obj->{$value};
print '<input type="hidden" name="type_template" value="'.$obj->type_template.'">';
print $obj->type_template;
} else {
print $form->selectarray('type_template', $elementList, (!empty($obj->{$value}) ? $obj->{$value}:''), 1, 0, 0, '', 0, 0, 0, '', 'minwidth150', 1, '', 0, 1);
print $form->selectarray('type_template', $elementList, (!empty($obj->type_template) ? $obj->type_template:''), 1, 0, 0, '', 0, 0, 0, '', 'minwidth150', 1, '', 0, 1);
}
print '</td>';
} elseif ($context == 'add' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
@ -1378,7 +1377,7 @@ function fieldList($fieldlist, $obj = '', $tabname = '', $context = '')
$class = 'maxwidth50'; $classtd = 'center';
}
if ($value == 'position') {
$class = 'maxwidth50'; $classtd = 'center';
$class = 'maxwidth50 center'; $classtd = 'center';
}
if ($value == 'libelle') {
$class = 'quatrevingtpercent';
@ -1395,7 +1394,6 @@ function fieldList($fieldlist, $obj = '', $tabname = '', $context = '')
if (empty($user->admin)) {
print $form->selectyesno($value, '1', 1);
} else {
//print '<input type="text" '.$size.'class="flat'.($class?' '.$class:'').'" value="1" name="'.$fieldlist[$field].'">';
print $form->selectyesno($value, (isset($obj->{$value}) ? $obj->{$value}:''), 1);
}
} else {

View File

@ -1929,14 +1929,14 @@ class Form
* @param integer $show_every 0=default list, 1=add also a value "Everybody" at beginning of list
* @param string $enableonlytext If option $enableonlytext is set, we use this text to explain into label why record is disabled. Not used if enableonly is empty.
* @param string $morecss More css
* @param int $noactive Show only active users (this will also happened whatever is this option if USER_HIDE_INACTIVE_IN_COMBOBOX is on).
* @param int $notdisabled Show only active users (this will also happened whatever is this option if USER_HIDE_INACTIVE_IN_COMBOBOX is on).
* @param int $outputmode 0=HTML select string, 1=Array
* @param bool $multiple add [] in the name of element and add 'multiple' attribut
* @param int $forcecombo Force the component to be a simple combo box without ajax
* @return string HTML select string
* @see select_dolgroups()
*/
public function select_dolusers($selected = '', $htmlname = 'userid', $show_empty = 0, $exclude = null, $disabled = 0, $include = '', $enableonly = '', $force_entity = '0', $maxlength = 0, $showstatus = 0, $morefilter = '', $show_every = 0, $enableonlytext = '', $morecss = '', $noactive = 0, $outputmode = 0, $multiple = false, $forcecombo = 0)
public function select_dolusers($selected = '', $htmlname = 'userid', $show_empty = 0, $exclude = null, $disabled = 0, $include = '', $enableonly = '', $force_entity = '0', $maxlength = 0, $showstatus = 0, $morefilter = '', $show_every = 0, $enableonlytext = '', $morecss = '', $notdisabled = 0, $outputmode = 0, $multiple = false, $forcecombo = 0)
{
// phpcs:enable
global $conf, $user, $langs, $hookmanager;
@ -2005,7 +2005,7 @@ class Form
if ($includeUsers) {
$sql .= " AND u.rowid IN (".$this->db->sanitize($includeUsers).")";
}
if (!empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX) || $noactive) {
if (!empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX) || $notdisabled) {
$sql .= " AND u.statut <> 0";
}
if (!empty($morefilter)) {
@ -2065,7 +2065,7 @@ class Form
$disableline = ($enableonlytext ? $enableonlytext : '1');
}
$labeltoshow = '';
$labeltoshow = ''; $labeltoshowhtml = '';
// $fullNameMode is 0=Lastname+Firstname (MAIN_FIRSTNAME_NAME_POSITION=1), 1=Firstname+Lastname (MAIN_FIRSTNAME_NAME_POSITION=0)
$fullNameMode = 0;
@ -2073,37 +2073,50 @@ class Form
$fullNameMode = 1; //Firstname+lastname
}
$labeltoshow .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
$labeltoshowhtml .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
if (empty($obj->firstname) && empty($obj->lastname)) {
$labeltoshow .= $obj->login;
$labeltoshowhtml .= $obj->login;
}
// Complete name with more info
$moreinfo = '';
// Complete name with a more info string like: ' (info1 - info2 - ...)'
$moreinfo = ''; $moreinfohtml = '';
if (!empty($conf->global->MAIN_SHOW_LOGIN)) {
$moreinfo .= ($moreinfo ? ' - ' : ' (').$obj->login;
$moreinfo .= ($moreinfo ? ' - ' : ' (');
$moreinfohtml .= ($moreinfohtml ? ' - ' : ' <span class="opacitymedium">(');
$moreinfo .= $obj->login;
$moreinfohtml .= $obj->login;
}
if ($showstatus >= 0) {
if ($obj->status == 1 && $showstatus == 1) {
$moreinfo .= ($moreinfo ? ' - ' : ' (').$langs->trans('Enabled');
$moreinfohtml .= ($moreinfohtml ? ' - ' : ' <span class="opacitymedium">(').$langs->trans('Enabled');
}
if ($obj->status == 0 && $showstatus == 1) {
$moreinfo .= ($moreinfo ? ' - ' : ' (').$langs->trans('Disabled');
$moreinfohtml .= ($moreinfohtml ? ' - ' : ' <span class="opacitymedium">(').$langs->trans('Disabled');
}
}
if (isModEnabled('multicompany') && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1 && $user->admin && !$user->entity) {
if (!$obj->entity) {
$moreinfo .= ($moreinfo ? ' - ' : ' (').$langs->trans("AllEntities");
$moreinfohtml .= ($moreinfohtml ? ' - ' : ' <span class="opacitymedium">(').$langs->trans("AllEntities");
} else {
if ($obj->entity != $conf->entity) {
$moreinfo .= ($moreinfo ? ' - ' : ' (').($obj->label ? $obj->label : $langs->trans("EntityNameNotDefined"));
$moreinfohtml .= ($moreinfohtml ? ' - ' : ' <span class="opacitymedium">(').($obj->label ? $obj->label : $langs->trans("EntityNameNotDefined"));
}
}
}
$moreinfo .= ($moreinfo ? ')' : '');
$moreinfohtml .= ($moreinfohtml ? ')' : '');
if ($disableline && $disableline != '1') {
$moreinfo .= ' - '.$disableline; // This is text from $enableonlytext parameter
// Add text from $enableonlytext parameter
$moreinfo .= ' - '.$disableline;
$moreinfohtml .= ' - '.$disableline;
}
$labeltoshow .= $moreinfo;
$labeltoshowhtml .= $moreinfohtml;
$out .= '<option value="'.$obj->rowid.'"';
if ($disableline) {
@ -2120,7 +2133,7 @@ class Form
if ($showstatus >= 0 && $obj->status == 0) {
$outhtml .= '<strike class="opacitymediumxxx">';
}
$outhtml .= $labeltoshow;
$outhtml .= $labeltoshowhtml;
if ($showstatus >= 0 && $obj->status == 0) {
$outhtml .= '</strike>';
}

View File

@ -2692,7 +2692,7 @@ class User extends CommonObject
}
/**
* Return a link to the user card (with optionaly the picto)
* Return a HTML link to the user card (with optionaly the picto)
* Use this->id,this->lastname, this->firstname
*
* @param int $withpictoimg Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto, -1=Include photo into link, -2=Only picto photo, -3=Only photo very small)
@ -2720,8 +2720,7 @@ class User extends CommonObject
$withpictoimg = 0;
}
$result = ''; $label = '';
$companylink = '';
$result = ''; $label = ''; $companylink = '';
if (!empty($this->photo)) {
$label .= '<div class="photointooltip floatright">';