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