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