alecpl
2010-11-04 83ba22c77b8790d8cbea8c684c4e1a0c431b83d6
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                     |
A 8  | Copyright (C) 2005-2009, Roundcube Dev. - Switzerland                 |
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
22
f11541 23 // read contact record
f92aba 24 if (($cid = get_input_value('_cid', RCUBE_INPUT_GPC)) && ($record = $CONTACTS->get_record($cid, true))) {
a79417 25     $OUTPUT->set_env('cid', $record['ID']);
f92aba 26 }
cb7d32 27
T 28
4e17e6 29 function rcmail_contact_details($attrib)
f92aba 30 {
a79417 31     global $CONTACTS, $RCMAIL;
4e17e6 32
a79417 33     // check if we have a valid result
A 34     if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) {
35         $RCMAIL->output->show_message('contactnotfound');
36         return false;
4e17e6 37     }
a79417 38
A 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;    
f92aba 64     }
a79417 65     else {
A 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);
f92aba 84 }
4e17e6 85
T 86
a79417 87 function rcmail_contact_record_groups($contact_id)
cb7d32 88 {
a79417 89     global $RCMAIL, $CONTACTS, $GROUPS;
cb7d32 90
a79417 91     $GROUPS = $CONTACTS->list_groups();
A 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');
cb7d32 121   
a79417 122     return $form_start . $table->show() . $form_end;
cb7d32 123 }
T 124
125
f11541 126 //$OUTPUT->framed = $_framed;
T 127 $OUTPUT->add_handler('contactdetails', 'rcmail_contact_details');
a79417 128
83ba22 129 $OUTPUT->send('contact');