Thomas Bruederli
2014-03-21 d2215764898919f1ea3b461fb08ac430db4340a4
program/steps/addressbook/show.inc
@@ -5,8 +5,11 @@
 | program/steps/addressbook/show.inc                                    |
 |                                                                       |
 | This file is part of the Roundcube Webmail client                     |
 | Copyright (C) 2005-2009, The Roundcube Dev Team                       |
 | Licensed under the GNU GPL                                            |
 | Copyright (C) 2005-2013, The Roundcube Dev Team                       |
 |                                                                       |
 | Licensed under the GNU General Public License version 3 or            |
 | any later version with exceptions for skins & plugins.                |
 | See the README file for a full license statement.                     |
 |                                                                       |
 | PURPOSE:                                                              |
 |   Show contact details                                                |
@@ -14,15 +17,12 @@
 +-----------------------------------------------------------------------+
 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
 +-----------------------------------------------------------------------+
 $Id$
*/
// Get contact ID and source ID from request
$cids   = rcmail_get_cids();
$source = key($cids);
$cid    = array_shift($cids[$source]);
$cid    = $cids ? array_shift($cids[$source]) : null;
// Initialize addressbook source
$CONTACTS  = rcmail_contact_source($source, true);
@@ -30,39 +30,22 @@
// read contact record
if ($cid && ($record = $CONTACTS->get_record($cid, true))) {
    $OUTPUT->set_env('readonly', $CONTACTS->readonly || $record['readonly']);
    $OUTPUT->set_env('cid', $record['ID']);
    $OUTPUT->set_env('compose_extwin', $RCMAIL->config->get('compose_extwin',false));
}
// get address book name (for display)
if ($_SESSION['addressbooks_count'] > 1) {
    $name = $CONTACTS->get_name();
    if (!$name && $source == 0) {
        $name = rcube_label('personaladrbook');
    }
    $OUTPUT->set_env('sourcename', $name);
}
rcmail_set_sourcename($CONTACTS);
// return raw photo of the given contact
if ($RCMAIL->action == 'photo') {
    if (($file_id = get_input_value('_photo', RCUBE_INPUT_GPC)) && ($tempfile = $_SESSION['contacts']['files'][$file_id])) {
        $tempfile = $RCMAIL->plugins->exec_hook('attachment_display', $tempfile);
        if ($tempfile['status']) {
            if ($tempfile['data'])
                $data = $tempfile['data'];
            else if ($tempfile['path'])
                $data = file_get_contents($tempfile['path']);
        }
    }
    else if ($record['photo']) {
        $data = is_array($record['photo']) ? $record['photo'][0] : $record['photo'];
        if (!preg_match('![^a-z0-9/=+-]!i', $data))
            $data = base64_decode($data, true);
    }
$OUTPUT->add_handlers(array(
    'contacthead'    => 'rcmail_contact_head',
    'contactdetails' => 'rcmail_contact_details',
    'contactphoto'   => 'rcmail_contact_photo',
));
    header('Content-Type: ' . rc_image_content_type($data));
    echo $data ? $data : file_get_contents('program/blank.gif');
    exit;
}
$OUTPUT->send('contact');
function rcmail_contact_head($attrib)
@@ -71,11 +54,9 @@
    // check if we have a valid result
    if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) {
        $RCMAIL->output->show_message('contactnotfound');
        $RCMAIL->output->show_message('contactnotfound', 'error');
        return false;
    }
    $microformats = array('name' => 'fn', 'email' => 'email');
    $form = array(
        'head' => array(  // section 'head' is magic!
@@ -100,7 +81,6 @@
    // check if we have a valid result
    if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) {
        //$RCMAIL->output->show_message('contactnotfound');
        return false;
    }
@@ -108,7 +88,7 @@
    $form = array(
        'contact' => array(
            'name'    => rcube_label('contactproperties'),
            'name'    => $RCMAIL->gettext('properties'),
            'content' => array(
              'email' => array('size' => $i_size, 'render_func' => 'rcmail_render_email_value'),
              'phone' => array('size' => $i_size),
@@ -118,7 +98,7 @@
            ),
        ),
        'personal' => array(
            'name'    => rcube_label('personalinfo'),
            'name'    => $RCMAIL->gettext('personalinfo'),
            'content' => array(
                'gender' => array('size' => $i_size),
                'maidenname' => array('size' => $i_size),
@@ -130,19 +110,19 @@
            ),
        ),
    );
    if (isset($CONTACT_COLTYPES['notes'])) {
        $form['notes'] = array(
            'name'    => rcube_label('notes'),
            'name'    => $RCMAIL->gettext('notes'),
            'content' => array(
                'notes' => array('type' => 'textarea', 'label' => false),
            ),
        );
    }
    if ($CONTACTS->groups) {
        $form['groups'] = array(
            'name'    => rcube_label('groups'),
            'name'    => $RCMAIL->gettext('groups'),
            'content' => rcmail_contact_record_groups($record['ID']),
        );
    }
@@ -151,25 +131,27 @@
}
function rcmail_render_email_value($email, $col)
function rcmail_render_email_value($email)
{
    global $RCMAIL;
    return html::a(array(
        'href' => 'mailto:' . $email,
        'onclick' => sprintf("return %s.command('compose','%s',this)", JS_OBJECT_NAME, JQ($email)),
        'title' => rcube_label('composeto'),
        'onclick' => sprintf("return %s.command('compose','%s',this)", rcmail_output::JS_OBJECT_NAME, rcube::JQ($email)),
        'title' => $RCMAIL->gettext('composeto'),
        'class' => 'email',
    ), Q($email));
    ), rcube::Q($email));
}
function rcmail_render_url_value($url, $col)
function rcmail_render_url_value($url)
{
    $prefix = preg_match('!^(http|ftp)s?://!', $url) ? '' : 'http://';
    return html::a(array(
        'href' => $prefix . $url,
        'target' => '_blank',
        'class' => 'url',
    ), Q($url));
    ), rcube::Q($url));
}
@@ -183,9 +165,8 @@
        return '';
    }
    $table = new html_table(array('cols' => 2, 'cellspacing' => 0, 'border' => 0));
    $members = $CONTACTS->get_record_groups($contact_id);
    $members  = $CONTACTS->get_record_groups($contact_id);
    $table    = new html_table(array('cols' => 2, 'cellspacing' => 0, 'border' => 0));
    $checkbox = new html_checkbox(array('name' => '_gid[]',
        'class' => 'groupmember', 'disabled' => $CONTACTS->readonly));
