-
Notifications
You must be signed in to change notification settings - Fork 4
/
statistics.php
168 lines (141 loc) · 5.04 KB
/
statistics.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
// Include files, including the database connection
include('includes/dbConfig.php');
include('includes/functions.php');
// Start the session. This checks whether someone is logged in and if not redirects them
session_start();
if (isset($_SESSION['is_logged_in']) || $_SESSION['db_is_logged_in'] == true) {
// Just continue the code
} else {
header('Location: login.php');
exit;
}
if (!isAdmin()) {
header('Location: error.php?no=100&page='.basename($_SERVER['SCRIPT_FILENAME']));
exit;
}
// Get the query string
$method = $_GET["method"];
// If the form has been submitted, then we need to handle the data.
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if($method == 'truncate') {
$sql = "CREATE TABLE tmp_system_statistics as SELECT * from cr_statistics WHERE type='system'";
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
$sql = ("TRUNCATE TABLE cr_statistics");
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
$sql = ("ALTER TABLE cr_statistics AUTO_INCREMENT = 50");
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
$sql = "INSERT INTO cr_statistics (userid,date,type,detail1,detail2,detail3,script) ";
$sql = $sql . "SELECT userid,date,type,detail1,detail2,detail3,script from tmp_system_statistics order by date";
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
$sql = "DROP TABLE tmp_system_statistics";
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
insertStatistics("system",__FILE__,"statistics deleted");
// After we have truncated the data, we want to reload the page
header('Location: statistics.php'); // Move to the home page of the admin section
exit;
} else {
}
}
if($method == 'showall') {
$limit=" ";
$browserLimit=" ";
}
else{
$limit="LIMIT 10";
$browserLimit="LIMIT 5";
}
include('includes/header.php');
?>
<div class="elementBackground">
<h2>Church Rota Statistics:</h2>
<p>
<?php
if ($debug) {
echo "<table class=\"statistics\">";
echo "<thead>";
echo "<tr><th >Browser / Platform</th><th>Count</th></tr>";
echo "</thead>";
echo "<tbody>";
$sql = "SELECT VERSION( ) AS mysql_version";
$result = mysql_query($sql) or die("MySQL-Error: ".mysql_error());
$dbv = mysql_fetch_array($result, MYSQL_ASSOC);
$mysql_version = $dbv['mysql_version'];
if (substr($mysql_version,0,1) == 5) {
$sql = "SELECT getBrowserInfo(detail3) as browser,count(*) as count from cr_statistics where detail1 like 'login%' and detail3!='' group by getBrowserInfo(detail3) order by count desc ".$browserLimit;
}else{
$sql = "SELECT detail3 as browser,count(*) as count from cr_statistics where detail1 like 'login%' and detail3!='' group by detail3 order by count desc ".$browserLimit;
}
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
extract($row);
echo "<tr>";
echo "<td>".$browser."</td>";
echo "<td>".$count."</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
}
?>
<p>
<table class="statistics">
<thead>
<tr><th>Date</th><th>User</th><th>Type</th><th>Action</th><th>Info</th></tr>
</thead>
<tbody>
<?php
$sql = "SELECT s.date,s.detail1,s.detail2,s.detail3,s.type,trim(concat(u.firstName,' ',u.lastName)) as name from cr_statistics s,cr_users u where u.ID=s.userID";
if ($debug==false) $sql = $sql . " and s.type = 'system'";
$sql = $sql . " ORDER BY date desc, detail1, detail2 desc " . $limit;
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
extract($row);
echo "<tr>";
echo "<td>".$date."</td>";
echo "<td>".$name."</td>";
echo "<td>".$type."</td>";
echo "<td>".$detail1."</td>";
echo "<td>".$detail2."</td>";
//echo "<td>".$detail3."</td>";
echo "</tr>";
}
?>
</tbody>
</table>
<a href="#" data-reveal-id="truncStatData" class="button">Delete User Statistics</a>
<div id="truncStatData" class="reveal-modal">
<h1>Really delete user statistics?</h1>
<p>Are you sure you really want to delete ALL user statistics data? <br>There is no way of undoing this action.</p>
<p><form action="statistics.php?method=truncate" method="post" id="truncate">
<input type="submit" value="Sure, delete statistics" /></form></p>
<a class="close-reveal-modal">×</a>
</div>
</div>
<?php
if(isAdmin()) { ?>
<div id="right">
<div class="item"><a href="settings.php">Back to settings</a></div>
<?php if($method != "showall") { ?>
<div class="item"><a href="statistics.php?method=showall">Show all statistics</a></div>
<?php } else { ?>
<div class="item"><a href="statistics.php">Show latest statistics</a></div>
<?php } ?>
</div>
<?php } ?>
<?php include('includes/footer.php'); ?>