songinstance.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <?php
  2. $page = 4;
  3. require("inc_header.php");
  4. if(!isset($_GET['id']))
  5. {
  6. header("Location: songs.php");
  7. }
  8. $songinstance_id = $_GET['id'];
  9. // ======================================================
  10. // GET SONG DETAILS
  11. // ======================================================
  12. $query = "SELECT songinstance.`id`, `song`, `enemies`, `difficulty`, `title`, `author`,
  13. (SELECT COUNT(1) FROM `playdata` WHERE `songinstance`=$songinstance_id) as sis
  14. FROM `songinstance`, `song`
  15. WHERE songinstance.song=song.id AND songinstance.`id`=$songinstance_id";
  16. $result_temp = mysqli_query($connection, $query);
  17. $result = mysqli_fetch_assoc($result_temp);
  18. $song_title = $result['title'];
  19. $song_enemies = $result['enemies'];
  20. $song_difficulty = $result['difficulty'];
  21. $song_played = $result['sis'];
  22. $song_id = $result['song'];
  23. // ======================================================
  24. // DATA POINTS FOR MOST PLAYED GRAPH
  25. // DATA POINTS FOR AVERAGE PLAY TIME GRAPH
  26. // ======================================================
  27. $most_played_array = array();
  28. $average_play_time_array = array();
  29. $query = "SELECT DATE(`start_time`) AS date, COUNT(*) AS data, AVG(`play_time`) AS average
  30. FROM `playdata`, `songinstance`
  31. WHERE `playdata`.`songinstance` = `songinstance`.`id`
  32. AND `songinstance`.`id` = $songinstance_id
  33. GROUP BY DATE(`start_time`)
  34. ORDER BY `start_time` DESC
  35. LIMIT 0,7";
  36. $result_temp = mysqli_query($connection, $query);
  37. while($result = mysqli_fetch_assoc($result_temp))
  38. {
  39. $most_played_array[] = "{y: '" . $result['date'] . "', gp: " . $result['data'] . "}";
  40. $average_play_time_array[] = "{y: '" . $result['date'] . "', pt: " . format($result['average'])['tseconds'] . "}";
  41. }
  42. $most_played_array = array_reverse($most_played_array);
  43. $average_play_time_array = array_reverse($average_play_time_array);
  44. // ======================================================
  45. // DATA POINTS FOR SCORES GRAPH
  46. // ======================================================
  47. $scores_array = array();
  48. $scores_names_array = array();
  49. $query = "SELECT `date`, `score`, `username`
  50. FROM highscore, songinstance
  51. WHERE highscore.songinstance = songinstance.id
  52. AND songinstance.id = $songinstance_id
  53. ORDER BY `date` DESC
  54. LIMIT 0,28";
  55. $result_temp = mysqli_query($connection, $query);
  56. while($result = mysqli_fetch_assoc($result_temp))
  57. {
  58. $scores_array[] = "{y: '" . $result['date'] . "', sc: " . $result['score'] . "}";
  59. $scores_names_array[] = "'" . $result['username'] . "'";
  60. }
  61. $scores_array = array_reverse($scores_array);
  62. $scores_names_array = array_reverse($scores_names_array);
  63. // ======================================================
  64. // LATEST GAMES
  65. // ======================================================
  66. $table = "";
  67. $query = "SELECT `title`, `difficulty`, songinstance.id as siid, song.id as sid, (`enemies_hit` / (`enemies_missed` + `enemies_hit`)) * 100 as ratio, `buttons_pressed`, `joystick_moved`, `start_time`, `play_time`
  68. FROM `playdata`, `songinstance`, `song`
  69. WHERE playdata.songinstance = songinstance.id AND songinstance.song = song.id AND songinstance.id = $songinstance_id
  70. ORDER BY `start_time` DESC";
  71. $result_temp = mysqli_query($connection, $query);
  72. while($result = mysqli_fetch_assoc($result_temp))
  73. {
  74. $ratio = round($result['ratio']);
  75. $label = "danger";
  76. if($ratio >= 40)
  77. $label = "warning";
  78. if($ratio >= 80)
  79. $label = "success";
  80. $table .= "<tr>";
  81. $table .= "<td><a href='" . returnurl('song.php?id=' . $result['sid']) . "'>" . $result['title'] . "</a></td>";
  82. $table .= "<td><a href='" . returnurl('songinstance.php?id=' . $result['siid']) . "'>" . $result['difficulty'] . "</a></td>";
  83. $table .= "<td><span class='label label-" . $label . "'>" . $ratio . "<small>%</small></span></td>";
  84. $table .= "<td>" . $result['buttons_pressed'] . "</td>";
  85. $table .= "<td>" . $result['joystick_moved'] . "</td>";
  86. $table .= "<td>" . format($result['play_time'])['string'] . "</td>";
  87. $table .= "<td>" . $result['start_time'] . "</td>";
  88. $table .= "</tr>";
  89. }
  90. // ======================================================
  91. // LATEST GAMES
  92. // ======================================================
  93. $table2 = "";
  94. $query = "SELECT `title`, `difficulty`, songinstance.id as siid, song.id as sid, `username`, `score`, `date`
  95. FROM `highscore`, `songinstance`, `song`
  96. WHERE highscore.songinstance = songinstance.id AND songinstance.song = song.id
  97. AND songinstance.id = $songinstance_id
  98. ORDER BY `date` DESC";
  99. $result_temp = mysqli_query($connection, $query);
  100. while($result = mysqli_fetch_assoc($result_temp))
  101. {
  102. $table2 .= "<tr>";
  103. $table2 .= "<td><a href='" . returnurl('song.php?id=' . $result['sid']) . "'>" . $result['title'] . "</a></td>";
  104. $table2 .= "<td><a href='" . returnurl('songinstance.php?id=' . $result['siid']) . "'>" . $result['difficulty'] . "</a></td>";
  105. $table2 .= "<td>" . $result['username'] . "</td>";
  106. $table2 .= "<td>" . $result['score'] . "</td>";
  107. $table2 .= "<td>" . $result['date'] . "</td>";
  108. $table2 .= "</tr>";
  109. }
  110. ?>
  111. <!-- Content Wrapper. Contains page content -->
  112. <div class="content-wrapper">
  113. <!-- Content Header (Page header) -->
  114. <section class="content-header">
  115. <h1>
  116. Song
  117. <small><?php echo $song_title; ?></small>
  118. </h1>
  119. <ol class="breadcrumb">
  120. <li><a href="songs.php"><i class="ion ion-music-note"></i> Songs</a></li>
  121. <li><a href="song.php?id=<?php echo $song_id; ?>"></i> <?php echo $song_title; ?></a></li>
  122. <li class="active"><a href="#"></i> <?php echo $song_difficulty; ?></a></li>
  123. </ol>
  124. </section>
  125. <section class="content">
  126. <div class="row">
  127. <div class="col-lg-6 col-sm-12 col-xs-12">
  128. <!-- small box -->
  129. <div class="small-box bg-aqua">
  130. <div class="inner">
  131. <h3><?php echo $song_title; ?></h3>
  132. <p>Title</p>
  133. </div>
  134. </div>
  135. </div><!-- ./col -->
  136. <div class="col-lg-2 col-sm-4 col-xs-12">
  137. <!-- small box -->
  138. <div class="small-box bg-green">
  139. <div class="inner">
  140. <h3><?php echo $song_difficulty; ?></h3>
  141. <p>Difficulty</p>
  142. </div>
  143. </div>
  144. </div><!-- ./col -->
  145. <div class="clearfix visible-sm-block"></div>
  146. <div class="col-lg-2 col-sm-4 col-xs-12">
  147. <!-- small box -->
  148. <div class="small-box bg-yellow">
  149. <div class="inner">
  150. <h3><?php echo $song_enemies ?></h3>
  151. <p>Total Enemies</p>
  152. </div>
  153. </div>
  154. </div><!-- ./col -->
  155. <div class="col-lg-2 col-sm-4 col-xs-12">
  156. <!-- small box -->
  157. <div class="small-box bg-red">
  158. <div class="inner">
  159. <h3><?php echo $song_played; ?></h3>
  160. <p>Times Played</p>
  161. </div>
  162. </div>
  163. </div><!-- ./col -->
  164. </div><!-- /.row -->
  165. <div class="row">
  166. <div class="col-lg-4 col-xs-12">
  167. <!-- games played graph -->
  168. <div class="box box-solid bg-teal">
  169. <div class="box-header">
  170. <i class="fa fa-gamepad"></i>
  171. <h3 class="box-title">Games played</h3>
  172. </div>
  173. <div class="box-body border-radius-none">
  174. <div class="chart" id="games-played-chart" style="height: 250px;"></div>
  175. </div><!-- /.box-body -->
  176. </div><!-- /.box -->
  177. </div>
  178. <div class="col-lg-4 col-xs-12">
  179. <!-- TABLE: LATEST SONGS -->
  180. <!-- games played graph -->
  181. <div class="box box-solid bg-purple">
  182. <div class="box-header">
  183. <i class="ion ion-ribbon-b"></i>
  184. <h3 class="box-title">Scores</h3>
  185. </div>
  186. <div class="box-body border-radius-none">
  187. <div class="chart" id="scores-chart" style="height: 250px;"></div>
  188. </div><!-- /.box-body -->
  189. </div><!-- /.box -->
  190. </div><!-- /.col -->
  191. <div class="col-lg-4 col-xs-12">
  192. <div class="box box-solid bg-orange">
  193. <div class="box-header">
  194. <i class="ion ion-clock"></i>
  195. <h3 class="box-title">Average Play Time</h3>
  196. </div>
  197. <div class="box-body border-radius-none">
  198. <div class="chart" id="average-play-time-chart" style="height: 250px;"></div>
  199. </div><!-- /.box-body -->
  200. </div><!-- /.box -->
  201. </div>
  202. </div>
  203. <div class="row">
  204. <div class="col-lg-12">
  205. <!-- TABLE: LATEST SONGS -->
  206. <div class="box">
  207. <div class="box-header with-border">
  208. <i class="fa fa-gamepad"></i>
  209. <h3 class="box-title">Latest Games</h3>
  210. </div><!-- /.box-header -->
  211. <div class="box-body">
  212. <table id="games-played-table" class="table table-bordered">
  213. <thead>
  214. <tr>
  215. <th>Song Name</th>
  216. <th>Difficulty</th>
  217. <th>Hit Ratio</th>
  218. <th>Buttons Pressed</th>
  219. <th>Joystick Moved</th>
  220. <th>Length</th>
  221. <th>Time</th>
  222. </tr>
  223. </thead>
  224. <tbody>
  225. <?php
  226. echo $table;
  227. ?>
  228. </tbody>
  229. </table>
  230. </div><!-- /.box-body -->
  231. </div><!-- /.box -->
  232. </div><!-- /.col -->
  233. </div>
  234. <div class="row">
  235. <div class="col-lg-12">
  236. <!-- TABLE: LATEST SONGS -->
  237. <div class="box">
  238. <div class="box-header with-border">
  239. <i class="ion ion-ribbon-b"></i>
  240. <h3 class="box-title">Scores</h3>
  241. </div><!-- /.box-header -->
  242. <div class="box-body">
  243. <table id="scores-table" class="table table-bordered">
  244. <thead>
  245. <tr>
  246. <th>Song Name</th>
  247. <th>Difficulty</th>
  248. <th>Name</th>
  249. <th>Score</th>
  250. <th>Time</th>
  251. </tr>
  252. </thead>
  253. <tbody>
  254. <?php
  255. echo $table2;
  256. ?>
  257. </tbody>
  258. </table>
  259. </div><!-- /.box-body -->
  260. </div><!-- /.box -->
  261. </div><!-- /.col -->
  262. </div><!-- /.row -->
  263. </section><!-- /.content -->
  264. </div><!-- /.content-wrapper -->
  265. <!-- DATA TABES SCRIPT -->
  266. <script src="plugins/datatables/jquery.dataTables.min.js" type="text/javascript"></script>
  267. <script src="plugins/datatables/dataTables.bootstrap.min.js" type="text/javascript"></script>
  268. <!-- Morris.js charts -->
  269. <script src="http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
  270. <script src="plugins/morris/morris.min.js" type="text/javascript"></script>
  271. <!-- Page specific javascript -->
  272. <script type="text/javascript">
  273. var most_played_data = [ <?php
  274. foreach ($most_played_array as $value)
  275. {
  276. echo $value . ",\n";
  277. }
  278. ?> ];
  279. var average_play_time_data = [ <?php
  280. foreach ($average_play_time_array as $value)
  281. {
  282. echo $value . ",\n";
  283. }
  284. ?> ];
  285. var scores_data = [ <?php
  286. foreach ($scores_array as $value)
  287. {
  288. echo $value . ",\n";
  289. }
  290. ?> ];
  291. var scores_names_data = [ <?php
  292. foreach ($scores_names_array as $value)
  293. {
  294. echo $value . ",\n";
  295. }
  296. ?> ];
  297. </script>
  298. <script src="dist/js/pages/songinstance.js" type="text/javascript"></script>
  299. <?php
  300. require("inc_footer.php");
  301. ?>