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