Merge pull request #8 from radiocontrolled/0004872
[atutor.git] / index.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002 - 2009                                            */
6 /* Inclusive Design Institute                                           */
7 /*                                                                      */
8 /* This program is free software. You can redistribute it and/or        */
9 /* modify it under the terms of the GNU General Public License          */
10 /* as published by the Free Software Foundation.                        */
11 /************************************************************************/
12
13 define('AT_INCLUDE_PATH', 'include/');
14 require(AT_INCLUDE_PATH . 'vitals.inc.php');
15
16 if (isset($_GET['cid'])) {
17         header('Location: '.$_base_href.'content.php?cid='.intval($_GET['cid']));
18         exit;
19 }
20
21 if (isset($_SESSION['course_id'])) 
22         $course_id = $_SESSION['course_id'];
23 else if (isset($_GET['p_course'])) // is set when pretty url is turned on and a public course is accessed
24         $course_id = $_GET['p_course'];
25 else // is set when guests access protected course
26         $course_id = $_GET['course'];
27         
28 require(AT_INCLUDE_PATH . '../mods/_standard/tests/lib/test_result_functions.inc.php');
29         
30 if (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE) {
31         $course_base_href = 'get.php/';
32 } else {
33         $course_base_href = 'content/' . $course_id . '/';
34 }
35
36 //query reading the type of home viewable. 0: icon view   1: detail view
37 $sql = "SELECT home_view FROM ".TABLE_PREFIX."courses WHERE course_id = $course_id";
38 $result = mysql_query($sql,$db);
39 $row= mysql_fetch_assoc($result);
40 $home_view = $row['home_view'];
41
42 // Enable drag and drop to reorder displayed modules when the module view mode is 
43 // set to "detail view" and user role is instructor
44 if ($home_view == 1 && authenticate(AT_PRIV_ADMIN,AT_PRIV_RETURN))
45 {
46         $_custom_head .= '
47 <link rel="stylesheet" type="text/css" href="'.AT_BASE_HREF.'jscripts/infusion/framework/fss/css/fss-text.css" />
48 <link rel="stylesheet" type="text/css" href="'.AT_BASE_HREF.'jscripts/infusion/framework/fss/css/fss-theme-mist.css" />
49 <link rel="stylesheet" type="text/css" href="'.AT_BASE_HREF.'jscripts/infusion/framework/fss/css/fss-theme-hc.css" />
50 <link rel="stylesheet" type="text/css" href="'.AT_BASE_HREF.'jscripts/infusion/components/reorderer/css/Reorderer.css" />
51
52 <script type="text/javascript">
53 //<!--
54 jQuery(document).ready(function () {
55         var reorder_example_grid = fluid.reorderGrid("#details_view",  {
56                 selectors : {
57                         movables : ".home_box"
58                 },
59             listeners: {
60                         afterMove: function (item, requestedPosition, movables) {
61                                 //save the state to the db
62                                 var myDivs = jQuery ("div[class^=home_box]", "#details_view");
63                                 var moved_modules = "";
64                                 
65                                 if (myDivs.constructor.toString().indexOf("Array"))   // myDivs is an array
66                                 {
67                                         for (i=0; i<myDivs.length; i++)
68                                                 moved_modules += myDivs[i].id+"|";
69                                 }
70                                 moved_modules = moved_modules.substring(0, moved_modules.length-1); // remove the last "|"
71                                 
72                                 if (moved_modules != "")
73                                         jQuery.post("'.AT_BASE_HREF.'move_module.php", { "moved_modules":moved_modules, "from":"course_index" }, function(data) {});     
74                 }
75             },
76                 styles: {
77                     selected: "draggable_selected",
78                     hover: "draggable_selected"
79                 }
80         });
81         
82 });
83
84 function remove_module(module)
85 {
86         jQuery.post("'.AT_BASE_HREF.'move_module.php", { "remove":module, "from":"course_index" }, function(data) {});
87         jQuery("div[id=\""+module.replace(/\//g,"-")+"\"]").remove();
88 }
89 //-->
90 </script>
91         
92 ';
93 }
94
95 require(AT_INCLUDE_PATH . 'header.inc.php');
96
97 /* the "home" links: */
98 $home_links = get_home_navigation();
99 $savant->assign('home_links', $home_links);
100
101
102 /* the news announcements: */
103 $news = array(); 
104 $num_pages = 1;
105 $page = isset($_GET['p']) ? intval($_GET['p']) : 1;
106 if (!$page) {
107         $page = 1;
108 }       
109
110 $module =& $moduleFactory->getModule(AT_MODULE_DIR_STANDARD.'/announcements');
111 if (!$module->isEnabled()) {
112         $result = FALSE;
113         $news = array();
114 } else {
115         $sql    = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."news WHERE course_id=$course_id";
116         $result = mysql_query($sql, $db);
117 }
118
119 if ($result && ($row = mysql_fetch_assoc($result))) {
120         $num_results = $row['cnt'];
121         $results_per_page = NUM_ANNOUNCEMENTS;
122         $num_pages = ceil($num_results / $results_per_page);
123
124         $count = (($page-1) * $results_per_page) + 1;
125
126         $offset = ($page-1)*$results_per_page;
127
128         $sql = "SELECT N.*, DATE_FORMAT(N.date, '%Y-%m-%d %H:%i:%s') AS date, first_name, last_name 
129                   FROM ".TABLE_PREFIX."news N, ".TABLE_PREFIX."members M 
130                  WHERE N.course_id=$course_id 
131                    AND N.member_id = M.member_id
132                  ORDER BY date DESC LIMIT $offset, $results_per_page";
133         
134         $result = mysql_query($sql, $db);
135         while ($row = mysql_fetch_assoc($result)) {
136                 /* this can't be cached because it called _AT */
137
138                 $news[$row['news_id']] = array(
139                                                 'date'          => AT_date(     _AT('announcement_date_format'), 
140                                                 $row['date'],
141                                                 AT_DATE_MYSQL_DATETIME),
142                                                 'author'  => $row['first_name'] . ' ' . $row['last_name'],
143                                                 'title'         => AT_print($row['title'], 'news.title'),
144                                                 'body'          => format_content($row['body'], $row['formatting'], $glossary));
145
146         }
147 }
148
149 $sql = "SELECT banner FROM ".TABLE_PREFIX."courses WHERE course_id=$course_id";
150 $result = mysql_query($sql, $db);
151 if ($row = mysql_fetch_assoc($result)) {
152         $savant->assign('banner', AT_print($row['banner'], 'courses.banner'));
153 } else {
154         $savant->assign('banner', '');
155 }
156
157 $savant->assign('view_mode', $home_view);
158 $savant->assign('announcements', $news);
159 $savant->assign('num_pages', $num_pages);
160 $savant->assign('current_page', $page);
161 $savant->display('index.tmpl.php');
162
163 require(AT_INCLUDE_PATH.'footer.inc.php');
164
165 ?>