Add method to load type code from dictionary

This commit is contained in:
Jean-François Ferry 2014-03-15 23:58:16 +01:00 committed by jfefe
parent 04aa373282
commit eb2c274525

View File

@ -135,6 +135,63 @@ class FormResource
if ($outputmode) return $outarray;
return $out;
}
/**
* Return html list of tickets type
*
* @param string $selected Id du type pre-selectionne
* @param string $htmlname Nom de la zone select
* @param string $filtertype To filter on field type in llx_c_ticketsup_type (array('code'=>xx,'label'=>zz))
* @param int $format 0=id+libelle, 1=code+code, 2=code+libelle, 3=id+code
* @param int $empty 1=peut etre vide, 0 sinon
* @param int $noadmininfo 0=Add admin info, 1=Disable admin info
* @param int $maxlength Max length of label
* @return void
*/
function select_types_resource($selected='',$htmlname='type_resource',$filtertype='',$format=0, $empty=0, $noadmininfo=0,$maxlength=0)
{
global $langs,$user;
$resourcestat = new Resource($this->db);
dol_syslog(get_class($this)."::select_types_resource ".$selected.", ".$htmlname.", ".$filtertype.", ".$format,LOG_DEBUG);
$filterarray=array();
if ($filtertype != '' && $filtertype != '-1') $filterarray=explode(',',$filtertype);
$resourcestat->load_cache_code_type_resource();
print '<select id="select'.$htmlname.'" class="flat select_tickettype" name="'.$htmlname.'">';
if ($empty) print '<option value="">&nbsp;</option>';
if (is_array($resourcestat->cache_code_type_resource) && count($resourcestat->cache_code_type_resource))
{
foreach($resourcestat->cache_code_type_resource as $id => $arraytypes)
{
// We discard empty line if showempty is on because an empty line has already been output.
if ($empty && empty($arraytypes['code'])) continue;
if ($format == 0) print '<option value="'.$id.'"';
if ($format == 1) print '<option value="'.$arraytypes['code'].'"';
if ($format == 2) print '<option value="'.$arraytypes['code'].'"';
if ($format == 3) print '<option value="'.$id.'"';
// Si selected est text, on compare avec code, sinon avec id
if (preg_match('/[a-z]/i', $selected) && $selected == $arraytypes['code']) print ' selected="selected"';
elseif ($selected == $id) print ' selected="selected"';
print '>';
if ($format == 0) $value=($maxlength?dol_trunc($arraytypes['label'],$maxlength):$arraytypes['label']);
if ($format == 1) $value=$arraytypes['code'];
if ($format == 2) $value=($maxlength?dol_trunc($arraytypes['label'],$maxlength):$arraytypes['label']);
if ($format == 3) $value=$arraytypes['code'];
print $value?$value:'&nbsp;';
print '</option>';
}
}
print '</select>';
if ($user->admin && ! $noadmininfo) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
}
}