tagging as ATutor 1.5.4-release
[atutor.git] / include / html / forum.inc.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2007 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
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 if (!defined('AT_INCLUDE_PATH')) { exit; }
14
15 $sql    = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."forums_threads WHERE parent_id=0 AND forum_id=$fid";
16 $result = mysql_query($sql, $db);
17 $num_threads = mysql_fetch_assoc($result);
18 $num_threads = $num_threads['cnt'];
19
20 $num_per_page = 10;
21 if (!$_GET['page']) {
22         $page = 1;
23 } else {
24         $page = intval($_GET['page']);
25 }
26 $start = ($page-1)*$num_per_page;
27 $num_pages = ceil($num_threads/$num_per_page);
28
29 $page_string = SEP.'fid='. $fid;
30
31 $orders = array('asc' => 'desc', 'desc' => 'asc');
32 $cols   = array('subject' => 1, 'num_comments' => 1, 'login' => 1, 'last_comment' => 1);
33
34 if (isset($_GET['asc'])) {
35         $order = 'asc';
36         $col   = isset($cols[$_GET['asc']]) ? $_GET['asc'] : 'last_comment';
37 } else if (isset($_GET['desc'])) {
38         $order = 'desc';
39         $col   = isset($cols[$_GET['desc']]) ? $_GET['desc'] : 'last_comment';
40 } else {
41         // no order set
42         $order = 'desc';
43         $col   = 'last_comment';
44 }
45
46 $sql    = "SELECT *, last_comment + 0 AS stamp, DATE_FORMAT(last_comment, '%Y-%m-%d %H-%i:%s') AS last_comment FROM ".TABLE_PREFIX."forums_threads WHERE parent_id=0 AND forum_id=$fid AND member_id>0 ORDER BY sticky DESC, $col $order LIMIT $start,$num_per_page";
47 $result = mysql_query($sql, $db);
48
49 if (!($row = mysql_fetch_assoc($result))) {
50         $msg->printInfos('NO_POSTS_FOUND');
51         return;
52 }
53 ?>
54 <table class="data static" summary="" rules="rows">
55 <colgroup>
56         <?php if ($col == 'subject'): ?>
57                 <col class="sort" />
58                 <col span="4" />
59         <?php elseif($col == 'num_comments'): ?>
60                 <col  />
61                 <col class="sort" />
62                 <col span="3" />
63         <?php elseif($col == 'login'): ?>
64                 <col span="2" />
65                 <col class="sort" />
66                 <col span="2" />
67         <?php elseif($col == 'last_comment'): ?>
68                 <col span="3" />
69                 <col class="sort" />
70                 <col />
71         <?php endif; ?>
72 </colgroup>
73 <thead>
74 <tr>
75         <th scope="col"><a href="forum/index.php?<?php echo $orders[$order]; ?>=subject<?php echo $page_string; ?>"><?php echo _AT('topic'); ?></a></th>
76         <th scope="col"><a href="forum/index.php?<?php echo $orders[$order]; ?>=num_comments<?php echo $page_string; ?>"><?php echo _AT('replies'); ?></a></th>
77         <th scope="col"><a href="forum/index.php?<?php echo $orders[$order]; ?>=login<?php echo $page_string; ?>"><?php echo _AT('started_by'); ?></a></th>
78         <th scope="col"><a href="forum/index.php?<?php echo $orders[$order]; ?>=last_comment<?php echo $page_string; ?>"><?php echo _AT('last_comment'); ?></a></th>
79 <?php
80         $colspan = 4;
81         if (authenticate(AT_PRIV_FORUMS, AT_PRIV_RETURN)) {
82                 echo '<th class="cat">&nbsp;</th>';
83                 $colspan++;
84         }
85
86         echo '</tr>';
87         echo '</thead>';
88         echo '<tfoot>';
89         echo '<tr>';
90         echo '<td style="background-image: none" colspan="'.$colspan.'" align="right">'._AT('page').': ';
91
92         for ($i=1; $i<=$num_pages; $i++) {
93                 if ($i == $page) {
94                         echo $i;
95                 } else {
96                         echo '<a href="'.$_SERVER['PHP_SELF'].'?fid='.$fid.SEP.'page='.$i.'">'.$i.'</a>';
97                 }
98
99                 if ($i<$num_pages){
100                         echo ' <span class="spacer">|</span> ';
101                 }
102         }
103         
104         echo '</td>';
105         echo '</tr>';
106         echo '</tfoot>';
107         echo '<tbody>';
108
109         $current_thread = $row['thread_id'];
110         do {
111                 $row['subject'] = AT_print($row['subject'], 'forums_threads.subject');
112
113                 /* crop the subject, if needed */
114                 if (strlen($row['subject']) > 28) {
115                         $row['subject'] = substr($row['subject'], 0, 25).'...';
116                 }
117                 echo '<tr>';
118                 echo '<td>';
119
120                 if ($_SESSION['valid_user']) {
121                         if ($row['stamp'] > $last_accessed[$row['post_id']]['last_accessed']) {
122                                 echo '<i style="color: green; font-weight: bold; font-size: .7em;" title="'._AT('new_thread').'">'._AT('new').'</i> ';
123                         }
124                 }
125
126                 if ($row['num_comments'] > 10) {
127                         echo '<em style="color: red; font-weight: bold; font-size: .7em;" title="'._AT('hot_thread').'">'._AT('hot').'</em> ';
128                 }
129
130                 if ($row['locked'] != 0) {
131                         echo '<img src="images/topic_lock.gif" alt="'._AT('thread_locked').'" class="menuimage3" title="'._AT('thread_locked').'" /> ';
132                 }
133                 
134                 if ($row['sticky'] != 0) {
135                         echo '<img src="images/forum/topic_stick.gif" alt="'._AT('sticky_thread').'" class="menuimage3"  title="'._AT('sticky_thread').'" /> ';
136                 }
137                 
138                 if ($row['locked'] != 1) {
139                         echo '<a href="forum/view.php?fid='.$fid.SEP.'pid='.$row['post_id'].'">'.$row['subject'].'</a>';
140
141                         if ($row['locked'] == 2) {
142                                 echo ' <i class="spacer">('._AT('post_lock').')</i>';
143                         }
144                 } else {
145                         echo $row['subject'].' <i class="spacer">('._AT('read_lock').')</i>';
146                 }
147
148                 /* print page numbers */
149                 $num_pages_2 = ceil(($row['num_comments']+1)/$num_per_page);
150
151                 if ($num_pages_2 > 1) {
152                         echo ' <small class="spacer">( Page: ';
153                         for ($i=2; $i<=$num_pages_2; $i++) {
154                                 echo '<a href="forum/view.php?fid='.$fid.SEP.'pid='.$row['post_id'].SEP.'page='.$i.'">'.$i.'</a>';
155
156                                 if ($i<$num_pages_2){
157                                         echo ' | ';
158                                 }
159                         }
160                         echo ' )</small> ';
161                 }
162                 if ($_SESSION['enroll'] && !$row['locked']) {
163                         if (isset($last_accessed[$row['post_id']]) && $last_accessed[$row['post_id']]['subscribe']){
164                                 echo  ' <br /><small><a href="forum/subscribe.php?us=1'.SEP.'pid='.$row['post_id'].SEP.'fid='.$fid.SEP.'t=1">('._AT('unsubscribe1').')</a></small>';
165                         } else {
166                                 echo  ' <br /><small><a href="forum/subscribe.php?pid='.$row['post_id'].SEP.'fid='.$fid.SEP.'t=1">('._AT('subscribe1').')</a></small>';
167                         }
168                 }
169                 echo '</td>';
170
171                 echo '<td width="10%" align="center">'.$row['num_comments'].'</td>';
172
173                 echo '<td width="10%"><a href="'.AT_BASE_HREF.'profile.php?id='.$row['member_id'].'">'.get_display_name($row['member_id']).'</a></td>';
174
175                 echo '<td width="20%" align="right" nowrap="nowrap">';
176                 echo AT_date(_AT('forum_date_format'), $row['last_comment'], AT_DATE_MYSQL_DATETIME);
177                 echo '</td>';
178
179                 if (authenticate(AT_PRIV_FORUMS, AT_PRIV_RETURN)) {
180                         echo '<td nowrap="nowrap">';
181                         echo ' <a href="forum/stick.php?fid='.$fid.SEP.'pid='.$row['post_id'].'"><img src="images/forum/sticky.gif" border="0" alt="'._AT('sticky_thread').'" title="'._AT('sticky_thread').'" /></a> ';
182
183                         if ($row['locked'] != 0) {
184                                 echo '<a href="forum/lock_thread.php?fid='.$fid.SEP.'pid='.$row['post_id'].SEP.'unlock='.$row['locked'].'"><img src="images/unlock.gif" border="0"  alt="'._AT('unlock_thread').'" title="'._AT('unlock_thread').'"/></a>';
185                         } else {
186                                 echo '<a href="forum/lock_thread.php?fid='.$fid.SEP.'pid='.$row['post_id'].'"><img src="images/lock.gif" border="0" alt="'._AT('lock_thread').'"   title="'._AT('lock_thread').'"/></a>';
187                         }
188                         echo ' <a href="forum/move_thread.php?fid='.$fid.SEP.'pid='.$row['post_id'].SEP.'ppid=0"><img src="images/forum/move.gif" border="0" alt="'._AT('move_thread').'" title="'._AT('move_thread').'"/></a>';
189
190                         echo ' <a href="forum/delete_thread.php?fid='.$fid.SEP.'pid='.$row['post_id'].SEP.'ppid=0"><img src="images/icon_delete.gif" border="0" alt="'._AT('delete_thread').'" title="'._AT('delete_thread').'"/></a>';
191                         
192                         echo '</td>';
193                 }
194                 echo '</tr>';
195
196         } while ($row = mysql_fetch_assoc($result));
197         echo '</tbody>';
198         echo '</table>';
199
200 ?>