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.

\n"; print "\n"; print getUserCurrentBlockHTML(); } else { print "

Manage Block Allocations

\n"; print "
\n"; print getCurrentBlockHTML(); print "
\n"; print "\n"; print "

Block Allocation Requests

\n"; print "
\n"; print getPendingBlockHTML(); print "
\n"; } $blockids = getBlockAllocationIDs($user); if(! count($blockids)) return; $inids = implode(',', $blockids); $query = "SELECT id, " . "name " . "FROM blockRequest " . "WHERE id in ($inids) AND " . "status = 'accepted'"; $qh = doQuery($query, 101); while($row = mysql_fetch_assoc($qh)) $blocks[$row['id']] = $row['name']; print "
\n"; print "

Your Active Block Allocations

\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 "

New Block Allocation

\n"; } elseif($mode == 'editBlockAllocation') { print "

Edit Block Allocation

\n"; } elseif($mode == 'requestBlockAllocation') { print "

Request New Block Allocation

\n"; print "Complete the following form to request a new block allocation. Your request
\n"; print "will need to be approved by a VCL admin before it is created.

\n"; } $resources = getUserResources(array("imageAdmin", "imageCheckOut")); $resources["image"] = removeNoCheckout($resources["image"]); print "\n"; if($mode != 'requestBlockAllocation') { 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"; if($mode != 'requestBlockAllocation') { if(! empty($data['admingroupid']) && ! array_key_exists($data['admingroupid'], $groups)) { $groups[$data['admingroupid']] = array('name' => getUserGroupName($data['admingroupid'], 1)); $extragroups[$data['admingroupid']] = array('name' => getUserGroupName($data['admingroupid'], 1)); uasort($groups, "sortKeepIndex"); } print " \n"; print " \n"; print " \n"; print " \n"; } print " \n"; print " \n"; print " \n"; print " \n"; print "
Name:\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 "
Owner:\n"; $initval = $data['owner']; if(empty($initval)) $initval = "{$user['unityid']}@{$user['affiliation']}"; print " \n"; print "
Environment:\n"; if(USEFILTERINGSELECT && count($resources['image']) < FILTERINGSELECTTHRESHOLD) { print " "; foreach($resources['image'] as $id => $name) { if($id == $data['imageid']) print " \n"; else print " \n"; } print " \n"; print "
User group:\n"; $groups = getUserGroups(0, $user['affiliationid']); if(USEFILTERINGSELECT && count($groups) < FILTERINGSELECTTHRESHOLD) { print " "; $extragroups = array(); if($mode == 'requestBlockAllocation') print " \n"; if(! empty($data['usergroupid']) && ! array_key_exists($data['usergroupid'], $groups)) { $groups[$data['usergroupid']] = array('name' => getUserGroupName($data['usergroupid'], 1)); $extragroups[$data['usergroupid']] = array('name' => getUserGroupName($data['usergroupid'], 1)); uasort($groups, "sortKeepIndex"); } foreach($groups as $id => $group) { if($group['name'] == ' None@') continue; if($id == $data['usergroupid']) print " \n"; else print " \n"; } print " \n"; print " \n"; print "
Managing User Group\n"; if(USEFILTERINGSELECT && count($groups) < FILTERINGSELECTTHRESHOLD) { print " \n"; print " \n"; foreach($groups as $id => $group) { if($group['name'] == ' None@') continue; if($id == $data['admingroupid']) print " \n"; else print " \n"; } print " \n"; print " \n"; print "
Number of seats:\n"; print " \n"; print " \n"; print "
\n"; print "Specify dates/times by:\n"; print "
\n"; print "\n"; print "
\n"; print "\n"; print "
\n"; print "\n"; print "

\n"; print "
\n"; print "
\n"; # repeating weekly print "
\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
First Date of Usage:\n"; print " \n"; print " \n"; print "
Last Date of Usage:\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 "
Days Times
\n"; foreach($days as $day) { print " \n"; print "
\n"; } print "
\n"; print "Start:
\n"; print "End:
\n"; print "\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
StartEndRemove
\n"; print "
\n"; print "
\n"; # repeating weekly # repeating monthly print "
\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
First Date of Usage:\n"; print " \n"; print " \n"; print "
Last Date of Usage:\n"; print " \n"; print " \n"; print "
\n"; $weeknumArr = array(1 => "1st", 2 => "2nd", 3 => "3rd", 4 => "4th", 5 => "5th"); $dayArr = array(1 => "Sunday", 2 => "Monday", 3 => "Tuesday", 4 => "Wednesday", 5 => "Thursday", 6 => "Friday", 7 => "Saturday"); print "Repeat on the "; printSelectInput('weeknum', $weeknumArr, $data['mnweeknumid'], 0, 0, 'mnweeknum'); printSelectInput('day', $dayArr, $data['mndayid'], 0, 0, 'mnday'); print " of every month

\n"; print "Start:
\n"; print "End:
\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
StartEndRemove
\n"; print "
\n"; # repeating monthly # list of times print "
\n"; print "Date:
\n"; print "Start:\n"; print "End:\n"; print "\n"; print "\n"; print "
\n"; print "
\n"; # grid wrapper print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
DateStartEndRemove
\n"; print "
\n"; # grid wrapper print "
\n"; # list of times print "
\n"; # tabcontainer print "

\n"; if($mode == 'requestBlockAllocation') { print "Additional comments:\n"; print "
\n"; print "

\n"; } print "\n"; $cont = addContinuationsEntry('AJvalidateUserid'); print "\n"; print "
\n"; print "

Confirm Block Allocation

\n"; print "Please confirm the following values and then
click $btntxt

\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 " \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 " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
Environment:
User Group:
Seats:
Repeating:
\n"; print "Your additional comments will be submitted.

\n"; $data = array('extragroups' => $extragroups); if($mode == 'newBlockAllocation') $data['method'] = 'new'; elseif($mode == 'editBlockAllocation') { $data['method'] = 'edit'; $data['blockid'] = $blockid; } elseif($mode == 'requestBlockAllocation') $data['method'] = 'request'; $cont = addContinuationsEntry('AJblockAllocationSubmit', $data, SECINWEEK, 1, 0); print "\n"; print "\n"; print "\n"; print "
\n"; # confirm dialog # tooltips print << This is the number of environments that
will be loaded for the Block Allocation.
User in this user group will be able to make reservations
for the computers set aside for this block allocation.
If you do not see an applicable user group listed, please
select "(group not listed)" and describe the group you need
in the Additional Comments section at the bottom of
the page. If this is for a class, make sure to list the course
and section number.
Users in this user group can modify this
block allocation. Select None to keep
anyone else from being able to modify it.
For repeating block allocations, there are three ways you can enter the dates and times:
This is the first date the block allocation will be used.
This is the last date the block allocation will be used.
Select the checkbox for each of the days you
would like the block allocation to occur. For
example, check Monday, Wednesday, and Friday
for a class that meets on those days.
Here you specify the start and end times of the
block allocation. The times will occur on each
of the selected days. You might specify more than
one start/end combination if you had multiple
sections that met on the same day.
This is the first date the block allocation will be used.
This is the last date the block allocation will be used.
Here you specify the start and end times of the
block allocation. You might specify more than
one start/end combination if you had multiple
sections that met on the same day.
Specify individual dates and times during
which the block allocation will occur.
Enter any additional information about this block allocation.
< and > are not allowed.
If you selected "(group not listed)" as the User group, make sure
to clearly describe the requirements of a new user group that
will be created for this block allocation.
END; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJblockAllocationSubmit() /// /// \brief ajax function to process the form displayed by blockAllocationForm /// //////////////////////////////////////////////////////////////////////////////// function AJblockAllocationSubmit() { global $user, $blockNotifyUsers; $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, " . "admingroupid, " . "managementnodeid, " . "expireTime, " . "status) " . "VALUES " . "('$escname', " . "{$data['imageid']}, " . "{$data['seats']}, " . "{$data['groupid']}, " . "'{$data['type']}', " . "{$data['ownerid']}, " . "{$data['admingroupid']}, " . "$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']}, " . "admingroupid = {$data['admingroupid']}, " . "repeating = '{$data['type']}', " . "expireTime = '{$data['expiretime']}' " . "WHERE id = $blockreqid"; doQuery($query, 101); } elseif($method == 'request') { # send email notifying about a new block allocation request $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" . "(This is an automated message sent by VCL.)\n"; $mailParams = "-f" . ENVELOPESENDER; mail($blockNotifyUsers, "VCL Block Allocation Request ({$user['unityid']})", $message, '', $mailParams); $esccomments = mysql_real_escape_string($data['comments']); $query = "INSERT INTO blockRequest " . "(name, " . "imageid, " . "numMachines, " . "groupid, " . "repeating, " . "ownerid, " . "admingroupid, " . "expireTime, " . "status, " . "comments) " . "VALUES " . "('(awaiting approval)', " . "{$data['imageid']}, " . "{$data['seats']}, " . "{$data['groupid']}, " . "'{$data['type']}', " . "{$user['id']}, " . "0, " . "'{$data['expiretime']}', " . "'requested', " . "'$esccomments')"; doQuery($query, 101); $blockreqid = dbLastInsertID(); } 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, $day, $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 = 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')"; } } } $allvals = implode(',', $vals); $query = "INSERT INTO blockTimes " . "(blockRequestid, " . "start, " . "end) " . "VALUES $allvals"; doQuery($query, 101); deleteBlockSkipDuplicates($blockid); } //////////////////////////////////////////////////////////////////////////////// /// /// \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 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; $groups = getUserEditGroups($user['id']); $groupids = implode(',', array_keys($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.admingroupid as admingroupid, " . "CONCAT(ga.name, '@', aa.name) AS `admingroup`, " . "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 usergroup ga ON (b.admingroupid = ga.id) " . "LEFT JOIN affiliation aa ON (ga.affiliationid = aa.id) " . "LEFT JOIN user u ON (b.ownerid = u.id) " . "LEFT JOIN affiliation ua ON (u.affiliationid = ua.id) " . "WHERE (b.ownerid = {$user['id']} "; if(! empty($groupids)) $query .= "OR b.admingroupid IN ($groupids) "; $query .= ") AND b.imageid = i.id AND " . "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() " . "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 .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; foreach($blocks as $block) { $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; if(empty($block['admingroup'])) $rt .= " \n"; else $rt .= " \n"; $rt .= " \n"; if($block['nextstartactive']) { $cont = addContinuationsEntry('viewBlockStatus', array('id' => $block['id'])); $rt .= " \n"; } else $rt .= " \n"; $rt .= " \n"; } $rt .= "
NameEnvironmentReserved
Machines
Reserved
For
Manageable
By
RepeatingNext Start Time
\n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " {$block['blockname']}{$block['image']}{$block['machinecnt']}{$block['group']}None (owner only){$block['admingroup']}{$block['available']}"; $rt .= "{$block['nextstart']}{$block['nextstart']}
\n"; if($listonly) return $rt; $rt .= "
\n"; $rt .= "

