commit | author | age
|
4e17e6
|
1 |
<?php |
T |
2 |
|
a95874
|
3 |
/** |
4e17e6
|
4 |
+-----------------------------------------------------------------------+ |
T |
5 |
| program/steps/addressbook/edit.inc | |
|
6 |
| | |
e019f2
|
7 |
| This file is part of the Roundcube Webmail client | |
c97625
|
8 |
| Copyright (C) 2005-2013, The Roundcube Dev Team | |
7fe381
|
9 |
| | |
T |
10 |
| Licensed under the GNU General Public License version 3 or | |
|
11 |
| any later version with exceptions for skins & plugins. | |
|
12 |
| See the README file for a full license statement. | |
4e17e6
|
13 |
| | |
T |
14 |
| PURPOSE: | |
|
15 |
| Show edit form for a contact entry or to add a new one | |
|
16 |
| | |
|
17 |
+-----------------------------------------------------------------------+ |
|
18 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
|
19 |
+-----------------------------------------------------------------------+ |
|
20 |
*/ |
|
21 |
|
ecf295
|
22 |
if ($RCMAIL->action == 'edit') { |
A |
23 |
// Get contact ID and source ID from request |
|
24 |
$cids = rcmail_get_cids(); |
|
25 |
$source = key($cids); |
|
26 |
$cid = array_shift($cids[$source]); |
4e17e6
|
27 |
|
ecf295
|
28 |
// Initialize addressbook |
A |
29 |
$CONTACTS = rcmail_contact_source($source, true); |
10a699
|
30 |
|
ecf295
|
31 |
// Contact edit |
A |
32 |
if ($cid && ($record = $CONTACTS->get_record($cid, true))) { |
|
33 |
$OUTPUT->set_env('cid', $record['ID']); |
|
34 |
} |
|
35 |
|
4cf42f
|
36 |
// editing not allowed here |
T |
37 |
if ($CONTACTS->readonly || $record['readonly']) { |
ecf295
|
38 |
$OUTPUT->show_message('sourceisreadonly'); |
6b2b2e
|
39 |
$RCMAIL->overwrite_action('show'); |
ecf295
|
40 |
return; |
A |
41 |
} |
|
42 |
} |
|
43 |
else { |
6b2b2e
|
44 |
$source = rcube_utils::get_input_value('_source', rcube_utils::INPUT_GPC); |
ecf295
|
45 |
|
62350b
|
46 |
if (strlen($source)) { |
AM |
47 |
$CONTACTS = $RCMAIL->get_address_book($source, true); |
34854b
|
48 |
} |
A |
49 |
|
62350b
|
50 |
if (!$CONTACTS || $CONTACTS->readonly) { |
AM |
51 |
$CONTACTS = $RCMAIL->get_address_book(-1, true); |
|
52 |
$source = $RCMAIL->get_address_book_id($CONTACTS); |
|
53 |
} |
ecf295
|
54 |
|
A |
55 |
// Initialize addressbook |
|
56 |
$CONTACTS = rcmail_contact_source($source, true); |
f11541
|
57 |
} |
a79417
|
58 |
|
c3dabf
|
59 |
$SOURCE_ID = $source; |
da89cf
|
60 |
rcmail_set_sourcename($CONTACTS); |
5b3ac3
|
61 |
|
f5d2ee
|
62 |
|
AM |
63 |
$OUTPUT->add_handlers(array( |
|
64 |
'contactedithead' => 'rcmail_contact_edithead', |
|
65 |
'contacteditform' => 'rcmail_contact_editform', |
|
66 |
'contactphoto' => 'rcmail_contact_photo', |
|
67 |
'photouploadform' => 'rcmail_upload_photo_form', |
|
68 |
'sourceselector' => 'rcmail_source_selector', |
|
69 |
'filedroparea' => 'rcmail_photo_drop_area', |
|
70 |
)); |
|
71 |
|
1e22cb
|
72 |
$OUTPUT->set_pagetitle($RCMAIL->gettext(($RCMAIL->action == 'add' ? 'addcontact' : 'editcontact'))); |
AM |
73 |
|
f5d2ee
|
74 |
if ($RCMAIL->action == 'add' && $OUTPUT->template_exists('contactadd')) { |
AM |
75 |
$OUTPUT->send('contactadd'); |
|
76 |
} |
|
77 |
|
|
78 |
// this will be executed if no template for addcontact exists |
|
79 |
$OUTPUT->send('contactedit'); |
|
80 |
|
|
81 |
|
|
82 |
|
3d8b54
|
83 |
function rcmail_get_edit_record() |
T |
84 |
{ |
|
85 |
global $RCMAIL, $CONTACTS; |
|
86 |
|
|
87 |
// check if we have a valid result |
|
88 |
if ($GLOBALS['EDIT_RECORD']) { |
|
89 |
$record = $GLOBALS['EDIT_RECORD']; |
|
90 |
} |
|
91 |
else if ($RCMAIL->action != 'add' |
|
92 |
&& !(($result = $CONTACTS->get_result()) && ($record = $result->first())) |
|
93 |
) { |
f768a6
|
94 |
$RCMAIL->output->show_message('contactnotfound', 'error'); |
3d8b54
|
95 |
return false; |
T |
96 |
} |
ecf295
|
97 |
|
3d8b54
|
98 |
return $record; |
T |
99 |
} |
|
100 |
|
0501b6
|
101 |
function rcmail_contact_edithead($attrib) |
f11541
|
102 |
{ |
24e89e
|
103 |
global $RCMAIL; |
TB |
104 |
|
a79417
|
105 |
// check if we have a valid result |
3d8b54
|
106 |
$record = rcmail_get_edit_record(); |
827159
|
107 |
$i_size = $attrib['size'] ?: 20; |
0501b6
|
108 |
|
T |
109 |
$form = array( |
|
110 |
'head' => array( |
24e89e
|
111 |
'name' => $RCMAIL->gettext('contactnameandorg'), |
0501b6
|
112 |
'content' => array( |
T |
113 |
'prefix' => array('size' => $i_size), |
|
114 |
'firstname' => array('size' => $i_size, 'visible' => true), |
|
115 |
'middlename' => array('size' => $i_size), |
|
116 |
'surname' => array('size' => $i_size, 'visible' => true), |
|
117 |
'suffix' => array('size' => $i_size), |
|
118 |
'name' => array('size' => 2*$i_size), |
|
119 |
'nickname' => array('size' => 2*$i_size), |
317372
|
120 |
'organization' => array('size' => 2*$i_size), |
T |
121 |
'department' => array('size' => 2*$i_size), |
|
122 |
'jobtitle' => array('size' => 2*$i_size), |
0501b6
|
123 |
) |
T |
124 |
) |
|
125 |
); |
|
126 |
|
|
127 |
list($form_start, $form_end) = get_form_tags($attrib); |
|
128 |
unset($attrib['form'], $attrib['name'], $attrib['size']); |
|
129 |
|
|
130 |
// return the address edit form |
|
131 |
$out = rcmail_contact_form($form, $record, $attrib); |
|
132 |
|
|
133 |
return $form_start . $out . $form_end; |
|
134 |
} |
|
135 |
|
|
136 |
function rcmail_contact_editform($attrib) |
|
137 |
{ |
3d8b54
|
138 |
global $RCMAIL, $CONTACT_COLTYPES; |
0501b6
|
139 |
|
3d8b54
|
140 |
$record = rcmail_get_edit_record(); |
4e17e6
|
141 |
|
b0c70b
|
142 |
// copy (parsed) address template to client |
T |
143 |
if (preg_match_all('/\{([a-z0-9]+)\}([^{]*)/i', $RCMAIL->config->get('address_template', ''), $templ, PREG_SET_ORDER)) |
|
144 |
$RCMAIL->output->set_env('address_template', $templ); |
10a699
|
145 |
|
827159
|
146 |
$i_size = $attrib['size'] ?: 40; |
AM |
147 |
$t_rows = $attrib['textarearows'] ?: 10; |
|
148 |
$t_cols = $attrib['textareacols'] ?: 40; |
4e17e6
|
149 |
|
a79417
|
150 |
$form = array( |
29aab5
|
151 |
'contact' => array( |
6b2b2e
|
152 |
'name' => $RCMAIL->gettext('properties'), |
a79417
|
153 |
'content' => array( |
1db4c0
|
154 |
'email' => array('size' => $i_size, 'maxlength' => 254, 'visible' => true), |
0501b6
|
155 |
'phone' => array('size' => $i_size, 'visible' => true), |
T |
156 |
'address' => array('visible' => true), |
|
157 |
'website' => array('size' => $i_size), |
|
158 |
'im' => array('size' => $i_size), |
fbeb46
|
159 |
), |
T |
160 |
), |
|
161 |
'personal' => array( |
6b2b2e
|
162 |
'name' => $RCMAIL->gettext('personalinfo'), |
fbeb46
|
163 |
'content' => array( |
T |
164 |
'gender' => array('visible' => true), |
|
165 |
'maidenname' => array('size' => $i_size), |
|
166 |
'birthday' => array('visible' => true), |
ede174
|
167 |
'anniversary' => array(), |
0501b6
|
168 |
'manager' => array('size' => $i_size), |
T |
169 |
'assistant' => array('size' => $i_size), |
|
170 |
'spouse' => array('size' => $i_size), |
a79417
|
171 |
), |
A |
172 |
), |
|
173 |
); |
ecf295
|
174 |
|
0501b6
|
175 |
if (isset($CONTACT_COLTYPES['notes'])) { |
T |
176 |
$form['notes'] = array( |
6b2b2e
|
177 |
'name' => $RCMAIL->gettext('notes'), |
0501b6
|
178 |
'content' => array( |
T |
179 |
'notes' => array('size' => $t_cols, 'rows' => $t_rows, 'label' => false, 'visible' => true, 'limit' => 1), |
|
180 |
), |
|
181 |
'single' => true, |
|
182 |
); |
|
183 |
} |
4e17e6
|
184 |
|
a79417
|
185 |
list($form_start, $form_end) = get_form_tags($attrib); |
A |
186 |
unset($attrib['form']); |
4e17e6
|
187 |
|
a79417
|
188 |
// return the complete address edit form as table |
0501b6
|
189 |
$out = rcmail_contact_form($form, $record, $attrib); |
4e17e6
|
190 |
|
a79417
|
191 |
return $form_start . $out . $form_end; |
0501b6
|
192 |
} |
T |
193 |
|
|
194 |
function rcmail_upload_photo_form($attrib) |
|
195 |
{ |
c97625
|
196 |
global $RCMAIL, $OUTPUT; |
0501b6
|
197 |
|
c97625
|
198 |
// set defaults |
AM |
199 |
$attrib += array('id' => 'rcmUploadform', 'buttons' => 'yes'); |
0501b6
|
200 |
|
c97625
|
201 |
// find max filesize value |
AM |
202 |
$max_filesize = parse_bytes(ini_get('upload_max_filesize')); |
|
203 |
$max_postsize = parse_bytes(ini_get('post_max_size')); |
ecf295
|
204 |
|
c97625
|
205 |
if ($max_postsize && $max_postsize < $max_filesize) { |
AM |
206 |
$max_filesize = $max_postsize; |
|
207 |
} |
|
208 |
$max_filesize = $RCMAIL->show_bytes($max_filesize); |
ecf295
|
209 |
|
c97625
|
210 |
$hidden = new html_hiddenfield(array('name' => '_cid', 'value' => $GLOBALS['cid'])); |
AM |
211 |
$input = new html_inputfield(array('type' => 'file', 'name' => '_photo', 'size' => $attrib['size'])); |
|
212 |
$button = new html_inputfield(array('type' => 'button')); |
ecf295
|
213 |
|
c97625
|
214 |
$content = $hidden->show() . html::div(null, $input->show()) |
AM |
215 |
. html::div('hint', $RCMAIL->gettext(array('name' => 'maxuploadsize', 'vars' => array('size' => $max_filesize)))); |
|
216 |
|
|
217 |
if (rcube_utils::get_boolean($attrib['buttons'])) { |
|
218 |
$content .= html::div('buttons', |
|
219 |
$button->show($RCMAIL->gettext('close'), array( |
|
220 |
'class' => 'button', |
|
221 |
'onclick' => "$('#$attrib[id]').hide()" |
|
222 |
)) |
|
223 |
. ' ' . |
|
224 |
$button->show($RCMAIL->gettext('upload'), array( |
|
225 |
'class' => 'button mainaction', |
|
226 |
'onclick' => rcmail_output::JS_OBJECT_NAME . ".command('upload-photo', this.form)" |
|
227 |
)) |
|
228 |
); |
|
229 |
} |
|
230 |
|
|
231 |
$out = html::div($attrib, |
|
232 |
$OUTPUT->form_tag(array( |
|
233 |
'id' => $attrib['id'] . 'Frm', |
|
234 |
'name' => 'uploadform', |
|
235 |
'method' => 'post', |
|
236 |
'enctype' => 'multipart/form-data' |
|
237 |
), |
|
238 |
$content |
|
239 |
) |
|
240 |
); |
|
241 |
|
|
242 |
$OUTPUT->add_label('addphoto','replacephoto'); |
|
243 |
$OUTPUT->add_gui_object('uploadform', $attrib['id'].'Frm'); |
|
244 |
|
|
245 |
return $out; |
f11541
|
246 |
} |
4e17e6
|
247 |
|
T |
248 |
// similar function as in /steps/settings/edit_identity.inc |
|
249 |
function get_form_tags($attrib) |
57f0c8
|
250 |
{ |
5b3ac3
|
251 |
global $CONTACTS, $EDIT_FORM, $RCMAIL, $SOURCE_ID; |
4e17e6
|
252 |
|
a79417
|
253 |
$form_start = $form_end = ''; |
83ba22
|
254 |
|
a79417
|
255 |
if (empty($EDIT_FORM)) { |
5b3ac3
|
256 |
$hiddenfields = new html_hiddenfield(); |
A |
257 |
|
|
258 |
if ($RCMAIL->action == 'edit') |
|
259 |
$hiddenfields->add(array('name' => '_source', 'value' => $SOURCE_ID)); |
a79417
|
260 |
$hiddenfields->add(array('name' => '_gid', 'value' => $CONTACTS->group_id)); |
765a0b
|
261 |
$hiddenfields->add(array('name' => '_search', 'value' => rcube_utils::get_input_value('_search', rcube_utils::INPUT_GPC))); |
83ba22
|
262 |
|
a79417
|
263 |
if (($result = $CONTACTS->get_result()) && ($record = $result->first())) |
A |
264 |
$hiddenfields->add(array('name' => '_cid', 'value' => $record['ID'])); |
83ba22
|
265 |
|
a79417
|
266 |
$form_start = $RCMAIL->output->request_form(array( |
A |
267 |
'name' => "form", 'method' => "post", |
|
268 |
'task' => $RCMAIL->task, 'action' => 'save', |
|
269 |
'request' => 'save.'.intval($record['ID']), |
|
270 |
'noclose' => true) + $attrib, $hiddenfields->show()); |
|
271 |
$form_end = !strlen($attrib['form']) ? '</form>' : ''; |
57f0c8
|
272 |
|
827159
|
273 |
$EDIT_FORM = $attrib['form'] ?: 'form'; |
a79417
|
274 |
$RCMAIL->output->add_gui_object('editform', $EDIT_FORM); |
A |
275 |
} |
4e17e6
|
276 |
|
a79417
|
277 |
return array($form_start, $form_end); |
57f0c8
|
278 |
} |
4e17e6
|
279 |
|
5b3ac3
|
280 |
function rcmail_source_selector($attrib) |
A |
281 |
{ |
|
282 |
global $RCMAIL, $SOURCE_ID; |
|
283 |
|
65dff8
|
284 |
$sources_list = $RCMAIL->get_address_sources(true, true); |
5b3ac3
|
285 |
|
A |
286 |
if (count($sources_list) < 2) { |
|
287 |
$source = $sources_list[$SOURCE_ID]; |
|
288 |
$hiddenfield = new html_hiddenfield(array('name' => '_source', 'value' => $SOURCE_ID)); |
1b9923
|
289 |
return html::span($attrib, $source['name'] . $hiddenfield->show()); |
5b3ac3
|
290 |
} |
A |
291 |
|
1b9923
|
292 |
$attrib['name'] = '_source'; |
AM |
293 |
$attrib['is_escaped'] = true; |
6b2b2e
|
294 |
$attrib['onchange'] = rcmail_output::JS_OBJECT_NAME . ".command('save', 'reload', this.form)"; |
5b3ac3
|
295 |
|
A |
296 |
$select = new html_select($attrib); |
|
297 |
|
|
298 |
foreach ($sources_list as $source) |
|
299 |
$select->add($source['name'], $source['id']); |
|
300 |
|
|
301 |
return $select->show($SOURCE_ID); |
|
302 |
} |
|
303 |
|
4e17e6
|
304 |
|
0be8bd
|
305 |
/** |
TB |
306 |
* Register container as active area to drop photos onto |
|
307 |
*/ |
|
308 |
function rcmail_photo_drop_area($attrib) |
|
309 |
{ |
|
310 |
global $OUTPUT; |
|
311 |
|
|
312 |
if ($attrib['id']) { |
|
313 |
$OUTPUT->add_gui_object('filedrop', $attrib['id']); |
|
314 |
$OUTPUT->set_env('filedrop', array('action' => 'upload-photo', 'fieldname' => '_photo', 'single' => 1, 'filter' => '^image/.+')); |
|
315 |
} |
|
316 |
} |