Page MenuHomePhorge

No OneTemporary

Size
103 KB
Referenced Files
None
Subscribers
None
diff --git a/plugins/kolab_addressbook/kolab_addressbook.js b/plugins/kolab_addressbook/kolab_addressbook.js
index b9402501..fb280b1d 100644
--- a/plugins/kolab_addressbook/kolab_addressbook.js
+++ b/plugins/kolab_addressbook/kolab_addressbook.js
@@ -1,440 +1,620 @@
/**
* Client script for the Kolab address book plugin
*
* @author Aleksander Machniak <machniak@kolabsys.com>
* @author Thomas Bruederli <bruederli@kolabsys.com>
*
* @licstart The following is the entire license notice for the
* JavaScript code in this file.
*
* Copyright (C) 2011-2014, Kolab Systems AG <contact@kolabsys.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @licend The above is the entire license notice
* for the JavaScript code in this file.
*/
if (window.rcmail) {
rcmail.addEventListener('init', function() {
rcmail.set_book_actions();
if (rcmail.gui_objects.editform && rcmail.env.action.match(/^plugin\.book/)) {
rcmail.enable_command('book-save', true);
}
// contextmenu
kolab_addressbook_contextmenu();
// append search form for address books
if (rcmail.gui_objects.folderlist) {
var container = $(rcmail.gui_objects.folderlist);
$('<div class="listsearchbox" style="display:none">' +
'<div class="searchbox" role="search" aria-labelledby="aria-labelfoldersearchform" aria-controls="' + rcmail.gui_objects.folderlist.id + '">' +
'<h3 id="aria-label-labelfoldersearchform" class="voice">' + rcmail.gettext('foldersearchform', 'kolab_addressbook') + '" /></h3>' +
'<label for="addressbooksearch" class="voice">' + rcmail.gettext('searchterms', 'kolab_addressbook') + '</label>' +
'<input type="text" name="q" id="addressbooksearch" placeholder="' + rcmail.gettext('findaddressbooks', 'kolab_addressbook') + '" />' +
'<a class="iconbutton searchicon"></a>' +
'<a href="#reset" onclick="return rcmail.command(\'reset-listsearch\',null,this,event)" id="directorylistsearch-reset" class="iconbutton reset" title="' + rcmail.gettext('resetsearch') + '">' +
rcmail.gettext('resetsearch') + '</a>' +
'</div>' +
'</div>')
.insertBefore(container.parent());
$('<a href="#search" class="iconbutton search" title="' + rcmail.gettext('findaddressbooks', 'kolab_addressbook') + '" tabindex="0">' +
rcmail.gettext('findaddressbooks', 'kolab_addressbook') + '</a>')
.appendTo('#directorylistbox h2.boxtitle')
.click(function(e){
var title = $('#directorylistbox .boxtitle'),
box = $('#directorylistbox .listsearchbox'),
dir = box.is(':visible') ? -1 : 1;
box.slideToggle({
duration: 160,
progress: function(animation, progress) {
if (dir < 0) progress = 1 - progress;
$('#directorylistbox .scroller').css('top', (title.outerHeight() + 34 * progress) + 'px');
},
complete: function() {
box.toggleClass('expanded');
if (box.is(':visible')) {
box.find('input[type=text]').focus();
}
else {
$('#directorylistsearch-reset').click();
}
}
});
});
// remove event handlers set by the regular treelist widget
rcmail.treelist.container.off('click mousedown focusin focusout');
// re-initialize folderlist widget
// copy form app.js with additional parameters
var widget_class = window.kolab_folderlist || rcube_treelist_widget;
rcmail.treelist = new widget_class(rcmail.gui_objects.folderlist, {
selectable: true,
id_prefix: 'rcmli',
id_encode: rcmail.html_identifier_encode,
id_decode: rcmail.html_identifier_decode,
searchbox: '#addressbooksearch',
search_action: 'plugin.book-search',
search_sources: [ 'folders', 'users' ],
search_title: rcmail.gettext('listsearchresults','kolab_addressbook'),
check_droptarget: function(node) { return !node.virtual && rcmail.check_droptarget(node.id) }
});
rcmail.treelist
.addEventListener('collapse', function(node) { rcmail.folder_collapsed(node) })
.addEventListener('expand', function(node) { rcmail.folder_collapsed(node) })
.addEventListener('select', function(node) { rcmail.triggerEvent('selectfolder', { folder:node.id, prefix:'rcmli' }) })
.addEventListener('subscribe', function(node) {
var source;
if ((source = rcmail.env.address_sources[node.id])) {
source.subscribed = node.subscribed || false;
rcmail.http_post('plugin.book-subscribe', { _source:node.id, _permanent:source.subscribed?1:0 });
}
})
.addEventListener('remove', function(node) {
if (rcmail.env.address_sources[node.id]) {
rcmail.book_remove(node.id);
}
})
.addEventListener('insert-item', function(data) {
// register new address source
rcmail.env.address_sources[data.id] = rcmail.env.contactfolders[data.id] = data.data;
// subscribe folder and load groups to add them to the list
if (!data.data.virtual)
rcmail.http_post('plugin.book-subscribe', { _source:data.id, _permanent:data.data.subscribed?1:0, _groups:1 });
})
.addEventListener('search-complete', function(data) {
if (data.length)
rcmail.display_message(rcmail.gettext('nraddressbooksfound','kolab_addressbook').replace('$nr', data.length), 'voice');
else
rcmail.display_message(rcmail.gettext('noaddressbooksfound','kolab_addressbook'), 'info');
});
}
+
+ // append button to show contact audit trail
+ if (rcmail.env.action == 'show' && rcmail.env.kolab_audit_trail && rcmail.env.cid) {
+ $('<a href="#history" class="btn-contact-history active" role="button" tabindex="0">' + rcmail.get_label('kolab_addressbook.showhistory') + '</a>')
+ .click(function(e) {
+ var rc = rcmail.is_framed() && parent.rcmail.contact_history_dialog ? parent.rcmail : rcmail;
+ rc.contact_history_dialog();
+ return false;
+ })
+ .appendTo($('<div>').addClass('formbuttons-secondary-kolab').appendTo('.formbuttons'));
+ }
});
rcmail.addEventListener('listupdate', function() {
rcmail.set_book_actions();
});
// wait until rcmail.contact_list is ready and subscribe to 'select' events
setTimeout(function() {
rcmail.contact_list && rcmail.contact_list.addEventListener('select', function(list) {
var selected = list.selection.length,
source = rcmail.env.source ? rcmail.env.address_sources[rcmail.env.source] : null;
if (selected && source.kolab) {
- console.log('select', source.rights)
rcmail.enable_command('delete', 'move', selected && source.rights.indexOf('t') >= 0);
}
});
}, 100);
}
// (De-)activates address book management commands
rcube_webmail.prototype.set_book_actions = function()
{
var source = !this.env.group ? this.env.source : null,
- sources = this.env.address_sources;
+ sources = this.env.address_sources || {};
var props = source && sources[source] && sources[source].kolab ? sources[source] : { removable: false, rights: '' }
this.enable_command('book-create', true);
this.enable_command('book-edit', props.rights.indexOf('a') >= 0);
this.enable_command('book-delete', props.rights.indexOf('x') >= 0 || props.rights.indexOf('a') >= 0);
this.enable_command('book-remove', props.removable);
this.enable_command('book-showurl', !!props.carddavurl);
};
rcube_webmail.prototype.book_create = function()
{
this.book_show_contentframe('create');
};
rcube_webmail.prototype.book_edit = function()
{
this.book_show_contentframe('edit');
};
rcube_webmail.prototype.book_remove = function(id)
{
if (!id) id = this.env.source;
if (id != '' && rcmail.env.address_sources[id]) {
rcmail.book_delete_done(id, true);
rcmail.http_post('plugin.book-subscribe', { _source:id, _permanent:0, _recursive:1 });
}
};
rcube_webmail.prototype.book_delete = function()
{
if (this.env.source != '' && confirm(this.get_label('kolab_addressbook.bookdeleteconfirm'))) {
var lock = this.set_busy(true, 'kolab_addressbook.bookdeleting');
this.http_request('plugin.book', '_act=delete&_source='+urlencode(this.book_realname()), lock);
}
};
rcube_webmail.prototype.book_showurl = function()
{
var source = this.env.source ? this.env.address_sources[this.env.source] : null;
if (source && source.carddavurl) {
$('div.showurldialog:ui-dialog').dialog('close');
var $dialog = $('<div>').addClass('showurldialog').append('<p>'+rcmail.gettext('carddavurldescription', 'kolab_addressbook')+'</p>'),
textbox = $('<textarea>').addClass('urlbox').css('width', '100%').attr('rows', 2).appendTo($dialog);
$dialog.dialog({
resizable: true,
closeOnEscape: true,
title: rcmail.gettext('bookshowurl', 'kolab_addressbook'),
close: function() {
$dialog.dialog("destroy").remove();
},
width: 520
}).show();
textbox.val(source.carddavurl).select();
}
};
// displays page with book edit/create form
rcube_webmail.prototype.book_show_contentframe = function(action, framed)
{
var add_url = '', target = window;
// unselect contact
this.contact_list.clear_selection();
this.enable_command('edit', 'delete', 'compose', false);
if (this.env.contentframe && window.frames && window.frames[this.env.contentframe]) {
add_url = '&_framed=1';
target = window.frames[this.env.contentframe];
this.show_contentframe(true);
}
else if (framed)
return false;
if (action) {
this.lock_frame();
this.location_href(this.env.comm_path+'&_action=plugin.book&_act='+action
+'&_source='+urlencode(this.book_realname())
+add_url, target);
}
return true;
};
// submits book create/update form
rcube_webmail.prototype.book_save = function()
{
var form = this.gui_objects.editform,
input = $("input[name='_name']", form)
if (input.length && input.val() == '') {
alert(this.get_label('kolab_addressbook.nobooknamewarning'));
input.focus();
return;
}
input = this.display_message(this.get_label('kolab_addressbook.booksaving'), 'loading');
$('<input type="hidden" name="_unlock" />').val(input).appendTo(form);
form.submit();
};
// action executed after book delete
rcube_webmail.prototype.book_delete_done = function(id, recur)
{
var n, groups = this.env.contactgroups,
sources = this.env.address_sources,
olddata = sources[id];
this.treelist.remove(id);
for (n in groups)
if (groups[n].source == id) {
delete this.env.contactgroups[n];
delete this.env.contactfolders[n];
}
delete this.env.address_sources[id];
delete this.env.contactfolders[id];
if (recur)
return;
this.enable_command('group-create', 'book-edit', 'book-delete', false);
// remove subfolders
olddata.realname += this.env.delimiter;
for (n in sources)
if (sources[n].realname && sources[n].realname.indexOf(olddata.realname) == 0)
this.book_delete_done(n, true);
};
// action executed after book create/update
rcube_webmail.prototype.book_update = function(data, old)
{
var classes = ['addressbook'],
content = $('<div class="subscribed">').append(
$('<a>').html(data.listname).attr({
href: this.url('', {_source: data.id}),
id: 'kabt:' + data.id,
rel: data.id,
onclick: "return rcmail.command('list', '" + data.id + "', this)"
}),
$('<span>').attr({
'class': 'subscribed',
role: 'checkbox',
'aria-checked': true,
title: this.gettext('kolab_addressbook.foldersubscribe')
})
);
this.show_contentframe(false);
// set row attributes
if (data.readonly)
classes.push('readonly');
if (data.group)
classes.push(data.group);
// update (remove old row)
if (old) {
// is the folder subscribed?
if (!data.subscribed) {
content.removeClass('subscribed').find('span').attr('aria-checked', false);
}
this.treelist.update(old, {id: data.id, html: content, classes: classes, parent: (old != data.id ? data.parent : null)}, data.group || true);
}
else {
this.treelist.insert({id: data.id, html: content, classes: classes, childlistclass: 'groups'}, data.parent, data.group || true);
}
this.env.contactfolders[data.id] = this.env.address_sources[data.id] = data;
// updated currently selected book
if (this.env.source != '' && this.env.source == old) {
this.treelist.select(data.id);
this.env.source = data.id;
}
// update contextmenu
kolab_addressbook_contextmenu();
};
// returns real IMAP folder name
rcube_webmail.prototype.book_realname = function()
{
var source = this.env.source, sources = this.env.address_sources;
return source != '' && sources[source] && sources[source].realname ? sources[source].realname : '';
};
+// open dialog to show the current contact's changelog
+rcube_webmail.prototype.contact_history_dialog = function()
+{
+ var $dialog, rec = { cid: this.get_single_cid(), source: rcmail.env.source },
+ source = this.env.address_sources ? this.env.address_sources[rcmail.env.source] || {} : {};
+
+ if (!rec.cid || !window.libkolab_audittrail || !source.audittrail) {
+ return false;
+ }
+
+ // render dialog
+ $dialog = libkolab_audittrail.object_history_dialog({
+ module: 'kolab_addressbooks',
+ container: '#contacthistory',
+ title: rcmail.gettext('objectchangelog','kolab_addressbook'),
+
+ // callback function for list actions
+ listfunc: function(action, rev) {
+ var rec = $dialog.data('rec');
+ console.log(action, rev, rec)
+ //rcmail.loading_lock = rcmail.set_busy(true, 'loading', this.loading_lock);
+ //rcmail.http_post('action', { _do: action, _data: { uid: rec.uid, list:rec.list, rev: rev } }, saving_lock);
+ },
+
+ // callback function for comparing two object revisions
+ comparefunc: function(rev1, rev2) {
+ var rec = $dialog.data('rec');
+ rcmail.kab_loading_lock = rcmail.set_busy(true, 'loading', rcmail.kab_loading_lock);
+ rcmail.http_post('plugin.contact-diff', { cid: rec.cid, source: rec.source, rev1: rev1, rev2: rev2 }, rcmail.kab_loading_lock);
+ }
+ });
+
+ $dialog.data('rec', rec);
+
+ // fetch changelog data
+ this.kab_loading_lock = rcmail.set_busy(true, 'loading', this.kab_loading_lock);
+ this.http_post('plugin.contact-changelog', rec, this.kab_loading_lock);
+};
+
+// callback for displaying a contact's change history
+rcube_webmail.prototype.contact_render_changelog = function(data)
+{
+ var $dialog = $('#contacthistory'),
+ rec = $dialog.data('rec');
+
+ if (data === false || !data.length || !event) {
+ // display 'unavailable' message
+ $('<div class="notfound-message note-dialog-message warning">' + rcmail.gettext('objectchangelognotavailable','kolab_addressbook') + '</div>')
+ .insertBefore($dialog.find('.changelog-table').hide());
+ return;
+ }
+
+ source = this.env.address_sources[rec.source] || {}
+ // source.editable = !source.readonly
+
+ data.module = 'kolab_addressbook';
+ libkolab_audittrail.render_changelog(data, rec, source);
+
+ // set dialog size according to content
+ // dialog_resize($dialog.get(0), $dialog.height(), 600);
+};
+
+// callback for rendering a diff view of two contact revisions
+rcube_webmail.prototype.contact_show_diff = function(data)
+{
+ var $dialog = $('#contactdiff'),
+ rec = {}, namediff = { 'old': '', 'new': '', 'set': false };
+
+ if (this.contact_list && this.contact_list.data[data.cid]) {
+ rec = this.contact_list.data[data.cid];
+ }
+
+ $dialog.find('div.form-section, h2.contact-names-new').hide().data('set', false);
+ $dialog.find('div.form-section.clone').remove();
+
+ var name_props = ['prefix','firstname','middlename','surname','suffix'];
+
+ // Quote HTML entities
+ var Q = function(str){
+ return String(str).replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
+ };
+
+ // show each property change
+ $.each(data.changes, function(i, change) {
+ var prop = change.property, r2, html = !!change.ishtml,
+ row = $('div.contact-' + prop, $dialog).first();
+
+ // special case: names
+ if ($.inArray(prop, name_props) >= 0) {
+ namediff['old'] += change['old'] + ' ';
+ namediff['new'] += change['new'] + ' ';
+ namediff['set'] = true;
+ return true;
+ }
+
+ // no display container for this property
+ if (!row.length) {
+ return true;
+ }
+
+ // clone row if already exists
+ if (row.data('set')) {
+ r2 = row.clone().addClass('clone').insertAfter(row);
+ row = r2;
+ }
+
+ // render photo as image with data: url
+ if (prop == 'photo') {
+ row.children('.diff-img-old').attr('src', change['old'] ? 'data:' + (change['old'].mimetype || 'image/gif') + ';base64,' + change['old'].base64 : 'data:image/gif;base64,R0lGODlhAQABAPAAAOjq6gAAACH/C1hNUCBEYXRhWE1QAT8AIfkEBQAAAAAsAAAAAAEAAQAAAgJEAQA7');
+ row.children('.diff-img-new').attr('src', change['new'] ? 'data:' + (change['new'].mimetype || 'image/gif') + ';base64,' + change['new'].base64 : 'data:image/gif;base64,R0lGODlhAQABAPAAAOjq6gAAACH/C1hNUCBEYXRhWE1QAT8AIfkEBQAAAAAsAAAAAAEAAQAAAgJEAQA7');
+ }
+ else if (change.diff_) {
+ row.children('.diff-text-diff').html(change.diff_);
+ row.children('.diff-text-old, .diff-text-new').hide();
+ }
+ else {
+ if (!html) {
+ // escape HTML characters
+ change.old_ = Q(change.old_ || change['old'] || '--')
+ change.new_ = Q(change.new_ || change['new'] || '--')
+ }
+ row.children('.diff-text-old').html(change.old_ || change['old'] || '--').show();
+ row.children('.diff-text-new').html(change.new_ || change['new'] || '--').show();
+ }
+
+ // display index number
+ if (typeof change.index != 'undefined') {
+ row.find('.index').html('(' + change.index + ')');
+ }
+
+ row.show().data('set', true);
+ });
+
+ // always show name
+ if (namediff.set) {
+ $('.contact-names', $dialog).html($.trim(namediff['old'] || '--')).addClass('diff-text-old').show();
+ $('.contact-names-new', $dialog).html($.trim(namediff['new'] || '--')).show();
+ }
+ else {
+ $('.contact-names', $dialog).text(rec.name).removeClass('diff-text-old').show();
+ }
+
+ // open jquery UI dialog
+ $dialog.dialog({
+ modal: false,
+ resizable: true,
+ closeOnEscape: true,
+ title: rcmail.gettext('objectdiff','kolab_addressbook').replace('$rev1', data.rev1).replace('$rev2', data.rev2),
+ open: function() {
+ $dialog.attr('aria-hidden', 'false');
+ },
+ close: function() {
+ $dialog.dialog('destroy').attr('aria-hidden', 'true').hide();
+ },
+ buttons: [
+ {
+ text: rcmail.gettext('close'),
+ click: function() { $dialog.dialog('close'); },
+ autofocus: true
+ }
+ ],
+ minWidth: 400,
+ width: 480
+ }).show();
+
+ // set dialog size according to content
+ // dialog_resize($dialog.get(0), $dialog.height(), rcmail.gui_containers.notedetailview.width() - 40);
+};
+
+
function kolab_addressbook_contextmenu()
{
if (!window.rcm_callbackmenu_init) {
return;
}
if (!rcmail.env.kolab_addressbook_contextmenu) {
// adjust default addressbook menu actions
rcmail.addEventListener('contextmenu_init', function(menu) {
if (menu.menu_name == 'abooklist') {
menu.addEventListener('activate', function(p) {
// deactivate kolab addressbook actions
if (p.command.match(/^book-/)) {
return p.command == 'book-create';
}
});
}
});
}
rcmail.env.kolab_addressbook_contextmenu = true;
// add menu on kolab addressbooks
var menu = rcm_callbackmenu_init({
menu_name: 'kolab_abooklist',
mouseover_timeout: -1, // no submenus here
menu_source: ['#directorylist-footer', '#groupoptionsmenu']
}, {
'activate': function(p) {
var source = !rcmail.env.group ? rcmail.env.source : null,
sources = rcmail.env.address_sources,
props = source && sources[source] && sources[source].kolab ?
sources[source] : { readonly: true, removable: false, rights: '' };
if (p.command == 'book-create') {
return true;
}
if (p.command == 'book-edit') {
return props.rights.indexOf('a') >= 0;
}
if (p.command == 'book-delete') {
return props.rights.indexOf('a') >= 0 || props.rights.indexOf('x') >= 0;
}
if (p.command == 'group-create') {
return !props.readonly;
}
if (p.command == 'book-remove') {
return props.removable;
}
if (p.command == 'book-showurl') {
return !!(props.carddavurl);
}
if (p.command == 'group-rename' || p.command == 'group-delete') {
return !!(rcmail.env.group && sources[rcmail.env.source] && !sources[rcmail.env.source].readonly);
}
return false;
},
'beforeactivate': function(p) {
// remove dummy items
$('li.submenu', p.ref.container).remove();
rcmail.env.kolab_old_source = rcmail.env.source;
rcmail.env.kolab_old_group = rcmail.env.group;
var elem = $(p.source), onclick = elem.attr('onclick');
if (onclick && onclick.match(rcmail.context_menu_command_pattern)) {
rcmail.env.source = RegExp.$2;
rcmail.env.group = null;
}
else if (elem.parent().hasClass('contactgroup')) {
var grp = String(elem.attr('rel')).split(':');
rcmail.env.source = grp[0];
rcmail.env.group = grp[1];
}
},
'aftercommand': function(p) {
rcmail.env.source = rcmail.env.kolab_old_source;
rcmail.env.group = rcmail.env.kolab_old_group;
}
}
);
$('#directorylist').off('contextmenu').on('contextmenu', 'div > a, li.contactgroup > a', function(e) {
$(this).blur();
rcm_show_menu(e, this, $(this).attr('rel'), menu);
});
};
diff --git a/plugins/kolab_addressbook/kolab_addressbook.php b/plugins/kolab_addressbook/kolab_addressbook.php
index 6a2aaa6e..35908bbf 100644
--- a/plugins/kolab_addressbook/kolab_addressbook.php
+++ b/plugins/kolab_addressbook/kolab_addressbook.php
@@ -1,904 +1,1119 @@
<?php
/**
* Kolab address book
*
* Sample plugin to add a new address book source with data from Kolab storage
* It provides also a possibilities to manage contact folders
* (create/rename/delete/acl) directly in Addressbook UI.
*
* @version @package_version@
* @author Thomas Bruederli <bruederli@kolabsys.com>
* @author Aleksander Machniak <machniak@kolabsys.com>
*
- * Copyright (C) 2011, Kolab Systems AG <contact@kolabsys.com>
+ * Copyright (C) 2011-2015, Kolab Systems AG <contact@kolabsys.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class kolab_addressbook extends rcube_plugin
{
public $task = '?(?!login|logout).*';
private $sources;
private $folders;
private $rc;
private $ui;
+ public $bonnie_api = false;
+
const GLOBAL_FIRST = 0;
const PERSONAL_FIRST = 1;
const GLOBAL_ONLY = 2;
const PERSONAL_ONLY = 3;
/**
* Startup method of a Roundcube plugin
*/
public function init()
{
require_once(dirname(__FILE__) . '/lib/rcube_kolab_contacts.php');
$this->rc = rcube::get_instance();
// load required plugin
$this->require_plugin('libkolab');
// register hooks
$this->add_hook('addressbooks_list', array($this, 'address_sources'));
$this->add_hook('addressbook_get', array($this, 'get_address_book'));
$this->add_hook('config_get', array($this, 'config_get'));
if ($this->rc->task == 'addressbook') {
$this->add_texts('localization');
$this->add_hook('contact_form', array($this, 'contact_form'));
$this->add_hook('template_object_directorylist', array($this, 'directorylist_html'));
// Plugin actions
$this->register_action('plugin.book', array($this, 'book_actions'));
$this->register_action('plugin.book-save', array($this, 'book_save'));
$this->register_action('plugin.book-search', array($this, 'book_search'));
$this->register_action('plugin.book-subscribe', array($this, 'book_subscribe'));
+ $this->register_action('plugin.contact-changelog', array($this, 'contact_changelog'));
+ $this->register_action('plugin.contact-diff', array($this, 'contact_diff'));
+ $this->register_action('plugin.contact-show', array($this, 'contact_show'));
+
+ // get configuration for the Bonnie API
+ if ($bonnie_config = $this->rc->config->get('kolab_bonnie_api', false)) {
+ $this->bonnie_api = new kolab_bonnie_api($bonnie_config);
+ }
+
// Load UI elements
if ($this->api->output->type == 'html') {
$this->load_config();
require_once($this->home . '/lib/kolab_addressbook_ui.php');
$this->ui = new kolab_addressbook_ui($this);
}
}
else if ($this->rc->task == 'settings') {
$this->add_texts('localization');
$this->add_hook('preferences_list', array($this, 'prefs_list'));
$this->add_hook('preferences_save', array($this, 'prefs_save'));
}
$this->add_hook('folder_delete', array($this, 'prefs_folder_delete'));
$this->add_hook('folder_rename', array($this, 'prefs_folder_rename'));
$this->add_hook('folder_update', array($this, 'prefs_folder_update'));
}
/**
* Handler for the addressbooks_list hook.
*
* This will add all instances of available Kolab-based address books
* to the list of address sources of Roundcube.
* This will also hide some addressbooks according to kolab_addressbook_prio setting.
*
* @param array $p Hash array with hook parameters
*
* @return array Hash array with modified hook parameters
*/
public function address_sources($p)
{
$abook_prio = $this->addressbook_prio();
// Disable all global address books
// Assumes that all non-kolab_addressbook sources are global
if ($abook_prio == self::PERSONAL_ONLY) {
$p['sources'] = array();
}
$sources = array();
foreach ($this->_list_sources() as $abook_id => $abook) {
// register this address source
$sources[$abook_id] = $this->abook_prop($abook_id, $abook);
// flag folders with 'i' right as writeable
if ($this->rc->action == 'add' && strpos($abook->rights, 'i') !== false) {
$sources[$abook_id]['readonly'] = false;
}
}
// Add personal address sources to the list
if ($abook_prio == self::PERSONAL_FIRST) {
// $p['sources'] = array_merge($sources, $p['sources']);
// Don't use array_merge(), because if you have folders name
// that resolve to numeric identifier it will break output array keys
foreach ($p['sources'] as $idx => $value)
$sources[$idx] = $value;
$p['sources'] = $sources;
}
else {
// $p['sources'] = array_merge($p['sources'], $sources);
foreach ($sources as $idx => $value)
$p['sources'][$idx] = $value;
}
return $p;
}
/**
* Helper method to build a hash array of address book properties
*/
protected function abook_prop($id, $abook)
{
if ($abook->virtual) {
return array(
'id' => $id,
'name' => $abook->get_name(),
'listname' => $abook->get_foldername(),
'group' => $abook instanceof kolab_storage_folder_user ? 'user' : $abook->get_namespace(),
'readonly' => true,
'rights' => 'l',
'kolab' => true,
'virtual' => true,
);
}
else {
return array(
'id' => $id,
'name' => $abook->get_name(),
'listname' => $abook->get_foldername(),
'readonly' => $abook->readonly,
'rights' => $abook->rights,
'groups' => $abook->groups,
'undelete' => $abook->undelete && $this->rc->config->get('undo_timeout'),
'realname' => rcube_charset::convert($abook->get_realname(), 'UTF7-IMAP'), // IMAP folder name
'group' => $abook->get_namespace(),
'subscribed' => $abook->is_subscribed(),
'carddavurl' => $abook->get_carddav_url(),
- 'removable' => true,
- 'kolab' => true,
+ 'removable' => true,
+ 'kolab' => true,
+ 'audittrail' => !empty($this->bonnie_api),
);
}
}
/**
*
*/
public function directorylist_html($args)
{
$out = '';
$jsdata = array();
$sources = (array)$this->rc->get_address_sources();
// list all non-kolab sources first
foreach (array_filter($sources, function($source){ return empty($source['kolab']); }) as $j => $source) {
$id = strval(strlen($source['id']) ? $source['id'] : $j);
$out .= $this->addressbook_list_item($id, $source, $jsdata) . '</li>';
}
// render a hierarchical list of kolab contact folders
kolab_storage::folder_hierarchy($this->folders, $tree);
$out .= $this->folder_tree_html($tree, $sources, $jsdata);
$this->rc->output->set_env('contactgroups', array_filter($jsdata, function($src){ return $src['type'] == 'group'; }));
$this->rc->output->set_env('address_sources', array_filter($jsdata, function($src){ return $src['type'] != 'group'; }));
$args['content'] = html::tag('ul', $args, $out, html::$common_attrib);
return $args;
}
/**
* Return html for a structured list <ul> for the folder tree
*/
public function folder_tree_html($node, $data, &$jsdata)
{
$out = '';
foreach ($node->children as $folder) {
$id = $folder->id;
$source = $data[$id];
$is_collapsed = strpos($this->rc->config->get('collapsed_abooks',''), '&'.rawurlencode($id).'&') !== false;
if ($folder->virtual) {
$source = $this->abook_prop($folder->id, $folder);
}
else if (empty($source)) {
$this->sources[$id] = new rcube_kolab_contacts($folder->name);
$source = $this->abook_prop($id, $this->sources[$id]);
}
$content = $this->addressbook_list_item($id, $source, $jsdata);
if (!empty($folder->children)) {
$child_html = $this->folder_tree_html($folder, $data, $jsdata);
// copy group items...
if (preg_match('!<ul[^>]*>(.*)</ul>\n*$!Ums', $content, $m)) {
$child_html = $m[1] . $child_html;
$content = substr($content, 0, -strlen($m[0]) - 1);
}
// ... and re-create the subtree
if (!empty($child_html)) {
$content .= html::tag('ul', array('class' => 'groups', 'style' => ($is_collapsed ? "display:none;" : null)), $child_html);
}
}
$out .= $content . '</li>';
}
return $out;
}
/**
*
*/
protected function addressbook_list_item($id, $source, &$jsdata, $search_mode = false)
{
$current = rcube_utils::get_input_value('_source', rcube_utils::INPUT_GPC);
if (!$source['virtual']) {
$jsdata[$id] = $source;
$jsdata[$id]['name'] = html_entity_decode($source['name'], ENT_NOQUOTES, RCUBE_CHARSET);
}
// set class name(s)
$classes = array('addressbook');
if ($source['group'])
$classes[] = $source['group'];
if ($current === $id)
$classes[] = 'selected';
if ($source['readonly'])
$classes[] = 'readonly';
if ($source['virtual'])
$classes[] = 'virtual';
if ($source['class_name'])
$classes[] = $source['class_name'];
$name = !empty($source['listname']) ? $source['listname'] : (!empty($source['name']) ? $source['name'] : $id);
$label_id = 'kabt:' . $id;
$inner = ($source['virtual'] ?
html::a(array('tabindex' => '0'), $name) :
html::a(array(
'href' => $this->rc->url(array('_source' => $id)),
'rel' => $source['id'],
'id' => $label_id,
'onclick' => "return " . rcmail_output::JS_OBJECT_NAME.".command('list','" . rcube::JQ($id) . "',this)",
), $name)
);
if (isset($source['subscribed'])) {
$inner .= html::span(array(
'class' => 'subscribed',
'title' => $this->gettext('foldersubscribe'),
'role' => 'checkbox',
'aria-checked' => $source['subscribed'] ? 'true' : 'false',
), '');
}
// don't wrap in <li> but add a checkbox for search results listing
if ($search_mode) {
$jsdata[$id]['group'] = join(' ', $classes);
if (!$source['virtual']) {
$inner .= html::tag('input', array(
'type' => 'checkbox',
'name' => '_source[]',
'value' => $id,
'checked' => false,
'aria-labelledby' => $label_id,
));
}
return html::div(null, $inner);
}
$out .= html::tag('li', array(
'id' => 'rcmli' . rcube_utils::html_identifier($id, true),
'class' => join(' ', $classes),
'noclose' => true,
),
html::div($source['subscribed'] ? 'subscribed' : null, $inner)
);
$groupdata = array('out' => '', 'jsdata' => $jsdata, 'source' => $id);
if ($source['groups'] && function_exists('rcmail_contact_groups')) {
$groupdata = rcmail_contact_groups($groupdata);
}
$jsdata = $groupdata['jsdata'];
$out .= $groupdata['out'];
return $out;
}
/**
* Sets autocomplete_addressbooks option according to
* kolab_addressbook_prio setting extending list of address sources
* to be used for autocompletion.
*/
public function config_get($args)
{
if ($args['name'] != 'autocomplete_addressbooks') {
return $args;
}
$abook_prio = $this->addressbook_prio();
// here we cannot use rc->config->get()
$sources = $GLOBALS['CONFIG']['autocomplete_addressbooks'];
// Disable all global address books
// Assumes that all non-kolab_addressbook sources are global
if ($abook_prio == self::PERSONAL_ONLY) {
$sources = array();
}
if (!is_array($sources)) {
$sources = array();
}
$kolab_sources = array();
foreach (array_keys($this->_list_sources()) as $abook_id) {
if (!in_array($abook_id, $sources))
$kolab_sources[] = $abook_id;
}
// Add personal address sources to the list
if (!empty($kolab_sources)) {
if ($abook_prio == self::PERSONAL_FIRST) {
$sources = array_merge($kolab_sources, $sources);
}
else {
$sources = array_merge($sources, $kolab_sources);
}
}
$args['result'] = $sources;
return $args;
}
/**
* Getter for the rcube_addressbook instance
*
* @param array $p Hash array with hook parameters
*
* @return array Hash array with modified hook parameters
*/
public function get_address_book($p)
{
if ($p['id']) {
$id = kolab_storage::id_decode($p['id']);
// check for falsely base64 decoded identifier
if (preg_match('![^A-Za-z0-9=/+&._ -]!', $id)) {
$id = $p['id'];
}
$folder = kolab_storage::get_folder($id);
// try with unencoded (old-style) identifier
if ((!$folder || $folder->type != 'contact') && $id != $p['id']) {
$folder = kolab_storage::get_folder($p['id']);
}
if ($folder && $folder->type == 'contact') {
$p['instance'] = new rcube_kolab_contacts($folder->name);
// flag source as writeable if 'i' right is given
if ($p['writeable'] && $this->rc->action == 'save' && strpos($p['instance']->rights, 'i') !== false) {
$p['instance']->readonly = false;
}
else if ($this->rc->action == 'delete' && strpos($p['instance']->rights, 't') !== false) {
$p['instance']->readonly = false;
}
}
}
return $p;
}
private function _list_sources()
{
// already read sources
if (isset($this->sources))
return $this->sources;
kolab_storage::$encode_ids = true;
$this->sources = array();
$this->folders = array();
$abook_prio = $this->addressbook_prio();
// Personal address source(s) disabled?
if ($abook_prio == self::GLOBAL_ONLY) {
return $this->sources;
}
// get all folders that have "contact" type
$folders = kolab_storage::sort_folders(kolab_storage::get_folders('contact'));
if (PEAR::isError($folders)) {
rcube::raise_error(array(
'code' => 600, 'type' => 'php',
'file' => __FILE__, 'line' => __LINE__,
'message' => "Failed to list contact folders from Kolab server:" . $folders->getMessage()),
true, false);
}
else {
// we need at least one folder to prevent from errors in Roundcube core
// when there's also no sql nor ldap addressbook (Bug #2086)
if (empty($folders)) {
if ($folder = kolab_storage::create_default_folder('contact')) {
$folders = array(new kolab_storage_folder($folder, 'contact'));
}
}
// convert to UTF8 and sort
foreach ($folders as $folder) {
// create instance of rcube_contacts
$abook_id = $folder->id;
$abook = new rcube_kolab_contacts($folder->name);
$this->sources[$abook_id] = $abook;
$this->folders[$abook_id] = $folder;
}
}
return $this->sources;
}
/**
* Plugin hook called before rendering the contact form or detail view
*
* @param array $p Hash array with hook parameters
*
* @return array Hash array with modified hook parameters
*/
public function contact_form($p)
{
// none of our business
if (!is_object($GLOBALS['CONTACTS']) || !is_a($GLOBALS['CONTACTS'], 'rcube_kolab_contacts'))
return $p;
// extend the list of contact fields to be displayed in the 'personal' section
if (is_array($p['form']['personal'])) {
$p['form']['personal']['content']['profession'] = array('size' => 40);
$p['form']['personal']['content']['children'] = array('size' => 40);
$p['form']['personal']['content']['freebusyurl'] = array('size' => 40);
$p['form']['personal']['content']['pgppublickey'] = array('size' => 70);
$p['form']['personal']['content']['pkcs7publickey'] = array('size' => 70);
// re-order fields according to the coltypes list
$p['form']['contact']['content'] = $this->_sort_form_fields($p['form']['contact']['content'], $GLOBALS['CONTACTS']);
$p['form']['personal']['content'] = $this->_sort_form_fields($p['form']['personal']['content'], $GLOBALS['CONTACTS']);
/* define a separate section 'settings'
$p['form']['settings'] = array(
'name' => $this->gettext('settings'),
'content' => array(
'freebusyurl' => array('size' => 40, 'visible' => true),
'pgppublickey' => array('size' => 70, 'visible' => true),
'pkcs7publickey' => array('size' => 70, 'visible' => false),
)
);
*/
}
+ if ($this->bonnie_api && $this->rc->action == 'show') {
+ $this->rc->output->set_env('kolab_audit_trail', true);
+ }
+
return $p;
}
+ /**
+ * Handler for contact audit trail changelog requests
+ */
+ public function contact_changelog()
+ {
+ if (empty($this->bonnie_api)) {
+ return false;
+ }
+
+ $contact = rcube_utils::get_input_value('cid', rcube_utils::INPUT_POST, true);
+ $source = rcube_utils::get_input_value('source', rcube_utils::INPUT_POST);
+
+ list($uid, $mailbox, $msguid) = $this->_resolve_contact_identity($contact, $source);
+
+ $result = $uid && $mailbox ? $this->bonnie_api->changelog('contact', $uid, $mailbox, $msguid) : null;
+ if (is_array($result) && $result['uid'] == $uid) {
+ if (is_array($result['changes'])) {
+ $dtformat = $this->rc->config->get('date_format') . ' ' . $this->rc->config->get('time_format');
+ array_walk($result['changes'], function(&$change) use ($dtformat) {
+ if ($change['date']) {
+ $dt = rcube_utils::anytodatetime($change['date']);
+ if ($dt instanceof DateTime) {
+ $change['date'] = $this->rc->format_date($dt, $dtformat);
+ }
+ }
+ });
+ }
+ $this->rc->output->command('contact_render_changelog', $result['changes']);
+ }
+ else {
+ $this->rc->output->command('contact_render_changelog', false);
+ }
+
+ $this->rc->output->send();
+ }
+
+ /**
+ * Handler for audit trail diff view requests
+ */
+ public function contact_diff()
+ {
+ if (empty($this->bonnie_api)) {
+ return false;
+ }
+
+ $contact = rcube_utils::get_input_value('cid', rcube_utils::INPUT_POST, true);
+ $source = rcube_utils::get_input_value('source', rcube_utils::INPUT_POST);
+ $rev1 = rcube_utils::get_input_value('rev1', rcube_utils::INPUT_POST);
+ $rev2 = rcube_utils::get_input_value('rev2', rcube_utils::INPUT_POST);
+
+ list($uid, $mailbox, $msguid) = $this->_resolve_contact_identity($contact, $source);
+
+ $result = $this->bonnie_api->diff('contact', $uid, $rev1, $rev2, $mailbox, $msguid);
+ if (is_array($result) && $result['uid'] == $uid) {
+ $result['rev1'] = $rev1;
+ $result['rev2'] = $rev2;
+ $result['cid'] = $contact;
+
+ // convert some properties, similar to rcube_kolab_contacts::_to_rcube_contact()
+ $keymap = array(
+ 'lastmodified-date' => 'changed',
+ 'additional' => 'middlename',
+ 'fn' => 'name',
+ 'tel' => 'phone',
+ 'url' => 'website',
+ 'bday' => 'birthday',
+ 'note' => 'notes',
+ 'role' => 'profession',
+ 'title' => 'jobtitle',
+ );
+
+ $propmap = array('email' => 'address', 'website' => 'url', 'phone' => 'number');
+ $date_format = $this->rc->config->get('date_format', 'Y-m-d');
+
+ // map kolab object properties to keys and values the client expects
+ array_walk($result['changes'], function(&$change, $i) use ($keymap, $propmap, $date_format) {
+ if (array_key_exists($change['property'], $keymap)) {
+ $change['property'] = $keymap[$change['property']];
+ }
+
+ // format date-time values
+ if ($change['property'] == 'created' || $change['property'] == 'changed') {
+ if ($old_ = rcube_utils::anytodatetime($change['old'])) {
+ $change['old_'] = $this->rc->format_date($old_);
+ }
+ if ($new_ = rcube_utils::anytodatetime($change['new'])) {
+ $change['new_'] = $this->rc->format_date($new_);
+ }
+ }
+ // format dates
+ else if ($change['property'] == 'birthday' || $change['property'] == 'anniversary') {
+ if ($old_ = rcube_utils::anytodatetime($change['old'])) {
+ $change['old_'] = $this->rc->format_date($old_, $date_format);
+ }
+ if ($new_ = rcube_utils::anytodatetime($change['new'])) {
+ $change['new_'] = $this->rc->format_date($new_, $date_format);
+ }
+ }
+ // convert email, website, phone values
+ else if (array_key_exists($change['property'], $propmap)) {
+ $propname = $propmap[$change['property']];
+ foreach (array('old','new') as $k) {
+ $k_ = $k . '_';
+ if (!empty($change[$k])) {
+ $change[$k_] = html::quote($change[$k][$propname] ?: '--');
+ if ($change[$k]['type']) {
+ $change[$k_] .= '&nbsp;' . html::span('subtype', rcmail_get_type_label($change[$k]['type']));
+ }
+ $change['ishtml'] = true;
+ }
+ }
+ }
+ // serialize address structs
+ if ($change['property'] == 'address') {
+ foreach (array('old','new') as $k) {
+ $k_ = $k . '_';
+ $change[$k]['zipcode'] = $change[$k]['code'];
+ $template = $this->rc->config->get('address_template', '{'.join('} {', array_keys($change[$k])).'}');
+ $composite = array();
+ foreach ($change[$k] as $p => $val) {
+ if (strlen($val))
+ $composite['{'.$p.'}'] = $val;
+ }
+ $change[$k_] = preg_replace('/\{\w+\}/', '', strtr($template, $composite));
+ if ($change[$k]['type']) {
+ $change[$k_] .= html::div('subtype', rcmail_get_type_label($change[$k]['type']));
+ }
+ $change['ishtml'] = true;
+ }
+
+ $change['diff_'] = libkolab::html_diff($change['old_'], $change['new_'], true);
+ }
+ // localize gender values
+ else if ($change['property'] == 'gender') {
+ if ($change['old']) $change['old_'] = $this->rc->gettext($change['old']);
+ if ($change['new']) $change['new_'] = $this->rc->gettext($change['new']);
+ }
+ // translate 'key' entries in individual properties
+ else if ($change['property'] == 'key') {
+ $p = $change['old'] ?: $change['new'];
+ $t = $p['type'];
+ $change['property'] = $t . 'publickey';
+ $change['old'] = $change['old'] ? $change['old']['key'] : '';
+ $change['new'] = $change['new'] ? $change['new']['key'] : '';
+ }
+ // compute a nice diff of notes
+ else if ($change['property'] == 'notes') {
+ $change['diff_'] = libkolab::html_diff($change['old'], $change['new'], false);
+ }
+ });
+
+ $this->rc->output->command('contact_show_diff', $result);
+ }
+ else {
+ $this->rc->output->command('display_message', $this->gettext('objectdiffnotavailable'), 'error');
+ }
+
+ $this->rc->output->send();
+ }
+
+ /**
+ * Handler for audit trail revision view requests
+ */
+ public function contact_show()
+ {
+
+ $this->rc->output->send();
+ }
+
+
+ /**
+ * Helper method to resolved the given contact identifier into uid and mailbox
+ *
+ * @return array (uid,mailbox,msguid) tuple
+ */
+ private function _resolve_contact_identity($id, $abook)
+ {
+ $mailbox = $msguid = null;
+
+ $source = $this->get_address_book(array('id' => $abook));
+ if ($source['instance']) {
+ $uid = $source['instance']->id2uid($id);
+ $list = kolab_storage::id_decode($abook);
+ }
+ else {
+ return array(null, $mailbox, $msguid);
+ }
+ // get resolve message UID and mailbox identifier
+ if ($folder = kolab_storage::get_folder($list)) {
+ $mailbox = $folder->get_mailbox_id();
+ $msguid = $folder->cache->uid2msguid($uid);
+ }
+
+ return array($uid, $mailbox, $msguid);
+ }
+
+ /**
+ *
+ */
private function _sort_form_fields($contents, $source)
{
$block = array();
foreach (array_keys($source->coltypes) as $col) {
if (isset($contents[$col]))
$block[$col] = $contents[$col];
}
return $block;
}
/**
* Handler for user preferences form (preferences_list hook)
*
* @param array $args Hash array with hook parameters
*
* @return array Hash array with modified hook parameters
*/
public function prefs_list($args)
{
if ($args['section'] != 'addressbook') {
return $args;
}
$ldap_public = $this->rc->config->get('ldap_public');
$abook_type = $this->rc->config->get('address_book_type');
// Hide option if there's no global addressbook
if (empty($ldap_public) || $abook_type != 'ldap') {
return $args;
}
// Check that configuration is not disabled
$dont_override = (array) $this->rc->config->get('dont_override', array());
$prio = $this->addressbook_prio();
if (!in_array('kolab_addressbook_prio', $dont_override)) {
// Load localization
$this->add_texts('localization');
$field_id = '_kolab_addressbook_prio';
$select = new html_select(array('name' => $field_id, 'id' => $field_id));
$select->add($this->gettext('globalfirst'), self::GLOBAL_FIRST);
$select->add($this->gettext('personalfirst'), self::PERSONAL_FIRST);
$select->add($this->gettext('globalonly'), self::GLOBAL_ONLY);
$select->add($this->gettext('personalonly'), self::PERSONAL_ONLY);
$args['blocks']['main']['options']['kolab_addressbook_prio'] = array(
'title' => html::label($field_id, Q($this->gettext('addressbookprio'))),
'content' => $select->show($prio),
);
}
return $args;
}
/**
* Handler for user preferences save (preferences_save hook)
*
* @param array $args Hash array with hook parameters
*
* @return array Hash array with modified hook parameters
*/
public function prefs_save($args)
{
if ($args['section'] != 'addressbook') {
return $args;
}
// Check that configuration is not disabled
$dont_override = (array) $this->rc->config->get('dont_override', array());
$key = 'kolab_addressbook_prio';
if (!in_array('kolab_addressbook_prio', $dont_override) || !isset($_POST['_'.$key])) {
$args['prefs'][$key] = (int) rcube_utils::get_input_value('_'.$key, rcube_utils::INPUT_POST);
}
return $args;
}
/**
* Handler for plugin actions
*/
public function book_actions()
{
$action = trim(rcube_utils::get_input_value('_act', rcube_utils::INPUT_GPC));
if ($action == 'create') {
$this->ui->book_edit();
}
else if ($action == 'edit') {
$this->ui->book_edit();
}
else if ($action == 'delete') {
$this->book_delete();
}
}
/**
* Handler for address book create/edit form submit
*/
public function book_save()
{
$prop = array(
'name' => trim(rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST)),
'oldname' => trim(rcube_utils::get_input_value('_oldname', rcube_utils::INPUT_POST, true)), // UTF7-IMAP
'parent' => trim(rcube_utils::get_input_value('_parent', rcube_utils::INPUT_POST, true)), // UTF7-IMAP
'type' => 'contact',
'subscribed' => true,
);
$result = $error = false;
$type = strlen($prop['oldname']) ? 'update' : 'create';
$prop = $this->rc->plugins->exec_hook('addressbook_'.$type, $prop);
if (!$prop['abort']) {
if ($newfolder = kolab_storage::folder_update($prop)) {
$folder = $newfolder;
$result = true;
}
else {
$error = kolab_storage::$last_error;
}
}
else {
$result = $prop['result'];
$folder = $prop['name'];
}
if ($result) {
$kolab_folder = kolab_storage::get_folder($folder);
// get folder/addressbook properties
$abook = new rcube_kolab_contacts($folder);
$props = $this->abook_prop(kolab_storage::folder_id($folder, true), $abook);
$props['parent'] = kolab_storage::folder_id($kolab_folder->get_parent(), true);
$this->rc->output->show_message('kolab_addressbook.book'.$type.'d', 'confirmation');
$this->rc->output->command('book_update', $props, kolab_storage::folder_id($prop['oldname'], true));
$this->rc->output->send('iframe');
}
if (!$error)
$error = $plugin['message'] ? $plugin['message'] : 'kolab_addressbook.book'.$type.'error';
$this->rc->output->show_message($error, 'error');
// display the form again
$this->ui->book_edit();
}
/**
*
*/
public function book_search()
{
$results = array();
$query = rcube_utils::get_input_value('q', rcube_utils::INPUT_GPC);
$source = rcube_utils::get_input_value('source', rcube_utils::INPUT_GPC);
kolab_storage::$encode_ids = true;
$search_more_results = false;
$this->sources = array();
$this->folders = array();
// find unsubscribed IMAP folders that have "event" type
if ($source == 'folders') {
foreach ((array)kolab_storage::search_folders('contact', $query, array('other')) as $folder) {
$this->folders[$folder->id] = $folder;
$this->sources[$folder->id] = new rcube_kolab_contacts($folder->name);
}
}
// search other user's namespace via LDAP
else if ($source == 'users') {
$limit = $this->rc->config->get('autocomplete_max', 15) * 2; // we have slightly more space, so display twice the number
foreach (kolab_storage::search_users($query, 0, array(), $limit * 10) as $user) {
$folders = array();
// search for contact folders shared by this user
foreach (kolab_storage::list_user_folders($user, 'contact', false) as $foldername) {
$folders[] = new kolab_storage_folder($foldername, 'contact');
}
if (count($folders)) {
$userfolder = new kolab_storage_folder_user($user['kolabtargetfolder'], '', $user);
$this->folders[$userfolder->id] = $userfolder;
$this->sources[$userfolder->id] = $userfolder;
foreach ($folders as $folder) {
$this->folders[$folder->id] = $folder;
$this->sources[$folder->id] = new rcube_kolab_contacts($folder->name);;
$count++;
}
}
if ($count >= $limit) {
$search_more_results = true;
break;
}
}
}
$delim = $this->rc->get_storage()->get_hierarchy_delimiter();
// build results list
foreach ($this->sources as $id => $source) {
$folder = $this->folders[$id];
$imap_path = explode($delim, $folder->name);
// find parent
do {
array_pop($imap_path);
$parent_id = kolab_storage::folder_id(join($delim, $imap_path));
}
while (count($imap_path) > 1 && !$this->folders[$parent_id]);
// restore "real" parent ID
if ($parent_id && !$this->folders[$parent_id]) {
$parent_id = kolab_storage::folder_id($folder->get_parent());
}
$prop = $this->abook_prop($id, $source);
$prop['parent'] = $parent_id;
$html = $this->addressbook_list_item($id, $prop, $jsdata, true);
unset($prop['group']);
$prop += (array)$jsdata[$id];
$prop['html'] = $html;
$results[] = $prop;
}
// report more results available
if ($search_more_results) {
$this->rc->output->show_message('autocompletemore', 'info');
}
$this->rc->output->command('multi_thread_http_response', $results, rcube_utils::get_input_value('_reqid', rcube_utils::INPUT_GPC));
}
/**
*
*/
public function book_subscribe()
{
$success = false;
$id = rcube_utils::get_input_value('_source', rcube_utils::INPUT_GPC);
if ($id && ($folder = kolab_storage::get_folder(kolab_storage::id_decode($id)))) {
if (isset($_POST['_permanent']))
$success |= $folder->subscribe(intval($_POST['_permanent']));
if (isset($_POST['_active']))
$success |= $folder->activate(intval($_POST['_active']));
// list groups for this address book
if (!empty($_POST['_groups'])) {
$abook = new rcube_kolab_contacts($folder->name);
foreach ((array)$abook->list_groups() as $prop) {
$prop['source'] = $id;
$prop['id'] = $prop['ID'];
unset($prop['ID']);
$this->rc->output->command('insert_contact_group', $prop);
}
}
}
if ($success) {
$this->rc->output->show_message('successfullysaved', 'confirmation');
}
else {
$this->rc->output->show_message($this->gettext('errorsaving'), 'error');
}
$this->rc->output->send();
}
/**
* Handler for address book delete action (AJAX)
*/
private function book_delete()
{
$folder = trim(rcube_utils::get_input_value('_source', rcube_utils::INPUT_GPC, true, 'UTF7-IMAP'));
if (kolab_storage::folder_delete($folder)) {
$storage = $this->rc->get_storage();
$delimiter = $storage->get_hierarchy_delimiter();
$this->rc->output->show_message('kolab_addressbook.bookdeleted', 'confirmation');
$this->rc->output->set_env('pagecount', 0);
$this->rc->output->command('set_rowcount', rcmail_get_rowcount_text(new rcube_result_set()));
$this->rc->output->command('set_env', 'delimiter', $delimiter);
$this->rc->output->command('list_contacts_clear');
$this->rc->output->command('book_delete_done', kolab_storage::folder_id($folder, true));
}
else {
$this->rc->output->show_message('kolab_addressbook.bookdeleteerror', 'error');
}
$this->rc->output->send();
}
/**
* Returns value of kolab_addressbook_prio setting
*/
private function addressbook_prio()
{
// Load configuration
if (!$this->config_loaded) {
$this->load_config();
$this->config_loaded = true;
}
$abook_prio = (int) $this->rc->config->get('kolab_addressbook_prio');
// Make sure any global addressbooks are defined
if ($abook_prio == 0 || $abook_prio == 2) {
$ldap_public = $this->rc->config->get('ldap_public');
$abook_type = $this->rc->config->get('address_book_type');
if (empty($ldap_public) || $abook_type != 'ldap') {
$abook_prio = 1;
}
}
return $abook_prio;
}
/**
* Hook for (contact) folder deletion
*/
function prefs_folder_delete($args)
{
// ignore...
if ($args['abort'] && !$args['result']) {
return $args;
}
$this->_contact_folder_rename($args['name'], false);
}
/**
* Hook for (contact) folder renaming
*/
function prefs_folder_rename($args)
{
// ignore...
if ($args['abort'] && !$args['result']) {
return $args;
}
$this->_contact_folder_rename($args['oldname'], $args['newname']);
}
/**
* Hook for (contact) folder updates. Forward to folder_rename handler if name was changed
*/
function prefs_folder_update($args)
{
// ignore...
if ($args['abort'] && !$args['result']) {
return $args;
}
if ($args['record']['name'] != $args['record']['oldname']) {
$this->_contact_folder_rename($args['record']['oldname'], $args['record']['name']);
}
}
/**
* Apply folder renaming or deletion to the registered birthday calendar address books
*/
private function _contact_folder_rename($oldname, $newname = false)
{
$update = false;
$delimiter = $this->rc->get_storage()->get_hierarchy_delimiter();
$bday_addressbooks = (array)$this->rc->config->get('calendar_birthday_adressbooks', array());
foreach ($bday_addressbooks as $i => $id) {
$folder_name = kolab_storage::id_decode($id);
if ($oldname === $folder_name || strpos($folder_name, $oldname.$delimiter) === 0) {
if ($newname) { // rename
$new_folder = $newname . substr($folder_name, strlen($oldname));
$bday_addressbooks[$i] = kolab_storage::id_encode($new_folder);
}
else { // delete
unset($bday_addressbooks[$i]);
}
$update = true;
}
}
if ($update) {
$this->rc->user->save_prefs(array('calendar_birthday_adressbooks' => $bday_addressbooks));
}
}
}
diff --git a/plugins/kolab_addressbook/lib/kolab_addressbook_ui.php b/plugins/kolab_addressbook/lib/kolab_addressbook_ui.php
index 65476488..e20cf14d 100644
--- a/plugins/kolab_addressbook/lib/kolab_addressbook_ui.php
+++ b/plugins/kolab_addressbook/lib/kolab_addressbook_ui.php
@@ -1,303 +1,344 @@
<?php
/**
* Kolab address book UI
*
* @author Aleksander Machniak <machniak@kolabsys.com>
*
* Copyright (C) 2012, Kolab Systems AG <contact@kolabsys.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class kolab_addressbook_ui
{
private $plugin;
private $rc;
/**
* Class constructor
*
* @param kolab_addressbook $plugin Plugin object
*/
public function __construct($plugin)
{
$this->rc = rcube::get_instance();
$this->plugin = $plugin;
$this->init_ui();
}
/**
* Adds folders management functionality to Addressbook UI
*/
private function init_ui()
{
- if (!empty($this->rc->action) && !preg_match('/^plugin\.book/', $this->rc->action)) {
+ if (!empty($this->rc->action) && !preg_match('/^plugin\.book/', $this->rc->action) && $this->rc->action != 'show') {
return;
}
// Include script
$this->plugin->include_script('kolab_addressbook.js');
if (empty($this->rc->action)) {
// Include stylesheet (for directorylist)
$this->plugin->include_stylesheet($this->plugin->local_skin_path().'/kolab_addressbook.css');
// include kolab folderlist widget if available
if (in_array('libkolab', $this->plugin->api->loaded_plugins())) {
$this->plugin->api->include_script('libkolab/js/folderlist.js');
}
// Add actions on address books
$options = array('book-create', 'book-edit', 'book-delete', 'book-remove');
$idx = 0;
if ($this->rc->config->get('kolab_addressbook_carddav_url')) {
$options[] = 'book-showurl';
$this->rc->output->set_env('kolab_addressbook_carddav_url', true);
}
foreach ($options as $command) {
$content = html::tag('li', $idx ? null : array('class' => 'separator_above'),
$this->plugin->api->output->button(array(
'label' => 'kolab_addressbook.'.str_replace('-', '', $command),
'domain' => $this->ID,
'classact' => 'active',
'command' => $command
)));
$this->plugin->api->add_content($content, 'groupoptions');
$idx++;
}
// Link to Settings/Folders
$content = html::tag('li', array('class' => 'separator_above'),
$this->plugin->api->output->button(array(
'label' => 'managefolders',
'type' => 'link',
'classact' => 'active',
'command' => 'folders',
'task' => 'settings',
)));
$this->plugin->api->add_content($content, 'groupoptions');
$this->rc->output->add_label('kolab_addressbook.bookdeleteconfirm',
'kolab_addressbook.bookdeleting', 'kolab_addressbook.bookshowurl',
'kolab_addressbook.carddavurldescription',
'kolab_addressbook.bookedit',
'kolab_addressbook.bookdelete',
'kolab_addressbook.bookshowurl',
'kolab_addressbook.findaddressbooks',
'kolab_addressbook.searchterms',
'kolab_addressbook.foldersearchform',
'kolab_addressbook.listsearchresults',
'kolab_addressbook.nraddressbooksfound',
'kolab_addressbook.noaddressbooksfound',
'kolab_addressbook.foldersubscribe',
'resetsearch');
+
+
+ if ($this->plugin->bonnie_api) {
+ $this->plugin->api->include_script('libkolab/js/audittrail.js');
+
+ $this->rc->output->add_label(
+ 'kolab_addressbook.showhistory',
+ 'kolab_addressbook.compare',
+ 'kolab_addressbook.objectchangelog',
+ 'kolab_addressbook.objectdiff',
+ 'kolab_addressbook.showrevision',
+ 'kolab_addressbook.actionappend',
+ 'kolab_addressbook.actionmove',
+ 'kolab_addressbook.actiondelete',
+ 'kolab_addressbook.objectdiffnotavailable',
+ 'kolab_addressbook.objectchangelognotavailable',
+ 'close'
+ );
+
+ $this->plugin->add_hook('render_page', array($this, 'render_audittrail_page'));
+ $this->plugin->register_handler('plugin.object_changelog_table', array('libkolab', 'object_changelog_table'));
+ }
+ }
+ // include stylesheet for audit trail
+ else if ($this->rc->action == 'show' && $this->plugin->bonnie_api) {
+ $this->plugin->include_stylesheet($this->plugin->local_skin_path().'/kolab_addressbook.css');
+ $this->rc->output->add_label('kolab_addressbook.showhistory');
}
// book create/edit form
else {
$this->rc->output->add_label('kolab_addressbook.nobooknamewarning',
'kolab_addressbook.booksaving');
}
}
/**
* Handler for address book create/edit action
*/
public function book_edit()
{
$this->rc->output->add_handler('bookdetails', array($this, 'book_form'));
$this->rc->output->send('kolab_addressbook.bookedit');
}
/**
* Handler for 'bookdetails' object returning form content for book create/edit
*
* @param array $attr Object attributes
*
* @return string HTML output
*/
public function book_form($attrib)
{
$action = trim(rcube_utils::get_input_value('_act', rcube_utils::INPUT_GPC));
$folder = trim(rcube_utils::get_input_value('_source', rcube_utils::INPUT_GPC, true)); // UTF8
$hidden_fields[] = array('name' => '_source', 'value' => $folder);
$folder = rcube_charset::convert($folder, RCMAIL_CHARSET, 'UTF7-IMAP');
$storage = $this->rc->get_storage();
$delim = $storage->get_hierarchy_delimiter();
if ($this->rc->action == 'plugin.book-save') {
// save error
$name = trim(rcube_utils::get_input_value('_name', rcube_utils::INPUT_GPC, true)); // UTF8
$old = trim(rcube_utils::get_input_value('_oldname', rcube_utils::INPUT_GPC, true)); // UTF7-IMAP
$path_imap = trim(rcube_utils::get_input_value('_parent', rcube_utils::INPUT_GPC, true)); // UTF7-IMAP
$hidden_fields[] = array('name' => '_oldname', 'value' => $old);
$folder = $old;
}
else if ($action == 'edit') {
$path_imap = explode($delim, $folder);
$name = rcube_charset::convert(array_pop($path_imap), 'UTF7-IMAP');
$path_imap = implode($path_imap, $delim);
}
else { // create
$path_imap = $folder;
$name = '';
$folder = '';
}
// Store old name, get folder options
if (strlen($folder)) {
$hidden_fields[] = array('name' => '_oldname', 'value' => $folder);
$options = $storage->folder_info($folder);
}
$form = array();
// General tab
$form['props'] = array(
'name' => $this->rc->gettext('properties'),
);
if (!empty($options) && ($options['norename'] || $options['protected'])) {
$foldername = Q(str_replace($delim, ' &raquo; ', kolab_storage::object_name($folder)));
}
else {
$foldername = new html_inputfield(array('name' => '_name', 'id' => '_name', 'size' => 30));
$foldername = $foldername->show($name);
}
$form['props']['fieldsets']['location'] = array(
'name' => $this->rc->gettext('location'),
'content' => array(
'name' => array(
'label' => $this->plugin->gettext('bookname'),
'value' => $foldername,
),
),
);
if (!empty($options) && ($options['norename'] || $options['protected'])) {
// prevent user from moving folder
$hidden_fields[] = array('name' => '_parent', 'value' => $path_imap);
}
else {
$select = kolab_storage::folder_selector('contact', array('name' => '_parent'), $folder);
$form['props']['fieldsets']['location']['content']['path'] = array(
'label' => $this->plugin->gettext('parentbook'),
'value' => $select->show(strlen($folder) ? $path_imap : ''),
);
}
// Allow plugins to modify address book form content (e.g. with ACL form)
$plugin = $this->rc->plugins->exec_hook('addressbook_form',
array('form' => $form, 'options' => $options, 'name' => $folder));
$form = $plugin['form'];
// Set form tags and hidden fields
list($form_start, $form_end) = $this->get_form_tags($attrib, 'plugin.book-save', null, $hidden_fields);
unset($attrib['form']);
// return the complete edit form as table
$out = "$form_start\n";
// Create form output
foreach ($form as $tab) {
if (!empty($tab['fieldsets']) && is_array($tab['fieldsets'])) {
$content = '';
foreach ($tab['fieldsets'] as $fieldset) {
$subcontent = $this->get_form_part($fieldset);
if ($subcontent) {
$content .= html::tag('fieldset', null, html::tag('legend', null, Q($fieldset['name'])) . $subcontent) ."\n";
}
}
}
else {
$content = $this->get_form_part($tab);
}
if ($content) {
$out .= html::tag('fieldset', null, html::tag('legend', null, Q($tab['name'])) . $content) ."\n";
}
}
$out .= "\n$form_end";
return $out;
}
+ /**
+ *
+ */
+ public function render_audittrail_page($p)
+ {
+ // append audit trail UI elements to contact page
+ if ($p['template'] === 'addressbook' && !$p['kolab-audittrail']) {
+ $this->rc->output->add_footer($this->rc->output->parse('kolab_addressbook.audittrail', false, false));
+ $p['kolab-audittrail'] = true;
+ }
+
+ return $p;
+ }
+
private function get_form_part($form)
{
$content = '';
if (is_array($form['content']) && !empty($form['content'])) {
$table = new html_table(array('cols' => 2, 'class' => 'propform'));
foreach ($form['content'] as $col => $colprop) {
$colprop['id'] = '_'.$col;
$label = !empty($colprop['label']) ? $colprop['label'] : rcube_label($col);
$table->add('title', sprintf('<label for="%s">%s</label>', $colprop['id'], Q($label)));
$table->add(null, $colprop['value']);
}
$content = $table->show();
}
else {
$content = $form['content'];
}
return $content;
}
private function get_form_tags($attrib, $action, $id = null, $hidden = null)
{
$form_start = $form_end = '';
$request_key = $action . (isset($id) ? '.'.$id : '');
$form_start = $this->rc->output->request_form(array(
'name' => 'form',
'method' => 'post',
'task' => $this->rc->task,
'action' => $action,
'request' => $request_key,
'noclose' => true,
) + $attrib);
if (is_array($hidden)) {
foreach ($hidden as $field) {
$hiddenfield = new html_hiddenfield($field);
$form_start .= $hiddenfield->show();
}
}
$form_end = !strlen($attrib['form']) ? '</form>' : '';
$EDIT_FORM = !empty($attrib['form']) ? $attrib['form'] : 'form';
$this->rc->output->add_gui_object('editform', $EDIT_FORM);
return array($form_start, $form_end);
}
}
diff --git a/plugins/kolab_addressbook/localization/en_US.inc b/plugins/kolab_addressbook/localization/en_US.inc
index b636d4d5..a65f46c9 100644
--- a/plugins/kolab_addressbook/localization/en_US.inc
+++ b/plugins/kolab_addressbook/localization/en_US.inc
@@ -1,66 +1,80 @@
<?php
/**
* Localizations for the Kolab Address Book plugin
*
* Copyright (C) 2014, Kolab Systems AG
*
* For translation see https://www.transifex.com/projects/p/kolab/resource/kolab_addressbook/
*/
$labels = array();
$labels['initials'] = 'Initials';
$labels['profession'] = 'Profession';
$labels['officelocation'] = 'Office location';
$labels['children'] = 'Children';
$labels['pgppublickey'] = 'PGP public key';
$labels['pkcs7publickey'] = 'S/MIME public key';
$labels['freebusyurl'] = 'Free-busy URL';
$labels['typebusiness'] = 'Business';
$labels['typebusinessfax'] = 'Business Fax';
$labels['typecompany'] = 'Company';
$labels['typeprimary'] = 'Primary';
$labels['typetelex'] = 'Telex';
$labels['typeradio'] = 'Radio';
$labels['typeisdn'] = 'ISDN';
$labels['typettytdd'] = 'TTY/TDD';
$labels['typecallback'] = 'Callback';
$labels['settings'] = 'Settings';
$labels['bookcreate'] = 'Create address book';
$labels['bookedit'] = 'Edit address book';
$labels['bookdelete'] = 'Delete address book';
$labels['bookremove'] = 'Remove from list';
$labels['bookproperties'] = 'Address book properties';
$labels['bookname'] = 'Book name';
$labels['parentbook'] = 'Superior book';
$labels['bookshowurl'] = 'Show CardDAV URL';
$labels['carddavurldescription'] = 'Copy this address to a <a href="http://en.wikipedia.org/wiki/CardDAV" target="_blank">CardDAV</a> client application to fully synchronize this specific address book with your computer or mobile device.';
$labels['addressbookprio'] = 'Address book(s) selection/behaviour';
$labels['personalfirst'] = 'Personal address book(s) first';
$labels['globalfirst'] = 'Global address book(s) first';
$labels['personalonly'] = 'Personal address book(s) only';
$labels['globalonly'] = 'Global address book(s) only';
$labels['findaddressbooks'] = 'Find address books';
$labels['searchterms'] = 'Search terms';
$labels['listsearchresults'] = 'Additional address books';
$labels['foldersearchform'] = 'Address book search form';
$labels['foldersubscribe'] = 'List permanently';
$labels['nraddressbooksfound'] = '$nr address books found';
$labels['noaddressbooksfound'] = 'No address books found';
+// history dialog
+$labels['showhistory'] = 'Show History';
+$labels['compare'] = 'Compare';
+$labels['objectchangelog'] = 'Change History';
+$labels['objectdiff'] = 'Changes from $rev1 to $rev2';
+$labels['actionappend'] = 'Saved';
+$labels['actionmove'] = 'Moved';
+$labels['actiondelete'] = 'Deleted';
+$labels['showrevision'] = 'Show this version';
+$labels['restore'] = 'Restore this version';
+$labels['objectnotfound'] = 'Failed to load contact data';
+$labels['objectchangelognotavailable'] = 'Change history is not available for this contact';
+$labels['objectdiffnotavailable'] = 'No comparison possible for the selected revisions';
+
$messages['bookdeleteconfirm'] = 'Do you really want to delete the selected address book and all contacts in it?';
$messages['bookdeleting'] = 'Deleting address book...';
$messages['booksaving'] = 'Saving address book...';
$messages['bookdeleted'] = 'Address book deleted successfully.';
$messages['bookupdated'] = 'Address book updated successfully.';
$messages['bookcreated'] = 'Address book created successfully.';
$messages['bookdeleteerror'] = 'An error occured while deleting address book.';
$messages['bookupdateerror'] = 'An error occured while updating address book.';
$messages['bookcreateerror'] = 'An error occured while creating address book.';
$messages['nobooknamewarning'] = 'Please, enter address book name.';
$messages['noemailnamewarning'] = 'Please, enter email address or contact name.';
?>
diff --git a/plugins/kolab_addressbook/skins/classic/templates/audittrail.html b/plugins/kolab_addressbook/skins/classic/templates/audittrail.html
new file mode 100644
index 00000000..e69de29b
diff --git a/plugins/kolab_addressbook/skins/larry/folder_icons.png b/plugins/kolab_addressbook/skins/larry/folder_icons.png
index b9c59b5a..19b8cfab 100644
Binary files a/plugins/kolab_addressbook/skins/larry/folder_icons.png and b/plugins/kolab_addressbook/skins/larry/folder_icons.png differ
diff --git a/plugins/kolab_addressbook/skins/larry/kolab_addressbook.css b/plugins/kolab_addressbook/skins/larry/kolab_addressbook.css
index 5484807e..2d2d8795 100644
--- a/plugins/kolab_addressbook/skins/larry/kolab_addressbook.css
+++ b/plugins/kolab_addressbook/skins/larry/kolab_addressbook.css
@@ -1,141 +1,246 @@
#directorylistbox .listsearchbox + .scroller {
top: 34px;
}
#directorylistbox .listsearchbox.expanded + .scroller {
top: 68px;
}
#directorylistbox .boxtitle a.iconbutton.search {
position: absolute;
top: 8px;
right: 8px;
width: 16px;
cursor: pointer;
background-position: -2px -317px;
}
#directorylist li.addressbook.selected > div a {
background-position: 6px -791px;
}
#directorylist ul li.addressbook.selected > div a {
background-position: 32px -791px;
}
#directorylist ul ul li.addressbook.selected > div a {
background-position: 58px -791px;
}
#directorylist ul ul ul li.addressbook.selected > div a {
background-position: 84px -791px;
}
#directorylistbox ul.treelist li.virtual {
background-image: none !important;
}
#directorylistbox ul.treelist li.virtual > div a {
color: #aaa;
background-image: none;
height: 16px;
padding-top: 3px;
padding-bottom: 3px;
}
#directorylistbox ul.treelist li.virtual > .treetoggle {
top: 6px !important;
}
#directorylistbox ul.treelist li input[type='checkbox'] {
position: absolute;
top: 4px;
left: 10px;
}
#directorylistbox ul.treelist ul li input[type='checkbox'] {
left: 36px;
}
#directorylist li input[type='checkbox'] {
display: none;
}
#directorylistbox ul.treelist div span.subscribed {
display: inline-block;
position: absolute;
top: 4px;
right: 5px;
height: 16px;
width: 16px;
padding: 0;
background: url(folder_icons.png) -100px 0 no-repeat;
overflow: hidden;
text-indent: -5000px;
cursor: pointer;
}
#directorylistbox ul.treelist div span.subscribed:focus,
#directorylistbox ul.treelist div:hover span.subscribed {
background-position: 0px -160px;
}
#directorylistbox ul.treelist div.subscribed span.subscribed {
background-position: -16px -160px;
}
#directorylistbox ul.treelist div span.subscribed:focus {
border-radius: 3px;
outline: 2px solid rgba(30,150,192, 0.5);
}
#directorylistbox .searchresults .listing li {
background-color: #c7e3ef;
}
#directorylist li.addressbook.readonly,
#directorylist li.addressbook.shared,
#directorylist li.addressbook.other {
background-image: url(folder_icons.png);
background-position: right -1000px;
background-repeat: no-repeat;
}
#directorylist li.addressbook.readonly {
background-position: 98% -21px;
}
#directorylist li.addressbook.personal.readonly,
#directorylist li.addressbook.other.readonly {
background-position: 98% -77px;
}
#directorylist li.addressbook.shared {
background-position: 98% -103px;
}
#directorylist li.addressbook.shared.readonly {
background-position: 98% -130px;
}
#directorylist li.addressbook.virtual.user {
background-image: url(folder_icons.png) !important;
background-position: 98% -52px;
}
#directorylist li.addressbook.readonly a,
#directorylist li.addressbook.shared a,
#directorylist li.addressbook.other a {
padding-right: 24px;
}
#directorylist li.addressbook.other.readonly a,
#directorylist li.addressbook.shared.readonly a {
padding-right: 36px;
}
/* for contextmenu */
#directorylist a.contextRow {
background-color: #C7E3EF;
}
+
+#contactdiff,
+#contacthistory {
+ display: none;
+}
+
+.formbuttons .formbuttons-secondary-kolab {
+ display: block;
+ margin: 2px 2px 0 0;
+ text-align: center;
+}
+
+.formbuttons .btn-contact-history {
+ display: inline-block;
+ padding: 1px;
+ color: #333;
+ text-decoration: none;
+}
+
+.formbuttons .btn-contact-history:hover {
+ text-decoration: underline;
+}
+
+.formbuttons .btn-contact-history:before {
+ content: "";
+ display: inline-block;
+ position: relative;
+ top: 5px;
+ width: 16px;
+ height: 16px;
+ margin-right: 3px;
+ background: url('folder_icons.png') 0px -200px no-repeat;
+}
+
+#contactdiff .contact-names,
+#contactdiff .contact-names-new {
+ margin-top: 0;
+}
+
+#contactdiff .contact-names.diff-text-old {
+ margin-bottom: 0;
+}
+
+#contactdiff .diff-text-diff del,
+#contactdiff .diff-text-diff ins {
+ text-decoration: none;
+ color: inherit;
+}
+
+#contactdiff .diff-img-old,
+#contactdiff .diff-text-old,
+#contactdiff .diff-text-diff del {
+ background-color: #fdd;
+ text-decoration: line-through;
+}
+
+#contactdiff .diff-text-new,
+#contactdiff .diff-img-new,
+#contactdiff .diff-text-diff ins,
+#contactdiff .diff-text-diff .diffmod img {
+ background-color: #dfd;
+}
+
+#contactdiff .diff-img-old,
+#contactdiff .diff-img-new {
+ min-width: 48px;
+ max-width: 112px;
+}
+
+#contactdiff label {
+ color: #666;
+ font-weight: bold;
+}
+
+#contactdiff label span.index {
+ vertical-align: inherit;
+ margin-left: 0.6em;
+ font-weight: normal;
+}
+
+#contactdiff .contact-name {
+ font-size: 120%;
+ font-weight: bold;
+}
+
+#contactdiff .subtype {
+ color: #666;
+}
+
+#contactdiff span.subtype {
+ margin-left: 0.5em;
+}
+
+#contactdiff div.subtype {
+ margin-top: 0.2em;
+}
+
+#contactdiff .subtype:before {
+ content: "(";
+}
+
+#contactdiff .subtype:after {
+ content: ")";
+}
+
diff --git a/plugins/kolab_addressbook/skins/larry/templates/audittrail.html b/plugins/kolab_addressbook/skins/larry/templates/audittrail.html
new file mode 100644
index 00000000..9411b03a
--- /dev/null
+++ b/plugins/kolab_addressbook/skins/larry/templates/audittrail.html
@@ -0,0 +1,144 @@
+<div id="contacthistory" class="uidialog" aria-hidden="true">
+ <roundcube:object name="plugin.object_changelog_table" class="records-table changelog-table" domain="calendar" />
+ <div class="compare-button"><input type="button" class="button" value="↳ <roundcube:label name='kolab_addressbook.compare' />" /></div>
+</div>
+
+<div id="contactdiff" class="uidialog contentbox" aria-hidden="true">
+ <h2 class="contact-names">Contact Name</h2>
+ <h2 class="contact-names-new diff-text-new"></h2>
+
+ <div class="form-section contact-name">
+ <span class="diff-text-old"></span> &#8674;
+ <span class="diff-text-new"></span>
+ </div>
+
+ <div class="form-section contact-nickname">
+ <span class="diff-text-old"></span> &#8674;
+ <span class="diff-text-new"></span>
+ </div>
+
+ <div class="form-section contact-organization">
+ <span class="diff-text-old"></span> &#8674;
+ <span class="diff-text-new"></span>
+ </div>
+
+ <div class="form-section contact-department">
+ <span class="diff-text-old"></span> &#8674;
+ <span class="diff-text-new"></span>
+ </div>
+
+ <div class="form-section contact-jobtitle">
+ <span class="diff-text-old"></span> &#8674;
+ <span class="diff-text-new"></span>
+ </div>
+
+ <div class="form-section contact-photo">
+ <img class="diff-img-old" /> &#8674;
+ <img class="diff-img-new" />
+ </div>
+
+ <div class="form-section contact-email">
+ <label><roundcube:label name="email" /><span class="index"></span></label>
+ <span class="diff-text-old"></span> &#8674;
+ <span class="diff-text-new"></span>
+ </div>
+
+ <div class="form-section contact-phone">
+ <label><roundcube:label name="phone" /><span class="index"></span></label>
+ <span class="diff-text-old"></span> &#8674;
+ <span class="diff-text-new"></span>
+ </div>
+
+ <div class="form-section contact-address">
+ <label><roundcube:label name="address" /><span class="index"></span></label>
+ <div class="diff-text-diff" style="white-space:pre-wrap"></div>
+ <div class="diff-text-old"></div>
+ <div class="diff-text-new"></div>
+ </div>
+
+ <div class="form-section contact-website">
+ <label><roundcube:label name="website" /><span class="index"></span></label>
+ <span class="diff-text-old"></span> &#8674;
+ <span class="diff-text-new"></span>
+ </div>
+
+ <div class="form-section contact-im">
+ <label><roundcube:label name="instantmessenger" /><span class="index"></span></label>
+ <span class="diff-text-old"></span> &#8674;
+ <span class="diff-text-new"></span>
+ </div>
+
+ <div class="form-section contact-gender">
+ <label><roundcube:label name="gender" /><span class="index"></span></label>
+ <span class="diff-text-old"></span> &#8674;
+ <span class="diff-text-new"></span>
+ </div>
+
+ <div class="form-section contact-birthday">
+ <label><roundcube:label name="birthday" /><span class="index"></span></label>
+ <span class="diff-text-old"></span> &#8674;
+ <span class="diff-text-new"></span>
+ </div>
+
+ <div class="form-section contact-anniversary">
+ <label><roundcube:label name="anniversary" /><span class="index"></span></label>
+ <span class="diff-text-old"></span> &#8674;
+ <span class="diff-text-new"></span>
+ </div>
+
+ <div class="form-section contact-profession">
+ <label><roundcube:label name="profession" /><span class="index"></span></label>
+ <span class="diff-text-old"></span> &#8674;
+ <span class="diff-text-new"></span>
+ </div>
+
+ <div class="form-section contact-manager">
+ <label><roundcube:label name="manager" /><span class="index"></span></label>
+ <span class="diff-text-old"></span> &#8674;
+ <span class="diff-text-new"></span>
+ </div>
+
+ <div class="form-section contact-assistant">
+ <label><roundcube:label name="assistant" /><span class="index"></span></label>
+ <span class="diff-text-old"></span> &#8674;
+ <span class="diff-text-new"></span>
+ </div>
+
+ <div class="form-section contact-spouse">
+ <label><roundcube:label name="spouse" /><span class="index"></span></label>
+ <span class="diff-text-old"></span> &#8674;
+ <span class="diff-text-new"></span>
+ </div>
+
+ <div class="form-section contact-children">
+ <label><roundcube:label name="children" /><span class="index"></span></label>
+ <span class="diff-text-old"></span> &#8674;
+ <span class="diff-text-new"></span>
+ </div>
+
+ <div class="form-section contact-notes">
+ <label><roundcube:label name="notes" /></label>
+ <div class="diff-text-diff" style="white-space:pre-wrap"></div>
+ <div class="diff-text-old"></div>
+ <div class="diff-text-new"></div>
+ </div>
+
+ <div class="form-section contact-freebusyurl">
+ <label><roundcube:label name="kolab_addressbook.freebusyurl" /></label>
+ <div class="diff-text-old"></div>
+ <div class="diff-text-new"></div>
+ </div>
+
+ <div class="form-section contact-pgppublickey">
+ <label><roundcube:label name="kolab_addressbook.pgppublickey" /></label>
+ <div class="diff-text-old" style="white-space:pre-wrap"></div>
+ <div class="diff-text-new" style="white-space:pre-wrap"></div>
+ </div>
+
+ <div class="form-section contact-pkcs7publickey">
+ <label><roundcube:label name="kolab_addressbook.pkcs7publickey" /></label>
+ <div class="diff-text-old" style="white-space:pre-wrap"></div>
+ <div class="diff-text-new" style="white-space:pre-wrap"></div>
+ </div>
+
+</div>
\ No newline at end of file
diff --git a/plugins/libkolab/js/audittrail.js b/plugins/libkolab/js/audittrail.js
index 42cdbf0c..87340b3f 100644
--- a/plugins/libkolab/js/audittrail.js
+++ b/plugins/libkolab/js/audittrail.js
@@ -1,201 +1,201 @@
/**
* Kolab groupware audit trail utilities
*
* @author Thomas Bruederli <bruederli@kolabsys.com>
*
* @licstart The following is the entire license notice for the
* JavaScript code in this file.
*
* Copyright (C) 2015, Kolab Systems AG <contact@kolabsys.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @licend The above is the entire license notice
* for the JavaScript code in this file.
*/
var libkolab_audittrail = {}
libkolab_audittrail.quote_html = function(str)
{
return String(str).replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
};
// show object changelog in a dialog
libkolab_audittrail.object_history_dialog = function(p)
{
// render dialog
var $dialog = $(p.container);
// close show dialog first
if ($dialog.is(':ui-dialog'))
$dialog.dialog('close');
// hide and reset changelog table
$dialog.find('div.notfound-message').remove();
$dialog.find('.changelog-table').show().children('tbody')
.html('<tr><td colspan="6"><span class="loading">' + rcmail.gettext('loading') + '</span></td></tr>');
// open jquery UI dialog
$dialog.dialog({
modal: false,
resizable: true,
closeOnEscape: true,
title: p.title,
open: function() {
$dialog.attr('aria-hidden', 'false');
},
close: function() {
$dialog.dialog('destroy').attr('aria-hidden', 'true').hide();
},
buttons: [
{
text: rcmail.gettext('close'),
click: function() { $dialog.dialog('close'); },
autofocus: true
}
],
minWidth: 450,
width: 650,
height: 350,
- minHeight: 200,
+ minHeight: 200
})
.show().children('.compare-button').hide();
// initialize event handlers for history dialog UI elements
if (!$dialog.data('initialized')) {
// compare button
$dialog.find('.compare-button input').click(function(e) {
var rev1 = $dialog.find('.changelog-table input.diff-rev1:checked').val(),
rev2 = $dialog.find('.changelog-table input.diff-rev2:checked').val();
if (rev1 && rev2 && rev1 != rev2) {
// swap revisions if the user got it wrong
if (rev1 > rev2) {
var tmp = rev2;
rev2 = rev1;
rev1 = tmp;
}
if (p.comparefunc) {
p.comparefunc(rev1, rev2);
}
}
else {
alert('Invalid selection!')
}
if (!rcube_event.is_keyboard(e) && this.blur) {
this.blur();
}
return false;
});
// delegate handlers for list actions
$dialog.find('.changelog-table tbody').on('click', 'td.actions a', function(e) {
var link = $(this),
action = link.hasClass('restore') ? 'restore' : 'show',
event = $('#eventhistory').data('event'),
rev = link.attr('data-rev');
// ignore clicks on first row (current revision)
if (link.closest('tr').hasClass('first')) {
return false;
}
// let the user confirm the restore action
if (action == 'restore' && !confirm(rcmail.gettext('revisionrestoreconfirm', p.module).replace('$rev', rev))) {
return false;
}
if (p.listfunc) {
p.listfunc(action, rev);
}
if (!rcube_event.is_keyboard(e) && this.blur) {
this.blur();
}
return false;
})
.on('click', 'input.diff-rev1', function(e) {
if (!this.checked) return true;
var rev1 = this.value, selection_valid = false;
$dialog.find('.changelog-table input.diff-rev2').each(function(i, elem) {
$(elem).prop('disabled', elem.value <= rev1);
if (elem.checked && elem.value > rev1) {
selection_valid = true;
}
});
if (!selection_valid) {
$dialog.find('.changelog-table input.diff-rev2:not([disabled])').last().prop('checked', true);
}
});
$dialog.addClass('changelog-dialog').data('initialized', true);
}
return $dialog;
};
// callback from server with changelog data
libkolab_audittrail.render_changelog = function(data, object, folder)
{
var Q = libkolab_audittrail.quote_html;
var $dialog = $('.changelog-dialog')
if (data === false || !data.length) {
return false;
}
var i, change, accessible, op_append,
first = data.length - 1, last = 0,
is_writeable = !!folder.editable,
op_labels = { APPEND: 'actionappend', MOVE: 'actionmove', DELETE: 'actiondelete' },
actions = '<a href="#show" class="iconbutton preview" title="'+ rcmail.gettext('showrevision',data.module) +'" data-rev="{rev}" /> ' +
(is_writeable ? '<a href="#restore" class="iconbutton restore" title="'+ rcmail.gettext('restore',data.module) + '" data-rev="{rev}" />' : ''),
tbody = $dialog.find('.changelog-table tbody').html('');
for (i=first; i >= 0; i--) {
change = data[i];
accessible = change.date && change.user;
if (change.op == 'MOVE' && change.mailbox) {
op_append = ' ⇢ ' + change.mailbox;
}
else {
op_append = '';
}
$('<tr class="' + (i == first ? 'first' : (i == last ? 'last' : '')) + (accessible ? '' : 'undisclosed') + '">')
.append('<td class="diff">' + (accessible && change.op != 'DELETE' ?
'<input type="radio" name="rev1" class="diff-rev1" value="' + change.rev + '" title="" '+ (i == last ? 'checked="checked"' : '') +' /> '+
'<input type="radio" name="rev2" class="diff-rev2" value="' + change.rev + '" title="" '+ (i == first ? 'checked="checked"' : '') +' /></td>'
: ''))
.append('<td class="revision">' + Q(i+1) + '</td>')
.append('<td class="date">' + Q(change.date || '') + '</td>')
.append('<td class="user">' + Q(change.user || 'undisclosed') + '</td>')
.append('<td class="operation" title="' + op_append + '">' + Q(rcmail.gettext(op_labels[change.op] || '', data.module) + (op_append ? ' ...' : '')) + '</td>')
.append('<td class="actions">' + (accessible && change.op != 'DELETE' ? actions.replace(/\{rev\}/g, change.rev) : '') + '</td>')
.appendTo(tbody);
}
if (first > 0) {
$dialog.find('.compare-button').fadeIn(200);
$dialog.find('.changelog-table tr.last input.diff-rev1').click();
}
return $dialog;
};
\ No newline at end of file

File Metadata

Mime Type
text/x-diff
Expires
Wed, Jul 8, 7:40 PM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1049475
Default Alt Text
(103 KB)

Event Timeline