Bugfix: $empty was not always set; yields spurious notices.
[squirrelmail.git] / src / options_identities.php
1 <?php
2
3 /**
4 * options_identities.php
5 *
6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Display Identities Options
10 *
11 * @version $Id$
12 * @package squirrelmail
13 * @subpackage prefs
14 */
15
16 /**
17 * Path for SquirrelMail required files.
18 * @ignore
19 */
20 define('SM_PATH','../');
21
22 /* SquirrelMail required files. */
23 require_once(SM_PATH . 'include/validate.php');
24 include_once(SM_PATH . 'functions/global.php');
25 include_once(SM_PATH . 'functions/display_messages.php');
26 include_once(SM_PATH . 'functions/html.php');
27 include_once(SM_PATH . 'functions/identity.php');
28
29 if (!sqgetGlobalVar('identities', $identities, SQ_SESSION)) {
30 $identities = get_identities();
31 }
32 sqgetGlobalVar('newidentities', $newidentities, SQ_POST);
33 sqgetGlobalVar('smaction', $smaction, SQ_POST);
34 sqgetGlobalVar('return', $return, SQ_POST);
35
36 // First lets see if there are any actions to perform //
37 if (!empty($smaction) && is_array($smaction)) {
38
39 $doaction = '';
40 $identid = 0;
41
42 foreach($smaction as $action=>$row) {
43 // we only need to extract the action and the identity we are
44 // altering
45
46 foreach($row as $key=>$data) {
47 $identid = $key;
48 }
49
50 $doaction = $action;
51 }
52
53 $identities = sqfixidentities( $newidentities , $identid , $action );
54 save_identities($identities);
55 }
56
57 if (!empty($return)) {
58 header('Location: ' . get_location() . '/options_personal.php');
59 exit;
60 }
61
62 displayPageHeader($color, 'None');
63
64 do_hook('options_identities_top');
65
66 $td_str = '';
67 $td_str .= '<form name="f" action="options_identities.php" method="post"><br />' . "\n";
68 $td_str .= '<table border="0" cellspacing="0" cellpadding="0" width="100%">' . "\n";
69 $cnt = count($identities);
70 foreach( $identities as $key=>$ident ) {
71
72 if ($key == 0) {
73 $hdr_str = _("Default Identity");
74 } else {
75 $hdr_str = sprintf( _("Alternate Identity %d"), $key);
76 }
77
78 $td_str .= ShowIdentityInfo( $hdr_str, $ident, $key );
79
80 }
81
82 $td_str .= ShowIdentityInfo( _("Add a New Identity"), array('full_name'=>'','email_address'=>'','reply_to'=>'','signature'=>''), $cnt);
83 $td_str .= '</table>' . "\n";
84 $td_str .= '</form>';
85
86 echo '<br /> ' . "\n" .
87 html_tag('table', "\n" .
88 html_tag('tr', "\n" .
89 html_tag('td' , "\n" .
90 '<b>' . _("Options") . ' - ' . _("Advanced Identities") . '</b><br />' .
91 html_tag('table', "\n" .
92 html_tag('tr', "\n" .
93 html_tag('td', "\n" .
94 html_tag('table' , "\n" .
95 html_tag('tr' , "\n" .
96 html_tag('td', "\n" . $td_str ,'','', 'style="text-align:center;"')
97 ),
98 '', '', 'width="80%" cellpadding="2" cellspacing="0" border="0"' ) ,
99 'center', $color[4])
100 ),
101 '', '', 'width="100%" border="0" cellpadding="1" cellspacing="1"' )) ,
102 'center', $color[0]),
103 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"' ) . '</body></html>';
104
105
106 function ShowIdentityInfo($title, $identity, $id ) {
107 global $color;
108
109 if (empty($identity['full_name']) && empty($identity['email_address']) && empty($identity['reply_to']) && empty($identity['signature'])) {
110 $bg = '';
111 $empty = true;
112 } else {
113 $bg = ' style="background-color:' . $color[0] . ';"';
114 $empty = false;
115 }
116
117 $name = 'newidentities[%d][%s]';
118
119
120 $return_str = '';
121
122 $return_str .= '<tr>' . "\n";
123 $return_str .= ' <th style="text-align:center;background-color:' . $color[9] . ';" colspan="2">' . $title . '</th> '. "\n";
124 $return_str .= '</tr>' . "\n";
125 $return_str .= sti_input( _("Full Name") , sprintf($name, $id, 'full_name'), $identity['full_name'], $bg);
126 $return_str .= sti_input( _("E-Mail Address") , sprintf($name, $id, 'email_address'), $identity['email_address'], $bg);
127 $return_str .= sti_input( _("Reply To"), sprintf($name, $id, 'reply_to'), $identity['reply_to'], $bg);
128 $return_str .= sti_textarea( _("Signature"), sprintf($name, $id, 'signature'), $identity['signature'], $bg);
129 $return_str .= concat_hook_function('options_identities_table', array($bg, $empty, $id));
130 $return_str .= '<tr' . $bg . '> ' . "\n";
131 $return_str .= ' <td> &nbsp; </td>' . "\n";
132 $return_str .= ' <td>' . "\n";
133 $return_str .= ' <input type="submit" name="smaction[save][' . $id . ']" value="' . _("Save / Update") . '" />' . "\n";
134
135 if (!$empty && $id > 0) {
136 $return_str .= ' <input type="submit" name="smaction[makedefault][' . $id . ']" value="' . _("Make Default") . '" />' . "\n";
137 $return_str .= ' <input type="submit" name="smaction[delete]['.$id.']" value="' . _("Delete") . '" />' . "\n";
138
139 if ($id > 1) {
140 $return_str .= ' <input type="submit" name="smaction[move]['.$id.']" value="' . _("Move Up") . '" />' . "\n";
141 }
142
143 }
144
145 $return_str .= concat_hook_function('options_identities_buttons', array($empty, $id));
146 $return_str .= ' </td>' . "\n";
147 $return_str .= '</tr>' . "\n";
148 $return_str .= '<tr>' . "\n";
149 $return_str .= ' <td colspan="2"> &nbsp; </td>' . "\n";
150 $return_str .= '</tr>';
151
152 return $return_str;
153
154 }
155
156 function sti_input( $title, $name, $data, $bgcolor ) {
157 $str = '';
158 $str .= '<tr' . $bgcolor . ">\n";
159 $str .= ' <td style="white-space: nowrap;text-align:right;">' . $title . ' </td>' . "\n";
160 $str .= ' <td> <input type="text" name="' . $name . '" size="50" value="'. htmlspecialchars($data) . '"> </td>' . "\n";
161 $str .= '</tr>';
162
163 return $str;
164
165 }
166
167 function sti_textarea( $title, $name, $data, $bgcolor ) {
168 $str = '';
169 $str .= '<tr' . $bgcolor . ">\n";
170 $str .= ' <td style="white-space: nowrap;text-align:right;">' . $title . ' </td>' . "\n";
171 $str .= ' <td> <textarea name="' . $name . '" cols="50" rows="5">'. htmlspecialchars($data) . '</textarea> </td>' . "\n";
172 $str .= '</tr>';
173
174 return $str;
175
176 }
177
178 ?>