function course_belonged($cid, $uid) { $uids = uids_load_from_cid($cid); if (in_array($uid, $uids)) { return true; } else { return false; } }
<?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); }