commit | author | age
|
4e17e6
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
+-----------------------------------------------------------------------+ |
|
5 |
| program/steps/addressbook/edit.inc | |
|
6 |
| | |
e019f2
|
7 |
| This file is part of the Roundcube Webmail client | |
f5e7b3
|
8 |
| Copyright (C) 2005-2007, 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'); |
A |
39 |
rcmail_overwrite_action('show'); |
|
40 |
return; |
|
41 |
} |
|
42 |
} |
|
43 |
else { |
|
44 |
$source = get_input_value('_source', RCUBE_INPUT_GPC); |
|
45 |
|
34854b
|
46 |
if (!strlen($source)) { |
A |
47 |
// Give priority to configured default |
|
48 |
$source = $RCMAIL->config->get('default_addressbook'); |
|
49 |
} |
|
50 |
|
|
51 |
$CONTACTS = $RCMAIL->get_address_book($source, true); |
ecf295
|
52 |
|
A |
53 |
// find writable addressbook |
|
54 |
if (!$CONTACTS || $CONTACTS->readonly) |
|
55 |
$source = rcmail_default_source(true); |
|
56 |
|
|
57 |
// Initialize addressbook |
|
58 |
$CONTACTS = rcmail_contact_source($source, true); |
f11541
|
59 |
} |
a79417
|
60 |
|
c3dabf
|
61 |
$SOURCE_ID = $source; |
da89cf
|
62 |
rcmail_set_sourcename($CONTACTS); |
5b3ac3
|
63 |
|
3d8b54
|
64 |
function rcmail_get_edit_record() |
T |
65 |
{ |
|
66 |
global $RCMAIL, $CONTACTS; |
|
67 |
|
|
68 |
// check if we have a valid result |
|
69 |
if ($GLOBALS['EDIT_RECORD']) { |
|
70 |
$record = $GLOBALS['EDIT_RECORD']; |
|
71 |
} |
|
72 |
else if ($RCMAIL->action != 'add' |
|
73 |
&& !(($result = $CONTACTS->get_result()) && ($record = $result->first())) |
|
74 |
) { |
|
75 |
$RCMAIL->output->show_message('contactnotfound'); |
|
76 |
return false; |
|
77 |
} |
ecf295
|
78 |
|
3d8b54
|
79 |
return $record; |
T |
80 |
} |
|
81 |
|
0501b6
|
82 |
function rcmail_contact_edithead($attrib) |
f11541
|
83 |
{ |
a79417
|
84 |
// check if we have a valid result |
3d8b54
|
85 |
$record = rcmail_get_edit_record(); |
0501b6
|
86 |
$i_size = !empty($attrib['size']) ? $attrib['size'] : 20; |
T |
87 |
|
|
88 |
$form = array( |
|
89 |
'head' => array( |
|
90 |
'content' => array( |
|
91 |
'prefix' => array('size' => $i_size), |
|
92 |
'firstname' => array('size' => $i_size, 'visible' => true), |
|
93 |
'middlename' => array('size' => $i_size), |
|
94 |
'surname' => array('size' => $i_size, 'visible' => true), |
|
95 |
'suffix' => array('size' => $i_size), |
|
96 |
'name' => array('size' => 2*$i_size), |
|
97 |
'nickname' => array('size' => 2*$i_size), |
317372
|
98 |
'organization' => array('size' => 2*$i_size), |
T |
99 |
'department' => array('size' => 2*$i_size), |
|
100 |
'jobtitle' => array('size' => 2*$i_size), |
0501b6
|
101 |
) |
T |
102 |
) |
|
103 |
); |
|
104 |
|
|
105 |
list($form_start, $form_end) = get_form_tags($attrib); |
|
106 |
unset($attrib['form'], $attrib['name'], $attrib['size']); |
|
107 |
|
|
108 |
// return the address edit form |
|
109 |
$out = rcmail_contact_form($form, $record, $attrib); |
|
110 |
|
|
111 |
return $form_start . $out . $form_end; |
|
112 |
} |
|
113 |
|
|
114 |
function rcmail_contact_editform($attrib) |
|
115 |
{ |
3d8b54
|
116 |
global $RCMAIL, $CONTACT_COLTYPES; |
0501b6
|
117 |
|
3d8b54
|
118 |
$record = rcmail_get_edit_record(); |
4e17e6
|
119 |
|
b0c70b
|
120 |
// copy (parsed) address template to client |
T |
121 |
if (preg_match_all('/\{([a-z0-9]+)\}([^{]*)/i', $RCMAIL->config->get('address_template', ''), $templ, PREG_SET_ORDER)) |
|
122 |
$RCMAIL->output->set_env('address_template', $templ); |
10a699
|
123 |
|
a79417
|
124 |
$i_size = !empty($attrib['size']) ? $attrib['size'] : 40; |
0501b6
|
125 |
$t_rows = !empty($attrib['textarearows']) ? $attrib['textarearows'] : 10; |
a79417
|
126 |
$t_cols = !empty($attrib['textareacols']) ? $attrib['textareacols'] : 40; |
4e17e6
|
127 |
|
a79417
|
128 |
$form = array( |
29aab5
|
129 |
'contact' => array( |
1c029b
|
130 |
'name' => rcube_label('properties'), |
a79417
|
131 |
'content' => array( |
0501b6
|
132 |
'email' => array('size' => $i_size, 'visible' => true), |
T |
133 |
'phone' => array('size' => $i_size, 'visible' => true), |
|
134 |
'address' => array('visible' => true), |
|
135 |
'website' => array('size' => $i_size), |
|
136 |
'im' => array('size' => $i_size), |
fbeb46
|
137 |
), |
T |
138 |
), |
|
139 |
'personal' => array( |
|
140 |
'name' => rcube_label('personalinfo'), |
|
141 |
'content' => array( |
|
142 |
'gender' => array('visible' => true), |
|
143 |
'maidenname' => array('size' => $i_size), |
|
144 |
'birthday' => array('visible' => true), |
ede174
|
145 |
'anniversary' => array(), |
0501b6
|
146 |
'manager' => array('size' => $i_size), |
T |
147 |
'assistant' => array('size' => $i_size), |
|
148 |
'spouse' => array('size' => $i_size), |
a79417
|
149 |
), |
A |
150 |
), |
|
151 |
); |
ecf295
|
152 |
|
0501b6
|
153 |
if (isset($CONTACT_COLTYPES['notes'])) { |
T |
154 |
$form['notes'] = array( |
|
155 |
'name' => rcube_label('notes'), |
|
156 |
'content' => array( |
|
157 |
'notes' => array('size' => $t_cols, 'rows' => $t_rows, 'label' => false, 'visible' => true, 'limit' => 1), |
|
158 |
), |
|
159 |
'single' => true, |
|
160 |
); |
|
161 |
} |
4e17e6
|
162 |
|
a79417
|
163 |
list($form_start, $form_end) = get_form_tags($attrib); |
A |
164 |
unset($attrib['form']); |
4e17e6
|
165 |
|
a79417
|
166 |
// return the complete address edit form as table |
0501b6
|
167 |
$out = rcmail_contact_form($form, $record, $attrib); |
4e17e6
|
168 |
|
a79417
|
169 |
return $form_start . $out . $form_end; |
0501b6
|
170 |
} |
T |
171 |
|
|
172 |
function rcmail_upload_photo_form($attrib) |
|
173 |
{ |
|
174 |
global $OUTPUT; |
|
175 |
|
bab043
|
176 |
// set defaults |
a84bfa
|
177 |
$attrib += array('id' => 'rcmUploadform', 'buttons' => 'yes'); |
0501b6
|
178 |
|
T |
179 |
// find max filesize value |
|
180 |
$max_filesize = parse_bytes(ini_get('upload_max_filesize')); |
|
181 |
$max_postsize = parse_bytes(ini_get('post_max_size')); |
|
182 |
if ($max_postsize && $max_postsize < $max_filesize) |
|
183 |
$max_filesize = $max_postsize; |
|
184 |
$max_filesize = show_bytes($max_filesize); |
ecf295
|
185 |
|
0501b6
|
186 |
$hidden = new html_hiddenfield(array('name' => '_cid', 'value' => $GLOBALS['cid'])); |
T |
187 |
$input = new html_inputfield(array('type' => 'file', 'name' => '_photo', 'size' => $attrib['size'])); |
|
188 |
$button = new html_inputfield(array('type' => 'button')); |
ecf295
|
189 |
|
0501b6
|
190 |
$out = html::div($attrib, |
a84bfa
|
191 |
$OUTPUT->form_tag(array('id' => $attrib['id'].'Frm', 'name' => 'uploadform', 'method' => 'post', 'enctype' => 'multipart/form-data'), |
0501b6
|
192 |
$hidden->show() . |
T |
193 |
html::div(null, $input->show()) . |
|
194 |
html::div('hint', rcube_label(array('name' => 'maxuploadsize', 'vars' => array('size' => $max_filesize)))) . |
bab043
|
195 |
(get_boolean($attrib['buttons']) ? html::div('buttons', |
0501b6
|
196 |
$button->show(rcube_label('close'), array('class' => 'button', 'onclick' => "$('#$attrib[id]').hide()")) . ' ' . |
T |
197 |
$button->show(rcube_label('upload'), array('class' => 'button mainaction', 'onclick' => JS_OBJECT_NAME . ".command('upload-photo', this.form)")) |
bab043
|
198 |
) : '') |
0501b6
|
199 |
) |
T |
200 |
); |
ecf295
|
201 |
|
0501b6
|
202 |
$OUTPUT->add_label('addphoto','replacephoto'); |
a84bfa
|
203 |
$OUTPUT->add_gui_object('uploadform', $attrib['id'].'Frm'); |
0501b6
|
204 |
return $out; |
f11541
|
205 |
} |
4e17e6
|
206 |
|
T |
207 |
// similar function as in /steps/settings/edit_identity.inc |
|
208 |
function get_form_tags($attrib) |
57f0c8
|
209 |
{ |
5b3ac3
|
210 |
global $CONTACTS, $EDIT_FORM, $RCMAIL, $SOURCE_ID; |
4e17e6
|
211 |
|
a79417
|
212 |
$form_start = $form_end = ''; |
83ba22
|
213 |
|
a79417
|
214 |
if (empty($EDIT_FORM)) { |
5b3ac3
|
215 |
$hiddenfields = new html_hiddenfield(); |
A |
216 |
|
|
217 |
if ($RCMAIL->action == 'edit') |
|
218 |
$hiddenfields->add(array('name' => '_source', 'value' => $SOURCE_ID)); |
a79417
|
219 |
$hiddenfields->add(array('name' => '_gid', 'value' => $CONTACTS->group_id)); |
83ba22
|
220 |
|
a79417
|
221 |
if (($result = $CONTACTS->get_result()) && ($record = $result->first())) |
A |
222 |
$hiddenfields->add(array('name' => '_cid', 'value' => $record['ID'])); |
83ba22
|
223 |
|
a79417
|
224 |
$form_start = $RCMAIL->output->request_form(array( |
A |
225 |
'name' => "form", 'method' => "post", |
|
226 |
'task' => $RCMAIL->task, 'action' => 'save', |
|
227 |
'request' => 'save.'.intval($record['ID']), |
|
228 |
'noclose' => true) + $attrib, $hiddenfields->show()); |
|
229 |
$form_end = !strlen($attrib['form']) ? '</form>' : ''; |
57f0c8
|
230 |
|
a79417
|
231 |
$EDIT_FORM = !empty($attrib['form']) ? $attrib['form'] : 'form'; |
A |
232 |
$RCMAIL->output->add_gui_object('editform', $EDIT_FORM); |
|
233 |
} |
4e17e6
|
234 |
|
a79417
|
235 |
return array($form_start, $form_end); |
57f0c8
|
236 |
} |
4e17e6
|
237 |
|
5b3ac3
|
238 |
function rcmail_source_selector($attrib) |
A |
239 |
{ |
|
240 |
global $RCMAIL, $SOURCE_ID; |
|
241 |
|
|
242 |
$sources_list = $RCMAIL->get_address_sources(true); |
|
243 |
|
|
244 |
if (count($sources_list) < 2) { |
|
245 |
$source = $sources_list[$SOURCE_ID]; |
|
246 |
$hiddenfield = new html_hiddenfield(array('name' => '_source', 'value' => $SOURCE_ID)); |
1b9923
|
247 |
return html::span($attrib, $source['name'] . $hiddenfield->show()); |
5b3ac3
|
248 |
} |
A |
249 |
|
1b9923
|
250 |
$attrib['name'] = '_source'; |
AM |
251 |
$attrib['is_escaped'] = true; |
|
252 |
$attrib['onchange'] = JS_OBJECT_NAME . ".command('save', 'reload', this.form)"; |
5b3ac3
|
253 |
|
A |
254 |
$select = new html_select($attrib); |
|
255 |
|
|
256 |
foreach ($sources_list as $source) |
|
257 |
$select->add($source['name'], $source['id']); |
|
258 |
|
|
259 |
return $select->show($SOURCE_ID); |
|
260 |
} |
|
261 |
|
4e17e6
|
262 |
|
0be8bd
|
263 |
/** |
TB |
264 |
* Register container as active area to drop photos onto |
|
265 |
*/ |
|
266 |
function rcmail_photo_drop_area($attrib) |
|
267 |
{ |
|
268 |
global $OUTPUT; |
|
269 |
|
|
270 |
if ($attrib['id']) { |
|
271 |
$OUTPUT->add_gui_object('filedrop', $attrib['id']); |
|
272 |
$OUTPUT->set_env('filedrop', array('action' => 'upload-photo', 'fieldname' => '_photo', 'single' => 1, 'filter' => '^image/.+')); |
|
273 |
} |
|
274 |
} |
|
275 |
|
|
276 |
|
ecf295
|
277 |
$OUTPUT->add_handlers(array( |
A |
278 |
'contactedithead' => 'rcmail_contact_edithead', |
|
279 |
'contacteditform' => 'rcmail_contact_editform', |
|
280 |
'contactphoto' => 'rcmail_contact_photo', |
|
281 |
'photouploadform' => 'rcmail_upload_photo_form', |
5b3ac3
|
282 |
'sourceselector' => 'rcmail_source_selector', |
0be8bd
|
283 |
'filedroparea' => 'rcmail_photo_drop_area', |
ecf295
|
284 |
)); |
4e17e6
|
285 |
|
ecf295
|
286 |
if ($RCMAIL->action == 'add' && $OUTPUT->template_exists('contactadd')) |
83ba22
|
287 |
$OUTPUT->send('contactadd'); |
4e17e6
|
288 |
|
T |
289 |
// this will be executed if no template for addcontact exists |
83ba22
|
290 |
$OUTPUT->send('contactedit'); |