decir/viewforum.php
author Dan
Wed, 17 Oct 2007 23:44:22 -0400
changeset 4 c31210950118
parent 2 253118325c65
child 6 3f66ec435f08
permissions -rw-r--r--
Some access controls implemented... we'll see how well this works
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
     1
<?php
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
     2
/*
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
     3
 * Decir
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
     4
 * Version 0.1
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
     5
 * Copyright (C) 2007 Dan Fuhry
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
     6
 * install.php - Database installation wizard
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
     7
 *
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
     8
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
     9
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    10
 *
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    11
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    12
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    13
 */
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    14
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    15
require('common.php');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    16
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    17
$template->header();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    18
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    19
$fid = ( $n = $paths->getParam(1) ) ? $n : ( ( isset($_GET['fid']) ) ? $_GET['fid'] : 0 );
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    20
$fid = intval($fid);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    21
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    22
if(empty($fid))
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    23
{
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    24
  echo '<p>Invalid forum ID</p>';
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    25
  $template->footer();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    26
  return;
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    27
}
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    28
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    29
$perms = $session->fetch_page_acl((string)$fid, 'DecirForum');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    30
if ( !$perms->get_permissions('decir_view_forum') )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    31
{
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    32
  die_friendly('Access denied', '<p>You are not authorized to view this forum.</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    33
}
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    34
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    35
$sort_column = ( isset($_GET['sort_column']) && in_array($_GET['sort_column'], array('t.timestamp', 't.topic_title')) ) ? $_GET['sort_column'] : 't.timestamp';
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    36
$sort_dir    = ( isset($_GET['sort_dir'])    && in_array($_GET['sort_dir'],    array('ASC', 'DESC')) ) ? $_GET['sort_dir'] : 'DESC';
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    37
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    38
$q = $db->sql_query('SELECT t.topic_id,t.topic_title,t.topic_type,t.topic_icon,
2
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
    39
                     t.num_views,t.topic_starter AS starter_id, u.username AS topic_starter,
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    40
                     p.poster_name AS last_post_name, p.timestamp AS last_post_time, t.topic_deleted, u2.username AS deletor,
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    41
                     t.topic_delete_reason
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    42
                       FROM '.table_prefix.'decir_topics AS t
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    43
                     LEFT JOIN '.table_prefix.'decir_posts AS p
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    44
                       ON (t.topic_id = p.topic_id)
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    45
                     LEFT JOIN '.table_prefix.'decir_hits AS h
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    46
                       ON (t.topic_id=h.topic_id)
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    47
                     LEFT JOIN '.table_prefix.'users AS u
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    48
                       ON (u.user_id=t.topic_starter)
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    49
                     LEFT JOIN '.table_prefix.'users AS u2
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    50
                       ON (u2.user_id = t.topic_deletor OR t.topic_deletor IS NULL)
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    51
                     WHERE t.forum_id='.$fid.'
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    52
                     GROUP BY p.post_id
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    53
                     ORDER BY '.$sort_column.' '.$sort_dir.', p.timestamp DESC;');
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    54
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    55
if(!$q)
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    56
  $db->_die();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    57
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    58
echo '<div class="tblholder">
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    59
      <table border="0" cellspacing="1" cellpadding="4">
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    60
      <tr>
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    61
        <th colspan="3">Topic</th>
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    62
        <th>Author</th>
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    63
        <th>Replies</th>
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    64
        <th>Views</th>
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    65
        <th>Last post</th>
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    66
      </th>';
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    67
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    68
if ( $row = $db->fetchrow() )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    69
{
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    70
  $last_row = $row;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    71
  $i = 0;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    72
  $num_replies = -1;
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    73
  do
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    74
  {
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    75
    $i++;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    76
    if ( $last_row['topic_id'] != $row['topic_id'] || $i == $db->numrows() )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    77
    {
2
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
    78
      if ( $num_replies < 0 )
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
    79
        $num_replies = 0;
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    80
      if ( $last_row['topic_deleted'] == 1 )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    81
      {
4
c31210950118 Some access controls implemented... we'll see how well this works
Dan
parents: 2
diff changeset
    82
        $thread_link = '&lt;Deleted&gt;';
c31210950118 Some access controls implemented... we'll see how well this works
Dan
parents: 2
diff changeset
    83
        if ( $session->get_permissions('decir_see_deleted_topic_full') )
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    84
        {
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    85
          $thread_link = '<b><a class="wikilink-nonexistent" href="' . makeUrlNS('DecirTopic', $last_row['topic_id']) . '">' . $last_row['topic_title'] . '</a></b>';
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    86
        }
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    87
        echo '<tr>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    88
              <td class="row2"></td>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    89
              <td class="row2"></td>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    90
              <td class="row2" style="width: 100%;">' . $thread_link . '</td>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    91
              <td class="row3" style="text-align: center;" colspan="4">Thread deleted by <b>' . htmlspecialchars($row['deletor']) . '</b><br />Reason: <i>' . htmlspecialchars($row['topic_delete_reason']) . '</i></td>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    92
            </tr>';
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    93
      }
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    94
      else
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    95
      {
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    96
        echo '<tr>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    97
              <td class="row2"></td>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    98
              <td class="row2"></td>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    99
              <td class="row2" style="width: 100%;"><b><a href="' . makeUrlNS('DecirTopic', $last_row['topic_id']) . '">' . $last_row['topic_title'] . '</a></b></td>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   100
              <td class="row3" style="text-align: center; max-width: 100px;">' . $last_row['topic_starter'] . '</td>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   101
              <td class="row1" style="text-align: center; width: 50px;">' . $num_replies . '</td>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   102
              <td class="row1" style="text-align: center; width: 50px;">' . $last_row['num_views'] . '</td>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   103
              <td class="row3" style="text-align: center;"><small style="white-space: nowrap;">' . date('d M Y h:i a', $last_row['last_post_time']) . '<br />by '.$last_row['last_post_name'].'</small></td>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   104
            </tr>';
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   105
      }
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   106
      $num_replies = 0;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   107
    }
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   108
    $num_replies++;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   109
    $last_row = $row;
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   110
  } while ( $row = $db->fetchrow() );
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   111
}
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   112
else
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   113
{
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   114
  echo '<tr>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   115
          <td colspan="7" style="text-align: center;" class="row1">There are no topics in this forum.</td>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   116
        </tr>';
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   117
}
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   118
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   119
echo '</table></div>';
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   120
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   121
if ( $perms->get_permissions('decir_post') )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   122
{
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   123
  echo '<p><a href="' . makeUrlNS('Special', 'Forum/New/Topic/' . $fid) . '">Post new topic</a></p>';
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   124
}
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   125
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   126
$template->footer();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   127
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   128
?>