~ubuntu-branches/ubuntu/hardy/squirrelmail/hardy-updates

« back to all changes in this revision

Viewing changes to src/options.php

  • Committer: Bazaar Package Importer
  • Author(s): Sam Johnston
  • Date: 2004-02-04 01:42:12 UTC
  • Revision ID: james.westby@ubuntu.com-20040204014212-ek9533qvd2vo1wa1
Tags: upstream-1.5.0
ImportĀ upstreamĀ versionĀ 1.5.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * options.php
 
5
 *
 
6
 * Copyright (c) 1999-2003 The SquirrelMail Project Team
 
7
 * Licensed under the GNU GPL. For full terms see the file COPYING.
 
8
 *
 
9
 * Displays the options page. Pulls from proper user preference files
 
10
 * and config.php. Displays preferences as selected and other options.
 
11
 *
 
12
 * $Id: options.php,v 1.128 2003/12/01 21:56:57 cigamit Exp $
 
13
 * @package squirrelmail
 
14
 */
 
15
 
 
16
/** Path for SquirrelMail required files. */
 
17
define('SM_PATH','../');
 
18
 
 
19
/* SquirrelMail required files. */
 
20
require_once(SM_PATH . 'include/validate.php');
 
21
require_once(SM_PATH . 'functions/global.php');
 
22
require_once(SM_PATH . 'functions/display_messages.php');
 
23
require_once(SM_PATH . 'functions/imap.php');
 
24
require_once(SM_PATH . 'functions/options.php');
 
25
require_once(SM_PATH . 'functions/strings.php');
 
26
require_once(SM_PATH . 'functions/html.php');
 
27
 
 
28
/*********************************/
 
29
/*** Build the resultant page. ***/
 
30
/*********************************/
 
31
 
 
32
define('SMOPT_MODE_DISPLAY', 'display');
 
33
define('SMOPT_MODE_SUBMIT', 'submit');
 
34
define('SMOPT_MODE_LINK', 'link');
 
35
 
 
36
define('SMOPT_PAGE_MAIN', 'main');
 
37
define('SMOPT_PAGE_PERSONAL', 'personal');
 
38
define('SMOPT_PAGE_DISPLAY', 'display');
 
39
define('SMOPT_PAGE_HIGHLIGHT', 'highlight');
 
40
define('SMOPT_PAGE_FOLDER', 'folder');
 
41
define('SMOPT_PAGE_ORDER', 'order');
 
42
 
 
43
function process_optionmode_submit($optpage, $optpage_data) {
 
44
    /* Initialize the maximum option refresh level. */
 
45
    $max_refresh = SMOPT_REFRESH_NONE;
 
46
 
 
47
    /* Save each option in each option group. */
 
48
    foreach ($optpage_data['options'] as $option_grp) {
 
49
        foreach ($option_grp['options'] as $option) {
 
50
            /* Remove Debug Mode Until Needed
 
51
            echo "name = '$option->name', "
 
52
               . "value = '$option->value', "
 
53
               . "new_value = '$option->new_value'\n";
 
54
            echo "<br>";
 
55
            */
 
56
            if ($option->changed()) {
 
57
                $option->save();
 
58
                $max_refresh = max($max_refresh, $option->refresh_level);
 
59
            }
 
60
        }
 
61
    }
 
62
 
 
63
    /* Return the max refresh level. */
 
64
    return ($max_refresh);
 
65
}
 
66
 
 
67
function process_optionmode_link($optpage) {
 
68
   /* There will be something here, later. */
 
69
}
 
70
 
 
71
 
 
72
/**
 
73
 * This function prints out an option page row.
 
74
 */
 
