/
pubbans.php
169 lines (138 loc) · 4.31 KB
/
pubbans.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
169
<?php
$auth_user_here = false;
$page = 'pubbans';
$page_title = 'Public Ban List';
$b3_conn = true; // this page needs to connect to the B3 database
$pagination = true; // this page requires the pagination part of the footer
$query_normal = true;
require 'inc.php';
checkBL(); // check the blacklist for the users IP (this is needed because this is a public page)
##########################
######## Varibles ########
## Default Vars ##
$orderby = "time_add";
$order = "DESC";
## Sorts requests vars ##
if($_GET['ob'])
$orderby = addslashes($_GET['ob']);
if($_GET['o'])
$order = addslashes($_GET['o']);
// allowed things to sort by
$allowed_orderby = array('name', 'time_add', 'time_expire');
if(!in_array($orderby, $allowed_orderby)) // Check if the sent varible is in the allowed array
$orderby = 'time_add'; // if not just set to default id
## Page Vars ##
if ($_GET['p'])
$page_no = addslashes($_GET['p']);
$start_row = $page_no * $limit_rows;
$time = time();
###########################
######### QUERIES #########
$query = "SELECT SQL_CACHE c.id as client_id, c.name, p.id as ban_id, p.type, p.time_add, p.time_expire, p.reason, p.duration FROM penalties p LEFT JOIN clients c ON p.client_id = c.id WHERE p.inactive = 0 AND p.type != 'Warning' AND p.type != 'Notice' AND (p.time_expire = -1 OR p.time_expire > $time)";
$query .= sprintf(" ORDER BY %s ", $orderby);
## Append this section to all queries since it is the same for all ##
if($order == "DESC")
$query .= " DESC"; // set to desc
else
$query .= " ASC"; // default to ASC if nothing adds up
$query_limit = sprintf("%s LIMIT %s, %s", $query, $start_row, $limit_rows); // add limit section
## Require Header ##
require 'inc/header.php';
if(!$db->error) :
?>
<table summary="A list of <?php echo $limit_rows; ?> active tempbans/bans">
<caption>Public Ban List<small>There are <strong><?php echo $total_rows; ?></strong> active bans/tempbans for
<form action="pubbans.php" method="get" id="pubbans-form" class="sm-f-select">
<select name="game" onchange="this.form.submit()">
<?php
$games_list = $dbl->getGamesList();
$i = 0;
$count = count($games_list);
$count--; // minus 1
while($i <= $count) :
if($game == $games_list[$i]['id'])
$selected = 'selected="selected"';
else
$selected = NULL;
echo '<option value="'. $games_list[$i]['id'] .'" '. $selected .'>'. $games_list[$i]['name'] .'</option>';
$i++;
endwhile;
?>
</select>
</form>
</small>
</caption>
<thead>
<tr>
<th>Client
<?php linkSort('name', 'Name'); ?>
</th>
<th>Ban-id</th>
<th>Type</th>
<th>Added
<?php linkSort('time_add', 'time the penalty was added'); ?>
</th>
<th>Duration</th>
<th>Expires
<?php linkSort('time_expire', 'time the penalty expires'); ?>
</th>
<th>Reason</th>
</tr>
</thead>
<tfoot>
<tr>
<th colspan="7"></th>
</tr>
</tfoot>
<tbody>
<?php
if($num_rows > 0) : // query contains stuff
foreach($data_set as $pen): // get data from query and loop
$ban_id = $pen['ban_id'];
$type = $pen['type'];
$time_add = $pen['time_add'];
$time_expire = $pen['time_expire'];
$reason = tableClean($pen['reason']);
$client_id = $pen['client_id'];
$client_name = tableClean($pen['name']);
$duration = $pen['duration'];
## Tidt data to make more human friendly
if($time_expire != '-1')
$duration_read = time_duration($duration*60); // all penalty durations are stored in minutes, so multiple by 60 in order to get seconds
else
$duration_read = '';
$time_expire_read = timeExpirePen($time_expire);
$time_add_read = date($tformat, $time_add);
$reason_read = removeColorCode($reason);
if($mem->loggedIn())
$client_name_read = clientLink($client_name, $client_id);
else
$client_name_read = $client_name;
## Row color
$alter = alter();
// setup heredoc (table data)
$data = <<<EOD
<tr class="$alter">
<td><strong>$client_name_read</strong></td>
<td>$ban_id</td>
<td>$type</td>
<td>$time_add_read</td>
<td>$duration_read</td>
<td>$time_expire_read</td>
<td>$reason_read</td>
</tr>
EOD;
echo $data;
endforeach;
$no_data = false;
else:
$no_data = true;
echo '<tr class="odd"><td colspan="7">There no active bans in the B3 Database</td></tr>';
endif;
?>
</tbody>
</table>
<?php
endif; // db error
require 'inc/footer.php';
?>