1: <?php
2: /**
3: * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
4: *
5: * See the enclosed file LICENSE for license information (BSD). If you did
6: * did not receive this file, see http://cvs.horde.org/co.php/vilma/LICENSE.
7: *
8: * @author Marko Djukic <marko@oblo.com>
9: * @author David Cummings <davidcummings@acm.org>
10: * @package Vilma
11: */
12: class Vilma
13: {
14: /**
15: * Checks whether the current user has administrative permissions over the
16: * requested domain at the given permissions level.
17: *
18: * Also checks to see if the user is a Vilma superadmin. If the user is a
19: * Horde admin they automatically have permission.
20: *
21: * @param string $domain Domain for which to check permissions.
22: * @param integer $permmask Permissions that must be set for the user.
23: *
24: * @return boolean True if the user has the requested permission.
25: */
26: static public function hasPermission($domain = null, $permmask = null)
27: {
28: if ($GLOBALS['registry']->isAdmin()) {
29: return true;
30: }
31:
32: if (is_null($permmask)) {
33: $permmask = Horde_Perms::SHOW | Horde_Perms::READ;
34: }
35: $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
36:
37: if ($perms->hasPermission('vilma:domains', $GLOBALS['registry']->getAuth(), $permmask)) {
38: return true;
39: }
40: if ($domain &&
41: $perms->hasPermission('vilma:domains:' . $domain, $GLOBALS['registry']->getAuth(), $permmask)) {
42: return true;
43: }
44:
45: return false;
46: }
47:
48: static public function getUserMgrTypes()
49: {
50: return array(
51: 'all' => array(
52: 'singular' => _("All"),
53: 'plural' => _("All")),
54: 'user' => array(
55: 'singular' => _("User"),
56: 'plural' => _("Users")),
57: 'alias' => array(
58: 'singular' => _("Alias"),
59: 'plural' => _("Aliases")),
60: 'group' => array(
61: 'singular' => _("Group"),
62: 'plural' => _("Groups")),
63: 'forward' => array(
64: 'singular' => _("Forward"),
65: 'plural' => _("Forwards")));
66: }
67:
68: /**
69: * Creates tabs to navigate the user manager area.
70: *
71: * @return Horde_Core_Ui_Tabs
72: */
73: static public function getUserMgrTabs(Variables $vars)
74: {
75: $url = Horde::url('users/index.php');
76: $tabs = new Horde_Core_Ui_Tabs('section', $vars);
77: foreach (Vilma::getUserMgrTypes() as $section => $desc) {
78: $tabs->addTab($desc['plural'], $url, $section);
79: }
80: return $tabs;
81: }
82:
83: /**
84: * Set the current domain.
85: */
86: static public function setCurDomain($domain = null)
87: {
88: $GLOBALS['session']->set('vilma', 'domain', $domain);
89: }
90:
91: /**
92: * Strips the domain from an email address (leaving the user name).
93: *
94: * @param string $email Email address to strip.
95: *
96: * @return string User name portion of the email address.
97: */
98: static public function stripUser($email)
99: {
100: list($user, $domain) = explode('@', $email);
101: return $user;
102: }
103:
104: /**
105: * Strip the user name from an email address (leaving the domain).
106: *
107: * @param string $email Email address to strip.
108: *
109: * @return string Domain portion of the email address.
110: */
111: static public function stripDomain($email)
112: {
113: $parts = explode('@', $email);
114: if (count($parts) == 2) {
115: $parts = explode(',', $parts[1]);
116: return $parts[0];
117: }
118: return null;
119: }
120: }
121: