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