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