move the hook before send to a more efficient location
[squirrelmail.git] / src / options_highlight.php
CommitLineData
9d157cec 1<?php
895905c0 2
c57b0888 3/**
4 * options_highlight.php
5 *
76911253 6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
c57b0888 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Displays message highlighting options
10 *
11 * $Id$
12 */
ef870322 13
86725763 14/* Path for SquirrelMail required files. */
15define('SM_PATH','../');
16
17/* SquirrelMail required files. */
08185f2a 18require_once(SM_PATH . 'include/validate.php');
86725763 19require_once(SM_PATH . 'functions/display_messages.php');
20require_once(SM_PATH . 'functions/imap.php');
86725763 21require_once(SM_PATH . 'functions/plugin.php');
22require_once(SM_PATH . 'functions/strings.php');
23require_once(SM_PATH . 'functions/html.php');
9d157cec 24
fe369c70 25/* get globals */
26if (isset($_GET['action'])) {
27 $action = $_GET['action'];
28}
29if (isset($_GET['theid'])) {
30 $theid = $_GET['theid'];
31}
32if (isset($_GET['identname'])) {
33 $identname = $_GET['identname'];
34}
35if (isset($_GET['newcolor_choose'])) {
36 $newcolor_choose = $_GET['newcolor_choose'];
37}
38if (isset($_GET['newcolor_input'])) {
39 $newcolor_input = $_GET['newcolor_input'];
40}
41if (isset($_GET['color_type'])) {
42 $color_type = $_GET['color_type'];
43}
44if (isset($_GET['match_type'])) {
45 $match_type = $_GET['match_type'];
46}
47if (isset($_GET['value'])) {
48 $value = $_GET['value'];
49}
50
fe369c70 51/* end of get globals */
52
c57b0888 53function oh_opt( $val, $sel, $tit ) {
d79e01f5 54 echo "<option value=\"$val\"";
c57b0888 55 if ( $sel )
bd9bbfef 56 echo ' selected';
c57b0888 57 echo ">$tit</option>\n";
58}
e697b6cc 59
d79e01f5 60if (! isset($action)) {
61 $action = '';
62}
63if (! isset($message_highlight_list)) {
64 $message_highlight_list = array();
65}
66
8415b2d3 67if (isset($theid) && ($action == 'delete') ||
68 ($action == 'up') ||
69 ($action == 'down')) {
1c159927 70 $new_rules = array();
8415b2d3 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;
1c159927 95 }
96 $message_highlight_list = $new_rules;
97
98 setPref($data_dir, $username, 'hililist', serialize($message_highlight_list));
99
100 header( 'Location: options_highlight.php' );
d79e01f5 101 exit;
102} else if ($action == 'save') {
1c159927 103
d79e01f5 104 if ($color_type == 1) $newcolor = $newcolor_choose;
105 elseif ($color_type == 2) $newcolor = $newcolor_input;
106 else $newcolor = $color_type;
107
0f8a1ce9 108 $newcolor = str_replace('#', '', $newcolor);
109 $newcolor = str_replace('"', '', $newcolor);
110 $newcolor = str_replace('\'', '', $newcolor);
111 $value = str_replace(',', ' ', $value);
d79e01f5 112
1c159927 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));
d79e01f5 124}
125displayPageHeader($color, 'None');
c36ed9cf 126
6206f6c4 127echo
545238b1 128html_tag( 'table', "\n" .
129 html_tag( 'tr', "\n" .
6206f6c4 130 html_tag( 'td', '<center><b>' . _("Options") . ' - ' . _("Message Highlighting") . '</b></center>', 'left')
131 ),
f6536dcf 132 'center', $color[9], 'width="95%" border="0" cellpadding="1" cellspacing="0"' ) . "<br>\n" .
133html_tag( 'table', '', '', '', 'width="100%" border="0" cellpadding="1" cellspacing="0"' ) .
545238b1 134 html_tag( 'tr' ) . "\n" .
135 html_tag( 'td', '', 'left' );
136
137echo '<center>[<a href="options_highlight.php?action=add">' . _("New") . '</a>]'.
e697b6cc 138 ' - [<a href="options.php">'._("Done").'</a>]</center><br>'."\n";
8415b2d3 139$mhl_count = count($message_highlight_list);
140if ($mhl_count > 0) {
f6536dcf 141 echo html_tag( 'table', '', 'center', '', 'width="80%" border="0" cellpadding="3" cellspacing="0"' ) . "\n";
8415b2d3 142 for ($i=0; $i < $mhl_count; $i++) {
545238b1 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
8415b2d3 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
545238b1 174 echo html_tag( 'tr',
175 html_tag( 'td',
8415b2d3 176 $links,
545238b1 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";
d79e01f5 186 }
187 echo "</table>\n".
188 "<br>\n";
189} else {
190 echo '<center>' . _("No highlighting is defined") . "</center><br>\n".
191 "<br>\n";
192}
193if ($action == 'edit' || $action == 'add') {
d79e01f5 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 }
89465360 337 if ($action == 'edit' && isset($theid) && isset($message_highlight_list[$theid]['color'])) {
d79e01f5 338 for ($i=0; $i < 14; $i++) {
e1db998a 339 if ($color_list[$i] == $message_highlight_list[$theid]['color']) {
89465360 340 $selected_choose = ' checked';
341 ${"selected".$i} = ' selected';
342 continue;
cd928157 343 }
89465360 344 }
d79e01f5 345 }
545238b1 346
89465360 347 if ($action == 'edit' && isset($theid) && isset($message_highlight_list[$theid]['color'])) {
545238b1 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
d79e01f5 365 if (!isset($message_highlight_list[$theid]['color']))
366 $selected_choose = ' checked';
545238b1 367 else if ($pre_defined_color)
368 $selected_predefined = ' checked';
d79e01f5 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";
1c159927 374 if($action == 'edit')
89465360 375 echo '<input type="hidden" value="'.(isset($theid)?$theid:'').'" name="theid">' . "\n";
545238b1 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";
d79e01f5 379 echo _("Identifying name") . ":";
380 echo ' </b></td>' . "\n";
545238b1 381 echo html_tag( 'td', '', 'left' ) . "\n";
89465360 382 if ($action == 'edit' && isset($theid) && isset($message_highlight_list[$theid]['name']))
d79e01f5 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";
545238b1 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' );
d79e01f5 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=\"";
89465360 411 if ($selected_input && isset($theid)) echo $message_highlight_list[$theid]["color"];
d79e01f5 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
545238b1 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
d79e01f5 421 for($x = 0; $x < 5; $x++) {
545238b1 422 echo html_tag( 'tr' ) . "\n";
721d2a60 423 for($y = 0; $y < 19; $y++) {
d79e01f5 424 $gridindex = "$y,$x";
425 $gridcolor = $new_color_list[$gridindex];
545238b1 426 $selected = ($gridcolor == $current_color) ? ' checked' : '' ;
427 echo html_tag( 'td', '<input type="radio" name="color_type" value="#' . $gridcolor .'"' . $selected . '>', 'left', $gridcolor, 'colspan="2"' );
721d2a60 428 }
429 echo "</tr>\n";
d79e01f5 430 }
431 echo "</table>\n";
bd9bbfef 432 echo "</td></tr>\n";
d79e01f5 433
545238b1 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";
d79e01f5 437 echo " <select name=match_type>\n";
438 oh_opt( 'from',
89465360 439 (isset($theid)?$message_highlight_list[$theid]['match_type'] == 'from':1),
d79e01f5 440 _("From") );
441 oh_opt( 'to',
89465360 442 (isset($theid)?$message_highlight_list[$theid]['match_type'] == 'to':0),
d79e01f5 443 _("To") );
444 oh_opt( 'cc',
89465360 445 (isset($theid)?$message_highlight_list[$theid]['match_type'] == 'cc':0),
d79e01f5 446 _("Cc") );
447 oh_opt( 'to_cc',
89465360 448 (isset($theid)?$message_highlight_list[$theid]['match_type'] == 'to_cc':0),
d79e01f5 449 _("To or Cc") );
450 oh_opt( 'subject',
89465360 451 (isset($theid)?$message_highlight_list[$theid]['match_type'] == 'subject':0),
d79e01f5 452 _("Subject") );
453 echo " </select>\n";
454 echo '<b>' . _("Matches") . ':</b> ';
89465360 455 if ($action == 'edit' && isset($theid) && isset($message_highlight_list[$theid]['value']))
d79e01f5 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}
468do_hook('options_highlight_bottom');
9d157cec 469?>
f6536dcf 470</table></body></html>