-
Notifications
You must be signed in to change notification settings - Fork 1
/
studentProfile.php
134 lines (125 loc) · 4.68 KB
/
studentProfile.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
<?php
require_once("connectDB.php");
require_once("addPDF.php");
require_once("htmlStructure.php");
if(session_status() == PHP_SESSION_NONE) session_start();
$db = connectToDB();
$entry = $_SESSION["studentProfile"];
$courses = getCourses($db);
$coursesBody = buildCoursesHTML($courses);
$studentBodyData = "";
if(isset($_SESSION["student"])){
$studentBodyData =<<< EODATA
<div class="form-group">
<h3>Choose courses to TA:</h3><br>
<div class="form-group">
$coursesBody
</div>
<input type="submit" name="coursesToTutor" value="Submit Intended Courses"/>
</div>
<div class="form-group">
<h3>Upload student documents:</h3><br>
<div class="row">
<div class="col-md-2">Unofficial Transcript</div>
<div class="col-md-3"><input type="file" name="transcriptFileName" accept=".pdf"></div>
</div>
<br>
<div class="form-group">
<input type="submit" name="submitDocuments" value="Submit Documents">
</div>
</div>
EODATA;
}
$body =<<< EOBODY
<form class="form-group" method="get">
<div class="form-group">
<h1>{$entry["fName"]} {$entry["lName"]}</h1>
</div>
<div class="form-group">
<h3>Personal Information</h3><br>
<div class="row">
<div class="col-md-2">Email:</div>
<div class="col-md-3">{$entry["email"]}</div>
</div>
<div class="row">
<div class="col-md-2">University ID:</div>
<div class="col-md-3">{$entry["uid"]}</div>
</div>
<div class="row">
<div class="col-md-2">GPA:</div>
<div class="col-md-3">{$entry["gpa"]}</div>
</div>
<div class="row">
<div class="col-md-2">Previous Experience as TA:</div>
<div class="col-md-3">{$entry["taB4"]}</div>
</div>
<div class="row">
<div class="col-md-2">Number of Semesters TA'd:</div>
<div class="col-md-3">{$entry["numOfSemesters"]}</div>
</div>
<div class="row">
<div class="col-md-2">Student Level:</div>
<div class="col-md-3">{$entry["grad"]}</div>
</div>
</div>
$studentBodyData
</form>
EOBODY;
if(isset($_GET["submitDocuments"])){
if(isset($_GET["transcriptFileName"])){
$transcriptFile = $_GET["transcriptFileName"];
addTrans($transcriptFile, $entry["email"]);
}
}
if(isset($_GET["coursesToTutor"])){
$chosenCourses = [];
foreach($courses as $course){
if(isset($_GET[$course])){
array_push($chosenCourses, substr($course, 4));
}
}
$coursesAsString = (count($chosenCourses) > 0) ? implode(",",$chosenCourses) : NULL;
// Now that we have the chosen courses, the student table can be updated.
$table = "studenttable";
$field = "courseIDs";
$email = $entry["email"];
$query = "update $table set courseIDs='$coursesAsString' where email='$email'";
$result = $db->query($query);
if (!$result) {
die("Update failed: ". $db->error);
}
}
function getCourses($db){
$table = "coursetable";
$query = "select course from $table";
$result = $db->query($query);
$courses = [];
if (!$result) {
die("Retrieval failed: ". $db->error);
} else if($result->num_rows == 0) {
echo "No course entries exist in the database.";
} else {
$num_rows = $result->num_rows;
for ($row_index = 0; $row_index < $num_rows; $row_index++) {
$result->data_seek($row_index);
$row = $result->fetch_array(MYSQLI_ASSOC);
array_push($courses, "CMSC" . $row["course"]);
}
}
$courses = array_unique($courses);
return $courses;
}
function buildCoursesHTML($courses){
$body = "";
foreach((array) $courses as $course){
$boxes = keepBoxesChecked($course);
$body .= "$course <input type='checkbox' name=$course $boxes /><br>";
}
return $body;
}
function keepBoxesChecked($course){
if(isset($_GET[$course])){
return "checked";
} else "";
}
echo generatePage($body);