-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.php
executable file
·203 lines (183 loc) · 6.12 KB
/
Main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
/*
* Copyright 2009 Bion Oren
*
* Licensed 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.
*/
require_once($path."Object.php");
require_once($path."Course.php");
require_once($path."functions.php");
/**
* Handles processing of the main page.
*
* Provides user input to other classes that need it.
*
* @author Bion Oren
* @version 1.0
*/
abstract class Main extends Object {
/** ARRAY Mapping of semester abbreviations to long names. */
public static $SEMESTER_NAMES = array("SP"=>"Spring", "SU"=>"Summer", "FA"=>"Fall");
/** ARRAY Mapping from campus names to their bit value (for bitmasking campuses). */
public static $CAMPUS_MASK = 0;
/** STRING The name of the campus we're getting courses for. */
protected static $campus;
/** STRING The unique name of the current semester. */
protected static $semester;
/** BOOLEAN True if student information should be evaluated and displayed. */
protected static $student;
/** BOOLEAN True if schedules should be generated. */
protected static $submit = false;
/** BOOLEAN True if we're dealing with traditional courses. */
protected static $traditional;
/** INTEGER Mask of valid campuses to display. */
protected $campusMask = 0;
/**
* Initializes all the class variables.
*/
public function __construct() {
}
/**
* Returns the campus classes are coming from.
*
* @return STRING Campus name.
* @see $campus
*/
public static function getCampus() {
return Main::$campus;
}
/**
* Returns the name of the cookie that should store previous schedule information.
*
* @return STRING Cookie name.
*/
public static function getCookieName() {
$trad = (Main::isTraditional())?"trad":"non";
return Main::getSemester().$trad.Main::getCampus();
}
/**
* Returns the name of the current semester.
*
* @return STRING Semester identifier.
*/
protected static function getCurrentSemester() {
if(empty($_REQUEST["semester"])) {
$files = getFileArray();
return $files[0];
} else {
return $_REQUEST["semester"];
}
}
/**
* Returns the name of the current semester.
*
* @return STRING Semester identifier.
*/
public static function getSemester() {
return Main::$semester;
}
/**
* Returns true if the user has selected at least one class.
*
* @return BOOLEAN True on user selection.
*/
public static function haveSelections() {
return isset($_REQUEST["choice"]);
}
/**
* Initializes environment variables.
*
* @return VOID
*/
public static function init() {
//setup enough environment to actually set up
Main::setup();
//look for cookie data
if(Main::isStudent() && isset($_COOKIE[Main::getCookieName()]) && !isset($_REQUEST["ignore"])) {
$args = json_decode(stripslashes($_COOKIE[Main::getCookieName()]), true);
if($args) {
$_REQUEST = array_merge($_REQUEST, $args);
}
Main::setup();
}
}
/**
* Sets up static environment variables.
*
* @return VOID
*/
protected static function setup() {
Main::$semester = Main::getCurrentSemester();
Main::$traditional = !isset($_REQUEST["type"]) || $_REQUEST["type"] != "non";
Main::$student = !isset($_REQUEST["role"]) || $_REQUEST["role"] == "student";
Main::$campus = (isset($_REQUEST["campus"]))?$_REQUEST["campus"]:"MAIN";
Main::$submit = isset($_REQUEST["submit"]);
Student::init();
}
/**
* Returns true if the schedules to be displayed are for students.
*
* @return BOOLEAN True for student schedules.
*/
public static function isStudent() {
return Main::$student;
}
/**
* Returns true if traditional classes are being evaluated.
*
* @return BOOLEAN True if traditional classes are being used.
*/
public static function isTraditional() {
return Main::$traditional;
}
/**
* Prints options for a SELECT block with all available semesters.
*
* @return VOID
*/
public static function printSemesterOptions() {
foreach(getFileArray() as $key) {
print '<option value="'.$key.'"';
if(Main::getSemester() == $key) {
print " selected='selected'";
}
print '>'.Main::$SEMESTER_NAMES[substr($key, -2)].' '.substr($key, 0, 4).'</option>';
}
}
/**
* Sets the bitmask for campuses that should be displayed.
*
* @return VOID
*/
public function setCampusMask() {
$this->campusMask = Main::$CAMPUS_MASK[Main::$campus];
if(Main::$campus == "MAIN" && isset(Main::$CAMPUS_MASK["ARPT"])) {
$this->campusMask |= Main::$CAMPUS_MASK["ARPT"];
}
if(isset(Main::$CAMPUS_MASK["XOL"])) {
$this->campusMask |= Main::$CAMPUS_MASK["XOL"];
}
if(isset(Main::$CAMPUS_MASK["N/A"])) {
$this->campusMask |= Main::$CAMPUS_MASK["N/A"];
}
}
/**
* Returns the full name (including path) for this script.
*
* @return STRING Fully-qualified PHP file path.
*/
public function __toString() {
return $_SERVER["PHP_SELF"];
}
}
require_once($path."Student.php");
require_once($path."Professor.php");
?>