source: github/program/steps/addressbook/edit.inc @ da89cf2

HEADcourier-fixdev-browser-capabilitiespdorelease-0.6release-0.7release-0.8
Last change on this file since da89cf2 was da89cf2, checked in by thomascube <thomas@…>, 22 months ago

Always show address book name if multiple books are configured; fix styling

  • Property mode set to 100644
File size: 9.4 KB
Line 
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-2007, The Roundcube Dev Team                       |
9 | Licensed under the GNU GPL                                            |
10 |                                                                       |
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
22if ($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    // adding not allowed here
37    if ($CONTACTS->readonly) {
38        $OUTPUT->show_message('sourceisreadonly');
39        rcmail_overwrite_action('show');
40        return;
41    }
42}
43else {
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);
54}
55
56$SOURCE_ID = $source;
57rcmail_set_sourcename($CONTACTS);
58
59function rcmail_get_edit_record()
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     }
73
74     return $record;
75}
76
77function rcmail_contact_edithead($attrib)
78{
79    // check if we have a valid result
80    $record = rcmail_get_edit_record();
81    $i_size = !empty($attrib['size']) ? $attrib['size'] : 20;
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
109function rcmail_contact_editform($attrib)
110{
111    global $RCMAIL, $CONTACT_COLTYPES;
112
113    $record = rcmail_get_edit_record();
114
115    // add some labels to client
116    $RCMAIL->output->add_label('noemailwarning', 'nonamewarning');
117
118    // copy (parsed) address template to client
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);
121
122    $i_size = !empty($attrib['size']) ? $attrib['size'] : 40;
123    $t_rows = !empty($attrib['textarearows']) ? $attrib['textarearows'] : 10;
124    $t_cols = !empty($attrib['textareacols']) ? $attrib['textareacols'] : 40;
125
126    $form = array(
127        'contact' => array(
128            'name'    => rcube_label('contactproperties'),
129            'content' => array(
130                'email' => array('size' => $i_size, 'visible' => true),
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),
135            ),
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),
143                'anniversary' => array(),
144                'manager' => array('size' => $i_size),
145                'assistant' => array('size' => $i_size),
146                'spouse' => array('size' => $i_size),
147            ),
148        ),
149    );
150
151    if (isset($CONTACT_COLTYPES['notes'])) {
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    }
160
161    list($form_start, $form_end) = get_form_tags($attrib);
162    unset($attrib['form']);
163
164    // return the complete address edit form as table
165    $out = rcmail_contact_form($form, $record, $attrib);
166
167    return $form_start . $out . $form_end;
168}
169
170function 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);
184
185  $hidden = new html_hiddenfield(array('name' => '_cid', 'value' => $GLOBALS['cid']));
186  $input = new html_inputfield(array('type' => 'file', 'name' => '_photo', 'size' => $attrib['size']));
187  $button = new html_inputfield(array('type' => 'button'));
188
189  $out = html::div($attrib,
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  );
200
201  $OUTPUT->add_label('addphoto','replacephoto');
202  $OUTPUT->add_gui_object('uploadbox', $attrib['id']);
203  return $out;
204}
205
206// similar function as in /steps/settings/edit_identity.inc
207function get_form_tags($attrib)
208{
209    global $CONTACTS, $EDIT_FORM, $RCMAIL, $SOURCE_ID;
210
211    $form_start = $form_end = '';
212
213    if (empty($EDIT_FORM)) {
214        $hiddenfields = new html_hiddenfield();
215
216        if ($RCMAIL->action == 'edit')
217            $hiddenfields->add(array('name' => '_source', 'value' => $SOURCE_ID));
218        $hiddenfields->add(array('name' => '_gid', 'value' => $CONTACTS->group_id));
219
220        if (($result = $CONTACTS->get_result()) && ($record = $result->first()))
221            $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID']));
222
223        $form_start = $RCMAIL->output->request_form(array(
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>' : '';
229
230        $EDIT_FORM = !empty($attrib['form']) ? $attrib['form'] : 'form';
231        $RCMAIL->output->add_gui_object('editform', $EDIT_FORM);
232    }
233
234    return array($form_start, $form_end);
235}
236
237function rcmail_source_selector($attrib)
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
260
261$OUTPUT->add_handlers(array(
262    'contactedithead' => 'rcmail_contact_edithead',
263    'contacteditform' => 'rcmail_contact_editform',
264    'contactphoto'    => 'rcmail_contact_photo',
265    'photouploadform' => 'rcmail_upload_photo_form',
266    'sourceselector'  => 'rcmail_source_selector',
267));
268
269if ($RCMAIL->action == 'add' && $OUTPUT->template_exists('contactadd'))
270    $OUTPUT->send('contactadd');
271
272// this will be executed if no template for addcontact exists
273$OUTPUT->send('contactedit');
Note: See TracBrowser for help on using the repository browser.