Confirm Delete Block Allocation

\n"; $rt .= "Please confirm the following values and then
click Delete Block Allocation

\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 .= " \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 .= "
Name:
Owner:
Environment:
User Group:
Managing User Group:
Seats:
Repeating:
\n"; $rt .= "\n"; $rt .= "\n"; $rt .= "\n"; $rt .= "
\n"; # confirm dialog $rt .= "
\n"; $rt .= "

Block Allocation Times

\n"; $rt .= "\n"; $rt .= "\n"; $rt .= "\n"; $rt .= "\n"; $rt .= "\n"; $rt .= "\n"; $rt .= "\n"; $rt .= "\n"; $rt .= "\n"; $rt .= "\n"; $rt .= "
DateStartEndSkip
\n"; $rt .= "
\n"; $rt .= "\n"; $rt .= "
\n"; $rt .= "\n"; $rt .= "
\n"; # times dialog return $rt; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn getUserCurrentBlockHTML($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 getUserCurrentBlockHTML($listonly=0) { global $user, $days; $query = "SELECT b.id, " . "b.name AS blockname, " . "b.ownerid, " . "CONCAT(u.unityid, '@', ua.name) AS owner, " . "i.prettyname AS image, " . "b.numMachines AS machinecnt, " . "CONCAT(g.name, '@', a.name) AS `group`, " . "b.repeating AS available, " . "b.status " . "FROM image i, " . "usergroup g, " . "affiliation a, " . "blockRequest b " . "LEFT JOIN user u ON (b.ownerid = u.id) " . "LEFT JOIN affiliation ua ON (u.affiliationid = ua.id) " . "WHERE b.ownerid = {$user['id']} AND " . "b.imageid = i.id AND " . "b.status IN ('accepted', 'requested') AND " . "b.groupid = g.id AND " . "g.affiliationid = a.id " . "ORDER BY b.name"; $qh = doQuery($query, 101); $blocks = array(); while($row = mysql_fetch_assoc($qh)) $blocks[$row['id']] = $row; if(empty($blocks)) return; 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 .= "

Manage Block Allocations

\n"; $rt .= "
\n"; $rt .= "\n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; foreach($blocks as $block) { $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; } $rt .= "
NameEnvironmentReserved
Machines
Reserved
For
Repeating
\n"; $rt .= " \n"; $rt .= " \n"; if($block['status'] == 'accepted') { $rt .= " \n"; } $rt .= " {$block['blockname']}{$block['image']}{$block['machinecnt']}{$block['group']}{$block['available']}
\n"; $rt .= "
\n"; if($listonly) return $rt; $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 .= " \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 .= "
Name:
Owner:
Environment:
User Group:
Seats:
Repeating:
\n"; $rt .= "
\n"; $rt .= "\n"; $rt .= "
\n"; $rt .= "
\n"; # confirm dialog $rt .= "
\n"; $rt .= "

Block Allocation Times