75
function print_optionpages_row($leftopt, $rightopt = false) {
 
76
    global $color;
 
77
 
 
78
    if ($rightopt) {
 
79
        $rightopt_name = html_tag( 'td', '<a href="' . $rightopt['url'] . '">' . $rightopt['name'] . '</a>', 'left', $color[9], 'valign="top" width="49%"' );
 
80
        $rightopt_desc = html_tag( 'td', $rightopt['desc'], 'left', $color[0], 'valign="top" width="49%"' );
 
81
    } else {
 
82
        $rightopt_name = html_tag( 'td', '&nbsp;', 'left', $color[4], 'valign="top" width="49%"' );
 
83
        $rightopt_desc = html_tag( 'td', '&nbsp;', 'left', $color[4], 'valign="top" width="49%"' );
 
84
    }
 
85
 
 
86
    echo
 
87
    html_tag( 'table', "\n" .
 
88
        html_tag( 'tr', "\n" .
 
89
            html_tag( 'td', "\n" .
 
90
                html_tag( 'table', "\n" .
 
91
                    html_tag( 'tr', "\n" .
 
92
                        html_tag( 'td',
 
93
                            '<a href="' . $leftopt['url'] . '">' . $leftopt['name'] . '</a>' ,
 
94
                        'left', $color[9], 'valign="top" width="49%"' ) .
 
95
                        html_tag( 'td',
 
96
                            '&nbsp;' ,
 
97
                        'left', $color[4], 'valign="top" width="2%"' ) . "\n" .
 
98
                        $rightopt_name
 
99
                    ) . "\n" .
 
100
                    html_tag( 'tr', "\n" .
 
101
                        html_tag( 'td',
 
102
                            $leftopt['desc'] ,
 
103
                        'left', $color[0], 'valign="top" width="49%"' ) .
 
104
                        html_tag( 'td',
 
105
                            '&nbsp;' ,
 
106
                        'left', $color[4], 'valign="top" width="2%"' ) . "\n" .
 
107
                        $rightopt_desc
 
108
                    ) ,
 
109
                '', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) ,
 
110
            'left', '', 'valign="top"' )
 
111
        ) ,
 
112
    '', $color[4], 'width="100%" cellpadding="0" cellspacing="5" border="0"' );
 
113
}
 
114
 
 
115
/* ---------------------------- main ---------------------------- */
 
116
 
 
117
/* get the globals that we may need */
 
118
sqgetGlobalVar('key',       $key,           SQ_COOKIE);
 
119
sqgetGlobalVar('username',  $username,      SQ_SESSION);
 
120
sqgetGlobalVar('onetimepad',$onetimepad,    SQ_SESSION);
 
121
sqgetGlobalVar('delimiter', $delimiter,     SQ_SESSION);
 
122
 
 
123
sqgetGlobalVar('optpage',     $optpage);
 
124
sqgetGlobalVar('optmode',     $optmode,      SQ_FORM);
 
125
sqgetGlobalVar('optpage_data',$optpage_data, SQ_POST);
 
126
/* end of getting globals */
 
127
 
 
128
/* Make sure we have an Option Page set. Default to main. */
 
129
if ( !isset($optpage) || $optpage == '' ) {
 
130
    $optpage = SMOPT_PAGE_MAIN;
 
131
} else {
 
132
    $optpage = strip_tags( $optpage );
 
133
}
 
134
 
 
135
/* Make sure we have an Option Mode set. Default to display. */
 
136
if (!isset($optmode)) {
 
137
    $optmode = SMOPT_MODE_DISPLAY;
 
138
}
 
139
 
 
140
/*
 
141
 * First, set the load information for each option page.   
 
142
 */
 
143
 
 
144
/* Initialize load information variables. */
 
145
$optpage_name = '';
 
146
$optpage_file = '';
 
147
$optpage_loader = '';
 
148
 
 
149
/* Set the load information for each page. */
 
150
switch ($optpage) {
 
151
    case SMOPT_PAGE_MAIN: 
 
152
        break;
 
153
    case SMOPT_PAGE_PERSONAL:
 
154
        $optpage_name     = _("Personal Information");
 
155
        $optpage_file     = SM_PATH . 'include/options/personal.php';
 
156
        $optpage_loader   = 'load_optpage_data_personal';
 
157
        $optpage_loadhook = 'optpage_loadhook_personal';
 
158
        break;
 
159
    case SMOPT_PAGE_DISPLAY:
 
160
        $optpage_name   = _("Display Preferences");
 
161
        $optpage_file   = SM_PATH . 'include/options/display.php';
 
162
        $optpage_loader = 'load_optpage_data_display';
 
163
        $optpage_loadhook = 'optpage_loadhook_display';
 
164
        break;
 
165
    case SMOPT_PAGE_HIGHLIGHT:
 
166
        $optpage_name   = _("Message Highlighting");
 
167
        $optpage_file   = SM_PATH . 'include/options/highlight.php';
 
168
        $optpage_loader = 'load_optpage_data_highlight';
 
169
        $optpage_loadhook = 'optpage_loadhook_highlight';
 
170
        break;
 
171
    case SMOPT_PAGE_FOLDER:
 
172
        $optpage_name   = _("Folder Preferences");
 
173
        $optpage_file   = SM_PATH . 'include/options/folder.php';
 
174
        $optpage_loader = 'load_optpage_data_folder';
 
175
        $optpage_loadhook = 'optpage_loadhook_folder';
 
176
        break;
 
177
    case SMOPT_PAGE_ORDER:
 
178
        $optpage_name = _("Index Order");
 
179
        $optpage_file = SM_PATH . 'include/options/order.php';
 
180
        $optpage_loader = 'load_optpage_data_order';
 
181
        $optpage_loadhook = 'optpage_loadhook_order';
 
182
        break;
 
183
    default: do_hook('optpage_set_loadinfo');
 
184
}
 
