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