2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay & Joel Kronenberg */
6 /* Adaptive Technology Resource Centre / University of Toronto */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /****************************************************************/
14 if (!defined('AT_INCLUDE_PATH')) { exit; }
16 if (isset($_POST['enroll'])) {
18 $msg->addError('NO_STUDENT_SELECTED');
19 $_GET['tab'] = $_POST['tab'];
22 foreach ($_POST['id'] as $elem) {
23 $text .= 'id'.$i.'='.$elem.SEP;
26 header('Location: enroll_edit.php?'.$text.'func=enroll'.SEP.'tab=0'.SEP.'course_id='.$course_id);
29 } else if (isset($_POST['unenroll'])) {
30 // different from a plain delete. This removes from groups as well.
32 $msg->addError('NO_STUDENT_SELECTED');
33 $_GET['tab'] = $_POST['tab'];
36 foreach ($_POST['id'] as $elem) {
37 $text .= 'id'.$i.'='.$elem.SEP;
40 header('Location: enroll_edit.php?'.$text.'func=unenroll'.SEP.'tab=1'.SEP.'course_id='.$course_id);
43 } else if (isset($_POST['role'])) {
45 $msg->addError('NO_STUDENT_SELECTED');
46 $_GET['tab'] = $_POST['tab'];
49 foreach ($_POST['id'] as $elem) {
50 $text .= 'mid'.$i.'='.$elem.SEP;
53 header('Location: privileges.php?'.$text.SEP.'course_id='.$course_id);
56 } else if (isset($_POST['alumni'])) {
58 $msg->addError('NO_STUDENT_SELECTED');
59 $_GET['tab'] = $_POST['tab'];
62 foreach ($_POST['id'] as $elem) {
63 $text .= 'id'.$i.'='.$elem.SEP;
66 header('Location: enroll_edit.php?'.$text.'func=alumni'.SEP.'tab=2'.SEP.'course_id='.$course_id);
73 if ($_GET['reset_filter']) {
79 if (isset($_GET['role']) && ($_GET['role'] != '')) {
80 $filter['role'] = intval($_GET['role']);
83 if (isset($_GET['status']) && ($_GET['status'] != '')) {
84 $filter['status'] = intval($_GET['status']);
87 if (isset($_GET['group']) && ($_GET['group'] != '')) {
88 $filter['group'] = intval($_GET['group']);
91 require(AT_INCLUDE_PATH.'html/enroll_tab_functions.inc.php');
96 $num_tabs = count($tabs);
98 for ($i=0; $i < $num_tabs; $i++) {
99 if (isset($_POST['button_'.$i]) && ($_POST['button_'.$i] != -1)) {
101 $_POST['current_tab'] = $i;
106 //get present tab if specified
107 if ($_GET['current_tab']) {
108 $current_tab = $_GET['current_tab'];
109 $_POST['current_tab'] = $_GET['current_tab'];
112 $orders = array('asc' => 'desc', 'desc' => 'asc');
113 $cols = array('login' => 1, 'first_name' => 1, 'second_name' => 1, 'last_name' => 1, 'email' => 1);
115 if (isset($_GET['asc'])) {
117 $col = isset($cols[$_GET['asc']]) ? $_GET['asc'] : 'login';
118 } else if (isset($_GET['desc'])) {
120 $col = isset($cols[$_GET['desc']]) ? $_GET['desc'] : 'login';
126 $view_select = intval($_POST['view_select']);
128 // the possible tabs. order matters.
129 $tabs = array('enrolled', 'assistants', 'alumni', 'pending_enrollment', 'not_enrolled');
132 // Remove Not Enrolled tab if system preference is turned off 1.6.2
133 if($_config['allow_instructor_registration'] != 1){
137 $num_tabs = count($tabs);
138 if (isset($_REQUEST['tab'])) {
139 $current_tab = intval($_REQUEST['tab']);
142 if (!isset($current_tab)) {
146 if (isset($_GET['match']) && $_GET['match'] == 'one') {
147 $checked_match_one = ' checked="checked"';
148 $page_string .= SEP.'match=one';
150 $_GET['match'] = 'all';
151 $checked_match_all = ' checked="checked"';
152 $page_string .= SEP.'match=all';
155 if (admin_authenticate(AT_ADMIN_PRIV_ENROLLMENT, TRUE)) {
156 $page_string .= SEP.'course_id='.$course_id;
159 if ($_GET['search']) {
160 $page_string .= SEP.'search='.urlencode($_GET['search']);
161 $search = $addslashes($_GET['search']);
162 $search = explode(' ', $search);
164 if ($_GET['match'] == 'all') {
171 foreach ($search as $term) {
173 $term = str_replace(array('%','_'), array('\%', '\_'), $term);
175 $term = '%'.$term.'%';
176 $sql .= "((M.first_name LIKE '$term') OR (M.second_name LIKE '$term') OR (M.last_name LIKE '$term') OR (M.email LIKE '$term') OR (M.login LIKE '$term')) $predicate";
179 $sql = '('.substr($sql, 0, -strlen($predicate)).')';
185 $instructor_id = $system_courses[$course_id]['member_id'];
186 // retrieve all the members of this course (used later to get all those who aren't in this course)
187 $course_enrollment = get_group_concat('course_enrollment', 'member_id', "course_id=$course_id AND member_id<>$instructor_id");
188 $course_enrollment .= ','.$instructor_id;
190 $tab_counts = array();
191 $tab_sql_counts = array();
192 $tab_sql_counts[0] = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."course_enrollment CE INNER JOIN ".TABLE_PREFIX."members M USING (member_id) WHERE CE.course_id=$course_id
193 AND CE.approved='y' AND M.member_id<>$instructor_id AND CE.privileges=0 AND $search";
194 $tab_sql_counts[1] = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."course_enrollment CE INNER JOIN ".TABLE_PREFIX."members M USING (member_id) WHERE CE.course_id=$course_id
195 AND CE.approved='y' AND CE.privileges>0 AND $search";
196 $tab_sql_counts[2] = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."course_enrollment CE INNER JOIN ".TABLE_PREFIX."members M USING (member_id) WHERE CE.course_id=$course_id
197 AND approved='a' AND $search";
198 $tab_sql_counts[3] = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."course_enrollment CE INNER JOIN ".TABLE_PREFIX."members M USING (member_id) WHERE CE.course_id=$course_id
199 AND approved='n' AND $search";
200 $tab_sql_counts[4] = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."members M WHERE M.status>1 AND M.member_id NOT IN ($course_enrollment) AND $search";
202 foreach ($tab_sql_counts as $tab => $sql) {
203 if ($tab == 3 && $system_courses[$course_id]['access'] != 'private') {
204 $tab_counts[$tab] = 0;
206 $result = mysql_query($sql);
207 $row = mysql_fetch_assoc($result);
208 $tab_counts[$tab] = $row['cnt'];
213 if ($current_tab == 0) {
215 $sql = "SELECT CE.member_id, CE.privileges, CE.approved, M.login, M.first_name, M.second_name, M.last_name, M.email
216 FROM ".TABLE_PREFIX."course_enrollment CE INNER JOIN ".TABLE_PREFIX."members M USING (member_id)
217 WHERE CE.course_id=$course_id AND approved='y' AND M.member_id<>$instructor_id AND CE.privileges=0 AND $search
218 ORDER BY $col $order";
219 } else if ($current_tab == 1) {
221 $sql = "SELECT CE.member_id, CE.approved, CE.privileges, M.login, M.first_name, M.second_name, M.last_name, M.email
222 FROM ".TABLE_PREFIX."course_enrollment CE INNER JOIN ".TABLE_PREFIX."members M USING (member_id)
223 WHERE CE.course_id=$course_id AND CE.approved='y' AND CE.privileges>0 AND $search
224 ORDER BY $col $order";
226 } else if ($current_tab == 3) {
228 if ($system_courses[$course_id]['access'] == 'private') {
229 $sql = "SELECT CE.member_id, CE.approved, CE.privileges, M.login, M.first_name, M.second_name, M.last_name, M.email
230 FROM ".TABLE_PREFIX."course_enrollment CE INNER JOIN ".TABLE_PREFIX."members M USING (member_id)
231 WHERE CE.course_id=$course_id AND approved='n' AND $search
232 ORDER BY $col $order";
234 // not sure what this is about
235 // $sql_cnt = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."members WHERE 0";
236 $sql = "SELECT login FROM ".TABLE_PREFIX."members WHERE 0";
238 } else if ($current_tab == 2) {
240 $sql = "SELECT CE.member_id, CE.approved, CE.privileges, M.login, M.first_name, M.second_name, M.last_name, M.email
241 FROM ".TABLE_PREFIX."course_enrollment CE INNER JOIN ".TABLE_PREFIX."members M USING (member_id)
242 WHERE CE.course_id=$course_id AND approved='a' AND $search
243 ORDER BY $col $order";
244 } else { // current_tab == 4
246 // $sql_cnt= "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."members M WHERE M.status>1 AND M.member_id NOT IN ($course_enrollment) AND $search";
248 $sql = "SELECT M.member_id, M.login, M.first_name, M.second_name, M.last_name, M.email FROM ".TABLE_PREFIX."members M WHERE M.member_id NOT IN ($course_enrollment) AND M.status>1 AND $search ORDER BY $col $order";
251 $results_per_page = 50;
253 $num_pages = max(ceil($tab_counts[$current_tab] / $results_per_page), 1);
254 $page = intval($_GET['p']);
258 $count = (($page-1) * $results_per_page) + 1;
259 $offset = ($page-1)*$results_per_page;
260 $sql .= " LIMIT $offset, $results_per_page";
262 $enrollment_result = mysql_query($sql, $db);
263 $page_string_w_tab = $page_string . SEP . 'tab='.$current_tab;
264 require(AT_INCLUDE_PATH.'header.inc.php');
268 <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
269 <input type="hidden" name="tab" value="<?php echo $current_tab; ?>"/>
270 <input type="hidden" name="course_id" value="<?php echo $course_id; ?>"/>
271 <div class="input-form">
272 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('search'); ?></legend>
273 <?php if (admin_authenticate(AT_ADMIN_PRIV_ENROLLMENT, TRUE)): ?>
275 <label for="course"><?php echo _AT('course'); ?></label><br/>
276 <select name="course_id" id="course">
278 $sql = "SELECT course_id, title FROM ".TABLE_PREFIX."courses ORDER BY title";
279 $result = mysql_query($sql, $db);
280 while ($courses_row = mysql_fetch_assoc($result)) {
281 if ($courses_row['course_id'] == $course_id) {
282 echo '<option value="'.$courses_row['course_id'].'" selected="selected">'.validate_length($courses_row['title'], 45,VALIDATE_LENGTH_FOR_DISPLAY).'</option>';
284 echo '<option value="'.$courses_row['course_id'].'">'.validate_length($courses_row['title'],45,VALIDATE_LENGTH_FOR_DISPLAY).'</option>';
292 <label for="search"><?php echo _AT('search'); ?> (<?php echo _AT('login_name').', '._AT('first_name').', '._AT('second_name').', '._AT('last_name') .', '._AT('email'); ?>)</label><br />
293 <input type="text" name="search" id="search" size="40" value="<?php echo htmlspecialchars($_GET['search']); ?>" />
295 <?php echo _AT('search_match'); ?>:
296 <input type="radio" name="match" value="all" id="match_all" <?php echo $checked_match_all; ?> /><label for="match_all"><?php echo _AT('search_all_words'); ?></label> <input type="radio" name="match" value="one" id="match_one" <?php echo $checked_match_one; ?> /><label for="match_one"><?php echo _AT('search_any_word'); ?></label>
299 <div class="row buttons">
300 <input type="submit" name="filter" value="<?php echo _AT('filter'); ?>" />
301 <input type="submit" name="reset_filter" value="<?php echo _AT('reset_filter'); ?>" />
307 <?php print_paginator($page, $tab_counts[$current_tab], $page_string_w_tab . SEP . $order .'='. $col, $results_per_page); ?>
309 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="selectform">
310 <input type="hidden" name="tab" value="<?php echo $current_tab; ?>" />
311 <input type="hidden" name="course_id" value="<?php echo $course_id; ?>"/>
312 <div style="width: 95%; margin-right: auto; margin-left: auto;">
314 <?php for ($i = 0; $i< $num_tabs; $i++): ?>
315 <?php if ($current_tab == $i): ?>
316 <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?tab=<?php echo $i.$page_string; ?>" class="active"><strong><?php echo _AT($tabs[$i]); ?> - <?php echo $tab_counts[$i]; ?></strong></a></li>
318 <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?tab=<?php echo $i.$page_string; ?>"><?php echo _AT($tabs[$i]); ?> - <?php echo $tab_counts[$i]; ?></a></li>
324 <table class="data" style="width:95%;" summary="" rules="cols">
326 <?php if ($col == 'login'): ?>
330 <?php elseif($col == 'first_name'): ?>
334 <?php elseif($col == 'second_name'): ?>
338 <?php elseif($col == 'last_name'): ?>
342 <?php elseif($col == 'email'): ?>
349 <th scope="col" align="left"><input type="checkbox" value="<?php echo _AT('select_all'); ?>" id="all" title="<?php echo _AT('select_all'); ?>" name="selectall" onclick="CheckAll();" /></th>
351 <th scope="col"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $orders[$order]; ?>=login<?php echo $page_string_w_tab;?>"><?php echo _AT('login_name'); ?></a></th>
353 <th scope="col"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $orders[$order]; ?>=first_name<?php echo $page_string_w_tab;?>"><?php echo _AT('first_name'); ?></a></th>
355 <th scope="col"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $orders[$order]; ?>=second_name<?php echo $page_string_w_tab;?>"><?php echo _AT('second_name'); ?></a></th>
357 <th scope="col"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $orders[$order]; ?>=last_name<?php echo $page_string_w_tab;?>"><?php echo _AT('last_name'); ?></a></th>
359 <th scope="col"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $orders[$order]; ?>=email<?php echo $page_string_w_tab;?>"><?php echo _AT('email'); ?></a></th>
365 <?php if ($current_tab == 0): ?>
366 <input type="submit" name="role" value="<?php echo _AT('privileges'); ?>" />
367 <input type="submit" name="unenroll" value="<?php echo _AT('remove'); ?>" />
368 <input type="submit" name="alumni" value="<?php echo _AT('mark_alumni'); ?>" />
369 <?php elseif ($current_tab == 1): ?>
370 <input type="submit" name="role" value="<?php echo _AT('privileges'); ?>" />
371 <input type="submit" name="unenroll" value="<?php echo _AT('remove'); ?>" />
373 <?php elseif ($current_tab == 2): ?>
374 <input type="submit" name="enroll" value="<?php echo _AT('enroll'); ?>" />
375 <input type="submit" name="unenroll" value="<?php echo _AT('remove'); ?>" />
377 <?php elseif ($current_tab == 3): ?>
378 <input type="submit" name="enroll" value="<?php echo _AT('enroll'); ?>" />
379 <input type="submit" name="unenroll" value="<?php echo _AT('remove'); ?>" />
381 <?php elseif ($current_tab == 4): ?>
382 <input type="submit" name="enroll" value="<?php echo _AT('enroll'); ?>" />
388 <?php if ($tab_counts[$current_tab]): ?>
389 <?php while ($row = mysql_fetch_assoc($enrollment_result)): ?>
390 <tr onmousedown="document.selectform['m<?php echo $row['member_id']; ?>'].checked = !document.selectform['m<?php echo $row['member_id']; ?>'].checked; togglerowhighlight(this, 'm<?php echo $row['member_id']; ?>');" id="rm<?php echo $row['member_id']; ?>">
391 <td><input type="checkbox" name="id[]" value="<?php echo $row['member_id']; ?>" id="m<?php echo $row['member_id']; ?>" onmouseup="this.checked=!this.checked" title="<?php echo AT_print($row['login'], 'members.login'); ?>" /></td>
392 <td><?php echo AT_print($row['login'], 'members.login'); ?></td>
393 <td><?php echo AT_print($row['first_name'], 'members.name'); ?></td>
394 <td><?php echo AT_print($row['second_name'], 'members.name'); ?></td>
395 <td><?php echo AT_print($row['last_name'], 'members.name'); ?></td>
396 <td><?php echo AT_print($row['email'], 'members.email'); ?></td>
401 <td colspan="6"><?php echo _AT('none_found'); ?></td>
408 <script language="JavaScript" type="text/javascript">
410 function CheckAll() {
411 for (var i=0;i<document.selectform.elements.length;i++) {
412 var e = document.selectform.elements[i];
413 if ((e.name == 'id[]') && (e.type=='checkbox')) {
414 e.checked = document.selectform.selectall.checked;
415 togglerowhighlight(document.getElementById("r" + e.id), e.id);
420 function togglerowhighlight(obj, boxid) {
421 if (document.getElementById(boxid).checked) {
422 obj.className = 'selected';
429 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>