aa1f8705126f9b91f4f1586239b7606faee297a4
[atutor.git] / docs / users / index.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 $page = 'my_courses';
16 $_user_location = 'users';
17
18 define('AT_INCLUDE_PATH', '../include/');
19 require(AT_INCLUDE_PATH.'vitals.inc.php');
20
21 if ($_SESSION['valid_user'] !== true) {
22         require(AT_INCLUDE_PATH.'header.inc.php');
23
24         $info = array('INVALID_USER', $_SESSION['course_id']);
25         $msg->printInfos($info);
26         
27         require(AT_INCLUDE_PATH.'footer.inc.php');
28         exit;
29 }
30
31 $title = _AT('home'); 
32
33 // Get the course catagories
34 $sql = "SELECT * FROM ".TABLE_PREFIX."course_cats ORDER BY cat_name";
35 $result = mysql_query($sql,$db);
36 if(mysql_num_rows($result) != 0){
37         while($row = mysql_fetch_assoc($result)){
38                 $current_cats[$row['cat_id']] = $row['cat_name'];
39                 $parent_cats[$row['cat_id']] =  $row['cat_parent'];
40                 $cat_cats[$row['cat_id']] = $row['cat_id'];
41         }
42 }
43
44 //get courses
45 $sql = "SELECT E.approved, E.last_cid, C.* FROM ".TABLE_PREFIX."course_enrollment E, ".TABLE_PREFIX."courses C WHERE E.member_id=$_SESSION[member_id] AND E.course_id=C.course_id ORDER BY C.title";
46 $result = mysql_query($sql,$db);
47
48 $courses = array();
49 while ($row = mysql_fetch_assoc($result)) {
50         /* get tests for these courses: */
51         $tests['tests'] = array();
52         $sql3   = "SELECT test_id, title FROM ".TABLE_PREFIX."tests WHERE course_id=$row[course_id] AND (TO_DAYS(start_date) <= TO_DAYS(NOW()) AND TO_DAYS(end_date) >= TO_DAYS(NOW())) AND format=1";
53         $result3 = mysql_query($sql3,$db);
54         while ($row3 = mysql_fetch_assoc($result3)) {
55                 $tests['tests'][] = $row3;
56         }
57
58         $courses[] = array_merge($row, (array) $tests);
59 }
60
61 function get_category_name($cat_id) {
62         global $db;
63         $sql    = "SELECT cat_name FROM ".TABLE_PREFIX."course_cats WHERE cat_id=".$cat_id;
64         $result = mysql_query($sql,$db);
65         $row = mysql_fetch_assoc($result);
66
67         if ($row['cat_name'] == '') {
68                 $row['cat_name'] = _AT('cats_uncategorized');
69         } 
70         return $row['cat_name'];
71 }
72
73 //LAW
74 //$_SESSION['first_login'] = true; //for testing
75 if ($_SESSION['first_login']) {
76     $msg->addInfo(array('FIRST_PREFS', $_base_path.'users/pref_wizard/index.php'));
77 }
78
79 if (!$courses && get_instructor_status())
80         $msg->addInfo('NO_COURSES_INST');
81 elseif (!$courses)
82         $msg->addInfo('NO_COURSES');
83         
84
85 //sort function for all_news
86 function all_news_cmp($a, $b){
87         if ($b['time'] < $a['time']){
88                 return -1;
89         } elseif ($b['time'] > $a['time']){
90                 return 1;
91         } else {
92                 return 0;
93         }
94 }
95 $all_news = array();    //all news 
96
97 $module_status_bits = AT_MODULE_STATUS_ENABLED;
98 $module_type_bits = AT_MODULE_TYPE_STANDARD + AT_MODULE_TYPE_EXTRA;
99
100 $module_list = $moduleFactory->getModules($module_status_bits, $module_type_bits, $sort = TRUE);
101
102 foreach($module_list as $key=>$obj) {
103         $news = $obj->getNews();
104         while(!empty($news)){
105                 $current_item = array_pop($news);
106                 array_push($all_news, $current_item);
107         }
108 }
109
110 usort($all_news, 'all_news_cmp');
111
112 $savant->assign('all_news', $all_news);
113 $savant->assign('courses', $courses);
114
115
116 $savant->display('users/index.tmpl.php');
117 ?>