made a copy
[atutor.git] / include / html / announcements.inc.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay & Joel Kronenberg        */
6 /* Adaptive Technology Resource Centre / University of Toronto  */
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 if (!defined('AT_INCLUDE_PATH')) { exit; }
15
16         require_once(AT_INCLUDE_PATH.'lib/test_result_functions.inc.php');
17
18         /* help for content pages */
19
20         if (FALSE && defined('AT_SHOW_TEST_BOX') && AT_SHOW_TEST_BOX) {
21                 // print new available tests
22                 
23                 $sql    = "SELECT T.test_id, T.title FROM ".TABLE_PREFIX."tests T WHERE T.course_id=$_SESSION[course_id] AND T.start_date<=NOW() AND T.end_date>= NOW() ORDER BY T.start_date, T.title";
24                 $result = mysql_query($sql, $db);
25                 $num_tests = mysql_num_rows($result);
26                 $tests = '';
27                 while (($row = mysql_fetch_assoc($result)) && authenticate_test($row['test_id'])) {
28                         $tests .= '<a href="'.$_base_path.'tools/take_test.php?tid='.$row['test_id'].'">'.$row['title'].'</a><br />';
29                 } 
30
31                 if ($tests) { ?>
32                                 <table border="0" cellspacing="0" cellpadding="0" align="center">
33                                 <tr>
34                                         <td class="test-box"><small><a href="<?php echo AT_BASE_HREF; ?>tools/my_tests.php?g=32"><?php echo _AT('curren_tests_surveys'); ?></a></small></td>
35                                 </tr>
36                                 <tr>
37                                         <td class="dropdown"><?php echo $tests; ?></td>
38                                 </tr>
39                                 </table><br />
40                 <?php 
41                 }
42         }
43
44 /* the "home" links: */
45 $home_links = get_home_navigation();
46 $savant->assign('home_links', $home_links);
47
48
49 /* the news announcements: */
50 $news = array();
51 $num_pages = 1;
52 $page = intval($_GET['p']);
53 if (!$page) {
54         $page = 1;
55 }       
56
57 $sql    = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."news WHERE course_id=$_SESSION[course_id]";
58 $result = mysql_query($sql, $db);
59
60 if ($row = mysql_fetch_assoc($result)) {        
61         $num_results = $row['cnt'];
62         $results_per_page = NUM_ANNOUNCEMENTS;
63         $num_pages = ceil($num_results / $results_per_page);
64
65         $count = (($page-1) * $results_per_page) + 1;
66
67         $offset = ($page-1)*$results_per_page;
68
69         $sql = "SELECT N.* FROM ".TABLE_PREFIX."news N WHERE N.course_id=$_SESSION[course_id] ORDER BY date DESC LIMIT $offset, $results_per_page";
70         
71         $result = mysql_query($sql, $db);
72         while ($row = mysql_fetch_assoc($result)) {
73                 /* this can't be cached because it called _AT */
74
75                 $news[$row['news_id']] = array(
76                                                 'date'          => AT_date(     _AT('announcement_date_format'), 
77                                                                                                 $row['date'], 
78                                                                                                 AT_DATE_MYSQL_DATETIME),
79                                                 'title'         => AT_print($row['title'], 'news.title'),
80                                                 'body'          => AT_print($row['body'], 'news.body', $row['formatting']));
81         }
82 }
83
84 $savant->assign('announcements', $news);
85 $savant->assign('num_pages', $num_pages);
86 $savant->assign('current_page', $page);
87 $savant->display('index.tmpl.php');
88
89 ?>