| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * select.tpl |
| 5 | * |
| 6 | * Template for constructing a select input tag. |
| 7 | * |
| 8 | * The following variables are available in this template: |
| 9 | * string $name The name of the select input |
| 10 | * array $aValues An associative array corresponding to each |
| 11 | * select option where keys must be used as |
| 12 | * the option value and the values must be used |
| 13 | * as the option text |
| 14 | * boolean $bUsekeys When FALSE, the value of each option should |
| 15 | * be the same as the option text instead of |
| 16 | * using the array key for the option value |
| 17 | * boolean $multiple When TRUE, a multiple select list should be |
| 18 | * shown. |
| 19 | * array $default An array of option values that should be |
| 20 | * selected by default (only will contain one |
| 21 | * array element unless this is a multiple select |
| 22 | * list) |
| 23 | * array $aAttribs Any extra attributes: an associative array, where |
| 24 | * keys are attribute names, and values (which are |
| 25 | * optional and might be null) should be placed |
| 26 | * in double quotes as attribute values (optional; |
| 27 | * may not be present) |
| 28 | * int $size The desired height of multiple select boxes (not |
| 29 | * applicable when $multiple is FALSE) |
| 30 | * |
| 31 | * @copyright © 1999-2008 The SquirrelMail Project Team |
| 32 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
| 33 | * @version $Id$ |
| 34 | * @package squirrelmail |
| 35 | * @subpackage templates |
| 36 | */ |
| 37 | |
| 38 | |
| 39 | // retrieve the template vars |
| 40 | // |
| 41 | extract($t); |
| 42 | |
| 43 | |
| 44 | if (isset($aAttribs['id'])) { |
| 45 | $label_open = '<label for="' . $aAttribs['id'] . '">'; |
| 46 | $label_close = '</label>'; |
| 47 | } else { |
| 48 | $label_open = ''; |
| 49 | $label_close = ''; |
| 50 | } |
| 51 | |
| 52 | |
| 53 | echo '<select name="' . $name . ($multiple ? '[]" multiple="multiple" size="' . $size . '"' : '"'); |
| 54 | foreach ($aAttribs as $key => $value) { |
| 55 | echo ' ' . $key . (is_null($value) ? '' : '="' . $value . '"'); |
| 56 | } |
| 57 | echo ">\n"; |
| 58 | |
| 59 | |
| 60 | foreach ($aValues as $key => $value) { |
| 61 | if (!$bUsekeys) $key = $value; |
| 62 | echo '<option value="' . $key . '"'; |
| 63 | |
| 64 | // multiple select lists have possibly more than one default selection |
| 65 | // |
| 66 | if ($multiple) { |
| 67 | foreach ($default as $def) { |
| 68 | if ((string)$def == (string)$key) { |
| 69 | echo ' selected="selected"'; |
| 70 | break; |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | // single select widget only needs to check for one default value |
| 76 | // (we could use the same code above, but we do this here to increase |
| 77 | // efficency and performance) |
| 78 | // |
| 79 | else if ((string)$default[0] == (string)$key) |
| 80 | echo ' selected="selected"'; |
| 81 | |
| 82 | echo '>' . $label_open . $value . $label_close . "</option>\n"; |
| 83 | } |
| 84 | echo "</select>\n"; |
| 85 | |
| 86 | |