| <?php |
| /* |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. |
| The ASF licenses this file to You under the Apache License, Version 2.0 |
| (the "License"); you may not use this file except in compliance with |
| the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| */ |
| |
| /** |
| * \file |
| */ |
| |
| //////////////////////////////////////////////////////////////////////////////// |
| /// |
| /// \fn blockAllocations() |
| /// |
| /// \brief prints a page with block allocation request form for normal users and |
| /// a page with current block allocations and pending allocations for admin |
| /// users |
| /// |
| //////////////////////////////////////////////////////////////////////////////// |
| function blockAllocations() { |
| global $user; |
| if(! checkUserHasPerm('Manage Block Allocations (global)') && |
| ! checkUserHasPerm('Manage Block Allocations (affiliation only)')) { |
| print "<H2>" . i("Block Allocations") . "</H2>\n"; |
| print i("Block Allocations are a way to have a set of machines preloaded with a particular environment at specified times and made available to a specific group of users. This is very useful for classroom use and for workshops. They can be made available on a repeating schedule such as when a course meets each week. Block Allocations only allocate machines for the group of users - they do not create the actual, end user reservations for the machines. All users still must log in to the VCL web site and make their own reservations DURING the period a block allocation is active. The forms here provide a way for you to submit a request for a Block Allocation for review by a sysadmin. If you just need to use a machine through VCL, use the New Reservation page for that."); |
| print "<br><br>"; |
| print i("Please submit Block Allocation requests at least one full business day in advance to allow time for them to be approved.") . "<br><br>\n"; |
| print "<button dojoType=\"dijit.form.Button\" type=\"button\">\n"; |
| print i( "Request New Block Allocation") . "\n"; |
| print " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| print " location.href = '" . BASEURL . SCRIPT . "?mode=requestBlockAllocation';\n"; |
| print " </script>\n"; |
| print "</button>\n"; |
| print getUserCurrentBlockHTML(); |
| } |
| else { |
| print "<h2>" . i("Manage Block Allocations") . "</h2>\n"; |
| $cont = addContinuationsEntry('viewBlockAllocatedMachines'); |
| print "<a href=\"" . BASEURL . SCRIPT . "?continuation=$cont\">"; |
| print i("View Block Allocated Machines") . "</a><br><br>\n"; |
| print "<div id=\"blocklist\">\n"; |
| print getCurrentBlockHTML(); |
| print "</div>\n"; |
| print "<button dojoType=\"dijit.form.Button\" type=\"button\">\n"; |
| print " " . i("Create New Block Allocation") . "\n"; |
| print " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| $cont = addContinuationsEntry('newBlockAllocation'); |
| print " location.href = '" . BASEURL . SCRIPT . "?continuation=$cont';\n"; |
| print " </script>\n"; |
| print "</button>\n"; |
| print "<h2>" . i("Block Allocation Requests") . "</h2>\n"; |
| print "<div id=\"pendinglist\">\n"; |
| print getPendingBlockHTML(); |
| print "</div>\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 = mysqli_fetch_assoc($qh)) |
| $blocks[$row['id']] = $row['name']; |
| print "<hr>\n"; |
| print "<h2>" . i("Your Active Block Allocations") . "</h2>\n"; |
| print i("You are currently a member of the following Block Allocations.") . "<br>\n"; |
| print i("Click an item to view its current status.") . "<br>\n"; |
| foreach($blocks as $id => $name) { |
| $cont = addContinuationsEntry('viewBlockStatus', array('id' => $id)); |
| print "<a href=\"" . BASEURL . SCRIPT . "?continuation=$cont\">"; |
| print "$name</a><br>\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(array_key_exists('tzoffset', $_SESSION['persistdata'])) |
| $now = time() - ($_SESSION['persistdata']['tzoffset'] * 60); |
| else |
| $now = time(); |
| print "<input type=\"hidden\" id=\"nowtimestamp\" value=\"$now\">\n"; |
| print "<input type=\"hidden\" id=\"timezone\" value=\"" . date('T') . "\">\n"; |
| if($mode == 'newBlockAllocation') { |
| $brname = ''; |
| $imageid = ''; |
| print "<h2>" . i("New Block Allocation") . "</h2>\n"; |
| } |
| elseif($mode == 'editBlockAllocation') { |
| print "<h2>" . i("Edit Block Allocation") . "</h2>\n"; |
| } |
| elseif($mode == 'requestBlockAllocation') { |
| print "<h2>" . i("Request New Block Allocation") . "</h2>\n"; |
| print i("Complete the following form to request a new block allocation. Your request will need to be approved by a VCL admin before it is created."); |
| print "<br><br>\n"; |
| } |
| $resources = getUserResources(array("imageAdmin", "imageCheckOut")); |
| $resources["image"] = removeNoCheckout($resources["image"]); |
| print "<table summary=\"\">\n"; |
| if($mode != 'requestBlockAllocation') { |
| print " <tr>\n"; |
| print " <th align=right>" . i("Name:") . "</th>\n"; |
| print " <td>\n"; |
| print " <input type=\"text\" value=\"{$data['name']}\" dojoType=\"dijit.form.ValidationTextBox\" "; |
| print "id=\"brname\" required=\"true\" invalidMessage=\""; |
| print i("Name can only contain letters, numbers, spaces, dashes(-), parenthesis, 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 " </td>\n"; |
| print " </tr>\n"; |
| print " <tr>\n"; |
| print " <th align=right>" . i("Owner:") . "</th>\n"; |
| print " <td>\n"; |
| $initval = $data['owner']; |
| if(empty($initval)) |
| $initval = "{$user['unityid']}@{$user['affiliation']}"; |
| print " <input type=\"text\" value=\"$initval\" dojoType=\"dijit.form.ValidationTextBox\" "; |
| print "id=\"browner\" required=\"true\" invalidMessage=\"" . i("Unknown user") . "\" style=\"width: 300px\" "; |
| print "validator=\"checkOwner\" onFocus=\"ownerFocus\">\n"; |
| print " </td>\n"; |
| print " </tr>\n"; |
| } |
| print " <tr>\n"; |
| print " <th align=right>" . i("Environment") . ":</th>\n"; |
| print " <td>\n"; |
| if(USEFILTERINGSELECT && count($resources['image']) < FILTERINGSELECTTHRESHOLD) { |
| print " <select dojoType=\"dijit.form.FilteringSelect\" id=imagesel style=\"width: 300px\" "; |
| print "queryExpr=\"*\${0}*\" highlightMatch=\"all\" autoComplete=\"false\" "; |
| print "onChange=\"clearCont2();\">\n"; |
| } |
| else |
| print " <select id=imagesel onChange=\"clearCont2();\">"; |
| foreach($resources['image'] as $id => $name) { |
| if($id == $data['imageid']) |
| print " <option value=\"$id\" selected>$name</option>\n"; |
| else |
| print " <option value=\"$id\">$name</option>\n"; |
| } |
| print " </select>\n"; |
| print " </td>\n"; |
| print " </tr>\n"; |
| print " <tr>\n"; |
| print " <th align=right>" . i("User group") . ":</th>\n"; |
| print " <td>\n"; |
| $groups = getUserGroups(0, $user['affiliationid']); |
| if(USEFILTERINGSELECT && count($groups) < FILTERINGSELECTTHRESHOLD) { |
| print " <select dojoType=\"dijit.form.FilteringSelect\" id=groupsel style=\"width: 300px\" "; |
| print "queryExpr=\"*\${0}*\" highlightMatch=\"all\" autoComplete=\"false\" "; |
| print "onChange=\"clearCont2();\">\n"; |
| } |
| else |
| print " <select id=groupsel onChange=\"clearCont2();\">"; |
| $extragroups = array(); |
| if($mode == 'requestBlockAllocation') |
| print " <option value=\"0\">(" . i("group not listed") . ")</option>\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 " <option value=\"$id\" selected>{$group['name']}</option>\n"; |
| else |
| print " <option value=\"$id\">{$group['name']}</option>\n"; |
| } |
| print " </select>\n"; |
| print " <img src=\"images/helpicon.png\" id=\"grouphelp\" />\n"; |
| print " </td>\n"; |
| print " </tr>\n"; |
| print " <tr>\n"; |
| print " <th align=right>" . i("Number of seats") . ":</th>\n"; |
| print " <td>\n"; |
| print " <input dojoType=\"dijit.form.NumberSpinner\" value=\"{$data['seats']}\" "; |
| print "smallDelta=1 largeDelta=5 constraints=\"{min:" . MIN_BLOCK_MACHINES . ", max:"; |
| print MAX_BLOCK_MACHINES . "}\" id=machinecnt required=\"true\" style=\"width: 70px\" filter=\"machinecntfilter\"/>\n"; |
| print " <img src=\"images/helpicon.png\" id=\"seathelp\" />\n"; |
| print " </td>\n"; |
| print " </tr>\n"; |
| print "</table>\n"; |
| |
| print i("Specify dates/times by:\n"); |
| print "<img src=\"images/helpicon.png\" id=\"repeattypehelp\" /><br>\n"; |
| print "<input type=\"radio\" name=\"datetime\" id=\"weeklyradio\" onClick=\"blockFormChangeTab('weekly');\" {$data['type']['weekly']} />\n"; |
| print "<label for=\"weeklyradio\">" . i("Repeating Weekly") . "</label><br>\n"; |
| print "<input type=\"radio\" name=\"datetime\" id=\"monthlyradio\" onClick=\"blockFormChangeTab('monthly');\" {$data['type']['monthly']} />\n"; |
| print "<label for=\"monthlyradio\">" . i("Repeating Monthly") . "</label><br>\n"; |
| print "<input type=\"radio\" name=\"datetime\" id=\"listradio\" onClick=\"blockFormChangeTab('list');\" {$data['type']['list']} />\n"; |
| print "<label for=\"listradio\">" . i("List of Dates/Times") . "</label><br><br>\n"; |
| |
| print "<div style=\"border: 1px solid; margin-right: 8px;\">\n"; |
| print "<div id=\"timeTypeContainer\" dojoType=\"dijit.layout.StackContainer\"\n"; |
| print " style=\"width:550px; height:240px; margin: 5px;\">\n"; |
| |
| # repeating weekly |
| print "<div id=\"weeklytab\" dojoType=\"dijit.layout.ContentPane\" "; |
| print "title=\"" . i("Repeating Weekly") . "\" {$data['type2']['weekly']}>\n"; |
| print "<table summary=\"\">\n"; |
| print " <tr>\n"; |
| print " <th align=right>" . i("First Date of Usage") . ":</th>\n"; |
| print " <td>\n"; |
| print " <input type=\"text\" dojoType=\"dijit.form.DateTextBox\" "; |
| print "required=\"true\" id=\"wkfirstdate\" value=\"{$data['swdate']}\" />\n"; |
| print " <small>(" . date('T') . ")</small>\n"; |
| print " <img src=\"images/helpicon.png\" id=\"wkfdhelp\" />\n"; |
| print " </td>\n"; |
| print " </tr>\n"; |
| print " <tr>\n"; |
| print " <th align=right>" . i("Last Date of Usage") . ":</th>\n"; |
| print " <td>\n"; |
| print " <input type=\"text\" dojoType=\"dijit.form.DateTextBox\" "; |
| print "required=\"true\" id=\"wklastdate\" value=\"{$data['ewdate']}\" />\n"; |
| print " <small>(" . date('T') . ")</small>\n"; |
| print " <img src=\"images/helpicon.png\" id=\"wkldhelp\" />\n"; |
| print " </td>\n"; |
| print " </tr>\n"; |
| print "</table>\n"; |
| print "<table summary=\"\">\n"; |
| print "<tr>\n"; |
| print "<th>" . i("Days") . " <img src=\"images/helpicon.png\" id=\"wkdayshelp\" /></th>\n"; |
| print "<th>" . i("Times") . " <img src=\"images/helpicon.png\" id=\"wktimeshelp\" /></th>\n"; |
| print "</tr>\n"; |
| print "<tr>\n"; |
| print "<td valign=top>\n"; |
| foreach($days as $id => $day) { |
| print " <INPUT type=checkbox id=\"wdays$id\" value=\"$day\" {$data['wdayschecked'][$day]}>\n"; |
| print " <label for=\"wdays$day\">" . i($day) . "</label><br>\n"; |
| } |
| print "</td>\n"; |
| print "<td>\n"; |
| |
| print i("Start") . ":<div type=\"text\" id=\"weeklyaddstart\" dojoType=\"dijit.form.TimeTextBox\" "; |
| print "required=\"true\" onChange=\"blockFormWeeklyAddBtnCheck(1);\" style=\"width: 78px\"></div>\n"; |
| print "<small>(" . date('T') . ")</small>\n"; |
| print " | "; |
| print i("End") . ":<div type=\"text\" id=\"weeklyaddend\" dojoType=\"vcldojo.TimeTextBoxEnd\" "; |
| print "required=\"true\" onChange=\"blockFormWeeklyAddBtnCheck(0);\" startid=\"weeklyaddstart\" "; |
| print "style=\"width: 78px\"></div>\n"; |
| print "<small>(" . date('T') . ")</small>\n"; |
| print "<button dojoType=\"dijit.form.Button\" type=\"button\" disabled=\"true\" "; |
| print "id=\"requestBlockWeeklyAddBtn\">\n"; |
| print i("Add") . "\n"; |
| print " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| print " blockFormAddWeeklyTime();\n"; |
| print " </script>\n"; |
| print "</button>\n"; |
| print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"requestBlockAddWeeklyStore\" "; |
| print "data=\"blockFormAddWeeklyData\"></div>\n"; |
| print "<table dojoType=\"dojox.grid.DataGrid\" jsId=\"requestBlockAddWeeklyGrid\" sortInfo=1 "; |
| print "store=\"requestBlockAddWeeklyStore\" style=\"width: 330px; height: 120px;\">\n"; |
| print "<thead>\n"; |
| print "<tr>\n"; |
| print "<th field=\"start\" width=\"102px\" formatter=\"gridTimePrimary\">"; |
| print i("Start") . "</th>\n"; |
| print "<th field=\"end\" width=\"102px\" formatter=\"timeFromTextBox\">"; |
| print i("End") . "</th>\n"; |
| print "<th field=\"remove\" width=\"80px\">" . i("Remove") . "</th>\n"; |
| print "</tr>\n"; |
| print "</thead>\n"; |
| print "</table>\n"; |
| |
| print "</td>\n"; |
| print "</tr>\n"; |
| print "</table>\n"; |
| print "</div>\n"; # repeating weekly |
| |
| # repeating monthly |
| print "<div id=\"monthlytab\" dojoType=\"dijit.layout.ContentPane\" "; |
| print "title=\"" . i("Repeating Monthly") . "\" {$data['type2']['monthly']}>\n"; |
| print "<table summary=\"\">\n"; |
| print " <tr>\n"; |
| print " <th align=right>" . i("First Date of Usage") . ":</th>\n"; |
| print " <td>\n"; |
| print " <input type=\"text\" id=\"mnfirstdate\" dojoType=\"dijit.form.DateTextBox\" "; |
| print "required=\"true\" value=\"{$data['smdate']}\"/>\n"; |
| print " <small>(" . date('T') . ")</small>\n"; |
| print " <img src=\"images/helpicon.png\" id=\"mnfdhelp\" />\n"; |
| print " </td>\n"; |
| print " </tr>\n"; |
| print " <tr>\n"; |
| print " <th align=right>" . i("Last Date of Usage") . ":</th>\n"; |
| print " <td>\n"; |
| print " <input type=\"text\" id=\"mnlastdate\" dojoType=\"dijit.form.DateTextBox\" "; |
| print "required=\"true\" value=\"{$data['emdate']}\" />\n"; |
| print " <small>(" . date('T') . ")</small>\n"; |
| print " <img src=\"images/helpicon.png\" id=\"mnldhelp\" />\n"; |
| print " </td>\n"; |
| print " </tr>\n"; |
| print "</table>\n"; |
| $weeknumArr = array(1 => i("1st"), |
| 2 => i("2nd"), |
| 3 => i("3rd"), |
| 4 => i("4th"), |
| 5 => i("5th")); |
| $dayArr = array(1 => i("Sunday"), |
| 2 => i("Monday"), |
| 3 => i("Tuesday"), |
| 4 => i("Wednesday"), |
| 5 => i("Thursday"), |
| 6 => i("Friday"), |
| 7 => i("Saturday")); |
| print i("Repeat on the") . " "; |
| printSelectInput('weeknum', $weeknumArr, $data['mnweeknumid'], 0, 0, 'mnweeknum'); |
| printSelectInput('day', $dayArr, $data['mndayid'], 0, 0, 'mnday'); |
| print " " . i("of every month") . "<br><br>\n"; |
| print i("Start") . ":<div type=\"text\" id=\"monthlyaddstart\" dojoType=\"dijit.form.TimeTextBox\" "; |
| print "required=\"true\" onChange=\"blockFormMonthlyAddBtnCheck(1)\" style=\"width: 78px\"></div>\n"; |
| print "<small>(" . date('T') . ")</small>\n"; |
| print " | "; |
| print i("End") . ":<div type=\"text\" id=\"monthlyaddend\" dojoType=\"vcldojo.TimeTextBoxEnd\" "; |
| print "required=\"true\" onChange=\"blockFormMonthlyAddBtnCheck(0)\" startid=\"monthlyaddstart\" "; |
| print "style=\"width: 78px\"></div>\n"; |
| print "<small>(" . date('T') . ")</small>\n"; |
| print "<button dojoType=\"dijit.form.Button\" type=\"button\" disabled=\"true\" "; |
| print "id=\"requestBlockMonthlyAddBtn\">\n"; |
| print i("Add") . "\n"; |
| print " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| print " blockFormAddMonthlyTime();\n"; |
| print " </script>\n"; |
| print "</button>\n"; |
| print "<img src=\"images/helpicon.png\" id=\"mntimeshelp\" />\n"; |
| print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"requestBlockAddMonthlyStore\" "; |
| print "data=\"blockFormAddMonthlyData\"></div>\n"; |
| print "<table dojoType=\"dojox.grid.DataGrid\" jsId=\"requestBlockAddMonthlyGrid\" sortInfo=1 "; |
| print "store=\"requestBlockAddMonthlyStore\" style=\"width: 330px; height: 120px;\">\n"; |
| print "<thead>\n"; |
| print "<tr>\n"; |
| print "<th field=\"start\" width=\"102px\" formatter=\"gridTimePrimary\">"; |
| print i("Start") . "</th>\n"; |
| print "<th field=\"end\" width=\"102px\" formatter=\"timeFromTextBox\">"; |
| print i("End") . "</th>\n"; |
| print "<th field=\"remove\" width=\"80px\">" . i("Remove") . "</th>\n"; |
| print "</tr>\n"; |
| print "</thead>\n"; |
| print "</table>\n"; |
| print "</div>\n"; # repeating monthly |
| |
| # list of times |
| print "<div id=\"listtab\" dojoType=\"dijit.layout.ContentPane\" "; |
| print "title=\"" . i("List of Times") . "\" {$data['type2']['list']}>\n"; |
| print i("Date") . ":<div type=\"text\" id=\"listadddate\" dojoType=\"dijit.form.DateTextBox\" "; |
| print "required=\"true\" onChange=\"blockFormListAddBtnCheck\" style=\"width: 95px\"></div>\n"; |
| print "<small>(" . date('T') . ")</small>\n"; |
| print " | "; |
| print i("Start") . ":<input type=\"text\" id=\"listaddstart\" dojoType=\"dijit.form.TimeTextBox\" "; |
| print "required=\"true\" onChange=\"blockFormListAddBtnCheck\" />\n"; |
| print "<small>(" . date('T') . ")</small>\n"; |
| print " | "; |
| print i("End") . ":<input type=\"text\" id=\"listaddend\" dojoType=\"vcldojo.TimeTextBoxEnd\" "; |
| print "required=\"true\" onChange=\"blockFormListAddBtnCheck\" startid=\"listaddstart\" />\n"; |
| print "<small>(" . date('T') . ")</small>\n"; |
| print "<button dojoType=\"dijit.form.Button\" type=\"button\" disabled=\"true\" "; |
| print "id=\"requestBlockListAddBtn\">\n"; |
| print i("Add") . "\n"; |
| print " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| print " blockFormAddListSlot();\n"; |
| print " </script>\n"; |
| print "</button>\n"; |
| print "<img src=\"images/helpicon.png\" id=\"listhelp\" />\n"; |
| print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"requestBlockAddListStore\" "; |
| print "data=\"blockFormAddListData\"></div>\n"; |
| print "<div>\n"; # grid wrapper |
| print "<table dojoType=\"dojox.grid.DataGrid\" jsId=\"requestBlockAddListGrid\" sortInfo=1 "; |
| print "store=\"requestBlockAddListStore\" style=\"width: 465px; height: 200px;\">\n"; |
| print "<thead>\n"; |
| print "<tr>\n"; |
| print "<th field=\"date1\" width=\"115px\" formatter=\"gridDateTimePrimary\">"; |
| print i("Date") . "</th>\n"; |
| print "<th field=\"start\" width=\"115px\" formatter=\"timeFromTextBox\">"; |
| print i("Start") . "</th>\n"; |
| print "<th field=\"end\" width=\"108px\" formatter=\"timeFromTextBox\">"; |
| print i("End") . "</th>\n"; |
| print "<th field=\"remove\" width=\"80px\">" . i("Remove") . "</th>\n"; |
| print "</tr>\n"; |
| print "</thead>\n"; |
| print "</table>\n"; |
| print "</div>\n"; # grid wrapper |
| print "</div>\n"; # list of times |
| |
| print "</div>\n"; # tabcontainer |
| print "</div><br>\n"; |
| |
| if($mode == 'requestBlockAllocation') { |
| print "<strong><big>" . i("Additional comments") . ":</big></strong>\n"; |
| print "<img src=\"images/helpicon.png\" id=\"commenthelp\" /><br>\n"; |
| print "<textarea id=\"comments\" dojoType=\"dijit.form.Textarea\" style=\"width: 400px;\">\n"; |
| print "</textarea><br><br>\n"; |
| } |
| |
| print "<button dojoType=\"dijit.form.Button\" type=\"button\" "; |
| print "id=\"requestBlockSubmitBtn\">\n"; |
| if($mode == 'requestBlockAllocation') { |
| $btntxt = i("Submit Block Allocation Request") . "\n"; |
| $arg = 'request'; |
| } |
| elseif($mode == 'newBlockAllocation') { |
| $btntxt = i("Submit New Block Allocation") . "\n"; |
| $arg = 'new'; |
| } |
| elseif($mode == 'editBlockAllocation') { |
| $btntxt = i("Submit Block Allocation Changes") . "\n"; |
| $arg = 'edit'; |
| } |
| print " $btntxt\n"; |
| print " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| print " blockFormConfirm('$arg');\n"; |
| print " </script>\n"; |
| print "</button>\n"; |
| $cont = addContinuationsEntry('AJvalidateUserid'); |
| print "<input type=\"hidden\" id=\"valuseridcont\" value=\"$cont\">\n"; |
| |
| print "<div id=\"confirmDialog\" dojoType=\"dijit.Dialog\" title=\""; |
| print i("Confirm Block Allocation") . "\">\n"; |
| print "<h2>" . i("Confirm Block Allocation") . "</h2>\n"; |
| if($mode == 'requestBlockAllocation') |
| print i("Please confirm the following values and then click <strong>Submit Block Allocation Request</strong>"); |
| else { |
| printf(i("Please confirm the following values and then click <strong>%s</strong>"), $btntxt); |
| } |
| print "<br><br>\n<table summary=\"\">\n"; |
| print " <tr>\n"; |
| print " <th align=\"right\"><span id=\"confnametitle\"></span></th>\n"; |
| print " <td><span id=\"confname\"></span></td>\n"; |
| print " </tr>\n"; |
| print " <tr>\n"; |
| print " <th align=\"right\"><span id=\"confownertitle\"></span></th>\n"; |
| print " <td><span id=\"confowner\"></span></td>\n"; |
| print " </tr>\n"; |
| print " <tr>\n"; |
| print " <th align=\"right\">" . i("Environment") . ":</th>\n"; |
| print " <td><span id=\"confimage\"></span></td>\n"; |
| print " </tr>\n"; |
| print " <tr>\n"; |
| print " <th align=\"right\">" . i("User group") . ":</th>\n"; |
| print " <td><span id=\"confgroup\"></span></td>\n"; |
| print " </tr>\n"; |
| print " <tr>\n"; |
| print " <th align=\"right\">" . i("Seats") . ":</th>\n"; |
| print " <td><span id=\"confseats\"></span></td>\n"; |
| print " </tr>\n"; |
| print " <tr>\n"; |
| print " <th align=\"right\">" . i("Repeating") . ":</th>\n"; |
| print " <td><span id=\"confrepeat\"></span></td>\n"; |
| print " </tr>\n"; |
| print " <tr valign=\"top\">\n"; |
| print " <th align=\"right\"><span id=\"conftitle1\"></span></th>\n"; |
| print " <td><span id=\"confvalue1\"></span></td>\n"; |
| print " </tr>\n"; |
| print " <tr valign=\"top\">\n"; |
| print " <th align=\"right\"><span id=\"conftitle2\"></span></th>\n"; |
| print " <td><span id=\"confvalue2\"></span></td>\n"; |
| print " </tr>\n"; |
| print " <tr valign=\"top\">\n"; |
| print " <th align=\"right\"><span id=\"conftitle3\"></span></th>\n"; |
| print " <td><span id=\"confvalue3\"></span></td>\n"; |
| print " </tr>\n"; |
| print " <tr valign=\"top\">\n"; |
| print " <th align=\"right\"><span id=\"conftitle4\"></span></th>\n"; |
| print " <td><span id=\"confvalue4\"></span></td>\n"; |
| print " </tr>\n"; |
| print "</table>\n"; |
| print "<span id=\"commentsnote\" class=\"hidden\">" . i("Your additional comments will be submitted.") . "<br><br></span>\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 "<input type=\"hidden\" id=\"submitcont\" value=\"$cont\">\n"; |
| print "<input type=\"hidden\" id=\"submitcont2\">\n"; |
| print "<button dojoType=\"dijit.form.Button\" type=\"button\">\n"; |
| print " $btntxt\n"; |
| print " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| print " blockFormSubmit('$arg');\n"; |
| print " </script>\n"; |
| print "</button>\n"; |
| print "<button dojoType=\"dijit.form.Button\" type=\"button\">\n"; |
| print i("Cancel") . "\n"; |
| print " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| print " clearHideConfirmForm();\n"; |
| print " </script>\n"; |
| print "</button>\n"; |
| print "</div>\n"; # confirm dialog |
| |
| # tooltips |
| print "<div dojoType=\"dijit.Tooltip\" connectId=\"seathelp\">\n"; |
| print "<div style=\"width: 440px;\">\n"; |
| print i("This is the number of environments that will be loaded for the Block Allocation."); |
| print "</div></div>\n"; |
| |
| print "<div dojoType=\"dijit.Tooltip\" connectId=\"grouphelp\">\n"; |
| print "<div style=\"width: 440px;\">\n"; |
| print i("Users 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 \"<font color=\"blue\">(group not listed)</font>\" and describe the group you need in the <strong>Additional Comments</strong> section at the bottom of the page. If this is for a class, make sure to list the course and section number."); |
| print "</div></div>\n"; |
| |
| print "<div dojoType=\"dijit.Tooltip\" connectId=\"repeattypehelp\">\n"; |
| print "<div style=\"width: 440px;\">\n"; |
| print i("For repeating block allocations, there are three ways you can enter the dates and times:") . "<br>\n"; |
| print "<ul>\n"; |
| print "<li>" . i("Repeating Weekly - Use this if the block allocation needs to occur every week.") . " "; |
| print i("You can make it repeat on a single day each week or on multiple days. The time(s) that it occurs will be the same on all days. You can list as many times as needed.") . "</li>\n"; |
| print "<li>" . i("Repeating Monthly - Use this if the block allocation needs to occur on a certain day of the month (i.e. 2nd Tuesday each month). You can list as many times as needed for that day of the month.") . "</li>\n"; |
| print "<li>" . i("List of Dates/Times - Use this to specify any other cases, including single events.") . " "; |
| print i("You can specify as many date/time combinations as needed.") . "</li>\n"; |
| print "</ul>\n"; |
| print "</div></div>\n"; |
| |
| print "<div dojoType=\"dijit.Tooltip\" connectId=\"wkfdhelp\">\n"; |
| print i("This is the first date the block allocation will be used.\n"); |
| print "</div>\n"; |
| |
| print "<div dojoType=\"dijit.Tooltip\" connectId=\"wkldhelp\">\n"; |
| print i("This is the last date the block allocation will be used.\n"); |
| print "</div>\n"; |
| |
| print "<div dojoType=\"dijit.Tooltip\" connectId=\"wkdayshelp\">\n"; |
| print "<div style=\"width: 340px;\">\n"; |
| print i("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."); |
| print "</div></div>\n"; |
| |
| print "<div dojoType=\"dijit.Tooltip\" connectId=\"wktimeshelp\">\n"; |
| print "<div style=\"width: 340px;\">\n"; |
| print i("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."); |
| print "</div></div>\n"; |
| |
| print "<div dojoType=\"dijit.Tooltip\" connectId=\"mnfdhelp\">\n"; |
| print i("This is the first date the block allocation will be used.\n"); |
| print "</div>\n"; |
| |
| print "<div dojoType=\"dijit.Tooltip\" connectId=\"mnldhelp\">\n"; |
| print i("This is the last date the block allocation will be used.\n"); |
| print "</div>\n"; |
| |
| print "<div dojoType=\"dijit.Tooltip\" connectId=\"mntimeshelp\">\n"; |
| print "<div style=\"width: 340px;\">\n"; |
| print i("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."); |
| print "</div></div>\n"; |
| |
| print "<div dojoType=\"dijit.Tooltip\" connectId=\"listhelp\">\n"; |
| print "<div style=\"width: 300px;\">\n"; |
| print i("Specify individual dates and times during which the block allocation will occur."); |
| print "</div></div>\n"; |
| |
| print "<div dojoType=\"dijit.Tooltip\" connectId=\"commenthelp\">\n"; |
| print "<div style=\"width: 340px;\">\n"; |
| print i("Enter any additional information about this block allocation. < and > are not allowed. If you selected \"<font color=\"blue\">(group not listed)</font>\" as the User group, make sure to clearly describe the requirements of a new user group that will be created for this block allocation."); |
| print "</div></div>\n"; |
| } |
| |
| //////////////////////////////////////////////////////////////////////////////// |
| /// |
| /// \fn AJblockAllocationSubmit() |
| /// |
| /// \brief ajax function to process the form displayed by blockAllocationForm |
| /// |
| //////////////////////////////////////////////////////////////////////////////// |
| function AJblockAllocationSubmit() { |
| global $user; |
| $data = processBlockAllocationInput(); |
| if($data['err']) |
| return; |
| $method = getContinuationVar('method'); |
| |
| if($method == 'new') { |
| $managementnodes = getManagementNodes('future'); |
| if(empty($managementnodes)) { |
| print "alert('" . i("Error encountered while trying to create block allocation:") . "\\n"; |
| print i("No active management nodes were found. Please try 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 = vcl_mysql_escape_string($data['name']); |
| $query = "INSERT INTO blockRequest " |
| . "(name, " |
| . "imageid, " |
| . "numMachines, " |
| . "groupid, " |
| . "repeating, " |
| . "ownerid, " |
| . "managementnodeid, " |
| . "expireTime, " |
| . "status) " |
| . "VALUES " |
| . "('$escname', " |
| . "{$data['imageid']}, " |
| . "{$data['seats']}, " |
| . "{$data['groupid']}, " |
| . "'{$data['type']}', " |
| . "{$data['ownerid']}, " |
| . "$mnid, " |
| . "'{$data['expiretime']}', " |
| . "'accepted')"; |
| doQuery($query, 101); |
| $blockreqid = dbLastInsertID(); |
| } |
| elseif($method == 'edit') { |
| $blockreqid = getContinuationVar('blockid'); |
| # FIXME need to handle creation of a block time that we're currently in the |
| # middle of if there wasn't already one we're in the middle of |
| # get blockTime entry for this allocation if we're in the middle of one |
| $checkCurBlockTime = 0; |
| $query = "SELECT id, " |
| . "start, " |
| . "end " |
| . "FROM blockTimes " |
| . "WHERE start <= NOW() AND " |
| . "end > NOW() AND " |
| . "blockRequestid = $blockreqid"; |
| $qh = doQuery($query, 101); |
| if($row = mysqli_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 = vcl_mysql_escape_string($data['name']); |
| $query = "UPDATE blockRequest " |
| . "SET name = '$escname', " |
| . "imageid = {$data['imageid']}, " |
| . "numMachines = {$data['seats']}, " |
| . "groupid = {$data['groupid']}, " |
| . "ownerid = {$data['ownerid']}, " |
| . "repeating = '{$data['type']}', " |
| . "expireTime = '{$data['expiretime']}' " |
| . "WHERE id = $blockreqid"; |
| doQuery($query, 101); |
| } |
| elseif($method == 'request') { |
| $esccomments = vcl_mysql_escape_string($data['comments']); |
| $query = "INSERT INTO blockRequest " |
| . "(name, " |
| . "imageid, " |
| . "numMachines, " |
| . "groupid, " |
| . "repeating, " |
| . "ownerid, " |
| . "expireTime, " |
| . "status, " |
| . "comments) " |
| . "VALUES " |
| . "('(" . i("awaiting approval") . ")', " |
| . "{$data['imageid']}, " |
| . "{$data['seats']}, " |
| . "{$data['groupid']}, " |
| . "'{$data['type']}', " |
| . "{$user['id']}, " |
| . "'{$data['expiretime']}', " |
| . "'requested', " |
| . "'$esccomments')"; |
| doQuery($query, 101); |
| $blockreqid = dbLastInsertID(); |
| |
| # send email notifying about a new block allocation request |
| $imagedata = getImages(0, $data['imageid']); |
| if($data['groupid'] == 0) |
| $grpname = "(Unspecified)"; |
| else |
| $grpname = getUserGroupName($data['groupid']); |
| if(! empty($data['comments'])) |
| $comments = "Comments:\n{$data['comments']}\n"; |
| else |
| $comments = ''; |
| $message = "A new block allocation request has been submitted by "; |
| if(! empty($user['firstname']) && ! empty($user['lastname']) && ! empty($user['email'])) |
| $message .= "{$user['firstname']} {$user['lastname']} ({$user['email']}). "; |
| elseif(! empty($user['email'])) |
| $message .= "{$user['email']}. "; |
| else |
| $message .= "{$user['unityid']}. "; |
| $message .= "Please visit the following URL to accept or reject it:\n\n" |
| . BASEURL . SCRIPT . "?mode=blockAllocations\n\n" |
| . "Image: {$imagedata[$data['imageid']]['prettyname']}\n" |
| . "Seats: {$data['seats']}\n" |
| . "User Group: $grpname\n$comments\n\n" |
| . "This is an automated message sent by VCL.\n" |
| . "You are receiving this message because you have access " |
| . "to create and approve block allocations."; |
| $mailParams = "-f" . ENVELOPESENDER; |
| $blockNotifyUsers = getBlockNotifyUsers($user['affiliationid']); |
| mail($blockNotifyUsers, "VCL Block Allocation Request ({$user['unityid']})", $message, '', $mailParams); |
| } |
| |
| if($data['type'] == 'weekly') { |
| $query = "INSERT INTO blockWebDate " |
| . "(blockRequestid, " |
| . "start, " |
| . "end, " |
| . "days) " |
| . "VALUES " |
| . "($blockreqid, " |
| . "'{$data['startdate']}', " |
| . "'{$data['enddate']}', " |
| . "{$data['daymask']})"; |
| doQuery($query, 101); |
| $today = mktime(0, 0, 0); |
| if($method == 'edit' && $data['startts'] < $today) |
| createWeeklyBlockTimes($blockreqid, $today, $data['endts'], $data['daymask'], $data['times']); |
| elseif($method == 'new' || $method == 'edit') |
| createWeeklyBlockTimes($blockreqid, $data['startts'], $data['endts'], $data['daymask'], $data['times']); |
| } |
| elseif($data['type'] == 'monthly') { |
| $query = "INSERT INTO blockWebDate " |
| . "(blockRequestid, " |
| . "start, " |
| . "end, " |
| . "days, " |
| . "weeknum) " |
| . "VALUES " |
| . "($blockreqid, " |
| . "'{$data['startdate']}', " |
| . "'{$data['enddate']}', " |
| . "{$data['day']}, " |
| . "{$data['weeknum']})"; |
| doQuery($query, 101); |
| $today = mktime(0, 0, 0); |
| if($method == 'edit' && $data['startts'] < $today) |
| createMonthlyBlockTimes($blockreqid, $today, $data['endts'], $data['day'], $data['weeknum'], $data['times']); |
| elseif($method == 'new' || $method == 'edit') |
| createMonthlyBlockTimes($blockreqid, $data['startts'], $data['endts'], $data['day'], $data['weeknum'], $data['times']); |
| } |
| if($data['type'] == 'weekly' || $data['type'] == 'monthly') { |
| $vals = array(); |
| $i = 0; |
| foreach($data['times'] as $time) { |
| $tmp = explode('|', $time); |
| $start = explode(':', $tmp[0]); |
| $startmin = $start[1]; |
| list($starth, $startm) = hour24to12($start[0]); |
| $end = explode(':', $tmp[1]); |
| $endmin = $end[1]; |
| list($endh, $endm) = hour24to12($end[0]); |
| $vals[] = "($blockreqid, " |
| . "'$starth', " |
| . "'$startmin', " |
| . "'$startm', " |
| . "'$endh', " |
| . "'$endmin', " |
| . "'$endm', " |
| . "$i)"; |
| $i++; |
| } |
| $allvals = implode(',', $vals); |
| $query = "INSERT INTO blockWebTime " |
| . "(blockRequestid, " |
| . "starthour, " |
| . "startminute, " |
| . "startmeridian, " |
| . "endhour, " |
| . "endminute, " |
| . "endmeridian, " |
| . "`order`) " |
| . "VALUES $allvals"; |
| doQuery($query, 101); |
| } |
| if($data['type'] == 'list') |
| createListBlockData($blockreqid, $data['slots'], $method); |
| if($method == 'edit' && $checkCurBlockTime) { |
| $query = "SELECT id, " |
| . "start, " |
| . "end " |
| . "FROM blockTimes " |
| . "WHERE start <= NOW() AND " |
| . "end > NOW() AND " |
| . "blockRequestid = $blockreqid AND " |
| . "id != {$curBlockTime['id']}"; |
| $qh = doQuery($query, 101); |
| if($row = mysqli_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 = "<h2>" . i("Request New Block Allocation") . "</h2>"; |
| $txt .= i("Your request for a Block Allocation has been submitted for approval.") . " "; |
| if(! empty($user['email'])) { |
| $txt .= i("You should be notified within a few business days of its acceptance or rejection."); |
| } |
| else { |
| $txt .= "<br><br><font color=\"red\"><strong>" . i("Note:") . "</strong> "; |
| $h = " " . i("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."); |
| $txt .= preg_replace("/(.{1,50}([ \n]|$))/", '\1<br>', $h) . "</font>"; |
| } |
| print "dojo.byId('content').innerHTML = '$txt';"; |
| print "scroll(0, 0);"; |
| return; |
| } |
| print "window.location.href = '" . BASEURL . SCRIPT . "?mode=blockAllocations';"; |
| } |
| |
| //////////////////////////////////////////////////////////////////////////////// |
| /// |
| /// \fn createWeeklyBlockTimes($blockid, $startts, $endts, $daymask, $times) |
| /// |
| /// \param $blockid - id of block allocation |
| /// \param $startts - unix timestamp for starting time |
| /// \param $endts - unix timestamp for ending time |
| /// \param $daymask - bitmask int of selected days |
| /// \param $times - array of times in HH:MM|HH:MM (start|end) format |
| /// |
| /// \brief creates entries in the blockTimes table for a weekly repeating block |
| /// allocation |
| /// |
| //////////////////////////////////////////////////////////////////////////////// |
| function createWeeklyBlockTimes($blockid, $startts, $endts, $daymask, $times) { |
| $vals = array(); |
| $startts += 3600; # This is a simple way to deal with DST; without it. We end |
| # up starting at midnight. When we go through the day DST |
| # ends, += SECINDAY only gets us to 11pm instead of the |
| # next day. Adding an hour to start with starts us at 1am |
| # and += SECINDAY gets us to midnight the next day. |
| $endts += 7200; # Conversely, we pass $endts too soon when DST starts; so |
| # we add 2 hours to it to make sure we don't pass it. |
| for($day = $startts; $day <= $endts; $day += SECINDAY) { |
| if(! ((1 << date('w', $day)) & $daymask)) |
| continue; |
| foreach($times as $time) { |
| $tmp = explode('|', $time); |
| $start = date("Y-m-d", $day) . " {$tmp[0]}:00"; |
| $end = date("Y-m-d", $day) . " {$tmp[1]}:00"; |
| $vals[] = "($blockid, " |
| . "'$start', " |
| . "'$end')"; |
| } |
| } |
| $allvals = implode(',', $vals); |
| $query = "INSERT INTO blockTimes " |
| . "(blockRequestid, " |
| . "start, " |
| . "end) " |
| . "VALUES $allvals"; |
| doQuery($query, 101); |
| deleteBlockSkipDuplicates($blockid); |
| } |
| |
| //////////////////////////////////////////////////////////////////////////////// |
| /// |
| /// \fn createMonthlyBlockTimes($blockid, $startts, $endts, $dayweek, $weeknum, |
| /// $times) |
| /// |
| /// \param $blockid - id of block allocation |
| /// \param $startts - unix timestamp for starting time |
| /// \param $endts - unix timestamp for ending time |
| /// \param $dayweek - day of the week (1 to 7) |
| /// \param $weeknum - week of the month (1 to 5) |
| /// \param $times - array of times in HH:MM|HH:MM (start|end) format |
| /// |
| /// \brief creates entries in the blockTimes table for a monthly repeating block |
| /// allocation |
| /// |
| //////////////////////////////////////////////////////////////////////////////// |
| function createMonthlyBlockTimes($blockid, $startts, $endts, $dayweek, $weeknum, |
| $times) { |
| $vals = getMonthlyBlockTimes($blockid, $startts, $endts, $dayweek, $weeknum, |
| $times); |
| $allvals = implode(',', $vals); |
| $query = "INSERT INTO blockTimes " |
| . "(blockRequestid, " |
| . "start, " |
| . "end) " |
| . "VALUES $allvals"; |
| doQuery($query, 101); |
| deleteBlockSkipDuplicates($blockid); |
| } |
| |
| //////////////////////////////////////////////////////////////////////////////// |
| /// |
| /// \fn getMonthlyBlockTimes($blockid, $startts, $endts, $dayweek, $weeknum, |
| /// $times) |
| /// |
| /// \param $blockid - id of block allocation |
| /// \param $startts - unix timestamp for starting time |
| /// \param $endts - unix timestamp for ending time |
| /// \param $dayweek - day of the week (1 to 7) |
| /// \param $weeknum - week of the month (1 to 5) |
| /// \param $times - array of times in HH:MM|HH:MM (start|end) format |
| /// |
| /// \brief generates query values for creating entries in the blockTimes table |
| /// for a monthly repeating block allocation |
| /// |
| //////////////////////////////////////////////////////////////////////////////// |
| function getMonthlyBlockTimes($blockid, $startts, $endts, $dayweek, $weeknum, |
| $times) { |
| $vals = array(); |
| $startts += 3600; # This is a simple way to deal with DST; without it. We end |
| # up starting at midnight. When we go through the day DST |
| # ends, += SECINDAY only gets us to 11pm instead of the |
| # next day. Adding an hour to start with starts us at 1am |
| # and += SECINDAY gets us to midnight the next day. |
| $endts += 7200; # Conversely, we pass $endts too soon when DST starts; so |
| # we add 2 hours to it to make sure we don't pass it. |
| for($day = $startts; $day <= $endts; $day += SECINDAY) { |
| if((date('w', $day) + 1) != $dayweek) |
| continue; |
| $dayofmon = date('j', $day); |
| if(($weeknum == 1 && ($dayofmon < 8)) || |
| ($weeknum == 2 && (7 < $dayofmon) && ($dayofmon < 15)) || |
| ($weeknum == 3 && (14 < $dayofmon) && ($dayofmon < 22)) || |
| ($weeknum == 4 && (21 < $dayofmon) && ($dayofmon < 29)) || |
| ($weeknum == 5 && (28 < $dayofmon) && ($dayofmon < 32))) { |
| $thedate = date("Y-m-d", $day); |
| foreach($times as $time) { |
| $tmp = explode('|', $time); |
| $start = "$thedate {$tmp[0]}:00"; |
| $end = "$thedate {$tmp[1]}:00"; |
| $vals[] = "($blockid, " |
| . "'$start', " |
| . "'$end')"; |
| } |
| } |
| } |
| return $vals; |
| } |
| |
| //////////////////////////////////////////////////////////////////////////////// |
| /// |
| /// \fn createListBlockData($blockid, $slots, $method) |
| /// |
| /// \param $blockid - id of block allocation |
| /// \param $slots - array of date/time slots in 'YYYY-MM-DD|HH:MM|HH:MM' format |
| /// (date|start|end) |
| /// \param $method - new, edit, or accept |
| /// |
| /// \brief creates entries in the blockTimes table for a list type block |
| /// allocation |
| /// |
| //////////////////////////////////////////////////////////////////////////////// |
| function createListBlockData($blockid, $slots, $method) { |
| $dvals = array(); |
| $tvals = array(); |
| if($method == 'new' || $method == 'edit') |
| $btvals = array(); |
| $i = 0; |
| foreach($slots as $slot) { |
| $tmp = explode('|', $slot); |
| $date = $tmp[0]; |
| if($method == 'new' || $method == 'edit' || $method == 'accept') { |
| $sdatets = strtotime("$date {$tmp[1]}:00"); |
| $sdatedt = unixToDatetime($sdatets); |
| $edatets = strtotime("$date {$tmp[2]}:00"); |
| $edatedt = unixToDatetime($edatets); |
| if($method != 'edit' || $edatets >= time()) { |
| $btvals[] = "($blockid, " |
| . "'$sdatedt', " |
| . "'$edatedt')"; |
| } |
| } |
| if($method != 'accept') { |
| $start = explode(':', $tmp[1]); |
| $startmin = $start[1]; |
| list($starth, $startm) = hour24to12($start[0]); |
| $end = explode(':', $tmp[2]); |
| $endmin = $end[1]; |
| list($endh, $endm) = hour24to12($end[0]); |
| $dvals[] = "($blockid, " |
| . "'$date', " |
| . "'$date', " |
| . "$i)"; |
| $tvals[] = "($blockid, " |
| . "'$starth', " |
| . "'$startmin', " |
| . "'$startm', " |
| . "'$endh', " |
| . "'$endmin', " |
| . "'$endm', " |
| . "$i)"; |
| $i++; |
| } |
| } |
| if($method != 'accept') { |
| $alldvals = implode(',', $dvals); |
| $query = "INSERT INTO blockWebDate " |
| . "(blockRequestid, " |
| . "start, " |
| . "end, " |
| . "days) " |
| . "VALUES $alldvals"; |
| doQuery($query, 101); |
| $alltvals = implode(',', $tvals); |
| $query = "INSERT INTO blockWebTime " |
| . "(blockRequestid, " |
| . "starthour, " |
| . "startminute, " |
| . "startmeridian, " |
| . "endhour, " |
| . "endminute, " |
| . "endmeridian, " |
| . "`order`) " |
| . "VALUES $alltvals"; |
| doQuery($query, 101); |
| } |
| if($method == 'new' || $method == 'edit' || $method == 'accept') { |
| $allbtvals = implode(',', $btvals); |
| $query = "INSERT INTO blockTimes " |
| . "(blockRequestid, " |
| . "start, " |
| . "end) " |
| . "VALUES $allbtvals"; |
| doQuery($query, 101); |
| deleteBlockSkipDuplicates($blockid); |
| } |
| } |
| |
| //////////////////////////////////////////////////////////////////////////////// |
| /// |
| /// \fn getBlockNotifyUsers($affiliationid) |
| /// |
| /// \param $affiliationid - an affiliation id |
| /// |
| /// \return string of comma delimited email addresses |
| /// |
| /// \brief gets email addresses for all users that should be notified about a |
| /// block allocation |
| /// |
| //////////////////////////////////////////////////////////////////////////////// |
| function getBlockNotifyUsers($affiliationid) { |
| $query = "SELECT DISTINCT(u.email) " |
| . "FROM user u, " |
| . "usergroupmembers ugm, " |
| . "usergroup ug, " |
| . "usergrouppriv ugp, " |
| . "usergroupprivtype ugpt " |
| . "WHERE ((ugpt.name = 'Manage Block Allocations (global)' AND " |
| . "ugp.userprivtypeid = ugpt.id AND " |
| . "ugp.usergroupid = ugm.usergroupid AND " |
| . "ugp.usergroupid = ug.id AND " |
| . "ugm.userid = u.id) OR " |
| . "(ugpt.name = 'Manage Block Allocations (affiliation only)' AND " |
| . "ugp.userprivtypeid = ugpt.id AND " |
| . "ugp.usergroupid = ugm.usergroupid AND " |
| . "ugm.userid = u.id AND " |
| . "ugp.usergroupid = ug.id AND " |
| . "ug.affiliationid = $affiliationid)) AND " |
| . "u.email != ''"; |
| $qh = doQuery($query); |
| $addrs = array(); |
| while($row = mysqli_fetch_assoc($qh)) |
| $addrs[] = $row['email']; |
| return implode(',', $addrs); |
| } |
| |
| //////////////////////////////////////////////////////////////////////////////// |
| /// |
| /// \fn deleteBlockSkipDuplicates($blockid) |
| /// |
| /// \param $blockid - id of a block allocation |
| /// |
| /// \brief deletes any block times without skip set for which there is a |
| /// matching block time with skip set; deletes any with skip set where there is |
| /// not a matching time without skip set |
| /// |
| //////////////////////////////////////////////////////////////////////////////// |
| function deleteBlockSkipDuplicates($blockid) { |
| $query = "SELECT id, " |
| . "start, " |
| . "end, " |
| . "skip " |
| . "FROM blockTimes " |
| . "WHERE blockRequestid = $blockid"; |
| $qh = doQuery($query, 101); |
| $skips = array(); |
| $noskips = array(); |
| while($row = mysqli_fetch_assoc($qh)) { |
| $key = "{$row['start']}:{$row['end']}"; |
| if($row['skip']) |
| $skips[$key] = $row['id']; |
| else |
| $noskips[$key] = $row['id']; |
| } |
| $deleteids = array(); |
| foreach($skips as $key => $id) { |
| if(array_key_exists($key, $noskips)) |
| $deleteids[] = $noskips[$key]; |
| else |
| $deleteids[] = $id; |
| } |
| if(empty($deleteids)) |
| return; |
| $inids = implode(',', $deleteids); |
| $query = "DELETE FROM blockTimes " |
| . "WHERE id IN ($inids)"; |
| doQuery($query, 101); |
| } |
| |
| //////////////////////////////////////////////////////////////////////////////// |
| /// |
| /// \fn getCurrentBlockHTML($listonly) |
| /// |
| /// \param $listonly (optional, default=0) - 0 to return everything, 1 to only |
| /// return the table of block allocations (i.e. don't include the delete dialog) |
| /// |
| /// \return HTML to display current block allocations |
| /// |
| /// \brief generates the HTML to display a list of the current block allocations |
| /// and a dojo dialog for deleting them |
| /// |
| //////////////////////////////////////////////////////////////////////////////// |
| function getCurrentBlockHTML($listonly=0) { |
| global $user, $days; |
| $groupids = implode(',', array_keys($user['groups'])); |
| $query = "SELECT b.id, " |
| . "b.name AS blockname, " |
| . "b.ownerid, " |
| . "CONCAT(u.unityid, '@', ua.name) AS owner, " |
| . "b.imageid, " |
| . "i.prettyname AS image, " |
| . "b.numMachines AS machinecnt, " |
| . "b.groupid as usergroupid, " |
| . "CONCAT(g.name, '@', a.name) AS `group`, " |
| . "b.repeating AS available " |
| . "FROM image i, " |
| . "blockRequest b " |
| . "LEFT JOIN usergroup g ON (b.groupid = g.id) " |
| . "LEFT JOIN affiliation a ON (g.affiliationid = a.id) " |
| . "LEFT JOIN user u ON (b.ownerid = u.id) " |
| . "LEFT JOIN affiliation ua ON (u.affiliationid = ua.id) " |
| . "WHERE b.imageid = i.id AND "; |
| if(! checkUserHasPerm('Manage Block Allocations (global)') && |
| checkUserHasPerm('Manage Block Allocations (affiliation only)')) |
| $query .= "u.affiliationid = {$user['affiliationid']} AND "; |
| $query .= "b.status = 'accepted' " |
| . "ORDER BY b.name"; |
| $allblockids = array(); |
| $blocks = array(); |
| $qh = doQuery($query, 101); |
| while($row = mysqli_fetch_assoc($qh)) { |
| if($row['group'] == '') { |
| $query3 = "SELECT name FROM usergroup WHERE id = {$row['usergroupid']}"; |
| $qh3 = doQuery($query3, 101); |
| if($row3 = mysqli_fetch_assoc($qh3)) |
| $row['group'] = $row3['name']; |
| } |
| $allblockids[] = $row['id']; |
| $blocks[$row['id']] = $row; |
| $query2 = "SELECT DATE_FORMAT(start, '%c/%e/%y<br>%l:%i %p') AS start1, " |
| . "UNIX_TIMESTAMP(start) AS unixstart, " |
| . "UNIX_TIMESTAMP(end) AS unixend " |
| . "FROM blockTimes " |
| . "WHERE blockRequestid = {$row['id']} AND " |
| . "end > NOW() AND " |
| . "skip = 0 " |
| . "ORDER BY start " |
| . "LIMIT 1"; |
| $qh2 = doQuery($query2, 101); |
| if($row2 = mysqli_fetch_assoc($qh2)) { |
| if(array_key_exists('tzoffset', $_SESSION['persistdata'])) { |
| $tmp = date('n/j/y+g:i=A=T', $row2['unixstart']); |
| $blocks[$row['id']]['nextstart'] = str_replace(array('+', '='), array('<br>', ' '), $tmp); |
| } |
| else |
| $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'] = i("none found"); |
| $blocks[$row['id']]['nextstartactive'] = 0; |
| } |
| } |
| 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 = mysqli_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 = mysqli_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 = mysqli_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 = mysqli_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 = mysqli_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 = mysqli_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 .= "<input type=\"hidden\" id=\"timezone\" value=\"" . date('T') . "\">\n"; |
| if(empty($blocks)) |
| $rt .= "There are currently no block allocations.\n"; |
| else { |
| $rt .= "<table summary=\"lists current block allocations\">\n"; |
| $rt .= " <TR align=center>\n"; |
| $rt .= " <TD colspan=3></TD>\n"; |
| $rt .= " <TH>" . i("Name") . "</TH>\n"; |
| $rt .= " <TH>" . i("Environment") . "</TH>\n"; |
| $rt .= " <TH>" . i("Reserved<br>Machines") . "</TH>\n"; |
| $rt .= " <TH>" . i("Reserved<br>For") . "</TH>\n"; |
| $rt .= " <TH>" . i("Repeating") . "</TH>\n"; |
| $rt .= " <TH>" . i("Next Start Time") . "</TH>\n"; |
| $rt .= " </TR>\n"; |
| foreach($blocks as $block) { |
| $rt .= " <TR align=center>\n"; |
| $rt .= " <TD>\n"; |
| $rt .= " <button dojoType=\"dijit.form.Button\" type=\"button\">\n"; |
| $rt .= i( "Edit") . "\n"; |
| $rt .= " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| $cont = addContinuationsEntry('editBlockAllocation', array('blockid' => $block['id'])); |
| $rt .= " location.href = '" . BASEURL . SCRIPT . "?continuation=$cont';\n"; |
| $rt .= " </script>\n"; |
| $rt .= " </button>\n"; |
| $rt .= " </TD>\n"; |
| $rt .= " <TD>\n"; |
| $rt .= " <button dojoType=\"dijit.form.Button\" type=\"button\">\n"; |
| $rt .= i( "Delete") . "\n"; |
| $rt .= " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| $cont = addContinuationsEntry('AJdeleteBlockAllocationConfirm', $block, SECINDAY); |
| $rt .= " deleteBlockConfirm('$cont');\n"; |
| $rt .= " </script>\n"; |
| $rt .= " </button>\n"; |
| $rt .= " </TD>\n"; |
| $rt .= " <TD>\n"; |
| $rt .= " <button dojoType=\"dijit.form.Button\" type=\"button\">\n"; |
| $rt .= i( "View Times") . "\n"; |
| $rt .= " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| $cont = addContinuationsEntry('AJviewBlockAllocationTimes', array('blockid' => $block['id']), SECINDAY); |
| $rt .= " viewBlockTimes('$cont');\n"; |
| $rt .= " </script>\n"; |
| $rt .= " </button>\n"; |
| $rt .= " </TD>\n"; |
| $rt .= " <TD>{$block['blockname']}</TD>\n"; |
| $rt .= " <TD>{$block['image']}</TD>\n"; |
| $rt .= " <TD><a href=\"javascript:void(0)\" onclick=\"viewBlockUsage({$block['id']});\">{$block['machinecnt']}</a></TD>\n"; |
| $rt .= " <TD>{$block['group']}</TD>\n"; |
| $rt .= " <TD>" . i($block['available']) . "</TD>\n"; |
| if($block['nextstartactive']) { |
| $cont = addContinuationsEntry('viewBlockStatus', array('id' => $block['id'])); |
| $rt .= " <TD><a href=\"" . BASEURL . SCRIPT . "?continuation=$cont\">"; |
| $rt .= "{$block['nextstart']}</a></TD>\n"; |
| } |
| else |
| $rt .= " <TD>{$block['nextstart']}</TD>\n"; |
| $rt .= " </TR>\n"; |
| } |
| $rt .= "</table>\n"; |
| } |
| if($listonly) |
| return $rt; |
| |
| $rt .= "<div id=\"confirmDialog\" dojoType=\"dijit.Dialog\" "; |
| $rt .= "title=\"" . i("Confirm Delete Block Allocation") . "\">\n"; |
| $rt .= "<h2>" . i("Confirm Delete Block Allocation") . "</h2>\n"; |
| $h = i("Please confirm the following values and then click <strong>Delete Block Allocation</strong>"); |
| $rt .= preg_replace("/(.{1,50}([ \n]|$))/", '\1<br>', $h) . "<br>\n"; |
| $rt .= "<table summary=\"\">\n"; |
| $rt .= " <tr>\n"; |
| $rt .= " <th align=\"right\">" . i("Name:") . "</th>\n"; |
| $rt .= " <td><span id=\"confname\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr>\n"; |
| $rt .= " <th align=\"right\">" . i("Owner:") . "</th>\n"; |
| $rt .= " <td><span id=\"confowner\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr>\n"; |
| $rt .= " <th align=\"right\">" . i("Environment:") . "</th>\n"; |
| $rt .= " <td><span id=\"confimage\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr>\n"; |
| $rt .= " <th align=\"right\">" . i("User Group:") . "</th>\n"; |
| $rt .= " <td><span id=\"confgroup\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr>\n"; |
| $rt .= " <th align=\"right\">" . i("Seats:") . "</th>\n"; |
| $rt .= " <td><span id=\"confseats\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr>\n"; |
| $rt .= " <th align=\"right\">" . i("Repeating:") . "</th>\n"; |
| $rt .= " <td><span id=\"confrepeat\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr valign=\"top\">\n"; |
| $rt .= " <th align=\"right\"><span id=\"conftitle1\"></span></th>\n"; |
| $rt .= " <td><span id=\"confvalue1\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr valign=\"top\">\n"; |
| $rt .= " <th align=\"right\"><span id=\"conftitle2\"></span></th>\n"; |
| $rt .= " <td><span id=\"confvalue2\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr valign=\"top\">\n"; |
| $rt .= " <th align=\"right\"><span id=\"conftitle3\"></span></th>\n"; |
| $rt .= " <td><span id=\"confvalue3\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr valign=\"top\">\n"; |
| $rt .= " <th align=\"right\"><span id=\"conftitle4\"></span></th>\n"; |
| $rt .= " <td><span id=\"confvalue4\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= "</table>\n"; |
| $rt .= "<button dojoType=\"dijit.form.Button\" type=\"button\">\n"; |
| $rt .= i("Delete Block Allocation") . "\n"; |
| $rt .= " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| $rt .= " deleteBlockSubmit();\n"; |
| $rt .= " </script>\n"; |
| $rt .= "</button>\n"; |
| $rt .= "<button dojoType=\"dijit.form.Button\" type=\"button\">\n"; |
| $rt .= i("Cancel") . "\n"; |
| $rt .= " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| $rt .= " clearHideConfirmDelete();\n"; |
| $rt .= " </script>\n"; |
| $rt .= "</button>\n"; |
| $rt .= "<input type=hidden id=submitdeletecont>\n"; |
| $rt .= "</div>\n"; # confirm dialog |
| |
| $rt .= "<div id=\"viewtimesDialog\" dojoType=\"dijit.Dialog\" "; |
| $rt .= "title=\"" . i("Block Allocation Times") . "\">\n"; |
| $rt .= "<h2>" . i("Block Allocation Times") . "</h2>\n"; |
| $rt .= "<table dojoType=\"dojox.grid.DataGrid\" jsId=\"blockTimesGrid\" sortInfo=1 "; |
| $rt .= "style=\"width: 328px; height: 200px;\">\n"; |
| $rt .= "<script type=\"dojo/method\" event=\"onStyleRow\" args=\"row\">\n"; |
| $rt .= "blockTimeRowStyle(row);\n"; |
| $rt .= "</script>\n"; |
| $rt .= "<thead>\n"; |
| $rt .= "<tr>\n"; |
| $rt .= "<th field=\"start\" width=\"70px\" formatter=\"blockTimesGridDate\">" . i("Date") . "</th>\n"; |
| $rt .= "<th field=\"start\" width=\"85px\" formatter=\"blockTimesGridStart\">" . i("Start") . "</th>\n"; |
| $rt .= "<th field=\"end\" width=\"85px\" formatter=\"blockTimesGridEnd\">" . i("End") . "</th>\n"; |
| $rt .= "<th field=\"delbtn\" width=\"60px\">" . i("Skip") . "</th>\n"; |
| $rt .= "</tr>\n"; |
| $rt .= "</thead>\n"; |
| $rt .= "</table>\n"; |
| $rt .= "<div align=\"center\">\n"; |
| $rt .= "<button dojoType=\"dijit.form.Button\" type=\"button\">\n"; |
| $rt .= i("Close") . "\n"; |
| $rt .= " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| $rt .= " dijit.byId('viewtimesDialog').hide();\n"; |
| $rt .= " </script>\n"; |
| $rt .= "</button>\n"; |
| $rt .= "</div>\n"; |
| $rt .= "<input type=hidden id=toggletimecont>\n"; |
| $rt .= "</div>\n"; # times dialog |
| |
| $rt .= "<div id=\"viewUsageDialog\" dojoType=\"dijit.Dialog\" "; |
| $rt .= "title=\"" . i("Block Allocation Usage") . "\">\n"; |
| $rt .= "<div id=\"blockusagechartdiv\" class=\"hidden\"></div>\n"; |
| $rt .= "<div id=\"blockusageemptydiv\" class=\"hidden\">"; |
| $rt .= i("This block allocation has never been used.") . "</div>\n"; |
| $rt .= "<div align=\"center\">\n"; |
| $rt .= "<button dojoType=\"dijit.form.Button\" type=\"button\">\n"; |
| $rt .= i("Close") . "\n"; |
| $rt .= " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| $rt .= " dijit.byId('viewUsageDialog').hide();\n"; |
| $rt .= " </script>\n"; |
| $rt .= "</button>\n"; |
| $rt .= "</div>\n"; |
| $blockids = array_keys($blocks); |
| $cont = addContinuationsEntry('AJviewBlockAllocationUsage', array('blockids' => $blockids), SECINDAY); |
| $rt .= "<input type=hidden id=viewblockusagecont value=\"$cont\">\n"; |
| $rt .= "</div>\n"; # usage 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, " |
| . "blockRequest b " |
| . "LEFT JOIN user u ON (b.ownerid = u.id) " |
| . "LEFT JOIN affiliation ua ON (u.affiliationid = ua.id) " |
| . "LEFT JOIN usergroup g ON (b.groupid = g.id) " |
| . "LEFT JOIN affiliation a ON (g.affiliationid = a.id) " |
| . "WHERE b.ownerid = {$user['id']} AND " |
| . "b.imageid = i.id AND " |
| . "b.status IN ('accepted', 'requested') " |
| . "ORDER BY b.name"; |
| $qh = doQuery($query, 101); |
| $blocks = array(); |
| while($row = mysqli_fetch_assoc($qh)) |
| $blocks[$row['id']] = $row; |
| if(empty($blocks)) |
| return; |
| |
| foreach($blocks as $id => $request) { |
| if($blocks[$id]['group'] == '') |
| $blocks[$id]['group'] = i('(unspecified)'); |
| 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 = mysqli_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 = mysqli_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 = mysqli_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 = mysqli_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 = mysqli_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 = mysqli_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 .= "<h2>" . i("Manage Block Allocations") . "</h2>\n"; |
| $rt .= "<div id=\"blocklist\">\n"; |
| $rt .= "<table summary=\"lists current block allocations\">\n"; |
| $rt .= " <TR align=center>\n"; |
| $rt .= " <TD colspan=2></TD>\n"; |
| $rt .= " <TH>" . i("Name") . "</TH>\n"; |
| $rt .= " <TH>" . i("Environment") . "</TH>\n"; |
| $rt .= " <TH>" . i("Reserved<br>Machines") . "</TH>\n"; |
| $rt .= " <TH>" . i("Reserved<br>For") . "</TH>\n"; |
| $rt .= " <TH>" . i("Repeating") . "</TH>\n"; |
| $rt .= " </TR>\n"; |
| foreach($blocks as $block) { |
| $rt .= " <TR align=center>\n"; |
| $rt .= " <TD>\n"; |
| $rt .= " <button dojoType=\"dijit.form.Button\" type=\"button\">\n"; |
| $rt .= i( "View") . "\n"; |
| $rt .= " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| $cont = addContinuationsEntry('AJviewBlockAllocation', $block, SECINDAY); |
| $rt .= " viewBlockAllocation('$cont');\n"; |
| $rt .= " </script>\n"; |
| $rt .= " </button>\n"; |
| $rt .= " </TD>\n"; |
| $rt .= " <TD>\n"; |
| if($block['status'] == 'accepted') { |
| $rt .= " <button dojoType=\"dijit.form.Button\" type=\"button\">\n"; |
| $rt .= i( "View Times") . "\n"; |
| $rt .= " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| $cont = addContinuationsEntry('AJviewBlockAllocationTimes', array('blockid' => $block['id']), SECINDAY); |
| $rt .= " viewBlockTimes('$cont');\n"; |
| $rt .= " </script>\n"; |
| $rt .= " </button>\n"; |
| } |
| $rt .= " </TD>\n"; |
| $rt .= " <TD>{$block['blockname']}</TD>\n"; |
| $rt .= " <TD>{$block['image']}</TD>\n"; |
| $rt .= " <TD>{$block['machinecnt']}</TD>\n"; |
| $rt .= " <TD>{$block['group']}</TD>\n"; |
| $rt .= " <TD>" . i($block['available']) . "</TD>\n"; |
| $rt .= " </TR>\n"; |
| } |
| $rt .= "</table>\n"; |
| $rt .= "</div>\n"; |
| if($listonly) |
| return $rt; |
| |
| $rt .= "<div id=\"viewDialog\" dojoType=\"dijit.Dialog\" title=\""; |
| $rt .= i("Block Allocation") . "\">\n"; |
| $rt .= "<table summary=\"\">\n"; |
| $rt .= " <tr>\n"; |
| $rt .= " <th align=\"right\">" . i("Name") . ":</th>\n"; |
| $rt .= " <td><span id=\"confname\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr>\n"; |
| $rt .= " <th align=\"right\">" . i("Owner") . ":</th>\n"; |
| $rt .= " <td><span id=\"confowner\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr>\n"; |
| $rt .= " <th align=\"right\">" . i("Environment") . ":</th>\n"; |
| $rt .= " <td><span id=\"confimage\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr>\n"; |
| $rt .= " <th align=\"right\">" . i("User group") . ":</th>\n"; |
| $rt .= " <td><span id=\"confgroup\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr>\n"; |
| $rt .= " <th align=\"right\">" . i("Seats") . ":</th>\n"; |
| $rt .= " <td><span id=\"confseats\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr>\n"; |
| $rt .= " <th align=\"right\">" . i("Repeating") . ":</th>\n"; |
| $rt .= " <td><span id=\"confrepeat\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr valign=\"top\">\n"; |
| $rt .= " <th align=\"right\"><span id=\"conftitle1\"></span></th>\n"; |
| $rt .= " <td><span id=\"confvalue1\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr valign=\"top\">\n"; |
| $rt .= " <th align=\"right\"><span id=\"conftitle2\"></span></th>\n"; |
| $rt .= " <td><span id=\"confvalue2\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr valign=\"top\">\n"; |
| $rt .= " <th align=\"right\"><span id=\"conftitle3\"></span></th>\n"; |
| $rt .= " <td><span id=\"confvalue3\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr valign=\"top\">\n"; |
| $rt .= " <th align=\"right\"><span id=\"conftitle4\"></span></th>\n"; |
| $rt .= " <td><span id=\"confvalue4\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= "</table>\n"; |
| $rt .= "<div align=\"center\">\n"; |
| $rt .= "<button dojoType=\"dijit.form.Button\" type=\"button\">\n"; |
| $rt .= i( "Close") . "\n"; |
| $rt .= " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| $rt .= " clearHideView();\n"; |
| $rt .= " </script>\n"; |
| $rt .= "</button>\n"; |
| $rt .= "</div>\n"; |
| $rt .= "</div>\n"; # confirm dialog |
| |
| $rt .= "<div id=\"viewtimesDialog\" dojoType=\"dijit.Dialog\" title=\""; |
| $rt .= i("Block Allocation Times") . "\">\n"; |
| $rt .= "<h2>" . i("Block Allocation Times") . "</h2>\n"; |
| $rt .= "<table dojoType=\"dojox.grid.DataGrid\" jsId=\"blockTimesGrid\" sortInfo=1 "; |
| $rt .= "style=\"width: 328px; height: 200px;\">\n"; |
| $rt .= "<script type=\"dojo/method\" event=\"onStyleRow\" args=\"row\">\n"; |
| $rt .= "blockTimeRowStyle(row);\n"; |
| $rt .= "</script>\n"; |
| $rt .= "<thead>\n"; |
| $rt .= "<tr>\n"; |
| $rt .= "<th field=\"start\" width=\"70px\" formatter=\"blockTimesGridDate\">"; |
| $rt .= i("Date") . "</th>\n"; |
| $rt .= "<th field=\"start\" width=\"85px\" formatter=\"blockTimesGridStart\">"; |
| $rt .= i("Start") . "</th>\n"; |
| $rt .= "<th field=\"end\" width=\"85px\" formatter=\"blockTimesGridEnd\">"; |
| $rt .= i("End") . "</th>\n"; |
| $rt .= "<th field=\"delbtn\" width=\"60px\">" . i("Skip") . "</th>\n"; |
| $rt .= "</tr>\n"; |
| $rt .= "</thead>\n"; |
| $rt .= "</table>\n"; |
| $rt .= "<div align=\"center\">\n"; |
| $rt .= "<button dojoType=\"dijit.form.Button\" type=\"button\">\n"; |
| $rt .= i( "Close") . "\n"; |
| $rt .= " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| $rt .= " dijit.byId('viewtimesDialog').hide();\n"; |
| $rt .= " </script>\n"; |
| $rt .= "</button>\n"; |
| $rt .= "</div>\n"; |
| $rt .= "<input type=hidden id=toggletimecont>\n"; |
| $rt .= "</div>\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"; |
| if(! checkUserHasPerm('Manage Block Allocations (global)')) |
| $query .= " AND u.affiliationid = {$user['affiliationid']}"; |
| $qh = doQuery($query, 101); |
| $h = "<table>\n"; |
| $h .= " <tr align=center>\n"; |
| $h .= " <td></td>\n"; |
| $h .= " <td></td>\n"; |
| $h .= " <th>" . i("Environment") . "</th>\n"; |
| $h .= " <th>" . i("Requested by") . "</th>\n"; |
| $h .= " <th>" . i("Reserved Machines") . "</th>\n"; |
| $h .= " <th>" . i("Repeating") . "</th>\n"; |
| $h .= " <th>" . i("Start Date") . "</th>\n"; |
| $h .= " <th>" . i("End Date") . "</th>\n"; |
| $h .= " </tr>\n"; |
| $d = ''; |
| $groups = getUserGroups(0, $user['affiliationid']); |
| while($row = mysqli_fetch_assoc($qh)) { |
| unset($start); |
| 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 = mysqli_fetch_assoc($qh2)) |
| abort(101); |
| $row = array_merge($row, $row2); |
| $start = $row['swdate']; |
| $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 = mysqli_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 = mysqli_fetch_assoc($qh2)) |
| abort(101); |
| $row = array_merge($row, $row2); |
| $start = $row['smdate']; |
| $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 = mysqli_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 = mysqli_fetch_assoc($qh2)) { |
| if(! isset($start)) |
| $start = $row2['date']; |
| 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 = mysqli_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 .= " <tr align=center>\n"; |
| $d .= " <td>\n"; |
| $d .= " <button dojoType=\"dijit.form.Button\" type=\"button\">\n"; |
| $d .= i( "Accept...") . "\n"; |
| $d .= " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| $cont = addContinuationsEntry('AJacceptBlockAllocationConfirm', $row); |
| $d .= " acceptBlockConfirm('$cont');\n"; |
| $d .= " </script>\n"; |
| $d .= " </button>\n"; |
| $d .= " </td>\n"; |
| $d .= " <td>\n"; |
| $d .= " <button dojoType=\"dijit.form.Button\" type=\"button\">\n"; |
| $d .= i( "Reject...") . "\n"; |
| $d .= " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| $cont = addContinuationsEntry('AJrejectBlockAllocationConfirm', $row); |
| $d .= " rejectBlockConfirm('$cont');\n"; |
| $d .= " </script>\n"; |
| $d .= " </button>\n"; |
| $d .= " </td>\n"; |
| $d .= "<td>{$row['image']}</td>\n"; |
| if(! empty($row['firstname']) && ! empty($row['lastname'])) |
| $d .= "<td>{$row['firstname']} {$row['lastname']} ({$row['unityid']})</td>\n"; |
| else |
| $d .= "<td>{$row['unityid']}</td>\n"; |
| $d .= "<td>{$row['numMachines']}</td>\n"; |
| $d .= "<td>" . i($row['repeating']) . "</td>\n"; |
| $d .= "<td>$start</td>\n"; |
| $d .= "<td>{$row['lastdate']}</td>\n"; |
| $d .= " </tr>\n"; |
| } |
| if(empty($d)) |
| return i("There are currently no pending block allocation requests."); |
| $rt = $h . $d . "</table>\n"; |
| |
| if($listonly) |
| return $rt; |
| |
| $rt .= "<div id=\"acceptDialog\" dojoType=\"dijit.Dialog\" "; |
| $rt .= "title=\"" . i("Accept Block Allocation") . "\">\n"; |
| $rt .= "<h2>" . i("Accept Block Allocation") . "</h2>\n"; |
| $h = i("Please review the following information, fill in the additional fields, and click <strong>Accept Block Allocation</strong>."); |
| $rt .= preg_replace("/(.{1,100}([ \n]|$))/", '\1<br>', $h) . "<br>"; |
| $rt .= "<table summary=\"\">\n"; |
| $rt .= " <tr>\n"; |
| $rt .= " <th align=\"right\">" . i("Environment:") . "</th>\n"; |
| $rt .= " <td><span id=\"acceptimage\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr>\n"; |
| $rt .= " <th align=\"right\">" . i("Seats:") . "</th>\n"; |
| $rt .= " <td><span id=\"acceptseats\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr>\n"; |
| $rt .= " <th align=\"right\">" . i("Repeating:") . "</th>\n"; |
| $rt .= " <td><span id=\"acceptrepeat\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr valign=\"top\">\n"; |
| $rt .= " <th align=\"right\"><span id=\"accepttitle1\"></span></th>\n"; |
| $rt .= " <td><span id=\"acceptvalue1\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr valign=\"top\">\n"; |
| $rt .= " <th align=\"right\"><span id=\"accepttitle2\"></span></th>\n"; |
| $rt .= " <td><span id=\"acceptvalue2\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr valign=\"top\">\n"; |
| $rt .= " <th align=\"right\"><span id=\"accepttitle3\"></span></th>\n"; |
| $rt .= " <td><span id=\"acceptvalue3\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr valign=\"top\">\n"; |
| $rt .= " <th align=\"right\"><span id=\"accepttitle4\"></span></th>\n"; |
| $rt .= " <td><span id=\"acceptvalue4\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr valign=\"top\">\n"; |
| $rt .= " <th align=\"right\"><span id=\"accepttitle5\"></span></th>\n"; |
| $rt .= " <td><span id=\"acceptvalue5\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr id=\"staticusergroup\">\n"; |
| $rt .= " <th align=\"right\">" . i("User Group:") . "</th>\n"; |
| $rt .= " <td><span id=\"acceptgroup\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr id=\"warnmsgtr\" class=\"hidden\">\n"; |
| $rt .= " <td colspan=2><span id=\"warnmsg\" class=\"rederrormsg\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr>\n"; |
| $rt .= " <td colspan=2><hr></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr id=\"editusergroup\" class=\"hidden\">\n"; |
| $rt .= " <th align=right>" . i("User Group:") . "</th>\n"; |
| $rt .= " <td>\n"; |
| if(USEFILTERINGSELECT && count($groups) < FILTERINGSELECTTHRESHOLD) { |
| $rt .= " <select dojoType=\"dijit.form.FilteringSelect\" id=groupsel "; |
| $rt .= "queryExpr=\"*\${0}*\" highlightMatch=\"all\" autoComplete=\"false\" "; |
| $rt .= "onChange=\"clearCont2();\">\n"; |
| } |
| else |
| $rt .= " <select id=groupsel onChange=\"clearCont2();\">\n"; |
| foreach($groups as $id => $group) { |
| if($group['name'] == ' None@') |
| continue; |
| $rt .= " <option value=\"$id\">{$group['name']}</option>\n"; |
| } |
| $rt .= " </select>\n"; |
| $rt .= " </td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr>\n"; |
| $rt .= " <th align=\"right\">" . i("Name:") . "</th>\n"; |
| $rt .= " <td>\n"; |
| $rt .= " <input type=\"text\" dojoType=\"dijit.form.ValidationTextBox\" "; |
| $rt .= "id=\"brname\" required=\"true\" invalidMessage=\""; |
| $h = i("Name can only contain letters, numbers, spaces, dashes(-), and periods(.) and can be from 3 to 80 characters long"); |
| $rt .= preg_replace("/(.{1,50}([ \n]|$))/", '\1<br>', $h) . "<br>"; |
| $rt .= "\" regExp=\"^([-a-zA-Z0-9\. ]){3,80}$\">\n"; |
| $rt .= " </td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= "</table><br>\n"; |
| $rt .= "<div id=\"acceptemailblock\">\n"; |
| $rt .= sprintf(i("The following text will be emailed to %s:"), "<span id=\"acceptemailuser\"></span>"); |
| $rt .= "<br><textarea id=\"acceptemailtext\" dojoType=\"dijit.form.Textarea\" style=\"width: 400px;\">\n"; |
| $rt .= "</textarea>\n"; |
| $rt .= "</div>\n"; |
| $rt .= "<div id=\"acceptemailwarning\" class=\"hidden\">\n"; |
| $rt .= "<strong>" . i("Note:") . "</strong> "; |
| $h = i("The requesting user does not have an email address registered with VCL. Therefore, the user cannot be notified automatically."); |
| $rt .= preg_replace("/(.{1,50}([ \n]|$))/", '\1<br>', $h) . "\n"; |
| $rt .= "</div>\n"; |
| $rt .= "<br>\n"; |
| $rt .= "<button dojoType=\"dijit.form.Button\" type=\"button\">\n"; |
| $rt .= i("Accept Block Allocation") . "\n"; |
| $rt .= " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| $rt .= " acceptBlockSubmit();\n"; |
| $rt .= " </script>\n"; |
| $rt .= "</button>\n"; |
| $rt .= "<button dojoType=\"dijit.form.Button\" type=\"button\">\n"; |
| $rt .= i("Cancel") . "\n"; |
| $rt .= " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| $rt .= " clearHideConfirmAccept();\n"; |
| $rt .= " </script>\n"; |
| $rt .= "</button>\n"; |
| $rt .= "<input type=hidden id=submitacceptcont>\n"; |
| $rt .= "<input type=hidden id=submitacceptcont2>\n"; |
| $rt .= "</div>\n"; # accept dialog |
| |
| $rt .= "<div id=\"rejectDialog\" dojoType=\"dijit.Dialog\" "; |
| $rt .= "title=\"" . i("Reject Block Allocation") . "\">\n"; |
| $rt .= "<h2>" . i("Reject Block Allocation") . "</h2>\n"; |
| $h = i("Please review the following information, add a reason for rejecting the block allocation, and click <strong>Reject Block Allocation</strong>."); |
| $rt .= preg_replace("/(.{1,100}([ \n]|$))/", '\1<br>', $h) . "<br>\n"; |
| $rt .= "<table summary=\"\">\n"; |
| $rt .= " <tr>\n"; |
| $rt .= " <th align=\"right\">" . i("Environment:") . "</th>\n"; |
| $rt .= " <td><span id=\"rejectimage\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr id=\"editusergroup\" class=\"hidden\">\n"; |
| $rt .= " <th align=\"right\">" . i("User Group:") . "</th>\n"; |
| $rt .= " <td><span id=\"rejectgroup\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr>\n"; |
| $rt .= " <th align=\"right\">" . i("Seats:") . "</th>\n"; |
| $rt .= " <td><span id=\"rejectseats\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr>\n"; |
| $rt .= " <th align=\"right\">" . i("Repeating:") . "</th>\n"; |
| $rt .= " <td><span id=\"rejectrepeat\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr valign=\"top\">\n"; |
| $rt .= " <th align=\"right\"><span id=\"rejecttitle1\"></span></th>\n"; |
| $rt .= " <td><span id=\"rejectvalue1\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr valign=\"top\">\n"; |
| $rt .= " <th align=\"right\"><span id=\"rejecttitle2\"></span></th>\n"; |
| $rt .= " <td><span id=\"rejectvalue2\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr valign=\"top\">\n"; |
| $rt .= " <th align=\"right\"><span id=\"rejecttitle3\"></span></th>\n"; |
| $rt .= " <td><span id=\"rejectvalue3\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr valign=\"top\">\n"; |
| $rt .= " <th align=\"right\"><span id=\"rejecttitle4\"></span></th>\n"; |
| $rt .= " <td><span id=\"rejectvalue4\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= " <tr valign=\"top\">\n"; |
| $rt .= " <th align=\"right\"><span id=\"rejecttitle5\"></span></th>\n"; |
| $rt .= " <td><span id=\"rejectvalue5\"></span></td>\n"; |
| $rt .= " </tr>\n"; |
| $rt .= "</table>\n"; |
| $rt .= "<div id=\"rejectemailblock\">\n"; |
| $rt .= sprintf(i("The following text will be emailed to %s:"), "<span id=\"rejectemailuser\"></span>"); |
| $rt .= "<br></div>\n"; |
| $rt .= "<div id=\"rejectemailwarning\" class=\"hidden\">\n"; |
| $h = i("The requesting user does not have an email address registered with VCL. Therefore, the user cannot be notified automatically. However, for archival purposes, fill in a reason for rejecting the request:"); |
| $rt .= preg_replace("/(.{1,60}([ \n]|$))/", '\1<br>', $h); |
| $rt .= "\n</div><br>\n"; |
| $rt .= "<textarea id=\"rejectemailtext\" dojoType=\"dijit.form.Textarea\" style=\"width: 400px;\">\n"; |
| $rt .= "</textarea>\n"; |
| $rt .= "<br>\n"; |
| $rt .= "<button dojoType=\"dijit.form.Button\" type=\"button\">\n"; |
| $rt .= i("Reject Block Allocation") . "\n"; |
| $rt .= " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| $rt .= " rejectBlockSubmit();\n"; |
| $rt .= " </script>\n"; |
| $rt .= "</button>\n"; |
| $rt .= "<button dojoType=\"dijit.form.Button\" type=\"button\">\n"; |
| $rt .= i("Cancel") . "\n"; |
| $rt .= " <script type=\"dojo/method\" event=\"onClick\">\n"; |
| $rt .= " clearHideConfirmReject();\n"; |
| $rt .= " </script>\n"; |
| $rt .= "</button>\n"; |
| $rt .= "<input type=hidden id=submitrejectcont>\n"; |
| $rt .= "</div>\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'], |
| '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 => i("1st"), |
| 2 => i("2nd"), |
| 3 => i("3rd"), |
| 4 => i("4th"), |
| 5 => i("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; |
| } |
| $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); |
| $reloadid = getUserlistID('vclreload@Local'); |
| $query = "DELETE FROM request " |
| . "WHERE stateid = 19 AND " |
| . "laststateid = 19 AND " |
| . "userid = $reloadid AND " |
| . "id IN (SELECT bc.reloadrequestid " |
| . "FROM blockComputers bc, " |
| . "blockTimes bt " |
| . "WHERE bt.blockRequestid = $blockid AND " |
| . "bt.id = bc.blockTimeid AND " |
| . "bc.reloadrequestid != 0)"; |
| doQuery($query); |
| $query = "DELETE FROM blockTimes WHERE blockRequestid = $blockid"; |
| doQuery($query); |
| $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 => i("1st"), |
| 2 => i("2nd"), |
| 3 => i("3rd"), |
| 4 => i("4th"), |
| 5 => i("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'] = sprintf(i("The VCL Block Allocation you requested for %d seats of %s repeating on a weekly schedule has been accepted."), $data['numMachines'], $data['image']); |
| } |
| 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 => i("1st"), |
| 2 => i("2nd"), |
| 3 => i("3rd"), |
| 4 => i("4th"), |
| 5 => i("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'] = sprintf(i("The VCL Block Allocation you requested for %d seats of %s repeating on a monthly schedule has been accepted."), $data['numMachines'], $data['image']); |
| } |
| 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'] = sprintf(i("The VCL Block Allocation you requested for %d seats of %s during the following time periods has been accepted:") . "\n" . implode("\n", $slots) . "\n", $data['numMachines'], $data['image']); |
| } |
| $rt['comments'] = preg_replace("/\n/", "<br>", $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; |
| if(! is_null($rt['usergroup'])) { |
| $groupresources = getUserResources(array("imageAdmin", "imageCheckOut"), |
| array("available"), 0, 0, 0, |
| $data['usergroupid']); |
| if(! array_key_exists($data['imageid'], $groupresources['image'])) |
| $rt['warnmsg'] = i("Warning: The requested user group does not currently have access to the requested image."); |
| } |
| $cdata = array('blockid' => $data['id'], |
| 'imageid' => $data['imageid']); |
| 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 $mysqli_link_vcl, $user; |
| $blockid = getContinuationVar('blockid'); |
| $comments = getContinuationVar('comments'); |
| $validemail = getContinuationVar('validemail'); |
| $emailuser = getContinuationVar('emailuser'); |
| $imageid = getContinuationVar('imageid'); |
| $setusergroup = getContinuationVar('setusergroup'); |
| if($setusergroup) |
| $usergroupid = processInputVar('groupid', ARG_NUMERIC); |
| $name = processInputVar('brname', ARG_STRING); |
| $emailtext = processInputVar('emailtext', ARG_STRING); |
| $override = getContinuationVar('override', 0); |
| |
| $err = 0; |
| if(! preg_match('/^([-a-zA-Z0-9\. ]){3,80}$/', $name)) { |
| $errmsg = i("The name can only contain letters, numbers, spaces, dashes(-), and periods(.) and can be from 3 to 80 characters long"); |
| $err = 1; |
| } |
| if($validemail) { |
| if(! $err && preg_match('/[<>|]/', $emailtext)) { |
| $errmsg = i("<>\'s and pipes (|) are not allowed in the email text."); |
| $err = 1; |
| } |
| if(! $err && ! preg_match('/[A-Za-z]{2,}/', $emailtext)) { |
| $errmsg = i("Something must be filled in for the email text."); |
| $err = 1; |
| } |
| } |
| $groups = getUserGroups(0, $user['affiliationid']); |
| if(! $err && $setusergroup && ! array_key_exists($usergroupid, $groups)) { |
| $errmsg = i("Invalid user group submitted."); |
| $err = 1; |
| } |
| $managementnodes = getManagementNodes('future'); |
| if(! $err && empty($managementnodes)) { |
| $errmsg = i("Error encountered while trying to create block allocation:") . "\\n\\n"; |
| $errmsg .= i("No active management nodes were found. Please try accepting the block allocation at a later time."); |
| $err = 1; |
| } |
| $dooverride = 0; |
| if(! $err && ! $override && $setusergroup) { |
| $groupresources = getUserResources(array("imageAdmin", "imageCheckOut"), |
| array("available"), 0, 0, 0, |
| $usergroupid); |
| if(! array_key_exists($imageid, $groupresources['image'])) { |
| $errmsg = i("Warning: The selected user group does not currently have access to the requested image. You can accept the Block Allocation again to ignore this warning."); |
| $err = 1; |
| $dooverride = 1; |
| } |
| } |
| $mnid = array_rand($managementnodes); |
| if(! $err) { |
| # update values for block allocation |
| if($validemail) |
| $esccomments = vcl_mysql_escape_string("COMMENTS: $comments|EMAIL: $emailtext"); |
| else |
| $esccomments = vcl_mysql_escape_string("COMMENTS: $comments|USER NOT EMAILED"); |
| $query = "UPDATE blockRequest " |
| . "SET name = '$name', "; |
| if($setusergroup) |
| $query .= "groupid = $usergroupid, "; |
| $query .= "status = 'accepted', " |
| . "comments = '$esccomments', " |
| . "managementnodeid = '$mnid' " |
| . "WHERE id = $blockid"; |
| doQuery($query, 101); |
| if(! mysqli_affected_rows($mysqli_link_vcl)) { |
| $errmsg = i("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';"; |
| if($dooverride) { |
| $cdata['override'] = 1; |
| $cont = addContinuationsEntry('AJacceptBlockAllocationSubmit', $cdata, SECINDAY, 1, 0); |
| print "dojo.byId('submitacceptcont2').value = '$cont';"; |
| } |
| else |
| print "dojo.byId('submitacceptcont2').value = '';"; |
| print "document.body.style.cursor = 'default';"; |
| return; |
| } |
| |
| # send accept email to requestor |
| $message = $emailtext . "\n\nVCL Admins"; |
| $mailParams = "-f" . HELPEMAIL; |
| mail($emailuser, i("VCL Block Allocation Accepted"), $message, '', |