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