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

« back to all changes in this revision

Viewing changes to src/options_identities.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_identities.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
 * Display Identities Options
 
10
 *
 
11
 * $Id: options_identities.php,v 1.28 2003/12/01 21:56:58 cigamit Exp $
 
12
 * @package squirrelmail
 
13
 */
 
14
 
 
15
/** Path for SquirrelMail required files. */
 
16
define('SM_PATH','../');
 
17
 
 
18
/* SquirrelMail required files. */
 
19
require_once(SM_PATH . 'include/validate.php');
 
20
require_once(SM_PATH . 'functions/global.php');
 
21
require_once(SM_PATH . 'functions/display_messages.php');
 
22
require_once(SM_PATH . 'functions/html.php');
 
23
 
 
24
/* POST data var names are dynamic because 
 
25
   of the possible multiple idents so lets get
 
26
   them all
 
27
   FIXME! This circumvents the benefits of rg=0
 
28
*/
 
29
if (!empty($_POST)) {
 
30
    extract($_POST);
 
31
}
 
32
/* got 'em all */
 
33
 
 
34
    if (isset($return)) {
 
35
       SaveUpdateFunction();
 
36
       header('Location: '.get_location().'/options_personal.php');
 
37
       exit();
 
38
    }
 
39
    
 
40
    displayPageHeader($color, 'None');
 
41
 
 
42
    $Info = do_hook('options_identities_process', 0);
 
43
    if ($Info[1]) {
 
44
        SaveUpdateFunction();
 
45
    }
 
46
    
 
47
    if (CheckAndDoDefault() || CheckAndDoPromote()) {
 
48
       SaveUpdateFunction();
 
49
    }
 
50
    if (isset($update) || CheckForDelete()) {
 
51
        SaveUpdateFunction();
 
52
    }
 
53
 
 
54
   do_hook('options_identities_top');
 
55
   LoadInfo($full_name, $email_address, $reply_to, $signature, '');
 
56
   $td_str = '';
 
57
   $td_str .= '<form name="f" action="options_identities.php" method="post"><br>';
 
58
   $td_str .= ShowTableInfo($full_name, $email_address, $reply_to, $signature, '');
 
59
  
 
60
   $num = 1;
 
61
   while (LoadInfo($full_name, $email_address, $reply_to, $signature, $num)) {
 
62
       $td_str .= html_tag( 'tr',
 
63
                          html_tag( 'th', sprintf (_("Alternate Identity %d"), $num), 'center', '', 'colspan="2"' ) ,
 
64
                      '', $color[9]);
 
65
       $td_str .= ShowTableInfo($full_name, $email_address, $reply_to, $signature, $num);
 
66
       $num ++;
 
67
       }
 
68
 
 
69
   echo '<br>' . 
 
70
   html_tag( 'table', "\n" .
 
71
       html_tag( 'tr', "\n" .
 
72
           html_tag( 'td', "\n" .
 
73
               '<b>'. _("Options") . ' - ' . _("Advanced Identities") .'</b><br>' .
 
74
               html_tag( 'table', "\n" .
 
75
                   html_tag( 'tr', "\n" .
 
76
                       html_tag( 'td', "\n" .
 
77
                           html_tag( 'table', "\n" .
 
78
                               html_tag( 'tr', "\n" .
 
79
                                   html_tag( 'th', _("Default Identity"), 'center', '', 'colspan="2"' ) ,
 
80
                                   '', $color[9]) . "\n" .
 
81
                                   $td_str . "\n" .
 
82
                               html_tag( 'tr',
 
83
                                   html_tag( 'th', _("Add a New Identity") . ShowTableInfo('', '', '', '', $num), 'center', '', 'colspan="2"' ) ,
 
84
                               '', $color[9]) ,
 
85
                            '', '', 'width="80%" cellpadding="2" cellspacing="0" border="0"' ) ,
 
86
                       'center', $color[4] )
 
87
                   ) ,
 
88
               '', '', 'width="100%" border="0" cellpadding="1" cellspacing="1"' ) ,
 
89
           'center', $color[0] )
 
90
       ) ,
 
91
   'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"' ) .
 
92
 
 
93
   '</body></html>';
 