@@ -193,11 +174,11 @@
        $gid = $group['ID'];
        $table->add(null, $checkbox->show($members[$gid] ? $gid : null,
            array('value' => $gid, 'id' => 'ff_gid' . $gid)));
        $table->add(null, html::label('ff_gid' . $gid, Q($group['name'])));
        $table->add(null, html::label('ff_gid' . $gid, rcube::Q($group['name'])));
    }
    $hiddenfields = new html_hiddenfield(array('name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC)));
    $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID']));
    $hiddenfields = new html_hiddenfield(array('name' => '_source', 'value' => rcube_utils::get_input_value('_source', rcube_utils::INPUT_GPC)));
    $hiddenfields->add(array('name' => '_cid', 'value' => $contact_id));
    $form_start = $RCMAIL->output->request_form(array(
        'name' => "form", 'method' => "post",
@@ -207,15 +188,7 @@
    $form_end = '</form>';
    $RCMAIL->output->add_gui_object('editform', 'form');
    $RCMAIL->output->add_label('addingmember', 'removingmember');
    return $form_start . $table->show() . $form_end;
    return $form_start . html::tag('fieldset', 'contactfieldgroup contactgroups', $table->show()) . $form_end;
}
$OUTPUT->add_handlers(array(
    'contacthead'    => 'rcmail_contact_head',
    'contactdetails' => 'rcmail_contact_details',
    'contactphoto'   => 'rcmail_contact_photo',
));
$OUTPUT->send('contact');