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