94
 
 
95
    function SaveUpdateFunction() {
 
96
        global $username, $data_dir, $full_name, $email_address, $reply_to, $signature;
 
97
 
 
98
        $i = 1;
 
99
        $fakeI = 1;
 
100
        $name = 'form_for_' . $i;
 
101
        global $$name;
 
102
        while (isset($$name))
 
103
        {
 
104
            $name = 'delete_' . $i;
 
105
            global $$name;
 
106
            if (isset($$name)) {
 
107
                $fakeI --;
 
108
            } else {
 
109
                do_hook('options_identities_renumber', $i, $fakeI);
 
110
                $filled = 0;
 
111
 
 
112
                $name = 'full_name' . $i;
 
113
                global $$name;
 
114
            if ($$name != '')
 
115
                $filled ++;
 
116
                setPref($data_dir, $username, 'full_name' . $fakeI, $$name);
 
117
 
 
118
                $name = 'email_address' . $i;
 
119
                global $$name;
 
120
            if ($$name != '')
 
121
                $filled ++;
 
122
                setPref($data_dir, $username, 'email_address' . $fakeI, $$name);
 
123
 
 
124
                $name = 'reply_to' . $i;
 
125
                global $$name;
 
126
            if ($$name != '')
 
127
                $filled ++;
 
128
                setPref($data_dir, $username, 'reply_to' . $fakeI, $$name);
 
129
 
 
130
                $name = 'signature' . $i;
 
131
                global $$name;
 
132
            if ($$name != '')
 
133
                $filled ++;
 
134
                setSig($data_dir, $username, $fakeI, $$name);
 
135
 
 
136
            if ($filled == 0)
 
137
                $fakeI --;
 
138
            }
 
139
 
 
140
            $fakeI ++;
 
141
            $i ++;
 
142
            $name = 'form_for_' . $i;
 
143
            global $$name;
 
144
        }
 
145
 
 
146
        setPref($data_dir, $username, 'identities', $fakeI);
 
147
 
 
148
        while ($fakeI != $i)
 
149
        {
 
150
            removePref($data_dir, $username, 'full_name' . $fakeI);
 
151
            removePref($data_dir, $username, 'email_address' . $fakeI);
 
152
            removePref($data_dir, $username, 'reply_to' . $fakeI);
 
153
            setSig($data_dir, $username, $fakeI, "");
 
154
            $fakeI ++;
 
155
        }
 
156
 
 
157
        setPref($data_dir, $username, 'full_name', $full_name);
 
158
        setPref($data_dir, $username, 'email_address', $email_address);
 
159
        setPref($data_dir, $username, 'reply_to', $reply_to);
 
160
        setSig($data_dir, $username, "g", $signature);
 
161
        
 
162
    }
 
163
 
 
164
    function CheckAndDoDefault() {
 
165
        global $username, $data_dir, $full_name, $email_address, $reply_to, $signature;
 
166
 
 
167
        $i = 1;
 
168
        $name = 'form_for_' . $i;
 
169
        global $$name;
 
170
        while (isset($$name))
 
171
        {
 
172
            $name = 'make_default_' . $i;
 
173
            global $$name;
 
174
            if (isset($$name)) {
 
175
                do_hook('options_identities_renumber', $i, 'default');
 
176
                global $full_name, $email_address, $reply_to, $signature;
 
177
 
 
178
                $name = 'full_name' . $i;
 
179
                global $$name;
 
180
                $temp = $full_name;
 
181
                $full_name = $$name;
 
182
                $$name = $temp;
 
183
 
 
184
                $name = 'email_address' . $i;
 
185
                global $$name;
 
186
                $temp = $email_address;
 
187
                $email_address = $$name;
 
188
                $$name = $temp;
 
189
 
 
190
                $name = 'reply_to' . $i;
 
191
                global $$name;
 
192
                $temp = $reply_to;
 
193
                $reply_to = $$name;
 
194
                $$name = $temp;
 
195
 
 
196
                $name = 'signature' . $i;
 
197
                global $$name;
 
198
                $temp = $signature;
 
199
                $signature = $$name;
 
200
                $$name = $temp;
 
201
 
 
202
 
 
203
                return true;
 
204
            }
 
205
 
 
206
            $i ++;
 
207
            $name = 'form_for_' . $i;
 
208
            global $$name;
 
209
        }
 
210
        return FALSE;
 
211
    }
 
212
 
 
213
    function CheckForDelete() {
 
214
        global $username, $data_dir, $full_name, $email_address, $reply_to, $signature;
 
215
 
 
216
        $i = 1;
 
217
        $name = 'form_for_' . $i;
 
218
        global $$name;
 
219
        while (isset($$name))
 
220
        {
 
221
            $name = 'delete_' . $i;
 
222
            global $$name;
 
223
            if (isset($$name)) {
 
224
                return true;
 
225
            }
 
226
 
 
227
            $i ++;
 
228
            $name = 'form_for_' . $i;
 
229
            global $$name;
 
230
        }
 
231
        return false;
 
232
    }
 
233
 
 
234
    function CheckAndDoPromote() {
 
235
        global $username, $data_dir, $full_name, $email_address, $reply_to;
 
236
 
 
237
        $i = 1;
 
238
        $name = 'form_for_' . $i;
 
239
        global $$name;
 
240
        while (isset($$name)) {
 
241
            $name = 'promote_' . $i;
 
242
            global $$name;
 
243
            if (isset($$name) && $i > 1) {
 
244
                do_hook('options_identities_renumber', $i, $i - 1);
 
245
 
 
246
                $nameA = 'full_name' . $i;
 
247
                $nameB = 'full_name' . ($i - 1);
 
248
                global $$nameA, $$nameB;
 
249
                $temp = $$nameA;
 
250
                $$nameA = $$nameB;
 
251
                $$nameB = $temp;
 
252
    
 
253
                $nameA = 'email_address' . $i;
 
254
                $nameB = 'email_address' . ($i - 1);
 
255
                global $$nameA, $$nameB;
 
256
                $temp = $$nameA;
 
257
                $$nameA = $$nameB;
 
258
                $$nameB = $temp;
 
259
    
 
260
                $nameA = 'reply_to' . $i;
 
261
                $nameB = 'reply_to' . ($i - 1);
 
262
                global $$nameA, $$nameB;
 
263
                $temp = $$nameA;
 
264
                $$nameA = $$nameB;
 
265
                $$nameB = $temp;
 
266
 
 
267
            $nameA = 'signature' . $i;
 
268
            $nameB = 'signature' . ($i - 1);
 
269
            global $$nameA, $$nameB;
 
270
            $temp = $$nameA;
 
271
            $$nameA = $$nameB;
 
272
            $$nameB = $temp;
 
273
 
 
274
                return true;
 
275
            }
 
276
 
 
277
            $i ++;
 
278
            $name = 'form_for_' . $i;
 
279
            global $$name;
 
280
        }
 
281
        return false;
 
282
    }
 
