function view_courses_by_uid($uid) { //Return courses list by user ID $output = ''; $course_user_cids = array(); $courses = array(); $course_users = course_users_load($uid); foreach ($course_users as $course_user) { $course_user_cids[] = $course_user['Course_ID']; } if ($_SESSION['rid'] == 1) { $course_user_cids = cids_load_all(); } sort($course_user_cids); foreach ($course_user_cids as $course_user_cid) { $courses[] = course_load($course_user_cid); } usort($courses, 'sort_course_code_ascend'); if (count($courses) > 0) { $output .= '<div class="heading">My courses</div>'; $output .= '<ul>'; for ($i = 0; $i < count($courses); $i++) { if (isset($courses[$i])) { $course = course_load($courses[$i]['Course_ID']); $users = users_load_by_cid($courses[$i]['Course_ID']); $output .= '<li class="course">'; $output .= '<a title="' . $course['Course_Name'] . '" class="cid-' . $course['Course_ID'] . ' course_code" href="?p=course/' . $course['Course_Code'] . '">' . $course['Course_Code'] . '</a><br/>'; $output .= '<span class="course_name">' . $course['Course_Name'] . '</span>'; $output .= '</li>'; } } $output .= '</ul>'; } return $output; }
<?php $cid = isset($_POST['cid']) ? $_POST['cid'] : ''; $course = course_load($cid); $users = users_load_by_cid($cid); $users_diff = array(); $uids = uids_load_all_by_rid(3); $course_uids = uids_load_from_cid($cid); $diff_uids = array_diff($uids, $course_uids); foreach ($diff_uids as $diff_uid) { $user_diff = user_load($diff_uid); $users_diff[] = $user_diff; } $users = array_filter($users, array(new filter('3'), 'filter_rid')); $users_diff = array_filter($users_diff, array(new filter('3'), 'filter_rid')); $users_label = 'lecturers'; sort($users); sort($users_diff); $to_uids = isset($_POST['toBox']) ? $_POST['toBox'] : array(); $from_uids = isset($to_uids) ? array_diff($uids, $to_uids) : $uids; sort($from_uids); sort($to_uids); if (isset($_POST['submit'])) { foreach ($from_uids as $from_uid) { delete_course_user($cid, $from_uid); } if (isset($to_uids)) { foreach ($to_uids as $to_uid) { delete_course_user($cid, $to_uid); create_course_user($cid, $to_uid); }