phpdoc updates
[squirrelmail.git] / src / options_highlight.php
1 <?php
2
3 /**
4 * options_highlight.php
5 *
6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Displays message highlighting options
10 *
11 * $Id$
12 * @package squirrelmail
13 */
14
15 /** Path for SquirrelMail required files. */
16 define('SM_PATH','../');
17
18 /* SquirrelMail required files. */
19 require_once(SM_PATH . 'include/validate.php');
20 require_once(SM_PATH . 'functions/display_messages.php');
21 require_once(SM_PATH . 'functions/imap.php');
22 require_once(SM_PATH . 'functions/plugin.php');
23 require_once(SM_PATH . 'functions/strings.php');
24 require_once(SM_PATH . 'functions/html.php');
25 require_once(SM_PATH . 'functions/forms.php');
26
27 /* get globals */
28 sqGetGlobalVar('action', $action);
29 sqGetGlobalVar('theid', $theid);
30 sqGetGlobalVar('identname', $identname);
31 sqGetGlobalVar('newcolor_choose', $newcolor_choose);
32 sqGetGlobalVar('newcolor_input', $newcolor_input);
33 sqGetGlobalVar('color_type', $color_type);
34 sqGetGlobalVar('match_type', $match_type);
35 sqGetGlobalVar('value', $value);
36
37 /* end of get globals */
38
39 function oh_opt( $val, $sel, $tit ) {
40 echo "<option value=\"$val\"";
41 if ( $sel )
42 echo ' selected';
43 echo ">$tit</option>\n";
44 }
45
46 if (! isset($action)) {
47 $action = '';
48 }
49 if (! isset($message_highlight_list)) {
50 $message_highlight_list = array();
51 }
52
53 if (isset($theid) && ($action == 'delete') ||
54 ($action == 'up') ||
55 ($action == 'down')) {
56 $new_rules = array();
57 switch($action) {
58 case('delete'):
59 foreach($message_highlight_list as $rid => $rule) {
60 if($rid != $theid) {
61 $new_rules[] = $rule;
62 }
63 }
64 break;
65 case('down'):
66 $theid++;
67 case('up'):
68 foreach($message_highlight_list as $rid => $rule) {
69 if($rid == $theid) {
70 $temp_rule = $new_rules[$rid-1];
71 $new_rules[$rid-1] = $rule;
72 $new_rules[$rid] = $temp_rule;
73 } else {
74 $new_rules[$rid] = $rule;
75 }
76 }
77 break;
78 default:
79 $new_rules = $message_highlight_list;
80 break;
81 }
82 $message_highlight_list = $new_rules;
83
84 setPref($data_dir, $username, 'hililist', serialize($message_highlight_list));
85
86 header( 'Location: ' .get_location(). '/options_highlight.php' );
87 exit;
88 } else if ($action == 'save') {
89
90 if ($color_type == 1) $newcolor = $newcolor_choose;
91 elseif ($color_type == 2) $newcolor = $newcolor_input;
92 else $newcolor = $color_type;
93
94 $newcolor = str_replace('#', '', $newcolor);
95 $newcolor = str_replace('"', '', $newcolor);
96 $newcolor = str_replace('\'', '', $newcolor);
97 $value = str_replace(',', ' ', $value);
98
99 if(isset($theid)) {
100 $message_highlight_list[$theid] =
101 array( 'name' => $identname, 'color' => $newcolor,
102 'value' => $value, 'match_type' => $match_type );
103 } else {
104 $message_highlight_list[] =
105 array( 'name' => $identname, 'color' => $newcolor,
106 'value' => $value, 'match_type' => $match_type );
107 }
108
109 setPref($data_dir, $username, 'hililist', serialize($message_highlight_list));
110 }
111 displayPageHeader($color, 'None');
112
113 echo
114 html_tag( 'table', "\n" .
115 html_tag( 'tr', "\n" .
116 html_tag( 'td', '<center><b>' . _("Options") . ' - ' . _("Message Highlighting") . '</b></center>', 'left')
117 ),
118 'center', $color[9], 'width="95%" border="0" cellpadding="1" cellspacing="0"' ) . "<br>\n" .
119 html_tag( 'table', '', '', '', 'width="100%" border="0" cellpadding="1" cellspacing="0"' ) .
120 html_tag( 'tr' ) . "\n" .
121 html_tag( 'td', '', 'left' );
122
123 echo '<center>[<a href="options_highlight.php?action=add">' . _("New") . '</a>]'.
124 ' - [<a href="options.php">'._("Done").'</a>]</center><br>'."\n";
125 $mhl_count = count($message_highlight_list);
126 if ($mhl_count > 0) {
127 echo html_tag( 'table', '', 'center', '', 'width="80%" border="0" cellpadding="3" cellspacing="0"' ) . "\n";
128 for ($i=0; $i < $mhl_count; $i++) {
129 $match_type = '';
130 switch ($message_highlight_list[$i]['match_type'] ) {
131 case 'from' :
132 $match_type = _("From");
133 break;
134 case 'to' :
135 $match_type = _("To");
136 break;
137 case 'cc' :
138 $match_type = _("Cc");
139 break;
140 case 'to_cc' :
141 $match_type = _("To or Cc");
142 break;
143 case 'subject' :
144 $match_type = _("subject");
145 break;
146 }
147
148 $links = '<small>[<a href="options_highlight.php?action=edit&amp;theid=' . $i . '">' .
149 _("Edit") .
150 '</a>]&nbsp;[<a href="options_highlight.php?action=delete&amp;theid='. $i . '">' .
151 _("Delete");
152 if($i > 0) {
153 $links .= '</a>]&nbsp;[<a href="options_highlight.php?action=up&amp;theid='. $i . '">' . _("Up");
154 }
155 if($i+1 < $mhl_count) {
156 $links .= '</a>]&nbsp;[<a href="options_highlight.php?action=down&amp;theid='. $i . '">' . _("Down");
157 }
158 $links .= '</a>]</small>';
159
160 echo html_tag( 'tr',
161 html_tag( 'td',
162 $links,
163 'left', $color[4], 'width="20%" nowrap' ) .
164 html_tag( 'td',
165 htmlspecialchars($message_highlight_list[$i]['name']) ,
166 'left' ) .
167 html_tag( 'td',
168 $match_type . ' = ' .
169 htmlspecialchars($message_highlight_list[$i]['value']) ,
170 'left' ) ,
171 '', $message_highlight_list[$i]['color'] ) . "\n";
172 }
173 echo "</table>\n".
174 "<br>\n";
175 } else {
176 echo '<center>' . _("No highlighting is defined") . "</center><br>\n".
177 "<br>\n";
178 }
179 if ($action == 'edit' || $action == 'add') {
180
181 $color_list[0] = '4444aa';
182 $color_list[1] = '44aa44';
183 $color_list[2] = 'aaaa44';
184 $color_list[3] = '44aaaa';
185 $color_list[4] = 'aa44aa';
186 $color_list[5] = 'aaaaff';
187 $color_list[6] = 'aaffaa';
188 $color_list[7] = 'ffffaa';
189 $color_list[8] = 'aaffff';
190 $color_list[9] = 'ffaaff';
191 $color_list[10] = 'aaaaaa';
192 $color_list[11] = 'bfbfbf';
193 $color_list[12] = 'dfdfdf';
194 $color_list[13] = 'ffffff';
195
196 # helpful color chart from http://www.visibone.com/colorlab/big.html
197 $new_color_list["0,0"] = 'cccccc';
198 $new_color_list["0,1"] = '999999';
199 $new_color_list["0,2"] = '666666';
200 $new_color_list["0,3"] = '333333';
201 $new_color_list["0,4"] = '000000';
202
203 # red
204 $new_color_list["1,0"] = 'ff0000';
205 $new_color_list["1,1"] = 'cc0000';
206 $new_color_list["1,2"] = '990000';
207 $new_color_list["1,3"] = '660000';
208 $new_color_list["1,4"] = '330000';
209
210 $new_color_list["2,0"] = 'ffcccc';
211 $new_color_list["2,1"] = 'cc9999';
212 $new_color_list["2,2"] = '996666';
213 $new_color_list["2,3"] = '663333';
214 $new_color_list["2,4"] = '330000';
215
216 $new_color_list["3,0"] = 'ffcccc';
217 $new_color_list["3,1"] = 'ff9999';
218 $new_color_list["3,2"] = 'ff6666';
219 $new_color_list["3,3"] = 'ff3333';
220 $new_color_list["3,4"] = 'ff0000';
221
222 # green
223 $new_color_list["4,0"] = '00ff00';
224 $new_color_list["4,1"] = '00cc00';
225 $new_color_list["4,2"] = '009900';
226 $new_color_list["4,3"] = '006600';
227 $new_color_list["4,4"] = '003300';
228
229 $new_color_list["5,0"] = 'ccffcc';
230 $new_color_list["5,1"] = '99cc99';
231 $new_color_list["5,2"] = '669966';
232 $new_color_list["5,3"] = '336633';
233 $new_color_list["5,4"] = '003300';
234
235 $new_color_list["6,0"] = 'ccffcc';
236 $new_color_list["6,1"] = '99ff99';
237 $new_color_list["6,2"] = '66ff66';
238 $new_color_list["6,3"] = '33ff33';
239 $new_color_list["6,4"] = '00ff00';
240
241 # blue
242 $new_color_list["7,0"] = '0000ff';
243 $new_color_list["7,1"] = '0000cc';
244 $new_color_list["7,2"] = '000099';
245 $new_color_list["7,3"] = '000066';
246 $new_color_list["7,4"] = '000033';
247
248 $new_color_list["8,0"] = 'ccccff';
249 $new_color_list["8,1"] = '9999cc';
250 $new_color_list["8,2"] = '666699';
251 $new_color_list["8,3"] = '333366';
252 $new_color_list["8,4"] = '000033';
253
254 $new_color_list["9,0"] = 'ccccff';
255 $new_color_list["9,1"] = '9999ff';
256 $new_color_list["9,2"] = '6666ff';
257 $new_color_list["9,3"] = '3333ff';
258 $new_color_list["9,4"] = '0000ff';
259
260 # yellow
261 $new_color_list["10,0"] = 'ffff00';
262 $new_color_list["10,1"] = 'cccc00';
263 $new_color_list["10,2"] = '999900';
264 $new_color_list["10,3"] = '666600';
265 $new_color_list["10,4"] = '333300';
266
267 $new_color_list["11,0"] = 'ffffcc';
268 $new_color_list["11,1"] = 'cccc99';
269 $new_color_list["11,2"] = '999966';
270 $new_color_list["11,3"] = '666633';
271 $new_color_list["11,4"] = '333300';
272
273 $new_color_list["12,0"] = 'ffffcc';
274 $new_color_list["12,1"] = 'ffff99';
275 $new_color_list["12,2"] = 'ffff66';
276 $new_color_list["12,3"] = 'ffff33';
277 $new_color_list["12,4"] = 'ffff00';
278
279 # cyan
280 $new_color_list["13,0"] = '00ffff';
281 $new_color_list["13,1"] = '00cccc';
282 $new_color_list["13,2"] = '009999';
283 $new_color_list["13,3"] = '006666';
284 $new_color_list["13,4"] = '003333';
285
286 $new_color_list["14,0"] = 'ccffff';
287 $new_color_list["14,1"] = '99cccc';
288 $new_color_list["14,2"] = '669999';
289 $new_color_list["14,3"] = '336666';
290 $new_color_list["14,4"] = '003333';
291
292 $new_color_list["15,0"] = 'ccffff';
293 $new_color_list["15,1"] = '99ffff';
294 $new_color_list["15,2"] = '66ffff';
295 $new_color_list["15,3"] = '33ffff';
296 $new_color_list["15,4"] = '00ffff';
297
298 # magenta
299 $new_color_list["16,0"] = 'ff00ff';
300 $new_color_list["16,1"] = 'cc00cc';
301 $new_color_list["16,2"] = '990099';
302 $new_color_list["16,3"] = '660066';
303 $new_color_list["16,4"] = '330033';
304
305 $new_color_list["17,0"] = 'ffccff';
306 $new_color_list["17,1"] = 'cc99cc';
307 $new_color_list["17,2"] = '996699';
308 $new_color_list["17,3"] = '663366';
309 $new_color_list["17,4"] = '330033';
310
311 $new_color_list["18,0"] = 'ffccff';
312 $new_color_list["18,1"] = 'ff99ff';
313 $new_color_list["18,2"] = 'ff66ff';
314 $new_color_list["18,3"] = 'ff33ff';
315 $new_color_list["18,4"] = 'ff00ff';
316
317 $selected_input = FALSE;
318 $selected_i = null;
319 $selected_choose = FALSE;
320 $selected_predefined = FALSE;
321
322 for ($i=0; $i < 14; $i++) {
323 ${"selected".$i} = '';
324 }
325 if ($action == 'edit' && isset($theid) && isset($message_highlight_list[$theid]['color'])) {
326 for ($i=0; $i < 14; $i++) {
327 if ($color_list[$i] == $message_highlight_list[$theid]['color']) {
328 $selected_choose = TRUE;
329 $selected_i = $color_list[$i];
330 continue;
331 }
332 }
333 }
334
335 if ($action == 'edit' && isset($theid) && isset($message_highlight_list[$theid]['color'])) {
336 $current_color = $message_highlight_list[$theid]['color'];
337 }
338 else {
339 $current_color = '63aa7f';
340 }
341
342 $pre_defined_color = 0;
343 for($x = 0; $x < 5; $x++) {
344 for($y = 0; $y < 19; $y++) {
345 $gridindex = "$y,$x";
346 $gridcolor = $new_color_list[$gridindex];
347 if ($gridcolor == $current_color) {
348 $pre_defined_color = 1;
349 break;
350 }
351 }
352 }
353
354 if (isset($theid) && !isset($message_highlight_list[$theid]['color']))
355 $selected_choose = TRUE;
356 else if ($pre_defined_color)
357 $selected_predefined = TRUE;
358 else if ($selected_choose == '')
359 $selected_input = TRUE;
360
361 echo addForm('options_highlight.php', 'POST', 'f').
362 addHidden('action', 'save');
363 if($action == 'edit') {
364 echo addHidden('theid', (isset($theid)?$theid:''));
365 }
366 echo html_tag( 'table', '', 'center', '', 'width="80%" cellpadding="3" cellspacing="0" border="0"' ) . "\n";
367 echo html_tag( 'tr', '', '', $color[0] ) . "\n";
368 echo html_tag( 'td', '', 'right', '', 'nowrap' ) . "<b>\n";
369 echo _("Identifying name") . ":";
370 echo ' </b></td>' . "\n";
371 echo html_tag( 'td', '', 'left' ) . "\n";
372 if ($action == 'edit' && isset($theid) && isset($message_highlight_list[$theid]['name']))
373 $disp = $message_highlight_list[$theid]['name'];
374 else
375 $disp = '';
376 echo " ".addInput('identname', $disp);
377 echo " </td>\n";
378 echo " </tr>\n";
379 echo html_tag( 'tr', html_tag( 'td', '<small><small>&nbsp;</small></small>', 'left' ) ) ."\n";
380 echo html_tag( 'tr', '', '', $color[0] ) . "\n";
381 echo html_tag( 'td', '<b>'. _("Color") . ':</b>', 'right' );
382 echo html_tag( 'td', '', 'left' );
383 echo ' '.addRadioBox('color_type', $selected_choose, '1');
384
385 $selops = array (
386 $color_list[0] => _("Dark Blue"),
387 $color_list[1] => _("Dark Green"),
388 $color_list[2] => _("Dark Yellow"),
389 $color_list[3] => _("Dark Cyan"),
390 $color_list[4] => _("Dark Magenta"),
391 $color_list[5] => _("Light Blue"),
392 $color_list[6] => _("Light Green"),
393 $color_list[7] => _("Light Yellow"),
394 $color_list[8] => _("Light Cyan"),
395 $color_list[9] => _("Light Magenta"),
396 $color_list[10] => _("Dark Gray"),
397 $color_list[11] => _("Medium Gray"),
398 $color_list[12] => _("Light Gray"),
399 $color_list[13] => _("White") );
400
401 echo addSelect('newcolor_choose', $selops, $selected_i, TRUE);
402 echo "<br>\n";
403
404 echo ' '.addRadioBox('color_type', $selected_input, 2).
405 ' &nbsp;'. _("Other:") .
406 addInput('newcolor_input',
407 (($selected_input && isset($theid)) ? $message_highlight_list[$theid]['color'] : ''),
408 '7');
409 echo _("Ex: 63aa7f")."<br>\n";
410 echo " </td>\n";
411 echo " </tr>\n";
412
413 # Show grid of color choices
414 echo html_tag( 'tr', '', '', $color[0] ) . "\n";
415 echo html_tag( 'td', '', 'left', '', 'colspan="2"' );
416 echo html_tag( 'table', '', 'center', '', 'border=0 cellpadding="2" cellspacing="1"' ) . "\n";
417
418 for($x = 0; $x < 5; $x++) {
419 echo html_tag( 'tr' ) . "\n";
420 for($y = 0; $y < 19; $y++) {
421 $gridindex = "$y,$x";
422 $gridcolor = $new_color_list[$gridindex];
423 echo html_tag( 'td', addRadioBox('color_type', ($gridcolor == $current_color), '#'.$gridcolor),
424 'left', $gridcolor, 'colspan="2"' );
425 }
426 echo "</tr>\n";
427 }
428 echo "</table>\n";
429 echo "</td></tr>\n";
430
431 echo html_tag( 'tr', html_tag( 'td', '<small><small>&nbsp;</small></small>', 'left' ) ) . "\n";
432 echo html_tag( 'tr', '', '', $color[0] ) . "\n";
433 echo html_tag( 'td', '', 'center', '', 'colspan="2"' ) . "\n";
434 echo " <select name=match_type>\n";
435 oh_opt( 'from',
436 (isset($theid)?$message_highlight_list[$theid]['match_type'] == 'from':1),
437 _("From") );
438 oh_opt( 'to',
439 (isset($theid)?$message_highlight_list[$theid]['match_type'] == 'to':0),
440 _("To") );
441 oh_opt( 'cc',
442 (isset($theid)?$message_highlight_list[$theid]['match_type'] == 'cc':0),
443 _("Cc") );
444 oh_opt( 'to_cc',
445 (isset($theid)?$message_highlight_list[$theid]['match_type'] == 'to_cc':0),
446 _("To or Cc") );
447 oh_opt( 'subject',
448 (isset($theid)?$message_highlight_list[$theid]['match_type'] == 'subject':0),
449 _("Subject") );
450 echo " </select>\n";
451 echo '<b>' . _("Matches") . ':</b> ';
452 if ($action == 'edit' && isset($theid) && isset($message_highlight_list[$theid]['value']))
453 $disp = $message_highlight_list[$theid]['value'];
454 else
455 $disp = '';
456 echo ' '.addInput('value', $disp, 40);
457 echo " </td>\n";
458 echo " </tr>\n";
459 echo "</table>\n";
460 echo '<center><input type="submit" value="' . _("Submit") . "\"></center>\n";
461 echo "</form>\n";
462 }
463 do_hook('options_highlight_bottom');
464 ?>
465 </table></body></html>