home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / forums / view_topics.php < prev    next >
Encoding:
PHP Script  |  2003-05-08  |  3.5 KB  |  118 lines

  1. <?php /* FORUMS $Id: view_topics.php,v 1.17 2003/05/08 06:44:49 eddieajau Exp $ */
  2. $AppUI->savePlace();
  3.  
  4. //Pull All Messages
  5. $sql = "
  6. SELECT fm1.*,
  7.     COUNT(fm2.message_id) AS replies,
  8.     MAX(fm2.message_date) AS latest_reply,
  9.     user_username, user_first_name,
  10.     watch_user
  11. FROM forum_messages fm1
  12. LEFT JOIN users ON fm1.message_author = users.user_id
  13. LEFT JOIN forum_messages fm2 ON fm1.message_id = fm2.message_parent
  14. LEFT JOIN forum_watch ON watch_user = $AppUI->user_id AND watch_topic = fm1.message_id
  15. WHERE fm1.message_forum = $forum_id
  16. ";
  17. switch ($f) {
  18.     case 1:
  19.         $sql.= " AND watch_user IS NOT NULL";
  20.         break;
  21.     case 2:
  22.         $sql.= " AND (NOW() < DATE_ADD(fm2.message_date, INTERVAL 30 DAY) OR NOW() < DATE_ADD(fm1.message_date, INTERVAL 30 DAY))";
  23.         break;
  24. }
  25. $sql .= "
  26. GROUP BY
  27.     fm1.message_id,
  28.     fm1.message_parent,
  29.     fm1.message_author,
  30.     fm1.message_title,
  31.     fm1.message_date,
  32.     fm1.message_body,
  33.     fm1.message_published" .
  34.   ( @$dPconfig['forum_descendent_order'] ? " ORDER BY latest_reply DESC" : "" );
  35.  
  36. $topics = db_loadList( $sql );
  37. ##echo "<pre>$sql</pre>".db_error();
  38.  
  39. $crumbs = array();
  40. $crumbs["?m=forums"] = "forums list";
  41. ?>
  42. <table width="100%" cellspacing="1" cellpadding="2" border="0">
  43. <tr>
  44.     <td><?php echo breadCrumbs( $crumbs );?></td>
  45.     <td align="right">
  46.     <?php if ($canEdit) { ?>
  47.         <input type="button" class=button style="width:120;" value="<?php echo $AppUI->_( 'start a new topic' );?>" onClick="javascript:window.location='./index.php?m=forums&a=viewer&forum_id=<?php echo $forum_id;?>&post_message=1';">
  48.     <?php } ?>
  49.     </td>
  50. </tr>
  51. </table>
  52.  
  53. <table width="100%" cellspacing="1" cellpadding="2" border="0" class="tbl">
  54. <form name="watcher" action="?m=forums&a=viewer&forum_id=<?php echo $forum_id;?>&f=<?php echo $f;?>" method="post">
  55. <tr>
  56.     <th><?php echo $AppUI->_('Watch');?></th>
  57.     <th><?php echo $AppUI->_('Topics');?></th>
  58.     <th><?php echo $AppUI->_('Author');?></th>
  59.     <th><?php echo $AppUI->_('Replies');?></th>
  60.     <th><?php echo $AppUI->_('Last Post');?></th>
  61. </tr>
  62. <?php
  63.  
  64. $now = new CDate();
  65.  
  66. foreach ($topics as $row) {
  67.     $last = intval( $row["latest_reply"] ) ? new CDate( $row["latest_reply"] ) : null;
  68.     
  69. //JBF limit displayed messages to first-in-thread
  70.     if ($row["message_parent"] < 0) { ?>
  71. <tr>
  72.     <td nowrap="nowrap" align="center" width="1%">
  73.         <input type="checkbox" name="forum_<?php echo $row['message_id'];?>" <?php echo $row['watch_user'] ? 'checked' : '';?> />
  74.     </td>
  75.     <td>
  76.         <span style="font-size:10pt;">
  77.         <a href="?m=forums&a=viewer&forum_id=<?php echo $forum_id . "&message_id=" . $row["message_id"];?>"><?php echo $row["message_title"];?></a>
  78.         </span>
  79.     </td>
  80.     <td bgcolor="#dddddd" width="10%"><?php echo $row["user_username"];?></td>
  81.     <td align="center" width="10%"><?php echo  $row["replies"];?></td>
  82.     <td bgcolor="#dddddd" width="150" nowrap="nowrap">
  83. <?php if ($row["latest_reply"]) {
  84.         echo $last->format( "$df $tf" ).'<br /><font color=#999966>(';
  85.  
  86.         $span = new Date_Span();
  87.         $span->setFromDateDiff( $now, $last );
  88.  
  89.         printf( "%.1f", $span->format( "%d" ) );
  90.         echo ' '.$AppUI->_('days ago');
  91.  
  92.         echo ')</font>';
  93.     } else {
  94.         echo $AppUI->_("No replies");
  95.     }
  96. ?>
  97.     </td>
  98. </tr>
  99. <?php
  100. //JBF
  101.     }
  102. }?>
  103. </table>
  104.  
  105. <table width="100%" border="0" cellpadding="0" cellspacing="1">
  106. <input type="hidden" name="dosql" value="do_watch_forum" />
  107. <input type="hidden" name="watch" value="topic" />
  108. <tr>
  109.     <td> </td>
  110. </tr>
  111. <tr>
  112.     <td align="left">
  113.         <input type="submit" class="button" value="<?php echo $AppUI->_( 'update watches' );?>" />
  114.     </td>
  115. </tr>
  116. </form>
  117. </table>
  118.