Basic remove/create/edit calendar methods implementation, with color in user preferences

This commit is contained in:
Aleksander Machniak (Kolab Systems) 2011-06-27 15:49:51 +02:00
parent 73ed987bb9
commit 6f296d0928
2 changed files with 94 additions and 21 deletions

View file

@ -12,6 +12,7 @@
| | | |
+-------------------------------------------------------------------------+ +-------------------------------------------------------------------------+
| Author: Thomas Bruederli <roundcube@gmail.com> | | Author: Thomas Bruederli <roundcube@gmail.com> |
| Author: Aleksander Machniak <machniak@kolabsys.com> |
+-------------------------------------------------------------------------+ +-------------------------------------------------------------------------+
*/ */
@ -76,6 +77,18 @@ class kolab_calendar
return rcube_charset_convert(strlen($dispname) ? $dispname : $this->imap_folder, "UTF7-IMAP"); 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) * Getter for the top-end calendar folder name (not the entire path)
* *
@ -84,19 +97,21 @@ class kolab_calendar
public function get_foldername() public function get_foldername()
{ {
$parts = explode('/', $this->imap_folder); $parts = explode('/', $this->imap_folder);
return end($parts); return rcube_charset_convert(end($parts), 'UTF7-IMAP');
} }
/** /**
* Return color to display this calendar * Return color to display this calendar
*/ */
public function get_color($owner) public function get_color()
{ {
// TODO: read color from backend (not yet supported) // Store temporarily calendar color in user prefs (will be changed)
//temporary color deffirence between own calendars and the rest $prefs = $this->cal->rc->config->get('kolab_calendars', array());
if ($owner == $_SESSION['username'])
return 'd63355'; if (!empty($prefs[$this->id]) && !empty($prefs[$this->id]['color']))
return '1f9ebe'; return $prefs[$this->id]['color'];
return 'cc0000';
} }

View file

@ -71,7 +71,7 @@ class kolab_driver extends calendar_driver
'id' => $calendar->id, 'id' => $calendar->id,
'name' => $calendar->get_name(), 'name' => $calendar->get_name(),
'editname' => $calendar->get_foldername(), 'editname' => $calendar->get_foldername(),
'color' => $calendar->get_color($c_folder->_owner), 'color' => $calendar->get_color(),
'readonly' => $c_folder->_owner != $_SESSION['username'], 'readonly' => $c_folder->_owner != $_SESSION['username'],
); );
} }
@ -117,10 +117,30 @@ class kolab_driver extends calendar_driver
*/ */
public function create_calendar($prop) 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; return false;
} }
/** /**
* Update properties of an existing calendar * Update properties of an existing calendar
* *
@ -128,9 +148,36 @@ class kolab_driver extends calendar_driver
*/ */
public function edit_calendar($prop) 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; return false;
} }
/** /**
* Delete the given calendar with all its contents * Delete the given calendar with all its contents
* *
@ -138,6 +185,17 @@ class kolab_driver extends calendar_driver
*/ */
public function remove_calendar($prop) 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; return false;
} }