Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 97585
Collapse All | Expand All

(-)squirrelmail/squirrelmail/functions/identity.php (+135 lines)
Lines 59-62 Link Here
59
    return $identities;
59
    return $identities;
60
}
60
}
61
/**
62
 * Function to save the identities array
63
 *
64
 * @param  array     $identities     Array of identities
65
 */
66
function save_identities($identities) {
67
68
    global $username, $data_dir, $domain;
69
70
    if (empty($identities) || !is_array($identities)) {
71
        return;
72
    }
73
74
75
    $num_cur = getPref($data_dir, $username, 'identities');
76
77
    $cnt = count($identities);
78
79
    // Remove any additional identities in prefs //
80
    for($i=$cnt; $i <= $num_cur; $i++) {
81
        removePref($data_dir, $username, 'full_name' . $i);
82
        removePref($data_dir, $username, 'email_address' . $i);
83
        removePref($data_dir, $username, 'reply_to' . $i);
84
        setSig($data_dir, $username, $i, '');
85
    }
86
87
    foreach($identities as $id=>$ident) {
88
89
        $key = ($id?$id:'');
90
91
        setPref($data_dir, $username, 'full_name' . $key, $ident['full_name']);
92
        setPref($data_dir, $username, 'email_address' . $key, $ident['email_address']);
93
        setPref($data_dir, $username, 'reply_to' . $key, $ident['reply_to']);
94
95
        if ($id === 0) {
96
            setSig($data_dir, $username, 'g', $ident['signature']);
97
        } else {
98
            setSig($data_dir, $username, $key, $ident['signature']);
99
        }
100
101
    }
102
103
    setPref($data_dir, $username, 'identities', $cnt);
104
105
}
106
107
/**
108
 * Returns an array with a fixed set of identities
109
 *
110
 * @param   array       $identities      Array of identities
111
 * @param   int         $id             Identity to modify
112
 * @param   string      $action         Action to perform
113
 * @return  array
114
 */
115
function sqfixidentities( $identities, $id, $action ) {
116
117
    $fixed = array();
118
    $tmp_hold = array();
119
    $i = 0;
120
121
    if (empty($identities) || !is_array($identities)) {
122
        return $fixed;
123
    }
124
125
    foreach( $identities as $key=>$ident ) {
126
127
        if (empty_identity($ident)) {
128
            continue;
129
        }
130
131
        switch($action) {
132
133
            case 'makedefault':
134
135
                if ($key == $id) {
136
                    $fixed[0] = $ident;
137
                    continue 2;
138
                } else {
139
                    $fixed[$i+1] = $ident;
140
                }
141
                break;
142
143
            case 'move':
144
145
                if ($key == ($id - 1)) {
146
                    $tmp_hold = $ident;
147
                    continue 2;
148
                } else {
149
                    $fixed[$i] = $ident;
150
151
                    if ($key == $id) {
152
                        $i++;
153
                        $fixed[$i] = $tmp_hold;
154
                    }
155
                }
156
                break;
157
158
            case 'delete':
159
160
                if ($key == $id) {
161
                    continue 2;
162
                } else {
163
                    $fixed[$i] = $ident;
164
                }
165
                break;
166
167
            // we should never hit this but just in case //
168
            default:
169
                $fixed[$i] = $ident;
170
171
        }
172
173
        // Inc array index //
174
        $i++;
175
    }
176
177
    ksort($fixed);
178
    return $fixed;
179
180
}
181
182
/**
183
 * Function to test if identity is empty
184
 *
185
 * @param   array   $identity   Identitiy Array
186
 * @return  boolean
187
 */
