4 +-----------------------------------------------------------------------+
5 | program/steps/addressbook/edit.inc |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2005-2007, The Roundcube Dev Team |
9 | Licensed under the GNU GPL |
12 | Show edit form for a contact entry or to add a new one |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: edit.inc 5681 2012-01-01 13:36:22Z alec $
22 if ($RCMAIL->action == 'edit') {
23 // Get contact ID and source ID from request
24 $cids = rcmail_get_cids();
26 $cid = array_shift($cids[$source]);
28 // Initialize addressbook
29 $CONTACTS = rcmail_contact_source($source, true);
32 if ($cid && ($record = $CONTACTS->get_record($cid, true))) {
33 $OUTPUT->set_env('cid', $record['ID']);
36 // adding not allowed here
37 if ($CONTACTS->readonly) {
38 $OUTPUT->show_message('sourceisreadonly');
39 rcmail_overwrite_action('show');
44 $source = get_input_value('_source', RCUBE_INPUT_GPC);
46 if (!strlen($source)) {
47 // Give priority to configured default
48 $source = $RCMAIL->config->get('default_addressbook');
51 $CONTACTS = $RCMAIL->get_address_book($source, true);
53 // find writable addressbook
54 if (!$CONTACTS || $CONTACTS->readonly)
55 $source = rcmail_default_source(true);
57 // Initialize addressbook
58 $CONTACTS = rcmail_contact_source($source, true);
62 rcmail_set_sourcename($CONTACTS);
64 function rcmail_get_edit_record()
66 global $RCMAIL, $CONTACTS;
68 // check if we have a valid result
69 if ($GLOBALS['EDIT_RECORD']) {
70 $record = $GLOBALS['EDIT_RECORD'];
72 else if ($RCMAIL->action != 'add'
73 && !(($result = $CONTACTS->get_result()) && ($record = $result->first()))
75 $RCMAIL->output->show_message('contactnotfound');
82 function rcmail_contact_edithead($attrib)
84 // check if we have a valid result
85 $record = rcmail_get_edit_record();
86 $i_size = !empty($attrib['size']) ? $attrib['size'] : 20;
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),
98 'organization' => array('size' => 2*$i_size),
99 'department' => array('size' => 2*$i_size),
100 'jobtitle' => array('size' => 2*$i_size),
105 list($form_start, $form_end) = get_form_tags($attrib);
106 unset($attrib['form'], $attrib['name'], $attrib['size']);
108 // return the address edit form
109 $out = rcmail_contact_form($form, $record, $attrib);
111 return $form_start . $out . $form_end;
114 function rcmail_contact_editform($attrib)
116 global $RCMAIL, $CONTACT_COLTYPES;
118 $record = rcmail_get_edit_record();
120 // add some labels to client
121 $RCMAIL->output->add_label('noemailwarning', 'nonamewarning');
123 // copy (parsed) address template to client
124 if (preg_match_all('/\{([a-z0-9]+)\}([^{]*)/i', $RCMAIL->config->get('address_template', ''), $templ, PREG_SET_ORDER))
125 $RCMAIL->output->set_env('address_template', $templ);
127 $i_size = !empty($attrib['size']) ? $attrib['size'] : 40;
128 $t_rows = !empty($attrib['textarearows']) ? $attrib['textarearows'] : 10;
129 $t_cols = !empty($attrib['textareacols']) ? $attrib['textareacols'] : 40;
133 'name' => rcube_label('properties'),
135 'email' => array('size' => $i_size, 'visible' => true),
136 'phone' => array('size' => $i_size, 'visible' => true),
137 'address' => array('visible' => true),
138 'website' => array('size' => $i_size),
139 'im' => array('size' => $i_size),
143 'name' => rcube_label('personalinfo'),
145 'gender' => array('visible' => true),
146 'maidenname' => array('size' => $i_size),
147 'birthday' => array('visible' => true),
148 'anniversary' => array(),
149 'manager' => array('size' => $i_size),
150 'assistant' => array('size' => $i_size),
151 'spouse' => array('size' => $i_size),
156 if (isset($CONTACT_COLTYPES['notes'])) {
157 $form['notes'] = array(
158 'name' => rcube_label('notes'),
160 'notes' => array('size' => $t_cols, 'rows' => $t_rows, 'label' => false, 'visible' => true, 'limit' => 1),
166 list($form_start, $form_end) = get_form_tags($attrib);
167 unset($attrib['form']);
169 // return the complete address edit form as table
170 $out = rcmail_contact_form($form, $record, $attrib);
172 return $form_start . $out . $form_end;
175 function rcmail_upload_photo_form($attrib)
179 // add ID if not given
181 $attrib['id'] = 'rcmUploadbox';
183 // find max filesize value
184 $max_filesize = parse_bytes(ini_get('upload_max_filesize'));
185 $max_postsize = parse_bytes(ini_get('post_max_size'));
186 if ($max_postsize && $max_postsize < $max_filesize)
187 $max_filesize = $max_postsize;
188 $max_filesize = show_bytes($max_filesize);
190 $hidden = new html_hiddenfield(array('name' => '_cid', 'value' => $GLOBALS['cid']));
191 $input = new html_inputfield(array('type' => 'file', 'name' => '_photo', 'size' => $attrib['size']));
192 $button = new html_inputfield(array('type' => 'button'));
194 $out = html::div($attrib,
195 $OUTPUT->form_tag(array('name' => 'uploadform', 'method' => 'post', 'enctype' => 'multipart/form-data'),
197 html::div(null, $input->show()) .
198 html::div('hint', rcube_label(array('name' => 'maxuploadsize', 'vars' => array('size' => $max_filesize)))) .
200 $button->show(rcube_label('close'), array('class' => 'button', 'onclick' => "$('#$attrib[id]').hide()")) . ' ' .
201 $button->show(rcube_label('upload'), array('class' => 'button mainaction', 'onclick' => JS_OBJECT_NAME . ".command('upload-photo', this.form)"))
206 $OUTPUT->add_label('addphoto','replacephoto');
207 $OUTPUT->add_gui_object('uploadbox', $attrib['id']);
211 // similar function as in /steps/settings/edit_identity.inc
212 function get_form_tags($attrib)
214 global $CONTACTS, $EDIT_FORM, $RCMAIL, $SOURCE_ID;
216 $form_start = $form_end = '';
218 if (empty($EDIT_FORM)) {
219 $hiddenfields = new html_hiddenfield();
221 if ($RCMAIL->action == 'edit')
222 $hiddenfields->add(array('name' => '_source', 'value' => $SOURCE_ID));
223 $hiddenfields->add(array('name' => '_gid', 'value' => $CONTACTS->group_id));
225 if (($result = $CONTACTS->get_result()) && ($record = $result->first()))
226 $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID']));
228 $form_start = $RCMAIL->output->request_form(array(
229 'name' => "form", 'method' => "post",
230 'task' => $RCMAIL->task, 'action' => 'save',
231 'request' => 'save.'.intval($record['ID']),
232 'noclose' => true) + $attrib, $hiddenfields->show());
233 $form_end = !strlen($attrib['form']) ? '</form>' : '';
235 $EDIT_FORM = !empty($attrib['form']) ? $attrib['form'] : 'form';
236 $RCMAIL->output->add_gui_object('editform', $EDIT_FORM);
239 return array($form_start, $form_end);
242 function rcmail_source_selector($attrib)
244 global $RCMAIL, $SOURCE_ID;
246 $sources_list = $RCMAIL->get_address_sources(true);
248 if (count($sources_list) < 2) {
249 $source = $sources_list[$SOURCE_ID];
250 $hiddenfield = new html_hiddenfield(array('name' => '_source', 'value' => $SOURCE_ID));
251 return html::span($attrib, Q($source['name']) . $hiddenfield->show());
254 $attrib['name'] = '_source';
255 $attrib['onchange'] = JS_OBJECT_NAME . ".command('save', 'reload', this.form)";
257 $select = new html_select($attrib);
259 foreach ($sources_list as $source)
260 $select->add($source['name'], $source['id']);
262 return $select->show($SOURCE_ID);
266 $OUTPUT->add_handlers(array(
267 'contactedithead' => 'rcmail_contact_edithead',
268 'contacteditform' => 'rcmail_contact_editform',
269 'contactphoto' => 'rcmail_contact_photo',
270 'photouploadform' => 'rcmail_upload_photo_form',
271 'sourceselector' => 'rcmail_source_selector',
274 if ($RCMAIL->action == 'add' && $OUTPUT->template_exists('contactadd'))
275 $OUTPUT->send('contactadd');
277 // this will be executed if no template for addcontact exists
278 $OUTPUT->send('contactedit');