Vanilla commit.
[tinybbs.git] / statistics.php
blob297fa68d3ab388fae219a31825940c85483a9345
1 <?php
3 require('includes/header.php');
4 force_id();
5 update_activity('statistics');
6 $page_title = 'Statistics';
8 $statistics = array();
10 $query = 'SELECT count(*) FROM topics;';
11 $query .= 'SELECT count(*) FROM replies;';
12 $query .= 'SELECT count(*) FROM uid_bans;';
13 $query .= "SELECT count(*) FROM topics WHERE author = '" . $link->real_escape_string($_SESSION['UID']) . "';";
14 $query .= "SELECT count(*) FROM replies WHERE author = '" . $link->real_escape_string($_SESSION['UID']) . "';";
15 $query .= 'SELECT count(*) FROM ip_bans;';
17 $link->multi_query($query);
18 do {
19 $result = $link->store_result();
20 while ($row = $result->fetch_row())
22 $statistics[] = $row[0];
24 $result->free();
25 } while ($link->next_result());
27 $num_topics = $statistics[0];
28 $num_replies = $statistics[1];
29 $replies_per_topic = round($num_replies / $num_topics);
30 $num_bans = $statistics[2];
31 $your_topics = $statistics[3];
32 $your_replies = $statistics[4];
33 $your_posts = $your_topics + $your_replies;
34 $num_ip_bans = $statistics[5];
36 $total_posts = $num_topics + $num_replies;
37 $days_since_start = floor(( $_SERVER['REQUEST_TIME'] - SITE_FOUNDED ) / 86400);
38 if ($days_since_start == 0) //Fix a division by zero error
39 $days_since_start = 1;
40 $posts_per_day = round($total_posts / $days_since_start);
41 $topics_per_day = round($num_topics / $days_since_start);
42 $replies_per_day = round($num_replies / $days_since_start);
46 <table>
47 <tr>
48 <th></th>
49 <th class="minimal">Amount</th>
50 <th>Comment</th>
51 </tr>
53 <tr class="odd">
54 <th class="minimal">Total existing posts</th>
55 <td class="minimal"><?php echo format_number($total_posts) ?></td>
56 <td>-</td>
57 </tr>
59 <tr>
60 <th class="minimal">Existing topics</th>
61 <td class="minimal"><?php echo format_number($num_topics) ?></td>
62 <td>-</td>
63 </tr>
65 <tr class="odd">
66 <th class="minimal">Existing replies</th>
67 <td class="minimal"><?php echo format_number($num_replies) ?></td>
68 <td>That's ~<?php echo $replies_per_topic ?> replies/topic.</td>
69 </tr>
71 <tr>
72 <th class="minimal">Posts/day</th>
73 <td class="minimal">~<?php echo format_number($posts_per_day) ?></td>
74 <td>-</td>
75 </tr>
77 <tr class="odd">
78 <th class="minimal">Topics/day</th>
79 <td class="minimal">~<?php echo format_number($topics_per_day) ?></td>
80 <td>-</td>
81 </tr>
83 <tr>
84 <th class="minimal">Replies/day</th>
85 <td class="minimal">~<?php echo format_number($replies_per_day) ?></td>
86 <td>-</td>
87 </tr>
89 <tr class="odd">
90 <th class="minimal">Temporarily banned IDs</th>
91 <td class="minimal"><?php echo format_number($num_bans) ?></td>
92 <td>-</td>
93 </tr>
95 <tr>
96 <th class="minimal">Banned IP addresses</th>
97 <td class="minimal"><?php echo format_number($num_ip_bans) ?></td>
98 <td>-</td>
99 </tr>
101 <tr class="odd">
102 <th class="minimal">Days since launch</th>
103 <td class="minimal"><?php echo number_format($days_since_start) ?></td>
104 <td>Went live on <?php echo date('Y-m-d', SITE_FOUNDED) . ', ' . calculate_age(SITE_FOUNDED) ?> ago.</td>
105 </tr>
106 </table>
108 <table>
109 <tr>
110 <th></th>
111 <th>Amount</th>
112 </tr>
114 <tr class="odd">
115 <th class="minimal">Total posts by you</th>
116 <td><?php echo format_number($your_posts) ?></td>
117 </tr>
119 <tr>
120 <th class="minimal">Topics started by you</th>
121 <td><?php echo format_number($your_topics) ?></td>
122 </tr>
124 <tr class="odd">
125 <th class="minimal">Replies by you</th>
126 <td><?php echo format_number($your_replies) ?></td>
127 </tr>
128 </table>
130 <?php
132 require('includes/footer.php');