188
function empty_identity($ident) {
189
    if (empty($ident['full_name']) && empty($ident['email_address']) && empty($ident['signature']) && empty($ident['reply_to'])) {
190
        return true;
191
    } else {
192
        return false;
193
    }
194
}
195
61
?>
196
?>
(-)options_identities.php (-282 / +101 lines)
Lines 20-74 Link Here
20
/* SquirrelMail required files. */
21
/* SquirrelMail required files. */
21
require_once(SM_PATH . 'include/validate.php');
22
require_once(SM_PATH . 'include/validate.php');
22
require_once(SM_PATH . 'functions/global.php');
23
include_once(SM_PATH . 'functions/global.php');
23
require_once(SM_PATH . 'functions/display_messages.php');
24
include_once(SM_PATH . 'functions/display_messages.php');
24
require_once(SM_PATH . 'functions/html.php');
25
include_once(SM_PATH . 'functions/html.php');
25
26
include_once(SM_PATH . 'functions/identity.php');
26
/* POST data var names are dynamic because
27
   of the possible multiple idents so lets get
28
   them all
29
*/
30
if (!empty($_POST)) {
31
    extract($_POST);
32
}
33
/* got 'em all */
34
    if (isset($return)) {
27
if (!sqgetGlobalVar('identities', $identities, SQ_SESSION)) {
35
       SaveUpdateFunction();
28
    $identities = get_identities();
36
       header('Location: options_personal.php');
37
       exit();
38
    }
29
    }
39
    displayPageHeader($color, 'None');
30
sqgetGlobalVar('newidentities', $newidentities, SQ_POST);
31
sqgetGlobalVar('smaction', $smaction, SQ_POST);
32
sqgetGlobalVar('return', $return, SQ_POST);
40
    $Info = do_hook('options_identities_process', 0);
33
// First lets see if there are any actions to perform //
41
    if ($Info[1]) {
34
if (!empty($smaction) && is_array($smaction)) {
42
        SaveUpdateFunction();
35
36
    $doaction = '';
37
    $identid = 0;
38
    foreach($smaction as $action=>$row) {
39
        // we only need to extract the action and the identity we are
40
        // altering
41
42
        foreach($row as $key=>$data) {
43
            $identid = $key;
43
    }
44
    }
44
    if (CheckAndDoDefault() || CheckAndDoPromote()) {
45
        $doaction = $action;
45
       SaveUpdateFunction();
46
    }
46
    }
47
    if (isset($update) || CheckForDelete()) {
47
48
        SaveUpdateFunction();
48
    $identities = sqfixidentities( $newidentities , $identid , $action );
49
    save_identities($identities);
49
    }
50
    }
51
if (!empty($return)) {
52
    header('Location: ' . get_location() . '/options_personal.php');
53
    exit;
54
}
55
56
displayPageHeader($color, 'None');
57
50
   do_hook('options_identities_top');
58
   do_hook('options_identities_top');
51
   LoadInfo($full_name, $email_address, $reply_to, $signature, '');
59
52
   $td_str = '';
60
   $td_str = '';
53
   $td_str .= '<form name="f" action="options_identities.php" method="post"><br />';
61
$td_str .= '<form name="f" action="options_identities.php" method="post"><br />' . "\n";
54
   $td_str .= ShowTableInfo($full_name, $email_address, $reply_to, $signature, '');
62
$td_str .= '<table border="0" cellspacing="0" cellpadding="0" width="100%">' . "\n";
63
$cnt = count($identities);
64
foreach( $identities as $key=>$ident ) {
65
66
    if ($key == 0) {
67
        $hdr_str = _("Default Identity");
68
    } else {
69
        $hdr_str = sprintf( _("Alternate Identity %d"), $key);
70
    }
71
72
    $td_str .= ShowIdentityInfo( $hdr_str, $ident, $key );
55
   $num = 1;
56
   while (LoadInfo($full_name, $email_address, $reply_to, $signature, $num)) {
57
       $td_str .= html_tag( 'tr',
58
                          html_tag( 'th', sprintf (_("Alternate Identity %d"), $num), 'center', '', 'colspan="2"' ) ,
59
                      '', $color[9]);
60
       $td_str .= ShowTableInfo($full_name, $email_address, $reply_to, $signature, $num);
61
       $num ++;
62
       }
73
       }