\n"; $rt .= "\n"; $rt .= "\n"; $rt .= "\n"; $rt .= "\n"; $rt .= "\n"; $rt .= "\n"; $rt .= "\n"; $rt .= "\n"; $rt .= "\n"; $rt .= "\n"; $rt .= "
DateStartEndSkip
\n"; $rt .= "
\n"; $rt .= "\n"; $rt .= "
\n"; $rt .= "\n"; $rt .= "
\n"; # times dialog return $rt; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn getPendingBlockHTML($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 dojo dialogs) /// /// \return HTML to display requested block allocations /// /// \brief generates the HTML to display a list of the requested block /// allocations and a dojo dialogs for accepting/rejecting them /// //////////////////////////////////////////////////////////////////////////////// function getPendingBlockHTML($listonly=0) { global $days, $user; $query = "SELECT b.id, " . "b.imageid, " . "i.prettyname AS image, " . "b.numMachines, " . "b.groupid AS usergroupid, " . "CONCAT(ug.name, '@', a.name) AS `group`, " . "b.repeating, " . "b.ownerid, " . "u.unityid, " . "u.firstname, " . "u.lastname, " . "u.email, " . "DATE_FORMAT(b.expireTime, '%m/%d/%y') AS lastdate, " . "b.comments " . "FROM image i, " . "user u, " . "blockRequest b " . "LEFT JOIN usergroup ug ON (b.groupid = ug.id) " . "LEFT JOIN affiliation a ON (ug.affiliationid = a.id) " . "WHERE status = 'requested' AND " . "b.imageid = i.id AND " . "b.ownerid = u.id"; $qh = doQuery($query, 101); $h = "\n"; $h .= " \n"; $h .= " \n"; $h .= " \n"; $h .= " \n"; $h .= " \n"; $h .= " \n"; $h .= " \n"; $h .= " \n"; $h .= " \n"; $h .= " \n"; $d = ''; $groups = getUserGroups(0, $user['affiliationid']); while($row = mysql_fetch_assoc($qh)) { if($row['repeating'] == 'weekly') { $query2 = "SELECT DATE_FORMAT(start, '%m/%d/%y') AS swdate, " . "DATE_FORMAT(end, '%m/%d/%y')AS ewdate, " . "UNIX_TIMESTAMP(start) AS startts, " . "UNIX_TIMESTAMP(end) AS endts, " . "days " . "FROM blockWebDate " . "WHERE blockRequestid = {$row['id']}"; $qh2 = doQuery($query2, 101); if(! $row2 = mysql_fetch_assoc($qh2)) abort(101); $row = array_merge($row, $row2); $wdays = array(); for($i = 0; $i < 7; $i++) { if($row['days'] & (1 << $i)) array_push($wdays, $days[$i]); } $row['wdays'] = $wdays; $query2 = "SELECT starthour, " . "startminute, " . "startmeridian, " . "endhour, " . "endminute, " . "endmeridian, " . "`order` " . "FROM blockWebTime " . "WHERE blockRequestid = {$row['id']} " . "ORDER BY startmeridian, starthour, startminute"; $qh2 = doQuery($query2, 101); $row['times'] = array(); while($row2 = mysql_fetch_assoc($qh2)) { $row['swhour'][$row2['order']] = $row2['starthour']; $row['swminute'][$row2['order']] = $row2['startminute']; $row['swmeridian'][$row2['order']] = $row2['startmeridian']; $row['ewhour'][$row2['order']] = $row2['endhour']; $row['ewminute'][$row2['order']] = $row2['endminute']; $row['ewmeridian'][$row2['order']] = $row2['endmeridian']; $row['times'][] = sprintf("%02d:%02d|%02d:%02d", hour12to24($row2['starthour'], $row2['startmeridian']), $row2['startminute'], hour12to24($row2['endhour'], $row2['endmeridian']), $row2['endminute']); } } elseif($row['repeating'] == 'monthly') { $query2 = "SELECT DATE_FORMAT(start, '%m/%d/%y') AS smdate, " . "DATE_FORMAT(end, '%m/%d/%y')AS emdate, " . "UNIX_TIMESTAMP(start) AS startts, " . "UNIX_TIMESTAMP(end) AS endts, " . "days AS day, " . "weeknum " . "FROM blockWebDate " . "WHERE blockRequestid = {$row['id']}"; $qh2 = doQuery($query2, 101); if(! $row2 = mysql_fetch_assoc($qh2)) abort(101); $row = array_merge($row, $row2); $query2 = "SELECT starthour, " . "startminute, " . "startmeridian, " . "endhour, " . "endminute, " . "endmeridian, " . "`order` " . "FROM blockWebTime " . "WHERE blockRequestid = {$row['id']} " . "ORDER BY startmeridian, starthour, startminute"; $qh2 = doQuery($query2, 101); $row['times'] = array(); while($row2 = mysql_fetch_assoc($qh2)) { $row['smhour'][$row2['order']] = $row2['starthour']; $row['smminute'][$row2['order']] = $row2['startminute']; $row['smmeridian'][$row2['order']] = $row2['startmeridian']; $row['emhour'][$row2['order']] = $row2['endhour']; $row['emminute'][$row2['order']] = $row2['endminute']; $row['emmeridian'][$row2['order']] = $row2['endmeridian']; $row['times'][] = sprintf("%02d:%02d|%02d:%02d", hour12to24($row2['starthour'], $row2['startmeridian']), $row2['startminute'], hour12to24($row2['endhour'], $row2['endmeridian']), $row2['endminute']); } } elseif($row['repeating'] == 'list') { $slotdates = array(); $query2 = "SELECT DATE_FORMAT(start, '%m/%d/%y') AS date, " . "start AS slotdate, " . "days AS `order` " . "FROM blockWebDate " . "WHERE blockRequestid = {$row['id']} " . "ORDER BY start"; $qh2 = doQuery($query2, 101); while($row2 = mysql_fetch_assoc($qh2)) { if($row2['date'] == '00/00/00') $row['date'][$row2['order']] = ''; else $row['date'][$row2['order']] = $row2['date']; $slotdates[$row2['order']] = $row2['slotdate']; } $query2 = "SELECT starthour, " . "startminute, " . "startmeridian, " . "endhour, " . "endminute, " . "endmeridian, " . "`order` " . "FROM blockWebTime " . "WHERE blockRequestid = {$row['id']}"; $qh2 = doQuery($query2, 101); $row['slots'] = array(); # yyyy-mm-dd|hh:mm|hh:mm while($row2 = mysql_fetch_assoc($qh2)) { $row['slhour'][$row2['order']] = $row2['starthour']; $row['slminute'][$row2['order']] = $row2['startminute']; $row['slmeridian'][$row2['order']] = $row2['startmeridian']; $row['elhour'][$row2['order']] = $row2['endhour']; $row['elminute'][$row2['order']] = $row2['endminute']; $row['elmeridian'][$row2['order']] = $row2['endmeridian']; $row['slots'][] = sprintf("%s|%02d:%02d|%02d:%02d", $slotdates[$row2['order']], hour12to24($row2['starthour'], $row2['startmeridian']), $row2['startminute'], hour12to24($row2['endhour'], $row2['endmeridian']), $row2['endminute']); } } $d .= " \n"; $d .= " \n"; $d .= " \n"; $d .= "\n"; if(! empty($row['firstname']) && ! empty($row['lastname'])) $d .= "\n"; else $d .= "\n"; $d .= "\n"; $d .= "\n"; $d .= "\n"; $d .= "\n"; $d .= " \n"; } if(empty($d)) return 'There are currently no pending block allocation requests.'; $rt = $h . $d . "
EnvironmentRequested byReserved MachinesRepeatingStart DateEnd Date
\n"; $d .= " \n"; $d .= " \n"; $d .= " \n"; $d .= " {$row['image']}{$row['firstname']} {$row['lastname']} ({$row['unityid']}){$row['unityid']}{$row['numMachines']}{$row['repeating']}{$row2['start']}{$row['lastdate']}
\n"; if($listonly) return $rt; $rt .= "
\n"; $rt .= "

Accept Block Allocation

\n"; $rt .= "Please review the following information, fill in the additional fields,
\n"; $rt .= "and click Accept Block Allocation.

\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 .= " \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 .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= "
Environment:
Seats:
Repeating:
User Group:

User Group:\n"; if(USEFILTERINGSELECT && count($groups) < FILTERINGSELECTTHRESHOLD) { $rt .= " \n"; foreach($groups as $id => $group) { if($group['name'] == ' None@') continue; $rt .= " \n"; } $rt .= " \n"; $rt .= "
Name:\n"; $rt .= " \n"; $rt .= "
Managing User Group:\n"; if(USEFILTERINGSELECT && count($groups) < FILTERINGSELECTTHRESHOLD) { $rt .= " \n"; $rt .= " \n"; foreach($groups as $id => $group) { if($group['name'] == ' None@') continue; $rt .= " \n"; } $rt .= " \n"; $rt .= "

\n"; $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 .= "
\n"; $rt .= "\n"; $rt .= "\n"; $rt .= "\n"; $rt .= "
\n"; # accept dialog $rt .= "
\n"; $rt .= "

Reject Block Allocation

\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 .= " \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 .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= "
Environment:
User Group:
Seats:
Repeating:
\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 .= "

