centralise the "From"-header construction in functions/identities.php.
[squirrelmail.git] / src / options_highlight.php
1 <?php
2
3 /**
4 * options_highlight.php
5 *
6 * Displays message highlighting options
7 *
8 * @copyright &copy; 1999-2007 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package squirrelmail
12 * @subpackage prefs
13 */
14
15 /**
16 * Include the SquirrelMail initialization file.
17 */
18 require('../include/init.php');
19
20 // include_once(SM_PATH . 'functions/imap.php');
21 require_once(SM_PATH . 'functions/forms.php');
22
23 /* get globals */
24 sqGetGlobalVar('action', $action);
25 sqGetGlobalVar('theid', $theid);
26 sqGetGlobalVar('identname', $identname);
27 sqGetGlobalVar('newcolor_choose', $newcolor_choose);
28 sqGetGlobalVar('newcolor_input', $newcolor_input);
29 sqGetGlobalVar('color_type', $color_type);
30 sqGetGlobalVar('match_type', $match_type);
31 sqGetGlobalVar('value', $value);
32
33 /* end of get globals */
34
35 function oh_opt( $val, $sel, $tit ) {
36 echo "<option value=\"$val\"";
37 if ( $sel )
38 echo ' selected="selected"';
39 echo ">$tit</option>\n";
40 }
41
42 if (! isset($action)) {
43 $action = '';
44 }
45 if (! isset($message_highlight_list)) {
46 $message_highlight_list = array();
47 }
48
49 if (isset($theid) && ($action == 'delete') ||
50 ($action == 'up') ||
51 ($action == 'down')) {
52 $new_rules = array();
53 switch($action) {
54 case('delete'):
55 foreach($message_highlight_list as $rid => $rule) {
56 if($rid != $theid) {
57 $new_rules[] = $rule;
58 }
59 }
60 break;
61 case('down'):
62 $theid++;
63 case('up'):
64 foreach($message_highlight_list as $rid => $rule) {
65 if($rid == $theid) {
66 $temp_rule = $new_rules[$rid-1];
67 $new_rules[$rid-1] = $rule;
68 $new_rules[$rid] = $temp_rule;
69 } else {
70 $new_rules[$rid] = $rule;
71 }
72 }
73 break;
74 default:
75 $new_rules = $message_highlight_list;
76 break;
77 }
78 $message_highlight_list = $new_rules;
79
80 setPref($data_dir, $username, 'hililist', serialize($message_highlight_list));
81
82 header( 'Location: ' .get_location(). '/options_highlight.php' );
83 exit;
84 } else if ($action == 'save') {
85
86 if ($color_type == 1) $newcolor = $newcolor_choose;
87 elseif ($color_type == 2) $newcolor = $newcolor_input;
88 else $newcolor = $color_type;
89
90 $newcolor = str_replace('#', '', $newcolor);
91 $newcolor = str_replace('"', '', $newcolor);
92 $newcolor = str_replace('\'', '', $newcolor);
93 $value = str_replace(',', ' ', $value);
94
95 if(isset($theid)) {
96 $message_highlight_list[$theid] =
97 array( 'name' => $identname, 'color' => $newcolor,
98 'value' => $value, 'match_type' => $match_type );
99 } else {
100 $message_highlight_list[] =
101 array( 'name' => $identname, 'color' => $newcolor,
102 'value' => $value, 'match_type' => $match_type );
103 }
104
105 setPref($data_dir, $username, 'hililist', serialize($message_highlight_list));
106 }
107 displayPageHeader($color);
108
109 /**
110 * Display the current rule list
111 */
112 $rules = array();
113 foreach($message_highlight_list as $index=>$rule) {
114 $a = array();
115
116 $a['Name'] = htmlspecialchars($rule['name']);
117 $a['Color'] = $rule['color'];
118 $a['MatchField'] = '';
119 $a['MatchValue'] = htmlspecialchars($rule['value']);
120 switch ($rule['match_type']) {
121 case 'from' :
122 $a['MatchField'] = _("From");
123 break;
124 case 'to' :
125 $a['MatchField'] = _("To");
126 break;
127 case 'cc' :
128 $a['MatchField'] = _("Cc");
129 break;
130 case 'to_cc' :
131 $a['MatchField'] = _("To or Cc");
132 break;
133 case 'subject' :
134 $a['MatchField'] = _("subject");
135 break;
136 }
137
138 $rules[$index] = $a;
139 }
140
141 $oTemplate->assign('current_rules', $rules);
142
143 $oTemplate->assign('add_rule', 'options_highlight.php?action=add');
144 $oTemplate->assign('edit_rule', 'options_highlight.php?action=edit&amp;theid=');
145 $oTemplate->assign('delete_rule', 'options_highlight.php?action=delete&amp;theid=');
146 $oTemplate->assign('move_up', 'options_highlight.php?action=up&amp;theid=');
147 $oTemplate->assign('move_down', 'options_highlight.php?action=down&amp;theid=');
148
149 $oTemplate->display('options_highlight_list.tpl');
150
151 /**
152 * Optionally, display the add/edit dialog
153 */
154 if ($action == 'edit' || $action == 'add') {
155
156 $color_list[0] = '4444aa';
157 $color_list[1] = '44aa44';
158 $color_list[2] = 'aaaa44';
159 $color_list[3] = '44aaaa';
160 $color_list[4] = 'aa44aa';
161 $color_list[5] = 'aaaaff';
162 $color_list[6] = 'aaffaa';
163 $color_list[7] = 'ffffaa';
164 $color_list[8] = 'aaffff';
165 $color_list[9] = 'ffaaff';
166 $color_list[10] = 'aaaaaa';
167 $color_list[11] = 'bfbfbf';
168 $color_list[12] = 'dfdfdf';
169 $color_list[13] = 'ffffff';
170
171 # helpful color chart from http://www.visibone.com/colorlab/big.html
172 $new_color_list["0,0"] = 'cccccc';
173 $new_color_list["0,1"] = '999999';
174 $new_color_list["0,2"] = '666666';
175 $new_color_list["0,3"] = '333333';
176 $new_color_list["0,4"] = '000000';
177
178 # red
179 $new_color_list["1,0"] = 'ff0000';
180 $new_color_list["1,1"] = 'cc0000';
181 $new_color_list["1,2"] = '990000';
182 $new_color_list["1,3"] = '660000';
183 $new_color_list["1,4"] = '330000';
184
185 $new_color_list["2,0"] = 'ffcccc';
186 $new_color_list["2,1"] = 'cc9999';
187 $new_color_list["2,2"] = '996666';
188 $new_color_list["2,3"] = '663333';
189 $new_color_list["2,4"] = '330000';
190
191 $new_color_list["3,0"] = 'ffcccc';
192 $new_color_list["3,1"] = 'ff9999';
193 $new_color_list["3,2"] = 'ff6666';
194 $new_color_list["3,3"] = 'ff3333';
195 $new_color_list["3,4"] = 'ff0000';
196
197 # green
198 $new_color_list["4,0"] = '00ff00';
199 $new_color_list["4,1"] = '00cc00';
200 $new_color_list["4,2"] = '009900';
201 $new_color_list["4,3"] = '006600';
202 $new_color_list["4,4"] = '003300';
203
204 $new_color_list["5,0"] = 'ccffcc';
205 $new_color_list["5,1"] = '99cc99';
206 $new_color_list["5,2"] = '669966';
207 $new_color_list["5,3"] = '336633';
208 $new_color_list["5,4"] = '003300';
209
210 $new_color_list["6,0"] = 'ccffcc';
211 $new_color_list["6,1"] = '99ff99';
212 $new_color_list["6,2"] = '66ff66';
213 $new_color_list["6,3"] = '33ff33';
214 $new_color_list["6,4"] = '00ff00';
215
216 # blue
217 $new_color_list["7,0"] = '0000ff';
218 $new_color_list["7,1"] = '0000cc';
219 $new_color_list["7,2"] = '000099';
220 $new_color_list["7,3"] = '000066';
221 $new_color_list["7,4"] = '000033';
222
223 $new_color_list["8,0"] = 'ccccff';
224 $new_color_list["8,1"] = '9999cc';
225 $new_color_list["8,2"] = '666699';
226 $new_color_list["8,3"] = '333366';
227 $new_color_list["8,4"] = '000033';
228
229 $new_color_list["9,0"] = 'ccccff';
230 $new_color_list["9,1"] = '9999ff';
231 $new_color_list["9,2"] = '6666ff';
232 $new_color_list["9,3"] = '3333ff';
233 $new_color_list["9,4"] = '0000ff';
234
235 # yellow
236 $new_color_list["10,0"] = 'ffff00';
237 $new_color_list["10,1"] = 'cccc00';
238 $new_color_list["10,2"] = '999900';
239 $new_color_list["10,3"] = '666600';
240 $new_color_list["10,4"] = '333300';
241
242 $new_color_list["11,0"] = 'ffffcc';
243 $new_color_list["11,1"] = 'cccc99';
244 $new_color_list["11,2"] = '999966';
245 $new_color_list["11,3"] = '666633';
246 $new_color_list["11,4"] = '333300';
247
248 $new_color_list["12,0"] = 'ffffcc';
249 $new_color_list["12,1"] = 'ffff99';
250 $new_color_list["12,2"] = 'ffff66';
251 $new_color_list["12,3"] = 'ffff33';
252 $new_color_list["12,4"] = 'ffff00';
253
254 # cyan
255 $new_color_list["13,0"] = '00ffff';
256 $new_color_list["13,1"] = '00cccc';
257 $new_color_list["13,2"] = '009999';
258 $new_color_list["13,3"] = '006666';
259 $new_color_list["13,4"] = '003333';
260
261 $new_color_list["14,0"] = 'ccffff';
262 $new_color_list["14,1"] = '99cccc';
263 $new_color_list["14,2"] = '669999';
264 $new_color_list["14,3"] = '336666';
265 $new_color_list["14,4"] = '003333';
266
267 $new_color_list["15,0"] = 'ccffff';
268 $new_color_list["15,1"] = '99ffff';
269 $new_color_list["15,2"] = '66ffff';
270 $new_color_list["15,3"] = '33ffff';
271 $new_color_list["15,4"] = '00ffff';
272
273 # magenta
274 $new_color_list["16,0"] = 'ff00ff';
275 $new_color_list["16,1"] = 'cc00cc';
276 $new_color_list["16,2"] = '990099';
277 $new_color_list["16,3"] = '660066';
278 $new_color_list["16,4"] = '330033';
279
280 $new_color_list["17,0"] = 'ffccff';
281 $new_color_list["17,1"] = 'cc99cc';
282 $new_color_list["17,2"] = '996699';
283 $new_color_list["17,3"] = '663366';
284 $new_color_list["17,4"] = '330033';
285
286 $new_color_list["18,0"] = 'ffccff';
287 $new_color_list["18,1"] = 'ff99ff';
288 $new_color_list["18,2"] = 'ff66ff';
289 $new_color_list["18,3"] = 'ff33ff';
290 $new_color_list["18,4"] = 'ff00ff';
291
292 $selected_input = FALSE;
293 $selected_choose = FALSE;
294 $selected_predefined = FALSE;
295
296 $name = $action=='edit' && isset($theid) && isset($message_highlight_list[$theid]['name']) ? $message_highlight_list[$theid]['name'] : '';
297 $field = $action=='edit' && isset($theid) && isset($message_highlight_list[$theid]['match_type']) ? $message_highlight_list[$theid]['match_type'] : '';
298 $value = $action=='edit' && isset($theid) && isset($message_highlight_list[$theid]['value']) ? $message_highlight_list[$theid]['value'] : '';
299 $color = $action=='edit' && isset($theid) && isset($message_highlight_list[$theid]['color']) ? $message_highlight_list[$theid]['color'] : '';
300
301 if ($action == 'edit' && isset($theid) && isset($message_highlight_list[$theid]['color'])) {
302 for ($i=0; $i < 14; $i++) {
303 if ($color_list[$i] == $message_highlight_list[$theid]['color']) {
304 $selected_choose = TRUE;
305 continue;
306 }
307 }
308 }
309
310 $pre_defined_color = 0;
311 for($x = 0; $x < 5; $x++) {
312 for($y = 0; $y < 19; $y++) {
313 $gridindex = "$y,$x";
314 $gridcolor = $new_color_list[$gridindex];
315 if ($gridcolor == $color) {
316 $pre_defined_color = 1;
317 break;
318 }
319 }
320 }
321
322 if (isset($theid) && !isset($message_highlight_list[$theid]['color']))
323 $selected_choose = TRUE;
324 else if ($pre_defined_color)
325 $selected_predefined = TRUE;
326 else if ($selected_choose == '')
327 $selected_input = TRUE;
328
329 $oTemplate->assign('rule_name', $name);
330 $oTemplate->assign('rule_value', $value);
331 $oTemplate->assign('rule_field', $field);
332 $oTemplate->assign('rule_color', $color);
333 $oTemplate->assign('color_radio', ($selected_choose ? 1 : ($selected_input ? 2 : 0)));
334 $oTemplate->assign('color_input', ($selected_input ? $color : ''));
335
336 echo addForm('options_highlight.php', 'post', 'f').
337 addHidden('action', 'save');
338 if($action == 'edit') {
339 echo addHidden('theid', (isset($theid)?$theid:''));
340 }
341
342 $oTemplate->display('options_highlight_addedit.tpl');
343
344 echo "</form>\n";
345 }
346 do_hook('options_highlight_bottom', $null);
347
348 $oTemplate->display('footer.tpl');
349 ?>