63
   echo '<br />' .
74
$td_str .= ShowIdentityInfo( _("Add a New Identity"), array('full_name'=>'','email_address'=>'','reply_to'=>'','signature'=>''), $cnt);
75
$td_str .= '</table>' . "\n";
76
$td_str .= '</form>';
77
78
echo '<br /> ' . "\n" .
64
   html_tag( 'table', "\n" .
79
   html_tag( 'table', "\n" .
65
       html_tag( 'tr', "\n" .
80
       html_tag( 'tr', "\n" .
66
           html_tag( 'td', "\n" .
81
           html_tag( 'td', "\n" .
Lines 78-358 Link Here
78
                       html_tag( 'td', "\n" .
93
                       html_tag( 'td', "\n" .
79
                           html_tag( 'table', "\n" .
94
                           html_tag( 'table', "\n" .
80
                               html_tag( 'tr', "\n" .
95
                               html_tag( 'tr', "\n" .
81
                                   html_tag( 'th', _("Default Identity"), 'center', '', 'colspan="2"' ) ,
96
                                html_tag('td', "\n" .  $td_str ,'','', 'style="text-align:center;"')
82
                                   '', $color[9]) . "\n" .
97
                            ),
83
                                   $td_str . "\n" .
84
                       html_tag( 'tr',
85
                                   html_tag( 'th', _("Add a New Identity") . ShowTableInfo('', '', '', '', $num), 'center', '', 'colspan="2"' ) ,
86
                               '', $color[9]) ,
87
                            '', '', 'width="80%" cellpadding="2" cellspacing="0" border="0"' ) ,
98
                            '', '', 'width="80%" cellpadding="2" cellspacing="0" border="0"' ) ,
88
                       'center', $color[4] )
99
                       'center', $color[4] )
89
                   ) ,
100
                   ) ,
90
               '', '', 'width="100%" border="0" cellpadding="1" cellspacing="1"' ) ,
101
            '', '', 'width="100%" border="0" cellpadding="1" cellspacing="1"' )) ,
91
           'center', $color[0] )
102
        'center', $color[0]),
92
       ) ,
103
    'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"' ) . '</body></html>';
93
   'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"' ) .
94
   '</body></html>';
