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