From 18d77e9827164a7133c73dfd0c51baa620f92be7 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Fri, 16 Apr 2010 17:32:51 +0200 Subject: [PATCH] Fix editing of remote calendars. --- kronolith/lib/Ajax/Application.php | 4 ++-- kronolith/lib/Forms/EditRemoteCalendar.php | 25 +----------------------- kronolith/lib/Forms/SubscribeRemoteCalendar.php | 6 +++--- kronolith/lib/Kronolith.php | 26 ++++++++++++++----------- kronolith/templates/chunks/calendar.php | 4 ++-- 5 files changed, 23 insertions(+), 42 deletions(-) diff --git a/kronolith/lib/Ajax/Application.php b/kronolith/lib/Ajax/Application.php index 22314ea52..df6f2342e 100644 --- a/kronolith/lib/Ajax/Application.php +++ b/kronolith/lib/Ajax/Application.php @@ -603,11 +603,11 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base case 'remote': $calendar = array(); - foreach (array('name', 'description', 'url', 'color', 'username', 'password') as $key) { + foreach (array('name', 'desc', 'url', 'color', 'user', 'password') as $key) { $calendar[$key] = $this->_vars->$key; } try { - Kronolith::subscribeRemoteCalendar($calendar); + Kronolith::subscribeRemoteCalendar($calendar, $calendar_id); } catch (Exception $e) { $GLOBALS['notification']->push($e, 'horde.error'); return $result; diff --git a/kronolith/lib/Forms/EditRemoteCalendar.php b/kronolith/lib/Forms/EditRemoteCalendar.php index 727a7617d..3052957d2 100644 --- a/kronolith/lib/Forms/EditRemoteCalendar.php +++ b/kronolith/lib/Forms/EditRemoteCalendar.php @@ -42,30 +42,7 @@ class Kronolith_EditRemoteCalendarForm extends Horde_Form foreach (array('name', 'new_url', 'user', 'password', 'color', 'desc') as $key) { $info[$key == 'new_url' ? 'url' : $key] = $this->_vars->get($key); } - $url = trim($this->_vars->get('url')); - - if (!strlen($info['name']) || !strlen($url)) { - return false; - } - - if (strlen($info['username']) || strlen($info['password'])) { - $key = Horde_Auth::getCredential('password'); - if ($key) { - $secret = $GLOBALS['injector']->getInstance('Horde_Secret'); - $info['username'] = base64_encode($secret->write($key, $info['username'])); - $info['password'] = base64_encode($secret->write($key, $info['password'])); - } - } - - $remote_calendars = unserialize($GLOBALS['prefs']->getValue('remote_cals')); - foreach ($remote_calendars as $key => $calendar) { - if ($calendar['url'] == $url) { - $remote_calendars[$key] = $info; - break; - } - } - - $GLOBALS['prefs']->setValue('remote_cals', serialize($remote_calendars)); + Kronolith::subscribeRemoteCalendar($info, trim($this->_vars->get('url'))); } } diff --git a/kronolith/lib/Forms/SubscribeRemoteCalendar.php b/kronolith/lib/Forms/SubscribeRemoteCalendar.php index 49aab5d58..386598404 100644 --- a/kronolith/lib/Forms/SubscribeRemoteCalendar.php +++ b/kronolith/lib/Forms/SubscribeRemoteCalendar.php @@ -24,8 +24,8 @@ class Kronolith_SubscribeRemoteCalendarForm extends Horde_Form $this->addVariable(_("Name"), 'name', 'text', true); $this->addVariable(_("Color"), 'color', 'colorpicker', false); $this->addVariable(_("URL"), 'url', 'text', true); - $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60)); - $this->addVariable(_("Username"), 'username', 'text', false); + $this->addVariable(_("Description"), 'desc', 'longtext', false, false, null, array(4, 60)); + $this->addVariable(_("Username"), 'user', 'text', false); $this->addVariable(_("Password"), 'password', 'password', false); $this->setButtons(array(_("Subscribe"))); @@ -37,7 +37,7 @@ class Kronolith_SubscribeRemoteCalendarForm extends Horde_Form public function execute() { $info = array(); - foreach (array('name', 'url', 'color', 'username', 'password') as $key) { + foreach (array('name', 'url', 'user', 'password', 'color', 'desc') as $key) { $info[$key] = $this->_vars->get($key); } Kronolith::subscribeRemoteCalendar($info); diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index cbb0a66a8..2d134a355 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -1770,13 +1770,15 @@ class Kronolith } /** - * Subscribes to a remote calendar. + * Subscribes to or updates a remote calendar. * - * @param array $info Hash with calendar information. + * @param array $info Hash with calendar information. + * @param string $update If present, the original URL of the calendar to + * update. * * @throws Kronolith_Exception */ - public static function subscribeRemoteCalendar($info) + public static function subscribeRemoteCalendar($info, $update = false) { if (!(strlen($info['name']) && strlen($info['url']))) { throw new Kronolith_Exception(_("You must specify a name and a URL.")); @@ -1792,14 +1794,16 @@ class Kronolith } $remote_calendars = unserialize($GLOBALS['prefs']->getValue('remote_cals')); - $remote_calendars[] = array( - 'name' => $info['name'], - 'desc' => $info['description'], - 'url' => $info['url'], - 'color' => $info['color'], - 'user' => $info['username'], - 'password' => $info['password'], - ); + if ($update) { + foreach ($remote_calendars as $key => $calendar) { + if ($calendar['url'] == $update) { + $remote_calendars[$key] = $info; + break; + } + } + } else { + $remote_calendars[] = $info; + } $GLOBALS['prefs']->setValue('remote_cals', serialize($remote_calendars)); } diff --git a/kronolith/templates/chunks/calendar.php b/kronolith/templates/chunks/calendar.php index 08d9c0d12..e5547a2df 100644 --- a/kronolith/templates/chunks/calendar.php +++ b/kronolith/templates/chunks/calendar.php @@ -209,7 +209,7 @@ $file_upload = $GLOBALS['browser']->allowFileUploads();
@@ -234,7 +234,7 @@ $file_upload = $GLOBALS['browser']->allowFileUploads();
-- 2.11.0