thomascube
2012-03-14 a621a9d7ecf334c4894ef8f5168eb6208e5ae0e4
commit | author | age
4e17e6 1 <?php
T 2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/addressbook/show.inc                                    |
6  |                                                                       |
e019f2 7  | This file is part of the Roundcube Webmail client                     |
f5e7b3 8  | Copyright (C) 2005-2009, The Roundcube Dev Team                       |
7fe381 9  |                                                                       |
T 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.                     |
4e17e6 13  |                                                                       |
T 14  | PURPOSE:                                                              |
15  |   Show contact details                                                |
16  |                                                                       |
17  +-----------------------------------------------------------------------+
18  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
19  +-----------------------------------------------------------------------+
20
21  $Id$
22
23 */
24
ecf295 25 // Get contact ID and source ID from request
A 26 $cids   = rcmail_get_cids();
27 $source = key($cids);
28 $cid    = array_shift($cids[$source]);
29
30 // Initialize addressbook source
c3dabf 31 $CONTACTS  = rcmail_contact_source($source, true);
A 32 $SOURCE_ID = $source;
4e17e6 33
f11541 34 // read contact record
ecf295 35 if ($cid && ($record = $CONTACTS->get_record($cid, true))) {
a79417 36     $OUTPUT->set_env('cid', $record['ID']);
f92aba 37 }
cb7d32 38
cc90ed 39 // get address book name (for display)
da89cf 40 rcmail_set_sourcename($CONTACTS);
cc90ed 41
0501b6 42 // return raw photo of the given contact
T 43 if ($RCMAIL->action == 'photo') {
44     if (($file_id = get_input_value('_photo', RCUBE_INPUT_GPC)) && ($tempfile = $_SESSION['contacts']['files'][$file_id])) {
45         $tempfile = $RCMAIL->plugins->exec_hook('attachment_display', $tempfile);
46         if ($tempfile['status']) {
47             if ($tempfile['data'])
48                 $data = $tempfile['data'];
49             else if ($tempfile['path'])
50                 $data = file_get_contents($tempfile['path']);
51         }
52     }
53     else if ($record['photo']) {
54         $data = is_array($record['photo']) ? $record['photo'][0] : $record['photo'];
55         if (!preg_match('![^a-z0-9/=+-]!i', $data))
56             $data = base64_decode($data, true);
57     }
ecf295 58
0501b6 59     header('Content-Type: ' . rc_image_content_type($data));
T 60     echo $data ? $data : file_get_contents('program/blank.gif');
61     exit;
62 }
cb7d32 63
0501b6 64
T 65 function rcmail_contact_head($attrib)
f92aba 66 {
a79417 67     global $CONTACTS, $RCMAIL;
4e17e6 68
a79417 69     // check if we have a valid result
A 70     if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) {
71         $RCMAIL->output->show_message('contactnotfound');
72         return false;
4e17e6 73     }
a79417 74
A 75     $microformats = array('name' => 'fn', 'email' => 'email');
0501b6 76
T 77     $form = array(
78         'head' => array(  // section 'head' is magic!
79             'content' => array(
80                 'prefix' => array('type' => 'text'),
81                 'firstname' => array('type' => 'text'),
82                 'middlename' => array('type' => 'text'),
83                 'surname' => array('type' => 'text'),
84                 'suffix' => array('type' => 'text'),
85             ),
86         ),
87     );
88
89     unset($attrib['name']);
90     return rcmail_contact_form($form, $record, $attrib);
91 }
92
93
94 function rcmail_contact_details($attrib)
95 {
96     global $CONTACTS, $RCMAIL, $CONTACT_COLTYPES;
97
98     // check if we have a valid result
99     if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) {
100         //$RCMAIL->output->show_message('contactnotfound');
101         return false;
102     }
103
104     $i_size = !empty($attrib['size']) ? $attrib['size'] : 40;
a79417 105
A 106     $form = array(
29aab5 107         'contact' => array(
1c029b 108             'name'    => rcube_label('properties'),
a79417 109             'content' => array(
0501b6 110               'email' => array('size' => $i_size, 'render_func' => 'rcmail_render_email_value'),
T 111               'phone' => array('size' => $i_size),
112               'address' => array(),
113               'website' => array('size' => $i_size, 'render_func' => 'rcmail_render_url_value'),
114               'im' => array('size' => $i_size),
fbeb46 115             ),
T 116         ),
117         'personal' => array(
118             'name'    => rcube_label('personalinfo'),
119             'content' => array(
120                 'gender' => array('size' => $i_size),
121                 'maidenname' => array('size' => $i_size),
122                 'birthday' => array('size' => $i_size),
123                 'anniversary' => array('size' => $i_size),
124                 'manager' => array('size' => $i_size),
125                 'assistant' => array('size' => $i_size),
126                 'spouse' => array('size' => $i_size),
a79417 127             ),
A 128         ),
129     );
0501b6 130     
T 131     if (isset($CONTACT_COLTYPES['notes'])) {
132         $form['notes'] = array(
133             'name'    => rcube_label('notes'),
134             'content' => array(
135                 'notes' => array('type' => 'textarea', 'label' => false),
136             ),
137         );
f92aba 138     }
0501b6 139     
T 140     if ($CONTACTS->groups) {
141         $form['groups'] = array(
142             'name'    => rcube_label('groups'),
143             'content' => rcmail_contact_record_groups($record['ID']),
144         );
a79417 145     }
A 146
147     return rcmail_contact_form($form, $record);
0501b6 148 }
T 149
150
151 function rcmail_render_email_value($email, $col)
152 {
153     return html::a(array(
154         'href' => 'mailto:' . $email,
155         'onclick' => sprintf("return %s.command('compose','%s',this)", JS_OBJECT_NAME, JQ($email)),
156         'title' => rcube_label('composeto'),
157         'class' => 'email',
158     ), Q($email));
159 }
160
161
162 function rcmail_render_url_value($url, $col)
163 {
f2e946 164     $prefix = preg_match('!^(http|ftp)s?://!', $url) ? '' : 'http://';
0501b6 165     return html::a(array(
T 166         'href' => $prefix . $url,
167         'target' => '_blank',
168         'class' => 'url',
169     ), Q($url));
f92aba 170 }
4e17e6 171
T 172
a79417 173 function rcmail_contact_record_groups($contact_id)
cb7d32 174 {
a79417 175     global $RCMAIL, $CONTACTS, $GROUPS;
cb7d32 176
a79417 177     $GROUPS = $CONTACTS->list_groups();
A 178
179     if (empty($GROUPS)) {
180         return '';
181     }
182
183     $table = new html_table(array('cols' => 2, 'cellspacing' => 0, 'border' => 0));
184
185     $members = $CONTACTS->get_record_groups($contact_id);
186     $checkbox = new html_checkbox(array('name' => '_gid[]',
187         'class' => 'groupmember', 'disabled' => $CONTACTS->readonly));
188
189     foreach ($GROUPS as $group) {
190         $gid = $group['ID'];
191         $table->add(null, $checkbox->show($members[$gid] ? $gid : null,
192             array('value' => $gid, 'id' => 'ff_gid' . $gid)));
193         $table->add(null, html::label('ff_gid' . $gid, Q($group['name'])));
194     }
195
196     $hiddenfields = new html_hiddenfield(array('name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC)));
197     $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID']));
198
199     $form_start = $RCMAIL->output->request_form(array(
200         'name' => "form", 'method' => "post",
201         'task' => $RCMAIL->task, 'action' => 'save',
202         'request' => 'save.'.intval($contact_id),
203         'noclose' => true), $hiddenfields->show());
204     $form_end = '</form>';
205
206     $RCMAIL->output->add_gui_object('editform', 'form');
2c77f5 207     $RCMAIL->output->add_label('addingmember', 'removingmember');
ecf295 208
aa3a9a 209     return $form_start . html::tag('fieldset', 'contactfieldgroup contactgroups', $table->show()) . $form_end;
cb7d32 210 }
T 211
212
ecf295 213 $OUTPUT->add_handlers(array(
A 214     'contacthead'    => 'rcmail_contact_head',
215     'contactdetails' => 'rcmail_contact_details',
216     'contactphoto'   => 'rcmail_contact_photo',
217 ));
a79417 218
83ba22 219 $OUTPUT->send('contact');