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

Last change on this file since 4441 was 4441, checked in by thomasb, 2 years ago

Better grouping of contact information

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 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
22
23if (($cid = get_input_value('_cid', RCUBE_INPUT_GPC)) && ($record = $CONTACTS->get_record($cid, true)))
24    $OUTPUT->set_env('cid', $record['ID']);
25
26// adding not allowed here
27if ($CONTACTS->readonly) {
28    $OUTPUT->show_message('sourceisreadonly');
29    rcmail_overwrite_action('show');
30    return;
31}
32
33
34function rcmail_contact_edithead($attrib)
35{
36   global $RCMAIL, $CONTACTS;
37
38    // check if we have a valid result
39    if ($RCMAIL->action != 'add'
40        && !(($result = $CONTACTS->get_result()) && ($record = $result->first()))
41    ) {
42        $RCMAIL->output->show_message('contactnotfound');
43        return false;
44    }
45   
46    $i_size = !empty($attrib['size']) ? $attrib['size'] : 20;
47
48    $form = array(
49        'head' => array(
50            'content' => array(
51                'prefix' => array('size' => $i_size),
52                'firstname' => array('size' => $i_size, 'visible' => true),
53                'middlename' => array('size' => $i_size),
54                'surname' => array('size' => $i_size, 'visible' => true),
55                'suffix' => array('size' => $i_size),
56                'name' => array('size' => 2*$i_size),
57                'nickname' => array('size' => 2*$i_size),
58                'company' => array('size' => $i_size),
59                'department' => array('size' => $i_size),
60                'jobtitle' => array('size' => $i_size),
61            )
62        )
63    );
64
65    list($form_start, $form_end) = get_form_tags($attrib);
66    unset($attrib['form'], $attrib['name'], $attrib['size']);
67
68    // return the address edit form
69    $out = rcmail_contact_form($form, $record, $attrib);
70
71    return $form_start . $out . $form_end;
72}
73
74
75function rcmail_contact_editform($attrib)
76{
77   global $RCMAIL, $CONTACTS, $CONTACT_COLTYPES;
78
79    // check if we have a valid result
80    if ($RCMAIL->action != 'add'
81        && !(($result = $CONTACTS->get_result()) && ($record = $result->first()))
82    ) {
83        $RCMAIL->output->show_message('contactnotfound');
84        return false;
85    }
86
87    // add some labels to client
88    $RCMAIL->output->add_label('noemailwarning', 'nonamewarning');
89
90    $i_size = !empty($attrib['size']) ? $attrib['size'] : 40;
91    $t_rows = !empty($attrib['textarearows']) ? $attrib['textarearows'] : 10;
92    $t_cols = !empty($attrib['textareacols']) ? $attrib['textareacols'] : 40;
93
94    $form = array(
95        'info' => array(
96            'name'    => rcube_label('contactproperties'),
97            'content' => array(
98                'email' => array('size' => $i_size, 'visible' => true),
99                'phone' => array('size' => $i_size, 'visible' => true),
100                'address' => array('visible' => true),
101                'website' => array('size' => $i_size),
102                'im' => array('size' => $i_size),
103            ),
104        ),
105        'personal' => array(
106            'name'    => rcube_label('personalinfo'),
107            'content' => array(
108                'gender' => array('visible' => true),
109                'maidenname' => array('size' => $i_size),
110                'birthday' => array('visible' => true),
111                'anniversary' => array('size' => $i_size),
112                'manager' => array('size' => $i_size),
113                'assistant' => array('size' => $i_size),
114                'spouse' => array('size' => $i_size),
115            ),
116        ),
117    );
118   
119    if (isset($CONTACT_COLTYPES['notes'])) {
120        $form['notes'] = array(
121            'name'    => rcube_label('notes'),
122            'content' => array(
123                'notes' => array('size' => $t_cols, 'rows' => $t_rows, 'label' => false, 'visible' => true, 'limit' => 1),
124            ),
125            'single' => true,
126        );
127    }
128
129    list($form_start, $form_end) = get_form_tags($attrib);
130    unset($attrib['form']);
131
132    // return the complete address edit form as table
133    $out = rcmail_contact_form($form, $record, $attrib);
134
135    return $form_start . $out . $form_end;
136}
137
138
139function rcmail_upload_photo_form($attrib)
140{
141  global $OUTPUT;
142
143  // add ID if not given
144  if (!$attrib['id'])
145    $attrib['id'] = 'rcmUploadbox';
146
147  // find max filesize value
148  $max_filesize = parse_bytes(ini_get('upload_max_filesize'));
149  $max_postsize = parse_bytes(ini_get('post_max_size'));
150  if ($max_postsize && $max_postsize < $max_filesize)
151    $max_filesize = $max_postsize;
152  $max_filesize = show_bytes($max_filesize);
153 
154  $hidden = new html_hiddenfield(array('name' => '_cid', 'value' => $GLOBALS['cid']));
155  $input = new html_inputfield(array('type' => 'file', 'name' => '_photo', 'size' => $attrib['size']));
156  $button = new html_inputfield(array('type' => 'button'));
157 
158  $out = html::div($attrib,
159    $OUTPUT->form_tag(array('name' => 'uploadform', 'method' => 'post', 'enctype' => 'multipart/form-data'),
160      $hidden->show() .
161      html::div(null, $input->show()) .
162      html::div('hint', rcube_label(array('name' => 'maxuploadsize', 'vars' => array('size' => $max_filesize)))) .
163      html::div('buttons',
164        $button->show(rcube_label('close'), array('class' => 'button', 'onclick' => "$('#$attrib[id]').hide()")) . ' ' .
165        $button->show(rcube_label('upload'), array('class' => 'button mainaction', 'onclick' => JS_OBJECT_NAME . ".command('upload-photo', this.form)"))
166      )
167    )
168  );
169 
170  $OUTPUT->add_label('addphoto','replacephoto');
171  $OUTPUT->add_gui_object('uploadbox', $attrib['id']);
172  return $out;
173}
174
175
176// similar function as in /steps/settings/edit_identity.inc
177function get_form_tags($attrib)
178{
179    global $CONTACTS, $EDIT_FORM, $RCMAIL;
180
181    $form_start = $form_end = '';
182
183    if (empty($EDIT_FORM)) {
184        $hiddenfields = new html_hiddenfield(array(
185            'name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC)));
186        $hiddenfields->add(array('name' => '_gid', 'value' => $CONTACTS->group_id));
187
188        if (($result = $CONTACTS->get_result()) && ($record = $result->first()))
189            $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID']));
190
191        $form_start = $RCMAIL->output->request_form(array(
192            'name' => "form", 'method' => "post",
193            'task' => $RCMAIL->task, 'action' => 'save',
194            'request' => 'save.'.intval($record['ID']),
195            'noclose' => true) + $attrib, $hiddenfields->show());
196        $form_end = !strlen($attrib['form']) ? '</form>' : '';
197
198        $EDIT_FORM = !empty($attrib['form']) ? $attrib['form'] : 'form';
199        $RCMAIL->output->add_gui_object('editform', $EDIT_FORM);
200    }
201
202    return array($form_start, $form_end);
203}
204
205
206$OUTPUT->add_handler('contactedithead', 'rcmail_contact_edithead');
207$OUTPUT->add_handler('contacteditform', 'rcmail_contact_editform');
208$OUTPUT->add_handler('contactphoto',    'rcmail_contact_photo');
209$OUTPUT->add_handler('photouploadform', 'rcmail_upload_photo_form');
210
211if (!$CONTACTS->get_result() && $OUTPUT->template_exists('contactadd'))
212    $OUTPUT->send('contactadd');
213
214// this will be executed if no template for addcontact exists
215$OUTPUT->send('contactedit');
Note: See TracBrowser for help on using the repository browser.