-
Notifications
You must be signed in to change notification settings - Fork 56
/
events.php
149 lines (126 loc) · 6.16 KB
/
events.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
<?php
// page header, and any additional required libraries
require_once 'header.php';
// minimum permission to view page
valid_login($action_permission['read']);
//#############################################################################
// EVENTS
//#############################################################################
function events()
{
global $output, $lang_events,
$realm_id, $world_db,
$itemperpage;
$sqlw = new SQL;
$sqlw->connect($world_db[$realm_id]['addr'], $world_db[$realm_id]['user'], $world_db[$realm_id]['pass'], $world_db[$realm_id]['name']);
//-------------------SQL Injection Prevention--------------------------------
// this page has multipage support and field ordering, so we need these
$start = (isset($_GET['start'])) ? $sqlw->quote_smart($_GET['start']) : 0;
if (is_numeric($start));
else
$start=0;
$order_by = (isset($_GET['order_by'])) ? $sqlw->quote_smart($_GET['order_by']) : 'description';
if (preg_match('/^[_[:lower:]]{1,11}$/', $order_by));
else
$order_by='description';
$dir = (isset($_GET['dir'])) ? $sqlw->quote_smart($_GET['dir']) : 1;
if (preg_match('/^[01]{1}$/', $dir));
else
$dir=1;
$order_dir = ($dir) ? 'ASC' : 'DESC';
$dir = ($dir) ? 0 : 1;
// for multipage support
$all_record = $sqlw->result($sqlw->query('SELECT count(*) FROM game_event WHERE start_time <> end_time'),0);
// main data that we need for this page, game events
$result = $sqlw->query('SELECT description, start_time, occurence, length
FROM game_event WHERE start_time <> end_time ORDER BY '.$order_by.' '.$order_dir.' LIMIT '.$start.', '.$itemperpage.'');
//---------------Page Specific Data Starts Here--------------------------
// we start with a lead of 10 spaces,
// because last line of header is an opening tag with 8 spaces
// keep html indent in sync, so debuging from browser source would be easy to read
$output .= '
<!-- start of events.php -->
<center>
<table class="top_hidden">
<tr>
<td width="25%" align="right">';
// multi page links
$output .= $lang_events['total'].' : '.$all_record.'<br /><br />'.
generate_pagination('events.php?order_by='.$order_by.'&dir='.(($dir) ? 0 : 1), $all_record, $itemperpage, $start);
// column headers, with links for sorting
$output .= '
</td>
</tr>
</table>
<table class="lined">
<tr>
<th width="35%"><a href="events.php?order_by=description&start='.$start.'&dir='.$dir.'"'.($order_by==='description' ? ' class="'.$order_dir.'"' : '').'>'.$lang_events['descr'].'</a></th>
<th width="25%"><a href="events.php?order_by=start_time&start='.$start.'&dir='.$dir.'"'.($order_by==='start_time' ? ' class="'.$order_dir.'"' : '').'>'.$lang_events['start'].'</a></th>
<th width="20%"><a href="events.php?order_by=occurence&start='.$start.'&dir='.$dir.'"'.($order_by==='occurence' ? ' class="'.$order_dir.'"' : '').'>'.$lang_events['occur'].'</a></th>
<th width="20%"><a href="events.php?order_by=length&start='.$start.'&dir='.$dir.'"'.($order_by==='length' ? ' class="'.$order_dir.'"' : '').'>'.$lang_events['length'].'</a></th>
</tr>';
while ($events = $sqlw->fetch_assoc($result))
{
$days = floor(round($events['occurence'] / 60) / 24);
$hours = round($events['occurence'] / 60) - ($days * 24);
$event_occurance = '';
if ($days)
$event_occurance .= $days.' days ';
if ($hours)
$event_occurance .= $hours.' hours';
$days = floor(round($events['length'] / 60) / 24);
$hours = round($events['length'] / 60) - ($days * 24);
$event_duration = '';
if ($days)
$event_duration .= $days.' days ';
if ($hours)
$event_duration .= $hours.' hours';
$output .= '
<tr valign="top">
<td align="left">'.$events['description'].'</td>
<td>'.$events['start_time'].'</td>
<td>'.$event_occurance.'</td>
<td>'.$event_duration.'</td>
</tr>';
}
unset($event_duration);
unset($event_occurance);
unset($hours);
unset($days);
unset($events);
unset($result);
$output .= '
<tr>
<td colspan="4" class="hidden" align="right" width="25%">';
// multi page links
$output .= generate_pagination('events.php?order_by='.$order_by.'&dir='.(($dir) ? 0 : 1), $all_record, $itemperpage, $start);
unset($start);
$output .= '
</td>
</tr>
<tr>
<td colspan="4" class="hidden" align="right">'.$lang_events['total'].' : '.$all_record.'</td>
</tr>
</table>
</center>
<!-- end of events.php -->';
}
//#############################################################################
// MAIN
//#############################################################################
// error variable reserved for future use
//$err = (isset($_GET['error'])) ? $_GET['error'] : NULL;
//unset($err);
$lang_events = lang_events();
$output .= '
<div class="top">
<h1>'.$lang_events['events'].'</h1>
</div>';
// action variable reserved for future use
//$action = (isset($_GET['action'])) ? $_GET['action'] : NULL;
events();
//unset($action);
unset($action_permission);
unset($lang_events);
require_once 'footer.php';
?>