Basic remove/create/edit calendar methods implementation, with color in user preferences
This commit is contained in:
parent
73ed987bb9
commit
6f296d0928
2 changed files with 94 additions and 21 deletions
|
@ -12,6 +12,7 @@
|
|||
| |
|
||||
+-------------------------------------------------------------------------+
|
||||
| Author: Thomas Bruederli <roundcube@gmail.com> |
|
||||
| Author: Aleksander Machniak <machniak@kolabsys.com> |
|
||||
+-------------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
|
@ -20,7 +21,7 @@ class kolab_calendar
|
|||
public $id;
|
||||
public $ready = false;
|
||||
public $readonly = true;
|
||||
|
||||
|
||||
private $cal;
|
||||
private $storage;
|
||||
private $events;
|
||||
|
@ -29,7 +30,7 @@ class kolab_calendar
|
|||
private $sensitivity_map = array('public', 'private', 'confidential');
|
||||
private $priority_map = array('low', 'normal', 'high');
|
||||
|
||||
|
||||
|
||||
private $fieldmap = array(
|
||||
// kolab => roundcube
|
||||
'summary' => 'title',
|
||||
|
@ -42,14 +43,14 @@ class kolab_calendar
|
|||
'show-time-as' => 'free_busy',
|
||||
'alarm','alarms'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public function __construct($imap_folder, $calendar)
|
||||
{
|
||||
$this->cal = $calendar;
|
||||
|
||||
|
||||
if (strlen($imap_folder))
|
||||
$this->imap_folder = $imap_folder;
|
||||
|
||||
|
@ -75,7 +76,19 @@ class kolab_calendar
|
|||
$dispname = preg_replace(array('!INBOX/Calendar/!', '!^INBOX/!', '!^shared/!', '!^user/([^/]+)/!'), array('','','','(\\1) '), $this->imap_folder);
|
||||
return rcube_charset_convert(strlen($dispname) ? $dispname : $this->imap_folder, "UTF7-IMAP");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Getter for the IMAP folder name
|
||||
*
|
||||
* @return string Name of the IMAP folder
|
||||
*/
|
||||
public function get_realname()
|
||||
{
|
||||
return $this->imap_folder;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Getter for the top-end calendar folder name (not the entire path)
|
||||
*
|
||||
|
@ -84,22 +97,24 @@ class kolab_calendar
|
|||
public function get_foldername()
|
||||
{
|
||||
$parts = explode('/', $this->imap_folder);
|
||||
return end($parts);
|
||||
return rcube_charset_convert(end($parts), 'UTF7-IMAP');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return color to display this calendar
|
||||
*/
|
||||
public function get_color($owner)
|
||||
public function get_color()
|
||||
{
|
||||
// TODO: read color from backend (not yet supported)
|
||||
//temporary color deffirence between own calendars and the rest
|
||||
if ($owner == $_SESSION['username'])
|
||||
return 'd63355';
|
||||
return '1f9ebe';
|
||||
// Store temporarily calendar color in user prefs (will be changed)
|
||||
$prefs = $this->cal->rc->config->get('kolab_calendars', array());
|
||||
|
||||
if (!empty($prefs[$this->id]) && !empty($prefs[$this->id]['color']))
|
||||
return $prefs[$this->id]['color'];
|
||||
|
||||
return 'cc0000';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Getter for a single event object
|
||||
*/
|
||||
|
|
|
@ -71,7 +71,7 @@ class kolab_driver extends calendar_driver
|
|||
'id' => $calendar->id,
|
||||
'name' => $calendar->get_name(),
|
||||
'editname' => $calendar->get_foldername(),
|
||||
'color' => $calendar->get_color($c_folder->_owner),
|
||||
'color' => $calendar->get_color(),
|
||||
'readonly' => $c_folder->_owner != $_SESSION['username'],
|
||||
);
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ class kolab_driver extends calendar_driver
|
|||
if ($this->create_calendar(array('name' => 'Default', 'color' => 'cc0000')))
|
||||
$this->_read_calendars();
|
||||
}
|
||||
|
||||
|
||||
return $this->calendars;
|
||||
}
|
||||
|
||||
|
@ -117,10 +117,30 @@ class kolab_driver extends calendar_driver
|
|||
*/
|
||||
public function create_calendar($prop)
|
||||
{
|
||||
|
||||
$folder = rcube_charset_convert($prop['name'], RCMAIL_CHARSET, 'UTF7-IMAP');
|
||||
|
||||
// add namespace prefix (when needed)
|
||||
$this->rc->imap_init();
|
||||
$folder = $this->rc->imap->mod_mailbox($folder, 'in');
|
||||
|
||||
// create ID
|
||||
$id = rcube_kolab::folder_id($folder);
|
||||
|
||||
// create IMAP folder
|
||||
if (rcube_kolab::folder_create($folder, 'event')) {
|
||||
// save color in user prefs (temp. solution)
|
||||
$prefs['kolab_calendars'] = $this->rc->config->get('kolab_calendars', array());
|
||||
$prefs['kolab_calendars'][$id]['color'] = $prop['color'];
|
||||
|
||||
$this->rc->user->save_prefs($prefs);
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update properties of an existing calendar
|
||||
*
|
||||
|
@ -128,9 +148,36 @@ class kolab_driver extends calendar_driver
|
|||
*/
|
||||
public function edit_calendar($prop)
|
||||
{
|
||||
if ($prop['id'] && ($cal = $this->folders[$prop['id']])) {
|
||||
$newfolder = rcube_charset_convert($prop['name'], RCMAIL_CHARSET, 'UTF7-IMAP');
|
||||
$oldfolder = $cal->get_realname();
|
||||
// add namespace prefix (when needed)
|
||||
$this->rc->imap_init();
|
||||
$newfolder = $this->rc->imap->mod_mailbox($newfolder, 'in');
|
||||
|
||||
if ($newfolder != $oldfolder)
|
||||
$result = rcube_kolab::folder_rename($oldfolder, $newfolder);
|
||||
else
|
||||
$result = true;
|
||||
|
||||
if ($result) {
|
||||
// create ID
|
||||
$id = rcube_kolab::folder_id($newfolder);
|
||||
// save color in user prefs (temp. solution)
|
||||
$prefs['kolab_calendars'] = $this->rc->config->get('kolab_calendars', array());
|
||||
$prefs['kolab_calendars'][$id]['color'] = $prop['color'];
|
||||
unset($prefs['kolab_calendars'][$prop['id']]);
|
||||
|
||||
$this->rc->user->save_prefs($prefs);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete the given calendar with all its contents
|
||||
*
|
||||
|
@ -138,7 +185,18 @@ class kolab_driver extends calendar_driver
|
|||
*/
|
||||
public function remove_calendar($prop)
|
||||
{
|
||||
|
||||
if ($prop['id'] && ($cal = $this->folders[$prop['id']])) {
|
||||
$folder = $cal->get_realname();
|
||||
if (rcube_kolab::folder_delete($folder)) {
|
||||
// remove color in user prefs (temp. solution)
|
||||
$prefs['kolab_calendars'] = $this->rc->config->get('kolab_calendars', array());
|
||||
unset($prefs['kolab_calendars'][$prop['id']]);
|
||||
|
||||
$this->rc->user->save_prefs($prefs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -153,7 +211,7 @@ class kolab_driver extends calendar_driver
|
|||
$cid = $event['calendar'] ? $event['calendar'] : reset(array_keys($this->calendars));
|
||||
if ($storage = $this->_get_storage($cid))
|
||||
return $storage->insert_event($event);
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -167,7 +225,7 @@ class kolab_driver extends calendar_driver
|
|||
{
|
||||
if ($storage = $this->_get_storage($event['calendar']))
|
||||
return $storage->update_event($event);
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -181,7 +239,7 @@ class kolab_driver extends calendar_driver
|
|||
{
|
||||
if (($storage = $this->_get_storage($event['calendar'])) && ($ev = $storage->get_event($event['id'])))
|
||||
return $storage->update_event($event + $ev);
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue