0
|
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-2013, The Roundcube Dev Team |
|
|
9 | |
|
|
10 | Licensed under the GNU General Public License version 3 or |
|
|
11 | any later version with exceptions for skins & plugins. |
|
|
12 | See the README file for a full license statement. |
|
|
13 | |
|
|
14 | PURPOSE: |
|
|
15 | Show contact details |
|
|
16 | |
|
|
17 +-----------------------------------------------------------------------+
|
|
18 | Author: Thomas Bruederli <roundcube@gmail.com> |
|
|
19 +-----------------------------------------------------------------------+
|
|
20 */
|
|
21
|
|
22 // Get contact ID and source ID from request
|
|
23 $cids = rcmail_get_cids();
|
|
24 $source = key($cids);
|
|
25 $cid = $cids ? array_shift($cids[$source]) : null;
|
|
26
|
|
27 // Initialize addressbook source
|
|
28 $CONTACTS = rcmail_contact_source($source, true);
|
|
29 $SOURCE_ID = $source;
|
|
30
|
|
31 // read contact record (or get the one defined in 'save' action)
|
|
32 if ($cid && ($record = ($CONTACT_RECORD ?: $CONTACTS->get_record($cid, true)))) {
|
|
33 $OUTPUT->set_env('readonly', $CONTACTS->readonly || $record['readonly']);
|
|
34 $OUTPUT->set_env('cid', $record['ID']);
|
|
35
|
|
36 // remember current search request ID (if in search mode)
|
|
37 if ($search = rcube_utils::get_input_value('_search', rcube_utils::INPUT_GET)) {
|
|
38 $OUTPUT->set_env('search_request', $search);
|
|
39 }
|
|
40 }
|
|
41
|
|
42 // get address book name (for display)
|
|
43 rcmail_set_sourcename($CONTACTS);
|
|
44
|
|
45 // Disable qr-code if php-gd or Endroid's QrCode is not installed
|
|
46 $OUTPUT->set_env('qrcode', function_exists('imagecreate') && class_exists('Endroid\QrCode\QrCode'));
|
|
47 $OUTPUT->add_label('qrcode');
|
|
48
|
|
49 $OUTPUT->add_handlers(array(
|
|
50 'contacthead' => 'rcmail_contact_head',
|
|
51 'contactdetails' => 'rcmail_contact_details',
|
|
52 'contactphoto' => 'rcmail_contact_photo',
|
|
53 ));
|
|
54
|
|
55 $OUTPUT->send('contact');
|
|
56
|
|
57
|
|
58
|
|
59 function rcmail_contact_head($attrib)
|
|
60 {
|
|
61 global $CONTACTS, $RCMAIL;
|
|
62
|
|
63 // check if we have a valid result
|
|
64 if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) {
|
|
65 $RCMAIL->output->show_message('contactnotfound', 'error');
|
|
66 return false;
|
|
67 }
|
|
68
|
|
69 $form = array(
|
|
70 'head' => array( // section 'head' is magic!
|
|
71 'name' => $RCMAIL->gettext('contactnameandorg'),
|
|
72 'content' => array(
|
|
73 'prefix' => array('type' => 'text'),
|
|
74 'firstname' => array('type' => 'text'),
|
|
75 'middlename' => array('type' => 'text'),
|
|
76 'surname' => array('type' => 'text'),
|
|
77 'suffix' => array('type' => 'text'),
|
|
78 'name' => array('type' => 'text'),
|
|
79 'nickname' => array('type' => 'text'),
|
|
80 'organization' => array('type' => 'text'),
|
|
81 'department' => array('type' => 'text'),
|
|
82 'jobtitle' => array('type' => 'text'),
|
|
83 ),
|
|
84 ),
|
|
85 );
|
|
86
|
|
87 unset($attrib['name']);
|
|
88 return rcmail_contact_form($form, $record, $attrib);
|
|
89 }
|
|
90
|
|
91
|
|
92 function rcmail_contact_details($attrib)
|
|
93 {
|
|
94 global $CONTACTS, $RCMAIL, $CONTACT_COLTYPES;
|
|
95
|
|
96 // check if we have a valid result
|
|
97 if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) {
|
|
98 return false;
|
|
99 }
|
|
100
|
|
101 $i_size = $attrib['size'] ?: 40;
|
|
102
|
|
103 $form = array(
|
|
104 'contact' => array(
|
|
105 'name' => $RCMAIL->gettext('properties'),
|
|
106 'content' => array(
|
|
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),
|
|
112 ),
|
|
113 ),
|
|
114 'personal' => array(
|
|
115 'name' => $RCMAIL->gettext('personalinfo'),
|
|
116 'content' => array(
|
|
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),
|
|
124 ),
|
|
125 ),
|
|
126 );
|
|
127
|
|
128 if (isset($CONTACT_COLTYPES['notes'])) {
|
|
129 $form['notes'] = array(
|
|
130 'name' => $RCMAIL->gettext('notes'),
|
|
131 'content' => array(
|
|
132 'notes' => array('type' => 'textarea', 'label' => false),
|
|
133 ),
|
|
134 );
|
|
135 }
|
|
136
|
|
137 if ($CONTACTS->groups) {
|
|
138 $form['groups'] = array(
|
|
139 'name' => $RCMAIL->gettext('groups'),
|
|
140 'content' => rcmail_contact_record_groups($record['ID']),
|
|
141 );
|
|
142 }
|
|
143
|
|
144 return rcmail_contact_form($form, $record);
|
|
145 }
|
|
146
|
|
147
|
|
148 function rcmail_render_email_value($email)
|
|
149 {
|
|
150 global $RCMAIL;
|
|
151
|
|
152 return html::a(array(
|
|
153 'href' => 'mailto:' . $email,
|
|
154 'onclick' => sprintf("return %s.command('compose','%s',this)", rcmail_output::JS_OBJECT_NAME, rcube::JQ($email)),
|
|
155 'title' => $RCMAIL->gettext('composeto'),
|
|
156 'class' => 'email',
|
|
157 ), rcube::Q($email));
|
|
158 }
|
|
159
|
|
160
|
|
161 function rcmail_render_url_value($url)
|
|
162 {
|
|
163 $prefix = preg_match('!^(http|ftp)s?://!', $url) ? '' : 'http://';
|
|
164 return html::a(array(
|
|
165 'href' => $prefix . $url,
|
|
166 'target' => '_blank',
|
|
167 'class' => 'url',
|
|
168 ), rcube::Q($url));
|
|
169 }
|
|
170
|
|
171
|
|
172 function rcmail_contact_record_groups($contact_id)
|
|
173 {
|
|
174 global $RCMAIL, $CONTACTS, $GROUPS;
|
|
175
|
|
176 $GROUPS = $CONTACTS->list_groups();
|
|
177
|
|
178 if (empty($GROUPS)) {
|
|
179 return '';
|
|
180 }
|
|
181
|
|
182 $members = $CONTACTS->get_record_groups($contact_id);
|
|
183 $table = new html_table(array('cols' => 2, 'cellspacing' => 0, 'border' => 0));
|
|
184 $checkbox = new html_checkbox(array('name' => '_gid[]',
|
|
185 'class' => 'groupmember', 'disabled' => $CONTACTS->readonly));
|
|
186
|
|
187 foreach ($GROUPS as $group) {
|
|
188 $gid = $group['ID'];
|
|
189 $table->add(null, $checkbox->show($members[$gid] ? $gid : null,
|
|
190 array('value' => $gid, 'id' => 'ff_gid' . $gid)));
|
|
191 $table->add(null, html::label('ff_gid' . $gid, rcube::Q($group['name'])));
|
|
192 }
|
|
193
|
|
194 $hiddenfields = new html_hiddenfield(array('name' => '_source', 'value' => rcube_utils::get_input_value('_source', rcube_utils::INPUT_GPC)));
|
|
195 $hiddenfields->add(array('name' => '_cid', 'value' => $contact_id));
|
|
196
|
|
197 $form_start = $RCMAIL->output->request_form(array(
|
|
198 'name' => "form", 'method' => "post",
|
|
199 'task' => $RCMAIL->task, 'action' => 'save',
|
|
200 'request' => 'save.'.intval($contact_id),
|
|
201 'noclose' => true), $hiddenfields->show());
|
|
202 $form_end = '</form>';
|
|
203
|
|
204 $RCMAIL->output->add_gui_object('editform', 'form');
|
|
205 $RCMAIL->output->add_label('addingmember', 'removingmember');
|
|
206
|
|
207 return $form_start . html::tag('fieldset', 'contactfieldgroup contactgroups', $table->show()) . $form_end;
|
|
208 }
|