Happy 2014
[squirrelmail.git] / templates / default / edit_list_associative_widget.tpl
CommitLineData
282f8e7c 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
32FIXME: 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 *
701e7bee 41 * @copyright 1999-2014 The SquirrelMail Project Team
282f8e7c 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//
51extract($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?
57if ($use_input_widget) {
58 echo _("Add") . '&nbsp;' . $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
88
89// Construct the select input showing all current values in the list
90//
91echo '<select name="new_' . $name . '[]" multiple="multiple" size="' . $select_height . '"';
92
93$onchange = '';
94foreach ($aAttribs as $key => $value) {
95 if (strtolower($key) == 'onchange' && $javascript_on) {
96 $onchange = $value;
97 continue;
98 }
99 echo ' ' . $key . (is_null($value) ? '' : '="' . $value . '"');
100}
101
102// 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 " = "
103if ($javascript_on) {
104 echo ' onchange="';
105 if (!empty($onchange)) echo $onchange;
106 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; } }"';
107// NOTE: i=f-1; j=e-1 is in lieu of break 2
108}
109
110echo ">\n";
111
112
113if (is_array($current_value))
114 $selected = $current_value;
115else
116 $selected = array($current_value);
117
118
119// Add each possible value to the select list.
120//
121foreach ($possible_values as $key => $value) {
122
123 // Start the next new option string.
124 //
125 echo '<option value="' . urlencode($key) . '"';
126
127 // having a selected item in the edit list doesn't have
128 // any meaning, but maybe someone will think of a way to
129 // use it, so we might as well put the code in
130 //
131 foreach ($selected as $default) {
132 if ((string)$default == (string)$key) {
133 echo ' selected="selected"';
134 break;
135 }
136 }
137
138 // Add the display value to our option string.
139 //
140 echo '>' . sm_encode_html_special_chars($key) . ' = ';
141
142 if ($poss_value_folders) {
143 foreach ($poss_value_folders as $real_value => $disp_value) {
144 if ( is_array($disp_value) ) {
145 foreach ($disp_value as $folder_info) {
146 if ($value == $folder_info['unformatted']) {
147 echo sm_encode_html_special_chars(str_replace('&nbsp;', '', $folder_info['formatted']));
148 break 2;
149 }
150 }
151 }
152 else
153 if ($value == $disp_value) {
154 echo sm_encode_html_special_chars($disp_value);
155 break;
156 }
157 }
158 }
159 else
160 echo sm_encode_html_special_chars($value);
161
162 echo "</option>\n";
163
164}
165
166echo '</select>';
167
168
169// Construct the delete input
170//
171if (!empty($possible_values) && $use_delete_widget)
172 echo '<br />' . $checkbox_widget . '&nbsp;<label for="delete_' . $name . '">'
173 . _("Delete Selected") . '</label>';