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