This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/includes/smarty/plugins/function.html_menu.php
2008-11-26 14:50:40 -08:00

41 lines
1.1 KiB
PHP

<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: html_menu
* Purpose: Get creates a html menu for associated records
* -------------------------------------------------------------
*/
function smarty_function_html_menu($params, &$smarty)
{
$conditions='';
extract($params);
if(empty($field)) $field = $name;
if(empty($id)) $id = $field;
$db = &DB();
$rs = & $db->Execute( $sql = sqlSelect($db, $assoc_table, "id,".$assoc_field, $conditions, $assoc_field));
#echo $sql;
$return = '<select id="'.$id.'" name="'. $field .'">';
if($default == "all" || $blank) $return .= '<option value="" selected></option>';
if($rs && $rs->RecordCount() > 0)
{
while(!$rs->EOF)
{
$return .= '<option value="' . $rs->fields['id'] . '"';
if($default == $rs->fields['id']) $return .= "selected";
$return .= '>' . $rs->fields["$assoc_field"] . '</option>';
$rs->MoveNext();
}
} else {
if( $default != "all") $return .= '<option value=""></option>';
}
$return .= '</select>';
echo $return;
}
?>