/** * Determin if the semester and year specified are the current one * * @param string $semester The semester in question. * @param integer $year The year of the semester in question. * @return boolean * @access public * @date 9/9/04 */ function isSemesterNow($semester, $year) { global $cfg; // If we aren't in the semester that is specified, don't bother // checking the year. if ($semester != currentSemester()) { return FALSE; } // Make sure we have a 4-digit year. if (strlen($year) == 2) { $year = $year + 2000; } // We are good if we are in the same year as asked for. if (date("Y") == $year) { return TRUE; } // If we aren't in the same year, then we need to check if we are in a // year beyond the specified one if the semester in question spans the // NewYear. $startDay = date("z", strtotime($cfg['semesters'][$semester]['start_month'] . "/" . $cfg['semesters'][$semester]['start_day'])); $endDay = date("z", strtotime($cfg['semesters'][$semester]['end_month'] . "/" . $cfg['semesters'][$semester]['end_day'])); // If the semester in question doesn't go across the new year, // then we are definately not in it. since we checked before // if our year was the same as the semester in question. if ($endDay - $startDay >= 0) { return FALSE; } else { if (date("Y") == $year + 1 && date("z") <= $endDay) { return TRUE; } else { return FALSE; } } }
} 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); } } } } } } else { //faculty & admin have unlimited hours if ($class == "Faculty") { $bookingSem = currentSemester($startDate); $currentSem = currentSemester($currentDate); $addMonth = date("Y-m-d", strtotime("+1 month", strtotime($currentDate))); $semInMonth = currentSemester($addMonth); if ($bookingSem == $currentSem) { //booking in current semester $canBook = True; } else { if ($bookingSem == $semInMonth) { //book within 1 month of next semester $canBook = True; } else { //Booking too far in advance $result['msg'] = "You may only make bookings for the current semester. You may start making bookings for the next semester one month in advance."; $canBook = False; } } } else { //Admin
function weeksLeftInSemester($currentDate, $startDate) { $semester = currentSemester($currentDate); $startDate = date('Y-m-d', strtotime($startDate)); $currentDate = date('Y-m-d', strtotime($currentDate)); $count = 0; if ($semester == "Winter") { $endSem = date('Y-m-d', strtotime("April 30, " . date("Y"))); $nextSem = date('Y-m-d', strtotime("April 1, " . date("Y"))); if ($currentDate >= $nextSem) { //can start booking for next semester $endSem = date('Y-m-d', strtotime("August 31, " . date("Y"))); } } else { if ($semester == "Summer") { $endSem = date('Y-m-d', strtotime("August 31, " . date("Y"))); $nextSem = date('Y-m-d', strtotime("August 1, " . date("Y"))); if ($currentDate >= strtotime("August 1, " . date("Y"))) { //can start booking for next semester $endSem = date('Y-m-d', strtotime("December 31, " . date("Y"))); } } else { if ($semester == "Fall") { $endSem = date('Y-m-d', strtotime("December 31, " . date("Y"))); $nextSem = date('Y-m-d', strtotime("April 30, " . date("Y"))); if ($currentDate >= strtotime("December 1, " . date("Y"))) { //can start booking for next semester $endSem = date('Y-m-d', strtotime("April 30, " . date("Y"))); } } } } while ($startDate <= $endSem) { $count = $count + 1; $startDate = date('Y-m-d', strtotime('+1 week', strtotime($startDate))); } return $count; }