Esempio n. 1
0
 /**
  * Allow setting of properties
  *
  * @param string $property  The property to set
  * @param mixed $value      The value to set to
  *
  * @return void
  */
 public function set($property, $value)
 {
     if ($property == 'members') {
         $value = serialize($value);
     }
     $this->_share->set($property, $value);
 }
Esempio n. 2
0
 public function execute()
 {
     switch ($this->_vars->submitbutton) {
         case _("Save"):
             $this->_addressbook->set('name', $this->_vars->get('name'));
             $this->_addressbook->set('desc', $this->_vars->get('description'));
             try {
                 $this->_addressbook->save();
             } catch (Horde_Share_Exception $e) {
                 throw new Turba_Exception(sprintf(_("Unable to save address book \"%s\": %s"), $this->_vars->get('name'), $e->getMessage()));
             }
             break;
         case _("Delete"):
             Horde::url('addressbooks/delete.php')->add('a', $this->_vars->a)->redirect();
             break;
         case _("Cancel"):
             Horde::url('', true)->redirect();
             break;
     }
 }
Esempio n. 3
0
 /**
  * Sets an attribute value in this object.
  *
  * @param string $attribute  The attribute to set.
  * @param mixed $value       The value for $attribute.
  * @param boolean $update    Commit only this change to storage.
  *
  * @throws Ansel_Exception
  */
 public function set($attribute, $value, $update = false)
 {
     if ($attribute == 'slug') {
         $this->_oldSlug = $this->get('slug');
     }
     /* Need to serialize the style object */
     if ($attribute == 'style') {
         $value = serialize($value);
     }
     if ($attribute == 'view_mode' && $this->get('view_mode') != $value) {
         //$mode = isset($attributes['attribute_view_mode']) ? $attributes['attribute_view_mode'] : 'Normal';
         $this->_setModeHelper($value);
     }
     try {
         $this->_share->set($attribute, $value, $update);
     } catch (Horde_Share_Exception $e) {
         throw new Ansel_Exception($e);
     }
 }
Esempio n. 4
0
 /**
  * Renames a share in the shares system.
  *
  * @param Horde_Share_Object $share  The share to rename.
  * @param string $name               The share's new name.
  *
  * @throws Horde_Share_Exception
  */
 protected function _renameShare(Horde_Share_Object $share, $name)
 {
     $share->set('share_name', $name);
 }
Esempio n. 5
0
 /**
  * Updates an existing share.
  *
  * @param Horde_Share_Object $tasklist  The share to update.
  * @param array $info                   Hash with task list information.
  *
  * @throws Horde_Exception_PermissionDenied
  * @throws Nag_Exception
  */
 public static function updateTasklist(Horde_Share_Object $tasklist, array $info)
 {
     if (!$GLOBALS['registry']->getAuth() || $tasklist->get('owner') != $GLOBALS['registry']->getAuth() && (!is_null($tasklist->get('owner')) || !$GLOBALS['registry']->isAdmin())) {
         throw new Horde_Exception_PermissionDenied(_("You are not allowed to change this task list."));
     }
     $tasklist->set('name', $info['name']);
     $tasklist->set('color', $info['color']);
     $tasklist->set('desc', $info['description']);
     $tasklist->set('owner', empty($info['system']) ? $GLOBALS['registry']->getAuth() : null);
     if ($tasklist->get('issmart')) {
         if (empty($info['search'])) {
             throw new Nag_Exception(_("Missing valid search criteria"));
         }
         $tasklist->set('search', $info['search']);
     }
     try {
         $tasklist->save();
     } catch (Horde_Share_Exception $e) {
         throw new Nag_Exception(sprintf(_("Unable to save task list \"%s\": %s"), $info['name'], $e->getMessage()));
     }
 }
Esempio n. 6
0
 /**
  * Add any modifiers required to the share in order to mark it as default.
  *
  * @param Horde_Share_Object $share The new default share.
  */
 protected function _prepareDefaultShare($share)
 {
     $share->set('default', true);
 }
