SVN tag for release should only contain scripts in "docs" folder without "mods",...
[atutor.git] / docs / mods / _core / courses / admin / courses.php
1 <?php
2 /****************************************************************************/
3 /* ATutor                                                                                                                                       */
4 /****************************************************************************/
5 /* Copyright (c) 2002-2010                                                  */
6 /* Inclusive Design Institute                                               */
7 /* http://atutor.ca                                                                                                                     */
8 /*                                                                                                                                                      */
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$
14
15 define('AT_INCLUDE_PATH', '../../../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17 admin_authenticate(AT_ADMIN_PRIV_COURSES);
18
19 if (isset($_GET['view'], $_GET['id'])) {
20         header('Location:instructor_login.php?course='.$_GET['id']);
21         exit;
22 } else if (isset($_GET['edit'], $_GET['id'])) {
23
24         header('Location:  ../../properties/admin/edit_course.php?course='.$_GET['id']);
25         exit;
26 } else if (isset($_GET['backups'], $_GET['id'])) {
27         header('Location: ../../backups/admin/index.php?course='.$_GET['id']);
28         exit;
29 } else if (isset($_GET['delete'], $_GET['id'])) {
30         header('Location: ../../properties/admin/delete_course.php?course='.$_GET['id']);
31         exit;
32 }  else if (isset($_GET['delete']) || isset($_GET['backups']) || isset($_GET['edit']) || isset($_GET['view'])) {
33         $msg->addError('NO_ITEM_SELECTED');
34 }
35
36 require(AT_INCLUDE_PATH.'header.inc.php'); 
37
38 $page_string = '';
39
40 if ($_GET['reset_filter']) {
41         unset($_GET);
42 }
43
44 $orders = array('asc' => 'desc', 'desc' => 'asc');
45 $cols   = array('title' => 1, 'login' => 1, 'access' => 1, 'created_date' => 1, 'cat_name' => 1);
46 $_access = array('public', 'protected', 'private');
47
48 if (isset($_GET['asc'])) {
49         $order = 'asc';
50         $col   = isset($cols[$_GET['asc']]) ? $_GET['asc'] : 'title';
51 } else if (isset($_GET['desc'])) {
52         $order = 'desc';
53         $col   = isset($cols[$_GET['desc']]) ? $_GET['desc'] : 'title';
54 } else {
55         // no order set
56         $order = 'asc';
57         $col   = 'title';
58 }
59
60 if (isset($_GET['access']) && ($_GET['access'] != '') && isset($_access[$_GET['access']])) {
61         $access = 'C.access = \'' . $_access[$_GET['access']].'\'';
62         $page_string .= SEP.'access='.$_GET['access'];
63 } else {
64         $access = '1';
65 }
66
67 if ($_GET['search']) {
68         $page_string .= SEP.'search='.urlencode($_GET['search']);
69         $search = $addslashes($_GET['search']);
70         $search = str_replace(array('%','_'), array('\%', '\_'), $search);
71         $search = '%'.$search.'%';
72         $search = "((C.title LIKE '$search') OR (C.description LIKE '$search'))";
73 } else {
74         $search = '1';
75 }
76
77 // get number of courses on the system
78 $sql    = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."courses C WHERE 1 AND $access AND $search";
79 $result = mysql_query($sql, $db);
80 $row = mysql_fetch_assoc($result);
81 $num_results = $row['cnt'];
82
83 $results_per_page = 100;
84 $num_pages = max(ceil($num_results / $results_per_page), 1);
85 $page = intval($_GET['p']);
86 if (!$page) {
87         $page = 1;
88 }       
89 $count  = (($page-1) * $results_per_page) + 1;
90 $offset = ($page-1)*$results_per_page;
91
92 ${'highlight_'.$col} = ' style="background-color: #fff;"';
93
94 $sql    = "SELECT COUNT(*) AS cnt, approved, course_id FROM ".TABLE_PREFIX."course_enrollment WHERE approved='y' OR approved='a' GROUP BY course_id, approved";
95 $result = mysql_query($sql, $db);
96 while ($row = mysql_fetch_assoc($result)) {
97         if ($row['approved'] == 'y') {
98                 $row['cnt']--; // remove the instructor
99         }
100         $enrolled[$row['course_id']][$row['approved']] = $row['cnt'];
101 }
102
103 $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";
104 $result = mysql_query($sql, $db);
105
106 $num_rows = mysql_num_rows($result);
107 ?>
108
109 <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
110         <div class="input-form">
111                 <div class="row">
112                         <h3><?php echo _AT('results_found', $num_results); ?></h3>
113                 </div>
114
115                 <div class="row">
116                         <?php echo _AT('access'); ?><br />
117
118                         <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
120                         <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
122                         <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
124                         <input type="radio" name="access" value="" id="s" <?php if ($_GET['access'] == '') { echo 'checked="checked"'; } ?> /><label for="s"><?php echo _AT('all'); ?></label>
125                 </div>
126
127                 <div class="row">
128                         <label for="search"><?php echo _AT('search'); ?> (<?php echo _AT('title').', '._AT('description'); ?>)</label><br />
129                         <input type="text" name="search" id="search" size="20" value="<?php echo htmlspecialchars($_GET['search']); ?>" />
130                 </div>
131
132                 <div class="row buttons">
133                         <input type="submit" name="filter" value="<?php echo _AT('filter'); ?>" />
134                         <input type="submit" name="reset_filter" value="<?php echo _AT('reset_filter'); ?>" />
135                 </div>
136         </div>
137 </form>
138
139 <?php print_paginator($page, $num_results, $page_string . SEP . $order .'='. $col, $results_per_page); ?>
140
141 <form name="form" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
142
143 <table class="data" summary="" rules="cols">
144 <colgroup>
145         <?php if ($col == 'title'): ?>
146                 <col />
147                 <col class="sort" />
148                 <col span="6" />
149         <?php elseif($col == 'login'): ?>
150                 <col span="2" />
151                 <col class="sort" />
152                 <col span="5" />
153         <?php elseif($col == 'access'): ?>
154                 <col span="3" />
155                 <col class="sort" />
156                 <col span="4" />
157         <?php elseif($col == 'created_date'): ?>
158                 <col span="4" />
159                 <col class="sort" />
160                 <col span="3" />
161         <?php elseif($col == 'cat_name'): ?>
162                 <col span="5" />
163                 <col class="sort" />
164                 <col span="2" />
165         <?php endif; ?>
166 </colgroup>
167 <thead>
168 <tr>
169         <th scope="col">&nbsp;</th>
170         <th scope="col"><a href="mods/_core/courses/admin/courses.php?<?php echo $orders[$order]; ?>=title<?php echo $page_string; ?>"><?php echo _AT('title');               ?></a></th>
171         <th scope="col"><a href="mods/_core/courses/admin/courses.php?<?php echo $orders[$order]; ?>=login<?php echo $page_string; ?>"><?php echo _AT('Instructor');          ?></a></th>
172         <th scope="col"><a href="mods/_core/courses/admin/courses.php?<?php echo $orders[$order]; ?>=access<?php echo $page_string; ?>"><?php echo _AT('access');             ?></a></th>
173         <th scope="col"><a href="mods/_core/courses/admin/courses.php?<?php echo $orders[$order]; ?>=created_date<?php echo $page_string; ?>"><?php echo _AT('created_date'); ?></a></th>
174         <th scope="col"><a href="mods/_core/courses/admin/courses.php?<?php echo $orders[$order]; ?>=cat_name<?php echo $page_string; ?>"><?php echo _AT('category'); ?></a></th>
175         <th scope="col"><?php echo _AT('enrolled'); ?></th>
176         <th scope="col"><?php echo _AT('alumni'); ?></th>
177 </tr>
178 </thead>
179 <tfoot>
180 <tr>
181         <td colspan="8"><input type="submit" name="view" value="<?php echo _AT('view'); ?>" /> 
182                                         <input type="submit" name="edit" value="<?php echo _AT('edit'); ?>" /> 
183                                         <input type="submit" name="backups" value="<?php echo _AT('backups'); ?>" /> 
184                                         <input type="submit" name="delete" value="<?php echo _AT('delete'); ?>" /></td>
185 </tr>
186 </tfoot>
187 <tbody>
188 <?php if ($num_rows): ?>
189         <?php while ($row = mysql_fetch_assoc($result)): ?>
190                 <tr onmousedown="document.form['m<?php echo $row['course_id']; ?>'].checked = true; rowselect(this);" id="r_<?php echo $row['course_id']; ?>">
191                         <td><input type="radio" name="id" value="<?php echo $row['course_id']; ?>" id="m<?php echo $row['course_id']; ?>" /></td>
192                         <td><label for="m<?php echo $row['course_id']; ?>"><?php echo AT_print($row['title'], 'courses.title'); ?></label></td>
193                         <td><?php echo AT_print($row['login'],'members.login'); ?></td>
194                         <td><?php echo _AT($row['access']); ?></td>
195                         <td><?php echo AT_date($startend_date_long_format, $row['created_date'], AT_DATE_UNIX_TIMESTAMP); ?></td>
196                         <td><?php echo ($row['cat_name'] ? $row['cat_name'] : '-')?></td>
197                         <td><?php echo ($enrolled[$row['course_id']]['y'] ? $enrolled[$row['course_id']]['y'] : 0); ?></td>
198                         <td><?php echo ($enrolled[$row['course_id']]['a'] ? $enrolled[$row['course_id']]['a'] : 0); ?></td>
199                 </tr>
200         <?php endwhile; ?>
201 <?php else: ?>
202         <tr>
203                 <td colspan="8"><?php echo _AT('none_found'); ?></td>
204         </tr>
205 <?php endif; ?>
206 </tbody>
207 </table>
208 </form>
209 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>