104
function ShowIdentityInfo($title, $identity, $id ) {
95
    function SaveUpdateFunction() {
105
    global $color;
96
        global $username, $data_dir, $full_name, $email_address, $reply_to, $signature;
97
        $i = 1;
106
    if (empty($identity['full_name']) && empty($identity['email_address']) && empty($identity['reply_to']) && empty($identity['signature'])) {
98
        $fakeI = 1;
107
        $bg = '';
99
        $name = 'form_for_' . $i;
108
        $empty = true;
100
        global $$name;
101
        while (isset($$name))
102
        {
103
            $name = 'delete_' . $i;
104
            global $$name;
105
            if (isset($$name)) {
106
                $fakeI --;
107
            } else {
109
            } else {
108
                do_hook('options_identities_renumber', $i, $fakeI);
110
        $bg = ' style="background-color:' . $color[0] . ';"';
109
                $filled = 0;
111
        $empty = false;
110
111
                $name = 'full_name' . $i;
112
                global $$name;
113
            if ($$name != '')
114
                $filled ++;
115
                setPref($data_dir, $username, 'full_name' . $fakeI, $$name);
116
117
                $name = 'email_address' . $i;
118
                global $$name;
119
            if ($$name != '')
120
                $filled ++;
121
                setPref($data_dir, $username, 'email_address' . $fakeI, $$name);
122
123
                $name = 'reply_to' . $i;
124
                global $$name;
125
            if ($$name != '')
126
                $filled ++;
127
                setPref($data_dir, $username, 'reply_to' . $fakeI, $$name);
128
129
                $name = 'signature' . $i;
130
                global $$name;
131
            if ($$name != '')
132
                $filled ++;
133
                setSig($data_dir, $username, $fakeI, $$name);
134
135
            if ($filled == 0)
136
                $fakeI --;
137
            }
138
139
            $fakeI ++;
140
            $i ++;
141
            $name = 'form_for_' . $i;
142
            global $$name;
143
        }
112
        }
144
        setPref($data_dir, $username, 'identities', $fakeI);
113
    $name = 'newidentities[%d][%s]';
145
        while ($fakeI != $i)
114
    $return_str = '';
146
        {
147
            removePref($data_dir, $username, 'full_name' . $fakeI);
148
            removePref($data_dir, $username, 'email_address' . $fakeI);
149
            removePref($data_dir, $username, 'reply_to' . $fakeI);
150
            setSig($data_dir, $username, $fakeI, "");
151
            $fakeI ++;
152
        }
153
154
        setPref($data_dir, $username, 'full_name', $full_name);
155
        setPref($data_dir, $username, 'email_address', $email_address);
156
        setPref($data_dir, $username, 'reply_to', $reply_to);
157
        setSig($data_dir, $username, "g", $signature);
158
159
    }
160
161
    function CheckAndDoDefault() {
162
        global $username, $data_dir, $full_name, $email_address, $reply_to, $signature;
163
164
        $i = 1;
165
        $name = 'form_for_' . $i;
166
        global $$name;
167
        while (isset($$name))
168
        {
169
            $name = 'make_default_' . $i;
170
            global $$name;
171
            if (isset($$name)) {
172
                do_hook('options_identities_renumber', $i, 'default');
173
                global $full_name, $email_address, $reply_to, $signature;
174
175
                $name = 'full_name' . $i;
176
                global $$name;
177
                $temp = $full_name;
178
                $full_name = $$name;
179
                $$name = $temp;
180
                $name = 'email_address' . $i;
181
                global $$name;
182
                $temp = $email_address;
183
                $email_address = $$name;
184
                $$name = $temp;
185
                $name = 'reply_to' . $i;
115
    $return_str .= '<tr>' . "\n";
186
                global $$name;
116
    $return_str .= '  <th style="text-align:center;background-color:' . $color[9] . ';" colspan="2">' . $title . '</th> '. "\n";
187
                $temp = $reply_to;
117
    $return_str .= '</tr>' . "\n";
188
                $reply_to = $$name;
118
    $return_str .= sti_input( _("Full Name") , sprintf($name, $id, 'full_name'), $identity['full_name'], $bg);
189
                $$name = $temp;
119
    $return_str .= sti_input( _("E-Mail Address") , sprintf($name, $id, 'email_address'), $identity['email_address'], $bg);
120
    $return_str .= sti_input( _("Reply To"), sprintf($name, $id, 'reply_to'), $identity['reply_to'], $bg);
121
    $return_str .= sti_textarea( _("Signature"), sprintf($name, $id, 'signature'), $identity['signature'], $bg);
122
    $return_str .= concat_hook_function('options_identities_table', array($bg, $empty, $id));
123
    $return_str .= '<tr' . $bg . '> ' . "\n";
124
    $return_str .= '  <td> &nbsp; </td>' . "\n";
125
    $return_str .= '  <td>' . "\n";
126
    $return_str .= '    <input type="submit" name="smaction[save][' . $id . ']" value="' . _("Save / Update") . '" />' . "\n";
190
                $name = 'signature' . $i;
127
    if (!$empty && $id > 0) {
191
                global $$name;
128
        $return_str .= '    <input type="submit" name="smaction[makedefault][' . $id . ']" value="' . _("Make Default") . '" />' . "\n";
192
                $temp = $signature;
129
        $return_str .= '    <input type="submit" name="smaction[delete]['.$id.']" value="' . _("Delete") . '" />' . "\n";
193
                $signature = $$name;
194
                $$name = $temp;
195
130
        if ($id > 1) {
196
                return true;
131
            $return_str .= '    <input type="submit" name="smaction[move]['.$id.']" value="' . _("Move Up") . '" />' . "\n";
197
            }
132
            }
198
            $i ++;
199
            $name = 'form_for_' . $i;
200
            global $$name;
201
        }
202
        return FALSE;
203
    }
133
    }
204
    function CheckForDelete() {
134
    $return_str .= concat_hook_function('options_identities_buttons', array($empty, $id));
205
        global $username, $data_dir, $full_name, $email_address, $reply_to, $signature;
135
    $return_str .= '  </td>' . "\n";
136
    $return_str .= '</tr>' . "\n";
137
    $return_str .= '<tr>' . "\n";
138
    $return_str .= '  <td colspan="2"> &nbsp; </td>' . "\n";
139
    $return_str .= '</tr>';
206
        $i = 1;
140
    return $return_str;
207
        $name = 'form_for_' . $i;
208
        global $$name;
209
        while (isset($$name))
210
        {
211
            $name = 'delete_' . $i;
212
            global $$name;
213
            if (isset($$name)) {
214
                return true;
215
            }
216
            $i ++;
217
            $name = 'form_for_' . $i;
218
            global $$name;
219
        }
141
        }
220
        return false;
142
function sti_input( $title, $name, $data, $bgcolor ) {
221
    }
143
    $str = '';
222
144
    $str .= '<tr' . $bgcolor . ">\n";
223
    function CheckAndDoPromote() {
145
    $str .= '  <td style="white-space: nowrap;text-align:right;">' . $title . ' </td>' . "\n";
224
        global $username, $data_dir, $full_name, $email_address, $reply_to;
146
    $str .= '  <td> <input type="text" name="' . $name . '" size="50" value="'. htmlspecialchars($data) . '"> </td>' . "\n";
225
147
    $str .= '</tr>';
226
        $i = 1;
227
        $name = 'form_for_' . $i;
228
        global $$name;
229
        while (isset($$name)) {
230
            $name = 'promote_' . $i;
231
            global $$name;
232
            if (isset($$name) && $i > 1) {
233
                do_hook('options_identities_renumber', $i, $i - 1);
234
                $nameA = 'full_name' . $i;
235
                $nameB = 'full_name' . ($i - 1);
236
                global $$nameA, $$nameB;
237
                $temp = $$nameA;
238
                $$nameA = $$nameB;
239
                $$nameB = $temp;
240
                $nameA = 'email_address' . $i;
148
    return $str;
241
                $nameB = 'email_address' . ($i - 1);
242
                global $$nameA, $$nameB;
243
                $temp = $$nameA;
244
                $$nameA = $$nameB;
245
                $$nameB = $temp;
246
                $nameA = 'reply_to' . $i;
247
                $nameB = 'reply_to' . ($i - 1);
248
                global $$nameA, $$nameB;
249
                $temp = $$nameA;
250
                $$nameA = $$nameB;
251
                $$nameB = $temp;
252
253
            $nameA = 'signature' . $i;
254
            $nameB = 'signature' . ($i - 1);
255
            global $$nameA, $$nameB;
256
            $temp = $$nameA;
257
            $$nameA = $$nameB;
258
            $$nameB = $temp;
259
260
                return true;
261
            }
149
            }
262
            $i ++;
150
function sti_textarea( $title, $name, $data, $bgcolor ) {
263
            $name = 'form_for_' . $i;
151
    $str = '';
264
            global $$name;
152
    $str .= '<tr' . $bgcolor . ">\n";
265
        }
153
    $str .= '  <td style="white-space: nowrap;text-align:right;">' . $title . ' </td>' . "\n";
266
        return false;
154
    $str .= '  <td> <textarea name="' . $name . '" cols="50" rows="5">'. htmlspecialchars($data) . '</textarea> </td>' . "\n";
267
    }
155
    $str .= '</tr>';
268
    function LoadInfo(&$n, &$e, &$r, &$s, $post) {
156
    return $str;
269
        global $username, $data_dir;
270
271
        $n = getPref($data_dir, $username, 'full_name' . $post);
272
        $e = getPref($data_dir, $username, 'email_address' . $post);
273
        $r = getPref($data_dir, $username, 'reply_to' . $post);
274
        if ($post == '')
275
           $post = 'g';
276
        $s = getSig($data_dir,$username,$post);
277
278
        if ($n != '' || $e != '' || $r != '' || $s != '')
279
            return true;
280
    }
281
function sti_input( $title, $hd, $data, $post, $bg ) {
282
    $return_val = html_tag( 'tr',
283
                           html_tag( 'td', $title . ':', 'right', '', 'nowrap' ) .
284
                           html_tag( 'td', '<input size="50" type="text" value="' . htmlspecialchars($data) . '" name="' . $hd . $post . '" />' , 'left' ) ,
285
                       '', $bg );
286
     return ($return_val);
287
}
157
}
288
function sti_textarea( $title, $hd, $data, $post, $bg ) {
289
    $return_val = html_tag( 'tr',
290
                           html_tag( 'td', $title . ':', 'right', '', 'nowrap' ) .
291
                           html_tag( 'td', '<textarea cols="50" rows="5" name="' . $hd . $post . '">' . htmlspecialchars($data) . '</textarea>' , 'left' ) ,
292
                       '', $bg );
293
     return ($return_val);
294
}
295
296
function ShowTableInfo($full_name, $email_address, $reply_to, $signature, $post) {
297
    global $color;
298
299
    $OtherBG = $color[0];
300
    if ($full_name == '' && $email_address == '' && $reply_to == '' && $signature == '')
301
        $OtherBG = '';
302
303
    if ($full_name == '' && $email_address == '' && $reply_to == '' && $signature == '')
304
        $isEmptySection = true;
305
    else
306
        $isEmptySection = false;
307
308
    $return_val = '';
309
    $return_val .= sti_input( _("Full Name"), 'full_name', $full_name, $post, $OtherBG );
310
    $return_val .= sti_input( _("E-Mail Address"), 'email_address', $email_address, $post, $OtherBG );
311
    $return_val .= sti_input( _("Reply To"), 'reply_to', $reply_to, $post, $OtherBG );
312
    $return_val .= sti_textarea( _("Signature"), 'signature', $signature, $post, $OtherBG );
313
314
    $return_val .= concat_hook_function('options_identities_table', array($OtherBG, $isEmptySection, $post));
315
    $return_val .= html_tag( 'tr', '', '', $OtherBG);
316
    $return_val .= html_tag( 'td', '&nbsp;', 'left' );
317
    $return_val .= html_tag( 'td', '', 'left' );
318
    $return_val .= '<input type="hidden" name="form_for_'. $post .'" value="1" />';
319
    $return_val .= '<input type="submit" name="update" value="' . _("Save / Update") . '" />';
320
321
322
    if (! $isEmptySection && $post != '') {
323
        $return_val .= '<input type="submit" name="make_default_' . $post . '" value="'.
324
             _("Make Default") . '" />'.
325
             '<input type="submit" name="delete_' . $post . '" value="'.
326
             _("Delete") . '" />';
327
    }
328
    if (! $isEmptySection && $post != '' && $post > 1) {
329
        $return_val .= '<input type="submit" name="promote_' . $post . '" value="'.
330
             _("Move Up") . '" />';
331
    }
332
    $return_val .= concat_hook_function('options_identities_buttons', array($isEmptySection, $post));
333
    $return_val .=  '</td></tr>'.
334
         html_tag( 'tr', html_tag( 'td', '&nbsp;', 'left', '', 'colspan="2"' ));
335
336
    return ($return_val);
337
}
338
?>
158
?>

Return to bug 97585