source: subversion/trunk/roundcubemail/program/steps/addressbook/edit.inc @ 4850

Last change on this file since 4850 was 4850, checked in by alec, 2 years ago
  • Added searching in all addressbook sources (global-search)
  • Added addressbook source selection in contacts import
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.6 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
57function rcmail_get_edit_record()
58{
59    global $RCMAIL, $CONTACTS;
60
61     // check if we have a valid result
62     if ($GLOBALS['EDIT_RECORD']) {
63         $record = $GLOBALS['EDIT_RECORD'];
64     }
65     else if ($RCMAIL->action != 'add'
66         && !(($result = $CONTACTS->get_result()) && ($record = $result->first()))
67     ) {
68         $RCMAIL->output->show_message('contactnotfound');
69         return false;
70     }
71
72     return $record;
73}
74
75function rcmail_contact_edithead($attrib)
76{
77    // check if we have a valid result
78    $record = rcmail_get_edit_record();
79    $i_size = !empty($attrib['size']) ? $attrib['size'] : 20;
80
81    $form = array(
82        'head' => array(
83            'content' => array(
84                'prefix' => array('size' => $i_size),
85                'firstname' => array('size' => $i_size, 'visible' => true),
86                'middlename' => array('size' => $i_size),
87                'surname' => array('size' => $i_size, 'visible' => true),
88                'suffix' => array('size' => $i_size),
89                'name' => array('size' => 2*$i_size),
90                'nickname' => array('size' => 2*$i_size),
91                'company' => array('size' => $i_size),
92                'department' => array('size' => $i_size),
93                'jobtitle' => array('size' => $i_size),
94            )
95        )
96    );
97
98    list($form_start, $form_end) = get_form_tags($attrib);
99    unset($attrib['form'], $attrib['name'], $attrib['size']);
100
101    // return the address edit form
102    $out = rcmail_contact_form($form, $record, $attrib);
103
104    return $form_start . $out . $form_end;
105}
106
107
108function rcmail_contact_editform($attrib)
109{
110    global $RCMAIL, $CONTACT_COLTYPES;
111
112    $record = rcmail_get_edit_record();
113
114    // add some labels to client
115    $RCMAIL->output->add_label('noemailwarning', 'nonamewarning');
116
117    // copy (parsed) address template to client
118    if (preg_match_all('/\{([a-z0-9]+)\}([^{]*)/i', $RCMAIL->config->get('address_template', ''), $templ, PREG_SET_ORDER))
119      $RCMAIL->output->set_env('address_template', $templ);
120
121    $i_size = !empty($attrib['size']) ? $attrib['size'] : 40;
122    $t_rows = !empty($attrib['textarearows']) ? $attrib['textarearows'] : 10;
123    $t_cols = !empty($attrib['textareacols']) ? $attrib['textareacols'] : 40;
124
125    $form = array(
126        'contact' => array(
127            'name'    => rcube_label('contactproperties'),
128            'content' => array(
129                'email' => array('size' => $i_size, 'visible' => true),
130                'phone' => array('size' => $i_size, 'visible' => true),
131                'address' => array('visible' => true),
132                'website' => array('size' => $i_size),
133                'im' => array('size' => $i_size),
134            ),
135        ),
136        'personal' => array(
137            'name'    => rcube_label('personalinfo'),
138            'content' => array(
139                'gender' => array('visible' => true),
140                'maidenname' => array('size' => $i_size),
141                'birthday' => array('visible' => true),
142                'anniversary' => array(),
143                'manager' => array('size' => $i_size),
144                'assistant' => array('size' => $i_size),
145                'spouse' => array('size' => $i_size),
146            ),
147        ),
148    );
149
150    if (isset($CONTACT_COLTYPES['notes'])) {
151        $form['notes'] = array(
152            'name'    => rcube_label('notes'),
153            'content' => array(
154                'notes' => array('size' => $t_cols, 'rows' => $t_rows, 'label' => false, 'visible' => true, 'limit' => 1),
155            ),
156            'single' => true,
157        );
158    }
159
160    list($form_start, $form_end) = get_form_tags($attrib);
161    unset($attrib['form']);
162
163    // return the complete address edit form as table
164    $out = rcmail_contact_form($form, $record, $attrib);
165
166    return $form_start . $out . $form_end;
167}
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
207// similar function as in /steps/settings/edit_identity.inc
208function get_form_tags($attrib)
209{
210    global $CONTACTS, $EDIT_FORM, $RCMAIL;
211
212    $form_start = $form_end = '';
213
214    if (empty($EDIT_FORM)) {
215        $hiddenfields = new html_hiddenfield(array(
216            'name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC)));
217        $hiddenfields->add(array('name' => '_gid', 'value' => $CONTACTS->group_id));
218
219        if (($result = $CONTACTS->get_result()) && ($record = $result->first()))
220            $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID']));
221
222        $form_start = $RCMAIL->output->request_form(array(
223            'name' => "form", 'method' => "post",
224            'task' => $RCMAIL->task, 'action' => 'save',
225            'request' => 'save.'.intval($record['ID']),
226            'noclose' => true) + $attrib, $hiddenfields->show());
227        $form_end = !strlen($attrib['form']) ? '</form>' : '';
228
229        $EDIT_FORM = !empty($attrib['form']) ? $attrib['form'] : 'form';
230        $RCMAIL->output->add_gui_object('editform', $EDIT_FORM);
231    }
232
233    return array($form_start, $form_end);
234}
235
236
237$OUTPUT->add_handlers(array(
238    'contactedithead' => 'rcmail_contact_edithead',
239    'contacteditform' => 'rcmail_contact_editform',
240    'contactphoto'    => 'rcmail_contact_photo',
241    'photouploadform' => 'rcmail_upload_photo_form',
242));
243
244if ($RCMAIL->action == 'add' && $OUTPUT->template_exists('contactadd'))
245    $OUTPUT->send('contactadd');
246
247// this will be executed if no template for addcontact exists
248$OUTPUT->send('contactedit');
Note: See TracBrowser for help on using the repository browser.