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