Esempio n. 7
0
 /**
  * Check if the passed in share is the default share for this source.
  *
  * @param Horde_Share_Object $share  The share object.
  * @param array $srcconfig           The cfgSource entry for the share.
  *
  * @return boolean TODO
  */
 public function checkDefaultShare(Horde_Share_Object $share, array $srcconfig)
 {
     $params = @unserialize($share->get('params'));
     if (!isset($params['default'])) {
         $params['default'] = $params['name'] == $GLOBALS['registry']->getAuth();
         $share->set('params', serialize($params));
         $share->save();
     }
     return $params['default'];
 }
Esempio n. 8
0
 /**
  * Reads a submitted permissions form and updates the share permissions.
  *
  * @param Horde_Share_Object|Kronolith_Resource_Base $share  The share to update.
  *
  * @return array  A list of error messages.
  * @throws Kronolith_Exception
  */
 public static function readPermsForm($share)
 {
     $auth = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Auth')->create();
     $perm = $share->getPermission();
     $errors = array();
     if ($GLOBALS['conf']['share']['notify']) {
         $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create();
         $mail = new Horde_Mime_Mail(array('From' => $identity->getDefaultFromAddress(true), 'User-Agent' => 'Kronolith ' . $GLOBALS['registry']->getVersion()));
         $image = self::getImagePart('big_share.png');
         $view = new Horde_View(array('templatePath' => KRONOLITH_TEMPLATES . '/share'));
         new Horde_View_Helper_Text($view);
         $view->identity = $identity;
         $view->calendar = $share->get('name');
         $view->imageId = $image->getContentId();
     }
     // Process owner and owner permissions.
     if (!$share instanceof Kronolith_Resource_Base) {
         $old_owner = $share->get('owner');
         $new_owner_backend = Horde_Util::getFormData('owner_select', Horde_Util::getFormData('owner_input', $old_owner));
         $new_owner = $GLOBALS['registry']->convertUsername($new_owner_backend, true);
         // Only set new owner if this isn't a system calendar, and the
         // owner actually changed and the new owner is set at all.
         if (!is_null($old_owner) && $old_owner !== $new_owner && !empty($new_owner)) {
             if ($old_owner != $GLOBALS['registry']->getAuth() && !$GLOBALS['registry']->isAdmin()) {
                 $errors[] = _("Only the owner or system administrator may change ownership or owner permissions for a share");
             } elseif ($auth->hasCapability('list') && !$auth->exists($new_owner_backend)) {
                 $errors[] = sprintf(_("The user \"%s\" does not exist."), $new_owner_backend);
             } else {
                 $share->set('owner', $new_owner);
                 $share->save();
                 if ($GLOBALS['conf']['share']['notify']) {
                     $view->ownerChange = true;
                     $multipart = self::buildMimeMessage($view, 'notification', $image);
                     $to = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($new_owner)->getDefaultFromAddress(true);
                     $mail->addHeader('Subject', _("Ownership assignment"));
                     $mail->addHeader('To', $to);
                     $mail->setBasePart($multipart);
                     $mail->send($GLOBALS['injector']->getInstance('Horde_Mail'));
                     $view->ownerChange = false;
                 }
             }
         }
     }
     if ($GLOBALS['conf']['share']['notify']) {
         if ($GLOBALS['conf']['share']['hidden']) {
             $view->subscribe = Horde::url('calendars/subscribe.php', true)->add('calendar', $share->getName());
         }
         $multipart = self::buildMimeMessage($view, 'notification', $image);
     }
     if ($GLOBALS['registry']->isAdmin() || !empty($GLOBALS['conf']['share']['world'])) {
         // Process default permissions.
         if (Horde_Util::getFormData('default_show')) {
             $perm->addDefaultPermission(Horde_Perms::SHOW, false);
         } else {
             $perm->removeDefaultPermission(Horde_Perms::SHOW, false);
         }
         if (Horde_Util::getFormData('default_read')) {
             $perm->addDefaultPermission(Horde_Perms::READ, false);
         } else {
             $perm->removeDefaultPermission(Horde_Perms::READ, false);
         }
         if (Horde_Util::getFormData('default_edit')) {
             $perm->addDefaultPermission(Horde_Perms::EDIT, false);
         } else {
             $perm->removeDefaultPermission(Horde_Perms::EDIT, false);
         }
         if (Horde_Util::getFormData('default_delete')) {
             $perm->addDefaultPermission(Horde_Perms::DELETE, false);
         } else {
             $perm->removeDefaultPermission(Horde_Perms::DELETE, false);
         }
         if (Horde_Util::getFormData('default_delegate')) {
             $perm->addDefaultPermission(self::PERMS_DELEGATE, false);
         } else {
             $perm->removeDefaultPermission(self::PERMS_DELEGATE, false);
         }
         // Process guest permissions.
         if (Horde_Util::getFormData('guest_show')) {
             $perm->addGuestPermission(Horde_Perms::SHOW, false);
         } else {
             $perm->removeGuestPermission(Horde_Perms::SHOW, false);
         }
         if (Horde_Util::getFormData('guest_read')) {
             $perm->addGuestPermission(Horde_Perms::READ, false);
         } else {
             $perm->removeGuestPermission(Horde_Perms::READ, false);
         }
         if (Horde_Util::getFormData('guest_edit')) {
             $perm->addGuestPermission(Horde_Perms::EDIT, false);
         } else {
             $perm->removeGuestPermission(Horde_Perms::EDIT, false);
         }
         if (Horde_Util::getFormData('guest_delete')) {
             $perm->addGuestPermission(Horde_Perms::DELETE, false);
         } else {
             $perm->removeGuestPermission(Horde_Perms::DELETE, false);
         }
         if (Horde_Util::getFormData('guest_delegate')) {
             $perm->addGuestPermission(self::PERMS_DELEGATE, false);
         } else {
             $perm->removeGuestPermission(self::PERMS_DELEGATE, false);
         }
     }
     // Process creator permissions.
     if (Horde_Util::getFormData('creator_show')) {
         $perm->addCreatorPermission(Horde_Perms::SHOW, false);
     } else {
         $perm->removeCreatorPermission(Horde_Perms::SHOW, false);
     }
     if (Horde_Util::getFormData('creator_read')) {
         $perm->addCreatorPermission(Horde_Perms::READ, false);
     } else {
         $perm->removeCreatorPermission(Horde_Perms::READ, false);
     }
     if (Horde_Util::getFormData('creator_edit')) {
         $perm->addCreatorPermission(Horde_Perms::EDIT, false);
     } else {
         $perm->removeCreatorPermission(Horde_Perms::EDIT, false);
     }
     if (Horde_Util::getFormData('creator_delete')) {
         $perm->addCreatorPermission(Horde_Perms::DELETE, false);
     } else {
         $perm->removeCreatorPermission(Horde_Perms::DELETE, false);
     }
     if (Horde_Util::getFormData('creator_delegate')) {
         $perm->addCreatorPermission(self::PERMS_DELEGATE, false);
     } else {
         $perm->removeCreatorPermission(self::PERMS_DELEGATE, false);
     }
     // Process user permissions.
     $u_names = Horde_Util::getFormData('u_names');
     $u_show = Horde_Util::getFormData('u_show');
     $u_read = Horde_Util::getFormData('u_read');
     $u_edit = Horde_Util::getFormData('u_edit');
     $u_delete = Horde_Util::getFormData('u_delete');
     $u_delegate = Horde_Util::getFormData('u_delegate');
     $current = $perm->getUserPermissions();
     if ($GLOBALS['conf']['share']['notify']) {
         $mail->addHeader('Subject', _("Access permissions"));
     }
     $perm->removeUserPermission(null, null, false);
     foreach ($u_names as $key => $user_backend) {
         // Apply backend hooks
         $user = $GLOBALS['registry']->convertUsername($user_backend, true);
         // If the user is empty, or we've already set permissions
         // via the owner_ options, don't do anything here.
         if (empty($user) || $user == $new_owner) {
             continue;
         }
         if ($auth->hasCapability('list') && !$auth->exists($user_backend)) {
             $errors[] = sprintf(_("The user \"%s\" does not exist."), $user_backend);
             continue;
         }
         $has_perms = false;
         if (!empty($u_show[$key])) {
             $perm->addUserPermission($user, Horde_Perms::SHOW, false);
             $has_perms = true;
         }
         if (!empty($u_read[$key])) {
             $perm->addUserPermission($user, Horde_Perms::READ, false);
             $has_perms = true;
         }
         if (!empty($u_edit[$key])) {
             $perm->addUserPermission($user, Horde_Perms::EDIT, false);
             $has_perms = true;
         }
         if (!empty($u_delete[$key])) {
             $perm->addUserPermission($user, Horde_Perms::DELETE, false);
             $has_perms = true;
         }
         if (!empty($u_delegate[$key])) {
             $perm->addUserPermission($user, self::PERMS_DELEGATE, false);
             $has_perms = true;
         }
         // Notify users that have been added.
         if ($GLOBALS['conf']['share']['notify'] && !isset($current[$user]) && $has_perms) {
             $to = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($user)->getDefaultFromAddress(true);
             $mail->addHeader('To', $to);
             $mail->setBasePart($multipart);
             $mail->send($GLOBALS['injector']->getInstance('Horde_Mail'));
         }
     }
     // Process group permissions.
     $g_names = Horde_Util::getFormData('g_names');
     $g_show = Horde_Util::getFormData('g_show');
     $g_read = Horde_Util::getFormData('g_read');
     $g_edit = Horde_Util::getFormData('g_edit');
     $g_delete = Horde_Util::getFormData('g_delete');
     $g_delegate = Horde_Util::getFormData('g_delegate');
     $current = $perm->getGroupPermissions();
     $perm->removeGroupPermission(null, null, false);
     foreach ($g_names as $key => $group) {
         if (empty($group)) {
             continue;
         }
         $has_perms = false;
         if (!empty($g_show[$key])) {
             $perm->addGroupPermission($group, Horde_Perms::SHOW, false);
             $has_perms = true;
         }
         if (!empty($g_read[$key])) {
             $perm->addGroupPermission($group, Horde_Perms::READ, false);
             $has_perms = true;
         }
         if (!empty($g_edit[$key])) {
             $perm->addGroupPermission($group, Horde_Perms::EDIT, false);
             $has_perms = true;
         }
         if (!empty($g_delete[$key])) {
             $perm->addGroupPermission($group, Horde_Perms::DELETE, false);
             $has_perms = true;
         }
         if (!empty($g_delegate[$key])) {
             $perm->addGroupPermission($group, self::PERMS_DELEGATE, false);
             $has_perms = true;
         }
         // Notify users that have been added.
         if ($GLOBALS['conf']['share']['notify'] && !isset($current[$group]) && $has_perms) {
             $groupOb = $GLOBALS['injector']->getInstance('Horde_Group')->getData($group);
             if (!empty($groupOb['email'])) {
                 $mail->addHeader('To', $groupOb['name'] . ' <' . $groupOb['email'] . '>');
                 $mail->setBasePart($multipart);
                 $mail->send($GLOBALS['injector']->getInstance('Horde_Mail'));
             }
         }
     }
     try {
         $share->setPermission($perm);
     } catch (Horde_Share_Exception $e) {
         throw new Kronolith_Exception($e);
     }
     return $errors;
 }