/** * espresso admin page select_input * Turns an array into a select fields * * @static * @access public * @param string $name field name * @param array $values option values, numbered array starting at 0, where each value is an array with a key 'text' (meaning text to display' and 'id' (meaning the internal value) * eg: array(1=>array('text'=>'Monday','id'=>1),2=>array('text'=>'Tuesday','id'=>2)...). or as an array of key-value pairs, where the key is to be used for the * select input's name, and the value will be the text shown to the user. Optionally you can also include an additional key of "class" which will add a specific class to the option for that value. * @param string $default default value * @param string $parameters extra paramaters * @param string $class css class * @param boolean $autosize whether to autosize the select or not * @return string html string for the select input */ public static function select_input($name, $values, $default = '', $parameters = '', $class = '', $autosize = true) { //if $values was submitted in the wrong format, convert it over if (!empty($values) && (!array_key_exists(0, $values) || !is_array($values[0]))) { $converted_values = array(); foreach ($values as $id => $text) { $converted_values[] = array('id' => $id, 'text' => $text); } $values = $converted_values; } //load formatter helper EE_Registry::instance()->load_helper('Formatter'); //EE_Registry::instance()->load_helper( 'Formatter' ); $field = '<select id="' . EEH_Formatter::ee_tep_output_string($name) . '" name="' . EEH_Formatter::ee_tep_output_string($name) . '"'; //Debug //EEH_Debug_Tools::printr( $values, '$values <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); if (EEH_Formatter::ee_tep_not_null($parameters)) { $field .= ' ' . $parameters; } if ($autosize) { $size = 'med'; for ($ii = 0, $ni = sizeof($values); $ii < $ni; $ii++) { if ($values[$ii]['text']) { if (strlen($values[$ii]['text']) > 5) { $size = 'wide'; } } } } else { $size = ''; } $field .= ' class="' . $class . ' ' . $size . '">'; if (empty($default) && isset($GLOBALS[$name])) { $default = stripslashes($GLOBALS[$name]); } for ($i = 0, $n = sizeof($values); $i < $n; $i++) { $field .= '<option value="' . $values[$i]['id'] . '"'; if ($default == $values[$i]['id']) { $field .= ' selected = "selected"'; } if (isset($values[$i]['class'])) { $field .= ' class="' . $values[$i]['class'] . '"'; } $field .= '>' . $values[$i]['text'] . '</option>'; } $field .= '</select>'; return $field; }