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;
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')));
}
}
$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")));
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);
}
/**
- * 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."));
}
$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));
}
<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>
<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>