remove old readme
[atutor.git] / 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 $savant->assign('results_per_page', $results_per_page);
109 $savant->assign('page', $page);
110 $savant->assign('page_string', $page_string);
111 $savant->assign('enrolled', $enrolled);
112 $savant->assign('num_rows', $num_rows);
113 $savant->assign('result', $result);
114 $savant->assign('orders', $orders);
115 $savant->assign('order', $order);
116 $savant->assign('num_results', $num_results);
117 $savant->display('admin/courses/courses.tmpl.php');
118 require(AT_INCLUDE_PATH.'footer.inc.php'); ?>