Copyright 2009-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: Michael J Rubinsky (mrubinsk@horde.org)
Inheritance: extends Kronolith_Resource_Base
Ejemplo n.º 1
0
 /**
  * @throws Kronolith_Exception
  */
 public function execute()
 {
     // If cancel was clicked, return false.
     if ($this->_vars->get('submitbutton') == _("Cancel")) {
         Horde::url($GLOBALS['prefs']->getValue('defaultview') . '.php', true)->redirect();
     }
     if (!$this->_resource->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE)) {
         throw new Kronolith_Exception(_("Permission denied"));
     }
     // Delete the resource.
     try {
         Kronolith::getDriver('Resource')->delete($this->_resource);
     } catch (Exception $e) {
         throw new Kronolith_Exception(sprintf(_("Unable to delete \"%s\": %s"), $this->_resource->get('name'), $e->getMessage()));
     }
 }
Ejemplo n.º 2
0
 /**
  * Adds $event to an available member resource's calendar.
  *
  * @param Kronolith_Event $event
  *
  * @throws Kronolith_Exception
  */
 public function addEvent(Kronolith_Event $event)
 {
     if (!empty($this->_selectedResource)) {
         $this->_selectedResource->addEvent($event);
     } else {
         throw new LogicException('Events should be added to the Single resource object, not directly to the Group object.');
     }
 }
Ejemplo n.º 3
0
 /**
  * @throws Kronolith_Exception
  */
 public function execute()
 {
     switch ($this->_vars->submitbutton) {
         case _("Save"):
             $new_name = $this->_vars->get('name');
             $this->_resource->set('name', $new_name);
             $this->_resource->set('description', $this->_vars->get('description'));
             $this->_resource->set('response_type', $this->_vars->get('responsetype'));
             $this->_resource->set('email', $this->_vars->get('email'));
             /* Update group memberships */
             $driver = Kronolith::getDriver('Resource');
             $existing_groups = $driver->getGroupMemberships($this->_resource->getId());
             $new_groups = $this->_vars->get('category');
             $new_groups = is_null($new_groups) ? array() : $new_groups;
             foreach ($existing_groups as $gid) {
                 $i = array_search($gid, $new_groups);
                 if ($i === false) {
                     // No longer in this group
                     $group = $driver->getResource($gid);
                     $members = $group->get('members');
                     $idx = array_search($this->_resource->getId(), $members);
                     if ($idx !== false) {
                         unset($members[$idx]);
                         reset($members);
                         $group->set('members', $members);
                         $group->save();
                     }
                 } else {
                     // We know it's already in the group, remove it so we don't
                     // have to check/add it again later.
                     unset($new_groups[$i]);
                 }
             }
             reset($new_groups);
             foreach ($new_groups as $gid) {
                 $group = $driver->getResource($gid);
                 $members = $group->get('members');
                 $members[] = $this->_resource->getId();
                 $group->set('members', $members);
                 $group->save();
             }
             try {
                 $this->_resource->save();
             } catch (Exception $e) {
                 throw new Kronolith_Exception(sprintf(_("Unable to save resource \"%s\": %s"), $new_name, $e->getMessage()));
             }
             return $this->_resource;
         case _("Delete"):
             Horde::url('resources/delete.php')->add('c', $this->_vars->c)->redirect();
             break;
         case _("Cancel"):
             Horde::url($GLOBALS['prefs']->getValue('defaultview') . '.php', true)->redirect();
             break;
     }
 }
Ejemplo n.º 4
0
 /**
  * @throws Kronolith_Exception
  */
 public function execute()
 {
     switch ($this->_vars->submitbutton) {
         case _("Save"):
             $new_name = $this->_vars->get('name');
             $this->_resource->set('name', $new_name);
             $this->_resource->set('description', $this->_vars->get('description'));
             $this->_resource->set('members', $this->_vars->get('members'));
             try {
                 $this->_resource->save();
             } catch (Exception $e) {
                 throw new Kronolith_Exception(sprintf(_("Unable to save resource \"%s\": %s"), $new_name, $e->getMessage()));
             }
             return $this->_resource;
         case _("Delete"):
             Horde::url('resources/groups/delete.php')->add('c', $this->_vars->c)->redirect();
             break;
         case _("Cancel"):
             Horde::url($GLOBALS['prefs']->getValue('defaultview') . '.php', true)->redirect();
             break;
     }
 }
Ejemplo n.º 5
0
 /**
  * Returns a hash representing this calendar.
  *
  * @return array  A simple hash.
  */
 public function toHash()
 {
     $owner = $GLOBALS['registry']->isAdmin() || $GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('resource_management');
     $hash = parent::toHash();
     $hash['id'] = $this->_resource->getId();
     $hash['name'] = $this->name();
     $hash['owner'] = $owner;
     $hash['show'] = $this->display();
     $hash['edit'] = $this->hasPermission(Horde_Perms::EDIT);
     $hash['sub'] = null;
     $hash['feed'] = null;
     $hash['embed'] = null;
     $hash['response_type'] = $this->_resource->get('response_type');
     if ($owner) {
         $hash['perms'] = Kronolith::permissionToJson($this->_resource->getPermission());
     }
     return $hash;
 }
Ejemplo n.º 6
0
 /**
  * Returns a hash representing this calendar.
  *
  * @return array  A simple hash.
  */
 public function toHash()
 {
     $owner = $GLOBALS['registry']->isAdmin();
     $hash = parent::toHash();
     $hash['id'] = $this->_resource->getId();
     $hash['name'] = $this->name();
     $hash['owner'] = $owner;
     $hash['show'] = $this->display();
     $hash['edit'] = $this->hasPermission(Horde_Perms::EDIT);
     $hash['sub'] = null;
     $hash['feed'] = null;
     $hash['embed'] = null;
     $hash['response_type'] = $this->_resource->get('response_type');
     if ($owner) {
         $hash['perms'] = array('type' => 'matrix', 'default' => 0, 'guest' => 0, 'creator' => 0);
     }
     return $hash;
 }