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