Clean code

This commit is contained in:
Laurent Destailleur 2020-11-16 12:54:16 +01:00
parent 928330c44b
commit ac5fa6c6df

View File

@ -1248,9 +1248,7 @@ abstract class CommonObject
{ {
$sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,"; $sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,";
$sql .= " tc.code, tc.libelle"; $sql .= " tc.code, tc.libelle";
//$sql.= ", s.fk_soc";
$sql .= " FROM (".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc)"; $sql .= " FROM (".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc)";
//$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as s ON ec.fk_socpeople=s.rowid"; // Si contact de type external, alors il est lie a une societe
$sql .= " WHERE ec.rowid =".$rowid; $sql .= " WHERE ec.rowid =".$rowid;
$sql .= " AND ec.fk_c_type_contact=tc.rowid"; $sql .= " AND ec.fk_c_type_contact=tc.rowid";
$sql .= " AND tc.element = '".$this->db->escape($this->element)."'"; $sql .= " AND tc.element = '".$this->db->escape($this->element)."'";
@ -2449,8 +2447,6 @@ abstract class CommonObject
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
$sql .= " SET model_pdf = '".$this->db->escape($newmodelpdf)."'"; $sql .= " SET model_pdf = '".$this->db->escape($newmodelpdf)."'";
$sql .= " WHERE rowid = ".$this->id; $sql .= " WHERE rowid = ".$this->id;
// if ($this->element == 'facture') $sql.= " AND fk_statut < 2";
// if ($this->element == 'propal') $sql.= " AND fk_statut = 0";
dol_syslog(get_class($this)."::setDocModel", LOG_DEBUG); dol_syslog(get_class($this)."::setDocModel", LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
@ -2565,8 +2561,7 @@ abstract class CommonObject
} else dol_print_error($this->db); } else dol_print_error($this->db);
if ($nl > 0) if ($nl > 0)
{ {
// The goal of this part is to reorder all lines, with all children lines sharing the same // The goal of this part is to reorder all lines, with all children lines sharing the same counter that parents.
// counter that parents.
$rows = array(); $rows = array();
// We first search all lines that are parent lines (for multilevel details lines) // We first search all lines that are parent lines (for multilevel details lines)
@ -5459,7 +5454,6 @@ abstract class CommonObject
$sql .= ")"; $sql .= ")";
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (!$resql) if (!$resql)
{ {
$this->error = $this->db->lasterror(); $this->error = $this->db->lasterror();
@ -5927,8 +5921,7 @@ abstract class CommonObject
} }
} }
if (in_array($type, array('date', 'datetime'))) if (in_array($type, array('date', 'datetime'))) {
{
$tmp = explode(',', $size); $tmp = explode(',', $size);
$newsize = $tmp[0]; $newsize = $tmp[0];
@ -5939,25 +5932,19 @@ abstract class CommonObject
// TODO Must also support $moreparam // TODO Must also support $moreparam
$out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1); $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1);
} elseif (in_array($type, array('duration'))) } elseif (in_array($type, array('duration'))) {
{
$out = $form->select_duration($keyprefix.$key.$keysuffix, $value, 0, 'text', 0, 1); $out = $form->select_duration($keyprefix.$key.$keysuffix, $value, 0, 'text', 0, 1);
} elseif (in_array($type, array('int', 'integer'))) } elseif (in_array($type, array('int', 'integer'))) {
{
$tmp = explode(',', $size); $tmp = explode(',', $size);
$newsize = $tmp[0]; $newsize = $tmp[0];
$out = '<input type="text" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$newsize.'" value="'.dol_escape_htmltag($value).'"'.($moreparam ? $moreparam : '').($autofocusoncreate ? ' autofocus' : '').'>'; $out = '<input type="text" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$newsize.'" value="'.dol_escape_htmltag($value).'"'.($moreparam ? $moreparam : '').($autofocusoncreate ? ' autofocus' : '').'>';
} elseif (in_array($type, array('real'))) } elseif (in_array($type, array('real'))) {
{
$out = '<input type="text" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'"'.($moreparam ? $moreparam : '').($autofocusoncreate ? ' autofocus' : '').'>'; $out = '<input type="text" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'"'.($moreparam ? $moreparam : '').($autofocusoncreate ? ' autofocus' : '').'>';
} elseif (preg_match('/varchar/', $type)) } elseif (preg_match('/varchar/', $type)) {
{
$out = '<input type="text" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$size.'" value="'.dol_escape_htmltag($value).'"'.($moreparam ? $moreparam : '').($autofocusoncreate ? ' autofocus' : '').'>'; $out = '<input type="text" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$size.'" value="'.dol_escape_htmltag($value).'"'.($moreparam ? $moreparam : '').($autofocusoncreate ? ' autofocus' : '').'>';
} elseif (in_array($type, array('mail', 'phone', 'url'))) } elseif (in_array($type, array('mail', 'phone', 'url'))) {
{
$out = '<input type="text" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').($autofocusoncreate ? ' autofocus' : '').'>'; $out = '<input type="text" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').($autofocusoncreate ? ' autofocus' : '').'>';
} elseif (preg_match('/^text/', $type)) } elseif (preg_match('/^text/', $type)) {
{
if (!preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field if (!preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
{ {
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
@ -5966,18 +5953,15 @@ abstract class CommonObject
} else { } else {
$out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').'>'; $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').'>';
} }
} elseif (preg_match('/^html/', $type)) } elseif (preg_match('/^html/', $type)) {
{ if (!preg_match('/search_/', $keyprefix)) { // If keyprefix is search_ or search_options_, we must just use a simple text field
if (!preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
{
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, !empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_5, '90%'); $doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, !empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_5, '90%');
$out = $doleditor->Create(1); $out = $doleditor->Create(1);
} else { } else {
$out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').'>'; $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').'>';
} }
} elseif ($type == 'boolean') } elseif ($type == 'boolean') {
{
$checked = ''; $checked = '';
if (!empty($value)) { if (!empty($value)) {
$checked = ' checked value="1" '; $checked = ' checked value="1" ';
@ -5985,20 +5969,17 @@ abstract class CommonObject
$checked = ' value="1" '; $checked = ' value="1" ';
} }
$out = '<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam ? $moreparam : '').'>'; $out = '<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam ? $moreparam : '').'>';
} elseif ($type == 'price') } elseif ($type == 'price') {
{
if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
$value = price($value); $value = price($value);
} }
$out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'> '.$langs->getCurrencySymbol($conf->currency); $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'> '.$langs->getCurrencySymbol($conf->currency);
} elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/', $type)) } elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/', $type)) {
{
if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
$value = price($value); $value = price($value);
} }
$out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'> '; $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'> ';
} elseif ($type == 'select') } elseif ($type == 'select') {
{
$out = ''; $out = '';
if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2))
{ {
@ -6018,18 +5999,15 @@ abstract class CommonObject
$out .= '>'.$val.'</option>'; $out .= '>'.$val.'</option>';
} }
$out .= '</select>'; $out .= '</select>';
} elseif ($type == 'sellist') } elseif ($type == 'sellist') {
{
$out = ''; $out = '';
if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) {
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
$out .= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); $out .= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
} }
$out .= '<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : '').'>'; $out .= '<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : '').'>';
if (is_array($param['options'])) if (is_array($param['options'])) {
{
$param_list = array_keys($param['options']); $param_list = array_keys($param['options']);
$InfoFieldList = explode(":", $param_list[0]); $InfoFieldList = explode(":", $param_list[0]);
$parentName = ''; $parentName = '';
@ -6175,12 +6153,10 @@ abstract class CommonObject
} }
} }
$out .= '</select>'; $out .= '</select>';
} elseif ($type == 'checkbox') } elseif ($type == 'checkbox') {
{
$value_arr = explode(',', $value); $value_arr = explode(',', $value);
$out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options']) ?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options']) ?null:$param['options']), $value_arr, '', 0, '', 0, '100%');
} elseif ($type == 'radio') } elseif ($type == 'radio') {
{
$out = ''; $out = '';
foreach ($param['options'] as $keyopt => $val) foreach ($param['options'] as $keyopt => $val)
{ {
@ -6190,8 +6166,7 @@ abstract class CommonObject
$out .= ($value == $keyopt ? 'checked' : ''); $out .= ($value == $keyopt ? 'checked' : '');
$out .= '/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>'; $out .= '/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>';
} }
} elseif ($type == 'chkbxlst') } elseif ($type == 'chkbxlst') {
{
if (is_array($value)) { if (is_array($value)) {
$value_arr = $value; $value_arr = $value;
} else { } else {
@ -6332,8 +6307,7 @@ abstract class CommonObject
print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>';
} }
} }
} elseif ($type == 'link') } elseif ($type == 'link') {
{
$param_list = array_keys($param['options']); // $param_list='ObjectName:classPath[:AddCreateButtonOrNot[:Filter]]' $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath[:AddCreateButtonOrNot[:Filter]]'
$param_list_array = explode(':', $param_list[0]); $param_list_array = explode(':', $param_list[0]);
$showempty = (($required && $default != '') ? 0 : 1); $showempty = (($required && $default != '') ? 0 : 1);
@ -6358,25 +6332,20 @@ abstract class CommonObject
$out .= '<a class="butActionNew" title="'.$langs->trans("New").'" href="'.$url_path.'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF'].($paramforthenewlink ? '?'.$paramforthenewlink : '')).'"><span class="fa fa-plus-circle valignmiddle"></span></a>'; $out .= '<a class="butActionNew" title="'.$langs->trans("New").'" href="'.$url_path.'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF'].($paramforthenewlink ? '?'.$paramforthenewlink : '')).'"><span class="fa fa-plus-circle valignmiddle"></span></a>';
} }
} }
} elseif ($type == 'password') } elseif ($type == 'password') {
{
// If prefix is 'search_', field is used as a filter, we use a common text field. // If prefix is 'search_', field is used as a filter, we use a common text field.
$out = '<input type="'.($keyprefix == 'search_' ? 'text' : 'password').'" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'>'; $out = '<input type="'.($keyprefix == 'search_' ? 'text' : 'password').'" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'>';
} elseif ($type == 'array') } elseif ($type == 'array') {
{
$newval = $val; $newval = $val;
$newval['type'] = 'varchar(256)'; $newval['type'] = 'varchar(256)';
$out = ''; $out = '';
$inputs = array();
if (!empty($value)) { if (!empty($value)) {
foreach ($value as $option) { foreach ($value as $option) {
$out .= '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; $out .= '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> ';
$out .= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', $option, $moreparam, '', '', $morecss).'<br></span>'; $out .= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', $option, $moreparam, '', '', $morecss).'<br></span>';
} }
} }
$out .= '<a id="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_add" href="javascript:;"><span class="fa fa-plus-circle valignmiddle"></span></a>'; $out .= '<a id="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_add" href="javascript:;"><span class="fa fa-plus-circle valignmiddle"></span></a>';
$newInput = '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; $newInput = '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> ';
@ -6479,27 +6448,20 @@ abstract class CommonObject
if (empty($morecss)) if (empty($morecss))
{ {
if ($type == 'date') if ($type == 'date') {
{
$morecss = 'minwidth100imp'; $morecss = 'minwidth100imp';
} elseif ($type == 'datetime' || $type == 'timestamp') } elseif ($type == 'datetime' || $type == 'timestamp') {
{
$morecss = 'minwidth200imp'; $morecss = 'minwidth200imp';
} elseif (in_array($type, array('int', 'double', 'price'))) } elseif (in_array($type, array('int', 'double', 'price'))) {
{
$morecss = 'maxwidth75'; $morecss = 'maxwidth75';
} elseif ($type == 'url') } elseif ($type == 'url') {
{
$morecss = 'minwidth400'; $morecss = 'minwidth400';
} elseif ($type == 'boolean') } elseif ($type == 'boolean') {
{
$morecss = ''; $morecss = '';
} else { } else {
if (round($size) < 12) if (round($size) < 12) {
{
$morecss = 'minwidth100'; $morecss = 'minwidth100';
} elseif (round($size) <= 48) } elseif (round($size) <= 48) {
{
$morecss = 'minwidth200'; $morecss = 'minwidth200';
} else { } else {
$morecss = 'minwidth400'; $morecss = 'minwidth400';
@ -6510,57 +6472,47 @@ abstract class CommonObject
// Format output value differently according to properties of field // Format output value differently according to properties of field
if ($key == 'ref' && method_exists($this, 'getNomUrl')) $value = $this->getNomUrl(1, '', 0, '', 1); if ($key == 'ref' && method_exists($this, 'getNomUrl')) $value = $this->getNomUrl(1, '', 0, '', 1);
elseif ($key == 'status' && method_exists($this, 'getLibStatut')) $value = $this->getLibStatut(3); elseif ($key == 'status' && method_exists($this, 'getLibStatut')) $value = $this->getLibStatut(3);
elseif ($type == 'date') elseif ($type == 'date') {
{
if (!empty($value)) { if (!empty($value)) {
$value = dol_print_date($value, 'day'); $value = dol_print_date($value, 'day');
} else { } else {
$value = ''; $value = '';
} }
} elseif ($type == 'datetime' || $type == 'timestamp') } elseif ($type == 'datetime' || $type == 'timestamp') {
{
if (!empty($value)) { if (!empty($value)) {
$value = dol_print_date($value, 'dayhour'); $value = dol_print_date($value, 'dayhour');
} else { } else {
$value = ''; $value = '';
} }
} elseif ($type == 'duration') } elseif ($type == 'duration') {
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
if (!is_null($value) && $value !== '') { if (!is_null($value) && $value !== '') {
$value = convertSecondToTime($value, 'allhourmin'); $value = convertSecondToTime($value, 'allhourmin');
} }
} elseif ($type == 'double' || $type == 'real') } elseif ($type == 'double' || $type == 'real') {
{
if (!is_null($value) && $value !== '') { if (!is_null($value) && $value !== '') {
$value = price($value); $value = price($value);
} }
} elseif ($type == 'boolean') } elseif ($type == 'boolean') {
{
$checked = ''; $checked = '';
if (!empty($value)) { if (!empty($value)) {
$checked = ' checked '; $checked = ' checked ';
} }
$value = '<input type="checkbox" '.$checked.' '.($moreparam ? $moreparam : '').' readonly disabled>'; $value = '<input type="checkbox" '.$checked.' '.($moreparam ? $moreparam : '').' readonly disabled>';
} elseif ($type == 'mail') } elseif ($type == 'mail') {
{
$value = dol_print_email($value, 0, 0, 0, 64, 1, 1); $value = dol_print_email($value, 0, 0, 0, 64, 1, 1);
} elseif ($type == 'url') } elseif ($type == 'url') {
{
$value = dol_print_url($value, '_blank', 32, 1); $value = dol_print_url($value, '_blank', 32, 1);
} elseif ($type == 'phone') } elseif ($type == 'phone') {
{
$value = dol_print_phone($value, '', 0, 0, '', '&nbsp;', 1); $value = dol_print_phone($value, '', 0, 0, '', '&nbsp;', 1);
} elseif ($type == 'price') } elseif ($type == 'price')
{ {
if (!is_null($value) && $value !== '') { if (!is_null($value) && $value !== '') {
$value = price($value, 0, $langs, 0, 0, -1, $conf->currency); $value = price($value, 0, $langs, 0, 0, -1, $conf->currency);
} }
} elseif ($type == 'select') } elseif ($type == 'select') {
{
$value = $param['options'][$value]; $value = $param['options'][$value];
} elseif ($type == 'sellist') } elseif ($type == 'sellist') {
{
$param_list = array_keys($param['options']); $param_list = array_keys($param['options']);
$InfoFieldList = explode(":", $param_list[0]); $InfoFieldList = explode(":", $param_list[0]);
@ -6632,11 +6584,9 @@ abstract class CommonObject
} }
} }
} else dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); } else dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
} elseif ($type == 'radio') } elseif ($type == 'radio') {
{
$value = $param['options'][$value]; $value = $param['options'][$value];
} elseif ($type == 'checkbox') } elseif ($type == 'checkbox') {
{
$value_arr = explode(',', $value); $value_arr = explode(',', $value);
$value = ''; $value = '';
if (is_array($value_arr) && count($value_arr) > 0) if (is_array($value_arr) && count($value_arr) > 0)
@ -6647,8 +6597,7 @@ abstract class CommonObject
} }
$value = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; $value = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
} }
} elseif ($type == 'chkbxlst') } elseif ($type == 'chkbxlst') {
{
$value_arr = explode(',', $value); $value_arr = explode(',', $value);
$param_list = array_keys($param['options']); $param_list = array_keys($param['options']);
@ -6714,8 +6663,7 @@ abstract class CommonObject
} else { } else {
dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
} }
} elseif ($type == 'link') } elseif ($type == 'link') {
{
$out = ''; $out = '';
// only if something to display (perf) // only if something to display (perf)
@ -6741,14 +6689,11 @@ abstract class CommonObject
return 'Error bad setup of extrafield'; return 'Error bad setup of extrafield';
} }
} else $value = ''; } else $value = '';
} elseif (preg_match('/^(text|html)/', $type)) } elseif (preg_match('/^(text|html)/', $type)) {
{
$value = dol_htmlentitiesbr($value); $value = dol_htmlentitiesbr($value);
} elseif ($type == 'password') } elseif ($type == 'password') {
{
$value = preg_replace('/./i', '*', $value); $value = preg_replace('/./i', '*', $value);
} elseif ($type == 'array') } elseif ($type == 'array') {
{
$value = implode('<br>', $value); $value = implode('<br>', $value);
} }
@ -7381,8 +7326,7 @@ abstract class CommonObject
*/ */
protected function isArray($info) protected function isArray($info)
{ {
if (is_array($info)) if (is_array($info)) {
{
if (isset($info['type']) && $info['type'] == 'array') return true; if (isset($info['type']) && $info['type'] == 'array') return true;
else return false; else return false;
} }
@ -7409,8 +7353,7 @@ abstract class CommonObject
*/ */
public function isDuration($info) public function isDuration($info)
{ {
if (is_array($info)) if (is_array($info)) {
{
if (isset($info['type']) && ($info['type'] == 'duration')) return true; if (isset($info['type']) && ($info['type'] == 'duration')) return true;
else return false; else return false;
} else return false; } else return false;
@ -7424,8 +7367,7 @@ abstract class CommonObject
*/ */
public function isInt($info) public function isInt($info)
{ {
if (is_array($info)) if (is_array($info)) {
{
if (isset($info['type']) && ($info['type'] == 'int' || preg_match('/^integer/i', $info['type']))) return true; if (isset($info['type']) && ($info['type'] == 'int' || preg_match('/^integer/i', $info['type']))) return true;
else return false; else return false;
} else return false; } else return false;
@ -7439,8 +7381,7 @@ abstract class CommonObject
*/ */
public function isFloat($info) public function isFloat($info)
{ {
if (is_array($info)) if (is_array($info)) {
{
if (isset($info['type']) && (preg_match('/^(double|real|price)/i', $info['type']))) return true; if (isset($info['type']) && (preg_match('/^(double|real|price)/i', $info['type']))) return true;
else return false; else return false;
} }
@ -7455,8 +7396,7 @@ abstract class CommonObject
*/ */
public function isText($info) public function isText($info)
{ {
if (is_array($info)) if (is_array($info)) {
{
if (isset($info['type']) && $info['type'] == 'text') return true; if (isset($info['type']) && $info['type'] == 'text') return true;
else return false; else return false;
} }
@ -7471,8 +7411,7 @@ abstract class CommonObject
*/ */
protected function canBeNull($info) protected function canBeNull($info)
{ {
if (is_array($info)) if (is_array($info)) {
{
if (isset($info['notnull']) && $info['notnull'] != '1') return true; if (isset($info['notnull']) && $info['notnull'] != '1') return true;
else return false; else return false;
} }
@ -7487,8 +7426,7 @@ abstract class CommonObject
*/ */
protected function isForcedToNullIfZero($info) protected function isForcedToNullIfZero($info)
{ {
if (is_array($info)) if (is_array($info)) {
{
if (isset($info['notnull']) && $info['notnull'] == '-1') return true; if (isset($info['notnull']) && $info['notnull'] == '-1') return true;
else return false; else return false;
} }
@ -7503,8 +7441,7 @@ abstract class CommonObject
*/ */
protected function isIndex($info) protected function isIndex($info)
{ {
if (is_array($info)) if (is_array($info)) {
{
if (isset($info['index']) && $info['index'] == true) return true; if (isset($info['index']) && $info['index'] == true) return true;
else return false; else return false;
} }
@ -7591,8 +7528,7 @@ abstract class CommonObject
{ {
foreach ($this->fields as $field => $info) foreach ($this->fields as $field => $info)
{ {
if ($this->isDate($info)) if ($this->isDate($info)) {
{
if (empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0; if (empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0;
else $this->{$field} = strtotime($obj->{$field}); else $this->{$field} = strtotime($obj->{$field});
} elseif ($this->isArray($info)) } elseif ($this->isArray($info))
@ -7604,12 +7540,10 @@ abstract class CommonObject
} else { } else {
$this->{$field} = array(); $this->{$field} = array();
} }
} elseif ($this->isInt($info)) } elseif ($this->isInt($info)) {
{
if ($field == 'rowid') $this->id = (int) $obj->{$field}; if ($field == 'rowid') $this->id = (int) $obj->{$field};
else { else {
if ($this->isForcedToNullIfZero($info)) if ($this->isForcedToNullIfZero($info)) {
{
if (empty($obj->{$field})) $this->{$field} = null; if (empty($obj->{$field})) $this->{$field} = null;
else $this->{$field} = (double) $obj->{$field}; else $this->{$field} = (double) $obj->{$field};
} else { } else {
@ -7620,10 +7554,8 @@ abstract class CommonObject
} }
} }
} }
} elseif ($this->isFloat($info)) } elseif ($this->isFloat($info)) {
{ if ($this->isForcedToNullIfZero($info)) {
if ($this->isForcedToNullIfZero($info))
{
if (empty($obj->{$field})) $this->{$field} = null; if (empty($obj->{$field})) $this->{$field} = null;
else $this->{$field} = (double) $obj->{$field}; else $this->{$field} = (double) $obj->{$field};
} else { } else {