public function __construct($vars, Horde_Share_Object $addressbook) { global $conf, $injector, $registry; $this->_addressbook = $addressbook; $owner = $addressbook->get('owner') == $registry->getAuth() || is_null($addressbook->get('owner')) && $registry->isAdmin(); parent::__construct($vars, $owner ? sprintf(_("Edit %s"), $addressbook->get('name')) : $addressbook->get('name')); $this->addHidden('', 'a', 'text', true); $this->addVariable(_("Name"), 'name', 'text', true); if (!$owner) { $v = $this->addVariable(_("Owner"), 'owner', 'text', false); $owner_name = $injector->getInstance('Horde_Core_Factory_Identity')->create($addressbook->get('owner'))->getValue('fullname'); if (trim($owner_name) == '') { $owner_name = $addressbook->get('owner'); } $v->setDefault($owner_name ? $owner_name : _("System")); } $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60)); /* Subscription URLs. */ $url = $registry->get('webroot', 'horde'); if (isset($conf['urls']['pretty']) && $conf['urls']['pretty'] == 'rewrite') { $webdavUrl = $url . '/rpc/turba/'; $carddavUrl = $url . '/rpc/addressbooks/'; $accountUrl = $url . '/rpc/'; } else { $webdavUrl = $url . '/rpc.php/turba/'; $carddavUrl = $url . '/rpc.php/addressbooks/'; $accountUrl = $url . '/rpc.php/'; } try { $accountUrl = Horde::url($accountUrl, true, -1) . 'principals/' . $registry->convertUsername($registry->getAuth(), false) . '/'; if ($addressbook->get('owner')) { $carddavUrl = Horde::url($carddavUrl, true, -1) . $registry->convertUsername($registry->getAuth(), false) . '/' . $injector->getInstance('Horde_Dav_Storage')->getExternalCollectionId($addressbook->getName(), 'contacts') . '/'; $this->addVariable(_("CardDAV Subscription URL"), '', 'link', false, false, null, array(array('url' => $carddavUrl, 'text' => $carddavUrl, 'title' => _("Copy this URL to a CardDAV client to subscribe to this address book"), 'target' => '_blank'))); } $this->addVariable(_("CardDAV Account URL"), '', 'link', false, false, null, array(array('url' => $accountUrl, 'text' => $accountUrl, 'title' => _("Copy this URL to a CarddAV client to subscribe to all your address books"), 'target' => '_blank'))); } catch (Horde_Exception $e) { } $webdavUrl = Horde::url($webdavUrl, true, -1) . ($addressbook->get('owner') ? $registry->convertUsername($addressbook->get('owner'), false) : '-system-') . '/' . $addressbook->getName() . '/'; $this->addVariable(_("WebDAV URL"), '', 'link', false, false, null, array(array('url' => $webdavUrl, 'text' => $webdavUrl, 'title' => _("Copy this URL to a WebDAV client to browse this address book"), 'target' => '_blank'))); /* Permissions link. */ if (empty($conf['share']['no_sharing']) && $owner) { $url = Horde::url($registry->get('webroot', 'horde') . '/services/shares/edit.php')->add(array('app' => 'turba', 'share' => $addressbook->getName())); $this->addVariable('', '', 'link', false, false, null, array(array('url' => $url, 'text' => _("Change Permissions"), 'onclick' => Horde::popupJs($url, array('params' => array('urlencode' => true))) . 'return false;', 'class' => 'horde-button', 'target' => '_blank'))); } $this->setButtons(array(_("Save"), array('class' => 'horde-delete', 'value' => _("Delete")), array('class' => 'horde-cancel', 'value' => _("Cancel")))); }
/** * Returns a hash representing this calendar. * * @return array A simple hash. */ public function toHash() { global $calendar_manager, $conf, $injector, $registry; $owner = $registry->getAuth() && $this->_share->get('owner') == $registry->getAuth(); $hash = parent::toHash(); $hash['name'] = Kronolith::getLabel($this->_share); $hash['desc'] = (string) $this->_share->get('desc'); $hash['owner'] = $owner; $hash['users'] = Kronolith::listShareUsers($this->_share); $hash['fg'] = Kronolith::foregroundColor($this->_share); $hash['bg'] = Kronolith::backgroundColor($this->_share); $hash['show'] = in_array('tasks/' . $this->_share->getName(), $calendar_manager->get(Kronolith::DISPLAY_EXTERNAL_CALENDARS)); $hash['edit'] = $this->_share->hasPermission($registry->getAuth(), Horde_Perms::EDIT); $hash['caldav'] = $this->caldavUrl(); $hash['sub'] = Horde::url($registry->get('webroot', 'horde') . ($conf['urls']['pretty'] == 'rewrite' ? '/rpc/nag/' : '/rpc.php/nag/'), true, -1) . ($this->_share->get('owner') ? $registry->convertUsername($this->_share->get('owner'), false) : '-system-') . '/' . $this->_share->getName() . '.ics'; if ($owner) { $hash['perms'] = Kronolith::permissionToJson($this->_share->getPermission(), is_null($this->_share->get('owner'))); } return $hash; }
/** * * @param array $vars * @param Horde_Share_Object $tasklist */ public function __construct($vars, Horde_Share_Object $tasklist) { $this->_tasklist = $tasklist; $owner = $tasklist->get('owner') == $GLOBALS['registry']->getAuth() || is_null($tasklist->get('owner')) && $GLOBALS['registry']->isAdmin(); parent::__construct($vars, $owner ? sprintf(_("Edit %s"), $tasklist->get('name')) : $tasklist->get('name')); $this->addHidden('', 't', 'text', true); $this->addVariable(_("Name"), 'name', 'text', true); if (!$owner) { $v = $this->addVariable(_("Owner"), 'owner', 'text', false); $owner_name = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($tasklist->get('owner'))->getValue('fullname'); if (trim($owner_name) == '') { $owner_name = $tasklist->get('owner'); } $v->setDefault($owner_name ? $owner_name : _("System")); } $this->addVariable(_("Color"), 'color', 'colorpicker', false); if ($GLOBALS['registry']->isAdmin()) { $this->addVariable(_("System Task List"), 'system', 'boolean', false, false, _("System task lists don't have an owner. Only administrators can change the task list settings and permissions.")); } $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60)); /* Display URL. */ $url = Horde::url('list.php', true, -1)->add('display_tasklist', $tasklist->getName()); $this->addVariable(_("Display URL"), '', 'link', false, false, null, array(array('url' => $url, 'text' => $url, 'title' => _("Click or copy this URL to display this task list"), 'target' => '_blank'))); /* Subscription URLs. */ try { $accountUrl = Nag::getUrl(Nag::DAV_ACCOUNT, $tasklist); $caldavUrl = Nag::getUrl(Nag::DAV_CALDAV, $tasklist); $this->addVariable(_("CalDAV Subscription URL"), '', 'link', false, false, null, array(array('url' => $caldavUrl, 'text' => $caldavUrl, 'title' => _("Copy this URL to a CalDAV client to subscribe to this task list"), 'target' => '_blank'))); $this->addVariable(_("CalDAV Account URL"), '', 'link', false, false, null, array(array('url' => $accountUrl, 'text' => $accountUrl, 'title' => _("Copy this URL to a CalDAV client to subscribe to all your task lists"), 'target' => '_blank'))); } catch (Horde_Exception $e) { } $webdavUrl = Nag::getUrl(Nag::DAV_WEBDAV, $tasklist); $this->addVariable(_("WebDAV/ICS Subscription URL"), '', 'link', false, false, null, array(array('url' => $webdavUrl, 'text' => $webdavUrl, 'title' => _("Copy this URL to a WebDAV or ICS client to subscribe to this task list"), 'target' => '_blank'))); /* Permissions link. */ if (empty($GLOBALS['conf']['share']['no_sharing']) && $owner) { $url = Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/services/shares/edit.php')->add(array('app' => 'nag', 'share' => $tasklist->getName())); $this->addVariable('', '', 'link', false, false, null, array(array('url' => $url, 'text' => _("Change Permissions"), 'onclick' => Horde::popupJs($url, array('params' => array('urlencode' => true))) . 'return false;', 'class' => 'horde-button', 'target' => '_blank'))); } $this->setButtons(array(_("Save"), array('class' => 'horde-delete', 'value' => _("Delete")), array('class' => 'horde-cancel', 'value' => _("Cancel")))); }
/** * Returns a hash representing this calendar. * * @return array A simple hash. */ public function toHash() { global $calendar_manager, $conf, $injector, $registry; $id = $this->_share->getName(); $owner = $registry->getAuth() && ($this->owner() == $registry->getAuth() || $this->isSystem() && $registry->isAdmin()); $hash = parent::toHash(); $hash['name'] = $this->name(); $hash['owner'] = $owner; $hash['system'] = $this->isSystem(); $hash['users'] = Kronolith::listShareUsers($this->_share); $hash['show'] = in_array($id, $calendar_manager->get(Kronolith::DISPLAY_CALENDARS)); $hash['edit'] = $this->hasPermission(Horde_Perms::EDIT); $hash['caldav'] = $this->caldavUrl(); $hash['sub'] = Horde::url($registry->get('webroot', 'horde') . ($conf['urls']['pretty'] == 'rewrite' ? '/rpc/kronolith/' : '/rpc.php/kronolith/'), true, -1) . ($this->owner() ? $registry->convertUsername($this->owner(), false) : '-system-') . '/' . $id . '.ics'; $hash['feed'] = (string) Kronolith::feedUrl($id); $hash['embed'] = Kronolith::embedCode($id); $hash['tg'] = array_values(Kronolith::getTagger()->getTags($id, Kronolith_Tagger::TYPE_CALENDAR)); if ($owner) { $hash['perms'] = Kronolith::permissionToJson($this->_share->getPermission()); } return $hash; }
/** * Returns a hash representing this calendar. * * @return array A simple hash. */ public function toHash() { global $calendar_manager, $conf, $injector, $registry; $id = $this->_share->getName(); $owner = $registry->getAuth() && $this->owner() == $registry->getAuth(); $hash = parent::toHash(); $hash['name'] = $this->name(); $hash['owner'] = $owner; $hash['users'] = Kronolith::listShareUsers($this->_share); $hash['show'] = in_array($id, $calendar_manager->get(Kronolith::DISPLAY_CALENDARS)); $hash['edit'] = $this->hasPermission(Horde_Perms::EDIT); try { $hash['caldav'] = Horde::url($registry->get('webroot', 'horde') . ($conf['urls']['pretty'] == 'rewrite' ? '/rpc/calendars/' : '/rpc.php/calendars/'), true, -1) . $registry->getAuth() . '/' . $injector->getInstance('Horde_Dav_Storage')->getExternalCollectionId($id, 'calendar') . '/'; } catch (Horde_Exception $e) { } $hash['sub'] = Horde::url($registry->get('webroot', 'horde') . ($conf['urls']['pretty'] == 'rewrite' ? '/rpc/kronolith/' : '/rpc.php/kronolith/'), true, -1) . ($this->owner() ? $this->owner() : '-system-') . '/' . $id . '.ics'; $hash['feed'] = (string) Kronolith::feedUrl($id); $hash['embed'] = Kronolith::embedCode($id); $hash['tg'] = array_values(Kronolith::getTagger()->getTags($id, Kronolith_Tagger::TYPE_CALENDAR)); if ($owner) { $hash['perms'] = Kronolith::permissionToJson($this->_share->getPermission()); } return $hash; }
/** * Removes a share from the shares system permanently. * * @param Horde_Share_Object $share The share to remove. * * @throws Horde_Share_Exception */ public function removeShare(Horde_Share_Object $share) { // First Remove Children foreach ($share->getChildren(null, null, true) as $child) { $this->removeShare($child); } // Run the results through the callback, if configured. $this->runCallback('remove', array($share)); /* Remove share from the caches. */ $id = $share->getId(); unset($this->_shareMap[$id]); unset($this->_cache[$share->getName()]); /* Reset caches that depend on unknown criteria. */ $this->expireListCache(); $this->_removeShare($share); }
/** * Deletes a task list. * * @param Horde_Share_Object $tasklist The task list to delete. * * @throws Nag_Exception * @throws Horde_Exception_PermissionDenied */ public static function deleteTasklist(Horde_Share_Object $tasklist) { 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 delete this task list.")); } // Delete the task list. $storage =& $GLOBALS['injector']->getInstance('Nag_Factory_Driver')->create($tasklist->getName()); $result = $storage->deleteAll(); // Remove share and all groups/permissions. try { $GLOBALS['nag_shares']->removeShare($tasklist); } catch (Horde_Share_Exception $e) { throw new Nag_Exception($e); } }
/** * 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; }