} else {
    if ($startDate < $firstDayWeek3) {
        $week = 'nextWeekHrs';
    } else {
        $week = 'thirdWeekHrs';
    }
}
$result = array();
//get daily bookings from database
$sth = $db->prepare("SELECT {$week} FROM User where uID = ?;");
$sth->execute(array($uID));
//Loop through each returned row
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
    $result = floatval($row[$week]);
}
$result += SufficientSpecialHours($db, $uID, $startDate);
//Close the connection
$db = NULL;
//encode result to json format
$json = json_encode($result);
echo $json;
//determine if there are sufficient special hours for the user to make the booking
//return true if they have sufficient time, otherwise return false
function SufficientSpecialHours($db, $uID, $startDate)
{
    $usableSpecialHours = 0;
    $sth = $db->prepare("SELECT SUM(Permission.specialHrs) totalHrs FROM Permission JOIN UGroups on UGroups.groupID = Permission.groupID WHERE uID = ? and ? BETWEEN UGroups.startDate and UGroups.endDate");
    $sth->execute(array($uID, $startDate));
    while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
        //Get number of blocks
        $usableSpecialHours = $row['totalHrs'];
Ejemplo n.º 2
0
         //remove the hours from the user's special groups
         useSpecialHours($db, $uID, $startDate, $remainingDuration);
         //update the hourse source for the blocks of the booking
         updateHrsSource($db, $uID, $bookingID, $hoursSourecList);
         http_response_code(200);
         //success
     } else {
         //not sufficient hours
         $result['msg'] = "You do not have sufficient special hours to complete this booking after using all your weekly hours";
         http_response_code(406);
     }
 } else {
     if ($hoursRemaining <= 0) {
         //check and see if the user has special hours valid this week
         //if there are sufficien special hours to make the booking, book the room
         if (SufficientSpecialHours($db, $uID, $startDate, $duration)) {
             //book the room
             $bookingID = createBookingInDB($db, $uID, $reason, $desc, $numP, $blocks, $startDate, $room, $totalB, $startTime, $endDate, $endTime, $hrsSource);
             //Send bookingID to front end
             $result['bookingID'] = $bookingID;
             //remove the hours from the user's special groups
             useSpecialHours($db, $uID, $startDate, $duration);
             //update the hourse source for the blocks of the booking
             updateHrsSource($db, $uID, $bookingID, $hoursSourecList);
             http_response_code(200);
             //success
         } else {
             //not sufficient hours
             $result['msg'] = "You do not have sufficient special hours to complete this booking, you also have no general weekly hours.";
             http_response_code(406);
         }