2 /****************************************************************************/
4 /****************************************************************************/
5 /* Copyright (c) 2002-2006 by Greg Gay, Joel Kronenberg & Heidi Hazelton */
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 /****************************************************************************/
15 define('AT_INCLUDE_PATH', '../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17 admin_authenticate(AT_ADMIN_PRIV_COURSES);
19 if (isset($_GET['view'], $_GET['id'])) {
20 header('Location: instructor_login.php?course='.$_GET['id']);
22 } else if (isset($_GET['edit'], $_GET['id'])) {
23 header('Location: edit_course.php?course='.$_GET['id']);
25 } else if (isset($_GET['backups'], $_GET['id'])) {
26 header('Location: backup/index.php?course='.$_GET['id']);
28 } else if (isset($_GET['delete'], $_GET['id'])) {
29 header('Location: delete_course.php?course='.$_GET['id']);
31 } else if (isset($_GET['delete']) || isset($_GET['backups']) || isset($_GET['edit']) || isset($_GET['view'])) {
32 $msg->addError('NO_ITEM_SELECTED');
35 require(AT_INCLUDE_PATH.'header.inc.php');
39 if ($_GET['reset_filter']) {
43 $orders = array('asc' => 'desc', 'desc' => 'asc');
44 $cols = array('title' => 1, 'login' => 1, 'access' => 1, 'created_date' => 1, 'cat_name' => 1);
45 $_access = array('public', 'protected', 'private');
47 if (isset($_GET['asc'])) {
49 $col = isset($cols[$_GET['asc']]) ? $_GET['asc'] : 'title';
50 } else if (isset($_GET['desc'])) {
52 $col = isset($cols[$_GET['desc']]) ? $_GET['desc'] : 'title';
59 if (isset($_GET['access']) && ($_GET['access'] != '') && isset($_access[$_GET['access']])) {
60 $access = 'C.access = \'' . $_access[$_GET['access']].'\'';
61 $page_string .= SEP.'access='.$_GET['access'];
66 if ($_GET['search']) {
67 $page_string .= SEP.'search='.urlencode($_GET['search']);
68 $search = $addslashes($_GET['search']);
69 $search = str_replace(array('%','_'), array('\%', '\_'), $search);
70 $search = '%'.$search.'%';
71 $search = "((C.title LIKE '$search') OR (C.description LIKE '$search'))";
76 // get number of courses on the system
77 $sql = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."courses C WHERE 1 AND $access AND $search";
78 $result = mysql_query($sql, $db);
79 $row = mysql_fetch_assoc($result);
80 $num_results = $row['cnt'];
82 $results_per_page = 100;
83 $num_pages = max(ceil($num_results / $results_per_page), 1);
84 $page = intval($_GET['p']);
88 $count = (($page-1) * $results_per_page) + 1;
89 $offset = ($page-1)*$results_per_page;
91 ${'highlight_'.$col} = ' style="background-color: #fff;"';
93 $sql = "SELECT COUNT(*) AS cnt, approved, course_id FROM ".TABLE_PREFIX."course_enrollment WHERE approved='y' OR approved='a' GROUP BY course_id, approved";
94 $result = mysql_query($sql, $db);
95 while ($row = mysql_fetch_assoc($result)) {
96 if ($row['approved'] == 'y') {
97 $row['cnt']--; // remove the instructor
99 $enrolled[$row['course_id']][$row['approved']] = $row['cnt'];
102 $sql = "SELECT C.*, M.login, T.cat_name FROM ".TABLE_PREFIX."members M INNER JOIN ".TABLE_PREFIX."courses C USING (member_id) LEFT JOIN ".TABLE_PREFIX."course_cats T USING (cat_id) WHERE 1 AND $access AND $search ORDER BY $col $order LIMIT $offset, $results_per_page";
103 $result = mysql_query($sql, $db);
105 $num_rows = mysql_num_rows($result);
108 <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
109 <div class="input-form">
111 <h3><?php echo _AT('results_found', $num_results); ?></h3>
115 <?php echo _AT('access'); ?><br />
117 <input type="radio" name="access" value="0" id="s0" <?php if ($_GET['access'] == 0) { echo 'checked="checked"'; } ?> /><label for="s0"><?php echo _AT('public'); ?></label>
119 <input type="radio" name="access" value="1" id="s1" <?php if ($_GET['access'] == 1) { echo 'checked="checked"'; } ?> /><label for="s1"><?php echo _AT('protected'); ?></label>
121 <input type="radio" name="access" value="2" id="s2" <?php if ($_GET['access'] == 2) { echo 'checked="checked"'; } ?> /><label for="s2"><?php echo _AT('private'); ?></label>
123 <input type="radio" name="access" value="" id="s" <?php if ($_GET['access'] == '') { echo 'checked="checked"'; } ?> /><label for="s"><?php echo _AT('all'); ?></label>
127 <label for="search"><?php echo _AT('search'); ?> (<?php echo _AT('title').', '._AT('description'); ?>)</label><br />
128 <input type="text" name="search" id="search" size="20" value="<?php echo htmlspecialchars($_GET['search']); ?>" />
131 <div class="row buttons">
132 <input type="submit" name="filter" value="<?php echo _AT('filter'); ?>" />
133 <input type="submit" name="reset_filter" value="<?php echo _AT('reset_filter'); ?>" />
138 <?php print_paginator($page, $num_results, $page_string . SEP . $order .'='. $col, $results_per_page); ?>
140 <form name="form" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
142 <table class="data" summary="" rules="cols">
144 <?php if ($col == 'title'): ?>
148 <?php elseif($col == 'login'): ?>
152 <?php elseif($col == 'access'): ?>
156 <?php elseif($col == 'created_date'): ?>
160 <?php elseif($col == 'cat_name'): ?>
168 <th scope="col"> </th>
169 <th scope="col"><a href="admin/courses.php?<?php echo $orders[$order]; ?>=title<?php echo $page_string; ?>"><?php echo _AT('title'); ?></a></th>
170 <th scope="col"><a href="admin/courses.php?<?php echo $orders[$order]; ?>=login<?php echo $page_string; ?>"><?php echo _AT('Instructor'); ?></a></th>
171 <th scope="col"><a href="admin/courses.php?<?php echo $orders[$order]; ?>=access<?php echo $page_string; ?>"><?php echo _AT('access'); ?></a></th>
172 <th scope="col"><a href="admin/courses.php?<?php echo $orders[$order]; ?>=created_date<?php echo $page_string; ?>"><?php echo _AT('created_date'); ?></a></th>
173 <th scope="col"><a href="admin/courses.php?<?php echo $orders[$order]; ?>=cat_name<?php echo $page_string; ?>"><?php echo _AT('category'); ?></a></th>
174 <th scope="col"><?php echo _AT('enrolled'); ?></th>
175 <th scope="col"><?php echo _AT('alumni'); ?></th>
180 <td colspan="8"><input type="submit" name="view" value="<?php echo _AT('view'); ?>" />
181 <input type="submit" name="edit" value="<?php echo _AT('edit'); ?>" />
182 <input type="submit" name="backups" value="<?php echo _AT('backups'); ?>" />
183 <input type="submit" name="delete" value="<?php echo _AT('delete'); ?>" /></td>
187 <?php if ($num_rows): ?>
188 <?php while ($row = mysql_fetch_assoc($result)): ?>
189 <tr onmousedown="document.form['m<?php echo $row['course_id']; ?>'].checked = true; rowselect(this);" id="r_<?php echo $row['course_id']; ?>">
190 <td><input type="radio" name="id" value="<?php echo $row['course_id']; ?>" id="m<?php echo $row['course_id']; ?>" /></td>
191 <td><label for="m<?php echo $row['course_id']; ?>"><?php echo AT_print($row['title'], 'courses.title'); ?></label></td>
192 <td><?php echo AT_print($row['login'],'members.login'); ?></td>
193 <td><?php echo _AT($row['access']); ?></td>
194 <td><?php echo $row['created_date']; ?></td>
195 <td><?php echo ($row['cat_name'] ? $row['cat_name'] : '-')?></td>
196 <td><?php echo ($enrolled[$row['course_id']]['y'] ? $enrolled[$row['course_id']]['y'] : 0); ?></td>
197 <td><?php echo ($enrolled[$row['course_id']]['a'] ? $enrolled[$row['course_id']]['a'] : 0); ?></td>
202 <td colspan="8"><?php echo _AT('none_found'); ?></td>
208 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>