2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2006 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 /****************************************************************/
13 // $Id: index.php 6751 2007-02-12 18:56:44Z joel $
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');
93 $num_tabs = count($tabs);
95 for ($i=0; $i < $num_tabs; $i++) {
96 if (isset($_POST['button_'.$i]) && ($_POST['button_'.$i] != -1)) {
98 $_POST['current_tab'] = $i;
103 //get present tab if specified
104 if ($_GET['current_tab']) {
105 $current_tab = $_GET['current_tab'];
106 $_POST['current_tab'] = $_GET['current_tab'];
109 $orders = array('asc' => 'desc', 'desc' => 'asc');
110 $cols = array('login' => 1, 'first_name' => 1, 'second_name' => 1, 'last_name' => 1, 'email' => 1);
112 if (isset($_GET['asc'])) {
114 $col = isset($cols[$_GET['asc']]) ? $_GET['asc'] : 'login';
115 } else if (isset($_GET['desc'])) {
117 $col = isset($cols[$_GET['desc']]) ? $_GET['desc'] : 'login';
123 $view_select = intval($_POST['view_select']);
125 // the possible tabs. order matters.
126 $tabs = array('enrolled', 'assistants', 'alumni', 'pending_enrollment', 'not_enrolled');
128 $num_tabs = count($tabs);
129 if (isset($_REQUEST['tab'])) {
130 $current_tab = intval($_REQUEST['tab']);
133 if (!isset($current_tab)) {
137 if (isset($_GET['match']) && $_GET['match'] == 'one') {
138 $checked_match_one = ' checked="checked"';
139 $page_string .= SEP.'match=one';
141 $_GET['match'] = 'all';
142 $checked_match_all = ' checked="checked"';
143 $page_string .= SEP.'match=all';
146 if (admin_authenticate(AT_ADMIN_PRIV_ENROLLMENT, TRUE)) {
147 $page_string .= SEP.'course_id='.$course_id;
150 if ($_GET['search']) {
151 $page_string .= SEP.'search='.urlencode($_GET['search']);
152 $search = $addslashes($_GET['search']);
153 $search = explode(' ', $search);
155 if ($_GET['match'] == 'all') {
162 foreach ($search as $term) {
164 $term = str_replace(array('%','_'), array('\%', '\_'), $term);
166 $term = '%'.$term.'%';
167 $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";
170 $sql = '('.substr($sql, 0, -strlen($predicate)).')';
177 $instructor_id = $system_courses[$course_id]['member_id'];
178 if ($current_tab == 0) {
180 $sql_cnt = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."course_enrollment CE, ".TABLE_PREFIX."members M
181 WHERE CE.course_id=$course_id AND CE.member_id=M.member_id AND approved='y' AND M.member_id<>$instructor_id AND CE.privileges=0 AND $search";
182 $sql = "SELECT CE.member_id, CE.privileges, CE.approved, M.login, M.first_name, M.second_name, M.last_name, M.email
183 FROM ".TABLE_PREFIX."course_enrollment CE, ".TABLE_PREFIX."members M
184 WHERE CE.course_id=$course_id AND CE.member_id=M.member_id AND approved='y' AND M.member_id<>$instructor_id AND CE.privileges=0 AND $search
185 ORDER BY $col $order";
186 } else if ($current_tab == 1) {
188 $sql_cnt= "SELECT COUNT(*) AS cnt
189 FROM ".TABLE_PREFIX."course_enrollment CE, ".TABLE_PREFIX."members M
190 WHERE CE.course_id=$course_id AND CE.member_id=M.member_id AND CE.approved='y' AND CE.privileges>0 AND $search";
191 $sql = "SELECT CE.member_id, CE.approved, CE.privileges, M.login, M.first_name, M.second_name, M.last_name, M.email
192 FROM ".TABLE_PREFIX."course_enrollment CE, ".TABLE_PREFIX."members M
193 WHERE CE.course_id=$course_id AND CE.member_id=M.member_id AND CE.approved='y' AND CE.privileges>0 AND $search
194 ORDER BY $col $order";
196 } else if ($current_tab == 3) {
198 if ($system_courses[$course_id]['access'] == 'private') {
199 $sql_cnt = "SELECT COUNT(*) AS cnt
200 FROM ".TABLE_PREFIX."course_enrollment CE, ".TABLE_PREFIX."members M
201 WHERE CE.course_id=$course_id AND CE.member_id=M.member_id AND approved='n' AND $search";
203 $sql = "SELECT CE.member_id, CE.approved, CE.privileges, M.login, M.first_name, M.second_name, M.last_name, M.email
204 FROM ".TABLE_PREFIX."course_enrollment CE, ".TABLE_PREFIX."members M
205 WHERE CE.course_id=$course_id AND CE.member_id=M.member_id AND approved='n' AND $search
206 ORDER BY $col $order";
208 // not sure what this is about
209 $sql_cnt = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."members WHERE 0";
210 $sql = "SELECT login FROM ".TABLE_PREFIX."members WHERE 0";
212 } else if ($current_tab == 2) {
214 $sql_cnt= "SELECT COUNT(*) AS cnt
215 FROM ".TABLE_PREFIX."course_enrollment CE, ".TABLE_PREFIX."members M
216 WHERE CE.course_id=$course_id AND CE.member_id=M.member_id AND approved='a' AND $search";
217 $sql = "SELECT CE.member_id, CE.approved, CE.privileges, M.login, M.first_name, M.second_name, M.last_name, M.email
218 FROM ".TABLE_PREFIX."course_enrollment CE, ".TABLE_PREFIX."members M
219 WHERE CE.course_id=$course_id AND CE.member_id=M.member_id AND approved='a' AND $search
220 ORDER BY $col $order";
222 // not sure what this is about
223 $tmp_sql = "SELECT member_id FROM ".TABLE_PREFIX."course_enrollment WHERE course_id=$course_id AND member_id<>$instructor_id ";
224 $tmp_result = mysql_query($tmp_sql, $db);
225 $course_enrollment = '';
226 while ($row = mysql_fetch_assoc($tmp_result)) {
227 $course_enrollment .= $row['member_id'] .',';
229 $course_enrollment .= $instructor_id;
231 $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";
233 $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";
236 $results_per_page = 50;
238 $result = mysql_query($sql_cnt, $db);
239 $row = mysql_fetch_assoc($result);
240 $num_results = $row['cnt'];
242 $num_pages = max(ceil($num_results / $results_per_page), 1);
243 $page = intval($_GET['p']);
247 $count = (($page-1) * $results_per_page) + 1;
248 $offset = ($page-1)*$results_per_page;
249 $sql .= " LIMIT $offset, $results_per_page";
251 $enrollment_result = mysql_query($sql, $db);
252 $page_string .= SEP . 'tab='.$current_tab;
253 require(AT_INCLUDE_PATH.'header.inc.php');
257 <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
258 <input type="hidden" name="tab" value="<?php echo $current_tab; ?>"/>
259 <input type="hidden" name="course_id" value="<?php echo $course_id; ?>"/>
260 <div class="input-form">
262 <h3><?php echo _AT('results_found', $num_results); ?></h3>
265 <?php if (admin_authenticate(AT_ADMIN_PRIV_ENROLLMENT, TRUE)): ?>
267 <label for="course"><?php echo _AT('course'); ?></label><br/>
268 <select name="course_id">
270 $sql = "SELECT course_id, title FROM ".TABLE_PREFIX."courses ORDER BY title";
271 $result = mysql_query($sql, $db);
272 while ($courses_row = mysql_fetch_assoc($result)) {
273 if ($courses_row['course_id'] == $course_id) {
274 echo '<option value="'.$courses_row['course_id'].'" selected="selected">'.$courses_row['title'].'</option>';
276 echo '<option value="'.$courses_row['course_id'].'">'.$courses_row['title'].'</option>';
284 <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 />
285 <input type="text" name="search" id="search" size="40" value="<?php echo htmlspecialchars($_GET['search']); ?>" />
287 <?php echo _AT('search_match'); ?>:
288 <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>
291 <div class="row buttons">
292 <input type="submit" name="filter" value="<?php echo _AT('filter'); ?>" />
293 <input type="submit" name="reset_filter" value="<?php echo _AT('reset_filter'); ?>" />
298 <?php print_paginator($page, $num_results, $page_string . SEP . $order .'='. $col, $results_per_page); ?>
300 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="selectform">
301 <input type="hidden" name="tab" value="<?php echo $current_tab; ?>" />
303 <div style="width: 95%; margin-right: auto; margin-left: auto;">
305 <?php for ($i = 0; $i< $num_tabs; $i++): ?>
306 <?php if ($current_tab == $i): ?>
307 <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?tab=<?php echo $i.SEP; ?>course_id=<?php echo $course_id; ?>" class="active"><strong><?php echo _AT($tabs[$i]); ?></strong></a></li>
309 <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?tab=<?php echo $i.SEP; ?>course_id=<?php echo $course_id; ?>"><?php echo _AT($tabs[$i]); ?></a></li>
315 <table class="data" style="width:95%;" summary="" rules="cols">
317 <?php if ($col == 'login'): ?>
321 <?php elseif($col == 'first_name'): ?>
325 <?php elseif($col == 'second_name'): ?>
329 <?php elseif($col == 'last_name'): ?>
333 <?php elseif($col == 'email'): ?>
340 <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>
342 <th scope="col"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $orders[$order]; ?>=login<?php echo $page_string;?>"><?php echo _AT('login_name'); ?></a></th>
344 <th scope="col"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $orders[$order]; ?>=first_name<?php echo $page_string;?>"><?php echo _AT('first_name'); ?></a></th>
346 <th scope="col"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $orders[$order]; ?>=second_name<?php echo $page_string;?>"><?php echo _AT('second_name'); ?></a></th>
348 <th scope="col"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $orders[$order]; ?>=last_name<?php echo $page_string;?>"><?php echo _AT('last_name'); ?></a></th>
350 <th scope="col"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $orders[$order]; ?>=email<?php echo $page_string;?>"><?php echo _AT('email'); ?></a></th>
356 <?php if ($current_tab == 0): ?>
357 <input type="submit" name="role" value="<?php echo _AT('privileges'); ?>" />
358 <input type="submit" name="unenroll" value="<?php echo _AT('remove'); ?>" />
359 <input type="submit" name="alumni" value="<?php echo _AT('mark_alumni'); ?>" />
360 <?php elseif ($current_tab == 1): ?>
361 <input type="submit" name="role" value="<?php echo _AT('privileges'); ?>" />
362 <input type="submit" name="unenroll" value="<?php echo _AT('remove'); ?>" />
364 <?php elseif ($current_tab == 2): ?>
365 <input type="submit" name="enroll" value="<?php echo _AT('enroll'); ?>" />
366 <input type="submit" name="unenroll" value="<?php echo _AT('remove'); ?>" />
368 <?php elseif ($current_tab == 3): ?>
369 <input type="submit" name="enroll" value="<?php echo _AT('enroll'); ?>" />
370 <input type="submit" name="unenroll" value="<?php echo _AT('remove'); ?>" />
372 <?php elseif ($current_tab == 4): ?>
373 <input type="submit" name="enroll" value="<?php echo _AT('enroll'); ?>" />
379 <?php if ($num_results): ?>
380 <?php while ($row = mysql_fetch_assoc($enrollment_result)): ?>
381 <tr onmousedown="document.selectform['m<?php echo $row['member_id']; ?>'].checked = !document.selectform['m<?php echo $row['member_id']; ?>'].checked;">
382 <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>
383 <td><?php echo AT_print($row['login'], 'members.login'); ?></td>
384 <td><?php echo AT_print($row['first_name'], 'members.name'); ?></td>
385 <td><?php echo AT_print($row['second_name'], 'members.name'); ?></td>
386 <td><?php echo AT_print($row['last_name'], 'members.name'); ?></td>
387 <td><?php echo AT_print($row['email'], 'members.email'); ?></td>
392 <td colspan="6"><?php echo _AT('none_found'); ?></td>
399 <script language="JavaScript" type="text/javascript">
401 function CheckAll() {
402 for (var i=0;i<document.selectform.elements.length;i++) {
403 var e = document.selectform.elements[i];
404 if ((e.name == 'id[]') && (e.type=='checkbox'))
405 e.checked = document.selectform.selectall.checked;
410 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>