-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluate_course.php
138 lines (124 loc) · 5.57 KB
/
evaluate_course.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
<?php
require_once 'includes/config.php';
if(!isset($_SESSION['username']) || empty($_SESSION['username'])){
header("location: login.php");
exit;
}
$courseid = htmlspecialchars($_GET['id']);
$title = htmlspecialchars($_GET['title']);
$recommended = $timespent = $reason = $grade = $gpa = $comment = "";
$recommended_err = $timespent_err = $reason_err = $grade_err = $gpa_err = $comment_err = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty(trim($_POST["recommended"]))) {
$recommended_err = "Please enter a rating.";
}
if (empty(trim($_POST["timespent"]))) {
$timespent_err = "Please enter the time spent.";
}
if (empty(trim($_POST["reason"]))) {
$reason_err = "Please enter a reason for taking the course.";
}
if (empty(trim($_POST["grade"]))) {
$grade_err = "Please enter a grade.";
}
if (empty(trim($_POST["gpa"])) || $_POST["gpa"] < 0 || $_POST["gpa"] > 4) {
$gpa_err = "Please enter a GPA between 0 and 4.0";
}
if (empty(trim($_POST["comment"]))) {
$comment_err = "Please enter a commment.";
}
if (empty($recommended_err) && empty($timespent_err) && empty($reason_err) && empty($grade_err) && empty($gpa_err) && empty($comment_err)) {
$sql = 'INSERT INTO Evaluations (CourseID, UserID, Recommended, TimeSpent, Reason, Grade, GPA, Comment) VALUES (?, ?, ?, ?, ?, ?, ?, ?);';
$userid = $_SESSION["userid"];
$recommended = trim($_POST['recommended']);
$timespent = trim($_POST['timespent']);
$reason = trim($_POST['reason']);
$grade = trim($_POST['grade']);
$gpa = trim($_POST['gpa']);
$comment = trim($_POST['comment']);
if ($stmt = mysqli_prepare($link, $sql)) {
mysqli_stmt_bind_param($stmt, "iiddssds", $courseid, $userid, $recommended, $timespent, $reason, $grade, $gpa, $comment);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
echo "<script> location.href='index.php'; </script>";
exit;
}
}
mysqli_close($link);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Evaluate <?php echo $title; ?></title>
<?php include("includes/header_includes.php"); ?>
</head>
<body>
<div class="page-header">
<h1><span> Evaluate </span> <?php echo $title?></h1>
</div>
<?php include("includes/nav_bar.php"); ?>
<form id="evalform" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]) . "?id=" . $courseid; ?>" method="post">
<div class="left input-container">
<div id="rating" class="display-block">
<div class="form-group <?php echo (!empty($recommended_err)) ? 'has-error' : ''; ?>">
<label>Rating:<sup>*</sup></label><br />
<label class="radio-inline"><input type="radio" name="recommended" value="1">1</label>
<label class="radio-inline"><input type="radio" name="recommended" value="2">2</label>
<label class="radio-inline"><input type="radio" name="recommended" value="3" checked>3</label>
<label class="radio-inline"><input type="radio" name="recommended" value="4">4</label>
<label class="radio-inline"><input type="radio" name="recommended" value="5">5</label>
<span class="help-block"><?php echo $recommended_err; ?></span>
</div>
</div>
<div id="timespent" class="form-group display-block <?php echo (!empty($timespent_err)) ? 'has-error' : ''; ?>">
<label>Hours spent per week:<sup>*</sup></label><br />
<label class="radio-inline"><input type="radio" name="timespent" value="1">1</label>
<label class="radio-inline"><input type="radio" name="timespent" value="5">5</label>
<label class="radio-inline"><input type="radio" name="timespent" value="10" checked>10</label>
<label class="radio-inline"><input type="radio" name="timespent" value="15">15</label>
<label class="radio-inline"><input type="radio" name="timespent" value="20">20+</label>
<span class="help-block"><?php echo $timespent_err; ?></span>
</div>
<div id="reason" class="form-group <?php echo (!empty($reason_err)) ? 'has-error' : ''; ?>">
<label>Reason for taking course:<sup>*</sup></label><br />
<label class="radio-inline"><input type="radio" name="reason" value="For fun" checked>For fun</label>
<label class="radio-inline"><input type="radio" name="reason" value="Required">Required</label>
<span class="help-block"><?php echo $reason_err; ?></span>
</div>
<div id="grade" class="form-group <?php echo (!empty($grade_err)) ? 'has-error' : ''; ?>">
<label for="grade">Grade received:<sup>*</sup></label><br />
<select name="grade" class="form-control">
<option value="A">A</option>
<option>A-</option>
<option>B+</option>
<option>B</option>
<option>B-</option>
<option>C+</option>
<option>C</option>
<option>C-</option>
<option>D+</option>
<option>D</option>
<option>D-</option>
<option>F</option>
</select>
<span class="help-block"><?php echo $grade_err; ?></span>
</div>
<div id="gpa" class="form-group <?php echo (!empty($gpa_err)) ? 'has-error' : ''; ?>">
<label>Current GPA:<sup>*</sup></label>
<input type="text" name="gpa" class="form-control bfh-number" data-min="1" data-max="10" value="<?php echo $gpa; ?>">
<span class="help-block"><?php echo $gpa_err; ?></span>
</div>
<div class="left rt-textarea <?php echo (!empty($comment_err)) ? 'has-error' : ''; ?>">
<textarea name="comment" cols="70" rows="15" form="evalform" placeholder="Please enter a comment.*"></textarea>
<div class="error"><?php echo $comment_err; ?></div>
</div>
<div class="buttons">
<input type="submit" class="btn btn-primary" value="Submit">
<input type="reset" class="btn btn-default" value="Reset">
</div>
</div>
</form>
<!-- <?php include("includes/footer.php"); ?>
-->
</body>