source: github/program/steps/addressbook/show.inc @ 0501b63

HEADcourier-fixdev-browser-capabilitiespdorelease-0.6release-0.7release-0.8
Last change on this file since 0501b63 was 0501b63, checked in by thomascube <thomas@…>, 2 years ago

Merge branch devel-addressbook (r4193:4382) back into trunk

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