2011-06-24 20:13:43 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Kolab address book UI
|
|
|
|
*
|
|
|
|
* @author Aleksander Machniak <machniak@kolabsys.com>
|
|
|
|
*
|
2012-03-08 21:24:13 +01:00
|
|
|
* Copyright (C) 2012, Kolab Systems AG <contact@kolabsys.com>
|
2011-06-24 20:13:43 +02:00
|
|
|
*
|
2011-10-27 10:20:46 +02:00
|
|
|
* 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.
|
2011-06-24 20:13:43 +02:00
|
|
|
*
|
|
|
|
* 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
|
2011-10-27 10:20:46 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
2011-06-24 20:13:43 +02:00
|
|
|
*
|
2011-10-27 10:20:46 +02:00
|
|
|
* 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/>.
|
2011-06-24 20:13:43 +02:00
|
|
|
*/
|
|
|
|
class kolab_addressbook_ui
|
|
|
|
{
|
|
|
|
private $plugin;
|
2024-01-25 13:47:41 +01:00
|
|
|
/** @var rcmail */
|
2011-06-24 20:13:43 +02:00
|
|
|
private $rc;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class constructor
|
|
|
|
*
|
|
|
|
* @param kolab_addressbook $plugin Plugin object
|
|
|
|
*/
|
|
|
|
public function __construct($plugin)
|
|
|
|
{
|
2024-01-25 13:47:41 +01:00
|
|
|
$this->rc = rcmail::get_instance();
|
2011-06-24 20:13:43 +02:00
|
|
|
$this->plugin = $plugin;
|
|
|
|
|
|
|
|
$this->init_ui();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds folders management functionality to Addressbook UI
|
|
|
|
*/
|
|
|
|
private function init_ui()
|
|
|
|
{
|
2015-04-16 14:50:16 +02:00
|
|
|
if (!empty($this->rc->action) && !preg_match('/^plugin\.book/', $this->rc->action) && $this->rc->action != 'show') {
|
2011-06-24 20:13:43 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Include script
|
|
|
|
$this->plugin->include_script('kolab_addressbook.js');
|
|
|
|
|
|
|
|
if (empty($this->rc->action)) {
|
|
|
|
// Include stylesheet (for directorylist)
|
2024-01-24 11:24:41 +01:00
|
|
|
$this->plugin->include_stylesheet($this->plugin->local_skin_path() . '/kolab_addressbook.css');
|
2011-06-24 20:13:43 +02:00
|
|
|
|
2014-06-25 17:09:04 +02:00
|
|
|
// include kolab folderlist widget if available
|
2014-12-16 14:12:21 +01:00
|
|
|
if (in_array('libkolab', $this->plugin->api->loaded_plugins())) {
|
2018-04-08 12:52:12 +00:00
|
|
|
$this->plugin->api->include_script('libkolab/libkolab.js');
|
2014-06-25 17:09:04 +02:00
|
|
|
}
|
|
|
|
|
2017-11-28 11:04:06 +01:00
|
|
|
$this->rc->output->add_footer($this->rc->output->parse('kolab_addressbook.search_addon', false, false));
|
|
|
|
|
2011-06-24 20:13:43 +02:00
|
|
|
// Add actions on address books
|
2022-11-04 12:08:22 +01:00
|
|
|
$options = ['book-create', 'book-edit', 'book-delete'];
|
|
|
|
if ($this->plugin->driver instanceof kolab_contacts_driver) {
|
|
|
|
$options[] = 'book-remove';
|
|
|
|
}
|
2011-06-24 20:13:43 +02:00
|
|
|
|
2022-11-04 12:08:22 +01:00
|
|
|
if ($this->plugin->driver instanceof kolab_contacts_driver && ($dav_url = $this->rc->config->get('kolab_addressbook_carddav_url'))) {
|
2022-10-14 16:34:19 +02:00
|
|
|
$options[] = 'book-showurl';
|
|
|
|
$this->rc->output->set_env('kolab_addressbook_carddav_url', true);
|
2015-07-29 04:07:38 -04:00
|
|
|
|
2022-10-14 16:34:19 +02:00
|
|
|
// set CardDAV URI for specified ldap addressbook
|
|
|
|
if ($ldap_abook = $this->rc->config->get('kolab_addressbook_carddav_ldap')) {
|
2024-01-24 11:24:41 +01:00
|
|
|
$dav_ldap_url = strtr($dav_url, [
|
2022-10-14 16:34:19 +02:00
|
|
|
'%h' => $_SERVER['HTTP_HOST'],
|
|
|
|
'%u' => urlencode($this->rc->get_user_name()),
|
|
|
|
'%i' => 'ldap-directory',
|
|
|
|
'%n' => '',
|
2024-01-24 11:24:41 +01:00
|
|
|
]);
|
2022-10-14 16:34:19 +02:00
|
|
|
$this->rc->output->set_env('kolab_addressbook_carddav_ldap', $ldap_abook);
|
|
|
|
$this->rc->output->set_env('kolab_addressbook_carddav_ldap_url', $dav_ldap_url);
|
|
|
|
}
|
2013-10-03 12:44:41 +02:00
|
|
|
}
|
|
|
|
|
2022-11-04 12:08:22 +01:00
|
|
|
$idx = 0;
|
2011-06-24 20:13:43 +02:00
|
|
|
foreach ($options as $command) {
|
2024-01-24 11:24:41 +01:00
|
|
|
$content = html::tag(
|
|
|
|
'li',
|
|
|
|
$idx ? null : ['class' => 'separator_above'],
|
|
|
|
$this->plugin->api->output->button([
|
|
|
|
'label' => 'kolab_addressbook.' . str_replace('-', '', $command),
|
2017-11-13 13:48:35 +01:00
|
|
|
'class' => str_replace('-', ' ', $command) . ' disabled',
|
|
|
|
'classact' => str_replace('-', ' ', $command) . ' active',
|
2017-07-11 14:33:31 +00:00
|
|
|
'command' => $command,
|
2024-01-24 11:24:41 +01:00
|
|
|
'type' => 'link',
|
|
|
|
])
|
|
|
|
);
|
2011-06-24 20:13:43 +02:00
|
|
|
$this->plugin->api->add_content($content, 'groupoptions');
|
|
|
|
$idx++;
|
|
|
|
}
|
|
|
|
|
2011-08-09 08:41:16 +02:00
|
|
|
// Link to Settings/Folders
|
2022-11-04 12:08:22 +01:00
|
|
|
if ($this->plugin->driver instanceof kolab_contacts_driver) {
|
2024-01-24 11:24:41 +01:00
|
|
|
$content = html::tag(
|
|
|
|
'li',
|
|
|
|
['class' => 'separator_above'],
|
2022-11-04 12:08:22 +01:00
|
|
|
$this->plugin->api->output->button([
|
|
|
|
'label' => 'managefolders',
|
|
|
|
'type' => 'link',
|
|
|
|
'class' => 'folders disabled',
|
|
|
|
'classact' => 'folders active',
|
|
|
|
'command' => 'folders',
|
|
|
|
'task' => 'settings',
|
2024-01-24 11:24:41 +01:00
|
|
|
])
|
|
|
|
);
|
2022-11-04 12:08:22 +01:00
|
|
|
|
|
|
|
$this->plugin->api->add_content($content, 'groupoptions');
|
|
|
|
}
|
2011-08-09 08:41:16 +02:00
|
|
|
|
2018-12-03 15:05:54 +00:00
|
|
|
$this->rc->output->add_label(
|
|
|
|
'kolab_addressbook.bookdeleteconfirm',
|
|
|
|
'kolab_addressbook.bookdeleting',
|
2013-10-30 16:59:04 +01:00
|
|
|
'kolab_addressbook.carddavurldescription',
|
2013-10-30 17:16:47 +01:00
|
|
|
'kolab_addressbook.bookdelete',
|
2014-06-25 17:09:04 +02:00
|
|
|
'kolab_addressbook.bookshowurl',
|
2018-12-03 15:05:54 +00:00
|
|
|
'kolab_addressbook.bookedit',
|
|
|
|
'kolab_addressbook.bookcreate',
|
|
|
|
'kolab_addressbook.nobooknamewarning',
|
|
|
|
'kolab_addressbook.booksaving',
|
2014-06-25 17:09:04 +02:00
|
|
|
'kolab_addressbook.findaddressbooks',
|
|
|
|
'kolab_addressbook.searchterms',
|
|
|
|
'kolab_addressbook.foldersearchform',
|
|
|
|
'kolab_addressbook.listsearchresults',
|
|
|
|
'kolab_addressbook.nraddressbooksfound',
|
|
|
|
'kolab_addressbook.noaddressbooksfound',
|
2014-09-03 10:36:53 +02:00
|
|
|
'kolab_addressbook.foldersubscribe',
|
2017-11-13 13:48:35 +01:00
|
|
|
'resetsearch'
|
|
|
|
);
|
2015-04-16 14:50:16 +02:00
|
|
|
|
|
|
|
if ($this->plugin->bonnie_api) {
|
2015-04-17 11:03:06 +02:00
|
|
|
$this->rc->output->set_env('kolab_audit_trail', true);
|
2018-03-19 13:52:58 +01:00
|
|
|
$this->plugin->api->include_script('libkolab/libkolab.js');
|
2015-04-16 14:50:16 +02:00
|
|
|
|
|
|
|
$this->rc->output->add_label(
|
|
|
|
'kolab_addressbook.showhistory',
|
|
|
|
'kolab_addressbook.objectchangelog',
|
|
|
|
'kolab_addressbook.objectdiff',
|
|
|
|
'kolab_addressbook.objectdiffnotavailable',
|
|
|
|
'kolab_addressbook.objectchangelognotavailable',
|
2015-04-20 17:20:39 +02:00
|
|
|
'kolab_addressbook.revisionrestoreconfirm'
|
2015-04-16 14:50:16 +02:00
|
|
|
);
|
|
|
|
|
2024-01-24 11:24:41 +01:00
|
|
|
$this->plugin->add_hook('render_page', [$this, 'render_audittrail_page']);
|
|
|
|
$this->plugin->register_handler('plugin.object_changelog_table', ['libkolab', 'object_changelog_table']);
|
2015-04-16 14:50:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// include stylesheet for audit trail
|
2024-01-24 11:24:41 +01:00
|
|
|
elseif ($this->rc->action == 'show' && $this->plugin->bonnie_api) {
|
|
|
|
$this->plugin->include_stylesheet($this->plugin->local_skin_path() . '/kolab_addressbook.css', true);
|
2015-04-16 14:50:16 +02:00
|
|
|
$this->rc->output->add_label('kolab_addressbook.showhistory');
|
2011-06-24 20:13:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for address book create/edit action
|
|
|
|
*/
|
|
|
|
public function book_edit()
|
|
|
|
{
|
2018-03-28 13:31:05 +00:00
|
|
|
$this->rc->output->set_env('pagetitle', $this->plugin->gettext('bookproperties'));
|
2022-11-04 12:08:22 +01:00
|
|
|
$this->rc->output->add_handler('folderform', [$this, 'book_form']);
|
2018-03-28 13:31:05 +00:00
|
|
|
$this->rc->output->send('libkolab.folderform');
|
2011-06-24 20:13:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2014-10-10 11:52:29 +02:00
|
|
|
$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
|
2011-06-24 20:13:43 +02:00
|
|
|
|
2022-11-04 12:08:22 +01:00
|
|
|
$form_html = $this->plugin->driver->folder_form($action, $folder);
|
2011-06-24 20:13:43 +02:00
|
|
|
|
2022-11-04 12:08:22 +01:00
|
|
|
$attrib += ['action' => 'plugin.book-save', 'method' => 'post', 'id' => 'bookpropform'];
|
2011-06-24 20:13:43 +02:00
|
|
|
|
2022-11-04 12:08:22 +01:00
|
|
|
return html::tag('form', $attrib, $form_html);
|
2011-06-24 20:13:43 +02:00
|
|
|
}
|
|
|
|
|
2015-04-16 14:50:16 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
2011-06-24 20:13:43 +02:00
|
|
|
}
|