File: groups.php

package info (click to toggle)
php-horde 5.2.1%2Bdebian0-2%2Bdeb8u3
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 12,252 kB
  • ctags: 2,180
  • sloc: php: 11,103; xml: 6,460; sh: 96; makefile: 33; sql: 1
file content (223 lines) | stat: -rw-r--r-- 6,424 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
/**
 * Copyright 1999-2014 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (LGPL-2). If you
 * did not receive this file, see http://www.horde.org/licenses/lgpl.
 *
 * @author   Chuck Hagenbuch <chuck@horde.org>
 * @category Horde
 * @license  http://www.horde.org/licenses/lgpl LGPL-2
 * @package  Horde
 */

require_once __DIR__ . '/../lib/Application.php';
Horde_Registry::appInit('horde', array(
    'permission' => array('horde:administration:groups')
));

$auth = $injector->getInstance('Horde_Core_Factory_Auth')->create();
$groups = $injector->getInstance('Horde_Group');
$vars = $injector->getInstance('Horde_Variables');

$form = $groups->readOnly() ? null : 'add.inc';
$gid = $vars->gid;

switch ($vars->actionID) {
case 'addform':
    try {
        $gid = $groups->create($vars->name);
        $group = $groups->getData($gid);
        $form = 'edit.inc';
        $notification->push(sprintf(_("\"%s\" was added to the groups system."), $vars->name), 'horde.success');
    } catch (Horde_Group_Exception $e) {
        Horde::log($e, 'ERR');
        $notification->push(sprintf(_("Group was not created: %s."), $e->getMessage()), 'horde.error');
        break;
    }
    break;

case 'delete':
    if ($groups->readOnly()) {
        break;
    }
    try {
        $group = $groups->getName($gid);
        $form = 'delete.inc';
    } catch (Horde_Group_Exception $e) {
    }
    break;

case 'deleteform':
    if ($groups->readOnly() || ($vars->confirm != _("Delete"))) {
        break;
    }
    if (!$groups->exists($gid)) {
        $notification->push(_("Attempt to delete a non-existent group."), 'horde.error');
        break;
    }

    $name = $groups->getName($gid);
    try {
        $groups->remove($gid);
        $notification->push(sprintf(_("Successfully deleted \"%s\"."), $name), 'horde.success');
        $gid = null;
    } catch (Horde_Group_Exception $e) {
        $notification->push(sprintf(_("Unable to delete \"%s\": %s."), $name, $e->getMessage()), 'horde.error');
    }
    break;

case 'edit':
    try {
        $group = $groups->getData($gid);
        $form = 'edit.inc';
    } catch (Horde_Group_Exception $e) {}
    break;

case 'editform':
    if ($groups->readOnly()) {
        break;
    }
    try {
        // Add any new users.
        $newuser = $vars->new_user;
        if (!empty($newuser)) {
            if (is_array($newuser)) {
                foreach ($newuser as $new) {
                    $groups->addUser($gid, $new);
                }
            } else {
                $groups->addUser($gid, $newuser);
            }
        }

        // Remove any users marked for purging.
        $removes = $vars->remove;
        if (!empty($removes) && is_array($removes)) {
            foreach ($removes as $user => $junk) {
                $groups->removeUser($gid, $user);
            }
        }

        // Set the email address of the group.
        $groups->setData($gid, 'email', $vars->email);

        $notification->push(sprintf(_("Updated \"%s\"."), $groups->getName($gid)), 'horde.success');
    } catch (Horde_Group_Exception $e) {
        $notification->push($e, 'horde.error');
        // restore backup copy
        $group = $restore;
    }

    try {
        $group = $groups->getData($gid);
        $form = 'edit.inc';
    } catch (Horde_Group_Exception $e) {}
    break;
}

switch ($form) {
case 'addchild.inc':
    $page_output->addInlineScript(array(
        '$("child").focus()'
    ), true);
    break;

case 'edit.inc':
    /* Set up the lists. */
    try {
        $users = $groups->listUsers($gid);
    } catch (Horde_Group_Exception $e) {
        $notification->push($e, 'horde.error');
        $users = array();
    }

    /*
    try {
        $all_users = $group->listAllUsers();
    } catch (Horde_Group_Exception $e) {
        $notification->push($e, 'horde.error');
        $all_users = array();
    }
    $inherited_users = array_diff($all_users, $users);
    */
    $inherited_users = array();

    if ($auth->hasCapability('list')) {
        try {
            $user_list = $auth->listUsers();
        } catch (Horde_Auth_Exception $e) {
            $notification->push($e, 'horde.error');
            $user_list = array();
        }
        sort($user_list);
    } else {
        $user_list = array();
    }
    break;
}

$page_output->header(array(
    'title' => _("Group Administration")
));
require HORDE_TEMPLATES . '/admin/menu.inc';
if (!empty($form)) {
    require HORDE_TEMPLATES . '/admin/groups/' . $form;
}

/* Get the perms tree. */
$nodes = $groups->listAll();

/* Set up some node params. */
$spacer = '&nbsp;&nbsp;&nbsp;&nbsp;';
$group_node = array('icon' => strval(Horde_Themes::img('group.png')));
$group_url = Horde::url('admin/groups.php', true);
$edit = $group_url->copy()->add('actionID', 'edit');
if (!$groups->readOnly()) {
    $add = $group_url->copy()->add('actionID', 'addchild');
    $add_img = Horde_Themes_Image::tag('add_group.png');
    $delete = $group_url->copy()->add('actionID', 'delete');
    $delete_img = Horde_Themes_Image::tag('delete.png', array(
        'alt' => _("Delete Group")
    ));
}

/* Set up the tree. */
$tree = $injector->getInstance('Horde_Core_Factory_Tree')->create('admin_groups', 'Javascript', array(
    'alternate' => true,
    'hideHeaders' => true
));
$tree->setHeader(array(
    array(
        'class' => 'horde-tree-spacer'
    )
));

$base_node_params = array(
    'icon' => strval(Horde_Themes::img('administration.png'))
);

foreach ($nodes as $id => $node) {
    $node_params = ($gid == $id) ? array('class' => 'selected') : array();

    $node_params['url'] = $edit->copy()->add('gid', $id);
    if ($groups->readOnly()) {
        $delete_link = null;
    } else {
        //$add_link = Horde::link($add->copy()->add('gid', $id), sprintf(_("Add a child group to \"%s\""), $name)) . $add_img . '</a>';
        $delete_link = Horde::link($delete->copy()->add('gid', $id), sprintf(_("Delete \"%s\""), $node)) . $delete_img . '</a>';
    }

    $tree->addNode(array(
        'id' => $id,
        'parent' => null,
        'label' => htmlspecialchars($node),
        'expanded' => false,
        'params' => $group_node + $node_params,
        'right' => array($spacer, $delete_link)
    ));
}

echo '<h1 class="header">' . Horde::img('group.png') . ' ' . _("Groups") . '</h1>';
$tree->renderTree();
$page_output->footer();