PageRenderTime 53ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/mods/_standard/forums/html/forum.inc.php

https://github.com/harriswong/ATutor
PHP | 195 lines | 153 code | 29 blank | 13 comment | 45 complexity | a8f1c1fa49a6ec6e0882c0959069e204 MD5 | raw file
  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. $sql = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."forums_threads WHERE parent_id=0 AND forum_id=$fid";
  14. $result = mysql_query($sql, $db);
  15. $num_threads = mysql_fetch_assoc($result);
  16. $num_threads = $num_threads['cnt'];
  17. $num_per_page = 10;
  18. if (!isset($_GET['page']) || !$_GET['page']) {
  19. $page = 1;
  20. } else {
  21. $page = intval($_GET['page']);
  22. }
  23. $start = ($page-1)*$num_per_page;
  24. $num_pages = ceil($num_threads/$num_per_page);
  25. $page_string = SEP.'fid='. $fid;
  26. $orders = array('asc' => 'desc', 'desc' => 'asc');
  27. $cols = array('subject' => 1, 'num_comments' => 1, 'last_comment' => 1);
  28. if (isset($_GET['asc'])) {
  29. $order = 'asc';
  30. $col = isset($cols[$_GET['asc']]) ? $_GET['asc'] : 'last_comment';
  31. } else if (isset($_GET['desc'])) {
  32. $order = 'desc';
  33. $col = isset($cols[$_GET['desc']]) ? $_GET['desc'] : 'last_comment';
  34. } else {
  35. // no order set
  36. $order = 'desc';
  37. $col = 'last_comment';
  38. }
  39. $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";
  40. $result = mysql_query($sql, $db);
  41. if (!($row = mysql_fetch_assoc($result))) {
  42. echo '<div class="input-form">';
  43. $msg->printInfos('NO_POSTS_FOUND');
  44. echo '</div>';
  45. return;
  46. }
  47. ?>
  48. <table class="data static" summary="" rules="rows">
  49. <colgroup>
  50. <?php if ($col == 'subject'): ?>
  51. <col class="sort" />
  52. <col span="4" />
  53. <?php elseif($col == 'num_comments'): ?>
  54. <col />
  55. <col class="sort" />
  56. <col span="3" />
  57. <?php elseif($col == 'last_comment'): ?>
  58. <col span="3" />
  59. <col class="sort" />
  60. <col />
  61. <?php endif; ?>
  62. </colgroup>
  63. <thead>
  64. <tr>
  65. <th scope="col"><a href="<?php echo url_rewrite($_SERVER['PHP_SELF']."?$orders[$order]=subject$page_string"); ?>"><?php echo _AT('topic'); ?></a></th>
  66. <th scope="col"><a href="<?php echo url_rewrite($_SERVER['PHP_SELF']."?$orders[$order]=num_comments$page_string"); ?>"><?php echo _AT('replies'); ?></a></th>
  67. <th scope="col"><?php echo _AT('started_by'); ?></th>
  68. <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>
  69. <?php
  70. $colspan = 4;
  71. if (authenticate(AT_PRIV_FORUMS, AT_PRIV_RETURN)) {
  72. echo '<th class="cat">&nbsp;</th>';
  73. $colspan++;
  74. }
  75. echo '</tr>';
  76. echo '</thead>';
  77. echo '<tfoot>';
  78. echo '<tr>';
  79. echo '<td style="background-image: none" colspan="'.$colspan.'" align="right">'._AT('page').': ';
  80. for ($i=1; $i<=$num_pages; $i++) {
  81. if ($i == $page) {
  82. echo $i;
  83. } else {
  84. echo '<a href="'.url_rewrite($_SERVER['PHP_SELF'].'?fid='.$fid.SEP.'page='.$i).'">'.$i.'</a>';
  85. }
  86. if ($i<$num_pages){
  87. echo ' <span class="spacer">|</span> ';
  88. }
  89. }
  90. echo '</td>';
  91. echo '</tr>';
  92. echo '</tfoot>';
  93. echo '<tbody>';
  94. do {
  95. /* crop the subject, if needed */
  96. $full_subject = $row['subject']; //save a copy before croping
  97. if ($strlen($row['subject']) > 28) {
  98. $row['subject'] = $substr($row['subject'], 0, 25).'...';
  99. }
  100. $row['subject'] = AT_print($row['subject'], 'forums_threads.subject');
  101. echo '<tr>';
  102. echo '<td>';
  103. if ($_SESSION['valid_user']) {
  104. if ($row['stamp'] > $last_accessed[$row['post_id']]['last_accessed']) {
  105. echo '<i style="color: green; font-weight: bold; font-size: .7em;" title="'._AT('new_thread').'">'._AT('new').'</i> ';
  106. }
  107. }
  108. if ($row['num_comments'] > 10) {
  109. echo '<em style="color: red; font-weight: bold; font-size: .7em;" title="'._AT('hot_thread').'">'._AT('hot').'</em> ';
  110. }
  111. if ($row['locked'] != 0) {
  112. echo '<img src="images/topic_lock.gif" alt="'._AT('thread_locked').'" class="menuimage3" title="'._AT('thread_locked').'" /> ';
  113. }
  114. if ($row['sticky'] != 0) {
  115. echo '<img src="images/forum/topic_stick.gif" alt="'._AT('sticky_thread').'" class="menuimage3" title="'._AT('sticky_thread').'" /> ';
  116. }
  117. if ($row['locked'] != 1) {
  118. 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>';
  119. if ($row['locked'] == 2) {
  120. echo ' <i class="spacer">('._AT('post_lock').')</i>';
  121. }
  122. } else {
  123. echo $row['subject'].' <i class="spacer">('._AT('read_lock').')</i>';
  124. }
  125. /* print page numbers */
  126. $num_pages_2 = ceil(($row['num_comments']+1)/$num_per_page);
  127. if ($num_pages_2 > 1) {
  128. echo ' <small class="spacer">( Page: ';
  129. for ($i=2; $i<=$num_pages_2; $i++) {
  130. 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>';
  131. if ($i<$num_pages_2){
  132. echo ' | ';
  133. }
  134. }
  135. echo ' )</small> ';
  136. }
  137. if ($_SESSION['enroll'] && !$row['locked']) {
  138. if (isset($last_accessed[$row['post_id']]) && $last_accessed[$row['post_id']]['subscribe']){
  139. 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>';
  140. } else {
  141. 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>';
  142. }
  143. }
  144. echo '</td>';
  145. echo '<td width="10%" align="center">'.$row['num_comments'].'</td>';
  146. echo '<td width="10%"><a href="'.AT_BASE_HREF.'profile.php?id='.$row['member_id'].'">'.get_display_name($row['member_id']).'</a></td>';
  147. echo '<td width="20%" align="right" nowrap="nowrap">';
  148. echo AT_date(_AT('forum_date_format'),$row['last_comment'], AT_DATE_MYSQL_DATETIME);
  149. echo '</td>';
  150. if (authenticate(AT_PRIV_FORUMS, AT_PRIV_RETURN)) {
  151. echo '<td nowrap="nowrap">';
  152. 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> ';
  153. if ($row['locked'] != 0) {
  154. 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>';
  155. } else {
  156. 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>';
  157. }
  158. 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>';
  159. 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>';
  160. echo '</td>';
  161. }
  162. echo '</tr>';
  163. } while ($row = mysql_fetch_assoc($result));
  164. echo '</tbody>';
  165. echo '</table>';
  166. ?>