This repository was archived by the owner on Jul 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin_acad_manages_enrollments.php
239 lines (191 loc) · 7.27 KB
/
admin_acad_manages_enrollments.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<?php
include_once 'header.php';
include_once 'check_access_permissions.php';
mustHaveAnyOfTheseRoles( array( 'AWS_ADMIN' ) );
include_once 'database.php';
include_once 'tohtml.php';
include_once 'methods.php';
echo userHTML( );
$year = __get__( $_GET, 'year', getCurrentYear( ) );
$sem = __get__( $_GET, 'semester', getCurrentSemester( ) );
$springChecked = ''; $autumnChecked = '';
if( $sem == 'SPRING' )
{
$springChecked = 'checked';
$autumnChecked = '';
}
else
{
$autumnChecked = 'checked';
$springChecked = '';
}
echo selectYearSemesterForm( $year, $sem );
echo noteWithFAIcon( "Selected semester $sem/$year", 'fa-bell-o' );
// Select semester and year here.
// Get the pervious value, else set them to empty.
$courseSelected = __get__( $_POST, 'course_id', '' );
$taskSelected = __get__( $_POST, 'task', '' );
$runningCourses = array();
foreach( getSemesterCourses( $year, $sem ) as $c )
$runningCourses[ $c[ 'course_id' ] ] = $c;
$runningCoursesSelect = arrayToSelectList(
'course_id'
, array_keys( $runningCourses ), array( )
, false, $courseSelected
);
$taskSelect = arrayToSelectList( 'task'
, array( 'Add enrollment', 'Change enrollment' )
, array( ), false, $taskSelected
);
echo '<h1>Manage Enrollements</h1>';
echo alertUser( "Your are working with semester $sem-$year" );
echo '<form method="post" action="">'; echo
"<table>
<tr>
<th>Select courses</th>
<th>Task</th>
</tr>
<tr>
<td>" . $runningCoursesSelect . "</td>
<td>" . $taskSelect . "</td>
<td><button type=\"submit\">Submit</button>
</tr>
</table>";
echo '</form>';
// Handle request here.
$taskSelected = __get__( $_POST, 'task', '' );
$_POST[ 'semester' ] = $sem;
$_POST[ 'year' ] = $year;
$whereExpr = '';
if( __get__( $_POST, 'course_id', '' ) )
$whereExpr = whereExpr( 'semester,year,course_id', $_POST );
$enrollments = getTableEntries( 'course_registration' ,'student_id', $whereExpr);
if( $taskSelected == '' )
{
echo printWarning( "No task has been selected yet!" );
}
else if( $_POST[ 'task' ] == 'Change enrollment' )
{
echo "<h2>Changing enrollment</h2>";
echo printInfo( "Press in button to change the status of ennrollment." );
$types = getTableColumnTypes( 'course_registration', 'type' );
$i = 0;
echo '<table>';
foreach( $enrollments as $enrol )
{
$i += 1;
echo "<tr><td>$i</td><td>";
echo '<form method="post"
action="admin_acad_manages_enrollments_action.php">';
echo arrayToTableHTML( $enrol, 'info', ''
, 'last_modified_on,grade,grade_is_given_on,status' );
$type = $enrol[ 'type' ];
foreach( $types as $t )
{
if( $t == $type )
continue ;
echo '</td><td><button name="response" value="' . $t
. '">'. $t . '</button>';
}
echo '</td></tr>';
echo '<input type="hidden" name="year" value="' . $enrol[ 'year'] . '" >';
echo '<input type="hidden" name="semester" value="' . $enrol['semester'] . '" >';
echo '<input type="hidden" name="student_id" value="' . $enrol['student_id'] . '" >';
echo '<input type="hidden" name="course_id" value="' . $enrol['course_id'] . '" >';
echo '</form>';
}
echo '</table>';
}
else if( $_POST[ 'task' ] == 'Add enrollment' )
{
$course = $_POST[ 'course_id' ] ;
$cname = getCourseName( $course );
echo "<h2> Adding new enrollments to $cname ($sem/$year) </h2>";
$form = '<form method="post" action="admin_acad_manages_enrollments_action.php">';
$form .= '<table>';
$form .= '<tr><td>';
$form .= '<textarea cols="30" rows="4" name="logins" placeholder="gabbar@ncbs.res.in kalia@instem.res.in"></textarea>';
$form .= '</td><td>';
$form .= arrayToSelectList( 'type', array( 'CREDIT', 'AUDIT' )
, array( 'CREDIT' ,'AUDIT' ), false, 'CREDIT' );
// Add semester and year as hidden input.
$form .= ' <input type="hidden" name="year" id="" value="' . $year . '" />';
$form .= ' <input type="hidden" name="semester" id="" value="' . $sem . '" />';
$form .= '</td><td>';
$form .= '<button type="submit" name="response" value="enroll_new">Enroll</button>';
$form .= '</td></tr>';
$form .= '</table>';
$form .= '<input type="hidden" name="course_id" value="' . $course . '">';
$form .= '</form>';
echo $form;
}
else
echo printInfo( "Unsupported task " . $_POST[ 'task' ] );
echo goBackToPageLink( 'admin_acad.php', 'Go back' );
echo "<h1>All enrollments for $sem/$year</h1>";
$enrolls = getTableEntries( 'course_registration', 'course_id'
, "status='VALID' AND year='$year' AND semester='$sem'"
);
$courseMap = array( );
foreach( $enrolls as $e )
$courseMap[$e['course_id']][] = $e;
foreach( $courseMap as $cid => $enrolls )
{
if( ! $cid )
continue;
$cname = getCourseName( $cid );
echo "<h2> ($cid) $cname </h2>";
// Create a form to add new registration.
$table = ' <table border="0">';
$table .= '<tr>
<td> <textarea cols="40" rows="3" name="enrollments"
placeholder="gabbar@ncbs.res.in:CREDIT
kalia@instem.res.in:AUDIT"></textarea> </td>
<td> <button name="response" value="quick_enroll"
title=\'Use "email:CREDIT" or "email:AUDIT" or "email:DROPPED" format.\'
>Quick Enroll</button> </td>
</tr>';
$table .= '</table>';
// Display form
$form = '<div id="show_hide_div">';
$form .= '<form action="admin_acad_manages_enrollments_action.php" method="post" accept-charset="utf-8">';
$form .= $table;
$form .= '<input type="hidden" name="course_id" value="' . $cid . '" />';
$form .= '<input type="hidden" name="year" value="' . $year . '" />';
$form .= '<input type="hidden" name="semester" value="' . $sem . '" />';
$form .= '</form>';
$form .= '</div>';
echo $form;
echo ' <br /> ';
echo '<table class="tiles">';
echo '<tr>';
echo ' <strong>Enrollement Table</strong> ';
foreach( $enrolls as $i => $e )
{
$student = $e[ 'student_id'];
$dropForm = '
<form action="admin_acad_manages_enrollments_action.php" method="post" accept-charset="utf-8">
<button class="show_as_link" name="response" value="drop_course"
title="Drop course"> <i class="fa fa-tint fa-1x"></i>
</button>
<input type="hidden" name="course_id" id="" value="' . $cid . '" />
<input type="hidden" name="year" value="' . $year . '" />
<input type="hidden" name="semester" value="' . $sem . '" />
<input type="hidden" name="student_id" value="' . $student . '" />
</form>
';
$sname = arrayToName( getLoginInfo( $student ) );
$grade = $e[ 'grade' ];
$type = $e[ 'type'];
// If grade is assigned, you can't drop the course.
if( $grade )
$dropForm = '';
echo "<td> $sname ($student) <br /> $type <br /> $grade $dropForm </td>";
if( ($i+1) % 4 == 0 )
echo '</tr><tr>';
}
echo '</tr>';
echo '</table>';
}
echo '<br />';
echo goBackToPageLink( 'admin_acad.php', 'Go back' );
?>