home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / forums / index.php < prev    next >
Encoding:
PHP Script  |  2003-12-09  |  6.7 KB  |  206 lines

  1. <?php /* FORUMS $Id: index.php,v 1.28 2003/12/09 00:26:49 gregorerhardt Exp $ */
  2. $AppUI->savePlace();
  3.  
  4. $df = $AppUI->getPref( 'SHDATEFORMAT' );
  5. $tf = $AppUI->getPref( 'TIMEFORMAT' );
  6.  
  7. $f = dPgetParam( $_POST, 'f', 0 );
  8.  
  9.  
  10. // get read denied projects
  11. $deny = array();
  12. $sql = "
  13. SELECT project_id
  14. FROM projects, permissions
  15. WHERE permission_user = $AppUI->user_id
  16.     AND permission_grant_on = 'projects'
  17.     AND permission_item = project_id
  18.     AND permission_value = 0
  19. ";
  20. $deny1 = db_loadColumn( $sql );
  21.  
  22. // get read denied forums
  23. $deny = array();
  24. $sql = "
  25. SELECT forum_id
  26. FROM forums, permissions
  27. WHERE permission_user = $AppUI->user_id
  28.     AND permission_grant_on = 'forums'
  29.     AND permission_item = forum_id
  30.     AND permission_value = 0
  31. ";
  32. $deny2 = db_loadColumn( $sql );
  33.  
  34. $max_msg_length = 30;
  35. $sql = "
  36. SELECT forum_id, forum_project, forum_description, forum_owner, forum_name, forum_moderated,
  37.     forum_create_date, forum_last_date,
  38.     COUNT(distinct t.message_id) forum_topics, COUNT(distinct r.message_id) forum_replies,
  39.     user_username,
  40.     project_name, project_color_identifier,
  41.     SUBSTRING(l.message_body,1,$max_msg_length) message_body,
  42.     LENGTH(l.message_body) message_length,
  43.     watch_user,
  44.     l.message_parent,
  45.     l.message_id
  46. FROM forums, users, projects, permissions
  47. LEFT JOIN forum_messages t ON t.message_forum = forum_id AND t.message_parent = -1
  48. LEFT JOIN forum_messages r ON r.message_forum = forum_id AND r.message_parent > -1
  49. LEFT JOIN forum_messages l ON l.message_id = forum_last_id
  50. LEFT JOIN forum_watch ON watch_user = $AppUI->user_id AND watch_forum = forum_id
  51. WHERE user_id = forum_owner
  52.     AND project_id = forum_project
  53. # filter projects permissions
  54.     AND permission_user = $AppUI->user_id
  55.     AND permission_value <> 0
  56.     AND (
  57.         (permission_grant_on = 'all')
  58.         OR (permission_grant_on = 'projects' AND permission_item = -1)
  59.         OR (permission_grant_on = 'projects' AND permission_item = project_id)
  60.         OR (permission_grant_on = 'forums' AND permission_item = -1)
  61.         OR (permission_grant_on = 'forums' AND permission_item = forum_id)
  62.         )"
  63. .(count($deny1) > 0 ? "\nAND forum_project NOT IN (" . implode( ',', $deny1 ) . ')' : '')
  64. .(count($deny2) > 0 ? "\nAND forum_id NOT IN (" . implode( ',', $deny2 ) . ')' : '')
  65. ;
  66.  
  67. //if (isset($project_id) && $project_id) {
  68. //    $sql.= "\nAND forum_project = $project_id";
  69. //}
  70. switch ($f) {
  71.     case 1:
  72.         $sql .= "\nAND project_active=1 AND forum_owner = $AppUI->user_id";
  73.         break;
  74.     case 2:
  75.         $sql .= "\nAND project_active=1 AND watch_user IS NOT NULL";
  76.         break;
  77.     case 3:
  78.         $sql .= "\nAND project_active=1 AND project_owner = $AppUI->user_id";
  79.         break;
  80.     case 4:
  81.         $sql .= "\nAND project_active=1 AND project_company = $AppUI->user_company";
  82.         break;
  83.     case 5:
  84.         $sql .= "\nAND project_active=0";
  85.         break;
  86.     default:
  87.         $sql .= "\nAND project_active=1";
  88.         break;
  89. }
  90. $sql .= "\nGROUP BY forum_id\nORDER BY forum_project, forum_name";
  91.  
  92. $forums = db_loadList( $sql );
  93. ##echo "<pre>$sql</pre>".db_error();##
  94.  
  95. // setup the title block
  96. $titleBlock = new CTitleBlock( 'Forums', 'support.png', $m, "$m.$a" );
  97. $titleBlock->addCell(
  98.     arraySelect( $filters, 'f', 'size="1" class="text" onChange="document.forum_filter.submit();"', $f , true ), '',
  99.     '<form name="forum_filter" action="?m=forums" method="post">', '</form>'
  100. );
  101. if ($canEdit) {
  102.     $titleBlock->addCell(
  103.         '<input type="submit" class="button" value="'.$AppUI->_('new forum').'">', '',
  104.         '<form action="?m=forums&a=addedit" method="post">', '</form>'
  105.     );
  106. }
  107. $titleBlock->show();
  108. ?>
  109.  
  110. <table width="100%" cellspacing="1" cellpadding="2" border="0" class="tbl">
  111. <form name="watcher" action="./index.php?m=forums&f=<?php echo $f;?>" method="post">
  112. <tr>
  113.     <th nowrap="nowrap"> </th>
  114.     <th nowrap="nowrap" width="25"><?php echo $AppUI->_( 'Watch' );?></th>
  115.     <th nowrap="nowrap"><?php echo $AppUI->_( 'Forum Name' );?></th>
  116.     <th nowrap="nowrap" width="50" align="center"><?php echo $AppUI->_( 'Topics' );?></th>
  117.     <th nowrap="nowrap" width="50" align="center"><?php echo $AppUI->_( 'Replies' );?></th>
  118.     <th nowrap="nowrap" width="200"><?php echo $AppUI->_( 'Last Post Info' );?></th>
  119. </tr>
  120. <?php
  121. $p ="";
  122. $now = new CDate();
  123. foreach ($forums as $row) {
  124.     $message_date = intval( $row['forum_last_date'] ) ? new CDate( $row['forum_last_date'] ) : null;
  125.  
  126.     if($p != $row["forum_project"]) {
  127.         $create_date = intval( $row['forum_create_date'] ) ? new CDate( $row['forum_create_date'] ) : null;
  128. ?>
  129. <tr>
  130.     <td colspan="6" style="background-color:#<?php echo $row["project_color_identifier"];?>">
  131.         <a href="?m=projects&a=view&project_id=<?php echo $row["forum_project"];?>">
  132.             <font color=<?php echo bestColor( $row["project_color_identifier"] );?>>
  133.             <strong><?php echo $row["project_name"];?></strong>
  134.             </font>
  135.         </a>
  136.     </td>
  137. </tr>
  138.     <?php
  139.         $p = $row["forum_project"];
  140.     }?>
  141. <tr>
  142.     <td nowrap="nowrap" align="center">
  143.     <?php if ( $row["forum_owner"] == $AppUI->user_id || (!empty($perms['all']) && !getDenyEdit('all')) ) { ?>
  144.         <a href="?m=forums&a=addedit&forum_id=<?php echo $row["forum_id"];?>" title="<?php echo $AppUI->_('edit');?>">
  145.         <?php echo dPshowImage( './images/icons/stock_edit-16.png', 16, 16, '' );?>
  146.         </a>
  147.     <?php } ?>
  148.     </td>
  149.  
  150.     <td nowrap="nowrap" align="center">
  151.         <input type="checkbox" name="forum_<?php echo $row['forum_id'];?>" <?php echo $row['watch_user'] ? 'checked' : '';?> />
  152.     </td>
  153.  
  154.     <td>
  155.         <span style="font-size:10pt;font-weight:bold">
  156.             <a href="?m=forums&a=viewer&forum_id=<?php echo $row["forum_id"];?>"><?php echo $row["forum_name"];?></a>
  157.         </span>
  158.         <br /><?php echo $row["forum_description"];?>
  159.         <br /><font color="#777777"><?php echo $AppUI->_( 'Owner' ).' '.$row["user_username"];?>,
  160.         <?php echo $AppUI->_( 'Started' ).' '.$create_date->format( $df );?>
  161.         </font>
  162.     </td>
  163.     <td nowrap="nowrap" align="center"><?php echo $row["forum_topics"];?></td>
  164.     <td nowrap="nowrap" align="center"><?php echo $row["forum_replies"];?></td>
  165.     <td width="225">
  166. <?php
  167.     if ($message_date !== null) {
  168.         echo $message_date->format( "$df $tf" );
  169.  
  170.         $last = new Date_Span();
  171.         $last->setFromDateDiff( $now, $message_date );
  172.  
  173.         echo '<br /><font color=#999966>(' . $AppUI->_('Last post').' ';
  174.         printf( "%.1f", $last->format( "%d" ) );
  175.         echo ' '.$AppUI->_('days ago') . ') </font>';
  176.  
  177.         $id = $row['message_parent'] < 0 ? $row['message_id'] : $row['message_parent'];
  178.  
  179.         echo '<br />> <a href="?m=forums&a=viewer&forum_id='.$row['forum_id'].'&message_id='.$id.'">';
  180.         echo '<font color=#777777>'.$row['message_body'];
  181.         echo $row['message_length'] > $max_msg_length ? '...' : '';
  182.         echo '</font></a>';
  183.     } else {
  184.         echo $AppUI->_('No posts');
  185.     }
  186. ?>
  187.     </td>
  188. </tr>
  189.  
  190. <?php } ?>
  191. </table>
  192.  
  193. <table width="100%" cellspacing="1" cellpadding="0" border="0">
  194.     <input type="hidden" name="dosql" value="do_watch_forum" />
  195.     <input type="hidden" name="watch" value="forum" />
  196. <tr>
  197.     <td> </td>
  198. </tr>
  199. <tr>
  200.     <td align="left">
  201.         <input type="submit" class="button" value="<?php echo $AppUI->_( 'update watches' );?>" />
  202.     </td>
  203. </tr>
  204. </form>
  205. </table>
  206.