| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  |  * Smarty plugin | 
					
						
							|  |  |  |  * ------------------------------------------------------------- | 
					
						
							|  |  |  |  * Type:     function
 | 
					
						
							|  |  |  |  * Name:     html_options | 
					
						
							| 
									
										
										
										
											2003-03-18 00:01:41 +00:00
										 |  |  |  * Input:      name       (optional) - string default "select" | 
					
						
							|  |  |  |  *             values     (required if no options supplied) - array | 
					
						
							|  |  |  |  *             options    (required if no values supplied) - associative array | 
					
						
							|  |  |  |  *             selected   (optional) - string default not set | 
					
						
							|  |  |  |  *             output     (required if not options supplied) - array | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  |  * Purpose:  Prints the list of <option> tags generated from | 
					
						
							|  |  |  |  *           the passed parameters | 
					
						
							|  |  |  |  * ------------------------------------------------------------- | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | function smarty_function_html_options($params, &$smarty) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-03-18 00:01:41 +00:00
										 |  |  |    require_once $smarty->_get_plugin_filepath('shared','escape_special_chars'); | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2003-03-18 09:17:51 +00:00
										 |  |  |    $name = null; | 
					
						
							| 
									
										
										
										
											2003-03-18 00:01:41 +00:00
										 |  |  |    $values = null; | 
					
						
							|  |  |  |    $options = null; | 
					
						
							|  |  |  |    $selected = array(); | 
					
						
							|  |  |  |    $output = null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    $extra = ''; | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |    foreach($params as $_key => $_val) {	 | 
					
						
							|  |  |  |       switch($_key) { | 
					
						
							|  |  |  |       case 'name': | 
					
						
							|  |  |  | 	 $$_key = (string)$_val; | 
					
						
							|  |  |  | 	 break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       case 'options': | 
					
						
							|  |  |  | 	 $$_key = (array)$_val; | 
					
						
							|  |  |  | 	 break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       case 'selected': | 
					
						
							|  |  |  |       case 'values': | 
					
						
							|  |  |  |       case 'output': | 
					
						
							|  |  |  | 	 $$_key = array_values((array)$_val);       | 
					
						
							|  |  |  | 	 break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       default: | 
					
						
							|  |  |  | 	 $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"'; | 
					
						
							|  |  |  | 	 break;					 | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |    } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    if (!isset($options) && !isset($values)) | 
					
						
							|  |  |  |       return ''; /* raise error here? */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    $_html_result = ''; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    if (is_array($options)) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       foreach ($options as $_key=>$_val) | 
					
						
							|  |  |  | 	 $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected);       | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |    } else {   | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       foreach ((array)$values as $_i=>$_key) { | 
					
						
							|  |  |  | 	 $_val = isset($output[$_i]) ? $output[$_i] : ''; | 
					
						
							|  |  |  | 	 $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected);       | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    if(!empty($name)) { | 
					
						
							|  |  |  |       $_html_result = '<select name="' . $name . '"' . $extra . '>' . "\n" . $_html_result . '</select>' . "\n"; | 
					
						
							|  |  |  |    } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    return $_html_result; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-01 15:18:27 +00:00
										 |  |  | function smarty_function_html_options_optoutput($key, $value, $selected) { | 
					
						
							| 
									
										
										
										
											2003-03-18 00:01:41 +00:00
										 |  |  |    if(!is_array($value)) { | 
					
						
							|  |  |  |       $_html_result = '<option label="' . smarty_function_escape_special_chars($value) . '" value="' .  | 
					
						
							|  |  |  | 	 smarty_function_escape_special_chars($key) . '"'; | 
					
						
							|  |  |  |       if (in_array($key, $selected)) | 
					
						
							|  |  |  | 	 $_html_result .= ' selected="selected"'; | 
					
						
							|  |  |  |       $_html_result .= '>' . smarty_function_escape_special_chars($value) . '</option>' . "\n"; | 
					
						
							|  |  |  |    } else { | 
					
						
							|  |  |  |       $_html_result = smarty_function_html_options_optgroup($key, $value, $selected); | 
					
						
							|  |  |  |    } | 
					
						
							|  |  |  |    return $_html_result;	 | 
					
						
							| 
									
										
										
										
											2002-11-01 15:18:27 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function smarty_function_html_options_optgroup($key, $values, $selected) { | 
					
						
							| 
									
										
										
										
											2003-03-18 21:04:13 +00:00
										 |  |  |    $optgroup_html = '<optgroup label="' . smarty_function_escape_special_chars($key) . '">' . "\n"; | 
					
						
							| 
									
										
										
										
											2003-03-18 00:01:41 +00:00
										 |  |  |    foreach ($values as $key => $value) { | 
					
						
							|  |  |  |       $optgroup_html .= smarty_function_html_options_optoutput($key, $value, $selected); | 
					
						
							|  |  |  |    } | 
					
						
							|  |  |  |    $optgroup_html .= "</optgroup>\n"; | 
					
						
							|  |  |  |    return $optgroup_html; | 
					
						
							| 
									
										
										
										
											2002-11-01 15:18:27 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  | /* vim: set expandtab: */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ?>
 |