| 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 | // Get contact ID and source ID from request |
|---|
| 23 | $cids = rcmail_get_cids(); |
|---|
| 24 | $source = key($cids); |
|---|
| 25 | $cid = array_shift($cids[$source]); |
|---|
| 26 | |
|---|
| 27 | // Initialize addressbook source |
|---|
| 28 | $CONTACTS = rcmail_contact_source($source, true); |
|---|
| 29 | $SOURCE_ID = $source; |
|---|
| 30 | |
|---|
| 31 | // read contact record |
|---|
| 32 | if ($cid && ($record = $CONTACTS->get_record($cid, true))) { |
|---|
| 33 | $OUTPUT->set_env('cid', $record['ID']); |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | // get address book name (for display) |
|---|
| 37 | rcmail_set_sourcename($CONTACTS); |
|---|
| 38 | |
|---|
| 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']); |
|---|
| 48 | } |
|---|
| 49 | } |
|---|
| 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); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | header('Content-Type: ' . rc_image_content_type($data)); |
|---|
| 57 | echo $data ? $data : file_get_contents('program/blank.gif'); |
|---|
| 58 | exit; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | function rcmail_contact_head($attrib) |
|---|
| 63 | { |
|---|
| 64 | global $CONTACTS, $RCMAIL; |
|---|
| 65 | |
|---|
| 66 | // check if we have a valid result |
|---|
| 67 | if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) { |
|---|
| 68 | $RCMAIL->output->show_message('contactnotfound'); |
|---|
| 69 | return false; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | $microformats = array('name' => 'fn', 'email' => 'email'); |
|---|
| 73 | |
|---|
| 74 | $form = array( |
|---|
| 75 | 'head' => array( // section 'head' is magic! |
|---|
| 76 | 'content' => array( |
|---|
| 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'), |
|---|
| 82 | ), |
|---|
| 83 | ), |
|---|
| 84 | ); |
|---|
| 85 | |
|---|
| 86 | unset($attrib['name']); |
|---|
| 87 | return rcmail_contact_form($form, $record, $attrib); |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | function rcmail_contact_details($attrib) |
|---|
| 92 | { |
|---|
| 93 | global $CONTACTS, $RCMAIL, $CONTACT_COLTYPES; |
|---|
| 94 | |
|---|
| 95 | // check if we have a valid result |
|---|
| 96 | if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) { |
|---|
| 97 | //$RCMAIL->output->show_message('contactnotfound'); |
|---|
| 98 | return false; |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | $i_size = !empty($attrib['size']) ? $attrib['size'] : 40; |
|---|
| 102 | |
|---|
| 103 | $form = array( |
|---|
| 104 | 'contact' => array( |
|---|
| 105 | 'name' => rcube_label('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' => rcube_label('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' => rcube_label('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' => rcube_label('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, $col) |
|---|
| 149 | { |
|---|
| 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'), |
|---|
| 154 | 'class' => 'email', |
|---|
| 155 | ), Q($email)); |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | function rcmail_render_url_value($url, $col) |
|---|
| 160 | { |
|---|
| 161 | $prefix = preg_match('!^(http|ftp)s?://!', $url) ? '' : 'http://'; |
|---|
| 162 | return html::a(array( |
|---|
| 163 | 'href' => $prefix . $url, |
|---|
| 164 | 'target' => '_blank', |
|---|
| 165 | 'class' => 'url', |
|---|
| 166 | ), Q($url)); |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | function rcmail_contact_record_groups($contact_id) |
|---|
| 171 | { |
|---|
| 172 | global $RCMAIL, $CONTACTS, $GROUPS; |
|---|
| 173 | |
|---|
| 174 | $GROUPS = $CONTACTS->list_groups(); |
|---|
| 175 | |
|---|
| 176 | if (empty($GROUPS)) { |
|---|
| 177 | return ''; |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | $table = new html_table(array('cols' => 2, 'cellspacing' => 0, 'border' => 0)); |
|---|
| 181 | |
|---|
| 182 | $members = $CONTACTS->get_record_groups($contact_id); |
|---|
| 183 | $checkbox = new html_checkbox(array('name' => '_gid[]', |
|---|
| 184 | 'class' => 'groupmember', 'disabled' => $CONTACTS->readonly)); |
|---|
| 185 | |
|---|
| 186 | foreach ($GROUPS as $group) { |
|---|
| 187 | $gid = $group['ID']; |
|---|
| 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']))); |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 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'])); |
|---|
| 195 | |
|---|
| 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>'; |
|---|
| 202 | |
|---|
| 203 | $RCMAIL->output->add_gui_object('editform', 'form'); |
|---|
| 204 | $RCMAIL->output->add_label('addingmember', 'removingmember'); |
|---|
| 205 | |
|---|
| 206 | return $form_start . html::tag('fieldset', 'contactfieldgroup contactgroups', $table->show()) . $form_end; |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | $OUTPUT->add_handlers(array( |
|---|
| 211 | 'contacthead' => 'rcmail_contact_head', |
|---|
| 212 | 'contactdetails' => 'rcmail_contact_details', |
|---|
| 213 | 'contactphoto' => 'rcmail_contact_photo', |
|---|
| 214 | )); |
|---|
| 215 | |
|---|
| 216 | $OUTPUT->send('contact'); |
|---|