Copyright 2010-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (GPL). If you did not receive this file, see http://www.horde.org/licenses/gpl.
Author: Jan Schneider (jan@horde.org)
Inheritance: extends Kronolith_Calendar
Exemplo n.º 1
0
 } else {
     $calendar_id = $targetcalendar;
     $user = $GLOBALS['registry']->getAuth();
 }
 try {
     /* Permission checks on the target calendar . */
     switch ($targetType) {
         case 'internal':
             $kronolith_calendar = $GLOBALS['calendar_manager']->getEntry(Kronolith::ALL_CALENDARS, $calendar_id);
             break;
         case 'remote':
             $kronolith_calendar = $GLOBALS['calendar_manager']->getEntry(Kronolith::ALL_REMOTE_CALENDARS, $calendar_id);
             break;
         case 'resource':
             $rid = Kronolith::getDriver('Resource')->getResourceIdByCalendar($calendar_id);
             $kronolith_calendar = new Kronolith_Calendar_Resource(array('resource' => Kronolith::getDriver('Resource')->getResource($rid)));
             break;
         default:
             break 2;
     }
     if ($user == $GLOBALS['registry']->getAuth() && !$kronolith_calendar->hasPermission(Horde_Perms::EDIT)) {
         $notification->push(_("You do not have permission to add events to this calendar."), 'horde.warning');
         break;
     }
     if ($user != $GLOBALS['registry']->getAuth() && !$kronolith_calendar->hasPermission(Kronolith::PERMS_DELEGATE)) {
         $notification->push(_("You do not have permission to delegate events to this user."), 'horde.warning');
         break;
     }
     $perms = $GLOBALS['injector']->getInstance('Horde_Core_Perms');
     if ($perms->hasAppPermission('max_events') !== true && $perms->hasAppPermission('max_events') <= Kronolith::countEvents()) {
         Horde::permissionDeniedError('kronolith', 'max_events', sprintf(_("You are not allowed to create more than %d events."), $perms->hasAppPermission('max_events')));
Exemplo n.º 2
0
 /**
  * TODO
  */
 public function saveCalendar()
 {
     global $calendar_manager, $injector, $notification, $prefs, $registry, $session;
     $calendar_id = $this->vars->calendar;
     $result = new stdClass();
     switch ($this->vars->type) {
         case 'internal':
             $info = array();
             foreach (array('name', 'color', 'description', 'tags', 'system') as $key) {
                 $info[$key] = $this->vars->{$key};
             }
             // Create a calendar.
             if (!$calendar_id) {
                 if (!$registry->getAuth() || $prefs->isLocked('default_share')) {
                     return $result;
                 }
                 try {
                     $calendar = Kronolith::addShare($info);
                     Kronolith::readPermsForm($calendar);
                     if ($calendar->hasPermission($registry->getAuth(), Horde_Perms::SHOW)) {
                         $wrapper = new Kronolith_Calendar_Internal(array('share' => $calendar));
                         $result->saved = true;
                         $result->id = $calendar->getName();
                         $result->calendar = $wrapper->toHash();
                     }
                 } catch (Exception $e) {
                     $notification->push($e, 'horde.error');
                     return $result;
                 }
                 $notification->push(sprintf(_("The calendar \"%s\" has been created."), $info['name']), 'horde.success');
                 break;
             }
             // Update a calendar.
             try {
                 $calendar = $injector->getInstance('Kronolith_Shares')->getShare($calendar_id);
                 $original_name = $calendar->get('name');
                 $original_owner = $calendar->get('owner');
                 Kronolith::updateShare($calendar, $info);
                 Kronolith::readPermsForm($calendar);
                 if (!$info['system'] && $calendar->get('owner') != $original_owner || $info['system'] && !is_null($original_owner)) {
                     $result->deleted = true;
                 }
                 if ($calendar->hasPermission($registry->getAuth(), Horde_Perms::SHOW) || is_null($calendar->get('owner')) && $registry->isAdmin()) {
                     $wrapper = new Kronolith_Calendar_Internal(array('share' => $calendar));
                     $result->saved = true;
                     $result->id = $calendar->getName();
                     $result->calendar = $wrapper->toHash();
                 }
             } catch (Exception $e) {
                 $notification->push($e, 'horde.error');
                 return $result;
             }
             if ($calendar->get('name') != $original_name) {
                 $notification->push(sprintf(_("The calendar \"%s\" has been renamed to \"%s\"."), $original_name, $calendar->get('name')), 'horde.success');
             } else {
                 $notification->push(sprintf(_("The calendar \"%s\" has been saved."), $original_name), 'horde.success');
             }
             break;
         case 'tasklists':
             $calendar = array();
             foreach (array('name', 'color', 'description') as $key) {
                 $calendar[$key] = $this->vars->{$key};
             }
             // Create a task list.
             if (!$calendar_id) {
                 if (!$registry->getAuth() || $prefs->isLocked('default_share')) {
                     return $result;
                 }
                 try {
                     $tasklistId = $registry->tasks->addTasklist($calendar['name'], $calendar['description'], $calendar['color']);
                     $tasklists = $registry->tasks->listTasklists(true);
                     if (!isset($tasklists[$tasklistId])) {
                         $notification->push(_("Added task list not found."), 'horde.error');
                         return $result;
                     }
                     $tasklist = $tasklists[$tasklistId];
                     Kronolith::readPermsForm($tasklist);
                     if ($tasklist->hasPermission($registry->getAuth(), Horde_Perms::SHOW)) {
                         $wrapper = new Kronolith_Calendar_External_Tasks(array('api' => 'tasks', 'name' => $tasklistId, 'share' => $tasklist));
                         // Update external calendars caches.
                         $all_external = $session->get('kronolith', 'all_external_calendars');
                         $all_external[] = array('a' => 'tasks', 'n' => $tasklistId, 'd' => $tasklist->get('name'));
                         $session->set('kronolith', 'all_external_calendars', $all_external);
                         $display_external = $calendar_manager->get(Kronolith::DISPLAY_EXTERNAL_CALENDARS);
                         $display_external[] = 'tasks/' . $tasklistId;
                         $calendar_manager->set(Kronolith::DISPLAY_EXTERNAL_CALENDARS, $display_external);
                         $prefs->setValue('display_external_cals', serialize($display_external));
                         $all_external = $calendar_manager->get(Kronolith::ALL_EXTERNAL_CALENDARS);
                         $all_external['tasks/' . $tasklistId] = $wrapper;
                         $calendar_manager->set(Kronolith::ALL_EXTERNAL_CALENDARS, $all_external);
                         $result->saved = true;
                         $result->id = 'tasks/' . $tasklistId;
                         $result->calendar = $wrapper->toHash();
                     }
                 } catch (Exception $e) {
                     $notification->push($e, 'horde.error');
                     return $result;
                 }
                 $notification->push(sprintf(_("The task list \"%s\" has been created."), $calendar['name']), 'horde.success');
                 break;
             }
             // Update a task list.
             $calendar_id = substr($calendar_id, 6);
             try {
                 $registry->tasks->updateTasklist($calendar_id, $calendar);
                 $tasklists = $registry->tasks->listTasklists(true, Horde_Perms::EDIT);
                 $tasklist = $tasklists[$calendar_id];
                 $original_owner = $tasklist->get('owner');
                 Kronolith::readPermsForm($tasklist);
                 if ($tasklist->get('owner') != $original_owner) {
                     $result->deleted = true;
                 }
                 if ($tasklist->hasPermission($registry->getAuth(), Horde_Perms::SHOW)) {
                     $wrapper = new Kronolith_Calendar_External_Tasks(array('api' => 'tasks', 'name' => $calendar_id, 'share' => $tasklist));
                     $result->saved = true;
                     $result->calendar = $wrapper->toHash();
                 }
             } catch (Exception $e) {
                 $notification->push($e, 'horde.error');
                 return $result;
             }
             if ($tasklist->get('name') != $calendar['name']) {
                 $notification->push(sprintf(_("The task list \"%s\" has been renamed to \"%s\"."), $tasklist->get('name'), $calendar['name']), 'horde.success');
             } else {
                 $notification->push(sprintf(_("The task list \"%s\" has been saved."), $tasklist->get('name')), 'horde.success');
             }
             break;
         case 'remote':
             $calendar = array();
             foreach (array('name', 'desc', 'url', 'color', 'user', 'password') as $key) {
                 $calendar[$key] = $this->vars->{$key};
             }
             try {
                 Kronolith::subscribeRemoteCalendar($calendar, $calendar_id);
             } catch (Exception $e) {
                 $notification->push($e, 'horde.error');
                 return $result;
             }
             if ($calendar_id) {
                 $notification->push(sprintf(_("The calendar \"%s\" has been saved."), $calendar['name']), 'horde.success');
             } else {
                 $notification->push(sprintf(_("You have been subscribed to \"%s\" (%s)."), $calendar['name'], $calendar['url']), 'horde.success');
                 $result->id = $calendar['url'];
             }
             $wrapper = new Kronolith_Calendar_Remote($calendar);
             $result->saved = true;
             $result->calendar = $wrapper->toHash();
             break;
         case 'resource':
             foreach (array('name', 'desc', 'response_type') as $key) {
                 $info[$key] = $this->vars->{$key};
             }
             if (!$calendar_id) {
                 // New resource
                 if (!$registry->isAdmin() && !$injector->getInstance('Horde_Core_Perms')->hasAppPermission('resource_management')) {
                     $notification->push(_("You are not allowed to create new resources."), 'horde.error');
                     return $result;
                 }
                 $resource = Kronolith_Resource::addResource($info);
                 Kronolith::readPermsForm($resource);
                 $resource->save();
             } else {
                 try {
                     $rdriver = Kronolith::getDriver('Resource');
                     $resource = $rdriver->getResource($rdriver->getResourceIdByCalendar($calendar_id));
                     if (!$resource->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) {
                         $notification->push(_("You are not allowed to edit this resource."), 'horde.error');
                         return $result;
                     }
                     foreach (array('name', 'desc', 'response_type', 'email') as $key) {
                         $resource->set($key, $this->vars->{$key});
                     }
                     Kronolith::readPermsForm($resource);
                     $resource->save();
                 } catch (Kronolith_Exception $e) {
                     $notification->push($e->getMessage(), 'horde.error');
                     return $result;
                 }
             }
             $wrapper = new Kronolith_Calendar_Resource(array('resource' => $resource));
             $result->calendar = $wrapper->toHash();
             $result->saved = true;
             $result->id = $resource->get('calendar');
             $notification->push(sprintf(_("The resource \"%s\" has been saved."), $resource->get('name'), 'horde.success'));
             break;
         case 'resourcegroup':
             $info = array('group' => true);
             foreach (array('name', 'desc', 'members') as $key) {
                 $info[$key] = $this->vars->{$key};
             }
             if (empty($calendar_id)) {
                 // New resource group.
                 $resource = Kronolith_Resource::addResource($info);
             } else {
                 $driver = Kronolith::getDriver('Resource');
                 $resource = $driver->getResource($calendar_id);
                 $resource->set('name', $this->vars->name);
                 $resource->set('desc', $this->vars->description);
                 $resource->set('members', $this->vars->members);
                 $resource->save();
             }
             $wrapper = new Kronolith_Calendar_ResourceGroup(array('resource' => $resource));
             $result->calendar = $wrapper->toHash();
             $result->saved = true;
             $result->id = $resource->get('calendar');
             $notification->push(sprintf(_("The resource group \"%s\" has been saved."), $resource->get('name'), 'horde.success'));
             break;
     }
     return $result;
 }
Exemplo n.º 3
0
 /**
  * Adds additional items to the sidebar.
  *
  * This is for the traditional view. For the dynamic view, see
  * Kronolith_View_Sidebar.
  *
  * @param Horde_View_Sidebar $sidebar  The sidebar object.
  */
 public function sidebar($sidebar)
 {
     global $calendar_manager, $conf, $injector, $prefs, $registry, $session;
     $admin = $registry->isAdmin();
     $perms = $injector->getInstance('Horde_Core_Perms');
     if (Kronolith::getDefaultCalendar(Horde_Perms::EDIT) && ($perms->hasAppPermission('max_events') === true || $perms->hasAppPermission('max_events') > Kronolith::countEvents())) {
         $sidebar->addNewButton(_("_New Event"), Horde::url('new.php')->add('url', Horde::selfUrl(true, false, true)));
     }
     if (strlen($session->get('kronolith', 'display_cal'))) {
         $calendars = Kronolith::displayedCalendars();
         $sidebar->containers['calendars'] = array('header' => array('id' => 'kronolith-toggle-calendars', 'label' => ngettext("Showing calendar:", "Showing calendars:", count($calendars)), 'collapsed' => false));
         foreach ($calendars as $calendar) {
             $row = array('label' => $calendar->name(), 'color' => $calendar->background(), 'type' => 'checkbox');
             $sidebar->addRow($row, 'calendars');
         }
         return;
     }
     $user = $registry->getAuth();
     $url = Horde::selfUrl();
     $edit = Horde::url('calendars/edit.php');
     $sidebar->containers['my'] = array('header' => array('id' => 'kronolith-toggle-my', 'label' => _("My Calendars"), 'collapsed' => false));
     if (!$prefs->isLocked('default_share')) {
         $sidebar->containers['my']['header']['add'] = array('url' => Horde::url('calendars/create.php'), 'label' => _("Create a new Local Calendar"));
     }
     if ($admin) {
         $sidebar->containers['system'] = array('header' => array('id' => 'kronolith-toggle-system', 'label' => _("System Calendars"), 'collapsed' => true));
         $sidebar->containers['system']['header']['add'] = array('url' => Horde::url('calendars/create.php')->add('system', 1), 'label' => _("Create a new System Calendar"));
     }
     $sidebar->containers['shared'] = array('header' => array('id' => 'kronolith-toggle-shared', 'label' => _("Shared Calendars"), 'collapsed' => true));
     foreach (Kronolith::listInternalCalendars() as $id => $calendar) {
         $owner = $calendar->get('owner');
         if ($admin && empty($owner)) {
             continue;
         }
         $row = array('selected' => in_array($id, $calendar_manager->get(Kronolith::DISPLAY_CALENDARS)), 'url' => $url->copy()->add('toggle_calendar', $id), 'label' => Kronolith::getLabel($calendar), 'color' => Kronolith::backgroundColor($calendar), 'edit' => $edit->add('c', $calendar->getName()), 'type' => 'checkbox');
         if ($calendar->get('owner') && $calendar->get('owner') == $user) {
             $sidebar->addRow($row, 'my');
         } else {
             $sidebar->addRow($row, 'shared');
         }
     }
     if ($admin) {
         foreach ($injector->getInstance('Kronolith_Shares')->listSystemShares() as $id => $calendar) {
             $row = array('selected' => in_array($id, $calendar_manager->get(Kronolith::DISPLAY_CALENDARS)), 'url' => $url->copy()->add('toggle_calendar', $id), 'label' => $calendar->get('name'), 'color' => Kronolith::backgroundColor($calendar), 'edit' => $edit->add('c', $calendar->getName()), 'type' => 'checkbox');
             $sidebar->addRow($row, 'system');
         }
     }
     if (!empty($conf['resources']['enabled']) && ($admin || $perms->hasAppPermission('resource_management'))) {
         $sidebar->containers['groups'] = array('header' => array('id' => 'kronolith-toggle-groups', 'label' => _("Resource Groups"), 'collapsed' => true, 'add' => array('url' => Horde::url('resources/groups/create.php'), 'label' => _("Create a new Resource Group"))));
         $editGroups = Horde::url('resources/groups/edit.php');
         $sidebar->containers['resources'] = array('header' => array('id' => 'kronolith-toggle-resources', 'label' => _("Resources"), 'collapsed' => true, 'add' => array('url' => Horde::url('resources/create.php'), 'label' => _("Create a new Resource"))));
         $edit = Horde::url('resources/edit.php');
         foreach (Kronolith::getDriver('Resource')->listResources() as $resource) {
             if ($resource->get('isgroup')) {
                 $row = array('label' => $resource->get('name'), 'color' => '#dddddd', 'edit' => $editGroups->add('c', $resource->getId()), 'type' => 'radiobox');
                 $sidebar->addRow($row, 'groups');
             } else {
                 $calendar = new Kronolith_Calendar_Resource(array('resource' => $resource));
                 $row = array('selected' => in_array($resource->get('calendar'), $calendar_manager->get(Kronolith::DISPLAY_RESOURCE_CALENDARS)), 'url' => $url->copy()->add('toggle_calendar', 'resource_' . $resource->get('calendar')), 'label' => $calendar->name(), 'color' => $calendar->background(), 'edit' => $edit->add('c', $resource->getId()), 'type' => 'checkbox');
                 $sidebar->addRow($row, 'resources');
             }
         }
     }
     foreach ($calendar_manager->get(Kronolith::ALL_EXTERNAL_CALENDARS) as $id => $calendar) {
         if (!$calendar->display()) {
             continue;
         }
         $app = $registry->get('name', $registry->hasInterface($calendar->api()));
         if (!strlen($app)) {
             $app = _("Other events");
         }
         $container = 'external_' . $app;
         if (!isset($sidebar->containers[$container])) {
             $sidebar->containers[$container] = array('header' => array('id' => 'kronolith-toggle-external-' . $calendar->api(), 'label' => $app, 'collapsed' => true));
         }
         $row = array('selected' => in_array($id, $calendar_manager->get(Kronolith::DISPLAY_EXTERNAL_CALENDARS)), 'url' => $url->copy()->add('toggle_calendar', 'external_' . $id), 'label' => $calendar->name(), 'color' => $calendar->background(), 'type' => 'checkbox');
         $sidebar->addRow($row, $container);
     }
     $sidebar->containers['remote'] = array('header' => array('id' => 'kronolith-toggle-remote', 'label' => _("Remote Calendars"), 'collapsed' => true, 'add' => array('url' => Horde::url('calendars/remote_subscribe.php'), 'label' => _("Subscribe to a Remote Calendar"))));
     $edit = Horde::url('calendars/remote_edit.php');
     foreach ($calendar_manager->get(Kronolith::ALL_REMOTE_CALENDARS) as $calendar) {
         $row = array('selected' => in_array($calendar->url(), $calendar_manager->get(Kronolith::DISPLAY_REMOTE_CALENDARS)), 'url' => $url->copy()->add('toggle_calendar', 'remote_' . $calendar->url()), 'label' => $calendar->name(), 'color' => $calendar->background(), 'edit' => $edit->add('url', $calendar->url()), 'type' => 'checkbox');
         $sidebar->addRow($row, 'remote');
     }
     if (!empty($conf['holidays']['enable'])) {
         $sidebar->containers['holidays'] = array('header' => array('id' => 'kronolith-toggle-holidays', 'label' => _("Holidays"), 'collapsed' => true));
         foreach ($calendar_manager->get(Kronolith::ALL_HOLIDAYS) as $id => $calendar) {
             $row = array('selected' => in_array($id, $calendar_manager->get(Kronolith::DISPLAY_HOLIDAYS)), 'url' => $url->copy()->add('toggle_calendar', 'holiday_' . $id), 'label' => $calendar->name(), 'color' => $calendar->background(), 'type' => 'checkbox');
             $sidebar->addRow($row, 'holidays');
         }
     }
 }