session_name('kms'); session_unset(); session_destroy(); } elseif (username_existed($_SESSION['username'])) { session_name('kms'); session_start(); } /* End Auth */ $p = isset($_GET['p']) ? rawurldecode($_GET['p']) : 'home'; $pid = get_pid_from_url($p); $uid = substr($p, 5); $username = get_username_from_url($p); $week = get_week_from_url($p); $course_week = get_course_week_from_url($p); $cid = isset($course_week) ? $course_week['cid'] : (isset($_POST['cid']) ? $_POST['cid'] : get_cid_from_url($p)); $cids = $_SESSION['rid'] == 1 ? cids_load_all() : user_cids_load_all($_SESSION['uid']); $pids = user_pids_load_all($_SESSION['uid']); $user = user_load($_SESSION['uid']); $post = post_load($pid); $course = course_load($cid); $users = $db->array_load_all('USER'); $user_paths = array(); for ($i = 0; $i < count($users); $i++) { $user_paths[$i] = 'user/' . $users[$i]['User_ID']; } $profile_paths = array(); for ($i = 0; $i < count($users); $i++) { $profile_paths[$i] = 'user/' . $users[$i]['User_Username']; } $profile_follow_paths = array(); for ($i = 0; $i < count($users); $i++) {
function list_courses() { //Return list of courses, for admin use global $db; $output = ''; $courses = $db->array_load_all('COURSE'); $cids = user_cids_load_all($_SESSION['uid']); $output .= $_SESSION['rid'] == 1 ? '<a class="button" href="?p=course/create">Create course</a>' : ''; $output .= '<table>'; $output .= '<tr><th>Course code</th><th>Course name</th><th>Lecturers</th><th colspan="8">Operations</th></tr>'; $j = 0; for ($i = 0; $i < count($courses); $i++) { $cid = $courses[$i]['Course_ID']; if (isset($_SESSION['rid']) && $_SESSION['rid'] == 1 || in_array($cid, $cids)) { $class = 'class="' . table_row_class($j) . '"'; $output .= '<tr ' . $class . '>'; $output .= '<td class="center">' . $courses[$i]['Course_Code'] . '</td>'; $output .= '<td>' . $courses[$i]['Course_Name'] . '</td>'; $output .= '<td>' . view_course_lecturers($cid) . '</td>'; $output .= isset($_SESSION['rid']) && $_SESSION['rid'] == 3 && in_array($cid, $cids) ? '<td class="center"><form action="?p=course/enrol" method="post"><input type="hidden" name="cid" value="' . $cid . '" /><input type="submit" name="course_enrol" title="Enrol students manually" value="Enrol students manually" /></form></td><td class="center"><form action="?p=course/csv" method="post"><input type="hidden" name="cid" value="' . $cid . '" /><input type="submit" name="course_csv" title="Enrol students by importer" value="Enrol students by importer" /></form></td><td class="center"><form action="triggers/course_post_allow.php" method="post"><input type="hidden" name="cid" value="' . $cid . '" /><input type="submit" name="' . ($courses[$i]['Course_Allowed'] == 1 ? 'course_allow' : 'course_not_allow') . '" title="' . ($courses[$i]['Course_Allowed'] == 0 ? 'Allow' : 'Not allow') . ' post" value="' . ($courses[$i]['Course_Allowed'] == 0 ? 'Allow' : 'Not allow') . ' post" /></form></td><td class="center"><form action="triggers/course_for_guest.php" method="post"><input type="hidden" name="cid" value="' . $cid . '" /><input type="submit" name="' . ($courses[$i]['Course_For_Guest'] == 1 ? 'course_guest_on' : 'course_guest_off') . '" title="' . ($courses[$i]['Course_For_Guest'] == 0 ? 'Turn on' : 'Turn off') . ' guest mode" value="' . ($courses[$i]['Course_For_Guest'] == 0 ? 'Turn on' : 'Turn off') . ' guest mode" /></form></td>' : '<td class="empty"></td><td class="empty"></td>'; $output .= isset($_SESSION['rid']) && ($_SESSION['rid'] == 3 && $_SESSION['uid'] == $courses[$i]['User_ID'] && in_array($cid, $cids)) || $_SESSION['rid'] == 1 ? '<td class="center"><form action="?p=course/assign" method="post"><input type="hidden" name="cid" value="' . $cid . '" /><input type="submit" name="course_assign" title="Assign lecturers" value="Assign lecturers" /></form></td>' : '<td class="empty"></td>'; $output .= isset($_SESSION['rid']) && $_SESSION['rid'] == 1 && count_lecturers($cid) > 0 ? '<td class="center"><form action="?p=course/promote" method="post"><input type="hidden" name="cid" value="' . $cid . '" /><input type="submit" name="course_promote" title="Promote coordinator" value="Promote coordinator" /></form></td>' : '<td class="empty"></td>'; $output .= isset($_SESSION['rid']) && ($_SESSION['rid'] == 3 && $_SESSION['uid'] == $courses[$i]['User_ID'] && in_array($cid, $cids)) || $_SESSION['rid'] == 1 ? '<td class="center"><form method="POST" action="?p=course/edit"><input type="hidden" name="cid" value="' . $cid . '" /><input type="hidden" name="code" value="' . $courses[$i]['Course_Code'] . '" /><input type="hidden" name="name" value="' . $courses[$i]['Course_Name'] . '" /><input name="course_edit" type="submit" title="Edit" value="Edit"/></form></td>' : '<td class="empty"></td>'; $output .= isset($_SESSION['rid']) && $_SESSION['rid'] == 1 ? '<td class="center"><form method="POST" action="?p=course/delete"><input type="hidden" name="cid" value="' . $cid . '" /><input name="course_delete" type="submit" title="Delete" value="Delete"/></form></td>' : '<td class="empty"></td>'; $output .= '</tr>'; $j++; } } $output .= '</table>'; $output .= '<span class="count" colspan="8">' . $j . ' course' . ($j > 1 ? 's' : '') . ' to display.</span>'; return $output; }