" . _("Block Allocations") . "\n";
print _("Block Allocations are a way to have a set of machines preloaded with a particular environment at specified times and made available to a specific group of users. This is very useful for classroom use and for workshops. They can be made available on a repeating schedule such as when a course meets each week. Block Allocations only allocate machines for the group of users - they do not create the actual, end user reservations for the machines. All users still must log in to the VCL web site and make their own reservations DURING the period a block allocation is active. The forms here provide a way for you to submit a request for a Block Allocation for review by a sysadmin. If you just need to use a machine through VCL, use the New Reservation page for that.");
print "
";
print _("Please submit Block Allocation requests at least one full business day in advance to allow time for them to be approved.") . "
\n";
print _("You are currently a member of the following Block Allocations.") . " \n";
print _("Click an item to view its current status.") . " \n";
foreach($blocks as $id => $name) {
$cont = addContinuationsEntry('viewBlockStatus', array('id' => $id));
print "";
print "$name \n";
}
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn blockAllocationForm()
///
/// \brief prints a page for submitting a new block allocation, editing an
/// existing block allocation, or requesting a new block allocation
///
////////////////////////////////////////////////////////////////////////////////
function blockAllocationForm() {
global $user, $days, $mode;
$blockid = getContinuationVar('blockid', '');
$data = getBlockAllocationData($blockid);
if($mode == 'newBlockAllocation') {
$brname = '';
$imageid = '';
print "
\n";
print _("Complete the following form to request a new block allocation. Your request will need to be approved by a VCL admin before it is created.");
print "
\n";
print " and periods(.) and can be from 3 to 80 characters long\" ";
print "regExp=\"^([-a-zA-Z0-9\. \(\)]){3,80}$\" style=\"width: 300px\" ";
print "postCreate=\"dijit.byId('brname').focus();\">\n";
print "
\n";
if($mode == 'requestBlockAllocation')
print _("Please confirm the following values and then click Submit Block Allocation Request");
else {
print "Please confirm the following values and then click ";
print "$btntxt";
}
print "
\n
\n";
print "
\n";
print "
\n";
print "
\n";
print "
\n";
print "
\n";
print "
\n";
print "
\n";
print "
\n";
print "
\n";
print "
" . _("Environment") . ":
\n";
print "
\n";
print "
\n";
print "
\n";
print "
" . _("User group") . ":
\n";
print "
\n";
print "
\n";
print "
\n";
print "
" . _("Seats") . ":
\n";
print "
\n";
print "
\n";
print "
\n";
print "
" . _("Repeating") . ":
\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";
print "
\n";
print "
\n";
print "
\n";
print "
\n";
print "
\n";
print "
\n";
print "
\n";
print "" . _("Your additional comments will be submitted.") . "
\n";
print _("This is the number of environments that \n");
print _("will be loaded for the Block Allocation.\n");
print "
\n";
print "
\n";
print _("User in this user group will be able to make reservations \n");
print _("for the computers set aside for this block allocation. \n");
print _("If you do not see an applicable user group listed, please \n");
print _("select \"(group not listed)\" and describe the group you need \n");
print _("in the Additional Comments section at the bottom of \n");
print _("the page. If this is for a class, make sure to list the course \n");
print _("and section number.\n");
print "
\n";
print "
\n";
print _("Users in this user group can modify this \n");
print _("block allocation. Select None to keep \n");
print _("anyone else from being able to modify it.\n");
print "
\n";
print "
\n";
print _("For repeating block allocations, there are three ways you can enter the dates and times: \n");
print "
\n";
print _("
Repeating Weekly - Use this if the block allocation needs to occur every week. \n");
print _("You can make it repeat on a single day each week or on multiple days. The time(s) \n");
print _("that it occurs will be the same on all days. You can list as many times as needed.
\n");
print _("
Repeating Monthly - Use this if the block allocation needs to occur on a certain \n");
print _("day of the month (i.e. 2nd Tuesday each month). You can list as many times as \n");
print _("needed for that day of the month.
\n");
print _("
List of Dates/Times - Use this to specify any other cases, including single \n");
print _("events. You can specify as many date/time combinations as needed.
\n");
print "
\n";
print "
\n";
print "
\n";
print _("This is the first date the block allocation will be used.\n");
print "
\n";
print "
\n";
print _("This is the last date the block allocation will be used.\n");
print "
\n";
print "
\n";
print _("Select the checkbox for each of the days you \n");
print _("would like the block allocation to occur. For \n");
print _("example, check Monday, Wednesday, and Friday \n");
print _("for a class that meets on those days.\n");
print "
\n";
print "
\n";
print _("Here you specify the start and end times of the \n");
print _("block allocation. The times will occur on each \n");
print _("of the selected days. You might specify more than \n");
print _("one start/end combination if you had multiple \n");
print _("sections that met on the same day.\n");
print "
\n";
print "
\n";
print _("This is the first date the block allocation will be used.\n");
print "
\n";
print "
\n";
print _("This is the last date the block allocation will be used.\n");
print "
\n";
print "
\n";
print _("Here you specify the start and end times of the \n");
print _("block allocation. You might specify more than \n");
print _("one start/end combination if you had multiple \n");
print _("sections that met on the same day.\n");
print "
\n";
print "
\n";
print _("Specify individual dates and times during \n");
print _("which the block allocation will occur.\n");
print "
\n";
print "
\n";
print _("Enter any additional information about this block allocation. \n");
print _("< and > are not allowed. \n");
print _("If you selected \"(group not listed)\" as the User group, make sure \n");
print _("to clearly describe the requirements of a new user group that \n");
print _("will be created for this block allocation.\n");
print "
\n";
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn AJblockAllocationSubmit()
///
/// \brief ajax function to process the form displayed by blockAllocationForm
///
////////////////////////////////////////////////////////////////////////////////
function AJblockAllocationSubmit() {
global $user;
$data = processBlockAllocationInput();
if($data['err'])
return;
$method = getContinuationVar('method');
if($method == 'new') {
$managementnodes = getManagementNodes('future');
if(empty($managementnodes)) {
print "alert('Error encountered while trying to create block allocation:\\n";
print "no active management nodes were found. Please try\\n";
print "creating the block allocation at a later time.');";
$data = array('extragroups' => getContinuationVar('extragroups'),
'method' => $method);
if($method == 'edit')
$data['blockid'] = getContinuationVar('blockid');
$cont = addContinuationsEntry('AJblockAllocationSubmit', $data, SECINWEEK, 1, 0);
print "dojo.byId('submitcont').value = '$cont';";
return;
}
$mnid = array_rand($managementnodes);
$escname = mysql_real_escape_string($data['name']);
$query = "INSERT INTO blockRequest "
. "(name, "
. "imageid, "
. "numMachines, "
. "groupid, "
. "repeating, "
. "ownerid, "
. "managementnodeid, "
. "expireTime, "
. "status) "
. "VALUES "
. "('$escname', "
. "{$data['imageid']}, "
. "{$data['seats']}, "
. "{$data['groupid']}, "
. "'{$data['type']}', "
. "{$data['ownerid']}, "
. "$mnid, "
. "'{$data['expiretime']}', "
. "'accepted')";
doQuery($query, 101);
$blockreqid = dbLastInsertID();
}
elseif($method == 'edit') {
$blockreqid = getContinuationVar('blockid');
# FIXME need to handle creation of a block time that we're currently in the
# middle of if there wasn't already one we're in the middle of
# get blockTime entry for this allocation if we're in the middle of one
$checkCurBlockTime = 0;
$query = "SELECT id, "
. "start, "
. "end "
. "FROM blockTimes "
. "WHERE start <= NOW() AND "
. "end > NOW() AND "
. "blockRequestid = $blockreqid";
$qh = doQuery($query, 101);
if($row = mysql_fetch_assoc($qh)) {
$checkCurBlockTime = 1;
$curBlockTime = $row;
}
# delete entries from blockTimes that start later than now
$query = "DELETE FROM blockTimes "
. "WHERE blockRequestid = $blockreqid AND "
. "start > NOW() AND "
. "skip = 0";
doQuery($query, 101);
# delete entries from blockWebDate and blockWebTime
$query = "DELETE FROM blockWebDate WHERE blockRequestid = $blockreqid";
doQuery($query, 101);
$query = "DELETE FROM blockWebTime WHERE blockRequestid = $blockreqid";
doQuery($query, 101);
$escname = mysql_real_escape_string($data['name']);
$query = "UPDATE blockRequest "
. "SET name = '$escname', "
. "imageid = {$data['imageid']}, "
. "numMachines = {$data['seats']}, "
. "groupid = {$data['groupid']}, "
. "ownerid = {$data['ownerid']}, "
. "repeating = '{$data['type']}', "
. "expireTime = '{$data['expiretime']}' "
. "WHERE id = $blockreqid";
doQuery($query, 101);
}
elseif($method == 'request') {
$esccomments = mysql_real_escape_string($data['comments']);
$query = "INSERT INTO blockRequest "
. "(name, "
. "imageid, "
. "numMachines, "
. "groupid, "
. "repeating, "
. "ownerid, "
. "expireTime, "
. "status, "
. "comments) "
. "VALUES "
. "('(" . _("awaiting approval") . ")', "
. "{$data['imageid']}, "
. "{$data['seats']}, "
. "{$data['groupid']}, "
. "'{$data['type']}', "
. "{$user['id']}, "
. "'{$data['expiretime']}', "
. "'requested', "
. "'$esccomments')";
doQuery($query, 101);
$blockreqid = dbLastInsertID();
# send email notifying about a new block allocation request
$imagedata = getImages(0, $data['imageid']);
if($data['groupid'] == 0)
$grpname = "(Unspecified)";
else
$grpname = getUserGroupName($data['groupid']);
if(! empty($data['comments']))
$comments = "Comments:\n{$data['comments']}\n";
else
$comments = '';
$message = "A new block allocation request has been submitted by ";
if(! empty($user['firstname']) && ! empty($user['lastname']) && ! empty($user['email']))
$message .= "{$user['firstname']} {$user['lastname']} ({$user['email']}). ";
elseif(! empty($user['email']))
$message .= "{$user['email']}. ";
else
$message .= "{$user['unityid']}. ";
$message .= "Please visit the following URL to accept or reject it:\n\n"
. BASEURL . SCRIPT . "?mode=blockAllocations\n\n"
. "Image: {$imagedata[$data['imageid']]['prettyname']}\n"
. "Seats: {$data['seats']}\n"
. "User Group: $grpname\n$comments\n\n"
. "This is an automated message sent by VCL.\n"
. "You are receiving this message because you have access "
. "to create and approve block allocations.";
$mailParams = "-f" . ENVELOPESENDER;
$blockNotifyUsers = getBlockNotifyUsers($user['affiliationid']);
mail($blockNotifyUsers, "VCL Block Allocation Request ({$user['unityid']})", $message, '', $mailParams);
}
if($data['type'] == 'weekly') {
$query = "INSERT INTO blockWebDate "
. "(blockRequestid, "
. "start, "
. "end, "
. "days) "
. "VALUES "
. "($blockreqid, "
. "'{$data['startdate']}', "
. "'{$data['enddate']}', "
. "{$data['daymask']})";
doQuery($query, 101);
$today = mktime(0, 0, 0);
if($method == 'edit' && $data['startts'] < $today)
createWeeklyBlockTimes($blockreqid, $today, $data['endts'], $data['daymask'], $data['times']);
elseif($method == 'new' || $method == 'edit')
createWeeklyBlockTimes($blockreqid, $data['startts'], $data['endts'], $data['daymask'], $data['times']);
}
elseif($data['type'] == 'monthly') {
$query = "INSERT INTO blockWebDate "
. "(blockRequestid, "
. "start, "
. "end, "
. "days, "
. "weeknum) "
. "VALUES "
. "($blockreqid, "
. "'{$data['startdate']}', "
. "'{$data['enddate']}', "
. "{$data['day']}, "
. "{$data['weeknum']})";
doQuery($query, 101);
$today = mktime(0, 0, 0);
if($method == 'edit' && $data['startts'] < $today)
createMonthlyBlockTimes($blockreqid, $today, $data['endts'], $data['day'], $data['weeknum'], $data['times']);
elseif($method == 'new' || $method == 'edit')
createMonthlyBlockTimes($blockreqid, $data['startts'], $data['endts'], $data['day'], $data['weeknum'], $data['times']);
}
if($data['type'] == 'weekly' || $data['type'] == 'monthly') {
$vals = array();
$i = 0;
foreach($data['times'] as $time) {
$tmp = explode('|', $time);
$start = explode(':', $tmp[0]);
$startmin = $start[1];
list($starth, $startm) = hour24to12($start[0]);
$end = explode(':', $tmp[1]);
$endmin = $end[1];
list($endh, $endm) = hour24to12($end[0]);
$vals[] = "($blockreqid, "
. "'$starth', "
. "'$startmin', "
. "'$startm', "
. "'$endh', "
. "'$endmin', "
. "'$endm', "
. "$i)";
$i++;
}
$allvals = implode(',', $vals);
$query = "INSERT INTO blockWebTime "
. "(blockRequestid, "
. "starthour, "
. "startminute, "
. "startmeridian, "
. "endhour, "
. "endminute, "
. "endmeridian, "
. "`order`) "
. "VALUES $allvals";
doQuery($query, 101);
}
if($data['type'] == 'list')
createListBlockData($blockreqid, $data['slots'], $method);
if($method == 'edit' && $checkCurBlockTime) {
$query = "SELECT id, "
. "start, "
. "end "
. "FROM blockTimes "
. "WHERE start <= NOW() AND "
. "end > NOW() AND "
. "blockRequestid = $blockreqid AND "
. "id != {$curBlockTime['id']}";
$qh = doQuery($query, 101);
if($row = mysql_fetch_assoc($qh)) {
if($curBlockTime['end'] != $row['end']) {
# update old end time
$query = "UPDATE blockTimes "
. "SET end = '{$row['end']}' "
. "WHERE id = {$curBlockTime['id']}";
doQuery($query, 101);
}
# delete $row entry
doQuery("DELETE FROM blockTimes WHERE id = {$row['id']}", 101);
}
else {
# the blockTime we were in the middle of was not recreated, so
# delete the old one
doQuery("DELETE FROM blockTimes WHERE id = {$curBlockTime['id']}", 101);
}
}
if($method == 'request') {
print "clearHideConfirmForm();";
$txt = "
" . _("Request New Block Allocation") . "
";
$txt .= _("Your request for a Block Allocation has been submitted for ")
. _("approval. ");
if(! empty($user['email'])) {
$txt .= _("You should be notified within a few business days ")
. _("of its acceptance or rejection.");
}
else {
$txt .= _("
Note: You do not have an ")
. _("email address registered with VCL. Therefore, you will ")
. _("not receive automatic notification when this block ")
. _("allocation is accepted or rejected.");
}
print "dojo.byId('content').innerHTML = '$txt';";
print "scroll(0, 0);";
return;
}
print "window.location.href = '" . BASEURL . SCRIPT . "?mode=blockAllocations';";
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn createWeeklyBlockTimes($blockid, $startts, $endts, $daymask, $times)
///
/// \param $blockid - id of block allocation
/// \param $startts - unix timestamp for starting time
/// \param $endts - unix timestamp for ending time
/// \param $daymask - bitmask int of selected days
/// \param $times - array of times in HH:MM|HH:MM (start|end) format
///
/// \brief creates entries in the blockTimes table for a weekly repeating block
/// allocation
///
////////////////////////////////////////////////////////////////////////////////
function createWeeklyBlockTimes($blockid, $startts, $endts, $daymask, $times) {
$vals = array();
$startts += 3600; # This is a simple way to deal with DST; without it. We end
# up starting at midnight. When we go through the day DST
# ends, += SECINDAY only gets us to 11pm instead of the
# next day. Adding an hour to start with starts us at 1am
# and += SECINDAY gets us to midnight the next day.
$endts += 7200; # Conversely, we pass $endts too soon when DST starts; so
# we add 2 hours to it to make sure we don't pass it.
for($day = $startts; $day <= $endts; $day += SECINDAY) {
if(! ((1 << date('w', $day)) & $daymask))
continue;
foreach($times as $time) {
$tmp = explode('|', $time);
$start = date("Y-m-d", $day) . " {$tmp[0]}:00";
$end = date("Y-m-d", $day) . " {$tmp[1]}:00";
$vals[] = "($blockid, "
. "'$start', "
. "'$end')";
}
}
$allvals = implode(',', $vals);
$query = "INSERT INTO blockTimes "
. "(blockRequestid, "
. "start, "
. "end) "
. "VALUES $allvals";
doQuery($query, 101);
deleteBlockSkipDuplicates($blockid);
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn createMonthlyBlockTimes($blockid, $startts, $endts, $dayweek, $weeknum,
/// $times)
///
/// \param $blockid - id of block allocation
/// \param $startts - unix timestamp for starting time
/// \param $endts - unix timestamp for ending time
/// \param $dayweek - day of the week (1 to 7)
/// \param $weeknum - week of the month (1 to 5)
/// \param $times - array of times in HH:MM|HH:MM (start|end) format
///
/// \brief creates entries in the blockTimes table for a monthly repeating block
/// allocation
///
////////////////////////////////////////////////////////////////////////////////
function createMonthlyBlockTimes($blockid, $startts, $endts, $dayweek, $weeknum,
$times) {
$vals = getMonthlyBlockTimes($blockid, $startts, $endts, $dayweek, $weeknum,
$times);
$allvals = implode(',', $vals);
$query = "INSERT INTO blockTimes "
. "(blockRequestid, "
. "start, "
. "end) "
. "VALUES $allvals";
doQuery($query, 101);
deleteBlockSkipDuplicates($blockid);
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn getMonthlyBlockTimes($blockid, $startts, $endts, $dayweek, $weeknum,
/// $times)
///
/// \param $blockid - id of block allocation
/// \param $startts - unix timestamp for starting time
/// \param $endts - unix timestamp for ending time
/// \param $dayweek - day of the week (1 to 7)
/// \param $weeknum - week of the month (1 to 5)
/// \param $times - array of times in HH:MM|HH:MM (start|end) format
///
/// \brief generates query values for creating entries in the blockTimes table
/// for a monthly repeating block allocation
///
////////////////////////////////////////////////////////////////////////////////
function getMonthlyBlockTimes($blockid, $startts, $endts, $dayweek, $weeknum,
$times) {
$vals = array();
$startts += 3600; # This is a simple way to deal with DST; without it. We end
# up starting at midnight. When we go through the day DST
# ends, += SECINDAY only gets us to 11pm instead of the
# next day. Adding an hour to start with starts us at 1am
# and += SECINDAY gets us to midnight the next day.
$endts += 7200; # Conversely, we pass $endts too soon when DST starts; so
# we add 2 hours to it to make sure we don't pass it.
for($day = $startts; $day <= $endts; $day += SECINDAY) {
if((date('w', $day) + 1) != $dayweek)
continue;
$dayofmon = date('j', $day);
if(($weeknum == 1 && ($dayofmon < 8)) ||
($weeknum == 2 && (7 < $dayofmon) && ($dayofmon < 15)) ||
($weeknum == 3 && (14 < $dayofmon) && ($dayofmon < 22)) ||
($weeknum == 4 && (21 < $dayofmon) && ($dayofmon < 29)) ||
($weeknum == 5 && (28 < $dayofmon) && ($dayofmon < 32))) {
$thedate = date("Y-m-d", $day);
foreach($times as $time) {
$tmp = explode('|', $time);
$start = "$thedate {$tmp[0]}:00";
$end = "$thedate {$tmp[1]}:00";
$vals[] = "($blockid, "
. "'$start', "
. "'$end')";
}
}
}
return $vals;
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn createListBlockData($blockid, $slots, $method)
///
/// \param $blockid - id of block allocation
/// \param $slots - array of date/time slots in 'YYYY-MM-DD|HH:MM|HH:MM' format
/// (date|start|end)
/// \param $method - new, edit, or accept
///
/// \brief creates entries in the blockTimes table for a list type block
/// allocation
///
////////////////////////////////////////////////////////////////////////////////
function createListBlockData($blockid, $slots, $method) {
$dvals = array();
$tvals = array();
if($method == 'new' || $method == 'edit')
$btvals = array();
$i = 0;
foreach($slots as $slot) {
$tmp = explode('|', $slot);
$date = $tmp[0];
if($method == 'new' || $method == 'edit' || $method == 'accept') {
$sdatets = strtotime("$date {$tmp[1]}:00");
$sdatedt = unixToDatetime($sdatets);
$edatets = strtotime("$date {$tmp[2]}:00");
$edatedt = unixToDatetime($edatets);
$btvals[] = "($blockid, "
. "'$sdatedt', "
. "'$edatedt')";
}
if($method != 'accept') {
$start = explode(':', $tmp[1]);
$startmin = $start[1];
list($starth, $startm) = hour24to12($start[0]);
$end = explode(':', $tmp[2]);
$endmin = $end[1];
list($endh, $endm) = hour24to12($end[0]);
$dvals[] = "($blockid, "
. "'$date', "
. "'$date', "
. "$i)";
$tvals[] = "($blockid, "
. "'$starth', "
. "'$startmin', "
. "'$startm', "
. "'$endh', "
. "'$endmin', "
. "'$endm', "
. "$i)";
$i++;
}
}
if($method != 'accept') {
$alldvals = implode(',', $dvals);
$query = "INSERT INTO blockWebDate "
. "(blockRequestid, "
. "start, "
. "end, "
. "days) "
. "VALUES $alldvals";
doQuery($query, 101);
$alltvals = implode(',', $tvals);
$query = "INSERT INTO blockWebTime "
. "(blockRequestid, "
. "starthour, "
. "startminute, "
. "startmeridian, "
. "endhour, "
. "endminute, "
. "endmeridian, "
. "`order`) "
. "VALUES $alltvals";
doQuery($query, 101);
}
if($method == 'new' || $method == 'edit' || $method == 'accept') {
$allbtvals = implode(',', $btvals);
$query = "INSERT INTO blockTimes "
. "(blockRequestid, "
. "start, "
. "end) "
. "VALUES $allbtvals";
doQuery($query, 101);
deleteBlockSkipDuplicates($blockid);
}
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn getBlockNotifyUsers($affiliationid)
///
/// \param $affiliationid - an affiliation id
///
/// \return string of comma delimited email addresses
///
/// \brief gets email addresses for all users that should be notified about a
/// block allocation
///
////////////////////////////////////////////////////////////////////////////////
function getBlockNotifyUsers($affiliationid) {
$query = "SELECT DISTINCT(u.email) "
. "FROM user u, "
. "usergroupmembers ugm, "
. "usergroup ug, "
. "usergrouppriv ugp, "
. "usergroupprivtype ugpt "
. "WHERE ((ugpt.name = 'Manage Block Allocations (global)' AND "
. "ugp.userprivtypeid = ugpt.id AND "
. "ugp.usergroupid = ugm.usergroupid AND "
. "ugp.usergroupid = ug.id AND "
. "ugm.userid = u.id) OR "
. "(ugpt.name = 'Manage Block Allocations (affiliation only)' AND "
. "ugp.userprivtypeid = ugpt.id AND "
. "ugp.usergroupid = ugm.usergroupid AND "
. "ugm.userid = u.id AND "
. "ugp.usergroupid = ug.id AND "
. "ug.affiliationid = $affiliationid)) AND "
. "u.email != ''";
$qh = doQuery($query);
$addrs = array();
while($row = mysql_fetch_assoc($qh))
$addrs[] = $row['email'];
return implode(',', $addrs);
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn deleteBlockSkipDuplicates($blockid)
///
/// \param $blockid - id of a block allocation
///
/// \brief deletes any block times without skip set for which there is a
/// matching block time with skip set; deletes any with skip set where there is
/// not a matching time without skip set
///
////////////////////////////////////////////////////////////////////////////////
function deleteBlockSkipDuplicates($blockid) {
$query = "SELECT id, "
. "start, "
. "end, "
. "skip "
. "FROM blockTimes "
. "WHERE blockRequestid = $blockid";
$qh = doQuery($query, 101);
$skips = array();
$noskips = array();
while($row = mysql_fetch_assoc($qh)) {
$key = "{$row['start']}:{$row['end']}";
if($row['skip'])
$skips[$key] = $row['id'];
else
$noskips[$key] = $row['id'];
}
$deleteids = array();
foreach($skips as $key => $id) {
if(array_key_exists($key, $noskips))
$deleteids[] = $noskips[$key];
else
$deleteids[] = $id;
}
if(empty($deleteids))
return;
$inids = implode(',', $deleteids);
$query = "DELETE FROM blockTimes "
. "WHERE id IN ($inids)";
doQuery($query, 101);
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn getCurrentBlockHTML($listonly)
///
/// \param $listonly (optional, default=0) - 0 to return everything, 1 to only
/// return the table of block allocations (i.e. don't include the delete dialog)
///
/// \return HTML to display current block allocations
///
/// \brief generates the HTML to display a list of the current block allocations
/// and a dojo dialog for deleting them
///
////////////////////////////////////////////////////////////////////////////////
function getCurrentBlockHTML($listonly=0) {
global $user, $days;
$groupids = implode(',', array_keys($user['groups']));
$query = "SELECT b.id, "
. "b.name AS blockname, "
. "b.ownerid, "
. "CONCAT(u.unityid, '@', ua.name) AS owner, "
. "b.imageid, "
. "i.prettyname AS image, "
. "b.numMachines AS machinecnt, "
. "b.groupid as usergroupid, "
. "CONCAT(g.name, '@', a.name) AS `group`, "
. "b.repeating AS available "
. "FROM image i, "
. "blockRequest b "
. "LEFT JOIN usergroup g ON (b.groupid = g.id) "
. "LEFT JOIN affiliation a ON (g.affiliationid = a.id) "
. "LEFT JOIN user u ON (b.ownerid = u.id) "
. "LEFT JOIN affiliation ua ON (u.affiliationid = ua.id) "
. "WHERE b.imageid = i.id AND ";
if(! checkUserHasPerm('Manage Block Allocations (global)') &&
checkUserHasPerm('Manage Block Allocations (affiliation only)'))
$query .= "u.affiliationid = {$user['affiliationid']} AND ";
$query .= "b.status = 'accepted' "
. "ORDER BY b.name";
$allblockids = array();
$qh = doQuery($query, 101);
while($row = mysql_fetch_assoc($qh)) {
if($row['group'] == '') {
$query3 = "SELECT name FROM usergroup WHERE id = {$row['usergroupid']}";
$qh3 = doQuery($query3, 101);
if($row3 = mysql_fetch_assoc($qh3))
$row['group'] = $row3['name'];
}
$allblockids[] = $row['id'];
$blocks[$row['id']] = $row;
$query2 = "SELECT DATE_FORMAT(start, '%c/%e/%y %l:%i %p') AS start1, "
. "UNIX_TIMESTAMP(start) AS unixstart, "
. "UNIX_TIMESTAMP(end) AS unixend "
. "FROM blockTimes "
. "WHERE blockRequestid = {$row['id']} AND "
. "end > NOW() AND "
. "skip = 0 "
. "ORDER BY start "
. "LIMIT 1";
$qh2 = doQuery($query2, 101);
if($row2 = mysql_fetch_assoc($qh2)) {
$blocks[$row['id']]['nextstart'] = $row2['start1'];
if(time() > ($row2['unixstart'] - 1800) &&
time() < $row2['unixend'])
$blocks[$row['id']]['nextstartactive'] = 1;
else
$blocks[$row['id']]['nextstartactive'] = 0;
}
else {
$blocks[$row['id']]['nextstart'] = "none found";
$blocks[$row['id']]['nextstartactive'] = 0;
}
}
if(empty($blocks)) {
return "There are currently no block allocations. \n";
}
foreach($blocks as $id => $request) {
if($request['available'] == 'weekly') {
$query = "SELECT DATE_FORMAT(start, '%m/%d/%Y') AS swdate, "
. "DATE_FORMAT(end, '%m/%d/%Y')AS ewdate, "
. "days "
. "FROM blockWebDate "
. "WHERE blockRequestid = $id";
$qh = doQuery($query, 101);
if(! $row = mysql_fetch_assoc($qh))
abort(101);
$blocks[$id] = array_merge($request, $row);
$wdays = array();
for($i = 0; $i < 7; $i++) {
if($row['days'] & (1 << $i))
array_push($wdays, $days[$i]);
}
unset($blocks[$id]['days']);
$blocks[$id]['wdays'] = $wdays;
$query = "SELECT starthour, "
. "startminute, "
. "startmeridian, "
. "endhour, "
. "endminute, "
. "endmeridian, "
. "`order` "
. "FROM blockWebTime "
. "WHERE blockRequestid = {$request['id']} "
. "ORDER BY startmeridian, starthour, startminute";
$qh = doQuery($query, 101);
while($row = mysql_fetch_assoc($qh)) {
$blocks[$id]['swhour'][$row['order']] = $row['starthour'];
$blocks[$id]['swminute'][$row['order']] = $row['startminute'];
$blocks[$id]['swmeridian'][$row['order']] = $row['startmeridian'];
$blocks[$id]['ewhour'][$row['order']] = $row['endhour'];
$blocks[$id]['ewminute'][$row['order']] = $row['endminute'];
$blocks[$id]['ewmeridian'][$row['order']] = $row['endmeridian'];
}
}
elseif($request['available'] == 'monthly') {
$query = "SELECT DATE_FORMAT(start, '%m/%d/%Y') AS smdate, "
. "DATE_FORMAT(end, '%m/%d/%Y')AS emdate, "
. "days AS day, "
. "weeknum "
. "FROM blockWebDate "
. "WHERE blockRequestid = $id";
$qh = doQuery($query, 101);
if(! $row = mysql_fetch_assoc($qh))
abort(101);
$blocks[$id] = array_merge($request, $row);
$query = "SELECT starthour, "
. "startminute, "
. "startmeridian, "
. "endhour, "
. "endminute, "
. "endmeridian, "
. "`order` "
. "FROM blockWebTime "
. "WHERE blockRequestid = {$request['id']} "
. "ORDER BY startmeridian, starthour, startminute";
$qh = doQuery($query, 101);
while($row = mysql_fetch_assoc($qh)) {
$blocks[$id]['smhour'][$row['order']] = $row['starthour'];
$blocks[$id]['smminute'][$row['order']] = $row['startminute'];
$blocks[$id]['smmeridian'][$row['order']] = $row['startmeridian'];
$blocks[$id]['emhour'][$row['order']] = $row['endhour'];
$blocks[$id]['emminute'][$row['order']] = $row['endminute'];
$blocks[$id]['emmeridian'][$row['order']] = $row['endmeridian'];
}
}
elseif($request['available'] == 'list') {
$query = "SELECT DATE_FORMAT(start, '%m/%d/%Y') AS date, "
. "days AS `order` "
. "FROM blockWebDate "
. "WHERE blockRequestid = $id "
. "ORDER BY start";
$qh = doQuery($query, 101);
while($row = mysql_fetch_assoc($qh)) {
if($row['date'] == '00/00/00')
$blocks[$id]['date'][$row['order']] = '';
else
$blocks[$id]['date'][$row['order']] = $row['date'];
}
$query = "SELECT starthour, "
. "startminute, "
. "startmeridian, "
. "endhour, "
. "endminute, "
. "endmeridian, "
. "`order` "
. "FROM blockWebTime "
. "WHERE blockRequestid = {$request['id']}";
$qh = doQuery($query, 101);
while($row = mysql_fetch_assoc($qh)) {
$blocks[$id]['slhour'][$row['order']] = $row['starthour'];
$blocks[$id]['slminute'][$row['order']] = $row['startminute'];
$blocks[$id]['slmeridian'][$row['order']] = $row['startmeridian'];
$blocks[$id]['elhour'][$row['order']] = $row['endhour'];
$blocks[$id]['elminute'][$row['order']] = $row['endminute'];
$blocks[$id]['elmeridian'][$row['order']] = $row['endmeridian'];
}
}
}
$rt = '';
$rt .= "
\n";
$rt .= "The following text will be emailed to : \n";
$rt .= "\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "Note: The requesting user does not have an email address registered \n";
$rt .= "with VCL. Therefore, the user cannot be notified automatically.\n";
$rt .= "
\n";
$rt .= "Please review the following information, add a reason for rejecting \n";
$rt .= "the block allocation, and click Reject Block Allocation.
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
Environment:
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
User Group:
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
Seats:
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
Repeating:
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "The following text will be emailed to : \n";
$rt .= "
\n";
$rt .= "
\n";
$rt .= "The requesting user does not have an email address registered with VCL. Therefore, \n";
$rt .= "the user cannot be notified automatically. However, for archival purposes, fill in a \n";
$rt .= "reason for rejecting the request:\n";
$rt .= "