-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcourseDatabaseForm.php
More file actions
142 lines (122 loc) · 4.22 KB
/
courseDatabaseForm.php
File metadata and controls
142 lines (122 loc) · 4.22 KB
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
<?php
include_once "./ajax/PointsCenter.php";
$points_center = new \Slivka\PointsCenter();
$showall = isset($_GET['all']) ? $_GET['all'] == '1' : false;
$quarters = $points_center->getQuarters();
// Only show most recent 3 quarters for selection
$quarters = array_slice($quarters, 0, 3);
?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<?php include 'header.html'; ?>
<title>Course Database Form</title>
</head>
<body style="background: none;">
<img class="pull-right" title="This Week's Schedule" src="/wordpress/wp-content/uploads/2013/03/Screen-Shot-2013-03-04-at-1.23.09-PM1.png" width="290" height="285" />
<ol>
<li>Sign into Caesar: <a title="http://www.northwestern.edu/caesar" href="http://www.northwestern.edu/caesar" target="_blank">http://www.northwestern.edu/caesar/</a></li>
<li>Click "Enrollment" and select the upcoming quarter.</li>
<li>Find and copy the table labeled "My [Current Quarter] Class Schedule" (See right)</li>
<li>Paste the table and press submit!</li>
</ol>
<p>Example:</p>
<blockquote> EECS 321-0-20 LEC<br/>
(23328)<br/>
MoFr 2:00PM - 3:20PM<br/>
Tech Institute Lecture Room 5<br/>
<br/>
EECS 473-1-20 LEC<br/>
(23366)<br/>
...</blockquote>
<p>Note: If you run into any difficulties, please email the IT chair.</p>
<form action="ajax/submitCourseDatabase.php" method="post" onsubmit="return courseDatabaseFormValidate();">
<div class="form-group">
<label for="name">Full Name:</label>
<input id="name" onfocusout="validateName();" type="text" name="name" class="form-control" />
<input id="nu_email" type="text" name="nu_email" style="display: none;" />
<div id="name-error" class="alert alert-warning" style="display: none;">Name isn't in directory.</div>
</div>
<div class="form-group">
<label for="courses">Pasted "This Week's Schedule": (currently <span id="matched">0</span> matched courses)</label>
<textarea id="courses" onkeyup="validateCourses();" name="courses" rows="12" cols="50" class="form-control"></textarea>
<div id="courses-error" class="alert alert-warning" style="display: none;">No matched courses.</div>
</div>
<div class="form-group">
<label for="qtr">Quarter:</label>
<select name="qtr" class="form-control">
<?php
foreach ($quarters as $q) {
echo '<option value="' . $q['qtr'] . '">' . $q['quarter'] . '</option>';
}
?>
<option value="0">Previous Quarter</option>
</select>
</div>
<div class="pull-right">
<input id="submit" type="submit" value="Submit" class="btn btn-primary" />
</div>
</form>
</div>
<script type="text/javascript" src="bower_components/jquery/jquery.min.js"></script>
<script type="text/javascript" src="bower_components/typeahead.js/dist/typeahead.min.js"></script>
<script type="text/javascript">
//add indexOfKey (useful: http://jsperf.com/js-for-loop-vs-array-indexof)
Array.prototype.indexOfKey = function (key, value) {
for (var i=0; i < this.length; i++) {
if (this[i][key] === value) {
return i;
}
}
return -1;
};
window.slivkans = [];
$(document).ready(function () {
$.getJSON("ajax/getSlivkans.php",function (data) {
slivkans = data.slivkans;
$("#name").typeahead({
name: "slivkans",
valueKey: "full_name",
local: slivkans
});
});
});
function courseDatabaseFormValidate()
{
var isvalid = true;
if (!validateName()) { isvalid = false; }
if (!validateCourses()) { isvalid = false; }
return isvalid;
}
function validateName()
{
var valid = false,
name = $("#name").val(),
ind = slivkans.indexOfKey("full_name",name);
valid = ind != -1;
if (valid) {
$("#nu_email").val(slivkans[ind].nu_email);
$("#name-error").fadeOut();
} else {
$("#name-error").fadeIn();
}
return valid;
}
function validateCourses()
{
var valid = false,
patt = /([A-Z_&]{2,9} \d{3}-\d-\d{2})/gm,
matched = $("#courses").val().match(patt);
if (matched) {
valid = true;
$("#courses").val(matched.join("; "));
$("#matched").html(matched.length);
$("#courses-error").fadeOut();
} else {
$("#courses-error").fadeIn();
}
return valid;
}
</script>
</body>
</html>