| 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$ |
|---|
| 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_head($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 | $microformats = array('name' => 'fn', 'email' => 'email'); |
|---|
| 40 | |
|---|
| 41 | $form = array( |
|---|
| 42 | 'head' => array( // section 'head' is magic! |
|---|
| 43 | 'content' => array( |
|---|
| 44 | 'firstname' => array('type' => 'text'), |
|---|
| 45 | 'middlename' => array('type' => 'text'), |
|---|
| 46 | 'surname' => array('type' => 'text'), |
|---|
| 47 | ), |
|---|
| 48 | ), |
|---|
| 49 | ); |
|---|
| 50 | |
|---|
| 51 | unset($attrib['name']); |
|---|
| 52 | return rcmail_contact_form($form, $record, $attrib); |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | function rcmail_contact_details($attrib) |
|---|
| 57 | { |
|---|
| 58 | global $CONTACTS, $RCMAIL; |
|---|
| 59 | |
|---|
| 60 | // check if we have a valid result |
|---|
| 61 | if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) { |
|---|
| 62 | //$RCMAIL->output->show_message('contactnotfound'); |
|---|
| 63 | return false; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | $i_size = !empty($attrib['size']) ? $attrib['size'] : 40; |
|---|
| 67 | |
|---|
| 68 | $form = array( |
|---|
| 69 | 'info' => array( |
|---|
| 70 | 'name' => rcube_label('contactproperties'), |
|---|
| 71 | 'content' => array( |
|---|
| 72 | 'email' => array('size' => $i_size, 'value' => array()), |
|---|
| 73 | 'phone' => array('size' => $i_size), |
|---|
| 74 | 'address' => array(), |
|---|
| 75 | 'birthday' => array('size' => $i_size), |
|---|
| 76 | 'website' => array('size' => $i_size, 'value' => array()), |
|---|
| 77 | 'im' => array('size' => $i_size), |
|---|
| 78 | ), |
|---|
| 79 | ), |
|---|
| 80 | 'notes' => array( |
|---|
| 81 | 'name' => rcube_label('notes'), |
|---|
| 82 | 'content' => array( |
|---|
| 83 | 'notes' => array('type' => 'textarea', 'label' => false), |
|---|
| 84 | ), |
|---|
| 85 | ), |
|---|
| 86 | 'groups' => array( |
|---|
| 87 | 'name' => rcube_label('groups'), |
|---|
| 88 | 'content' => rcmail_contact_record_groups($record['ID']), |
|---|
| 89 | ), |
|---|
| 90 | ); |
|---|
| 91 | /* FIXME: this destroys subtype assignments |
|---|
| 92 | foreach ((array)$record as $field => $values) { |
|---|
| 93 | if (strpos($field, 'email') === 0) { |
|---|
| 94 | foreach ((array)$values as $email) { |
|---|
| 95 | $form['info']['content']['email']['value'][] = html::a(array( |
|---|
| 96 | 'href' => 'mailto:' . $email, |
|---|
| 97 | 'onclick' => sprintf("return %s.command('compose','%s',this)", JS_OBJECT_NAME, JQ($email)), |
|---|
| 98 | 'title' => rcube_label('composeto'), |
|---|
| 99 | 'class' => 'email', |
|---|
| 100 | ), Q($email)); |
|---|
| 101 | } |
|---|
| 102 | } |
|---|
| 103 | else if (strpos($field, 'website') === 0) { |
|---|
| 104 | foreach ((array)$values as $url) { |
|---|
| 105 | $prefix = preg_match('![htfps]+://!', $url) ? '' : 'http://'; |
|---|
| 106 | $form['info']['content']['website']['value'][] = html::a(array( |
|---|
| 107 | 'href' => $prefix . $url, |
|---|
| 108 | 'target' => '_blank', |
|---|
| 109 | 'class' => 'url', |
|---|
| 110 | ), Q($url)); |
|---|
| 111 | } |
|---|
| 112 | } |
|---|
| 113 | } |
|---|
| 114 | */ |
|---|
| 115 | return rcmail_contact_form($form, $record); |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | function rcmail_contact_record_groups($contact_id) |
|---|
| 120 | { |
|---|
| 121 | global $RCMAIL, $CONTACTS, $GROUPS; |
|---|
| 122 | |
|---|
| 123 | $GROUPS = $CONTACTS->list_groups(); |
|---|
| 124 | |
|---|
| 125 | if (empty($GROUPS)) { |
|---|
| 126 | return ''; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | $table = new html_table(array('cols' => 2, 'cellspacing' => 0, 'border' => 0)); |
|---|
| 130 | |
|---|
| 131 | $members = $CONTACTS->get_record_groups($contact_id); |
|---|
| 132 | $checkbox = new html_checkbox(array('name' => '_gid[]', |
|---|
| 133 | 'class' => 'groupmember', 'disabled' => $CONTACTS->readonly)); |
|---|
| 134 | |
|---|
| 135 | foreach ($GROUPS as $group) { |
|---|
| 136 | $gid = $group['ID']; |
|---|
| 137 | $table->add(null, $checkbox->show($members[$gid] ? $gid : null, |
|---|
| 138 | array('value' => $gid, 'id' => 'ff_gid' . $gid))); |
|---|
| 139 | $table->add(null, html::label('ff_gid' . $gid, Q($group['name']))); |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | $hiddenfields = new html_hiddenfield(array('name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC))); |
|---|
| 143 | $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID'])); |
|---|
| 144 | |
|---|
| 145 | $form_start = $RCMAIL->output->request_form(array( |
|---|
| 146 | 'name' => "form", 'method' => "post", |
|---|
| 147 | 'task' => $RCMAIL->task, 'action' => 'save', |
|---|
| 148 | 'request' => 'save.'.intval($contact_id), |
|---|
| 149 | 'noclose' => true), $hiddenfields->show()); |
|---|
| 150 | $form_end = '</form>'; |
|---|
| 151 | |
|---|
| 152 | $RCMAIL->output->add_gui_object('editform', 'form'); |
|---|
| 153 | |
|---|
| 154 | return $form_start . $table->show() . $form_end; |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | //$OUTPUT->framed = $_framed; |
|---|
| 159 | $OUTPUT->add_handler('contacthead', 'rcmail_contact_head'); |
|---|
| 160 | $OUTPUT->add_handler('contactdetails', 'rcmail_contact_details'); |
|---|
| 161 | |
|---|
| 162 | $OUTPUT->send('contact'); |
|---|