Код:
function altSelect($fieldName, $classificatorName, $orderBy=1, $orderDirection=0, $multiply=false, $class='', $selectedArray=null, $defaultValue='', $options='') {
global $db;
$str = '';
$cl_tbl_Name = "Classificator_".$classificatorName;
$cl_ID = $classificatorName."_ID";
$cl_Name = $classificatorName."_Name";
$cl_Priority = $classificatorName."_Priority";
switch ($orderBy) {
case 1: $order = $cl_ID; break;
case 2: $order = $cl_Name; break;
case 3: $order = $cl_Priority; break;
}
switch ($orderDirection) {
case 0: $direction = "ASC"; break;
case 1: $direction = "DESC"; break;
}
if ($multiply) {
$multy = "multiple='multiple' size='10'";
}
else {
$multy = "";
}
if (!empty($class)) {
$className = "class='$class'";
}
else {
$className = "";
}
$q = "SELECT * FROM $cl_tbl_Name ORDER BY $order $direction";
$r = $db->get_results($q, ARRAY_A);
if ($db->num_rows) {
$str .= "<select name='f_".$fieldName."[]' $multy $className ".(!empty($options)?$options:'').">rn";
!empty($defaultValue) ? $str .= "<option value=''>$defaultValue</option>rn" : $str .= "";
foreach ($r as $k => $v) {
if (is_array($selectedArray)) {
if (in_array($v[$cl_ID], $selectedArray)) {
$selected = "selected='selected'";
}
else {
$selected = "";
}
}
else {
$selected = "";
}
$str .= "<option value='$v[$cl_ID]' $selected>$v[$cl_Name]</option>rn";
}
$str .= "</select>rn";
}
return $str;
}