4 +-----------------------------------------------------------------------+
5 | program/steps/addressbook/show.inc |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2005-2009, The Roundcube Dev Team |
9 | Licensed under the GNU GPL |
12 | Show contact details |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: show.inc 5681 2012-01-01 13:36:22Z alec $
22 // Get contact ID and source ID from request
23 $cids = rcmail_get_cids();
25 $cid = array_shift($cids[$source]);
27 // Initialize addressbook source
28 $CONTACTS = rcmail_contact_source($source, true);
31 // read contact record
32 if ($cid && ($record = $CONTACTS->get_record($cid, true))) {
33 $OUTPUT->set_env('cid', $record['ID']);
36 // get address book name (for display)
37 rcmail_set_sourcename($CONTACTS);
39 // return raw photo of the given contact
40 if ($RCMAIL->action == 'photo') {
41 if (($file_id = get_input_value('_photo', RCUBE_INPUT_GPC)) && ($tempfile = $_SESSION['contacts']['files'][$file_id])) {
42 $tempfile = $RCMAIL->plugins->exec_hook('attachment_display', $tempfile);
43 if ($tempfile['status']) {
44 if ($tempfile['data'])
45 $data = $tempfile['data'];
46 else if ($tempfile['path'])
47 $data = file_get_contents($tempfile['path']);
50 else if ($record['photo']) {
51 $data = is_array($record['photo']) ? $record['photo'][0] : $record['photo'];
52 if (!preg_match('![^a-z0-9/=+-]!i', $data))
53 $data = base64_decode($data, true);
56 header('Content-Type: ' . rc_image_content_type($data));
57 echo $data ? $data : file_get_contents('program/blank.gif');
62 function rcmail_contact_head($attrib)
64 global $CONTACTS, $RCMAIL;
66 // check if we have a valid result
67 if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) {
68 $RCMAIL->output->show_message('contactnotfound');
72 $microformats = array('name' => 'fn', 'email' => 'email');
75 'head' => array( // section 'head' is magic!
77 'prefix' => array('type' => 'text'),
78 'firstname' => array('type' => 'text'),
79 'middlename' => array('type' => 'text'),
80 'surname' => array('type' => 'text'),
81 'suffix' => array('type' => 'text'),
86 unset($attrib['name']);
87 return rcmail_contact_form($form, $record, $attrib);
91 function rcmail_contact_details($attrib)
93 global $CONTACTS, $RCMAIL, $CONTACT_COLTYPES;
95 // check if we have a valid result
96 if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) {
97 //$RCMAIL->output->show_message('contactnotfound');
101 $i_size = !empty($attrib['size']) ? $attrib['size'] : 40;
105 'name' => rcube_label('properties'),
107 'email' => array('size' => $i_size, 'render_func' => 'rcmail_render_email_value'),
108 'phone' => array('size' => $i_size),
109 'address' => array(),
110 'website' => array('size' => $i_size, 'render_func' => 'rcmail_render_url_value'),
111 'im' => array('size' => $i_size),
115 'name' => rcube_label('personalinfo'),
117 'gender' => array('size' => $i_size),
118 'maidenname' => array('size' => $i_size),
119 'birthday' => array('size' => $i_size),
120 'anniversary' => array('size' => $i_size),
121 'manager' => array('size' => $i_size),
122 'assistant' => array('size' => $i_size),
123 'spouse' => array('size' => $i_size),
128 if (isset($CONTACT_COLTYPES['notes'])) {
129 $form['notes'] = array(
130 'name' => rcube_label('notes'),
132 'notes' => array('type' => 'textarea', 'label' => false),
137 if ($CONTACTS->groups) {
138 $form['groups'] = array(
139 'name' => rcube_label('groups'),
140 'content' => rcmail_contact_record_groups($record['ID']),
144 return rcmail_contact_form($form, $record);
148 function rcmail_render_email_value($email, $col)
150 return html::a(array(
151 'href' => 'mailto:' . $email,
152 'onclick' => sprintf("return %s.command('compose','%s',this)", JS_OBJECT_NAME, JQ($email)),
153 'title' => rcube_label('composeto'),
159 function rcmail_render_url_value($url, $col)
161 $prefix = preg_match('!^(http|ftp)s?://!', $url) ? '' : 'http://';
162 return html::a(array(
163 'href' => $prefix . $url,
164 'target' => '_blank',
170 function rcmail_contact_record_groups($contact_id)
172 global $RCMAIL, $CONTACTS, $GROUPS;
174 $GROUPS = $CONTACTS->list_groups();
176 if (empty($GROUPS)) {
180 $table = new html_table(array('cols' => 2, 'cellspacing' => 0, 'border' => 0));
182 $members = $CONTACTS->get_record_groups($contact_id);
183 $checkbox = new html_checkbox(array('name' => '_gid[]',
184 'class' => 'groupmember', 'disabled' => $CONTACTS->readonly));
186 foreach ($GROUPS as $group) {
188 $table->add(null, $checkbox->show($members[$gid] ? $gid : null,
189 array('value' => $gid, 'id' => 'ff_gid' . $gid)));
190 $table->add(null, html::label('ff_gid' . $gid, Q($group['name'])));
193 $hiddenfields = new html_hiddenfield(array('name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC)));
194 $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID']));
196 $form_start = $RCMAIL->output->request_form(array(
197 'name' => "form", 'method' => "post",
198 'task' => $RCMAIL->task, 'action' => 'save',
199 'request' => 'save.'.intval($contact_id),
200 'noclose' => true), $hiddenfields->show());
201 $form_end = '</form>';
203 $RCMAIL->output->add_gui_object('editform', 'form');
204 $RCMAIL->output->add_label('addingmember', 'removingmember');
206 return $form_start . $table->show() . $form_end;
210 $OUTPUT->add_handlers(array(
211 'contacthead' => 'rcmail_contact_head',
212 'contactdetails' => 'rcmail_contact_details',
213 'contactphoto' => 'rcmail_contact_photo',
216 $OUTPUT->send('contact');