summaryrefslogtreecommitdiff
path: root/program/steps
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2015-02-17 11:54:04 +0100
committerAleksander Machniak <alec@alec.pl>2015-02-17 11:54:04 +0100
commitf7af22c7801afcc248b004c84d0f1fb45e1a1632 (patch)
tree54daab5a589f7f462aa82a608acd7b30a6178e85 /program/steps
parentae73c26f29aa230ba5ae3d86ef6d0c7886b7e657 (diff)
Add possibility to print contact information (of a single contact)
Diffstat (limited to 'program/steps')
-rw-r--r--program/steps/addressbook/func.inc75
-rw-r--r--program/steps/addressbook/print.inc138
-rw-r--r--program/steps/addressbook/show.inc15
3 files changed, 199 insertions, 29 deletions
diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc
index c40b517dc..594c2a695 100644
--- a/program/steps/addressbook/func.inc
+++ b/program/steps/addressbook/func.inc
@@ -518,12 +518,13 @@ function rcmail_contact_form($form, $record, $attrib = null)
$plugin = $RCMAIL->plugins->exec_hook('contact_form', array(
'form' => $form, 'record' => $record));
- $form = $plugin['form'];
- $record = $plugin['record'];
- $edit_mode = $RCMAIL->action != 'show';
+ $form = $plugin['form'];
+ $record = $plugin['record'];
+ $edit_mode = $RCMAIL->action != 'show' && $RCMAIL->action != 'print';
$del_button = $attrib['deleteicon'] ? html::img(array('src' => $RCMAIL->output->get_skin_file($attrib['deleteicon']), 'alt' => $RCMAIL->gettext('delete'))) : $RCMAIL->gettext('delete');
+ $out = '';
+
unset($attrib['deleteicon']);
- $out = '';
// get default coltypes
$coltypes = $GLOBALS['CONTACT_COLTYPES'];
@@ -544,8 +545,9 @@ function rcmail_contact_form($form, $record, $attrib = null)
foreach ($form as $section => $fieldset) {
// skip empty sections
- if (empty($fieldset['content']))
+ if (empty($fieldset['content'])) {
continue;
+ }
$select_add = new html_select(array('class' => 'addfieldmenu', 'rel' => $section));
$select_add->add($RCMAIL->gettext('addfield'), '');
@@ -555,18 +557,20 @@ function rcmail_contact_form($form, $record, $attrib = null)
$content = '';
// unset display name if it is composed from name parts
- if ($record['name'] == rcube_addressbook::compose_display_name(array('name' => '') + (array)$record))
- unset($record['name']);
+ if ($record['name'] == rcube_addressbook::compose_display_name(array('name' => '') + (array)$record)) {
+ unset($record['name']);
+ }
// group fields
$field_blocks = array(
- 'names' => array('prefix','firstname','middlename','surname','suffix'),
- 'displayname' => array('name'),
- 'nickname' => array('nickname'),
+ 'names' => array('prefix','firstname','middlename','surname','suffix'),
+ 'displayname' => array('name'),
+ 'nickname' => array('nickname'),
'organization' => array('organization'),
- 'department' => array('department'),
- 'jobtitle' => array('jobtitle'),
+ 'department' => array('department'),
+ 'jobtitle' => array('jobtitle'),
);
+
foreach ($field_blocks as $blockname => $colnames) {
$fields = '';
foreach ($colnames as $col) {
@@ -574,11 +578,16 @@ function rcmail_contact_form($form, $record, $attrib = null)
if (!$coltypes[$col])
continue;
+ // skip cols not listed in the form definition
+ if (is_array($fieldset['content']) && !in_array($col, array_keys($fieldset['content']))) {
+ continue;
+ }
+
// only string values are expected here
if (is_array($record[$col]))
$record[$col] = join(' ', $record[$col]);
- if ($RCMAIL->action == 'show') {
+ if (!$edit_mode) {
if (!empty($record[$col]))
$fields .= html::span('namefield ' . $col, rcube::Q($record[$col])) . " ";
}
@@ -611,11 +620,15 @@ function rcmail_contact_form($form, $record, $attrib = null)
$fullkey = $col.':'.$subtype;
// skip cols unknown to the backend
- if (!$coltypes[$field])
+ if (!$coltypes[$field] && empty($colprop['value'])) {
continue;
+ }
// merge colprop with global coltype configuration
- $colprop += $coltypes[$field];
+ if ($coltypes[$field]) {
+ $colprop += $coltypes[$field];
+ }
+
$label = isset($colprop['label']) ? $colprop['label'] : $RCMAIL->gettext($col);
// prepare subtype selector in edit mode
@@ -624,8 +637,9 @@ function rcmail_contact_form($form, $record, $attrib = null)
$select_subtype = new html_select(array('name' => '_subtype_'.$col.'[]', 'class' => 'contactselectsubtype', 'title' => $colprop['label'] . ' ' . $RCMAIL->gettext('type')));
$select_subtype->add($subtype_names, $colprop['subtypes']);
}
- else
+ else {
$select_subtype = null;
+ }
if (!empty($colprop['value'])) {
$values = (array)$colprop['value'];
@@ -729,12 +743,21 @@ function rcmail_contact_form($form, $record, $attrib = null)
// display row with label
if ($label) {
+ if ($RCMAIL->action == 'print') {
+ $_label = rcube::Q($colprop['label'] . ($label != $colprop['label'] ? ' (' . $label . ')' : ''));
+ }
+ else {
+ $_label = $select_subtype ? $select_subtype->show($subtype) : html::label($colprop['id'], rcube::Q($label));
+ }
+
$rows .= html::div('row',
- html::div('contactfieldlabel label', $select_subtype ? $select_subtype->show($subtype) : html::label($colprop['id'], rcube::Q($label))) .
+ html::div('contactfieldlabel label', $_label) .
html::div('contactfieldcontent '.$colprop['type'], $val));
}
- else // row without label
+ // row without label
+ else {
$rows .= html::div('row', html::div('contactfield', $val));
+ }
}
// add option to the add-field menu
@@ -745,9 +768,13 @@ function rcmail_contact_form($form, $record, $attrib = null)
// wrap rows in fieldgroup container
if ($rows) {
- $content .= html::tag('fieldset', array('class' => 'contactfieldgroup ' . ($colprop['subtypes'] ? 'contactfieldgroupmulti ' : '') . 'contactcontroller' . $col, 'style' => ($rows ? null : 'display:none')),
- ($colprop['subtypes'] ? html::tag('legend', null, rcube::Q($colprop['label'])) : ' ') .
- $rows);
+ $c_class = 'contactfieldgroup ' . ($colprop['subtypes'] ? 'contactfieldgroupmulti ' : '') . 'contactcontroller' . $col;
+ $with_label = $colprop['subtypes'] && $RCMAIL->action != 'print';
+ $content .= html::tag(
+ 'fieldset',
+ array('class' => $c_class, 'style' => ($rows ? null : 'display:none')),
+ ($with_label ? html::tag('legend', null, rcube::Q($colprop['label'])) : ' ') . $rows
+ );
}
}
@@ -769,9 +796,9 @@ function rcmail_contact_form($form, $record, $attrib = null)
}
if ($edit_mode) {
- $RCMAIL->output->set_env('coltypes', $coltypes + $coltype_labels);
- $RCMAIL->output->set_env('delbutton', $del_button);
- $RCMAIL->output->add_label('delete');
+ $RCMAIL->output->set_env('coltypes', $coltypes + $coltype_labels);
+ $RCMAIL->output->set_env('delbutton', $del_button);
+ $RCMAIL->output->add_label('delete');
}
return $out;
diff --git a/program/steps/addressbook/print.inc b/program/steps/addressbook/print.inc
new file mode 100644
index 000000000..c9460d44f
--- /dev/null
+++ b/program/steps/addressbook/print.inc
@@ -0,0 +1,138 @@
+<?php
+
+/*
+ +-----------------------------------------------------------------------+
+ | program/steps/addressbook/print.inc |
+ | |
+ | This file is part of the Roundcube Webmail client |
+ | Copyright (C) 2005-2015, The Roundcube Dev Team |
+ | Copyright (C) 2011-2015, Kolab Systems AG |
+ | |
+ | 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: |
+ | Print contact details |
+ | |
+ +-----------------------------------------------------------------------+
+ | Author: Thomas Bruederli <roundcube@gmail.com> |
+ | Author: Aleksander Machniak <machniak@kolabsys.com> |
+ +-----------------------------------------------------------------------+
+*/
+
+// Get contact ID and source ID from request
+$cids = rcmail_get_cids();
+$source = key($cids);
+$cid = $cids ? array_shift($cids[$source]) : null;
+
+// Initialize addressbook source
+$CONTACTS = rcmail_contact_source($source, true);
+$SOURCE_ID = $source;
+
+// read contact record
+if ($cid && $CONTACTS) {
+ $record = $CONTACTS->get_record($cid, true);
+}
+
+$OUTPUT->add_handlers(array(
+ 'contacthead' => 'rcmail_contact_head',
+ 'contactdetails' => 'rcmail_contact_details',
+ 'contactphoto' => 'rcmail_contact_photo',
+));
+
+$OUTPUT->send('contactprint');
+
+
+
+function rcmail_contact_head($attrib)
+{
+ global $CONTACTS, $RCMAIL;
+
+ // check if we have a valid result
+ if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) {
+ $RCMAIL->output->show_message('contactnotfound', 'error');
+ return false;
+ }
+
+ $form = array(
+ 'head' => array( // section 'head' is magic!
+ 'name' => $RCMAIL->gettext('contactnameandorg'),
+ 'content' => array(
+ 'prefix' => array(),
+ 'name' => array(),
+ 'firstname' => array(),
+ 'middlename' => array(),
+ 'surname' => array(),
+ 'suffix' => array(),
+ ),
+ ),
+ );
+
+ unset($attrib['name']);
+ return rcmail_contact_form($form, $record, $attrib);
+}
+
+
+function rcmail_contact_details($attrib)
+{
+ global $CONTACTS, $RCMAIL, $CONTACT_COLTYPES;
+
+ // check if we have a valid result
+ if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) {
+ return false;
+ }
+
+ $i_size = !empty($attrib['size']) ? $attrib['size'] : 40;
+
+ $form = array(
+ 'contact' => array(
+ 'name' => $RCMAIL->gettext('properties'),
+ 'content' => array(
+ 'organization' => array(),
+ 'department' => array(),
+ 'jobtitle' => array(),
+ 'email' => array(),
+ 'phone' => array(),
+ 'address' => array(),
+ 'website' => array(),
+ 'im' => array(),
+ 'groups' => array('value' => 'sdfsdfs', 'label' => $RCMAIL->gettext('groups')),
+ ),
+ ),
+ 'personal' => array(
+ 'name' => $RCMAIL->gettext('personalinfo'),
+ 'content' => array(
+ 'nickname' => array(),
+ 'gender' => array(),
+ 'maidenname' => array(),
+ 'birthday' => array(),
+ 'anniversary' => array(),
+ 'manager' => array(),
+ 'assistant' => array(),
+ 'spouse' => array(),
+ ),
+ ),
+ );
+
+ if (isset($CONTACT_COLTYPES['notes'])) {
+ $form['notes'] = array(
+ 'name' => $RCMAIL->gettext('notes'),
+ 'content' => array(
+ 'notes' => array('type' => 'textarea', 'label' => false),
+ ),
+ );
+ }
+
+ if ($CONTACTS->groups) {
+ $groups = $CONTACTS->get_record_groups($record['ID']);
+ if (!empty($groups)) {
+ $form['contact']['content']['groups'] = array(
+ 'value' => rcube::Q(implode(', ', $groups)),
+ 'label' => $RCMAIL->gettext('groups')
+ );
+ }
+ }
+
+ return rcmail_contact_form($form, $record);
+}
diff --git a/program/steps/addressbook/show.inc b/program/steps/addressbook/show.inc
index 5835ce7e5..d1bc8594d 100644
--- a/program/steps/addressbook/show.inc
+++ b/program/steps/addressbook/show.inc
@@ -66,11 +66,16 @@ function rcmail_contact_head($attrib)
'head' => array( // section 'head' is magic!
'name' => $RCMAIL->gettext('contactnameandorg'),
'content' => array(
- 'prefix' => array('type' => 'text'),
- 'firstname' => array('type' => 'text'),
- 'middlename' => array('type' => 'text'),
- 'surname' => array('type' => 'text'),
- 'suffix' => array('type' => 'text'),
+ 'prefix' => array('type' => 'text'),
+ 'firstname' => array('type' => 'text'),
+ 'middlename' => array('type' => 'text'),
+ 'surname' => array('type' => 'text'),
+ 'suffix' => array('type' => 'text'),
+ 'name' => array('type' => 'text'),
+ 'nickname' => array('type' => 'text'),
+ 'organization' => array('type' => 'text'),
+ 'department' => array('type' => 'text'),
+ 'jobtitle' => array('type' => 'text'),
),
),
);