PageRenderTime 48ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/stat.php

http://github.com/Mythos94/Minimanager-for-TrinityCore
PHP | 468 lines | 380 code | 55 blank | 33 comment | 13 complexity | 3e7f6d1a6529aacf073d3160fffd06aa MD5 | raw file
  1. <?php
  2. /*
  3. * Copyright (C) 2010-2011 TrinityScripts <http://www.trinityscripts.xe.cx/>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. require_once 'header.php';
  20. valid_login($action_permission['read']);
  21. function stats($action, &$sqlr, &$sqlc)
  22. {
  23. global $output, $lang_global, $lang_stat, $lang_id_tab, $lang_index,
  24. $realm_id, $realm_db, $theme;
  25. $race = Array
  26. (
  27. 1 => array(1, $lang_id_tab['human'],'',''),
  28. 2 => array(2, $lang_id_tab['orc'],'',''),
  29. 3 => array(3, $lang_id_tab['dwarf'],'',''),
  30. 4 => array(4, $lang_id_tab['nightelf'],'',''),
  31. 5 => array(5, $lang_id_tab['undead'],'',''),
  32. 6 => array(6, $lang_id_tab['tauren'],'',''),
  33. 7 => array(7, $lang_id_tab['gnome'],'',''),
  34. 8 => array(8, $lang_id_tab['troll'],'',''),
  35. 10 => array(10,$lang_id_tab['bloodelf'],'',''),
  36. 11 => array(11,$lang_id_tab['draenei'],'','')
  37. );
  38. $class = Array
  39. (
  40. 1 => array(1, $lang_id_tab['warrior'],'',''),
  41. 2 => array(2, $lang_id_tab['paladin'],'',''),
  42. 3 => array(3, $lang_id_tab['hunter'],'',''),
  43. 4 => array(4, $lang_id_tab['rogue'],'',''),
  44. 5 => array(5, $lang_id_tab['priest'],'',''),
  45. 6 => array(6, $lang_id_tab['death_knight'],'',''),
  46. 7 => array(7, $lang_id_tab['shaman'],'',''),
  47. 8 => array(8, $lang_id_tab['mage'],'',''),
  48. 9 => array(9, $lang_id_tab['warlock'],'',''),
  49. 11 => array(11,$lang_id_tab['druid'],'','')
  50. );
  51. $level = Array
  52. (
  53. 1 => array(1,1,9,'',''),
  54. 2 => array(2,10,19,'',''),
  55. 3 => array(3,20,29,'',''),
  56. 4 => array(4,30,39,'',''),
  57. 5 => array(5,40,49,'',''),
  58. 6 => array(6,50,59,'',''),
  59. 7 => array(7,60,69,'',''),
  60. 8 => array(8,70,79,'',''),
  61. 9 => array(9,80,80,'','')
  62. );
  63. $total_chars = $sqlc->result($sqlc->query('SELECT count(*) FROM characters'.( ($action) ? ' WHERE online= 1' : '' ).''), 0);
  64. if ($total_chars)
  65. {
  66. $output .= '
  67. <center>
  68. <div id="tab">
  69. <ul>
  70. <li'.(($action) ? '' : ' id="selected"').'>
  71. <a href="stat.php">
  72. '.$lang_stat['srv_statistics'].'
  73. </a>
  74. </li>
  75. <li'.(($action) ? ' id="selected"' : '').'>
  76. <a href="stat.php?action=true">
  77. '.$lang_stat['on_statistics'].'
  78. </a>
  79. </li>
  80. </ul>
  81. </div>
  82. <div id="tab_content">
  83. <div class="top"><h1>'.(($action) ? $lang_stat['on_statistics'] : $lang_stat['srv_statistics']).'</h1></div>
  84. <center>
  85. <table class="hidden">
  86. <tr>
  87. <td align="left">
  88. <h1>'.$lang_stat['general_info'].'</h1>
  89. </td>
  90. </tr>
  91. <tr align="left">
  92. <td class="large">';
  93. //if($action)
  94. if (1>2) //disable for testing purposes
  95. $output .= '
  96. <font class="bold">'.$lang_index['tot_users_online'].' : '.$total_chars.'</font><br /><br />';
  97. else
  98. {
  99. $query = $sqlr->query('SELECT count(*) FROM account UNION SELECT count(*) FROM account_access WHERE gmlevel > 0');
  100. $total_acc = $sqlr->result($query, 0);
  101. $total_gms = $sqlr->result($query, 1);
  102. unset($query);
  103. $data = date('Y-m-d H:i:s');
  104. $data_1day = mktime(date('H'), date('i'), date('s'), date('m'), date('d')-1, date('Y'));
  105. $data_1day = date('Y-m-d H:i:s', $data_1day);
  106. $uniqueIPs = $sqlr->result($sqlr->query('select distinct count(last_ip) from account where last_login > \''.$data_1day.'\' and last_login < \''.$data.'\''), 0);
  107. $data_2day = mktime(date('H'), date('i'), date('s'), date('m'), date('d')-2, date('Y'));
  108. $data_2day = date('Y-m-d H:i:s', $data_2day);
  109. $uniqueIPs2 = $sqlr->result($sqlr->query('select distinct count(last_ip) from account where last_login > \''.$data_2day.'\' and last_login < \''.$data.'\''), 0);
  110. $data_1week = mktime(date('H'), date('i'), date('s'), date('m'), date('d')-7, date('Y'));
  111. $data_1week = date('Y-m-d H:i:s', $data_1week);
  112. $uniqueIPsWeek = $sqlr->result($sqlr->query('select distinct count(last_ip) from account where last_login > \''.$data_1week.'\' and last_login < \''.$data.'\''), 0);
  113. $max_ever = $sqlr->result($sqlr->query('SELECT maxplayers FROM uptime WHERE realmid = '.$realm_id.' ORDER BY maxplayers DESC LIMIT 1'), 0);
  114. $max_restart = $sqlr->result($sqlr->query('SELECT maxplayers FROM uptime WHERE realmid = '.$realm_id.' ORDER BY starttime DESC LIMIT 1'), 0);
  115. $uptime = $sqlr->fetch_row($sqlr->query('SELECT AVG(uptime)/60, MAX(uptime)/60, ( 100*SUM(uptime)/( UNIX_TIMESTAMP()-MIN(starttime) ) ) FROM uptime WHERE realmid = '.$realm_id.''));
  116. $output .= '
  117. <table>
  118. <tr valign="top" align="center">
  119. <td align="left" width="210">
  120. '.$lang_stat['uptime_prec'].':<br />
  121. '.$lang_stat['avg_uptime'].':<br />
  122. '.$lang_stat['max_uptime'].':<br />
  123. <br />
  124. '.$lang_stat['tot_accounts'].':<br />
  125. '.$lang_stat['tot_chars_on_realm'].':<br />
  126. </td>
  127. <td align="left">
  128. '.round($uptime[2],1).'%<br />
  129. '.(int)($uptime[0]/60).':'.(int)(($uptime[0]%60)).'h<br />
  130. '.(int)($uptime[1]/60).':'.(int)(($uptime[1]%60)).'h<br />
  131. <br />
  132. '.$total_acc.'<br />
  133. '.$total_chars.'<br />
  134. </td>
  135. <td></td>
  136. <td align="left">
  137. '.$lang_stat['unique_ip'].':<br />
  138. '.$lang_stat['unique_ip2'].':<br />
  139. '.$lang_stat['unique_ipWeek'].':<br />
  140. <br />
  141. '.$lang_stat['max_players'].' :<br />
  142. '.$lang_stat['max_ever'].' :<br />
  143. '.$lang_stat['max_restart'].' :<br />
  144. </td>
  145. <td align="right">
  146. '.$uniqueIPs.'<br />
  147. '.$uniqueIPs2.'<br />
  148. '.$uniqueIPsWeek.'<br />
  149. <br />
  150. <br />
  151. '.$max_ever.'<br />
  152. '.$max_restart.'<br />
  153. </td>
  154. </tr>
  155. <tr align="left">
  156. <td colspan="2">
  157. '.$lang_stat['average_of'].' '.round($total_chars/$total_acc,1).' '.$lang_stat['chars_per_acc'].'<br />
  158. '.$lang_stat['total_of'].' '.$total_gms.' '.$lang_stat['gms_one_for'].' '.round($total_acc/$total_gms,1).' '.$lang_stat['players'].'
  159. </td>
  160. <td colspan="2">
  161. </td>
  162. </tr>
  163. </table>
  164. <br />';
  165. unset($uptime);
  166. unset($uniqueIPs);
  167. unset($max_restart);
  168. unset($max_ever);
  169. unset($total_gms);
  170. unset($total_acc);
  171. }
  172. // Total players in 24 Hours
  173. $horde1day = $sqlc->result($sqlc->query('SELECT count(guid) FROM characters WHERE race IN(2,5,6,8,10) AND account IN (SELECT account.id FROM '.$realm_db['name'].'.account WHERE last_login > \''.$data_1day.'\')'));
  174. $allys1day = $sqlc->result($sqlc->query('SELECT count(guid) FROM characters WHERE race IN(1,3,4,7,11) AND account IN (SELECT account.id FROM '.$realm_db['name'].'.account WHERE last_login > \''.$data_1day.'\')'));
  175. $day1total = $horde1day + $allys1day;
  176. if ($day1total == 0)
  177. $day1total = 1;
  178. $horde1daytotal = round(($horde1day)*100/$day1total ,1);
  179. $allys1daytotal = round(($allys1day)*100/$day1total ,1);
  180. // Total players in 48 Hours
  181. $horde2day = $sqlc->result($sqlc->query('SELECT count(guid) FROM characters WHERE race IN(2,5,6,8,10) AND account IN (SELECT account.id FROM '.$realm_db['name'].'.account WHERE last_login > \''.$data_2day.'\')'));
  182. $allys2day = $sqlc->result($sqlc->query('SELECT count(guid) FROM characters WHERE race IN(1,3,4,7,11) AND account IN (SELECT account.id FROM '.$realm_db['name'].'.account WHERE last_login > \''.$data_2day.'\')'));
  183. $day2total = $horde2day + $allys2day;
  184. if ($day2total == 0)
  185. $day2total = 1;
  186. $horde2daytotal = round(($horde1day)*100/$day2total ,1);
  187. $allys2daytotal = round(($allys1day)*100/$day2total ,1);
  188. // Total players in 1 Week
  189. $horde1week = $sqlc->result($sqlc->query('SELECT count(guid) FROM characters WHERE race IN(2,5,6,8,10) AND account IN (SELECT account.id FROM '.$realm_db['name'].'.account WHERE last_login > \''.$data_1week.'\')'));
  190. $allys1week = $sqlc->result($sqlc->query('SELECT count(guid) FROM characters WHERE race IN(1,3,4,7,11) AND account IN (SELECT account.id FROM '.$realm_db['name'].'.account WHERE last_login > \''.$data_1week.'\')'));
  191. $week1total = $horde1week + $allys1week;
  192. if ($week1total == 0)
  193. $week1total = 1;
  194. $horde1weektotal = round(($horde1week)*100/$week1total ,1);
  195. $allys1weektotal = round(($allys1week)*100/$week1total ,1);
  196. // Total players
  197. $horde_chars = $sqlc->result($sqlc->query('SELECT count(guid) FROM characters WHERE race IN(2,5,6,8,10)'.(($action) ? ' AND online= 1' : '')), 0);
  198. $horde_pros = round(($horde_chars*100)/$total_chars ,1);
  199. $allies_chars = $total_chars - $horde_chars;
  200. $allies_pros = 100 - $horde_pros;
  201. $output .= '
  202. <p align="center"><b>'.$lang_stat['acc_24'].'</b></p>
  203. <table class="tot_bar">
  204. <tr>
  205. <td width="'.$horde1daytotal.'%" background="img/bar_horde.gif" height="30"><a href="stat.php?action='.$action.'&amp;side=h">'.$lang_stat['horde'].': '.$horde1day.' ('.$horde1daytotal.'%)</a></td>
  206. <td width="'.$allys1daytotal.'%" background="img/bar_allie.gif" height="30"><a href="stat.php?action='.$action.'&amp;side=a">'.$lang_stat['alliance'].': '.$allys1day.' ('.$allys1daytotal.'%)</a></td>
  207. </tr>
  208. </table>
  209. <p align="center"><b>'.$lang_stat['acc_48'].'</b></p>
  210. <table class="tot_bar">
  211. <tr>
  212. <td width="'.$horde2daytotal.'%" background="img/bar_horde.gif" height="30"><a href="stat.php?action='.$action.'&amp;side=h">'.$lang_stat['horde'].': '.$horde2day.' ('.$horde2daytotal.'%)</a></td>
  213. <td width="'.$allys2daytotal.'%" background="img/bar_allie.gif" height="30"><a href="stat.php?action='.$action.'&amp;side=a">'.$lang_stat['alliance'].': '.$allys2day.' ('.$allys2daytotal.'%)</a></td>
  214. </tr>
  215. </table>
  216. <p align="center"><b>'.$lang_stat['acc_7'].'</b></p>
  217. <table class="tot_bar">
  218. <tr>
  219. <td width="'.$horde1weektotal.'%" background="img/bar_horde.gif" height="30"><a href="stat.php?action='.$action.'&amp;side=h">'.$lang_stat['horde'].': '.$horde1week.' ('.$horde1weektotal.'%)</a></td>
  220. <td width="'.$allys1weektotal.'%" background="img/bar_allie.gif" height="30"><a href="stat.php?action='.$action.'&amp;side=a">'.$lang_stat['alliance'].': '.$allys1week.' ('.$allys1weektotal.'%)</a></td>
  221. </tr>
  222. </table>
  223. <p align="center"><b>'.$lang_stat['acc_total'].'</b></p>
  224. <table class="tot_bar">
  225. <tr>
  226. <td width="'.$horde_pros.'%" background="img/bar_horde.gif" height="30"><a href="stat.php?action='.$action.'&amp;side=h">'.$lang_stat['horde'].': '.$horde_chars.' ('.$horde_pros.'%)</a></td>
  227. <td width="'.$allies_pros.'%" background="img/bar_allie.gif" height="30"><a href="stat.php?action='.$action.'&amp;side=a">'.$lang_stat['alliance'].': '.$allies_chars.' ('.$allies_pros.'%)</a></td>
  228. </tr>
  229. </table>';
  230. unset($horde_chars);
  231. unset($horde_pros);
  232. unset($allies_chars);
  233. unset($allies_pros);
  234. unset($data_1);
  235. unset($data_2day);
  236. unset($data_1week);
  237. unset($data);
  238. $order_race = (isset($_GET['race'])) ? 'AND race ='.$sqlc->quote_smart($_GET['race']) : '';
  239. $order_class = (isset($_GET['class'])) ? 'AND class ='.$sqlc->quote_smart($_GET['class']) : '';
  240. if(isset($_GET['level']))
  241. {
  242. $lvl_min = $sqlc->quote_smart($_GET['level']);
  243. $lvl_max = $lvl_min + 4;
  244. $order_level = 'AND level >= '.$lvl_min.' AND level <= '.$lvl_max.'';
  245. }
  246. else
  247. $order_level = '';
  248. if(isset($_GET['side']))
  249. {
  250. if ('h' == $sqlc->quote_smart($_GET['side']))
  251. $order_side = 'AND race IN(2,5,6,8,10)';
  252. elseif ('a' == $sqlc->quote_smart($_GET['side']))
  253. $order_side = 'AND race IN (1,3,4,7,11)';
  254. }
  255. else
  256. $order_side = '';
  257. // RACE
  258. foreach ($race as $id)
  259. {
  260. $race[$id[0]][2] = $sqlc->result($sqlc->query('SELECT count(guid) FROM characters WHERE race = '.$id[0].' '.$order_class.' '.$order_level.' '.$order_side.(($action) ? ' AND online= 1' : '')), 0);
  261. $race[$id[0]][3] = round((($race[$id[0]][2])*100)/$total_chars,1);
  262. }
  263. $output .= '
  264. <tr align="left">
  265. <td>
  266. <h1>'.$lang_stat['chars_by_race'].'</h1>
  267. </td>
  268. </tr>
  269. <tr>
  270. <td>
  271. <table class="bargraph">
  272. <tr>';
  273. foreach ($race as $id)
  274. {
  275. $height = ($race[$id[0]][3])*4;
  276. $output .= '
  277. <td>
  278. <a href="stat.php?action='.$action.'&amp;race='.$id[0].'" class="graph_link">'.$race[$id[0]][3].'%<img src="themes/'.$theme.'/column.gif" width="69" height="'.$height.'" alt="'.$race[$id[0]][2].'" /></a>
  279. </td>';
  280. }
  281. $output .= '
  282. </tr>
  283. <tr>';
  284. foreach ($race as $id)
  285. $output .= '
  286. <th>'.$race[$id[0]][1].'<br />'.$race[$id[0]][2].'</th>';
  287. unset($race);
  288. $output .= '
  289. </tr>
  290. </table>
  291. <br />
  292. </td>
  293. </tr>';
  294. // RACE END
  295. // CLASS
  296. foreach ($class as $id)
  297. {
  298. $class[$id[0]][2] = $sqlc->result($sqlc->query('SELECT count(guid) FROM characters WHERE class = '.$id[0].' '.$order_race.' '.$order_level.' '.$order_side.(($action) ? ' AND online= 1' : '')), 0);
  299. $class[$id[0]][3] = round((($class[$id[0]][2])*100)/$total_chars,1);
  300. }
  301. unset($order_level);
  302. $output .= '
  303. <tr align="left">
  304. <td>
  305. <h1>'.$lang_stat['chars_by_class'].'</h1>
  306. </td>
  307. </tr>
  308. <tr>
  309. <td>
  310. <table class="bargraph">
  311. <tr>';
  312. foreach ($class as $id)
  313. {
  314. $height = ($class[$id[0]][3])*4;
  315. $output .= '
  316. <td>
  317. <a href="stat.php?action='.$action.'&amp;class='.$id[0].'" class="graph_link">'.$class[$id[0]][3].'%<img src="themes/'.$theme.'/column.gif" width="69" height="'.$height.'" alt="'.$class[$id[0]][2].'" /></a>
  318. </td>';
  319. }
  320. $output .= '
  321. </tr>
  322. <tr>';
  323. foreach ($class as $id)
  324. {
  325. $output .= '
  326. <th>'.$class[$id[0]][1].'<br />'.$class[$id[0]][2].'</th>';
  327. }
  328. unset($class);
  329. $output .= '
  330. </tr>
  331. </table>
  332. <br />
  333. </td>
  334. </tr>';
  335. // CLASS END
  336. // LEVEL
  337. foreach ($level as $id)
  338. {
  339. $level[$id[0]][3] = $sqlc->result($sqlc->query('SELECT count(guid) FROM characters WHERE level >= '.$id[1].' AND level <= '.$id[2].'
  340. '.$order_race.' '.$order_class.' '.$order_side.(($action) ? ' AND online= 1' : '').''), 0);
  341. $level[$id[0]][4] = round((($level[$id[0]][3])*100)/$total_chars,1);
  342. }
  343. unset($order_level);
  344. unset($order_class);
  345. unset($order_race);
  346. unset($total_chars);
  347. unset($order_side);
  348. $output .= '
  349. <tr align="left">
  350. <td>
  351. <h1>'.$lang_stat['chars_by_level'].'</h1>
  352. </td>
  353. </tr>
  354. <tr>
  355. <td>
  356. <table class="bargraph">
  357. <tr>';
  358. foreach ($level as $id)
  359. {
  360. $height = ($level[$id[0]][4])*3;
  361. $output .= '
  362. <td><a href="stat.php?action='.$action.'&amp;level='.$id[1].'" class="graph_link">'.$level[$id[0]][4].'%<img src="themes/'.$theme.'/column.gif" width="77" height="'.$height.'" alt="'.$level[$id[0]][3].'" /></a></td>';
  363. }
  364. unset($height);
  365. $output .= '
  366. </tr>
  367. <tr>';
  368. foreach ($level as $id)
  369. $output .= '
  370. <th>'.$level[$id[0]][1].'-'.$level[$id[0]][2].'<br />'.$level[$id[0]][3].'</th>';
  371. unset($id);
  372. unset($level);
  373. $output .= '
  374. </tr>
  375. </table>
  376. <br />
  377. <hr/>
  378. </td>
  379. </tr>
  380. <tr>
  381. <td>';
  382. // LEVEL END
  383. makebutton($lang_stat['reset'], 'stat.php', 720);
  384. $output .= '
  385. </td>
  386. </tr>
  387. </table>
  388. </center>
  389. </div>
  390. <br />
  391. </center>';
  392. }
  393. else
  394. error($lang_global['err_no_result']);
  395. }
  396. //#############################################################################
  397. // MAIN
  398. //#############################################################################
  399. //$err = (isset($_GET['error'])) ? $_GET['error'] : NULL;
  400. //unset($err);
  401. $lang_index = lang_index();
  402. $lang_stat = lang_stat();
  403. $action = (isset($_GET['action'])) ? $_GET['action'] : NULL;
  404. stats($action, $sqlr, $sqlc);
  405. unset($action);
  406. unset($action_permission);
  407. unset($lang_index);
  408. unset($lang_stat);
  409. require_once 'footer.php';
  410. ?>