b1f5e786b8fb392b33270473aa46bf2b9a48278e
[atutor.git] / docs / mods / _standard / tests / module_news.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  * Get the latest updates of this module
16  * @return list of news, [timestamp]=>
17  */
18 function tests_news() {
19         global $db, $enrolled_courses, $system_courses;
20         $news = array();
21
22         if ($enrolled_courses == ''){
23                 return $news;
24         } 
25         $sql = "SELECT T.test_id, T.course_id, T.title, T.start_date as start_date, UNIX_TIMESTAMP(T.start_date) AS sd, UNIX_TIMESTAMP(T.end_date) AS ed 
26           FROM ".TABLE_PREFIX."tests T, ".TABLE_PREFIX."tests_questions_assoc Q 
27          WHERE Q.test_id=T.test_id 
28            AND T.course_id IN $enrolled_courses 
29          GROUP BY T.test_id 
30          ORDER BY T.start_date DESC";
31         $result = mysql_query($sql, $db);
32         if($result){
33                 while($row = mysql_fetch_assoc($result)){
34                         //show only the visible tests
35                         if ( ($row['sd'] <= time()) && ($row['ed'] >= time())){
36                                 $news[] = array('time'=>$row['start_date'], 
37                                                                 'object'=>$row,
38                                                                 'alt'=>_AT('tests'),
39                                                                 'course'=>$system_courses[$row['course_id']]['title'],
40                                                                 'thumb'=>'images/home-tests_sm.png',
41                                                                 'link'=>'<a href="bounce.php?course='.$row['course_id'].'&p='.urlencode('mods/_standard/tests/test_intro.php?tid='.$row['test_id']).'" '
42                                                                                 .(strlen($row['title']) > SUBLINK_TEXT_LEN ? ' title="'.$row['title'].'"' : '') .'>'
43                                                                                 .validate_length($row['title'], SUBLINK_TEXT_LEN, VALIDATE_LENGTH_FOR_DISPLAY) .'</a> <small>('._AT('start_date').':'.AT_DATE('%F %j, %g:%i',$row['start_date']).')</small>');
44                         }
45                 }
46         }
47         return $news;
48 }
49
50 ?>