\n"; $rt .= "\n"; $rt .= "
\n"; $rt .= "\n"; $rt .= "\n"; $rt .= "\n"; $rt .= "
\n"; # reject dialog return $rt; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJdeleteBlockAllocationConfirm() /// /// \brief ajax function to generate JSON data with information about a block /// allocation to be used when filling in the delete confirmation dialog /// //////////////////////////////////////////////////////////////////////////////// function AJdeleteBlockAllocationConfirm() { global $days; $data = getContinuationVar(); if($data['available'] == 'weekly') { $rt = array('name' => $data['blockname'], 'ownerid' => $data['ownerid'], 'owner' => $data['owner'], 'image' => $data['image'], 'seats' => $data['machinecnt'], 'usergroup' => $data['group'], 'admingroup' => $data['admingroup'], 'repeating' => $data['available'], 'startdate' => $data['swdate'], 'lastdate' => $data['ewdate'], 'days' => $data['wdays']); $rt['times'] = array(); foreach(array_keys($data['swhour']) as $key) { $rt['times'][] = sprintf("%d:%02d %s - %d:%02d %s", $data['swhour'][$key], $data['swminute'][$key], $data['swmeridian'][$key], $data['ewhour'][$key], $data['ewminute'][$key], $data['ewmeridian'][$key]); } } elseif($data['available'] == 'monthly') { $rt = array('name' => $data['blockname'], 'ownerid' => $data['ownerid'], 'owner' => $data['owner'], 'image' => $data['image'], 'seats' => $data['machinecnt'], 'usergroup' => $data['group'], 'admingroup' => $data['admingroup'], 'repeating' => $data['available'], 'startdate' => $data['smdate'], 'lastdate' => $data['emdate']); $weeknumArr = array(1 => "1st", 2 => "2nd", 3 => "3rd", 4 => "4th", 5 => "5th"); $rt['date1'] = "{$weeknumArr[$data['weeknum']]} {$days[($data['day'] - 1)]}"; $rt['times'] = array(); foreach(array_keys($data['smhour']) as $key) { $rt['times'][] = sprintf("%d:%02d %s - %d:%02d %s", $data['smhour'][$key], $data['smminute'][$key], $data['smmeridian'][$key], $data['emhour'][$key], $data['emminute'][$key], $data['emmeridian'][$key]); } } elseif($data['available'] == 'list') { $rt = array('name' => $data['blockname'], 'ownerid' => $data['ownerid'], 'owner' => $data['owner'], 'image' => $data['image'], 'seats' => $data['machinecnt'], 'usergroup' => $data['group'], 'admingroup' => $data['admingroup'], 'repeating' => $data['available']); $slots = array(); foreach($data['date'] as $key => $val) { $slots[] = sprintf("%s %d:%02d %s - %d:%02d %s", $val, $data['slhour'][$key], $data['slminute'][$key], $data['slmeridian'][$key], $data['elhour'][$key], $data['elminute'][$key], $data['elmeridian'][$key]); } $rt['slots'] = $slots; } if($data['admingroupid'] == 0) $rt['admingroup'] = 'None (owner only)'; $cont = addContinuationsEntry('AJdeleteBlockAllocationSubmit', array('blockid' => $data['id']), SECINDAY, 0, 0); $rt['cont'] = $cont; sendJSON($rt); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJdeleteBlockAllocationSubmit() /// /// \brief ajax function to delete a block allocation and send updated list of /// block allocations /// //////////////////////////////////////////////////////////////////////////////// function AJdeleteBlockAllocationSubmit() { $blockid = getContinuationVar('blockid'); $query = "UPDATE blockRequest SET status = 'deleted' WHERE id = $blockid"; doQuery($query, 101); $query = "DELETE FROM blockTimes WHERE blockRequestid = $blockid"; doQuery($query, 101); $html = getCurrentBlockHTML(1); $html = str_replace("\n", '', $html); $html = str_replace("'", "\'", $html); $html = preg_replace("/>\s*<", $html); print "dijit.byId('confirmDialog').hide();"; print setAttribute('blocklist', 'innerHTML', $html); print "AJdojoCreate('blocklist');"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJviewBlockAllocation() /// /// \brief ajax function to generate JSON data with information about a block /// allocation to be used when filling in the delete confirmation dialog /// //////////////////////////////////////////////////////////////////////////////// function AJviewBlockAllocation() { global $days; $data = getContinuationVar(); if($data['available'] == 'weekly') { $rt = array('name' => $data['blockname'], 'ownerid' => $data['ownerid'], 'owner' => $data['owner'], 'image' => $data['image'], 'seats' => $data['machinecnt'], 'usergroup' => $data['group'], 'repeating' => $data['available'], 'startdate' => $data['swdate'], 'lastdate' => $data['ewdate'], 'days' => $data['wdays']); $rt['times'] = array(); foreach(array_keys($data['swhour']) as $key) { $rt['times'][] = sprintf("%d:%02d %s - %d:%02d %s", $data['swhour'][$key], $data['swminute'][$key], $data['swmeridian'][$key], $data['ewhour'][$key], $data['ewminute'][$key], $data['ewmeridian'][$key]); } } elseif($data['available'] == 'monthly') { $rt = array('name' => $data['blockname'], 'ownerid' => $data['ownerid'], 'owner' => $data['owner'], 'image' => $data['image'], 'seats' => $data['machinecnt'], 'usergroup' => $data['group'], 'repeating' => $data['available'], 'startdate' => $data['smdate'], 'lastdate' => $data['emdate']); $weeknumArr = array(1 => "1st", 2 => "2nd", 3 => "3rd", 4 => "4th", 5 => "5th"); $rt['date1'] = "{$weeknumArr[$data['weeknum']]} {$days[($data['day'] - 1)]}"; $rt['times'] = array(); foreach(array_keys($data['smhour']) as $key) { $rt['times'][] = sprintf("%d:%02d %s - %d:%02d %s", $data['smhour'][$key], $data['smminute'][$key], $data['smmeridian'][$key], $data['emhour'][$key], $data['emminute'][$key], $data['emmeridian'][$key]); } } elseif($data['available'] == 'list') { $rt = array('name' => $data['blockname'], 'ownerid' => $data['ownerid'], 'owner' => $data['owner'], 'image' => $data['image'], 'seats' => $data['machinecnt'], 'usergroup' => $data['group'], 'repeating' => $data['available']); $slots = array(); foreach($data['date'] as $key => $val) { $slots[] = sprintf("%s %d:%02d %s - %d:%02d %s", $val, $data['slhour'][$key], $data['slminute'][$key], $data['slmeridian'][$key], $data['elhour'][$key], $data['elminute'][$key], $data['elmeridian'][$key]); } $rt['slots'] = $slots; } sendJSON($rt); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJacceptBlockAllocationConfirm() /// /// \brief ajax function to generate JSON data with information about a block /// allocation to be used when filling in the accept confirmation dialog /// //////////////////////////////////////////////////////////////////////////////// function AJacceptBlockAllocationConfirm() { global $days; $data = getContinuationVar(); if($data['repeating'] == 'weekly') { $rt = array('image' => $data['image'], 'seats' => $data['numMachines'], 'usergroup' => $data['group'], 'repeating' => $data['repeating'], 'startdate' => $data['swdate'], 'lastdate' => $data['ewdate'], 'days' => $data['wdays']); $rt['times'] = array(); foreach(array_keys($data['swhour']) as $key) { $rt['times'][] = sprintf("%d:%02d %s - %d:%02d %s", $data['swhour'][$key], $data['swminute'][$key], $data['swmeridian'][$key], $data['ewhour'][$key], $data['ewminute'][$key], $data['ewmeridian'][$key]); } $rt['email'] = "The VCL Block Allocation you requested for {$data['numMachines']} seats of {$data['image']} repeating on a weekly schedule has been accepted."; } elseif($data['repeating'] == 'monthly') { $rt = array('image' => $data['image'], 'seats' => $data['numMachines'], 'usergroup' => $data['group'], 'repeating' => $data['repeating'], 'startdate' => $data['smdate'], 'lastdate' => $data['emdate']); $weeknumArr = array(1 => "1st", 2 => "2nd", 3 => "3rd", 4 => "4th", 5 => "5th"); $rt['date1'] = "{$weeknumArr[$data['weeknum']]} {$days[($data['day'] - 1)]}"; $rt['times'] = array(); foreach(array_keys($data['smhour']) as $key) { $rt['times'][] = sprintf("%d:%02d %s - %d:%02d %s", $data['smhour'][$key], $data['smminute'][$key], $data['smmeridian'][$key], $data['emhour'][$key], $data['emminute'][$key], $data['emmeridian'][$key]); } $rt['email'] = "The VCL Block Allocation you requested for {$data['numMachines']} seats of {$data['image']} repeating on a monthly schedule has been accepted."; } elseif($data['repeating'] == 'list') { $rt = array('image' => $data['image'], 'seats' => $data['numMachines'], 'usergroup' => $data['group'], 'repeating' => $data['repeating']); $slots = array(); foreach($data['date'] as $key => $val) { $slots[] = sprintf("%s %d:%02d %s - %d:%02d %s", $val, $data['slhour'][$key], $data['slminute'][$key], $data['slmeridian'][$key], $data['elhour'][$key], $data['elminute'][$key], $data['elmeridian'][$key]); } $rt['slots'] = $slots; $rt['email'] = "The VCL Block Allocation you requested for {$data['numMachines']} seats of {$data['image']} during the following time periods has been accepted:\n" . implode("\n", $slots) . "\n"; } $rt['comments'] = preg_replace("/\n/", "
", $data['comments']); if($rt['comments'] == '') $rt['comments'] = '(none)'; $rt['validemail'] = 1; if(! empty($data['firstname']) && ! empty($data['lastname']) && ! empty($data['email'])) $rt['emailuser'] = "{$data['firstname']} {$data['lastname']} ({$data['email']})"; elseif(! empty($data['email'])) $rt['emailuser'] = "{$data['email']}"; else $rt['validemail'] = 0; $cdata = array('blockid' => $data['id']); if(empty($data['group'])) $cdata['setusergroup'] = 1; else $cdata['setusergroup'] = 0; $cdata['validemail'] = $rt['validemail']; $cdata['emailuser'] = $data['email']; $cdata['repeating'] = $data['repeating']; $cdata['comments'] = $data['comments']; if($data['repeating'] == 'weekly') { $cdata['startts'] = $data['startts']; $cdata['endts'] = $data['endts']; $cdata['daymask'] = $data['days']; $cdata['times'] = $data['times']; } elseif($data['repeating'] == 'monthly') { $cdata['startts'] = $data['startts']; $cdata['endts'] = $data['endts']; $cdata['day'] = $data['day']; $cdata['weeknum'] = $data['weeknum']; $cdata['times'] = $data['times']; } elseif($data['repeating'] == 'list') { $cdata['slots'] = $data['slots']; } $cont = addContinuationsEntry('AJacceptBlockAllocationSubmit', $cdata, SECINDAY, 1, 0); $rt['cont'] = $cont; sendJSON($rt); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJacceptBlockAllocationSubmit() /// /// \brief ajax function to accept a block allocation and send updated list of /// current block allocations and pending block allocations /// //////////////////////////////////////////////////////////////////////////////// function AJacceptBlockAllocationSubmit() { global $mysql_link_vcl, $user; $blockid = getContinuationVar('blockid'); $comments = getContinuationVar('comments'); $validemail = getContinuationVar('validemail'); $emailuser = getContinuationVar('emailuser'); $setusergroup = getContinuationVar('setusergroup'); if($setusergroup) $usergroupid = processInputVar('groupid', ARG_NUMERIC); $name = processInputVar('brname', ARG_STRING); $admingroupid = processInputVar('admingroupid', ARG_NUMERIC); $emailtext = processInputVar('emailtext', ARG_STRING); $err = 0; if(! preg_match('/^([-a-zA-Z0-9\. ]){3,80}$/', $name)) { $errmsg = "The name can only contain letters, numbers, spaces, dashes(-),\\nand periods(.) and can be from 3 to 80 characters long"; $err = 1; } if($validemail) { if(get_magic_quotes_gpc()) $emailtext = stripslashes($emailtext); if(! $err && preg_match('/[<>|]/', $emailtext)) { $errmsg = "<>\'s and pipes (|) are not allowed in the email text."; $err = 1; } if(! $err && ! preg_match('/[A-Za-z]{2,}/', $emailtext)) { $errmsg = "Something must be filled in for the email text."; $err = 1; } } $groups = getUserGroups(0, $user['affiliationid']); if(! $err && $admingroupid != 0 && ! array_key_exists($admingroupid, $groups)) { $errmsg = "Invalid managing user group submitted."; $err = 1; } if(! $err && $setusergroup && ! array_key_exists($usergroupid, $groups)) { $errmsg = "Invalid user group submitted."; $err = 1; } $managementnodes = getManagementNodes('future'); if(empty($managementnodes)) { $errmsg = "Error encountered while trying to create block allocation:\\n\\n"; $errmsg .= "No active management nodes were found. Please try\\n"; $errmsg .= "accepting the block allocation at a later time."; $err = 1; } $mnid = array_rand($managementnodes); if(! $err) { # update values for block allocation if($validemail) $esccomments = mysql_real_escape_string("COMMENTS: $comments|EMAIL: $emailtext"); else $esccomments = mysql_real_escape_string("COMMENTS: $comments|USER NOT EMAILED"); $query = "UPDATE blockRequest " . "SET name = '$name', " . "admingroupid = $admingroupid, "; if($setusergroup) $query .= "groupid = $usergroupid, "; $query .= "status = 'accepted', " . "comments = '$esccomments', " . "managementnodeid = '$mnid' " . "WHERE id = $blockid"; doQuery($query, 101); if(! mysql_affected_rows($mysql_link_vcl)) { $errmsg = "Error encountered while updating status of block allocation."; $err = 1; } else { $repeating = getContinuationVar('repeating'); if($repeating == 'weekly') { $startts = getContinuationVar('startts'); $endts = getContinuationVar('endts'); $daymask = getContinuationVar('daymask'); $times = getContinuationVar('times'); createWeeklyBlockTimes($blockid, $startts, $endts, $daymask, $times); } elseif($repeating == 'monthly') { $startts = getContinuationVar('startts'); $endts = getContinuationVar('endts'); $day = getContinuationVar('day'); $weeknum = getContinuationVar('weeknum'); $times = getContinuationVar('times'); createMonthlyBlockTimes($blockid, $startts, $endts, $day, $weeknum, $times); } elseif($repeating == 'list') { $slots = getContinuationVar('slots'); createListBlockData($blockid, $slots, 'accept'); } } } if($err) { print "alert('$errmsg');"; $cdata = getContinuationVar(); $cont = addContinuationsEntry('AJacceptBlockAllocationSubmit', $cdata, SECINDAY, 1, 0); print "dojo.byId('submitacceptcont').value = '$cont';"; print "document.body.style.cursor = 'default';"; return; } # send accept email to requestor $message = $emailtext . "\n\nVCL Admins"; $mailParams = "-f" . ENVELOPESENDER; mail($emailuser, "VCL Block Allocation Accepted", $message, '', $mailParams); print "clearHideConfirmAccept();"; $html = getPendingBlockHTML(1); $html = str_replace("\n", '', $html); $html = str_replace("'", "\'", $html); $html = preg_replace("/>\s*<", $html); print setAttribute('pendinglist', 'innerHTML', $html); print "AJdojoCreate('pendinglist');"; $html = getCurrentBlockHTML(1); $html = str_replace("\n", '', $html); $html = str_replace("'", "\'", $html); $html = preg_replace("/>\s*<", $html); print setAttribute('blocklist', 'innerHTML', $html); print "AJdojoCreate('blocklist');"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJrejectBlockAllocationConfirm() /// /// \brief ajax function to generate JSON data with information about a block /// allocation to be used when filling in the reject confirmation dialog /// //////////////////////////////////////////////////////////////////////////////// function AJrejectBlockAllocationConfirm() { global $days; $data = getContinuationVar(); if($data['repeating'] == 'weekly') { $rt = array('image' => $data['image'], 'seats' => $data['numMachines'], 'usergroup' => $data['group'], 'repeating' => $data['repeating'], 'startdate' => $data['swdate'], 'lastdate' => $data['ewdate'], 'days' => $data['wdays']); $rt['times'] = array(); foreach(array_keys($data['swhour']) as $key) { $rt['times'][] = sprintf("%d:%02d %s - %d:%02d %s", $data['swhour'][$key], $data['swminute'][$key], $data['swmeridian'][$key], $data['ewhour'][$key], $data['ewminute'][$key], $data['ewmeridian'][$key]); } $rt['email'] = "The VCL Block Allocation you requested for {$data['numMachines']} seats of {$data['image']} repeating on a weekly schedule has been rejected. "; } elseif($data['repeating'] == 'monthly') { $rt = array('image' => $data['image'], 'seats' => $data['numMachines'], 'usergroup' => $data['group'], 'repeating' => $data['repeating'], 'startdate' => $data['smdate'], 'lastdate' => $data['emdate']); $weeknumArr = array(1 => "1st", 2 => "2nd", 3 => "3rd", 4 => "4th", 5 => "5th"); $rt['date1'] = "{$weeknumArr[$data['weeknum']]} {$days[($data['day'] - 1)]}"; $rt['times'] = array(); foreach(array_keys($data['smhour']) as $key) { $rt['times'][] = sprintf("%d:%02d %s - %d:%02d %s", $data['smhour'][$key], $data['smminute'][$key], $data['smmeridian'][$key], $data['emhour'][$key], $data['emminute'][$key], $data['emmeridian'][$key]); } $rt['email'] = "The VCL Block Allocation you requested for {$data['numMachines']} seats of {$data['image']} repeating on a monthly schedule has been rejected. "; } elseif($data['repeating'] == 'list') { $rt = array('image' => $data['image'], 'seats' => $data['numMachines'], 'usergroup' => $data['group'], 'repeating' => $data['repeating']); $slots = array(); foreach($data['date'] as $key => $val) { $slots[] = sprintf("%s %d:%02d %s - %d:%02d %s", $val, $data['slhour'][$key], $data['slminute'][$key], $data['slmeridian'][$key], $data['elhour'][$key], $data['elminute'][$key], $data['elmeridian'][$key]); } $rt['slots'] = $slots; $rt['email'] = "The VCL Block Allocation you requested for {$data['numMachines']} seats of {$data['image']} during the following time periods has been rejected.\n" . implode("\n", $slots) . "\n\n"; } $rt['comments'] = preg_replace("/\n/", "
", $data['comments']); if($rt['comments'] == '') $rt['comments'] = '(none)'; $rt['validemail'] = 1; if(! empty($data['firstname']) && ! empty($data['lastname']) && ! empty($data['email'])) $rt['emailuser'] = "{$data['firstname']} {$data['lastname']} ({$data['email']})"; elseif(! empty($data['email'])) $rt['emailuser'] = "{$data['email']}"; else $rt['validemail'] = 0; $cdata = array('blockid' => $data['id']); $cdata['validemail'] = $rt['validemail']; $cdata['emailuser'] = $data['email']; $cdata['email'] = $rt['email']; $cdata['comments'] = $data['comments']; $cont = addContinuationsEntry('AJrejectBlockAllocationSubmit', $cdata, SECINDAY, 1, 0); $rt['cont'] = $cont; sendJSON($rt); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJrejectBlockAllocationSubmit() /// /// \brief ajax function to reject a block allocation and send updated list of /// pending block allocations /// //////////////////////////////////////////////////////////////////////////////// function AJrejectBlockAllocationSubmit() { global $mysql_link_vcl; $blockid = getContinuationVar('blockid'); $comments = getContinuationVar('comments'); $validemail = getContinuationVar('validemail'); $emailuser = getContinuationVar('emailuser'); $email = getContinuationVar('email'); $emailtext = processInputVar('emailtext', ARG_STRING); $err = 0; if($email == $emailtext) { $errmsg = "Please include a reason for rejecting the block allocation in the email."; $err = 1; } if(get_magic_quotes_gpc()) $emailtext = stripslashes($emailtext); if(! $err && preg_match('/[<>|]/', $emailtext)) { if($validemail) $errmsg = "<>\'s and pipes (|) are not allowed in the email text."; else $errmsg = "<>\'s and pipes (|) are not allowed in the reject reason."; $err = 1; } if(! $err && ! preg_match('/[A-Za-z]{2,}/', $emailtext)) { if($validemail) $errmsg = "Something must be filled in for the email text."; else $errmsg = "Something must be filled in for the reject reason."; $err = 1; } if(! $err) { # update values for block allocation if($validemail) $esccomments = mysql_real_escape_string("COMMENTS: $comments|EMAIL: $emailtext"); else $esccomments = mysql_real_escape_string("COMMENTS: $comments|REJECTREASON: $emailtext"); $query = "UPDATE blockRequest " . "SET name = 'rejected', " . "status = 'rejected', " . "comments = '$esccomments' " . "WHERE id = $blockid"; doQuery($query, 101); if(! mysql_affected_rows($mysql_link_vcl)) { $errmsg = "Error encountered while updating status of block allocation."; $err = 1; } } if($err) { print "alert('$errmsg');"; $cdata = getContinuationVar(); $cont = addContinuationsEntry('AJrejectBlockAllocationSubmit', $cdata, SECINDAY, 1, 0); print "dojo.byId('submitrejectcont').value = '$cont';"; print "document.body.style.cursor = 'default';"; return; } # send reject email to requestor $message = $emailtext . "\n\nVCL Admins"; $mailParams = "-f" . ENVELOPESENDER; mail($emailuser, "VCL Block Allocation Rejected", $message, '', $mailParams); print "clearHideConfirmReject();"; $html = getPendingBlockHTML(1); $html = str_replace("\n", '', $html); $html = str_replace("'", "\'", $html); $html = preg_replace("/>\s*<", $html); print setAttribute('pendinglist', 'innerHTML', $html); print "AJdojoCreate('pendinglist');"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJviewBlockAllocationTimes() /// /// \brief gets start/end data about a block time and sends it in json format /// //////////////////////////////////////////////////////////////////////////////// function AJviewBlockAllocationTimes() { $blockid = getContinuationVar('blockid'); $query = "SELECT id, " . "start, " . "end, " . "skip " . "FROM blockTimes " . "WHERE blockRequestid = $blockid AND " . "end > NOW() " . "ORDER BY start"; $qh = doQuery($query, 101); $data = array(); $items = array(); while($row = mysql_fetch_assoc($qh)) $items[] = $row; $cont = addContinuationsEntry('AJtoggleBlockTime', array('blockid' => $blockid)); $data['cont'] = $cont; $data['items'] = $items; sendJSON($data); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJtoggleBlockTime() /// /// \brief toggles the skip flag for a block time /// //////////////////////////////////////////////////////////////////////////////// function AJtoggleBlockTime() { $blockid = getContinuationVar('blockid'); $timeid = processInputVar('blocktimeid', ARG_NUMERIC); $query = "SELECT blockRequestid, " . "end, " . "skip " . "FROM blockTimes " . "WHERE id = $timeid"; $qh = doQuery($query, 101); if(! ($row = mysql_fetch_assoc($qh)) || $row['blockRequestid'] != $blockid) { $data['error'] = 'Invalid block time submitted'; sendJSON($data); return; } if(datetimeToUnix($row['end']) <= time()) { $data['error'] = "The end time for the submitted block allocation time\nhas passed. Therefore, it can no longer be modified."; sendJSON($data); return; } $query = "UPDATE request " . "SET stateid = 1 " . "WHERE id IN " . "(SELECT DISTINCT reloadrequestid " . "FROM blockComputers " . "WHERE blockTimeid = $timeid)"; doQuery($query, 101); $query = "DELETE FROM blockComputers " . "WHERE blockTimeid = $timeid"; doQuery($query, 101); $skip = $row['skip'] ^ 1; $query = "UPDATE blockTimes " . "SET skip = $skip " . "WHERE id = $timeid"; doQuery($query, 101); $data['newval'] = $skip; $data['timeid'] = $timeid; sendJSON($data); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn viewBlockStatus() /// /// \brief prints a page with information about an active block allocation /// //////////////////////////////////////////////////////////////////////////////// function viewBlockStatus() { $blockid = getContinuationVar('id'); print "

