aaf9abef |
1 | <?php |
895905c0 |
2 | |
35586184 |
3 | /** |
4 | * options_identities.php |
5 | * |
35586184 |
6 | * Display Identities Options |
7 | * |
47ccfad4 |
8 | * @copyright © 1999-2006 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 |
0f01b5d7 |
13 | * @since 1.1.3 |
35586184 |
14 | */ |
15 | |
30967a1e |
16 | /** |
202bcbcc |
17 | * Include the SquirrelMail initialization file. |
30967a1e |
18 | */ |
202bcbcc |
19 | require('../include/init.php'); |
86725763 |
20 | |
21 | /* SquirrelMail required files. */ |
202bcbcc |
22 | require_once(SM_PATH . 'functions/identity.php'); |
aaf9abef |
23 | |
e7f9c987 |
24 | if (!sqgetGlobalVar('identities', $identities, SQ_SESSION)) { |
25 | $identities = get_identities(); |
fe369c70 |
26 | } |
e7f9c987 |
27 | sqgetGlobalVar('newidentities', $newidentities, SQ_POST); |
28 | sqgetGlobalVar('smaction', $smaction, SQ_POST); |
29 | sqgetGlobalVar('return', $return, SQ_POST); |
fe369c70 |
30 | |
e7f9c987 |
31 | // First lets see if there are any actions to perform // |
32 | if (!empty($smaction) && is_array($smaction)) { |
91e0dccc |
33 | |
e7f9c987 |
34 | $doaction = ''; |
35 | $identid = 0; |
91e0dccc |
36 | |
e7f9c987 |
37 | foreach($smaction as $action=>$row) { |
38 | // we only need to extract the action and the identity we are |
39 | // altering |
91e0dccc |
40 | |
bb51bc8b |
41 | foreach($row as $iKey=>$data) { |
42 | $identid = $iKey; |
e7f9c987 |
43 | } |
44 | |
45 | $doaction = $action; |
32f4e318 |
46 | } |
91e0dccc |
47 | |
e7f9c987 |
48 | $identities = sqfixidentities( $newidentities , $identid , $action ); |
49 | save_identities($identities); |
50 | } |
e697b6cc |
51 | |
e7f9c987 |
52 | if (!empty($return)) { |
53 | header('Location: ' . get_location() . '/options_personal.php'); |
54 | exit; |
55 | } |
e697b6cc |
56 | |
e7f9c987 |
57 | displayPageHeader($color, 'None'); |
e697b6cc |
58 | |
0f01b5d7 |
59 | /* since 1.1.3 */ |
e7f9c987 |
60 | do_hook('options_identities_top'); |
91e0dccc |
61 | |
e7f9c987 |
62 | $td_str = ''; |
63 | $td_str .= '<form name="f" action="options_identities.php" method="post"><br />' . "\n"; |
64 | $td_str .= '<table border="0" cellspacing="0" cellpadding="0" width="100%">' . "\n"; |
65 | $cnt = count($identities); |
bb51bc8b |
66 | foreach( $identities as $iKey=>$ident ) { |
e697b6cc |
67 | |
bb51bc8b |
68 | if ($iKey == 0) { |
e7f9c987 |
69 | $hdr_str = _("Default Identity"); |
70 | } else { |
bb51bc8b |
71 | $hdr_str = sprintf( _("Alternate Identity %d"), $iKey); |
e697b6cc |
72 | } |
73 | |
bb51bc8b |
74 | $td_str .= ShowIdentityInfo( $hdr_str, $ident, $iKey ); |
e697b6cc |
75 | |
e7f9c987 |
76 | } |
77 | |
78 | $td_str .= ShowIdentityInfo( _("Add a New Identity"), array('full_name'=>'','email_address'=>'','reply_to'=>'','signature'=>''), $cnt); |
79 | $td_str .= '</table>' . "\n"; |
80 | $td_str .= '</form>'; |
81 | |
82 | echo '<br /> ' . "\n" . |
83 | html_tag('table', "\n" . |
84 | html_tag('tr', "\n" . |
bb51bc8b |
85 | html_tag('td' , "\n" . |
e7f9c987 |
86 | '<b>' . _("Options") . ' - ' . _("Advanced Identities") . '</b><br />' . |
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', "\n" . $td_str ,'','', 'style="text-align:center;"') |
93 | ), |
94 | '', '', 'width="80%" cellpadding="2" cellspacing="0" border="0"' ) , |
95 | 'center', $color[4]) |
96 | ), |
97 | '', '', 'width="100%" border="0" cellpadding="1" cellspacing="1"' )) , |
98 | 'center', $color[0]), |
99 | 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"' ) . '</body></html>'; |
bb51bc8b |
100 | |
0f01b5d7 |
101 | /** |
102 | * Returns html formated identity form fields |
bb51bc8b |
103 | * |
0f01b5d7 |
104 | * Contains options_identities_buttons and option_identities_table hooks. |
bb51bc8b |
105 | * Before 1.4.5/1.5.1 hooks were placed in ShowTableInfo() function. |
106 | * In 1.1.3-1.4.1 they were called in do_hook function with two or |
0f01b5d7 |
107 | * three arguments. Since 1.4.1 hooks are called in concat_hook_function. |
108 | * Arguments are moved to array. |
109 | * |
110 | * options_identities_buttons hook uses array with two keys. First array key is |
bb51bc8b |
111 | * boolean variable used to indicate empty identity field. Second array key |
0f01b5d7 |
112 | * is integer variable used to indicate identity number |
113 | * |
114 | * options_identities_table hook uses array with three keys. First array key is |
bb51bc8b |
115 | * a string containing background color style CSS (1.4.1-1.4.4/1.5.0 uses only |
116 | * html color code). Second array key is boolean variable used to indicate empty |
117 | * identity field. Third array key is integer variable used to indicate identity |
0f01b5d7 |
118 | * number |
119 | * @param string $title Name displayed in header row |
120 | * @param array $identity Identity information |
121 | * @param integer $id identity ID |
122 | * @return string html formatted table rows with form fields for identity management |
123 | * @since 1.5.1 and 1.4.5 (was called ShowTableInfo() in 1.1.3-1.4.4 and 1.5.0) |
124 | */ |
e7f9c987 |
125 | function ShowIdentityInfo($title, $identity, $id ) { |
126 | global $color; |
127 | |
128 | if (empty($identity['full_name']) && empty($identity['email_address']) && empty($identity['reply_to']) && empty($identity['signature'])) { |
129 | $bg = ''; |
130 | $empty = true; |
131 | } else { |
132 | $bg = ' style="background-color:' . $color[0] . ';"'; |
f9632976 |
133 | $empty = false; |
e697b6cc |
134 | } |
135 | |
e7f9c987 |
136 | $name = 'newidentities[%d][%s]'; |
137 | |
e697b6cc |
138 | |
e7f9c987 |
139 | $return_str = ''; |
140 | |
141 | $return_str .= '<tr>' . "\n"; |
142 | $return_str .= ' <th style="text-align:center;background-color:' . $color[9] . ';" colspan="2">' . $title . '</th> '. "\n"; |
143 | $return_str .= '</tr>' . "\n"; |
144 | $return_str .= sti_input( _("Full Name") , sprintf($name, $id, 'full_name'), $identity['full_name'], $bg); |
145 | $return_str .= sti_input( _("E-Mail Address") , sprintf($name, $id, 'email_address'), $identity['email_address'], $bg); |
146 | $return_str .= sti_input( _("Reply To"), sprintf($name, $id, 'reply_to'), $identity['reply_to'], $bg); |
147 | $return_str .= sti_textarea( _("Signature"), sprintf($name, $id, 'signature'), $identity['signature'], $bg); |
148 | $return_str .= concat_hook_function('options_identities_table', array($bg, $empty, $id)); |
149 | $return_str .= '<tr' . $bg . '> ' . "\n"; |
150 | $return_str .= ' <td> </td>' . "\n"; |
151 | $return_str .= ' <td>' . "\n"; |
152 | $return_str .= ' <input type="submit" name="smaction[save][' . $id . ']" value="' . _("Save / Update") . '" />' . "\n"; |
153 | |
154 | if (!$empty && $id > 0) { |
155 | $return_str .= ' <input type="submit" name="smaction[makedefault][' . $id . ']" value="' . _("Make Default") . '" />' . "\n"; |
156 | $return_str .= ' <input type="submit" name="smaction[delete]['.$id.']" value="' . _("Delete") . '" />' . "\n"; |
157 | |
158 | if ($id > 1) { |
159 | $return_str .= ' <input type="submit" name="smaction[move]['.$id.']" value="' . _("Move Up") . '" />' . "\n"; |
160 | } |
e697b6cc |
161 | |
e697b6cc |
162 | } |
163 | |
e7f9c987 |
164 | $return_str .= concat_hook_function('options_identities_buttons', array($empty, $id)); |
165 | $return_str .= ' </td>' . "\n"; |
166 | $return_str .= '</tr>' . "\n"; |
167 | $return_str .= '<tr>' . "\n"; |
168 | $return_str .= ' <td colspan="2"> </td>' . "\n"; |
169 | $return_str .= '</tr>'; |
170 | |
171 | return $return_str; |
aaf9abef |
172 | |
01265fba |
173 | } |
174 | |
0f01b5d7 |
175 | /** |
176 | * Creates html formated table row with input field |
177 | * @param string $title Name displayed next to input field |
178 | * @param string $name Name of input field |
179 | * @param string $data Default value of input field (data is sanitized with htmlspecialchars) |
180 | * @param string $bgcolor html attributes added to row element (tr) |
181 | * @return string html formated table row with text input field |
182 | * @since 1.2.0 (arguments differ since 1.4.5/1.5.1) |
183 | * @todo check right-to-left language issues |
184 | * @access private |
185 | */ |
e7f9c987 |
186 | function sti_input( $title, $name, $data, $bgcolor ) { |
187 | $str = ''; |
188 | $str .= '<tr' . $bgcolor . ">\n"; |
189 | $str .= ' <td style="white-space: nowrap;text-align:right;">' . $title . ' </td>' . "\n"; |
190 | $str .= ' <td> <input type="text" name="' . $name . '" size="50" value="'. htmlspecialchars($data) . '"> </td>' . "\n"; |
191 | $str .= '</tr>'; |
bb51bc8b |
192 | |
e7f9c987 |
193 | return $str; |
aaf9abef |
194 | |
e7f9c987 |
195 | } |
196 | |
0f01b5d7 |
197 | /** |
198 | * Creates html formated table row with textarea field |
199 | * @param string $title Name displayed next to textarea field |
200 | * @param string $name Name of textarea field |
201 | * @param string $data Default value of textarea field (data is sanitized with htmlspecialchars) |
202 | * @param string $bgcolor html attributes added to row element (tr) |
203 | * @return string html formated table row with textarea |
204 | * @since 1.2.5 (arguments differ since 1.4.5/1.5.1) |
205 | * @todo check right-to-left language issues |
206 | * @access private |
207 | */ |
e7f9c987 |
208 | function sti_textarea( $title, $name, $data, $bgcolor ) { |
209 | $str = ''; |
210 | $str .= '<tr' . $bgcolor . ">\n"; |
211 | $str .= ' <td style="white-space: nowrap;text-align:right;">' . $title . ' </td>' . "\n"; |
212 | $str .= ' <td> <textarea name="' . $name . '" cols="50" rows="5">'. htmlspecialchars($data) . '</textarea> </td>' . "\n"; |
213 | $str .= '</tr>'; |
bb51bc8b |
214 | |
e7f9c987 |
215 | return $str; |
545238b1 |
216 | |
aaf9abef |
217 | } |
a2b193bc |
218 | |
0f01b5d7 |
219 | ?> |