removed local directory name used for testing.
[squirrelmail.git] / src / options_highlight.php
CommitLineData
9d157cec 1<?php
895905c0 2
c57b0888 3/**
4 * options_highlight.php
5 *
6c84ba1e 6 * Copyright (c) 1999-2005 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 *
30967a1e 11 * @version $Id$
8f6f9ba5 12 * @package squirrelmail
ca479ad1 13 * @subpackage prefs
c57b0888 14 */
ef870322 15
30967a1e 16/**
17 * Path for SquirrelMail required files.
18 * @ignore
19 */
86725763 20define('SM_PATH','../');
21
22/* SquirrelMail required files. */
08185f2a 23require_once(SM_PATH . 'include/validate.php');
ca479ad1 24include_once(SM_PATH . 'functions/display_messages.php');
25include_once(SM_PATH . 'functions/imap.php');
26include_once(SM_PATH . 'functions/plugin.php');
27include_once(SM_PATH . 'functions/strings.php');
28include_once(SM_PATH . 'functions/html.php');
29include_once(SM_PATH . 'functions/forms.php');
9d157cec 30
fe369c70 31/* get globals */
62366261 32sqGetGlobalVar('action', $action);
33sqGetGlobalVar('theid', $theid);
34sqGetGlobalVar('identname', $identname);
35sqGetGlobalVar('newcolor_choose', $newcolor_choose);
36sqGetGlobalVar('newcolor_input', $newcolor_input);
37sqGetGlobalVar('color_type', $color_type);
38sqGetGlobalVar('match_type', $match_type);
39sqGetGlobalVar('value', $value);
fe369c70 40
fe369c70 41/* end of get globals */
91e0dccc 42
c57b0888 43function oh_opt( $val, $sel, $tit ) {
d79e01f5 44 echo "<option value=\"$val\"";
c57b0888 45 if ( $sel )
e1728a7a 46 echo ' selected="selected"';
c57b0888 47 echo ">$tit</option>\n";
48}
e697b6cc 49
d79e01f5 50if (! isset($action)) {
51 $action = '';
52}
53if (! isset($message_highlight_list)) {
54 $message_highlight_list = array();
55}
56
8415b2d3 57if (isset($theid) && ($action == 'delete') ||
58 ($action == 'up') ||
59 ($action == 'down')) {
1c159927 60 $new_rules = array();
8415b2d3 61 switch($action) {
62 case('delete'):
63 foreach($message_highlight_list as $rid => $rule) {
64 if($rid != $theid) {
65 $new_rules[] = $rule;
66 }
67 }
68 break;
69 case('down'):
70 $theid++;
71 case('up'):
72 foreach($message_highlight_list as $rid => $rule) {
73 if($rid == $theid) {
74 $temp_rule = $new_rules[$rid-1];
75 $new_rules[$rid-1] = $rule;
76 $new_rules[$rid] = $temp_rule;
77 } else {
78 $new_rules[$rid] = $rule;
79 }
80 }
81 break;
82 default:
83 $new_rules = $message_highlight_list;
84 break;
1c159927 85 }
134e4174 86 $message_highlight_list = $new_rules;
1c159927 87
88 setPref($data_dir, $username, 'hililist', serialize($message_highlight_list));
89
d7746ca5 90 header( 'Location: ' .get_location(). '/options_highlight.php' );
d79e01f5 91 exit;
92} else if ($action == 'save') {
1c159927 93
d79e01f5 94 if ($color_type == 1) $newcolor = $newcolor_choose;
95 elseif ($color_type == 2) $newcolor = $newcolor_input;
96 else $newcolor = $color_type;
97
0f8a1ce9 98 $newcolor = str_replace('#', '', $newcolor);
99 $newcolor = str_replace('"', '', $newcolor);
100 $newcolor = str_replace('\'', '', $newcolor);
101 $value = str_replace(',', ' ', $value);
d79e01f5 102
1c159927 103 if(isset($theid)) {
91e0dccc 104 $message_highlight_list[$theid] =
1c159927 105 array( 'name' => $identname, 'color' => $newcolor,
106 'value' => $value, 'match_type' => $match_type );
107 } else {
91e0dccc 108 $message_highlight_list[] =
1c159927 109 array( 'name' => $identname, 'color' => $newcolor,
110 'value' => $value, 'match_type' => $match_type );
111 }
112
113 setPref($data_dir, $username, 'hililist', serialize($message_highlight_list));
d79e01f5 114}
115displayPageHeader($color, 'None');
c36ed9cf 116
6206f6c4 117echo
545238b1 118html_tag( 'table', "\n" .
119 html_tag( 'tr', "\n" .
6206f6c4 120 html_tag( 'td', '<center><b>' . _("Options") . ' - ' . _("Message Highlighting") . '</b></center>', 'left')
121 ),
39bfea8f 122 'center', $color[9], 'width="95%" border="0" cellpadding="1" cellspacing="0"' ) . "<br />\n" .
91e0dccc 123html_tag( 'table', '', '', '', 'width="100%" border="0" cellpadding="1" cellspacing="0"' ) .
545238b1 124 html_tag( 'tr' ) . "\n" .
125 html_tag( 'td', '', 'left' );
126
127echo '<center>[<a href="options_highlight.php?action=add">' . _("New") . '</a>]'.
39bfea8f 128 ' - [<a href="options.php">'._("Done").'</a>]</center><br />'."\n";
8415b2d3 129$mhl_count = count($message_highlight_list);
130if ($mhl_count > 0) {
f6536dcf 131 echo html_tag( 'table', '', 'center', '', 'width="80%" border="0" cellpadding="3" cellspacing="0"' ) . "\n";
8415b2d3 132 for ($i=0; $i < $mhl_count; $i++) {
545238b1 133 $match_type = '';
134 switch ($message_highlight_list[$i]['match_type'] ) {
135 case 'from' :
136 $match_type = _("From");
137 break;
138 case 'to' :
139 $match_type = _("To");
140 break;
141 case 'cc' :
142 $match_type = _("Cc");
143 break;
144 case 'to_cc' :
145 $match_type = _("To or Cc");
146 break;
147 case 'subject' :
148 $match_type = _("subject");
149 break;
150 }
151
8415b2d3 152 $links = '<small>[<a href="options_highlight.php?action=edit&amp;theid=' . $i . '">' .
153 _("Edit") .
154 '</a>]&nbsp;[<a href="options_highlight.php?action=delete&amp;theid='. $i . '">' .
155 _("Delete");
156 if($i > 0) {
157 $links .= '</a>]&nbsp;[<a href="options_highlight.php?action=up&amp;theid='. $i . '">' . _("Up");
158 }
159 if($i+1 < $mhl_count) {
160 $links .= '</a>]&nbsp;[<a href="options_highlight.php?action=down&amp;theid='. $i . '">' . _("Down");
161 }
162 $links .= '</a>]</small>';
163
545238b1 164 echo html_tag( 'tr',
165 html_tag( 'td',
8415b2d3 166 $links,
c435f076 167 'left', $color[4], 'width="20%" style="white-space: nowrap;"' ) .
545238b1 168 html_tag( 'td',
169 htmlspecialchars($message_highlight_list[$i]['name']) ,
170 'left' ) .
171 html_tag( 'td',
172 $match_type . ' = ' .
173 htmlspecialchars($message_highlight_list[$i]['value']) ,
174 'left' ) ,
175 '', $message_highlight_list[$i]['color'] ) . "\n";
d79e01f5 176 }
177 echo "</table>\n".
39bfea8f 178 "<br />\n";
d79e01f5 179} else {
39bfea8f 180 echo '<center>' . _("No highlighting is defined") . "</center><br />\n".
181 "<br />\n";
d79e01f5 182}
183if ($action == 'edit' || $action == 'add') {
d79e01f5 184
185 $color_list[0] = '4444aa';
186 $color_list[1] = '44aa44';
187 $color_list[2] = 'aaaa44';
188 $color_list[3] = '44aaaa';
189 $color_list[4] = 'aa44aa';
190 $color_list[5] = 'aaaaff';
191 $color_list[6] = 'aaffaa';
192 $color_list[7] = 'ffffaa';
193 $color_list[8] = 'aaffff';
194 $color_list[9] = 'ffaaff';
195 $color_list[10] = 'aaaaaa';
196 $color_list[11] = 'bfbfbf';
197 $color_list[12] = 'dfdfdf';
198 $color_list[13] = 'ffffff';
199
200 # helpful color chart from http://www.visibone.com/colorlab/big.html
201 $new_color_list["0,0"] = 'cccccc';
202 $new_color_list["0,1"] = '999999';
203 $new_color_list["0,2"] = '666666';
204 $new_color_list["0,3"] = '333333';
205 $new_color_list["0,4"] = '000000';
206
207 # red
208 $new_color_list["1,0"] = 'ff0000';
209 $new_color_list["1,1"] = 'cc0000';
210 $new_color_list["1,2"] = '990000';
211 $new_color_list["1,3"] = '660000';
212 $new_color_list["1,4"] = '330000';
213
214 $new_color_list["2,0"] = 'ffcccc';
215 $new_color_list["2,1"] = 'cc9999';
216 $new_color_list["2,2"] = '996666';
217 $new_color_list["2,3"] = '663333';
218 $new_color_list["2,4"] = '330000';
219
220 $new_color_list["3,0"] = 'ffcccc';
221 $new_color_list["3,1"] = 'ff9999';
222 $new_color_list["3,2"] = 'ff6666';
223 $new_color_list["3,3"] = 'ff3333';
224 $new_color_list["3,4"] = 'ff0000';
225
226 # green
227 $new_color_list["4,0"] = '00ff00';
228 $new_color_list["4,1"] = '00cc00';
229 $new_color_list["4,2"] = '009900';
230 $new_color_list["4,3"] = '006600';
231 $new_color_list["4,4"] = '003300';
232
233 $new_color_list["5,0"] = 'ccffcc';
234 $new_color_list["5,1"] = '99cc99';
235 $new_color_list["5,2"] = '669966';
236 $new_color_list["5,3"] = '336633';
237 $new_color_list["5,4"] = '003300';
238
239 $new_color_list["6,0"] = 'ccffcc';
240 $new_color_list["6,1"] = '99ff99';
241 $new_color_list["6,2"] = '66ff66';
242 $new_color_list["6,3"] = '33ff33';
243 $new_color_list["6,4"] = '00ff00';
244
245 # blue
246 $new_color_list["7,0"] = '0000ff';
247 $new_color_list["7,1"] = '0000cc';
248 $new_color_list["7,2"] = '000099';
249 $new_color_list["7,3"] = '000066';
250 $new_color_list["7,4"] = '000033';
251
252 $new_color_list["8,0"] = 'ccccff';
253 $new_color_list["8,1"] = '9999cc';
254 $new_color_list["8,2"] = '666699';
255 $new_color_list["8,3"] = '333366';
256 $new_color_list["8,4"] = '000033';
257
258 $new_color_list["9,0"] = 'ccccff';
259 $new_color_list["9,1"] = '9999ff';
260 $new_color_list["9,2"] = '6666ff';
261 $new_color_list["9,3"] = '3333ff';
262 $new_color_list["9,4"] = '0000ff';
263
264 # yellow
265 $new_color_list["10,0"] = 'ffff00';
266 $new_color_list["10,1"] = 'cccc00';
267 $new_color_list["10,2"] = '999900';
268 $new_color_list["10,3"] = '666600';
269 $new_color_list["10,4"] = '333300';
270
271 $new_color_list["11,0"] = 'ffffcc';
272 $new_color_list["11,1"] = 'cccc99';
273 $new_color_list["11,2"] = '999966';
274 $new_color_list["11,3"] = '666633';
275 $new_color_list["11,4"] = '333300';
276
277 $new_color_list["12,0"] = 'ffffcc';
278 $new_color_list["12,1"] = 'ffff99';
279 $new_color_list["12,2"] = 'ffff66';
280 $new_color_list["12,3"] = 'ffff33';
281 $new_color_list["12,4"] = 'ffff00';
282
283 # cyan
284 $new_color_list["13,0"] = '00ffff';
285 $new_color_list["13,1"] = '00cccc';
286 $new_color_list["13,2"] = '009999';
287 $new_color_list["13,3"] = '006666';
288 $new_color_list["13,4"] = '003333';
289
290 $new_color_list["14,0"] = 'ccffff';
291 $new_color_list["14,1"] = '99cccc';
292 $new_color_list["14,2"] = '669999';
293 $new_color_list["14,3"] = '336666';
294 $new_color_list["14,4"] = '003333';
295
296 $new_color_list["15,0"] = 'ccffff';
297 $new_color_list["15,1"] = '99ffff';
298 $new_color_list["15,2"] = '66ffff';
299 $new_color_list["15,3"] = '33ffff';
300 $new_color_list["15,4"] = '00ffff';
301
302 # magenta
303 $new_color_list["16,0"] = 'ff00ff';
304 $new_color_list["16,1"] = 'cc00cc';
305 $new_color_list["16,2"] = '990099';
306 $new_color_list["16,3"] = '660066';
307 $new_color_list["16,4"] = '330033';
308
309 $new_color_list["17,0"] = 'ffccff';
310 $new_color_list["17,1"] = 'cc99cc';
311 $new_color_list["17,2"] = '996699';
312 $new_color_list["17,3"] = '663366';
313 $new_color_list["17,4"] = '330033';
314
315 $new_color_list["18,0"] = 'ffccff';
316 $new_color_list["18,1"] = 'ff99ff';
317 $new_color_list["18,2"] = 'ff66ff';
318 $new_color_list["18,3"] = 'ff33ff';
319 $new_color_list["18,4"] = 'ff00ff';
320
62366261 321 $selected_input = FALSE;
322 $selected_i = null;
323 $selected_choose = FALSE;
324 $selected_predefined = FALSE;
d79e01f5 325
326 for ($i=0; $i < 14; $i++) {
327 ${"selected".$i} = '';
328 }
89465360 329 if ($action == 'edit' && isset($theid) && isset($message_highlight_list[$theid]['color'])) {
d79e01f5 330 for ($i=0; $i < 14; $i++) {
e1db998a 331 if ($color_list[$i] == $message_highlight_list[$theid]['color']) {
62366261 332 $selected_choose = TRUE;
333 $selected_i = $color_list[$i];
89465360 334 continue;
cd928157 335 }
89465360 336 }
d79e01f5 337 }
545238b1 338
89465360 339 if ($action == 'edit' && isset($theid) && isset($message_highlight_list[$theid]['color'])) {
545238b1 340 $current_color = $message_highlight_list[$theid]['color'];
341 }
342 else {
343 $current_color = '63aa7f';
344 }
345
df2c5bc9 346 $pre_defined_color = 0;
545238b1 347 for($x = 0; $x < 5; $x++) {
348 for($y = 0; $y < 19; $y++) {
349 $gridindex = "$y,$x";
350 $gridcolor = $new_color_list[$gridindex];
351 if ($gridcolor == $current_color) {
352 $pre_defined_color = 1;
353 break;
354 }
355 }
356 }
357
935a06bb 358 if (isset($theid) && !isset($message_highlight_list[$theid]['color']))
62366261 359 $selected_choose = TRUE;
545238b1 360 else if ($pre_defined_color)
62366261 361 $selected_predefined = TRUE;
d79e01f5 362 else if ($selected_choose == '')
62366261 363 $selected_input = TRUE;
d79e01f5 364
c435f076 365 echo addForm('options_highlight.php', 'post', 'f').
62366261 366 addHidden('action', 'save');
367 if($action == 'edit') {
368 echo addHidden('theid', (isset($theid)?$theid:''));
369 }
545238b1 370 echo html_tag( 'table', '', 'center', '', 'width="80%" cellpadding="3" cellspacing="0" border="0"' ) . "\n";
371 echo html_tag( 'tr', '', '', $color[0] ) . "\n";
c435f076 372 echo html_tag( 'td', '', 'right', '', 'style="white-space: nowrap;"' ) . "<b>\n";
d79e01f5 373 echo _("Identifying name") . ":";
374 echo ' </b></td>' . "\n";
545238b1 375 echo html_tag( 'td', '', 'left' ) . "\n";
89465360 376 if ($action == 'edit' && isset($theid) && isset($message_highlight_list[$theid]['name']))
d79e01f5 377 $disp = $message_highlight_list[$theid]['name'];
378 else
379 $disp = '';
62366261 380 echo " ".addInput('identname', $disp);
d79e01f5 381 echo " </td>\n";
382 echo " </tr>\n";
545238b1 383 echo html_tag( 'tr', html_tag( 'td', '<small><small>&nbsp;</small></small>', 'left' ) ) ."\n";
384 echo html_tag( 'tr', '', '', $color[0] ) . "\n";
385 echo html_tag( 'td', '<b>'. _("Color") . ':</b>', 'right' );
386 echo html_tag( 'td', '', 'left' );
62366261 387 echo ' '.addRadioBox('color_type', $selected_choose, '1');
388
389 $selops = array (
134e4174 390 $color_list[0] => _("Dark Blue"),
391 $color_list[1] => _("Dark Green"),
392 $color_list[2] => _("Dark Yellow"),
393 $color_list[3] => _("Dark Cyan"),
394 $color_list[4] => _("Dark Magenta"),
395 $color_list[5] => _("Light Blue"),
396 $color_list[6] => _("Light Green"),
397 $color_list[7] => _("Light Yellow"),
398 $color_list[8] => _("Light Cyan"),
399 $color_list[9] => _("Light Magenta"),
400 $color_list[10] => _("Dark Gray"),
401 $color_list[11] => _("Medium Gray"),
402 $color_list[12] => _("Light Gray"),
403 $color_list[13] => _("White") );
404
62366261 405 echo addSelect('newcolor_choose', $selops, $selected_i, TRUE);
39bfea8f 406 echo "<br />\n";
62366261 407
408 echo ' '.addRadioBox('color_type', $selected_input, 2).
409 ' &nbsp;'. _("Other:") .
134e4174 410 addInput('newcolor_input',
411 (($selected_input && isset($theid)) ? $message_highlight_list[$theid]['color'] : ''),
412 '7');
39bfea8f 413 echo _("Ex: 63aa7f")."<br />\n";
d79e01f5 414 echo " </td>\n";
415 echo " </tr>\n";
416
417 # Show grid of color choices
545238b1 418 echo html_tag( 'tr', '', '', $color[0] ) . "\n";
419 echo html_tag( 'td', '', 'left', '', 'colspan="2"' );
39bfea8f 420 echo html_tag( 'table', '', 'center', '', 'border="0" cellpadding="2" cellspacing="1"' ) . "\n";
545238b1 421
d79e01f5 422 for($x = 0; $x < 5; $x++) {
545238b1 423 echo html_tag( 'tr' ) . "\n";
721d2a60 424 for($y = 0; $y < 19; $y++) {
d79e01f5 425 $gridindex = "$y,$x";
426 $gridcolor = $new_color_list[$gridindex];
62366261 427 echo html_tag( 'td', addRadioBox('color_type', ($gridcolor == $current_color), '#'.$gridcolor),
134e4174 428 'left', $gridcolor, 'colspan="2"' );
721d2a60 429 }
430 echo "</tr>\n";
d79e01f5 431 }
432 echo "</table>\n";
bd9bbfef 433 echo "</td></tr>\n";
d79e01f5 434
545238b1 435 echo html_tag( 'tr', html_tag( 'td', '<small><small>&nbsp;</small></small>', 'left' ) ) . "\n";
436 echo html_tag( 'tr', '', '', $color[0] ) . "\n";
437 echo html_tag( 'td', '', 'center', '', 'colspan="2"' ) . "\n";
39bfea8f 438 echo " <select name=\"match_type\">\n";
d79e01f5 439 oh_opt( 'from',
89465360 440 (isset($theid)?$message_highlight_list[$theid]['match_type'] == 'from':1),
d79e01f5 441 _("From") );
442 oh_opt( 'to',
89465360 443 (isset($theid)?$message_highlight_list[$theid]['match_type'] == 'to':0),
d79e01f5 444 _("To") );
445 oh_opt( 'cc',
89465360 446 (isset($theid)?$message_highlight_list[$theid]['match_type'] == 'cc':0),
d79e01f5 447 _("Cc") );
448 oh_opt( 'to_cc',
89465360 449 (isset($theid)?$message_highlight_list[$theid]['match_type'] == 'to_cc':0),
d79e01f5 450 _("To or Cc") );
451 oh_opt( 'subject',
89465360 452 (isset($theid)?$message_highlight_list[$theid]['match_type'] == 'subject':0),
d79e01f5 453 _("Subject") );
454 echo " </select>\n";
455 echo '<b>' . _("Matches") . ':</b> ';
89465360 456 if ($action == 'edit' && isset($theid) && isset($message_highlight_list[$theid]['value']))
d79e01f5 457 $disp = $message_highlight_list[$theid]['value'];
458 else
459 $disp = '';
62366261 460 echo ' '.addInput('value', $disp, 40);
d79e01f5 461 echo " </td>\n";
462 echo " </tr>\n";
463 echo "</table>\n";
39bfea8f 464 echo '<center><input type="submit" value="' . _("Submit") . "\" /></center>\n";
d79e01f5 465 echo "</form>\n";
466}
467do_hook('options_highlight_bottom');
a2b193bc 468
9d157cec 469?>
91e0dccc 470</table></body></html>