283
 
 
284
    function LoadInfo(&$n, &$e, &$r, &$s, $post) {
 
285
        global $username, $data_dir;
 
286
 
 
287
        $n = getPref($data_dir, $username, 'full_name' . $post);
 
288
        $e = getPref($data_dir, $username, 'email_address' . $post);
 
289
        $r = getPref($data_dir, $username, 'reply_to' . $post);
 
290
        if ($post == '')
 
291
           $post = 'g';
 
292
        $s = getSig($data_dir,$username,$post);
 
293
 
 
294
        if ($n != '' || $e != '' || $r != '' || $s != '')
 
295
            return true;
 
296
    }
 
297
 
 
298
function sti_input( $title, $hd, $data, $post, $bg ) {
 
299
    $return_val = html_tag( 'tr',
 
300
                           html_tag( 'td', $title . ':', 'right', '', 'nowrap' ) .
 
301
                           html_tag( 'td', '<input size="50" type="text" value="' . htmlspecialchars($data) . '" name="' . $hd . $post . '">' , 'left' ) ,
 
302
                       '', $bg );
 
303
     return ($return_val);
 
304
}
 
305
 
 
306
function sti_textarea( $title, $hd, $data, $post, $bg ) {
 
307
    $return_val = html_tag( 'tr',
 
308
                           html_tag( 'td', $title . ':', 'right', '', 'nowrap' ) .
 
309
                           html_tag( 'td', '<textarea cols="50" rows="5" name="' . $hd . $post . '">' . htmlspecialchars($data) . '</textarea>' , 'left' ) ,
 
310
                       '', $bg );
 
311
     return ($return_val);
 
312
}
 
313
 
 
314
function ShowTableInfo($full_name, $email_address, $reply_to, $signature, $post) {
 
315
    global $color;
 
316
 
 
317
    $OtherBG = $color[0];
 
318
    if ($full_name == '' && $email_address == '' && $reply_to == '' && $signature == '')
 
319
        $OtherBG = '';
 
320
 
 
321
    if ($full_name == '' && $email_address == '' && $reply_to == '' && $signature == '')
 
322
        $isEmptySection = true;
 
323
    else
 
324
        $isEmptySection = false;
 
325
 
 
326
    $return_val = '';
 
327
    $return_val .= sti_input( _("Full Name"), 'full_name', $full_name, $post, $OtherBG );
 
328
    $return_val .= sti_input( _("E-Mail Address"), 'email_address', $email_address, $post, $OtherBG );
 
329
    $return_val .= sti_input( _("Reply To"), 'reply_to', $reply_to, $post, $OtherBG );
 
330
    $return_val .= sti_textarea( _("Signature"), 'signature', $signature, $post, $OtherBG );
 
331
 
 
332
    $return_val .= concat_hook_function('options_identities_table', array($OtherBG, $isEmptySection, $post));
 
333
    $return_val .= html_tag( 'tr', '', '', $OtherBG);
 
334
    $return_val .= html_tag( 'td', '&nbsp;', 'left' );
 
335
    $return_val .= html_tag( 'td', '', 'left' );
 
336
    $return_val .= '<input type=hidden name="form_for_'. $post .'" value="1">';
 
337
    $return_val .= '<input type="submit" name="update" value="' . _("Save / Update") . '">';
 
338
 
 
339
 
 
340
    if (! $isEmptySection && $post != '') {
 
341
        $return_val .= '<input type="submit" name="make_default_' . $post . '" value="'.
 
342
             _("Make Default") . '">'.
 
343
             '<input type=submit name="delete_' . $post . '" value="'.
 
344
             _("Delete") . '">';
 
345
    }
 
346
    if (! $isEmptySection && $post != '' && $post > 1) {
 
347
        $return_val .= '<input type=submit name="promote_' . $post . '" value="'.
 
348
             _("Move Up") . '">';
 
349
    }
 
350
    $return_val .= concat_hook_function('options_identities_buttons', array($isEmptySection, $post));
 
351
    $return_val .=  '</td></tr>'.
 
352
         html_tag( 'tr', html_tag( 'td', '&nbsp;', 'left', '', 'colspan="2"' ));
 
353
 
 
354
    return ($return_val);
 
355
}
 
356
?>