\n";
if($state) {
if($data["type"] == "user")
print "
Add User Group \n";
else
print "
Add Resource Group \n";
}
else {
if($data["type"] == "user") {
print "
Edit User Group \n";
print "{$usergroups[$data['groupid']]['name']}
\n";
$editusergroup = 1;
}
else
print "
Edit Resource Group \n";
}
if(($state && $data["type"] == "user") || $data["isowner"] ||
$data["type"] == "resource") {
print "
\n";
if($data["type"] == "resource") {
print " \n";
print " Type: \n";
print " \n";
if($state && $submitErr)
$resourcetypeid = $data['resourcetypeid'];
else
$resourcetypeid = array_search($grouptype, $resourcetypes["resources"]);
if($state)
printSelectInput("resourcetypeid", $resourcetypes["resources"], $resourcetypeid);
else
print " $grouptype\n";
print " \n";
print " \n";
print " \n";
}
print " \n";
print " Name: \n";
print " ";
if($data['type'] == 'user' && $selectAffil) {
print "@";
printSelectInput('affiliationid', $affils, $data['affiliationid']);
}
print " \n";
print " ";
printSubmitErr(GRPNAMEERR);
print " \n";
print " \n";
if($data["type"] == "user") {
print " \n";
print " Owner: \n";
print " \n";
print " ";
printSubmitErr(GRPOWNER);
print " \n";
print " \n";
print " \n";
print " Editable by: \n";
print " \n";
if(! empty($data['editgroupid']) &&
! array_key_exists($data['editgroupid'], $affilusergroups)) {
$affilusergroups[$data['editgroupid']] =
array('name' => getUserGroupName($data['editgroupid'], 1));
uasort($affilusergroups, "sortKeepIndex");
}
printSelectInput("editgroupid", $affilusergroups, $data["editgroupid"]);
print " \n";
print " ";
print " \n";
print " \n";
print " Initial Max Time (minutes): \n";
print " \n";
print " ";
printSubmitErr(INITIALMAXERR);
print " \n";
print " \n";
print " \n";
print " Total Max Time (minutes): \n";
print " \n";
print " ";
printSubmitErr(TOTALMAXERR);
print " \n";
print " \n";
print " \n";
print " Max Extend Time (minutes): \n";
print " \n";
print " ";
printSubmitErr(MAXEXTENDERR);
print " \n";
print " \n";
if($viewmode == ADMIN_DEVELOPER) {
print " \n";
print " Max Overlapping Reservations: \n";
print " \n";
print " ";
printSubmitErr(MAXOVERLAPERR);
print " \n";
print " \n";
}
}
else {
print " \n";
print " Owning User Group: \n";
print " \n";
if(! array_key_exists($ownerid, $affilusergroups)) {
$affilusergroups[$ownerid] = $usergroups[$ownerid];
uasort($affilusergroups, "sortKeepIndex");
}
printSelectInput("ownergroup", $affilusergroups, $ownerid);
print " \n";
print " \n";
print " \n";
}
print "
\n";
print "
\n";
}
if($data["type"] != "user")
return;
if($editusergroup) {
print "
Group Membership \n";
if($mode == "addGroupUser" && ! ($submitErr & IDNAMEERR)) {
print "
$newuser successfully added to group";
print " \n";
}
if($mode == "deleteGroupUser") {
print "
$newuser successfully deleted from ";
print "group \n";
}
$groupmembers = getUserGroupMembers($data["groupid"]);
print "
\n";
print " \n";
print " \n";
print " \n";
foreach($groupmembers as $id => $login) {
print " \n";
print " \n";
print " \n";
print " \n";
print " $login \n";
print " \n";
}
print "
\n";
}
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn processGroupInput($checks)
///
/// \param $checks - (optional) 1 to perform validation, 0 not to
///
/// \return an array with the following indexes:\n
/// groupid, name, prettyname, platformid, osid
///
/// \brief validates input from the previous form; if anything was improperly
/// submitted, sets submitErr and submitErrMsg
///
////////////////////////////////////////////////////////////////////////////////
function processGroupInput($checks=1) {
global $submitErr, $submitErrMsg, $user, $viewmode;
$return = array();
$return["groupid"] = getContinuationVar("groupid");
$return["type"] = getContinuationVar("type");
$return["name"] = getContinuationVar('name', processInputVar("name", ARG_STRING));
$return["affiliationid"] = getContinuationVar('affiliationid', processInputVar("affiliationid", ARG_NUMERIC, $user['affiliationid']));
$return["resourcetypeid"] = getContinuationVar('resourcetypeid', processInputVar("resourcetypeid", ARG_NUMERIC));
$return["owner"] = getContinuationVar('owner', processInputVar("owner", ARG_STRING));
$return["ownergroup"] = processInputVar("ownergroup", ARG_NUMERIC);
$return["editgroupid"] = getContinuationVar('editgroupid', processInputVar("editgroupid", ARG_NUMERIC));
$return["isowner"] = getContinuationVar("isowner");
$return["initialmax"] = getContinuationVar('initialmax', processInputVar("initialmax", ARG_NUMERIC));
$return["totalmax"] = getContinuationVar('totalmax', processInputVar("totalmax", ARG_NUMERIC));
$return["maxextend"] = getContinuationVar('maxextend', processInputVar("maxextend", ARG_NUMERIC));
$return["overlap"] = getContinuationVar('overlap', processInputVar("overlap", ARG_NUMERIC, 0));
$affils = getAffiliations();
if(! array_key_exists($return['affiliationid'], $affils))
$return['affiliationid'] = $user['affiliationid'];
if(! $checks) {
return $return;
}
if(! preg_match('/^[-a-zA-Z0-9_\.: ]{3,30}$/', $return["name"])) {
$submitErr |= GRPNAMEERR;
$submitErrMsg[GRPNAMEERR] = "Name must be between 3 and 30 characters "
. "and can only contain letters, numbers, and "
. "these characters: - _ . :";
}
if($return['type'] == 'user')
$extraid = $return['affiliationid'];
else
$extraid = $return['resourcetypeid'];
if(! empty($return["type"]) && ! empty($return["name"]) &&
! ($submitErr & GRPNAMEERR) &&
checkForGroupName($return["name"], $return["type"], $return["groupid"],
$extraid)) {
$submitErr |= GRPNAMEERR;
$submitErrMsg[GRPNAMEERR] = "A group already exists with this name.";
}
if($return["type"] == "user" && ! validateUserid($return["owner"])) {
$submitErr |= GRPOWNER;
$submitErrMsg[GRPOWNER] = "Submitted ID is not valid";
}
if($return["type"] == "user" && $return["initialmax"] < 30) {
$submitErr |= INITIALMAXERR;
$submitErrMsg[INITIALMAXERR] = "Initial max time must be at least 30 "
. "minutes";
}
if($return["type"] == "user" && $return["totalmax"] < 30) {
$submitErr |= TOTALMAXERR;
$submitErrMsg[TOTALMAXERR] = "Total max time must be at least 30 "
. "minutes";
}
if($return["type"] == "user" && $return["maxextend"] < 15) {
$submitErr |= MAXEXTENDERR;
$submitErrMsg[MAXEXTENDERR] = "Max extend time must be at least 15 "
. "minutes";
}
if($viewmode == ADMIN_DEVELOPER &&
$return["type"] == "user" &&
($return["overlap"] < 0 ||
$return["overlap"] == 1)) {
$submitErr |= MAXOVERLAPERR;
$submitErrMsg[MAXOVERLAPERR] = "Overlap can be 0 or greater than or equal to 2";
}
return $return;
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn checkForGroupName($name, $type, $id, $extraid)
///
/// \param $name - the name of a group
/// \param $type - user or resource
/// \param $id - id of a group to ignore
/// \param $extraid - if $type is resource, this is a resource type id; if
/// $type is user, this is an affiliation id
///
/// \return 1 if $name is already in the associated table, 0 if not
///
/// \brief checks for $name being in usergroup/resource group (based on $type)
/// except for $id
///
////////////////////////////////////////////////////////////////////////////////
function checkForGroupName($name, $type, $id, $extraid) {
if($type == "user")
$query = "SELECT id FROM usergroup "
. "WHERE name = '$name' AND "
. "affiliationid = $extraid";
else
$query = "SELECT id FROM resourcegroup "
. "WHERE name = '$name' AND "
. "resourcetypeid = $extraid";
if(! empty($id))
$query .= " AND id != $id";
$qh = doQuery($query, 101);
if(mysql_num_rows($qh))
return 1;
return 0;
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn updateGroup($data)
///
/// \param $data - an array returned from processGroupInput
///
/// \return number of rows affected by the update\n
/// \b NOTE: mysql reports that no rows were affected if none of the fields
/// were actually changed even if the update matched a row
///
/// \brief performs a query to update the group with data from $data
///
////////////////////////////////////////////////////////////////////////////////
function updateGroup($data) {
global $viewmode;
if($data["type"] == "user") {
$ownerid = getUserlistID($data["owner"]);
$query = "UPDATE usergroup "
. "SET name = '{$data["name"]}', "
. "affiliationid = {$data['affiliationid']}, "
. "ownerid = $ownerid, "
. "editusergroupid = {$data["editgroupid"]}, "
. "initialmaxtime = {$data["initialmax"]}, "
. "totalmaxtime = {$data["totalmax"]}, ";
if($viewmode == ADMIN_DEVELOPER)
$query .= "overlapResCount = {$data["overlap"]}, ";
$query .= "maxextendtime = {$data["maxextend"]} "
. "WHERE id = {$data["groupid"]}";
}
else {
$query = "UPDATE resourcegroup "
. "SET name = '{$data["name"]}', "
. "ownerusergroupid = {$data["ownergroup"]} "
. "WHERE id = {$data["groupid"]}";
}
$qh = doQuery($query, 300);
return mysql_affected_rows($GLOBALS["mysql_link_vcl"]);
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn addGroup($data)
///
/// \param $data - an array returned from processGroupInput
///
/// \return number of rows affected by the insert\n
///
/// \brief performs a query to insert the group with data from $data
///
////////////////////////////////////////////////////////////////////////////////
function addGroup($data) {
global $viewmode;
if($data["type"] == "user") {
$ownerid = getUserlistID($data["owner"]);
$query = "INSERT INTO usergroup "
. "(name, "
. "affiliationid, "
. "ownerid, "
. "editusergroupid, "
. "custom, "
. "initialmaxtime, "
. "totalmaxtime, ";
if($viewmode == ADMIN_DEVELOPER)
$query .= "overlapResCount, ";
$query .= "maxextendtime) "
. "VALUES ('{$data["name"]}', "
. "{$data["affiliationid"]}, "
. "$ownerid, "
. "{$data["editgroupid"]}, "
. "1, "
. "{$data["initialmax"]}, "
. "{$data["totalmax"]}, ";
if($viewmode == ADMIN_DEVELOPER)
$query .= "{$data["overlap"]}, ";
$query .= "{$data["maxextend"]})";
}
else {
$query = "INSERT INTO resourcegroup "
. "(name, "
. "ownerusergroupid, "
. "resourcetypeid) "
. "VALUES ('" . $data["name"] . "', "
. $data["ownergroup"] . ", "
. "'" . $data["resourcetypeid"] . "')";
}
$qh = doQuery($query, 305);
clearPrivCache();
return mysql_affected_rows($GLOBALS["mysql_link_vcl"]);
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn checkForGroupUsage($groupid, $type)
///
/// \param $groupid - id of an group
/// \param $type - group type: "user" or "resource"
///
/// \return 0 if group is not used, 1 if it is
///
/// \brief checks for $groupid being in the priv table corresponding to $type
///
////////////////////////////////////////////////////////////////////////////////
function checkForGroupUsage($groupid, $type) {
if($type == "user") {
$query = "SELECT id FROM resourcegroup WHERE ownerusergroupid = $groupid";
$qh = doQuery($query, 310);
if(mysql_num_rows($qh))
return 1;
$query = "SELECT id "
. "FROM blockRequest "
. "WHERE groupid = $groupid "
. "OR admingroupid = $groupid";
$qh = doQuery($query, 311);
if(mysql_num_rows($qh))
return 1;
$query = "SELECT id FROM imagemeta WHERE usergroupid = $groupid";
$qh = doQuery($query, 312);
if(mysql_num_rows($qh))
return 1;
$query = "SELECT id "
. "FROM usergroup "
. "WHERE editusergroupid = $groupid "
. "AND id != $groupid";
$qh = doQuery($query, 313);
if(mysql_num_rows($qh))
return 1;
$query = "SELECT id FROM userpriv WHERE usergroupid = $groupid";
}
else
$query = "SELECT id FROM resourcepriv WHERE resourcegroupid = $groupid";
$qh = doQuery($query, 314);
if(mysql_num_rows($qh))
return 1;
return 0;
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn confirmEditOrAddGroup($state)
///
/// \param $state - 0 for edit, 1 for add
///
/// \brief prints a form for confirming changes to an group
///
////////////////////////////////////////////////////////////////////////////////
function confirmEditOrAddGroup($state) {
global $submitErr, $user, $viewmode;
$data = processGroupInput(1);
if($submitErr) {
editOrAddGroup($state);
return;
}
$resourcetypes = getTypes("resources");
$usergroups = getUserGroups(1);
$affils = getAffiliations();
if($state) {
if($data["type"] == "user") {
$title = "Add User Group";
$question = "Add the following user group?";
$target = "";
}
else {
$title = "Add Resource Group";
$question = "Add the following resource group?";
$target = "#resources";
}
$nextmode = "submitAddGroup";
}
else {
if($data["type"] == "user") {
$title = "Edit User Group";
$question = "Submit changes to the user group?";
$target = "";
}
else {
$title = "Edit Resource Group";
$question = "Submit changes to the resource group?";
$target = "#resources";
}
$nextmode = "submitEditGroup";
}
print "
\n";
print "
$title \n";
print "$question
\n";
print "
\n";
if($data["type"] == "resource") {
print " \n";
print " Type: \n";
print " " . $resourcetypes["resources"][$data["resourcetypeid"]];
print " \n";
print " \n";
}
print " \n";
print " Name: \n";
if($data['type'] == 'user' && ($user['showallgroups'] ||
$data['affiliationid'] != $user['affiliationid']))
print " {$data["name"]}@{$affils[$data['affiliationid']]} \n";
else
print " {$data["name"]} \n";
print " \n";
if($data["type"] == "user") {
print " \n";
print " Owner: \n";
print " " . $data["owner"] . " \n";
print " \n";
print " \n";
print " Editable by: \n";
if(! $user['showallgroups']) {
$tmp = explode('@', $usergroups[$data["editgroupid"]]["name"]);
if($tmp[1] == $user['affiliation'])
$usergroups[$data["editgroupid"]]["name"] = $tmp[0];
}
print " " . $usergroups[$data["editgroupid"]]["name"] . " \n";
print " \n";
print " \n";
print " Initial Max Time (minutes): \n";
print " {$data["initialmax"]} \n";
print " \n";
print " \n"; print " Total Max Time (minutes): \n";
print " {$data["totalmax"]} \n";
print " \n";
print " \n";
print " Max Extend Time (minutes): \n";
print " {$data["maxextend"]} \n";
print " \n";
if($viewmode == ADMIN_DEVELOPER) {
print " \n";
print " Max Overlapping Reservations: \n";
print " {$data["overlap"]} \n";
print " \n";
}
}
else {
print " \n";
print " Owning User Group: \n";
if(! $user['showallgroups'] &&
preg_match("/^(.+)@{$user['affiliation']}$/",
$usergroups[$data['ownergroup']]['name'], $matches))
print " {$matches[1]}";
else
print " " . $usergroups[$data["ownergroup"]]["name"];
print " \n";
print " \n";
}
print "
\n";
print "
\n";
print " \n";
print " \n";
print " \n";
print " \n";
print " \n";
print " \n";
print " \n";
print " \n";
print "
\n";
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn submitEditGroup()
///
/// \brief submits changes to group and notifies user
///
////////////////////////////////////////////////////////////////////////////////
function submitEditGroup() {
$data = getContinuationVar();
updateGroup($data);
$_SESSION['userresources'] = array();
$_SESSION['nodeprivileges'] = array();
#$_SESSION['cascadenodeprivileges'] = array(); // might need this uncommented
viewGroups();
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn submitAddGroup()
///
/// \brief adds the group and notifies user
///
////////////////////////////////////////////////////////////////////////////////
function submitAddGroup() {
global $submitErr;
$data = processGroupInput(1);
if($submitErr) {
editOrAddGroup(1);
return;
}
if(! addGroup($data))
abort(10);
viewGroups();
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn confirmDeleteGroup()
///
/// \brief prints a form to confirm the deletion of an group
///
////////////////////////////////////////////////////////////////////////////////
function confirmDeleteGroup() {
$groupid = getContinuationVar("groupid");
$type = getContinuationVar("type");
$usergroups = getUserGroups(1);
$resourcegroups = getResourceGroups();
if($type == "user") {
$title = "Delete User Group";
$usemsg = "This group is currently in use. You cannot delete it until "
. "it is no longer being used.";
$question = "Delete the following user group?";
$name = $usergroups[$groupid]["name"];
$target = "";
}
else {
$title = "Delete Resource Group";
$usemsg = "This group is currently assigned to at least one node in the "
. "privilege tree. You cannot delete it until it is no longer "
. "in use.";
$question = "Delete the following resource group?";
list($resourcetype, $name) =
explode('/', $resourcegroups[$groupid]["name"]);
$target = "#resources";
}
if(checkForGroupUsage($groupid, $type)) {
print "
$title \n";
print $usemsg;
return;
}
print "
\n";
print "
$title \n";
print "$question
\n";
print "
\n";
if($type == "resource") {
print " \n";
print " Type: \n";
print " $resourcetype \n";
print " \n";
}
print " \n";
print " Name: \n";
print " $name \n";
print " \n";
if($type == "resource") {
print " \n";
print " Owning User Group: \n";
print " " . $resourcegroups[$groupid]["owner"] . " \n";
print " \n";
}
print "
\n";
print "
\n";
print " \n";
print " \n";
print " \n";
print " \n";
print " \n";
print " \n";
print " \n";
print " \n";
print "
\n";
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn submitDeleteGroup()
///
/// \brief deletes an group from the database and notifies the user
///
////////////////////////////////////////////////////////////////////////////////
function submitDeleteGroup() {
$groupid = getContinuationVar("groupid");
$type = getContinuationVar("type");
if($type == "user")
$table = "usergroup";
else
$table = "resourcegroup";
$query = "DELETE FROM $table "
. "WHERE id = $groupid";
doQuery($query, 315);
clearPrivCache();
viewGroups();
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn addGroupUser()
///
/// \brief adds a user to a group
///
////////////////////////////////////////////////////////////////////////////////
function addGroupUser() {
global $submitErr, $submitErrMsg;
$groupid = getContinuationVar("groupid");
$newuser = processInputVar("newuser", ARG_STRING);
if(! validateUserid($newuser)) {
$submitErr |= IDNAMEERR;
$submitErrMsg[IDNAMEERR] = "Invalid login ID";
editOrAddGroup(0);
return;
}
addUserGroupMember($newuser, $groupid);
editOrAddGroup(0);
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn deleteGroupUser()
///
/// \brief deletes a user from a group
///
////////////////////////////////////////////////////////////////////////////////
function deleteGroupUser() {
$groupid = getContinuationVar("groupid");
$userid = getContinuationVar("userid");
$test = getUserUnityID($userid);
if(! empty($test))
deleteUserGroupMember($userid, $groupid);
editOrAddGroup(0);
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn jsonGetGroupInfo()
///
/// \brief
///
////////////////////////////////////////////////////////////////////////////////
function jsonGetGroupInfo() {
$groupid = processInputVar('groupid', ARG_NUMERIC);
$mousex = processInputVar('mousex', ARG_NUMERIC);
$mousey = processInputVar('mousey', ARG_NUMERIC);
$userresources = getUserResources(array("groupAdmin"),
array("manageGroup"), 1);
$found = 0;
foreach(array_keys($userresources) as $type) {
if(array_key_exists($groupid, $userresources[$type])) {
$found = 1;
break;
}
}
if(! $found || $mousex < 0 || $mousex > 5000 || $mousey < 0 || $mousey > 500000) {
header('Content-Type: text/json; charset=utf-8');
print '{} && {"items":' . json_encode(array()) . '}';
return;
}
$members = getResourceGroupMembers($type);
$data = '';
if(! empty($members[$type][$groupid])) {
uasort($members[$type][$groupid], "sortKeepIndex");
foreach($members[$type][$groupid] as $mem) {
$data .= "{$mem['name']}
";
}
}
else
$data = '(empty group)';
$arr = array('members' => $data, 'x' => $mousex, 'y' => $mousey, 'groupid' => $groupid);
header('Content-Type: text/json-comment-filtered; charset=utf-8');
print '{} && {"items":' . json_encode($arr) . '}';
}
?>