185
 
 
186
/**********************************************************/
 
187
/*** Second, load the option information for this page. ***/
 
188
/**********************************************************/
 
189
 
 
190
if ( !@is_file( $optpage_file ) ) {
 
191
    $optpage = SMOPT_PAGE_MAIN;
 
192
} else if ($optpage != SMOPT_PAGE_MAIN ) {
 
193
    /* Include the file for this optionpage. */
 
194
    
 
195
    require_once($optpage_file);
 
196
 
 
197
    /* Assemble the data for this option page. */
 
198
    $optpage_data = array();
 
199
    $optpage_data = $optpage_loader();
 
200
    do_hook($optpage_loadhook);
 
201
    $optpage_data['options'] =
 
202
        create_option_groups($optpage_data['grps'], $optpage_data['vals']);
 
203
}
 
204
 
 
205
/***********************************************************/
 
206
/*** Next, process anything that needs to be processed. ***/
 
207
/***********************************************************/
 
208
 
 
209
if ( isset( $optpage_data ) ) {
 
210
    switch ($optmode) {
 
211
        case SMOPT_MODE_SUBMIT:
 
212
            $max_refresh = process_optionmode_submit($optpage, $optpage_data);
 
213
            break;
 
214
        case SMOPT_MODE_LINK:
 
215
            $max_refresh = process_optionmode_link($optpage, $optpage_data);
 
216
            break;
 
217
    }
 
218
}
 
219
 
 
220
$optpage_title = _("Options");
 
221
if (isset($optpage_name) && ($optpage_name != '')) {
 
222
    $optpage_title .= " - $optpage_name";
 
223
}
 
224
 
 
225
/*******************************************************************/
 
226
/* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
 
227
/*******************************************************************/
 
228
 
 
229
/* If in submit mode, select a save hook name and run it. */
 
230
if ($optmode == SMOPT_MODE_SUBMIT) {
 
231
    /* Select a save hook name. */
 
232
    switch ($optpage) {
 
233
        case SMOPT_PAGE_PERSONAL:
 
234
            $save_hook_name = 'options_personal_save';
 
235
            break;
 
236
        case SMOPT_PAGE_DISPLAY:
 
237
            $save_hook_name = 'options_display_save';
 
238
            break;
 
239
        case SMOPT_PAGE_FOLDER:
 
240
            $save_hook_name = 'options_folder_save';
 
241
            break;
 
242
        default: 
 
243
            $save_hook_name = 'options_save';
 
244
            break;
 
245
    }
 
246
 
 
247
    /* Run the options save hook. */
 
248
    do_hook($save_hook_name);
 
249
}
 
250
 
 
251
/***************************************************************/
 
252
/* Apply logic to decide what optpage we want to display next. */
 
253
/***************************************************************/
 
254
 
 
255
/* If this is the result of an option page being submitted, then */
 
256
/* show the main page. Otherwise, show whatever page was called. */
 
257
 
 
258
if ($optmode == SMOPT_MODE_SUBMIT) {
 
259
    $optpage = SMOPT_PAGE_MAIN;
 
260
}
 
261
 
 
262
/***************************************************************/
 
263
/* Finally, display whatever page we are supposed to show now. */
 
264
/***************************************************************/
 
265
 
 
266
displayPageHeader($color, 'None', (isset($optpage_data['xtra']) ? $optpage_data['xtra'] : ''));
 
267
 
 
268
echo html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) . "\n" .
 
269
        html_tag( 'tr' ) . "\n" .
 
270
            html_tag( 'td', '', 'center' ) .
 
271
                "<b>$optpage_title</b><br>\n".
 
272
                html_tag( 'table', '', '', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) . "\n" .
 
273
                    html_tag( 'tr' ) . "\n" .
 
