2011-05-21 12:25:39 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2011-06-27 13:44:27 +02:00
|
|
|
* Kolab address book 0.5
|
2011-06-08 11:33:18 +02:00
|
|
|
*
|
2011-05-21 12:25:39 +02:00
|
|
|
* Sample plugin to add a new address book source with data from Kolab storage
|
2011-06-27 13:44:27 +02:00
|
|
|
* It provides also a possibilities to manage contact folders
|
|
|
|
* (create/rename/delete/acl) directly in Addressbook UI.
|
2011-05-21 12:25:39 +02:00
|
|
|
*
|
|
|
|
* @author Thomas Bruederli <roundcube@gmail.com>
|
2011-06-08 11:33:18 +02:00
|
|
|
* @author Aleksander Machniak <machniak@kolabsys.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011, Kolab Systems AG
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2011-05-21 12:25:39 +02:00
|
|
|
*/
|
|
|
|
class kolab_addressbook extends rcube_plugin
|
|
|
|
{
|
2011-07-25 12:49:46 +02:00
|
|
|
public $task = 'mail|settings|addressbook|calendar';
|
2011-06-27 13:44:27 +02:00
|
|
|
|
2011-05-21 12:25:39 +02:00
|
|
|
private $folders;
|
|
|
|
private $sources;
|
2011-06-08 11:33:18 +02:00
|
|
|
private $rc;
|
2011-06-27 13:44:27 +02:00
|
|
|
private $ui;
|
2011-06-08 11:33:18 +02:00
|
|
|
|
|
|
|
const GLOBAL_FIRST = 0;
|
|
|
|
const PERSONAL_FIRST = 1;
|
|
|
|
const GLOBAL_ONLY = 2;
|
|
|
|
const PERSONAL_ONLY = 3;
|
2011-05-21 12:25:39 +02:00
|
|
|
|
|
|
|
/**
|
2011-06-08 11:33:18 +02:00
|
|
|
* Startup method of a Roundcube plugin
|
2011-05-21 12:25:39 +02:00
|
|
|
*/
|
|
|
|
public function init()
|
|
|
|
{
|
2011-06-27 13:44:27 +02:00
|
|
|
require_once(dirname(__FILE__) . '/lib/rcube_kolab_contacts.php');
|
|
|
|
|
2011-06-08 11:33:18 +02:00
|
|
|
$this->rc = rcmail::get_instance();
|
|
|
|
|
2011-05-21 12:25:39 +02:00
|
|
|
// load required plugin
|
|
|
|
$this->require_plugin('kolab_core');
|
2011-06-02 09:45:04 +02:00
|
|
|
|
2011-05-21 12:25:39 +02:00
|
|
|
// register hooks
|
|
|
|
$this->add_hook('addressbooks_list', array($this, 'address_sources'));
|
|
|
|
$this->add_hook('addressbook_get', array($this, 'get_address_book'));
|
2011-07-25 12:49:46 +02:00
|
|
|
$this->add_hook('config_get', array($this, 'config_get'));
|
2011-06-02 10:33:29 +02:00
|
|
|
|
2011-06-08 11:33:18 +02:00
|
|
|
if ($this->rc->task == 'addressbook') {
|
2011-06-02 10:33:29 +02:00
|
|
|
$this->add_texts('localization');
|
2011-06-08 11:33:18 +02:00
|
|
|
$this->add_hook('contact_form', array($this, 'contact_form'));
|
2011-06-27 13:44:27 +02:00
|
|
|
|
|
|
|
// Plugin actions
|
|
|
|
$this->register_action('plugin.book', array($this, 'book_actions'));
|
|
|
|
$this->register_action('plugin.book-save', array($this, 'book_save'));
|
|
|
|
|
|
|
|
// Load UI elements
|
|
|
|
if ($this->api->output->type == 'html') {
|
|
|
|
require_once($this->home . '/lib/kolab_addressbook_ui.php');
|
|
|
|
$this->ui = new kolab_addressbook_ui($this);
|
|
|
|
}
|
2011-06-08 11:33:18 +02:00
|
|
|
}
|
|
|
|
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'));
|
2011-06-02 10:33:29 +02:00
|
|
|
}
|
2011-05-21 12:25:39 +02:00
|
|
|
}
|
|
|
|
|
2011-06-08 11:33:18 +02:00
|
|
|
|
2011-05-21 12:25:39 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
2011-06-08 11:33:18 +02:00
|
|
|
* This will also hide some addressbooks according to kolab_addressbook_prio setting.
|
|
|
|
*
|
|
|
|
* @param array $p Hash array with hook parameters
|
2011-05-21 12:25:39 +02:00
|
|
|
*
|
|
|
|
* @return array Hash array with modified hook parameters
|
|
|
|
*/
|
|
|
|
public function address_sources($p)
|
|
|
|
{
|
2011-06-08 11:33:18 +02:00
|
|
|
// Load configuration
|
|
|
|
$this->load_config();
|
|
|
|
|
|
|
|
$abook_prio = (int) $this->rc->config->get('kolab_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();
|
2011-06-27 13:44:27 +02:00
|
|
|
$names = array();
|
|
|
|
|
2011-05-21 12:25:39 +02:00
|
|
|
foreach ($this->_list_sources() as $abook_id => $abook) {
|
2011-06-27 13:44:27 +02:00
|
|
|
$name = $origname = $abook->get_name();
|
|
|
|
|
|
|
|
// find folder prefix to truncate
|
|
|
|
for ($i = count($names)-1; $i >= 0; $i--) {
|
|
|
|
if (strpos($name, $names[$i].' » ') === 0) {
|
|
|
|
$length = strlen($names[$i].' » ');
|
|
|
|
$prefix = substr($name, 0, $length);
|
|
|
|
$count = count(explode(' » ', $prefix));
|
|
|
|
$name = str_repeat(' ', $count-1) . '» ' . substr($name, $length);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$names[] = $origname;
|
|
|
|
|
2011-05-21 12:25:39 +02:00
|
|
|
// register this address source
|
2011-06-08 11:33:18 +02:00
|
|
|
$sources[$abook_id] = array(
|
2011-06-27 13:44:27 +02:00
|
|
|
'id' => $abook_id,
|
|
|
|
'name' => $name,
|
2011-05-21 12:25:39 +02:00
|
|
|
'readonly' => $abook->readonly,
|
2011-06-27 13:44:27 +02:00
|
|
|
'editable' => $abook->editable,
|
|
|
|
'groups' => $abook->groups,
|
|
|
|
'realname' => rcube_charset_convert($abook->get_realname(), 'UTF7-IMAP'), // IMAP folder name
|
2011-06-27 17:53:10 +02:00
|
|
|
'class_name' => $abook->get_namespace(),
|
2011-06-27 13:44:27 +02:00
|
|
|
'kolab' => true,
|
2011-05-21 12:25:39 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-06-08 11:33:18 +02:00
|
|
|
// Add personal address sources to the list
|
|
|
|
if ($abook_prio == self::PERSONAL_FIRST) {
|
2011-07-27 19:13:38 +02:00
|
|
|
// $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;
|
2011-06-08 11:33:18 +02:00
|
|
|
}
|
|
|
|
else {
|
2011-07-27 19:13:38 +02:00
|
|
|
// $p['sources'] = array_merge($p['sources'], $sources);
|
|
|
|
foreach ($sources as $idx => $value)
|
|
|
|
$p['sources'][$idx] = $value;
|
2011-06-08 11:33:18 +02:00
|
|
|
}
|
|
|
|
|
2011-05-21 12:25:39 +02:00
|
|
|
return $p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-08 11:33:18 +02:00
|
|
|
/**
|
2011-07-25 12:49:46 +02:00
|
|
|
* Sets autocomplete_addressbooks option according to
|
|
|
|
* kolab_addressbook_prio setting extending list of address sources
|
|
|
|
* to be used for autocompletion.
|
2011-06-08 11:33:18 +02:00
|
|
|
*/
|
2011-07-25 12:49:46 +02:00
|
|
|
public function config_get($args)
|
2011-06-08 11:33:18 +02:00
|
|
|
{
|
2011-07-25 12:49:46 +02:00
|
|
|
if ($args['name'] != 'autocomplete_addressbooks') {
|
|
|
|
return $args;
|
|
|
|
}
|
|
|
|
|
2011-06-08 11:33:18 +02:00
|
|
|
// Load configuration
|
|
|
|
$this->load_config();
|
|
|
|
|
|
|
|
$abook_prio = (int) $this->rc->config->get('kolab_addressbook_prio');
|
2011-07-25 12:49:46 +02:00
|
|
|
// here we cannot use rc->config->get()
|
|
|
|
$sources = $GLOBALS['CONFIG']['autocomplete_addressbooks'];
|
2011-06-08 11:33:18 +02:00
|
|
|
|
|
|
|
// Disable all global address books
|
|
|
|
// Assumes that all non-kolab_addressbook sources are global
|
|
|
|
if ($abook_prio == self::PERSONAL_ONLY) {
|
|
|
|
$sources = array();
|
|
|
|
}
|
|
|
|
|
2011-07-25 12:49:46 +02:00
|
|
|
if (!is_array($sources)) {
|
|
|
|
$sources = array();
|
|
|
|
}
|
|
|
|
|
2011-06-08 11:33:18 +02:00
|
|
|
$kolab_sources = array();
|
|
|
|
foreach ($this->_list_sources() as $abook_id => $abook) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2011-07-25 12:49:46 +02:00
|
|
|
|
|
|
|
$args['result'] = $sources;
|
|
|
|
|
|
|
|
return $args;
|
2011-06-08 11:33:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-21 12:25:39 +02:00
|
|
|
/**
|
|
|
|
* Getter for the rcube_addressbook instance
|
2011-06-08 11:33:18 +02:00
|
|
|
*
|
|
|
|
* @param array $p Hash array with hook parameters
|
|
|
|
*
|
|
|
|
* @return array Hash array with modified hook parameters
|
2011-05-21 12:25:39 +02:00
|
|
|
*/
|
|
|
|
public function get_address_book($p)
|
|
|
|
{
|
2011-06-03 15:28:42 +02:00
|
|
|
$this->_list_sources();
|
|
|
|
|
2011-05-21 12:25:39 +02:00
|
|
|
if ($this->sources[$p['id']]) {
|
|
|
|
$p['instance'] = $this->sources[$p['id']];
|
|
|
|
}
|
2011-06-02 09:45:04 +02:00
|
|
|
|
2011-05-21 12:25:39 +02:00
|
|
|
return $p;
|
|
|
|
}
|
2011-06-02 09:45:04 +02:00
|
|
|
|
|
|
|
|
2011-05-21 12:25:39 +02:00
|
|
|
private function _list_sources()
|
|
|
|
{
|
|
|
|
// already read sources
|
|
|
|
if (isset($this->sources))
|
|
|
|
return $this->sources;
|
|
|
|
|
2011-06-08 11:33:18 +02:00
|
|
|
$this->sources = array();
|
2011-07-08 17:39:03 +02:00
|
|
|
|
2011-06-08 11:33:18 +02:00
|
|
|
// Load configuration
|
|
|
|
$this->load_config();
|
|
|
|
|
|
|
|
$abook_prio = (int) $this->rc->config->get('kolab_addressbook_prio');
|
|
|
|
|
|
|
|
// Personal address source(s) disabled?
|
|
|
|
if ($abook_prio == self::GLOBAL_ONLY) {
|
|
|
|
return $this->sources;
|
|
|
|
}
|
|
|
|
|
2011-05-21 12:25:39 +02:00
|
|
|
// get all folders that have "contact" type
|
|
|
|
$this->folders = rcube_kolab::get_folders('contact');
|
2011-07-08 17:39:03 +02:00
|
|
|
|
2011-05-21 12:25:39 +02:00
|
|
|
if (PEAR::isError($this->folders)) {
|
|
|
|
raise_error(array(
|
|
|
|
'code' => 600, 'type' => 'php',
|
|
|
|
'file' => __FILE__, 'line' => __LINE__,
|
|
|
|
'message' => "Failed to list contact folders from Kolab server:" . $this->folders->getMessage()),
|
|
|
|
true, false);
|
|
|
|
}
|
|
|
|
else {
|
2011-06-27 13:44:27 +02:00
|
|
|
// convert to UTF8 and sort
|
|
|
|
$names = array();
|
|
|
|
foreach ($this->folders as $c_folder)
|
|
|
|
$names[$c_folder->name] = rcube_charset_convert($c_folder->name, 'UTF7-IMAP');
|
|
|
|
|
|
|
|
asort($names, SORT_LOCALE_STRING);
|
|
|
|
|
|
|
|
foreach ($names as $utf7name => $name) {
|
2011-05-21 12:25:39 +02:00
|
|
|
// create instance of rcube_contacts
|
2011-06-27 13:44:27 +02:00
|
|
|
$abook_id = rcube_kolab::folder_id($utf7name);
|
|
|
|
$abook = new rcube_kolab_contacts($utf7name);
|
2011-05-21 12:25:39 +02:00
|
|
|
$this->sources[$abook_id] = $abook;
|
|
|
|
}
|
|
|
|
}
|
2011-07-08 17:39:03 +02:00
|
|
|
|
2011-05-21 12:25:39 +02:00
|
|
|
return $this->sources;
|
|
|
|
}
|
2011-06-02 09:45:04 +02:00
|
|
|
|
|
|
|
|
2011-05-21 12:25:39 +02:00
|
|
|
/**
|
|
|
|
* Plugin hook called before rendering the contact form or detail view
|
2011-06-08 11:33:18 +02:00
|
|
|
*
|
|
|
|
* @param array $p Hash array with hook parameters
|
|
|
|
*
|
|
|
|
* @return array Hash array with modified hook parameters
|
2011-05-21 12:25:39 +02:00
|
|
|
*/
|
|
|
|
public function contact_form($p)
|
|
|
|
{
|
|
|
|
// none of our business
|
|
|
|
if (!is_a($GLOBALS['CONTACTS'], 'rcube_kolab_contacts'))
|
|
|
|
return $p;
|
2011-06-02 09:45:04 +02:00
|
|
|
|
2011-05-21 12:25:39 +02:00
|
|
|
// extend the list of contact fields to be displayed in the 'personal' section
|
|
|
|
if (is_array($p['form']['personal'])) {
|
|
|
|
$p['form']['contact']['content']['officelocation'] = array('size' => 40);
|
2011-06-02 10:33:29 +02:00
|
|
|
$p['form']['personal']['content']['initials'] = array('size' => 6);
|
|
|
|
$p['form']['personal']['content']['profession'] = array('size' => 40);
|
|
|
|
$p['form']['personal']['content']['children'] = array('size' => 40);
|
|
|
|
$p['form']['personal']['content']['pgppublickey'] = array('size' => 40);
|
|
|
|
$p['form']['personal']['content']['freebusyurl'] = array('size' => 40);
|
2011-06-02 09:45:04 +02:00
|
|
|
|
2011-05-21 12:25:39 +02:00
|
|
|
// re-order fields according to the coltypes list
|
2011-06-02 10:33:29 +02:00
|
|
|
$p['form']['contact']['content'] = $this->_sort_form_fields($p['form']['contact']['content']);
|
2011-05-21 12:25:39 +02:00
|
|
|
$p['form']['personal']['content'] = $this->_sort_form_fields($p['form']['personal']['content']);
|
2011-06-02 09:45:04 +02:00
|
|
|
|
2011-05-21 12:25:39 +02:00
|
|
|
/* define a separate section 'settings'
|
|
|
|
$p['form']['settings'] = array(
|
2011-06-02 10:33:29 +02:00
|
|
|
'name' => $this->gettext('settings'),
|
2011-05-21 12:25:39 +02:00
|
|
|
'content' => array(
|
|
|
|
'pgppublickey' => array('size' => 40, 'visible' => true),
|
|
|
|
'freebusyurl' => array('size' => 40, 'visible' => true),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
*/
|
|
|
|
}
|
2011-06-02 09:45:04 +02:00
|
|
|
|
2011-05-21 12:25:39 +02:00
|
|
|
return $p;
|
|
|
|
}
|
2011-06-02 09:45:04 +02:00
|
|
|
|
|
|
|
|
2011-05-21 12:25:39 +02:00
|
|
|
private function _sort_form_fields($contents)
|
|
|
|
{
|
|
|
|
$block = array();
|
|
|
|
$contacts = reset($this->sources);
|
|
|
|
foreach ($contacts->coltypes as $col => $prop) {
|
|
|
|
if (isset($contents[$col]))
|
|
|
|
$block[$col] = $contents[$col];
|
|
|
|
}
|
2011-06-02 09:45:04 +02:00
|
|
|
|
2011-05-21 12:25:39 +02:00
|
|
|
return $block;
|
|
|
|
}
|
|
|
|
|
2011-06-08 11:33:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load configuration
|
|
|
|
$this->load_config();
|
|
|
|
|
2011-06-27 13:44:27 +02:00
|
|
|
// Load localization
|
2011-06-08 11:33:18 +02:00
|
|
|
$this->add_texts('localization');
|
|
|
|
|
|
|
|
// Check that configuration is not disabled
|
|
|
|
$dont_override = (array) $this->rc->config->get('dont_override', array());
|
|
|
|
|
|
|
|
if (!in_array('kolab_addressbook_prio', $dont_override)) {
|
|
|
|
$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((int)$this->rc->config->get('kolab_addressbook_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load configuration
|
|
|
|
$this->load_config();
|
|
|
|
|
|
|
|
// Check that configuration is not disabled
|
|
|
|
$dont_override = (array) $this->rc->config->get('dont_override', array());
|
|
|
|
|
|
|
|
if (!in_array('kolab_addressbook_prio', $dont_override)) {
|
|
|
|
$key = 'kolab_addressbook_prio';
|
|
|
|
$args['prefs'][$key] = (int) get_input_value('_'.$key, RCUBE_INPUT_POST);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $args;
|
|
|
|
}
|
|
|
|
|
2011-06-27 13:44:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for plugin actions
|
|
|
|
*/
|
|
|
|
public function book_actions()
|
|
|
|
{
|
|
|
|
$action = trim(get_input_value('_act', RCUBE_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()
|
|
|
|
{
|
|
|
|
$folder = trim(get_input_value('_name', RCUBE_INPUT_POST, true, 'UTF7-IMAP'));
|
|
|
|
$oldfolder = trim(get_input_value('_oldname', RCUBE_INPUT_POST, true)); // UTF7-IMAP
|
|
|
|
$path = trim(get_input_value('_parent', RCUBE_INPUT_POST, true)); // UTF7-IMAP
|
|
|
|
$delimiter = $_SESSION['imap_delimiter'];
|
2011-06-27 14:10:00 +02:00
|
|
|
|
2011-08-01 12:44:30 +02:00
|
|
|
if (strlen($oldfolder)) {
|
|
|
|
$this->rc->imap_connect();
|
|
|
|
$options = $this->rc->imap->mailbox_info($oldfolder);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($options) && ($options['norename'] || $options['protected'])) {
|
|
|
|
}
|
2011-06-27 13:44:27 +02:00
|
|
|
// sanity checks (from steps/settings/save_folder.inc)
|
2011-08-01 12:44:30 +02:00
|
|
|
else if (!strlen($folder)) {
|
2011-06-27 13:44:27 +02:00
|
|
|
$error = rcube_label('cannotbeempty');
|
|
|
|
}
|
2011-07-26 10:32:09 +02:00
|
|
|
else if (strlen($folder) > 128) {
|
2011-06-27 13:44:27 +02:00
|
|
|
$error = rcube_label('nametoolong');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// these characters are problematic e.g. when used in LIST/LSUB
|
|
|
|
foreach (array($delimiter, '%', '*') as $char) {
|
2011-07-26 10:32:09 +02:00
|
|
|
if (strpos($folder, $delimiter) !== false) {
|
2011-06-27 13:44:27 +02:00
|
|
|
$error = rcube_label('forbiddencharacter') . " ($char)";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$error) {
|
2011-08-01 12:44:30 +02:00
|
|
|
if (!empty($options) && ($options['protected'] || $options['norename'])) {
|
2011-06-27 13:44:27 +02:00
|
|
|
$folder = $oldfolder;
|
|
|
|
}
|
|
|
|
else if (strlen($path)) {
|
|
|
|
$folder = $path . $delimiter . $folder;
|
|
|
|
}
|
|
|
|
else {
|
2011-06-27 14:10:00 +02:00
|
|
|
// add namespace prefix (when needed)
|
|
|
|
$this->rc->imap_init();
|
|
|
|
$folder = $this->rc->imap->mod_mailbox($folder, 'in');
|
2011-06-27 13:44:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// update the folder name
|
|
|
|
if (strlen($oldfolder)) {
|
|
|
|
$type = 'update';
|
|
|
|
$plugin = $this->rc->plugins->exec_hook('addressbook_update', array(
|
|
|
|
'name' => $folder, 'oldname' => $oldfolder));
|
|
|
|
|
|
|
|
if (!$plugin['abort']) {
|
|
|
|
if ($oldfolder != $folder)
|
|
|
|
$result = rcube_kolab::folder_rename($oldfolder, $folder);
|
|
|
|
else
|
|
|
|
$result = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$result = $plugin['result'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// create new folder
|
|
|
|
else {
|
|
|
|
$type = 'create';
|
|
|
|
$plugin = $this->rc->plugins->exec_hook('addressbook_create', array('name' => $folder));
|
|
|
|
|
|
|
|
$folder = $plugin['name'];
|
|
|
|
|
|
|
|
if (!$plugin['abort']) {
|
|
|
|
$result = rcube_kolab::folder_create($folder, 'contact', false);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$result = $plugin['result'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
$kolab_folder = new rcube_kolab_contacts($folder);
|
|
|
|
|
|
|
|
// create display name for the folder (see self::address_sources())
|
|
|
|
if (strpos($folder, $delimiter)) {
|
|
|
|
$names = array();
|
|
|
|
foreach ($this->_list_sources() as $abook_id => $abook) {
|
|
|
|
$realname = $abook->get_realname();
|
|
|
|
// The list can be not updated yet, handle old folder name
|
|
|
|
if ($type == 'update' && $realname == $oldfolder) {
|
|
|
|
$abook = $kolab_folder;
|
|
|
|
$realname = $folder;
|
|
|
|
}
|
|
|
|
|
|
|
|
$name = $origname = $abook->get_name();
|
|
|
|
|
|
|
|
// find folder prefix to truncate
|
|
|
|
for ($i = count($names)-1; $i >= 0; $i--) {
|
|
|
|
if (strpos($name, $names[$i].' » ') === 0) {
|
|
|
|
$length = strlen($names[$i].' » ');
|
|
|
|
$prefix = substr($name, 0, $length);
|
|
|
|
$count = count(explode(' » ', $prefix));
|
|
|
|
$name = str_repeat(' ', $count-1) . '» ' . substr($name, $length);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$names[] = $origname;
|
|
|
|
|
|
|
|
if ($realname == $folder) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$name = $kolab_folder->get_name();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->rc->output->show_message('kolab_addressbook.book'.$type.'d', 'confirmation');
|
|
|
|
$this->rc->output->command('set_env', 'delimiter', $delimiter);
|
|
|
|
$this->rc->output->command('book_update', array(
|
|
|
|
'id' => rcube_kolab::folder_id($folder),
|
|
|
|
'name' => $name,
|
|
|
|
'readonly' => false,
|
|
|
|
'editable' => true,
|
|
|
|
'groups' => true,
|
|
|
|
'realname' => rcube_charset_convert($folder, 'UTF7-IMAP'), // IMAP folder name
|
2011-06-27 17:53:10 +02:00
|
|
|
'class_name' => $kolab_folder->get_namespace(),
|
2011-06-27 13:44:27 +02:00
|
|
|
'kolab' => true,
|
|
|
|
), rcube_kolab::folder_id($oldfolder));
|
|
|
|
|
|
|
|
$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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for address book delete action (AJAX)
|
|
|
|
*/
|
|
|
|
private function book_delete()
|
|
|
|
{
|
|
|
|
$folder = trim(get_input_value('_source', RCUBE_INPUT_GPC, true, 'UTF7-IMAP'));
|
|
|
|
|
|
|
|
if (rcube_kolab::folder_delete($folder)) {
|
|
|
|
$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('list_contacts_clear');
|
|
|
|
$this->rc->output->command('book_delete_done', rcube_kolab::folder_id($folder));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$this->rc->output->show_message('kolab_addressbook.bookdeleteerror', 'error');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->rc->output->send();
|
|
|
|
}
|
2011-05-21 12:25:39 +02:00
|
|
|
}
|