]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/addressbook/show.inc
268489289bd8632800a7f0ffd1ab8adefb0b3554
[roundcube.git] / program / steps / addressbook / show.inc
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, Roundcube Dev. - Switzerland                 |
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: show.inc 4176 2010-11-04 09:59:55Z alec $
19
20 */
21
22
23 // read contact record
24 if (($cid = get_input_value('_cid', RCUBE_INPUT_GPC)) && ($record = $CONTACTS->get_record($cid, true))) {
25     $OUTPUT->set_env('cid', $record['ID']);
26 }
27
28
29 function rcmail_contact_details($attrib)
30 {
31     global $CONTACTS, $RCMAIL;
32
33     // check if we have a valid result
34     if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) {
35         $RCMAIL->output->show_message('contactnotfound');
36         return false;
37     }
38
39     $i_size = !empty($attrib['size']) ? $attrib['size'] : 40;
40     $t_rows = !empty($attrib['textarearows']) ? $attrib['textarearows'] : 6;
41     $t_cols = !empty($attrib['textareacols']) ? $attrib['textareacols'] : 40;
42
43     $microformats = array('name' => 'fn', 'email' => 'email');
44
45     $form = array(
46         'info' => array(
47             'name'    => rcube_label('contactproperties'),
48             'content' => array(
49                 'name' => array('type' => 'text', 'size' => $i_size),
50                 'firstname' => array('type' => 'text', 'size' => $i_size),
51                 'surname' => array('type' => 'text', 'size' => $i_size),
52                 'email' => array('type' => 'text', 'size' => $i_size),
53             ),
54         ),
55         'groups' => array(
56             'name'    => rcube_label('groups'),
57             'content' => '',
58         ),
59     );
60
61     // Get content of groups fieldset
62     if ($groups = rcmail_contact_record_groups($record['ID'])) {
63         $form['groups']['content'] = $groups;    
64     }
65     else {
66         unset($form['groups']);
67     }
68
69     if (!empty($record['email'])) {
70         $form['info']['content']['email']['value'] = html::a(array(
71             'href' => 'mailto:' . $record['email'],
72             'onclick' => sprintf("return %s.command('compose','%s',this)", JS_OBJECT_NAME, JQ($record['email'])),
73             'title' => rcube_label('composeto'),
74             'class' => $microformats['email'],
75         ), Q($record['email']));
76     }
77     foreach (array('name', 'firstname', 'surname') as $col) {
78         if ($record[$col]) {
79             $form['info']['content'][$col]['value'] = html::span($microformats[$col], Q($record[$col]));
80         }
81     }
82
83     return rcmail_contact_form($form, $record);
84 }
85
86
87 function rcmail_contact_record_groups($contact_id)
88 {
89     global $RCMAIL, $CONTACTS, $GROUPS;
90
91     $GROUPS = $CONTACTS->list_groups();
92
93     if (empty($GROUPS)) {
94         return '';
95     }
96
97     $table = new html_table(array('cols' => 2, 'cellspacing' => 0, 'border' => 0));
98
99     $members = $CONTACTS->get_record_groups($contact_id);
100     $checkbox = new html_checkbox(array('name' => '_gid[]',
101         'class' => 'groupmember', 'disabled' => $CONTACTS->readonly));
102
103     foreach ($GROUPS as $group) {
104         $gid = $group['ID'];
105         $table->add(null, $checkbox->show($members[$gid] ? $gid : null,
106             array('value' => $gid, 'id' => 'ff_gid' . $gid)));
107         $table->add(null, html::label('ff_gid' . $gid, Q($group['name'])));
108     }
109
110     $hiddenfields = new html_hiddenfield(array('name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC)));
111     $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID']));
112
113     $form_start = $RCMAIL->output->request_form(array(
114         'name' => "form", 'method' => "post",
115         'task' => $RCMAIL->task, 'action' => 'save',
116         'request' => 'save.'.intval($contact_id),
117         'noclose' => true), $hiddenfields->show());
118     $form_end = '</form>';
119
120     $RCMAIL->output->add_gui_object('editform', 'form');
121   
122     return $form_start . $table->show() . $form_end;
123 }
124
125
126 //$OUTPUT->framed = $_framed;
127 $OUTPUT->add_handler('contactdetails', 'rcmail_contact_details');
128
129 $OUTPUT->send('contact');