source: trunk/test_server/instances.php@ 649

Last change on this file since 649 was 649, checked in by barny, 15 years ago

*Přidán minimanager pro test server

File size: 6.1 KB
Line 
1<?php
2
3
4// page header, and any additional required libraries
5require_once 'header.php';
6require_once 'libs/map_zone_lib.php';
7// minimum permission to view page
8valid_login($action_permission['read']);
9
10//#############################################################################
11// INSTANCES
12//#############################################################################
13function instances()
14{
15 global $output, $lang_instances,
16 $realm_id, $world_db, $mmfpm_db,
17 $server_type, $itemperpage;
18
19 $sqlw = new SQL;
20 $sqlw->connect($world_db[$realm_id]['addr'], $world_db[$realm_id]['user'], $world_db[$realm_id]['pass'], $world_db[$realm_id]['name']);
21
22 //-------------------SQL Injection Prevention--------------------------------
23 // this page has multipage support and field ordering, so we need these
24 $start = (isset($_GET['start'])) ? $sqlw->quote_smart($_GET['start']) : 0;
25 if (is_numeric($start)); else $start=0;
26
27 $order_by = (isset($_GET['order_by'])) ? $sqlw->quote_smart($_GET['order_by']) : 'level_min';
28 if (preg_match('/^[_[:lower:]]{1,11}$/', $order_by)); else $order_by='level_min';
29
30 $dir = (isset($_GET['dir'])) ? $sqlw->quote_smart($_GET['dir']) : 1;
31 if (preg_match('/^[01]{1}$/', $dir)); else $dir=1;
32
33 $order_dir = ($dir) ? 'ASC' : 'DESC';
34 $dir = ($dir) ? 0 : 1;
35
36 // for multipage support
37 $all_record = $sqlw->result($sqlw->query('SELECT count(*) FROM instance_template'), 0);
38
39 // main data that we need for this page, instances
40 if ($server_type)
41 $result = $sqlw->query('SELECT map, level_min, level_max, maxPlayers as maxplayers, reset_delay
42 FROM instance_template JOIN access_requirement ON access_requirement.id = instance_template.access_id
43 ORDER BY '.$order_by.' '.$order_dir.' LIMIT '.$start.', '.$itemperpage.';');
44 else
45 $result = $sqlw->query('SELECT map, levelMin as level_min, levelMax as level_max, maxPlayers as maxplayers, reset_delay
46 FROM instance_template ORDER BY '.$order_by.' '.$order_dir.' LIMIT '.$start.', '.$itemperpage.';');
47
48 //---------------Page Specific Data Starts Here--------------------------
49 // we start with a lead of 10 spaces,
50 // because last line of header is an opening tag with 8 spaces
51 // keep html indent in sync, so debuging from browser source would be easy to read
52 $output .= '
53 <!-- start of instances.php -->
54 <center>
55 <table class="top_hidden">
56 <tr>
57 <td width="25%" align="right">';
58
59 // multi page links
60 $output .=
61 $lang_instances['total'].' : '.$all_record.'<br /><br />'.
62 generate_pagination('instances.php?order_by='.$order_by.'&amp;dir='.(($dir) ? 0 : 1), $all_record, $itemperpage, $start);
63
64 // column headers, with links for sorting
65 $output .= '
66 </td>
67 </tr>
68 </table>
69 <table class="lined">
70 <tr>
71 <th width="40%"><a href="instances.php?order_by=map&amp;start='.$start.'&amp;dir='.$dir.'"'.($order_by==='map' ? ' class="'.$order_dir.'"' : '').'>'.$lang_instances['map'].'</a></th>
72 <th width="15%"><a href="instances.php?order_by=level_min&amp;start='.$start.'&amp;dir='.$dir.'"'.($order_by==='level_min' ? ' class="'.$order_dir.'"' : '').'>'.$lang_instances['level_min'].'</a></th>
73 <th width="15%"><a href="instances.php?order_by=level_max&amp;start='.$start.'&amp;dir='.$dir.'"'.($order_by==='level_max' ? ' class="'.$order_dir.'"' : '').'>'.$lang_instances['level_max'].'</a></th>
74 <th width="15%"><a href="instances.php?order_by=maxplayers&amp;start='.$start.'&amp;dir='.$dir.'"'.($order_by==='maxplayers' ? ' class="'.$order_dir.'"' : '').'>'.$lang_instances['max_players'].'</a></th>
75 <th width="15%"><a href="instances.php?order_by=reset_delay&amp;start='.$start.'&amp;dir='.$dir.'"'.($order_by==='reset_delay' ? ' class="'.$order_dir.'"' : '').'>'.$lang_instances['reset_delay'].'</a></th>
76 </tr>';
77
78 $sqlm = new SQL;
79 $sqlm->connect($mmfpm_db['addr'], $mmfpm_db['user'], $mmfpm_db['pass'], $mmfpm_db['name']);
80
81 while ($instances = $sqlw->fetch_assoc($result))
82 {
83 $days = floor(round($instances['reset_delay'] / 3600) / 24);
84 $hours = round($instances['reset_delay'] / 3600) - ($days * 24);
85 $reset = "";
86 if ($days)
87 $reset .= $days.' days';
88 if ($hours)
89 $reset .= $hours.' hours';
90
91 $output .= '
92 <tr valign="top">
93 <td>'.get_map_name($instances['map'], $sqlm).' ('.$instances['map'].')</td>
94 <td>'.$instances['level_min'].'</td>
95 <td>'.$instances['level_max'].'</td>
96 <td>'.$instances['maxplayers'].'</td>
97 <td>'.$reset.'</td>
98 </tr>';
99 }
100 unset($reset);
101 unset($hours);
102 unset($days);
103 unset($instances);
104 unset($result);
105
106 $output .= '
107 <tr>
108 <td colspan="5" class="hidden" align="right" width="25%">';
109 // multi page links
110 $output .= generate_pagination('instances.php?order_by='.$order_by.'&amp;dir='.(($dir) ? 0 : 1), $all_record, $itemperpage, $start);
111 unset($start);
112 $output .= '
113 </td>
114 </tr>
115 <tr>
116 <td colspan="5" class="hidden" align="right">'.$lang_instances['total'].' : '.$all_record.'</td>
117 </tr>
118 </table>
119 </center>
120 <!-- end of instances.php -->';
121
122}
123
124
125//#############################################################################
126// MAIN
127//#############################################################################
128
129// error variable reserved for future use
130//$err = (isset($_GET['error'])) ? $_GET['error'] : NULL;
131
132//unset($err);
133
134$lang_instances = lang_instances();
135
136$output .= '
137 <div class="top">
138 <h1>'.$lang_instances['instances'].'</h1>
139 </div>';
140
141// action variable reserved for future use
142//$action = (isset($_GET['action'])) ? $_GET['action'] : NULL;
143
144instances();
145
146//unset($action);
147unset($action_permission);
148unset($lang_instances);
149
150require_once 'footer.php';
151
152
153?>
Note: See TracBrowser for help on using the repository browser.