This repository has been 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_current_courses.php
159 lines (128 loc) · 5.04 KB
/
admin_acad_manages_current_courses.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
<?php
include_once 'database.php';
include_once 'tohtml.php';
include_once 'methods.php';
include_once 'check_access_permissions.php';
mustHaveAnyOfTheseRoles( array( 'AWS_ADMIN' ) );
echo userHTML( );
$sem = getCurrentSemester( );
$year = getCurrentYear( );
$action = 'Add';
// Get the list of all courses. Admin will be asked to insert a course into
// database.
$allCourses = getTableEntries( 'courses_metadata', 'name' );
$coursesId = array_map( function( $x ) { return $x['id']; }, $allCourses );
asort( $coursesId );
$slotMap = getSlotMap( );
$coursesMap = array( );
foreach( $allCourses as $c )
$coursesMap[ $c[ 'id' ] ] = $c[ 'name' ];
$courseIdsSelect = arrayToSelectList( 'course_id', $coursesId, $coursesMap );
$venues = getTableEntries( 'venues', '', "type='LECTURE HALL'" );
$venueSelect = venuesToHTMLSelect( $venues );
$slotSelect = arrayToSelectList( 'slot', array_keys($slotMap), $slotMap );
// Running course for this semester.
$nextSem = getNextSemester( );
$runningCourses = getSemesterCourses( $year, $sem );
$nextSemCourses = getSemesterCourses( $nextSem[ 'year' ], $nextSem[ 'semester' ] );
$runningCourses = array_merge( $runningCourses, $nextSemCourses );
// Auto-complete for JS.
$runningCourseMapForAutoCompl = [ ];
foreach( $runningCourses as $x )
$runningCourseMapForAutoCompl[ $x['id'] . ': '
. getCourseName( $x[ 'course_id' ] ) ] = $x['id'];
// Array to hold runnig course.
$default = array(
'venue' => $venueSelect
, 'semester' => $sem
, 'year' => $year
, 'course_id' => $courseIdsSelect
);
// running course returned from autocomplete has extra information. Use the map
// to add another parameter in $_POST 'running_course_id' which is used to get
// the real course id.
if( $_POST && array_key_exists( 'running_course', $_POST ) )
{
$_POST[ 'running_course_id' ] = $runningCourseMapForAutoCompl[ $_POST[ 'running_course' ] ];
$runningCourse = getTableEntry(
'courses', 'id'
, array( 'id' => $_POST[ 'running_course_id' ] )
);
if( $runningCourse )
$default = array_merge( $default, $runningCourse );
$action = 'Edit';
}
$runningCoursesHTML = "<h1>Running courses in $sem, $year</h1>";
$runningCoursesHTML .= '<table class="info sortable">';
$tobefilterd = 'id,semester,year';
$runningCoursesHTML .= arrayHeaderRow( $runningCourses[0], 'info', $tobefilterd );
foreach( $runningCourses as $course )
{
$cname = getCourseName( $course[ 'course_id'] );
$course[ 'course_id' ] = '<strong>'. $course['course_id'] . '</strong><br> ' . $cname;
if( isCourseActive( $course ) )
$course[ 'course_id' ] = "<blink> $symbBell </blink>" . $course[ 'course_id' ];
$runningCoursesHTML .= '<tr>';
$runningCoursesHTML .= arrayToRowHTML( $course, 'aws', $tobefilterd, true, false );
$runningCoursesHTML .= '<td>
<form action="#" method="post" accept-charset="utf-8">
<button type="submit" value="Edit">Edit</button>
<input type="hidden" name="running_course" value="' .
$course[ 'id' ] . ': ' . $cname . '" />
</form>
</td>';
$runningCoursesHTML .= '</tr>';
}
$runningCoursesHTML .= '</table>';
echo $runningCoursesHTML;
/* --------------------------------------------------------------------------*/
/**
* @Synopsis Ask user which course to edit/update.
*/
/* ----------------------------------------------------------------------------*/
echo "</br>";
if( $action == 'Add' )
{
echo "<h1>Add a course to running courses list</h1>";
}
else
echo "<h1>Edit following course </h1>";
echo '<form method="post" action="admin_acad_manages_current_courses_action.php">';
$default[ 'slot' ] = $slotSelect;
$default[ 'venue' ] = $venueSelect;
$default[ 'semester' ] = $sem;
if( __get__( $_POST, 'running_course', '') )
{
$action = 'Update';
$course = getTableEntry( 'courses', 'id', array( 'id' => $_POST[ 'running_course_id' ]) );
$default[ 'semester' ] = $sem;
// Select the already assigned venue.
$venueSelect = venuesToHTMLSelect( $venues, false, 'venue', array( $course[ 'venue' ] ) );
$default[ 'venue' ] = $venueSelect;
// We show all venues and slots because some combination of (venue,slot) may
// be available. When updating the course we check for it. It can be fixed
// by adding a javascript but for now lets admin feel the pain.
$slotSelect = arrayToSelectList( 'slot'
, array_keys($slotMap), $slotMap
, false, $course['slot']
);
$default[ 'slot' ] = $slotSelect;
}
else
$action = 'Add';
echo dbTableToHTMLTable( 'courses'
, $default
, 'start_date,end_date,slot,venue,note,url,ignore_tiles,course_id', $action, ''
);
/* If we are updating, we might also like to remove the entry. This button also
* appears. Admin can remove the course schedule.
*/
if( $action == 'Update' )
echo '<button name="response" onclick="AreYouSure(this)"
title="Remove this course from running courses."
>' .
$symbDelete . '</button>';
echo '</form>';
echo "<br/><br/>";
echo goBackToPageLink( 'admin_acad.php', 'Go back' );
?>