<?php
/*
* ConPortal - Pomona College ITS scheduling appplication
* Copyright (C) 2005-2006 Pomona College
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of version 2 of the GNU General Public License
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
require_once('../standard.php');
if (isset($_POST['user']) && intval($_POST['user'])) {
$user = $_POST['user'];
$cur_groups = getGroupsForUser($user);
if (!isset($_POST['selgroups']))
$_POST['selgroups'] = array();
// Figure out what we need to add/remove
$remove = array_diff($cur_groups, $_POST['selgroups']);
$add = array_diff($_POST['selgroups'], $cur_groups);
// Remove users no longer in the group and add users to the group
foreach ($remove as $r)
removeUserFromGroup($user, $r);
foreach ($add as $a)
addUserToGroup($user, $a);
} elseif (isset($_POST['group']) && intval($_POST['group'])) {
$group = $_POST['group'];
$cur_users = getUsersForSecurityGroup($group);
$cur_perms = getPermissionsForGroup($group);
if (!isset($_POST['selusers']))
$_POST['selusers'] = array();
// Figure out what we need to add/remove
$remove = array_diff($cur_users, $_POST['selusers']);
$add = array_diff($_POST['selusers'], $cur_users);
// Remove users no longer in the group and add users to the group
foreach ($remove as $r)
removeUserFromGroup($r, $group);
foreach ($add as $a)
addUserToGroup($a, $group);
// --------------------
if (!isset($_POST['selperms']))
$_POST['selperms'] = array();
$remove = array_diff($cur_perms, $_POST['selperms']);
$add = array_diff($_POST['selperms'], $cur_perms);
// Remove/Add permissions to the group
foreach ($remove as $r)
revokePermissionFromGroup($r, $group);
foreach ($add as $a)
grantPermissionToGroup($a, $group);
} elseif (isset($_POST['perm']) && intval($_POST['perm'])) {
$perm = $_POST['perm'];
$cur_groups = getGroupsForPermission($perm);
if (!isset($_POST['selgroups']))
$_POST['selgroups'] = array();
// Figure out what we need to add/remove
$remove = array_diff($cur_groups, $_POST['selgroups']);
$add = array_diff($_POST['selgroups'], $cur_groups);
// Remove/Add permissions to groups
foreach ($remove as $r)
revokePermissionFromGroup($perm, $r);
foreach ($add as $a)
grantPermissionToGroup($perm, $a);
}
header("Location: ".$_SERVER['HTTP_REFERER']);
?>