274
                        html_tag( 'td', '', 'center', $color[4] ) . "\n";
 
275
 
 
276
/*
 
277
 * The main option page has a different layout then the rest of the option
 
278
 * pages. Therefore, we create it here first, then the others below.
 
279
 */
 
280
if ($optpage == SMOPT_PAGE_MAIN) {
 
281
    /**********************************************************/
 
282
    /* First, display the results of a submission, if needed. */
 
283
    /**********************************************************/
 
284
    if ($optmode == SMOPT_MODE_SUBMIT) {
 
285
        if (!isset($frame_top)) {
 
286
            $frame_top = '_top';
 
287
        }
 
288
        /* Display a message indicating a successful save. */
 
289
        echo '<b>' . _("Successfully Saved Options") . ": $optpage_name</b><br>\n";
 
290
 
 
291
        /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */
 
292
        if ( !isset( $max_refresh ) ) {
 
293
        } else if ($max_refresh == SMOPT_REFRESH_FOLDERLIST) {
 
294
            echo '<a href="../src/left_main.php" target="left">' . _("Refresh Folder List") . '</a><br>';
 
295
        } else if ($max_refresh) {
 
296
            echo '<a href="../src/webmail.php?right_frame=options.php" target="' . $frame_top . '">' . _("Refresh Page") . '</a><br>';
 
297
        }
 
298
    }
 
299
    /******************************************/
 
300
    /* Build our array of Option Page Blocks. */
 
301
    /******************************************/
 
302
    $optpage_blocks = array();
 
303
 
 
304
    /* Build a section for Personal Options. */
 
305
    $optpage_blocks[] = array(
 
306
        'name' => _("Personal Information"),
 
307
        'url'  => 'options.php?optpage=' . SMOPT_PAGE_PERSONAL,
 
308
        'desc' => _("This contains personal information about yourself such as your name, your email address, etc."),
 
309
        'js'   => false
 
310
    );
 
311
 
 
312
    /* Build a section for Display Options. */
 
313
    $optpage_blocks[] = array(
 
314
        'name' => _("Display Preferences"),
 
315
        'url'  => 'options.php?optpage=' . SMOPT_PAGE_DISPLAY,
 
316
        'desc' => _("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."),
 
317
        'js'   => false
 
318
    );
 
319
 
 
320
    /* Build a section for Message Highlighting Options. */
 
321
    $optpage_blocks[] = array(
 
322
        'name' =>_("Message Highlighting"),
 
323
        'url'  => 'options_highlight.php',
 
324
        'desc' =>_("Based upon given criteria, incoming messages can have different background colors in the message list.  This helps to easily distinguish who the messages are from, especially for mailing lists."),
 
325
        'js'   => false
 
326
    );
 
327
 
 
328
    /* Build a section for Folder Options. */
 
329
    $optpage_blocks[] = array(
 
330
        'name' => _("Folder Preferences"),
 
331
        'url'  => 'options.php?optpage=' . SMOPT_PAGE_FOLDER,
 
332
        'desc' => _("These settings change the way your folders are displayed and manipulated."),
 
333
        'js'   => false
 
334
    );
 
335
 
 
336
    /* Build a section for Index Order Options. */
 
337
    $optpage_blocks[] = array(
 
338
        'name' => _("Index Order"),
 
339
        'url'  => 'options_order.php',
 
340
        'desc' => _("The order of the message index can be rearranged and changed to contain the headers in any order you want."),
 
341
        'js'   => false
 
342
    );
 
343
 
 
344
    /* Build a section for plugins wanting to register an optionpage. */
 
345
    do_hook('optpage_register_block');
 
346
 
 
347
    /*****************************************************/
 
348
    /* Let's sort Javascript Option Pages to the bottom. */
 
349
    /*****************************************************/
 
350
    $js_optpage_blocks = array();
 
351
    $reg_optpage_blocks = array();
 
352
    foreach ($optpage_blocks as $cur_optpage) {
 
353
        if (!isset($cur_optpage['js']) || !$cur_optpage['js']) {
 
354
            $reg_optpage_blocks[] = $cur_optpage;
 
355
        } else if ($javascript_on == SMPREF_JS_ON) {
 
356
            $js_optpage_blocks[] = $cur_optpage;
 
357
        }
 
358
    }
 
359
    $optpage_blocks = array_merge($reg_optpage_blocks, $js_optpage_blocks);
 
360
 
 
361
    /********************************************/
 
362
    /* Now, print out each option page section. */
 
363
    /********************************************/
 
364
    $first_optpage = false;
 
365
    echo html_tag( 'table', '', '', $color[4], 'width="100%" cellpadding="0" cellspacing="5" border="0"' ) . "\n" .
 
366
                html_tag( 'tr' ) . "\n" .
 
367
                    html_tag( 'td', '', 'left', '', 'valign="top"' ) .
 
368
                        html_tag( 'table', '', '', $color[4], 'width="100%" cellpadding="3" cellspacing="0" border="0"' ) . "\n" .
 
369
                            html_tag( 'tr' ) . "\n" .
 
370
                                html_tag( 'td', '', 'left' );
 
371
    foreach ($optpage_blocks as $next_optpage) {
 
372
        if ($first_optpage == false) {
 
373
            $first_optpage = $next_optpage;
 
374
        } else {
 
375
            print_optionpages_row($first_optpage, $next_optpage);
 
376
            $first_optpage = false;
 
377
        }
 
378
    }
 
379
 
 
380
    if ($first_optpage != false) {
 
381
        print_optionpages_row($first_optpage);
 
382
    }
 
383
 
 
384
    echo "</td></tr></table></td></tr></table>\n";
 
385
 
 
386
    do_hook('options_link_and_description');
 
387
 
 
388
 
 
389
/*************************************************************************/
 
390
/* If we are not looking at the main option page, display the page here. */
 
391
/*************************************************************************/
 
392
} else {
 
393
    echo '<form name="f" action="options.php" method="post"><br>' . "\n"
 
394
       . create_optpage_element($optpage)
 
395
       . create_optmode_element(SMOPT_MODE_SUBMIT)
 
396
       . html_tag( 'table', '', '', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) . "\n"
 
397
       . html_tag( 'tr' ) . "\n"
 
398
       . html_tag( 'td', '', 'left' ) . "\n";
 
399
 
 
400
    /* Output the option groups for this page. */
 
401
    print_option_groups($optpage_data['options']);
 
402
 
 
403
    /* Set the inside_hook_name and submit_name. */
 
404
    switch ($optpage) {
 
405
        case SMOPT_PAGE_PERSONAL:
 
406
            $inside_hook_name = 'options_personal_inside';
 
407
            $bottom_hook_name = 'options_personal_bottom';
 
408
            $submit_name = 'submit_personal';
 
409
            break;
 
410
        case SMOPT_PAGE_DISPLAY:
 
411
            $inside_hook_name = 'options_display_inside';
 
412
            $bottom_hook_name = 'options_display_bottom';
 
413
            $submit_name = 'submit_display';
 
414
            break;
 
415
        case SMOPT_PAGE_HIGHLIGHT:
 
416
            $inside_hook_name = 'options_highlight_inside';
 
417
            $bottom_hook_name = 'options_highlight_bottom';
 
418
            $submit_name = 'submit_highlight';
 
419
            break;
 
420
        case SMOPT_PAGE_FOLDER:
 
421
            $inside_hook_name = 'options_folder_inside';
 
422
            $bottom_hook_name = 'options_folder_bottom';
 
423
            $submit_name = 'submit_folder';
 
424
            break;
 
425
        case SMOPT_PAGE_ORDER:
 
426
            $inside_hook_name = 'options_order_inside';
 
427
            $bottom_hook_name = 'options_order_bottom';
 
428
            $submit_name = 'submit_order';
 
429
            break;
 
430
        default:
 
431
            $inside_hook_name = '';
 
432
            $bottom_hook_name = '';
 
433
            $submit_name = 'submit';
 
434
    }
 
435
 
 
436
    /* If it is not empty, trigger the inside hook. */
 
437
    if ($inside_hook_name != '') {
 
438
        do_hook($inside_hook_name);    
 
439
    }
 
440
 
 
441
    /* Spit out a submit button. */
 
442
    OptionSubmit($submit_name);
 
443
    echo '</td></tr></table></form>';
 
444
 
 
445
    /* If it is not empty, trigger the bottom hook. */
 
446
    if ($bottom_hook_name != '') {
 
447
        do_hook($bottom_hook_name);    
 
448
    }
 
449
}
 
450
 
 
451
echo        '</td></tr>' .
 
452
        '</table>'.
 
453
        '</td></tr>'.
 
454
     '</table>' .
 
455
     '</body></html>';
 
456
 
 
457
?>