Fix editing of remote calendars.
authorJan Schneider <jan@horde.org>
Fri, 16 Apr 2010 15:32:51 +0000 (17:32 +0200)
committerJan Schneider <jan@horde.org>
Fri, 16 Apr 2010 15:32:51 +0000 (17:32 +0200)
kronolith/lib/Ajax/Application.php
kronolith/lib/Forms/EditRemoteCalendar.php
kronolith/lib/Forms/SubscribeRemoteCalendar.php
kronolith/lib/Kronolith.php
kronolith/templates/chunks/calendar.php

index 22314ea..df6f234 100644 (file)
@@ -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;
index 727a761..3052957 100644 (file)
@@ -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')));
     }
 
 }
index 49aab5d..3865984 100644 (file)
@@ -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);
index cbb0a66..2d134a3 100644 (file)
@@ -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));
     }
index 08d9c0d..e5547a2 100644 (file)
@@ -209,7 +209,7 @@ $file_upload = $GLOBALS['browser']->allowFileUploads();
 
 <div>
   <label><?php echo _("Username") ?>:<br />
-    <input type="text" name="username" id="kronolithCalendarremoteUsername" class="kronolithLongField" />
+    <input type="text" name="user" id="kronolithCalendarremoteUsername" class="kronolithLongField" />
   </label>
 </div>
 
@@ -234,7 +234,7 @@ $file_upload = $GLOBALS['browser']->allowFileUploads();
 
 <div>
   <label><?php echo _("Description") ?>:<br />
-    <textarea name="description" id="kronolithCalendarremoteDescription" rows="5" cols="40" class="kronolithLongField"></textarea>
+    <textarea name="desc" id="kronolithCalendarremoteDescription" rows="5" cols="40" class="kronolithLongField"></textarea>
   </label>
 </div>