-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadd_student_course.php
139 lines (138 loc) · 6.54 KB
/
add_student_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
139
<!--Allows user to add course for student -->
<?php
$title = 'IDCP - Add Course for Student';
$page = 'student';
$page_name = 'add_stu_crs';
require('includes/header.php');
# Connect to MySQL server and the database
require( 'includes/connect_db_c9.php' ) ;
# Includes these helper functions
require( 'includes/student_helpers.php' ) ;
# Check to make sure it is the first time user is visiting the page
if ($_SERVER['REQUEST_METHOD'] == 'GET'){
$crs_name = "";
$crs_enroll_start = "";
$credit = "";
//Regular user cannot access this page
if($user_role == "User"){
$page = 'home.php';
header("Location: $page");
}
}
# Check to make sure the form method is post
if ($_SERVER[ 'REQUEST_METHOD' ] == 'POST') {
$crs_name = $_POST['crs_name'];
//This is actually the course name, not the ID
$crs_pieces = explode(" ", $crs_name);
$crs_id = $crs_pieces[0];
$crs_enroll_start = $_POST['crs_enroll_start'];
$credit = $_POST['credit'];
$stu_id = $_SESSION['stu_id'];
$query = "SELECT * FROM CRS_ENROLLED WHERE STU_ID = $stu_id AND CRS_ID = '$crs_id' AND CRS_ENROLL_STATUS='Active'";
$results = mysqli_query($dbc, $query);
if(mysqli_num_rows( $results ) != 0 ){
?>
<div class="alert alert-danger alert-dismissible" role="alert" style="margin-top: 20px">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<strong>Error!</strong> Student is already taking this course. Please add a different one.
</div>
<?php
}
else{
$result = insert_record_crs_enrolled($dbc, $credit, $crs_enroll_start, $crs_id, $stu_id);
echo "Success! Thanks" ;
$_SESSION['addedCourse'] = true;
$page = 'add_student_course_home.php';
header("Location: $page");
}
}
# Close the connection
mysqli_close( $dbc ) ;
?>
<!-- Page Content -->
<div id="page-content-wrapper">
<div class="container-fluid">
<div class="dropdown">
<div class="page-header">
<?php
$stu_id = $_SESSION['stu_id'];
$name = get_stu_name($dbc, $stu_id);
echo '<h1>Add a Course for ' . "$name" . '</h1>';
?>
</div>
<form action="add_student_course.php" method="POST" class="form-horizontal" role="form" data-toggle="validator">
<div class="form-group">
<label class="col-xs-3 control-label"></label>
<div class="col-xs-5">
<h3>Enrollment Information</h3>
</div>
</div>
<div class="form-group">
<label class="col-xs-3 control-label">Course Name*</label>
<div class="col-xs-3">
<select class="form-control" id="sel1" name="crs_name" value="<?php if (isset($_POST['crs_name'])) echo $_POST['crs_name'];?>" data-error="Please select the course name" required>
<option disabled selected value>-- select an option --</option>
<?php
require( 'includes/connect_db_c9.php' ) ;
$query = 'SELECT CRS_ID, CRS_NAME FROM COURSE ORDER BY CRS_ID';
$results = mysqli_query($dbc, $query);
if($results){
while ( $row = mysqli_fetch_array( $results , MYSQLI_ASSOC ) )
{
echo '<option>' . $row['CRS_ID'] . " " . $row['CRS_NAME'] . '</option>' ;
}
}
else
{
echo '<p>' . mysqli_error( $dbc ) . '</p>' ;
}
# Free up the results in memory
mysqli_free_result( $results );
mysqli_close( $dbc ) ;
?>
</select>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="form-group">
<label class="col-xs-3 control-label" for="crs_enroll_start">Start Date*</label>
<div class="col-xs-3">
<input type="date" class="form-control" id="crs_enroll_start" name="crs_enroll_start" data-error="Please select the student's start date in the course" required>
</div>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label class="col-xs-3 control-label">Taking for Credit?*</label>
<div class="col-xs-2">
<select class="form-control" id="sel1" name="credit" value="<?php if (isset($_POST['credit'])) echo $_POST['credit'];?>" data-error="Please select if the student is taking the course for credit" required>
<option disabled selected value>--</option>
<option>Yes</option>
<option>No</option>
</select>
</div>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<div class="col-xs-5 col-xs-offset-3">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
<button type="button" class="btn btn-default" onclick ="location.href='add_student_course_home.php';">Back to Add Course</button>
</form>
</div>
<!-- dropdown -->
</div>
<!-- /#container -->
</div>
<!-- /#page-content-wrapper -->
<!--Footer-->
<?php require('includes/footer.php'); ?>
</div>
<!-- jQuery -->
<script src="js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
<!-- Validator Bootstrap Plugin-->
<script src="js/validator.js"></script>
</body>
</html>