!$this->rowExists($row) ||
!$this->colExists($col)) {
// Check permissions.
- if (Horde::hasPermission('max_blocks') !== true &&
- Horde::hasPermission('max_blocks') <= $this->count()) {
+ $max_blocks = $GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_blocks');
+ if (($max_blocks !== true) &&
+ ($max_blocks <= $this->count())) {
try {
$message = Horde::callHook('perms_denied', array('horde:max_blocks'));
} catch (Horde_Exception_HookNotSet $e) {
- $message = @htmlspecialchars(sprintf(ngettext("You are not allowed to create more than %d block.", "You are not allowed to create more than %d blocks.", Horde::hasPermission('max_blocks')), Horde::hasPermission('max_blocks')), ENT_COMPAT, $GLOBALS['registry']->getCharset());
+ $message = @htmlspecialchars(sprintf(ngettext("You are not allowed to create more than %d block.", "You are not allowed to create more than %d blocks.", $max_blocks), $max_blocks), ENT_COMPAT, $GLOBALS['registry']->getCharset());
}
$GLOBALS['notification']->push($message, 'horde.error', array('content.raw'));
break;
}
/**
- * Returns the specified permission for the current user.
- *
- * @param string $permission A permission, currently only 'max_blocks'.
- *
- * @return mixed The value of the specified permission.
- */
- static public function hasPermission($permission)
- {
- $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
-
- if (!$perms->exists('horde:' . $permission)) {
- return true;
- }
-
- $allowed = $perms->getPermissions('horde:' . $permission);
- if (is_array($allowed)) {
- switch ($permission) {
- case 'max_blocks':
- $allowed = max($allowed);
- break;
- }
- }
-
- return $allowed;
- }
-
- /**
* Utility function to send redirect headers to browser, handling any
* browser quirks.
*
: $GLOBALS['registry']->getApp();
if ($this->exists($app . ':' . $permission)) {
- $args = array($this->getPermissions($app . ':' . $permission));
- if (isset($opts['opts'])) {
- $args[] = $opts['opts'];
+ $perms = $this->getPermissions($app . ':' . $permission);
+ if ($perms === false) {
+ return false;
}
+ $args = array(
+ $permission,
+ $perms,
+ isset($opts['opts']) ? $opts['opts'] : array()
+ );
+
try {
return $GLOBALS['registry']->callAppMethod($app, 'hasPermission', array('args' => $args));
} catch (Horde_Exception $e) {}
}
/**
+ * Returns the specified permission for the given app permission.
+ *
+ * @param string $permission The permission to check.
+ * @param mixed $allowed The allowed permissions.
+ * @param array $opts Additional options (NONE).
+ *
+ * @return mixed The value of the specified permission.
+ */
+ public function hasPermission($permission, $allowed, $opts = array())
+ {
+ switch ($permission) {
+ case 'max_blocks':
+ $allowed = max($allowed);
+ break;
+ }
+
+ return $allowed;
+ }
+
+ /**
* Populate dynamically-generated preference values.
*
* @param Horde_Core_Prefs_Ui $ui The UI object.
<table class="nopadding" cellspacing="6" width="100%">
<?php
$rows = $layout->rows();
+$max_blocks = $GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_blocks');
list($current_row, $current_col) = $layout->getCurrentBlock();
$allow_add = !empty($conf['hooks']['permsdenied']) ||
- (Horde::hasPermission('max_blocks') === true) ||
- (Horde::hasPermission('max_blocks') > $layout->count());
+ ($max_blocks === true) ||
+ ($max_blocks > $layout->count());
$columns = 0;
for ($row = 0; $row < $rows; ++$row):
?>
}
/**
- * Returns the specified permission for the current user.
+ * Returns the specified permission for the given app permission.
*
- * @param mixed $allowed The allowed permissions.
- * @param array $opts Additinal options ('value').
+ * @param string $permission The permission to check.
+ * @param mixed $allowed The allowed permissions.
+ * @param array $opts Additional options ('value').
*
* @return mixed The value of the specified permission.
*/
- public function hasPermission($allowed, $opts = array())
+ public function hasPermission($permission, $allowed, $opts = array())
{
- if (is_array($allowed)) {
- switch ($permission) {
- case 'create_folders':
- $allowed = (bool)count(array_filter($allowed));
- break;
-
- case 'max_folders':
- case 'max_recipients':
- case 'max_timelimit':
- $allowed = max($allowed);
- break;
- }
+ switch ($permission) {
+ case 'create_folders':
+ $allowed = (bool)count(array_filter($allowed));
+ break;
+
+ case 'max_folders':
+ case 'max_recipients':
+ case 'max_timelimit':
+ $allowed = max($allowed);
+ break;
}
return (($permission == 'max_folders') && empty($opts['value']))
}
/**
- * Returns the specified permission for the current user.
+ * Returns the specified permission for the given app permission.
*
- * @param mixed $allowed The allowed permissions.
+ * @param string $permission The permission to check.
+ * @param mixed $allowed The allowed permissions.
+ * @param array $opts Additional options (NONE).
*
* @return mixed The value of the specified permission.
*/
- public function hasPermission($allowed)
+ public function hasPermission($permission, $allowed, $opts = array())
{
- if (is_array($allowed)) {
- switch ($permission) {
- case 'allow_rules':
- $allowed = (bool)count(array_filter($allowed));
- break;
-
- case 'max_rules':
- $allowed = max($allowed);
- break;
- }
+ switch ($permission) {
+ case 'allow_rules':
+ $allowed = (bool)count(array_filter($allowed));
+ break;
+
+ case 'max_rules':
+ $allowed = max($allowed);
+ break;
}
return $allowed;
}
/**
- * Returns the specified permission for the current user.
+ * Returns the specified permission for the given app permission.
*
- * @param mixed $allowed The allowed permissions.
+ * @param string $permission The permission to check.
+ * @param mixed $allowed The allowed permissions.
+ * @param array $opts Additional options (NONE).
*
* @return mixed The value of the specified permission.
*/
- public function hasPermission($allowed)
+ public function hasPermission($permission, $allowed, $opts = array())
{
- if (is_array($allowed)) {
- switch ($permission) {
- case 'max_events':
- $allowed = max($allowed);
- break;
- }
+ switch ($permission) {
+ case 'max_events':
+ $allowed = max($allowed);
+ break;
}
return $allowed;
$perms['title']['mnemo:max_notes'] = _("Maximum Number of Notes");
$perms['type']['mnemo:max_notes'] = 'int';
- return $perms;
+ return $perms;
+ }
+
+ /**
+ * Returns the specified permission for the given app permission.
+ *
+ * @param string $permission The permission to check.
+ * @param mixed $allowed The allowed permissions.
+ * @param array $opts Additional options (NONE).
+ *
+ * @return mixed The value of the specified permission.
+ */
+ public function hasPermission($permission, $allowed, $opts = array())
+ {
+ switch ($permission) {
+ case 'max_notes':
+ $allowed = max($allowed);
+ break;
+ }
+
+ return $allowed;
}
/**
* Sort by memo description.
*/
const SORT_DESC = 0;
-
+
/**
* Sort by memo category.
*/
const SORT_CATEGORY = 1;
-
+
/**
* Sort by notepad.
*/
const SORT_NOTEPAD = 2;
-
+
/**
* Sort in ascending order.
*/
const SORT_ASCEND = 0;
-
+
/**
* Sort in descending order.
*/
const SORT_DESCEND = 1;
-
+
/**
* No passphrase provided.
*/
const ERR_NO_PASSPHRASE = 100;
-
+
/**
* Decrypting failed
*/
switch ($actionID) {
case 'add_memo':
/* Check permissions. */
- if ($GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_notes') !== true &&
- $GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_notes') <= Mnemo::countMemos()) {
- $message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d notes."), Mnemo::hasPermission('max_notes')), ENT_COMPAT, $GLOBALS['registry']->getCharset());
+ if ($injector->getInstance('Horde_Perms')->hasAppPermission('max_notes') !== true &&
+ $injector->getInstance('Horde_Perms')->hasAppPermission('max_notes') <= Mnemo::countMemos()) {
+ $message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d notes."), $injector->getInstance('Horde_Perms')->hasAppPermission('max_notes')), ENT_COMPAT, $registry->getCharset());
if (!empty($conf['hooks']['permsdenied'])) {
$message = Horde::callHook('_perms_hook_denied', array('mnemo:max_notes'), 'horde', $message);
}
$memo_passphrase2 = Horde_Util::getFormData('memo_passphrase2');
try {
- $share = $GLOBALS['mnemo_shares']->getShare($notepad_target);
+ $share = $mnemo_shares->getShare($notepad_target);
} catch (Horde_Share_Exception $e) {
throw new Mnemo_Exception($e);
}
- if (!$share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
+ if (!$share->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) {
$notification->push(sprintf(_("Access denied saving note to %s."), $share->get('name')), 'horde.error');
} elseif ($memo_passphrase != $memo_passphrase2) {
$notification->push(_("The passwords don't match."), 'horde.error');
if ($memolist_original != $notepad_target) {
/* Moving the note to another notepad. */
try {
- $share = $GLOBALS['mnemo_shares']->getShare($memolist_original);
+ $share = $mnemo_shares->getShare($memolist_original);
} catch (Horde_Share_Exception $e) {
throw new Mnemo_Exception($e);
}
- if ($share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE)) {
+ if ($share->hasPermission($registry->getAuth(), Horde_Perms::DELETE)) {
try {
- $share = &$GLOBALS['mnemo_shares']->getShare($notepad_target);
+ $share = &$mnemo_shares->getShare($notepad_target);
} catch (Horde_Share_Exception $e) {
throw new Mnemo_Exception($e);
}
- if ($share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
+ if ($share->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) {
$result = $storage->move($memo_id, $notepad_target);
$storage = &Mnemo_Driver::singleton($notepad_target);
} else {
$result = $storage->modify($memo_id, $memo_desc, $memo_body, $memo_category, $memo_passphrase);
} else {
/* Check permissions. */
- if ($GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_notes') !== true &&
- $GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_notes') <= Mnemo::countMemos()) {
+ if ($injector->getInstance('Horde_Perms')->hasAppPermission('max_notes') !== true &&
+ $injector->getInstance('Horde_Perms')->hasAppPermission('max_notes') <= Mnemo::countMemos()) {
header('Location: ' . Horde::applicationUrl('list.php', true));
exit;
}
if (!is_null($memo_id) && Mnemo::getMemo($memolist_id, $memo_id)) {
try {
- $share = $GLOBALS['mnemo_shares']->getShare($memolist_id);
+ $share = $mnemo_shares->getShare($memolist_id);
} catch (Horde_Share_Exception $e) {
throw new Mnemo_Exception($e);
}
- if ($share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE)) {
+ if ($share->hasPermission($registry->getAuth(), Horde_Perms::DELETE)) {
$storage = &Mnemo_Driver::singleton($memolist_id);
$result = $storage->delete($memo_id);
if ($result instanceof PEAR_Error) {
}
/**
- * Returns the specified permission for the current user.
+ * Returns the specified permission for the given app permission.
*
- * @param mixed $allowed The allowed permissions.
+ * @param string $permission The permission to check.
+ * @param mixed $allowed The allowed permissions.
+ * @param array $opts Additional options (NONE).
*
* @return mixed The value of the specified permission.
*/
- public function hasPermission($allowed)
+ public function hasPermission($permission, $allowed, $opts = array())
{
- if (is_array($allowed)) {
- switch ($permission) {
- case 'max_tasks':
- $allowed = max($allowed);
- break;
- }
+ switch ($permission) {
+ case 'max_tasks':
+ $allowed = max($allowed);
+ break;
}
return $allowed;