Remove unused hook
[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 *
79ba18dc 8 * @copyright 1999-2013 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
ebd2391c 15/** This is the options_highlight page */
16define('PAGE_NAME', 'options_highlight');
17
30967a1e 18/**
202bcbcc 19 * Include the SquirrelMail initialization file.
30967a1e 20 */
202bcbcc 21require('../include/init.php');
86725763 22
202bcbcc 23// include_once(SM_PATH . 'functions/imap.php');
24require_once(SM_PATH . 'functions/forms.php');
9d157cec 25
fe369c70 26/* get globals */
62366261 27sqGetGlobalVar('action', $action);
28sqGetGlobalVar('theid', $theid);
29sqGetGlobalVar('identname', $identname);
30sqGetGlobalVar('newcolor_choose', $newcolor_choose);
31sqGetGlobalVar('newcolor_input', $newcolor_input);
32sqGetGlobalVar('color_type', $color_type);
33sqGetGlobalVar('match_type', $match_type);
34sqGetGlobalVar('value', $value);
12ba9472 35sqgetGlobalVar('smtoken', $submitted_token, SQ_FORM, '');
fe369c70 36
fe369c70 37/* end of get globals */
91e0dccc 38
c57b0888 39function oh_opt( $val, $sel, $tit ) {
d79e01f5 40 echo "<option value=\"$val\"";
c57b0888 41 if ( $sel )
e1728a7a 42 echo ' selected="selected"';
c57b0888 43 echo ">$tit</option>\n";
44}
e697b6cc 45
d79e01f5 46if (! isset($action)) {
47 $action = '';
48}
49if (! isset($message_highlight_list)) {
50 $message_highlight_list = array();
51}
52
8415b2d3 53if (isset($theid) && ($action == 'delete') ||
54 ($action == 'up') ||
55 ($action == 'down')) {
199a9ab8 56
57 // security check
2cefa62a 58 sm_validate_security_token($submitted_token, -1, TRUE);
199a9ab8 59
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
199a9ab8 94 // security check
2cefa62a 95 sm_validate_security_token($submitted_token, -1, TRUE);
199a9ab8 96
d79e01f5 97 if ($color_type == 1) $newcolor = $newcolor_choose;
98 elseif ($color_type == 2) $newcolor = $newcolor_input;
99 else $newcolor = $color_type;
100
0f8a1ce9 101 $newcolor = str_replace('#', '', $newcolor);
102 $newcolor = str_replace('"', '', $newcolor);
103 $newcolor = str_replace('\'', '', $newcolor);
104 $value = str_replace(',', ' ', $value);
d79e01f5 105
1c159927 106 if(isset($theid)) {
91e0dccc 107 $message_highlight_list[$theid] =
1c159927 108 array( 'name' => $identname, 'color' => $newcolor,
109 'value' => $value, 'match_type' => $match_type );
110 } else {
91e0dccc 111 $message_highlight_list[] =
1c159927 112 array( 'name' => $identname, 'color' => $newcolor,
113 'value' => $value, 'match_type' => $match_type );
114 }
115
116 setPref($data_dir, $username, 'hililist', serialize($message_highlight_list));
d79e01f5 117}
876fdb60 118displayPageHeader($color);
c36ed9cf 119
85c8aff6 120/**
121 * Display the current rule list
122 */
123$rules = array();
124foreach($message_highlight_list as $index=>$rule) {
125 $a = array();
126
3047e291 127 $a['Name'] = sm_encode_html_special_chars($rule['name']);
85c8aff6 128 $a['Color'] = $rule['color'];
129 $a['MatchField'] = '';
3047e291 130 $a['MatchValue'] = sm_encode_html_special_chars($rule['value']);
85c8aff6 131 switch ($rule['match_type']) {
545238b1 132 case 'from' :
85c8aff6 133 $a['MatchField'] = _("From");
134 break;
545238b1 135 case 'to' :
85c8aff6 136 $a['MatchField'] = _("To");
137 break;
545238b1 138 case 'cc' :
85c8aff6 139 $a['MatchField'] = _("Cc");
140 break;
545238b1 141 case 'to_cc' :
85c8aff6 142 $a['MatchField'] = _("To or Cc");
143 break;
545238b1 144 case 'subject' :
85c8aff6 145 $a['MatchField'] = _("subject");
146 break;
d79e01f5 147 }
85c8aff6 148
149 $rules[$index] = $a;
d79e01f5 150}
85c8aff6 151
152$oTemplate->assign('current_rules', $rules);
153
12ba9472 154$token = sm_generate_security_token();
155
85c8aff6 156$oTemplate->assign('add_rule', 'options_highlight.php?action=add');
157$oTemplate->assign('edit_rule', 'options_highlight.php?action=edit&amp;theid=');
12ba9472 158$oTemplate->assign('delete_rule', 'options_highlight.php?action=delete&amp;smtoken=' . $token . '&amp;theid=');
159$oTemplate->assign('move_up', 'options_highlight.php?action=up&amp;smtoken=' . $token . '&amp;theid=');
160$oTemplate->assign('move_down', 'options_highlight.php?action=down&amp;smtoken=' . $token . '&amp;theid=');
85c8aff6 161
162$oTemplate->display('options_highlight_list.tpl');
163
164/**
165 * Optionally, display the add/edit dialog
166 */
d79e01f5 167if ($action == 'edit' || $action == 'add') {
d79e01f5 168
169 $color_list[0] = '4444aa';
170 $color_list[1] = '44aa44';
171 $color_list[2] = 'aaaa44';
172 $color_list[3] = '44aaaa';
173 $color_list[4] = 'aa44aa';
174 $color_list[5] = 'aaaaff';
175 $color_list[6] = 'aaffaa';
176 $color_list[7] = 'ffffaa';
177 $color_list[8] = 'aaffff';
178 $color_list[9] = 'ffaaff';
179 $color_list[10] = 'aaaaaa';
180 $color_list[11] = 'bfbfbf';
181 $color_list[12] = 'dfdfdf';
182 $color_list[13] = 'ffffff';
183
184 # helpful color chart from http://www.visibone.com/colorlab/big.html
185 $new_color_list["0,0"] = 'cccccc';
186 $new_color_list["0,1"] = '999999';
187 $new_color_list["0,2"] = '666666';
188 $new_color_list["0,3"] = '333333';
189 $new_color_list["0,4"] = '000000';
190
191 # red
192 $new_color_list["1,0"] = 'ff0000';
193 $new_color_list["1,1"] = 'cc0000';
194 $new_color_list["1,2"] = '990000';
195 $new_color_list["1,3"] = '660000';
196 $new_color_list["1,4"] = '330000';
197
198 $new_color_list["2,0"] = 'ffcccc';
199 $new_color_list["2,1"] = 'cc9999';
200 $new_color_list["2,2"] = '996666';
201 $new_color_list["2,3"] = '663333';
202 $new_color_list["2,4"] = '330000';
203
204 $new_color_list["3,0"] = 'ffcccc';
205 $new_color_list["3,1"] = 'ff9999';
206 $new_color_list["3,2"] = 'ff6666';
207 $new_color_list["3,3"] = 'ff3333';
208 $new_color_list["3,4"] = 'ff0000';
209
210 # green
211 $new_color_list["4,0"] = '00ff00';
212 $new_color_list["4,1"] = '00cc00';
213 $new_color_list["4,2"] = '009900';
214 $new_color_list["4,3"] = '006600';
215 $new_color_list["4,4"] = '003300';
216
217 $new_color_list["5,0"] = 'ccffcc';
218 $new_color_list["5,1"] = '99cc99';
219 $new_color_list["5,2"] = '669966';
220 $new_color_list["5,3"] = '336633';
221 $new_color_list["5,4"] = '003300';
222
223 $new_color_list["6,0"] = 'ccffcc';
224 $new_color_list["6,1"] = '99ff99';
225 $new_color_list["6,2"] = '66ff66';
226 $new_color_list["6,3"] = '33ff33';
227 $new_color_list["6,4"] = '00ff00';
228
229 # blue
230 $new_color_list["7,0"] = '0000ff';
231 $new_color_list["7,1"] = '0000cc';
232 $new_color_list["7,2"] = '000099';
233 $new_color_list["7,3"] = '000066';
234 $new_color_list["7,4"] = '000033';
235
236 $new_color_list["8,0"] = 'ccccff';
237 $new_color_list["8,1"] = '9999cc';
238 $new_color_list["8,2"] = '666699';
239 $new_color_list["8,3"] = '333366';
240 $new_color_list["8,4"] = '000033';
241
242 $new_color_list["9,0"] = 'ccccff';
243 $new_color_list["9,1"] = '9999ff';
244 $new_color_list["9,2"] = '6666ff';
245 $new_color_list["9,3"] = '3333ff';
246 $new_color_list["9,4"] = '0000ff';
247
248 # yellow
249 $new_color_list["10,0"] = 'ffff00';
250 $new_color_list["10,1"] = 'cccc00';
251 $new_color_list["10,2"] = '999900';
252 $new_color_list["10,3"] = '666600';
253 $new_color_list["10,4"] = '333300';
254
255 $new_color_list["11,0"] = 'ffffcc';
256 $new_color_list["11,1"] = 'cccc99';
257 $new_color_list["11,2"] = '999966';
258 $new_color_list["11,3"] = '666633';
259 $new_color_list["11,4"] = '333300';
260
261 $new_color_list["12,0"] = 'ffffcc';
262 $new_color_list["12,1"] = 'ffff99';
263 $new_color_list["12,2"] = 'ffff66';
264 $new_color_list["12,3"] = 'ffff33';
265 $new_color_list["12,4"] = 'ffff00';
266
267 # cyan
268 $new_color_list["13,0"] = '00ffff';
269 $new_color_list["13,1"] = '00cccc';
270 $new_color_list["13,2"] = '009999';
271 $new_color_list["13,3"] = '006666';
272 $new_color_list["13,4"] = '003333';
273
274 $new_color_list["14,0"] = 'ccffff';
275 $new_color_list["14,1"] = '99cccc';
276 $new_color_list["14,2"] = '669999';
277 $new_color_list["14,3"] = '336666';
278 $new_color_list["14,4"] = '003333';
279
280 $new_color_list["15,0"] = 'ccffff';
281 $new_color_list["15,1"] = '99ffff';
282 $new_color_list["15,2"] = '66ffff';
283 $new_color_list["15,3"] = '33ffff';
284 $new_color_list["15,4"] = '00ffff';
285
286 # magenta
287 $new_color_list["16,0"] = 'ff00ff';
288 $new_color_list["16,1"] = 'cc00cc';
289 $new_color_list["16,2"] = '990099';
290 $new_color_list["16,3"] = '660066';
291 $new_color_list["16,4"] = '330033';
292
293 $new_color_list["17,0"] = 'ffccff';
294 $new_color_list["17,1"] = 'cc99cc';
295 $new_color_list["17,2"] = '996699';
296 $new_color_list["17,3"] = '663366';
297 $new_color_list["17,4"] = '330033';
298
299 $new_color_list["18,0"] = 'ffccff';
300 $new_color_list["18,1"] = 'ff99ff';
301 $new_color_list["18,2"] = 'ff66ff';
302 $new_color_list["18,3"] = 'ff33ff';
303 $new_color_list["18,4"] = 'ff00ff';
304
62366261 305 $selected_input = FALSE;
62366261 306 $selected_choose = FALSE;
307 $selected_predefined = FALSE;
d79e01f5 308
85c8aff6 309 $name = $action=='edit' && isset($theid) && isset($message_highlight_list[$theid]['name']) ? $message_highlight_list[$theid]['name'] : '';
310 $field = $action=='edit' && isset($theid) && isset($message_highlight_list[$theid]['match_type']) ? $message_highlight_list[$theid]['match_type'] : '';
311 $value = $action=='edit' && isset($theid) && isset($message_highlight_list[$theid]['value']) ? $message_highlight_list[$theid]['value'] : '';
312 $color = $action=='edit' && isset($theid) && isset($message_highlight_list[$theid]['color']) ? $message_highlight_list[$theid]['color'] : '';
313
89465360 314 if ($action == 'edit' && isset($theid) && isset($message_highlight_list[$theid]['color'])) {
d79e01f5 315 for ($i=0; $i < 14; $i++) {
e1db998a 316 if ($color_list[$i] == $message_highlight_list[$theid]['color']) {
62366261 317 $selected_choose = TRUE;
89465360 318 continue;
cd928157 319 }
89465360 320 }
d79e01f5 321 }
545238b1 322
df2c5bc9 323 $pre_defined_color = 0;
545238b1 324 for($x = 0; $x < 5; $x++) {
325 for($y = 0; $y < 19; $y++) {
326 $gridindex = "$y,$x";
327 $gridcolor = $new_color_list[$gridindex];
85c8aff6 328 if ($gridcolor == $color) {
545238b1 329 $pre_defined_color = 1;
330 break;
331 }
332 }
333 }
334
935a06bb 335 if (isset($theid) && !isset($message_highlight_list[$theid]['color']))
62366261 336 $selected_choose = TRUE;
545238b1 337 else if ($pre_defined_color)
62366261 338 $selected_predefined = TRUE;
d79e01f5 339 else if ($selected_choose == '')
62366261 340 $selected_input = TRUE;
85c8aff6 341
342 $oTemplate->assign('rule_name', $name);
343 $oTemplate->assign('rule_value', $value);
344 $oTemplate->assign('rule_field', $field);
345 $oTemplate->assign('rule_color', $color);
346 $oTemplate->assign('color_radio', ($selected_choose ? 1 : ($selected_input ? 2 : 0)));
347 $oTemplate->assign('color_input', ($selected_input ? $color : ''));
348
199a9ab8 349 echo addForm('options_highlight.php', 'post', 'f', '', '', array(), TRUE).
62366261 350 addHidden('action', 'save');
351 if($action == 'edit') {
352 echo addHidden('theid', (isset($theid)?$theid:''));
353 }
85c8aff6 354
355 $oTemplate->display('options_highlight_addedit.tpl');
356
d79e01f5 357 echo "</form>\n";
358}
6e515418 359do_hook('options_highlight_bottom', $null);
a2b193bc 360
5c4ff7bf 361$oTemplate->display('footer.tpl');