| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * edit_list_associative_widget.tpl |
| 5 | * |
| 6 | * Template for constructing an associative edit list. |
| 7 | * |
| 8 | * The following variables are available in this template: |
| 9 | * |
| 10 | * string $name The name of the edit list |
| 11 | * mixed $current_value The currently selected value(s) |
| 12 | * array $possible_values The original list of options in the edit list |
| 13 | * array $poss_value_folders When not empty, contains a list of names |
| 14 | * to be used to populate a drop-down selection |
| 15 | * list for the value input (instead of the |
| 16 | * $input_value_widget textual input). If any |
| 17 | * of the values is an array, it is assumed to |
| 18 | * be an IMAP folder list in the format given |
| 19 | * by sqimap_mailbox_list() |
| 20 | * string $folder_filter Controls the folders listed by |
| 21 | * $poss_value_folders. See $flag argument in |
| 22 | * the sqimap_mailbox_option_list() function |
| 23 | * boolean $use_input_widget Whether or not to present the key/value inputs |
| 24 | * boolean $use_delete_widget Whether or not to present the $checkbox_widget |
| 25 | * string $checkbox_widget A preconstructed checkbox used for deleting |
| 26 | * elements from the edit list |
| 27 | * string $input_key_widget A preconstructed input text box used |
| 28 | * for adding new element keys to the edit list |
| 29 | * string $input_value_widget A preconstructed input text box used |
| 30 | * for adding new element values to the edit list |
| 31 | * int $select_height The size of the edit list select widget |
| 32 | FIXME: which inputs to use $aAttribs for? currently only the <select> tag |
| 33 | * array $aAttribs Any extra attributes: an associative array, |
| 34 | * where keys are attribute names, and values |
| 35 | * (which are optional and might be null) |
| 36 | * should be placed in double quotes as attribute |
| 37 | * values (optional; may not be present) |
| 38 | * string $trailing_text Any text given by the caller to be displayed |
| 39 | * after the edit list input |
| 40 | * |
| 41 | * @copyright 1999-2020 The SquirrelMail Project Team |
| 42 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
| 43 | * @version $Id$ |
| 44 | * @package squirrelmail |
| 45 | * @subpackage templates |
| 46 | */ |
| 47 | |
| 48 | |
| 49 | // retrieve the template vars |
| 50 | // |
| 51 | extract($t); |
| 52 | |
| 53 | |
| 54 | // Construct the add key/value inputs |
| 55 | // |
| 56 | //FIXME implement poss_key_folders here? probably not worth the trouble, is there a use case? |
| 57 | if ($use_input_widget) { |
| 58 | echo _("Add") . ' ' . $input_key_widget . ' '; |
| 59 | |
| 60 | // FIXME: shall we allow these "poss value folders" (folder list selection for edit list values) for NON-Associative EDIT_LIST widgets? |
| 61 | if ($poss_value_folders) { |
| 62 | echo '<select name="add_' . $name . '_value">'; |
| 63 | |
| 64 | // Add each possible value to the select list |
| 65 | foreach ($poss_value_folders as $real_value => $disp_value) { |
| 66 | |
| 67 | if ( is_array($disp_value) ) { |
| 68 | // For folder list, we passed in the array of boxes |
| 69 | $new_option = sqimap_mailbox_option_list(0, 0, 0, $disp_value, $folder_filter); |
| 70 | |
| 71 | } else { |
| 72 | // Start the next new option string |
| 73 | $new_option = '<option value="' . sm_encode_html_special_chars($real_value) . '"'; |
| 74 | |
| 75 | // Add the display value to our option string |
| 76 | $new_option .= '>' . sm_encode_html_special_chars($disp_value) . "</option>\n"; |
| 77 | } |
| 78 | // And add the new option string to our select tag |
| 79 | echo $new_option; |
| 80 | } |
| 81 | // Close the select tag and return our happy result |
| 82 | echo '</select>'; |
| 83 | } |
| 84 | else |
| 85 | echo $input_value_widget . '<br />'; |
| 86 | } |
| 87 | if (!empty($trailing_text)) |
| 88 | echo ($trailing_text_small ? '<small>' : '') . ($trailing_text_is_html ? $trailing_text : sm_encode_html_special_chars($trailing_text)) . ($trailing_text_small ? '</small>' : '') . '<br />'; |
| 89 | |
| 90 | |
| 91 | // Construct the select input showing all current values in the list |
| 92 | // |
| 93 | echo '<select name="new_' . $name . '[]" multiple="multiple" size="' . $select_height . '"'; |
| 94 | |
| 95 | $onchange = ''; |
| 96 | foreach ($aAttribs as $key => $value) { |
| 97 | if (strtolower($key) == 'onchange' && $javascript_on) { |
| 98 | $onchange = $value; |
| 99 | continue; |
| 100 | } |
| 101 | echo ' ' . $key . (is_null($value) ? '' : '="' . $value . '"'); |
| 102 | } |
| 103 | |
| 104 | // FIXME: this can be fooled by having the delimiter " = " in a key value - in general, we may want to use a different delimiter other than " = " |
| 105 | if ($javascript_on) { |
| 106 | echo ' onchange="'; |
| 107 | if (!empty($onchange)) echo $onchange; |
| 108 | echo ' if (typeof(window.addinput_key_' . $name . ') == \'undefined\') { var f = document.forms.length; var i = 0; var pos = -1; while( pos == -1 && i < f ) { var e = document.forms[i].elements.length; var j = 0; while( pos == -1 && j < e ) { if ( document.forms[i].elements[j].type == \'text\' && document.forms[i].elements[j].name == \'add_' . $name . '_key\' ) { pos = j; j=e-1; i=f-1; } j++; } i++; } if( pos >= 0 ) { window.addinput_key_' . $name . ' = document.forms[i-1].elements[pos]; } } if (typeof(window.addinput_value_' . $name . ') == \'undefined\') { var f = document.forms.length; var i = 0; var pos = -1; while( pos == -1 && i < f ) { var e = document.forms[i].elements.length; var j = 0; while( pos == -1 && j < e ) { if ( document.forms[i].elements[j].type == \'text\' && document.forms[i].elements[j].name == \'add_' . $name . '_value\' ) { pos = j; j=e-1; i=f-1; } j++; } i++; } if( pos >= 0 ) { window.addinput_value_' . $name . ' = document.forms[i-1].elements[pos]; } } for (x = 0; x < this.length; x++) { if (this.options[x].selected) { pos = this.options[x].text.indexOf(\' = \'); if (pos > -1) { window.addinput_key_' . $name . '.value = this.options[x].text.substr(0, pos); if (typeof(window.addinput_value_' . $name . ') != \'undefined\') window.addinput_value_' . $name . '.value = this.options[x].text.substr(pos + 3); } break; } }"'; |
| 109 | // NOTE: i=f-1; j=e-1 is in lieu of break 2 |
| 110 | } |
| 111 | |
| 112 | echo ">\n"; |
| 113 | |
| 114 | |
| 115 | if (is_array($current_value)) |
| 116 | $selected = $current_value; |
| 117 | else |
| 118 | $selected = array($current_value); |
| 119 | |
| 120 | |
| 121 | // Add each possible value to the select list. |
| 122 | // |
| 123 | foreach ($possible_values as $key => $value) { |
| 124 | |
| 125 | // Start the next new option string. |
| 126 | // |
| 127 | echo '<option value="' . urlencode($key) . '"'; |
| 128 | |
| 129 | // having a selected item in the edit list doesn't have |
| 130 | // any meaning, but maybe someone will think of a way to |
| 131 | // use it, so we might as well put the code in |
| 132 | // |
| 133 | foreach ($selected as $default) { |
| 134 | if ((string)$default == (string)$key) { |
| 135 | echo ' selected="selected"'; |
| 136 | break; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | // Add the display value to our option string. |
| 141 | // |
| 142 | echo '>' . sm_encode_html_special_chars($key) . ' = '; |
| 143 | |
| 144 | if ($poss_value_folders) { |
| 145 | foreach ($poss_value_folders as $real_value => $disp_value) { |
| 146 | if ( is_array($disp_value) ) { |
| 147 | foreach ($disp_value as $folder_info) { |
| 148 | if ($value == $folder_info['unformatted']) { |
| 149 | echo sm_encode_html_special_chars(str_replace(' ', '', $folder_info['formatted'])); |
| 150 | break 2; |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | else |
| 155 | if ($value == $disp_value) { |
| 156 | echo sm_encode_html_special_chars($disp_value); |
| 157 | break; |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | else |
| 162 | echo sm_encode_html_special_chars($value); |
| 163 | |
| 164 | echo "</option>\n"; |
| 165 | |
| 166 | } |
| 167 | |
| 168 | echo '</select>'; |
| 169 | |
| 170 | |
| 171 | // Construct the delete input |
| 172 | // |
| 173 | if (!empty($possible_values) && $use_delete_widget) |
| 174 | echo '<br />' . $checkbox_widget . ' <label for="delete_' . $name . '">' |
| 175 | . _("Delete Selected") . '</label>'; |