Mercurial > hg > rc2
comparison program/steps/addressbook/edit.inc @ 0:4681f974d28b
vanilla 1.3.3 distro, I hope
author | Charlie Root |
---|---|
date | Thu, 04 Jan 2018 15:52:31 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4681f974d28b |
---|---|
1 <?php | |
2 | |
3 /** | |
4 +-----------------------------------------------------------------------+ | |
5 | program/steps/addressbook/edit.inc | | |
6 | | | |
7 | This file is part of the Roundcube Webmail client | | |
8 | Copyright (C) 2005-2013, The Roundcube Dev Team | | |
9 | | | |
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. | | |
13 | | | |
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 | |
22 if ($RCMAIL->action == 'edit') { | |
23 // Get contact ID and source ID from request | |
24 $cids = rcmail_get_cids(); | |
25 $source = key($cids); | |
26 $cid = array_shift($cids[$source]); | |
27 | |
28 // Initialize addressbook | |
29 $CONTACTS = rcmail_contact_source($source, true); | |
30 | |
31 // Contact edit | |
32 if ($cid && ($record = $CONTACTS->get_record($cid, true))) { | |
33 $OUTPUT->set_env('cid', $record['ID']); | |
34 } | |
35 | |
36 // editing not allowed here | |
37 if ($CONTACTS->readonly || $record['readonly']) { | |
38 $OUTPUT->show_message('sourceisreadonly'); | |
39 $RCMAIL->overwrite_action('show'); | |
40 return; | |
41 } | |
42 } | |
43 else { | |
44 $source = rcube_utils::get_input_value('_source', rcube_utils::INPUT_GPC); | |
45 | |
46 if (strlen($source)) { | |
47 $CONTACTS = $RCMAIL->get_address_book($source, true); | |
48 } | |
49 | |
50 if (!$CONTACTS || $CONTACTS->readonly) { | |
51 $CONTACTS = $RCMAIL->get_address_book(-1, true); | |
52 $source = $RCMAIL->get_address_book_id($CONTACTS); | |
53 } | |
54 | |
55 // Initialize addressbook | |
56 $CONTACTS = rcmail_contact_source($source, true); | |
57 } | |
58 | |
59 $SOURCE_ID = $source; | |
60 rcmail_set_sourcename($CONTACTS); | |
61 | |
62 | |
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 | |
72 $OUTPUT->set_pagetitle($RCMAIL->gettext(($RCMAIL->action == 'add' ? 'addcontact' : 'editcontact'))); | |
73 | |
74 if ($RCMAIL->action == 'add' && $OUTPUT->template_exists('contactadd')) { | |
75 $OUTPUT->send('contactadd'); | |
76 } | |
77 | |
78 // this will be executed if no template for addcontact exists | |
79 $OUTPUT->send('contactedit'); | |
80 | |
81 | |
82 | |
83 function rcmail_get_edit_record() | |
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 ) { | |
94 $RCMAIL->output->show_message('contactnotfound', 'error'); | |
95 return false; | |
96 } | |
97 | |
98 return $record; | |
99 } | |
100 | |
101 function rcmail_contact_edithead($attrib) | |
102 { | |
103 global $RCMAIL; | |
104 | |
105 // check if we have a valid result | |
106 $record = rcmail_get_edit_record(); | |
107 $i_size = $attrib['size'] ?: 20; | |
108 | |
109 $form = array( | |
110 'head' => array( | |
111 'name' => $RCMAIL->gettext('contactnameandorg'), | |
112 'content' => array( | |
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), | |
120 'organization' => array('size' => 2*$i_size), | |
121 'department' => array('size' => 2*$i_size), | |
122 'jobtitle' => array('size' => 2*$i_size), | |
123 ) | |
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 { | |
138 global $RCMAIL, $CONTACT_COLTYPES; | |
139 | |
140 $record = rcmail_get_edit_record(); | |
141 | |
142 // copy (parsed) address template to client | |
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); | |
145 | |
146 $i_size = $attrib['size'] ?: 40; | |
147 $t_rows = $attrib['textarearows'] ?: 10; | |
148 $t_cols = $attrib['textareacols'] ?: 40; | |
149 | |
150 $form = array( | |
151 'contact' => array( | |
152 'name' => $RCMAIL->gettext('properties'), | |
153 'content' => array( | |
154 'email' => array('size' => $i_size, 'maxlength' => 254, 'visible' => true), | |
155 'phone' => array('size' => $i_size, 'visible' => true), | |
156 'address' => array('visible' => true), | |
157 'website' => array('size' => $i_size), | |
158 'im' => array('size' => $i_size), | |
159 ), | |
160 ), | |
161 'personal' => array( | |
162 'name' => $RCMAIL->gettext('personalinfo'), | |
163 'content' => array( | |
164 'gender' => array('visible' => true), | |
165 'maidenname' => array('size' => $i_size), | |
166 'birthday' => array('visible' => true), | |
167 'anniversary' => array(), | |
168 'manager' => array('size' => $i_size), | |
169 'assistant' => array('size' => $i_size), | |
170 'spouse' => array('size' => $i_size), | |
171 ), | |
172 ), | |
173 ); | |
174 | |
175 if (isset($CONTACT_COLTYPES['notes'])) { | |
176 $form['notes'] = array( | |
177 'name' => $RCMAIL->gettext('notes'), | |
178 'content' => array( | |
179 'notes' => array('size' => $t_cols, 'rows' => $t_rows, 'label' => false, 'visible' => true, 'limit' => 1), | |
180 ), | |
181 'single' => true, | |
182 ); | |
183 } | |
184 | |
185 list($form_start, $form_end) = get_form_tags($attrib); | |
186 unset($attrib['form']); | |
187 | |
188 // return the complete address edit form as table | |
189 $out = rcmail_contact_form($form, $record, $attrib); | |
190 | |
191 return $form_start . $out . $form_end; | |
192 } | |
193 | |
194 function rcmail_upload_photo_form($attrib) | |
195 { | |
196 global $RCMAIL; | |
197 | |
198 $hidden = new html_hiddenfield(array('name' => '_cid', 'value' => $GLOBALS['cid'])); | |
199 $attrib['prefix'] = $hidden->show(); | |
200 $input_attr = array('name' => '_photo', 'accept' => 'image/*'); | |
201 | |
202 $RCMAIL->output->add_label('addphoto','replacephoto'); | |
203 | |
204 return $RCMAIL->upload_form($attrib, 'uploadform', 'upload-photo', $input_attr); | |
205 } | |
206 | |
207 // similar function as in /steps/settings/edit_identity.inc | |
208 function get_form_tags($attrib) | |
209 { | |
210 global $CONTACTS, $EDIT_FORM, $RCMAIL, $SOURCE_ID; | |
211 | |
212 $form_start = $form_end = ''; | |
213 | |
214 if (empty($EDIT_FORM)) { | |
215 $hiddenfields = new html_hiddenfield(); | |
216 | |
217 if ($RCMAIL->action == 'edit') | |
218 $hiddenfields->add(array('name' => '_source', 'value' => $SOURCE_ID)); | |
219 $hiddenfields->add(array('name' => '_gid', 'value' => $CONTACTS->group_id)); | |
220 $hiddenfields->add(array('name' => '_search', 'value' => rcube_utils::get_input_value('_search', rcube_utils::INPUT_GPC))); | |
221 | |
222 if (($result = $CONTACTS->get_result()) && ($record = $result->first())) | |
223 $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID'])); | |
224 | |
225 $form_start = $RCMAIL->output->request_form(array( | |
226 'name' => "form", 'method' => "post", | |
227 'task' => $RCMAIL->task, 'action' => 'save', | |
228 'request' => 'save.'.intval($record['ID']), | |
229 'noclose' => true) + $attrib, $hiddenfields->show()); | |
230 $form_end = !strlen($attrib['form']) ? '</form>' : ''; | |
231 | |
232 $EDIT_FORM = $attrib['form'] ?: 'form'; | |
233 $RCMAIL->output->add_gui_object('editform', $EDIT_FORM); | |
234 } | |
235 | |
236 return array($form_start, $form_end); | |
237 } | |
238 | |
239 function rcmail_source_selector($attrib) | |
240 { | |
241 global $RCMAIL, $SOURCE_ID; | |
242 | |
243 $sources_list = $RCMAIL->get_address_sources(true, true); | |
244 | |
245 if (count($sources_list) < 2) { | |
246 $source = $sources_list[$SOURCE_ID]; | |
247 $hiddenfield = new html_hiddenfield(array('name' => '_source', 'value' => $SOURCE_ID)); | |
248 return html::span($attrib, $source['name'] . $hiddenfield->show()); | |
249 } | |
250 | |
251 $attrib['name'] = '_source'; | |
252 $attrib['is_escaped'] = true; | |
253 $attrib['onchange'] = rcmail_output::JS_OBJECT_NAME . ".command('save', 'reload', this.form)"; | |
254 | |
255 $select = new html_select($attrib); | |
256 | |
257 foreach ($sources_list as $source) | |
258 $select->add($source['name'], $source['id']); | |
259 | |
260 return $select->show($SOURCE_ID); | |
261 } | |
262 | |
263 | |
264 /** | |
265 * Register container as active area to drop photos onto | |
266 */ | |
267 function rcmail_photo_drop_area($attrib) | |
268 { | |
269 global $OUTPUT; | |
270 | |
271 if ($attrib['id']) { | |
272 $OUTPUT->add_gui_object('filedrop', $attrib['id']); | |
273 $OUTPUT->set_env('filedrop', array('action' => 'upload-photo', 'fieldname' => '_photo', 'single' => 1, 'filter' => '^image/.+')); | |
274 } | |
275 } |