Unsupported PHP app for analysing and displaying stats for Team Fortress 2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

player.php 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?PHP
  2. require_once('inc/config.php');
  3. require_once('inc/common.php');
  4. require_once('inc/ext.php');
  5. require_once('inc/classestable.php');
  6. require_once('inc/eventhistory.php');
  7. require_once('inc/mostmaps.php');
  8. require_once('inc/playertable.php');
  9. require_once('inc/weaponslist.php');
  10. require_once(STATS_DIR . '/inc/database.php');
  11. $sql = 'SELECT player_steamid, player_rank, player_score, session_alias FROM players NATURAL JOIN sessions WHERE player_id = \'' . s($_GET['id']) . '\' ORDER BY session_endtime DESC LIMIT 0,1';
  12. $res = mysql_query($sql);
  13. if (mysql_num_rows($res) == 0) {
  14. require('404.php');
  15. exit;
  16. }
  17. $row = mysql_fetch_assoc($res);
  18. define('PLAYER', (int) $_GET['id']);
  19. define('RANK', (int) $row['player_rank']);
  20. define('STEAMID', $row['player_steamid']);
  21. define('NAME', $row['session_alias']);
  22. define('SCORE', (int) $row['player_score']);
  23. if (isset($_GET['class'])) {
  24. $sql = 'SELECT class_id, class_displayname FROM classes WHERE class_name = \'' . s($_GET['class']) . '\'';
  25. $res = mysql_query($sql);
  26. if (mysql_num_rows($res) == 0) {
  27. require('404.php');
  28. exit;
  29. }
  30. $row = mysql_fetch_assoc($res);
  31. define('CLASSID', $row['class_id']);
  32. define('CLASSNAME', $row['class_displayname']);
  33. }
  34. define('TITLE', 'Player information :: ' . htmlentities(NAME, ENT_COMPAT, 'UTF-8')
  35. . (defined('CLASSID') ? ' :: ' . CLASSNAME : ''));
  36. require_once('inc/header.php');
  37. echo '<h2>Player Information: ', htmlentities(NAME, ENT_COMPAT, 'UTF-8'),
  38. defined('CLASSID') ? ' &raquo; <img src="' . sprintf(URL_CLASS, 'blue', $_GET['class']) . '">' . CLASSNAME : '', '</h2>';
  39. if (!isset($_GET['eventhistory'])) {
  40. echo '<div class="left">';
  41. echo '<h3>Player links</h3>';
  42. if (defined('CLASSID')) {
  43. echo '<a class="blocklink" href="?id=', htmlentities(PLAYER), '">Player overview</a>';
  44. }
  45. echo '<a class="blocklink" href="?id=', htmlentities(PLAYER), '&amp;eventhistory">Event History</a>';
  46. if (ENABLE_COMMUNITY_LINKS) {
  47. require_once('inc/community.php');
  48. echo '<a class="blocklink" href="http://steamcommunity.com/profiles/', getCommunityID(STEAMID), '">Steam Community Profile</a>';
  49. }
  50. if (ENABLE_GROUPS) {
  51. $sql = 'SELECT group_id, group_name FROM groupmemberships NATURAL JOIN groups WHERE player_id = ' . PLAYER;
  52. $res = mysql_query($sql);
  53. if (mysql_num_rows($res) > 0) {
  54. $header = false;
  55. while ($row = mysql_fetch_assoc($res)) {
  56. $sql2 = 'SELECT COUNT(*) FROM groupmemberships WHERE group_id = ' . $row['group_id'];
  57. $res2 = mysql_query($sql2);
  58. $row2 = mysql_fetch_array($res2);
  59. $total = $row2[0];
  60. if ($total == 1) { continue; }
  61. if (!$header) {
  62. echo '<h3>Group affiliations</h3>';
  63. echo '<ul>';
  64. $header = true;
  65. }
  66. $sql2 = 'SELECT COUNT(*) FROM groupmemberships NATURAL JOIN players WHERE group_id = ' . $row['group_id'] . ' AND player_score > ' . SCORE;
  67. $res2 = mysql_query($sql2);
  68. $row2 = mysql_fetch_array($res2);
  69. $place = $row2[0];
  70. echo '<li><a href="', 'group.php?group=', $row['group_id'], '">', htmlentities($row['group_name'], ENT_QUOTES, 'UTF-8'), '</a> &mdash; ';
  71. echo 'ranked ', number_format($place), '<sup>', getSuffix($place), '</sup> out of ', number_format($total), '</li>';
  72. }
  73. if ($header) {
  74. echo '</ul>';
  75. }
  76. }
  77. }
  78. echo '<h3>Favourite maps</h3>';
  79. showMostMaps(defined('CLASSID') ? 'INNER JOIN roleperiods ON (roleperiods.session_id = sessions.session_id)' : '', 'sessions.player_id = ' . PLAYER . (defined('CLASSID') ? ' AND roleperiods.class_id = ' . CLASSID : ''));
  80. $extra = true;
  81. echo '<h3 class="extra">Top Weapons</h3>';
  82. showWeaponsList('INNER JOIN roleperiods ON roleperiod_id = kill_killer WHERE player_id = ' . PLAYER . (defined('CLASSID') ? ' AND class_id = ' . CLASSID : ''));
  83. echo '</div><div class="right">';
  84. echo '<h3>Ranking</h3>';
  85. $min = max(0, RANK - 3); $max = 5 + min(RANK - 3, 0);
  86. showPlayerTable('', '1=1', $min . ',' . $max, false, false, PLAYER);
  87. echo '<h3>Class Stats</h3>';
  88. $classes = array();
  89. $sql = 'SELECT rp1.class_id, class_name, COUNT(*) as num FROM classes NATURAL JOIN roleperiods AS rp1 INNER JOIN kills AS k1 ON kill_victim = roleperiod_id INNER JOIN roleperiods AS rp2 ON kill_killer = rp2.roleperiod_id WHERE rp2.player_id = ' . PLAYER . (defined('CLASSID') ? ' AND rp2.class_id = ' . CLASSID : '') . ' GROUP BY class_id';
  90. $res = mysql_query($sql) or print(mysql_error());
  91. while ($row = mysql_fetch_assoc($res)) {
  92. $classes[$row['class_id']]['name'] = $row['class_name'];
  93. $classes[$row['class_id']]['data1'] = $row['num'];
  94. }
  95. $sql = 'SELECT rp1.class_id, class_name, COUNT(*) as num FROM classes NATURAL JOIN roleperiods AS rp1 INNER JOIN kills AS k1 ON kill_killer = rp1.roleperiod_id INNER JOIN roleperiods AS rp2 ON kill_victim = rp2.roleperiod_id WHERE rp2.player_id = ' . PLAYER . (defined('CLASSID') ? ' AND rp2.class_id = ' . CLASSID : '') . ' GROUP BY class_id';
  96. $res = mysql_query($sql) or print(mysql_error());
  97. while ($row = mysql_fetch_assoc($res)) {
  98. $classes[$row['class_id']]['data2'] = $row['num'];
  99. $classes[$row['class_id']]['name'] = $row['class_name'];
  100. }
  101. if (!defined('CLASSID')) {
  102. $sql = 'SELECT rp1.class_id, class_name, COUNT(*) AS num FROM classes NATURAL JOIN roleperiods AS rp1 INNER JOIN kills AS k1 ON kill_killer = rp1.roleperiod_id WHERE rp1.player_id = ' . PLAYER . ' GROUP BY class_id';
  103. $res = mysql_query($sql) or print(mysql_error());
  104. while ($row = mysql_fetch_assoc($res)) {
  105. $classes[$row['class_id']]['data3'] = $row['num'];
  106. $classes[$row['class_id']]['name'] = $row['class_name'];
  107. }
  108. $sql = 'SELECT rp1.class_id, class_name, COUNT(*) AS num FROM classes NATURAL JOIN roleperiods AS rp1 INNER JOIN kills AS k1 ON kill_victim = rp1.roleperiod_id WHERE rp1.player_id = ' . PLAYER . ' GROUP BY class_id';
  109. $res = mysql_query($sql) or print(mysql_error());
  110. while ($row = mysql_fetch_assoc($res)) {
  111. $classes[$row['class_id']]['data4'] = $row['num'];
  112. $classes[$row['class_id']]['name'] = $row['class_name'];
  113. }
  114. showClassesTable($classes, 'Victim of ' . htmlentities(NAME, ENT_COMPAT, 'UTF-8'),
  115. 'Killer of ' . htmlentities(NAME, ENT_COMPAT, 'UTF-8'), true,
  116. htmlentities(NAME, ENT_COMPAT, 'UTF-8') . '\'s kills',
  117. htmlentities(NAME, ENT_COMPAT, 'UTF-8') . '\'s deaths', true);
  118. } else {
  119. showClassesTable($classes, 'Victim of ' . htmlentities(NAME, ENT_COMPAT, 'UTF-8'),
  120. 'Killer of ' . htmlentities(NAME, ENT_COMPAT, 'UTF-8'), true);
  121. }
  122. echo '</div>';
  123. } else {
  124. echo '<h3>Event History</h3>';
  125. showEventHistory(PLAYER);
  126. }
  127. require_once('inc/footer.php');
  128. ?>