Block Allocation

\n"; $data = getBlockAllocationStatus($blockid); if(is_null($data)) { print "The selected Block Allocation no longer exists."; return; } $startunix = datetimeToUnix($data['start']); $endunix = datetimeToUnix($data['end']); $start = date('g:ia n/j/Y', $startunix); $end = date('g:ia n/j/Y', $endunix); print "
\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; if($data['subimages']) print " \n"; else print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
Name:{$data['name']}
Environment:{$data['image']}
Resources:{$data['numMachines']} clusters{$data['numMachines']} computers
Starting:$start
Ending:$end

\n"; if(! $data['subimages']) { $available = 0; $reloading = 0; $used = 0; foreach($data['comps'] as $id => $comp) { if($comp['state'] == 'available') $available++; elseif($comp['state'] == 'reloading') $reloading++; elseif($comp['state'] == 'reserved' || $comp['state'] == 'inuse') $used++; } $failed = $data['numMachines'] - $available - $reloading - $used; print "Current status of computers:
\n"; } else { $imgdata = getImages(0, $data['imageid']); $imageids = $imgdata[$data['imageid']]['subimages']; array_unshift($imageids, $data['imageid']); $imgavailable = array(); $imgreloading = array(); $imgused = array(); $imgfailed = array(); foreach($imageids AS $id) { $imgavailable[$id] = 0; $imgreloading[$id] = 0; $imgused[$id] = 0; $imgfailed[$id] = 0; } foreach($data['comps'] as $id => $comp) { if($comp['state'] == 'available') $imgavailable[$comp['designatedimageid']]++; elseif($comp['state'] == 'reloading') $imgreloading[$comp['designatedimageid']]++; elseif($comp['state'] == 'reserved' || $comp['state'] == 'inuse') $imgused[$comp['designatedimageid']]++; } $failed = 0; $available = $data['numMachines']; $used = $imgused[$data['imageid']]; foreach($imageids AS $id) { $imgfailed[$id] = $data['numMachines'] - $imgavailable[$id] - $imgreloading[$id] - $used; if($failed < $imgfailed[$id]) $failed = $imgfailed[$id]; if($available > $imgavailable[$id]) $available = $imgavailable[$id]; } $reloading = $data['numMachines'] - $available - $used - $failed; print "Current status of clusters:
\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 "
Available:$available
Reloading:$reloading
Reserved/In use:$used
Failed:$failed
\n"; print "
\n"; $cont = addContinuationsEntry('AJupdateBlockStatus', array('id' => $blockid)); print "\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJupdateBlockStatus() /// /// \brief ajax function to send JSON data about the current status of a block /// allocation /// //////////////////////////////////////////////////////////////////////////////// function AJupdateBlockStatus() { $id = getContinuationVar('id'); $data = getBlockAllocationStatus($id); if(is_null($data)) { sendJSON(array('status' => 'gone')); return; } if(! $data['subimages']) { $available = 0; $reloading = 0; $used = 0; foreach($data['comps'] as $id => $comp) { if($comp['state'] == 'available') $available++; elseif($comp['state'] == 'reloading') $reloading++; elseif($comp['state'] == 'reserved' || $comp['state'] == 'inuse') $used++; } $failed = $data['numMachines'] - $available - $reloading - $used; } else { $imgdata = getImages(0, $data['imageid']); $imageids = $imgdata[$data['imageid']]['subimages']; array_unshift($imageids, $data['imageid']); $imgavailable = array(); $imgreloading = array(); $imgused = array(); $imgfailed = array(); foreach($imageids AS $id) { $imgavailable[$id] = 0; $imgreloading[$id] = 0; $imgused[$id] = 0; $imgfailed[$id] = 0; } foreach($data['comps'] as $id => $comp) { if($comp['state'] == 'available') $imgavailable[$comp['designatedimageid']]++; elseif($comp['state'] == 'reloading') $imgreloading[$comp['designatedimageid']]++; elseif($comp['state'] == 'reserved' || $comp['state'] == 'inuse') $imgused[$comp['designatedimageid']]++; } $failed = 0; $available = $data['numMachines']; $used = $imgused[$data['imageid']]; foreach($imageids AS $id) { $imgfailed[$id] = $data['numMachines'] - $imgavailable[$id] - $imgreloading[$id] - $used; if($failed < $imgfailed[$id]) $failed = $imgfailed[$id]; if($available > $imgavailable[$id]) $available = $imgavailable[$id]; } $reloading = $data['numMachines'] - $available - $used - $failed; } $arr = array('available' => $available, 'reloading' => $reloading, 'used' => $used, 'failed' => $failed); sendJSON($arr); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn processBlockAllocationInput() /// /// \return an array with these keys:\n /// \b name - name of block allocation\n /// \b imageid - selected image id\n /// \b seats - number of machines to allocate\n /// \b groupid - user group id for selected user group\n /// \b admingroupid - user group id for selected admin user group\n /// \b type - 'weekly', 'monthly', or 'list'\n /// \b slots - array of date/time slots in 'YYYY-MM-DD|HH:MM|HH:MM' format (date|start|end)\n /// \b times - array of times in HH:MM|HH:MM format (start|end)\n /// \b expiretime - datetime at which this block allocation will be completed\n /// \b startdate - start date of block allocation (only valid for weekly and monthly)\n /// \b enddate - end date of block allocation (only valid for weekly and monthly)\n /// \b startts - unix timestamp for startdate\n /// \b endts - unix timestamp for enddate\n /// \b daymask - bitmask int for days of week (only valid for weekly)\n /// \b weeknum - week of the month (from 1 to 5, only valid for monthly)\n /// \b day - day of week (from 1 to 7, only valid for monthly)\n /// \b comments - user submitted comments about this block allocation\n /// \b err - 1 if error encountered, 0 if not /// /// \brief processes input for blockallocations /// //////////////////////////////////////////////////////////////////////////////// function processBlockAllocationInput() { global $user; $return = array(); $method = getContinuationVar('method'); $return['name'] = processInputVar('name', ARG_STRING); $return['owner'] = processInputVar('owner', ARG_STRING); $return['imageid'] = processInputVar('imageid', ARG_NUMERIC); $return['seats'] = processInputVar('seats', ARG_NUMERIC); $return['groupid'] = processInputVar('groupid', ARG_NUMERIC); $return['admingroupid'] = processInputVar('admingroupid', ARG_NUMERIC); $type = processInputVar('type', ARG_STRING); $err = 0; if($method != 'request' && ! preg_match('/^([-a-zA-Z0-9\. \(\)]){3,80}$/', $return['name'])) { $errmsg = "The name can only contain letters, numbers, spaces, dashes(-),
and periods(.) and can be from 3 to 80 characters long"; $err = 1; } $resources = getUserResources(array("imageAdmin", "imageCheckOut")); $resources["image"] = removeNoCheckout($resources["image"]); if(! array_key_exists($return['imageid'], $resources['image'])) { $errmsg = 'The submitted image is invalid.'; $err = 1; } if(! $err && $method != 'request' && ! validateUserid($return['owner'])) { $errmsg = 'The submitted owner is invalid.'; $err = 1; } else $return['ownerid'] = getUserlistID($return['owner']); $groups = getUserGroups(0, $user['affiliationid']); $extragroups = getContinuationVar('extragroups'); if(! $err && ! array_key_exists($return['groupid'], $groups) && ! array_key_exists($return['groupid'], $extragroups) && $return['groupid'] != 0) { $errmsg = 'The submitted user group is invalid.'; $err = 1; } if(! $err && $method != 'request' && ! array_key_exists($return['admingroupid'], $groups) && $return['admingroupid'] != 0) { $errmsg = 'The submitted admin user group is invalid.'; $err = 1; } if(! $err && ($return['seats'] < MIN_BLOCK_MACHINES || $return['seats'] > MAX_BLOCK_MACHINES)) { $errmsg = 'The submitted number of seats must be between ' . MIN_BLOCK_MACHINES . ' and ' . MAX_BLOCK_MACHINES . '.'; $err = 1; } if(! $err && $type != 'weekly' && $type != 'monthly' && $type != 'list') { $errmsg = 'You must select one of "Repeating Weekly", "Repeating Monthly", ' . 'or "List of Dates/Times".'; $err = 1; } if(! $err) { if($type == 'list') { $slots = processInputVar('slots', ARG_STRING); $return['slots'] = explode(',', $slots); $return['times'] = array(); $lastdate = array('day' => '', 'ts' => 0); foreach($return['slots'] as $slot) { $tmp = explode('|', $slot); if(count($tmp) != 3) { $errmsg = 'Invalid date/time submitted.'; $err = 1; break; } $date = $tmp[0]; if(! $err) { $datets = strtotime($date); if($method != 'edit' && $datets < (time() - SECINDAY)) { $errmsg = 'The date must be today or later.'; $err = 1; break; } } $return['times'][] = "{$tmp[1]}|{$tmp[2]}"; if($datets > $lastdate['ts']) { $lastdate['ts'] = $datets; $lastdate['day'] = $date; } } if(! $err) { $expirets = strtotime("{$lastdate['day']} 23:59:59"); $return['expiretime'] = unixToDatetime($expirets); } } if($type == 'weekly' || $type == 'monthly') { $return['startdate'] = processInputVar('startdate', ARG_NUMERIC); $return['enddate'] = processInputVar('enddate', ARG_NUMERIC); $times = processInputVar('times', ARG_STRING); $return['startts'] = strtotime($return['startdate']); $return['endts'] = strtotime($return['enddate']); if($return['startts'] > $return['endts']) { $errmsg = 'The Last Date of Usage must be the same or later than the First Date of Usage.'; $err = 1; } elseif($method != 'edit' && $return['startts'] < (time() - SECINDAY)) { $errmsg = 'The start date must be today or later.'; $err = 1; } $expirets = strtotime("{$return['enddate']} 23:59:59"); $return['expiretime'] = unixToDatetime($expirets); $return['times'] = explode(',', $times); } foreach($return['times'] as $time) { $tmp = explode('|', $time); if(count($tmp) != 2) { $errmsg = 'Invalid start/end time submitted'; $err = 1; break; } $start = explode(':', $tmp[0]); if(count($start) != 2 || ! is_numeric($start[0]) || ! is_numeric($start[1]) || $start[0] < 0 || $start[0] > 23 || $start[1] < 0 || $start[1] > 59) { $errmsg = 'Invalid start time submitted'; $err = 1; break; } $end = explode(':', $tmp[1]); if(count($end) != 2 || ! is_numeric($end[0]) || ! is_numeric($end[1]) || $end[0] < 0 || $end[0] > 23 || $end[1] < 0 || $end[1] > 59) { $errmsg = 'Invalid end time submitted'; $err = 1; break; } $start = minuteOfDay($start[0], $start[1]); $end = minuteOfDay($end[0], $end[1]); if($start >= $end) { $errmsg = 'Each start time must be less than the corresponding end time.'; $err = 1; break; } } if($type == 'weekly') { $days = processInputVar('days', ARG_STRING); $return['daymask'] = 0; if(! $err) { foreach(explode(',', $days) as $day) { if($day == '' || $day < 0 || $day > 6) { $errmsg = "Invalid day submitted."; $err = 1; break; } $return['daymask'] |= (1 << $day); } } if(! $err && $return['daymask'] == 0) { $errmsg = "No valid days submitted."; $err = 1; } } if($type == 'monthly') { $return['weeknum'] = processInputVar('weeknum', ARG_NUMERIC); $return['day'] = processInputVar('day', ARG_NUMERIC); if(! $err && ($return['weeknum'] < 1 || $return['weeknum'] > 5)) { $errmsg = "Invalid week number submitted."; $err = 1; } if(! $err && ($return['day'] < 1 || $return['day'] > 7)) { $errmsg = "Invalid day of week submitted."; $err = 1; } } } if($method == 'request') { $return['comments'] = processInputVar('comments', ARG_STRING); if(get_magic_quotes_gpc()) $return['comments'] = stripslashes($return['comments']); if(! $err && preg_match('/[<>]/', $return['comments'])) { $errmsg = "<>\'s are not allowed in the comments."; $err = 1; } } if($err) { print "clearHideConfirmForm();"; print "alert('$errmsg');"; $data = array('extragroups' => $extragroups, 'method' => $method); if($method == 'edit') $data['blockid'] = getContinuationVar('blockid'); $cont = addContinuationsEntry('AJblockAllocationSubmit', $data, SECINWEEK, 1, 0); print "dojo.byId('submitcont').value = '$cont';"; } $return['type'] = $type; $return['err'] = $err; return $return; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn getBlockAllocationStatus($id) /// /// \param $id - id of a block allocation /// /// \return if $id, an array with these keys (NULL otherwise):\n /// \b name - name of block allocation\n /// \b imageid - id of image\n /// \b image - pretty name of image\n /// \b subimages - 0 or 1; if image has subimages\n /// \b numMachines - number of machines allocated for block allocation\n /// \b groupid - id of group associated with block allocation\n /// \b group - name of group associated with block allocation\n /// \b processing - flag from table\n /// \b timeid - id of associated block time having earliest start time\n /// \b start - start time of associated block time (datetime)\n /// \b end - end time of associated block time (datetime)\n /// \b processed - flag from table\n /// \b comps - array of data from blockComputers with these keys:\n /// \b id - id of computer\n /// \b state - state of computer\n /// \b currentimageid - current imageid of computer\n /// \b curentimage - current image of computer\n /// \b designatedimageid - id of image to be loaded on computer\n /// \b designatedimage - image to be loaded on computer\n /// \b hostname - hostname of computer\n /// \b type - the computer type /// /// \brief gets status information about the passed in block allocation id /// //////////////////////////////////////////////////////////////////////////////// function getBlockAllocationStatus($id) { $query = "SELECT r.name, " . "r.imageid, " . "i.prettyname AS image, " . "im.subimages, " . "r.numMachines, " . "r.groupid, " . "g.name AS 'group', " . "r.processing, " . "t.id AS timeid, " . "t.start, " . "t.end, " . "t.processed " . "FROM blockRequest r, " . "blockTimes t, " . "usergroup g, " . "image i " . "LEFT JOIN imagemeta im ON (i.imagemetaid = im.id) " . "WHERE t.blockRequestid = $id AND " . "r.id = $id AND " . "r.imageid = i.id AND " . "r.groupid = g.id " . "ORDER BY t.start " . "LIMIT 1"; $qh = doQuery($query, 101); if($data = mysql_fetch_assoc($qh)) { if(! is_numeric($data['subimages'])) $data['subimages'] = 0; $query = "SELECT c.id, " . "s.name AS state, " . "c.currentimageid, " . "ci.prettyname AS curentimage, " . "bc.imageid AS designatedimageid, " . "di.prettyname AS designatedimage, " . "c.hostname, " . "c.type " . "FROM blockComputers bc, " . "computer c, " . "state s, " . "image ci, " . "image di " . "WHERE bc.blockTimeid = {$data['timeid']} AND " . "bc.computerid = c.id AND " . "c.currentimageid = ci.id AND " . "bc.imageid = di.id AND " . "c.stateid = s.id"; $qh = doQuery($query, 101); $data['comps'] = array(); while($row = mysql_fetch_assoc($qh)) $data['comps'][$row['id']] = $row; return $data; } else return NULL; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn getBlockAllocationData($blockid) /// /// \param $blockid - id of a block allocation /// /// \return an array with these keys:\n /// \b name - name of block allocation\n /// \b imageid - id of image\n /// \b seats - number of machines allocated for block allocation\n /// \b ownerid - id from user table of block allocation owner\n /// \b owner - block allocation owner\n /// \b usergroupid - id of group associated with block allocation\n /// \b admingroupid - id of admin group associated with block allocation\n /// \b repeating - weekly, monthly, or list\n /// \b type - array with weekly, monthly, or list set to 'checked' and the /// others set to an empty string\n /// \b type2 - array with weekly, monthly, or list set to 'selected' and the /// others set to an empty string\n /// \b swdate - start date of associated block time (datetime)\n /// \b ewdate - end date of associated block time (datetime)\n /// \b smdate - start date of associated block time (datetime)\n /// \b emdate - end date of associated block time (datetime)\n /// \b wdayschecked - array where keys are days of the week and values are /// either 'checked' or empty /// \b mnweeknumid - week of the month (1 to 5)\n /// \b mndayid - day of the week (1 to 7) /// /// \brief gets information about a block allocation /// //////////////////////////////////////////////////////////////////////////////// function getBlockAllocationData($blockid) { global $days; $rt = array('name' => '', 'imageid' => '', 'seats' => MIN_BLOCK_MACHINES, 'ownerid' => '', 'owner' => '', 'usergroupid' => '', 'admingroupid' => '', 'repeating' => '', 'swdate' => '', 'ewdate' => '', 'wdayschecked' => array(), 'smdate' => '', 'emdate' => '', 'mnweeknumid' => '', 'mndayid' => ''); foreach($days as $day) $rt['wdayschecked'][$day] = ''; $rt['type'] = array('weekly' => 'checked', 'monthly' => '', 'list' => ''); $rt['type2'] = array('weekly' => 'selected', 'monthly' => '', 'list' => ''); if(empty($blockid)) return $rt; $query = "SELECT b.name, " . "b.imageid, " . "b.numMachines AS seats, " . "b.ownerid, " . "CONCAT(u.unityid, '@', a.name) AS owner, " . "b.groupid AS usergroupid, " . "b.admingroupid, " . "b.repeating, " . "d.start AS swdate, " . "d.end AS ewdate, " . "d.start AS smdate, " . "d.end AS emdate, " . "d.days AS mndayid, " . "d.weeknum AS mnweeknumid " . "FROM blockWebDate d, " . "blockRequest b " . "LEFT JOIN user u ON (b.ownerid = u.id) " . "LEFT JOIN affiliation a ON (u.affiliationid = a.id) " . "WHERE b.id = d.blockRequestid AND " . "b.id = $blockid"; $qh = doQuery($query, 101); $row = mysql_fetch_assoc($qh); if(empty($row)) return $rt; $row['wdayschecked'] = $rt['wdayschecked']; if($row['repeating'] == 'weekly') { $row['smdate'] = ''; $row['emdate'] = ''; for($i = 0; $i < 7; $i++) { if($row['mndayid'] & (1 << $i)) $row['wdayschecked'][$days[$i]] = 'checked'; } $row['type'] = $rt['type']; $row['type2'] = $rt['type2']; } elseif($row['repeating'] == 'monthly') { $row['swdate'] = ''; $row['ewdate'] = ''; $row['type'] = array('weekly' => '', 'monthly' => 'checked', 'list' => ''); $row['type2'] = array('weekly' => '', 'monthly' => 'selected', 'list' => ''); } elseif($row['repeating'] == 'list') { $row['smdate'] = ''; $row['emdate'] = ''; $row['swdate'] = ''; $row['ewdate'] = ''; $row['type'] = array('weekly' => '', 'monthly' => '', 'list' => 'checked'); $row['type2'] = array('weekly' => '', 'monthly' => '', 'list' => 'selected'); } return $row; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJpopulateBlockStore() /// /// \brief ajax function to send JSON data for creating the dojo data store for /// a block allocation set of times /// //////////////////////////////////////////////////////////////////////////////// function AJpopulateBlockStore() { $blockid = getContinuationVar('blockid'); $query = "SELECT repeating FROM blockRequest WHERE id = $blockid"; $qh = doQuery($query, 101); if(! ($row = mysql_fetch_assoc($qh))) { sendJSON(array('error' => 'Error: Failed to fetch start/end times for block allocation.')); return; } if($row['repeating'] == 'weekly' || $row['repeating'] == 'monthly') { $type = $row['repeating']; $query = "SELECT starthour, " . "startminute, " . "startmeridian, " . "endhour, " . "endminute, " . "endmeridian " . "FROM blockWebTime " . "WHERE blockRequestid = $blockid"; $qh = doQuery($query, 101); $starths = array(); $startms = array(); $endhs = array(); $endms = array(); while($row = mysql_fetch_assoc($qh)) { $starth = hour12to24($row['starthour'], $row['startmeridian']); $endh = hour12to24($row['endhour'], $row['endmeridian']); $starths[] = $starth; $startms[] = $row['startminute']; $endhs[] = $endh; $endms[] = $row['endminute']; } sendJSON(array('type' => $type, 'starths' => $starths, 'startms' => $startms, 'endhs' => $endhs, 'endms' => $endms)); } elseif($row['repeating'] == 'list') { $query = "SELECT starthour, " . "startminute, " . "startmeridian, " . "endhour, " . "endminute, " . "endmeridian, " . "`order` " . "FROM blockWebTime " . "WHERE blockRequestid = $blockid"; $qh = doQuery($query, 101); $data = array(); while($row = mysql_fetch_assoc($qh)) $data[$row['order']] = $row; $query = "SELECT MONTH(start) AS month, " . "DAY(start) AS day, " . "YEAR(start) AS year, " . "days " . "FROM blockWebDate " . "WHERE blockRequestid = $blockid"; $qh = doQuery($query, 101); $months = array(); $days = array(); $years = array(); $starths = array(); $startms = array(); $endhs = array(); $endms = array(); while($row = mysql_fetch_assoc($qh)) { $id = $row['days']; $months[] = $row['month']; $days[] = $row['day']; $years[] = $row['year']; $starth = hour12to24($data[$id]['starthour'], $data[$id]['startmeridian']); $endh = hour12to24($data[$id]['endhour'], $data[$id]['endmeridian']); $starths[] = $starth; $startms[] = $data[$id]['startminute']; $endhs[] = $endh; $endms[] = $data[$id]['endminute']; } sendJSON(array('type' => 'list', 'months' => $months, 'days' => $days, 'years' => $years, 'starths' => $starths, 'startms' => $startms, 'endhs' => $endhs, 'endms' => $endms)); } } ?>