Merge pull request #1130 from FHenry/3.4

Avoid php warning if extrafield "list from table" have bad settings
This commit is contained in:
Laurent Destailleur 2013-07-25 13:40:09 -07:00
commit 3ecb9c2dd8

View File

@ -677,49 +677,52 @@ class ExtraFields
} }
elseif ($type == 'sellist') elseif ($type == 'sellist')
{ {
$out='<select class="flat" name="options_'.$key.'">'; $out='<select class="flat" name="options_'.$key.'">';
$param_list=array_keys($param['options']); if (is_array($param['options'])) {
$InfoFieldList = explode(":", $param_list[0]); $param_list=array_keys($param['options']);
$InfoFieldList = explode(":", $param_list[0]);
// 0 1 : tableName
// 1 2 : label field name Nom du champ contenant le libelle // 0 1 : tableName
// 2 3 : key fields name (if differ of rowid) // 1 2 : label field name Nom du champ contenant le libelle
// 2 3 : key fields name (if differ of rowid)
$keyList='rowid';
$keyList='rowid';
if (count($InfoFieldList)==3)
$keyList=$InfoFieldList[2].' as rowid'; if (count($InfoFieldList)==3)
$keyList=$InfoFieldList[2].' as rowid';
$sql = 'SELECT '.$keyList.', '.$InfoFieldList[1];
$sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; $sql = 'SELECT '.$keyList.', '.$InfoFieldList[1];
//$sql.= ' WHERE entity = '.$conf->entity; $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0];
//$sql.= ' WHERE entity = '.$conf->entity;
dol_syslog(get_class($this).'::showInputField type=sellist sql='.$sql);
$resql = $this->db->query($sql); dol_syslog(get_class($this).'::showInputField type=sellist sql='.$sql);
$resql = $this->db->query($sql);
if ($resql)
{ if ($resql)
$out.='<option value="0">&nbsp;</option>';
$num = $this->db->num_rows($resql);
$i = 0;
if ($num)
{ {
while ($i < $num) $out.='<option value="0">&nbsp;</option>';
$num = $this->db->num_rows($resql);
$i = 0;
if ($num)
{ {
$obj = $this->db->fetch_object($resql); while ($i < $num)
$labeltoshow=dol_trunc($obj->$InfoFieldList[1],18);
if ($value==$obj->rowid)
{ {
$out.='<option value="'.$obj->rowid.'" selected="selected">'.$labeltoshow.'</option>'; $obj = $this->db->fetch_object($resql);
$labeltoshow=dol_trunc($obj->$InfoFieldList[1],18);
if ($value==$obj->rowid)
{
$out.='<option value="'.$obj->rowid.'" selected="selected">'.$labeltoshow.'</option>';
}
else
{
$out.='<option value="'.$obj->rowid.'" >'.$labeltoshow.'</option>';
}
$i++;
} }
else
{
$out.='<option value="'.$obj->rowid.'" >'.$labeltoshow.'</option>';
}
$i++;
} }
$this->db->free();
} }
$this->db->free();
} }
$out.='</select>'; $out.='</select>';
} }
@ -824,23 +827,25 @@ class ExtraFields
} }
elseif ($type == 'sellist') elseif ($type == 'sellist')
{ {
$param_list=array_keys($params['options']); if (is_array($params['options'])) {
$InfoFieldList = explode(":", $param_list[0]); $param_list=array_keys($params['options']);
$keyList='rowid'; $InfoFieldList = explode(":", $param_list[0]);
if (count($InfoFieldList)==3) $keyList='rowid';
$keyList=$InfoFieldList[2]; if (count($InfoFieldList)==3)
$keyList=$InfoFieldList[2];
$sql = 'SELECT '.$InfoFieldList[1];
$sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; $sql = 'SELECT '.$InfoFieldList[1];
$sql.= ' WHERE '.$keyList.'=\''.$this->db->escape($value).'\''; $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0];
//$sql.= ' AND entity = '.$conf->entity; $sql.= ' WHERE '.$keyList.'=\''.$this->db->escape($value).'\'';
dol_syslog(get_class($this).':showOutputField:$type=sellist sql='.$sql); //$sql.= ' AND entity = '.$conf->entity;
$resql = $this->db->query($sql); dol_syslog(get_class($this).':showOutputField:$type=sellist sql='.$sql);
if ($resql) $resql = $this->db->query($sql);
{ if ($resql)
$obj = $this->db->fetch_object($resql); {
$value=$obj->$InfoFieldList[1]; $obj = $this->db->fetch_object($resql);
$value=$obj->$InfoFieldList[1];
}
} }
} }
elseif ($type == 'radio') elseif ($type == 'radio')