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