Advertisement
polectron

Untitled

Jan 11th, 2019
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.99 KB | None | 0 0
  1. <?php header('Content-Type: text/html; charset=utf-8');?>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. </head>
  6. <body>
  7. <?php
  8.  
  9. $MYSQLSERVER = "localhost";
  10. $USER = "root";
  11. $PASSWORD = "";
  12. $DATABASE = "registro";
  13.  
  14. $location = file_get_contents('http://api.geoiplookup.net/?query='."89.131.18.162");
  15. $location = new SimpleXMLElement($location);
  16. $location = utf8_decode($location->results->result->countryname.", ".$location->results->result->city);
  17.  
  18. $mysqli = new mysqli($MYSQLSERVER, $USER, $PASSWORD, $DATABASE);
  19.  
  20. $mysqli->set_charset("utf8");
  21.  
  22. date_default_timezone_set ("Europe/Madrid");
  23.  
  24. if ($mysqli->connect_errno) {
  25. echo "ERROR DB";
  26. die('Error de conexión: ' . $mysqli->connect_error);
  27. exit;
  28. }
  29.  
  30. if(isset($_REQUEST["player_name"])){
  31.  
  32. $stmt = $mysqli->prepare("INSERT INTO registro (player_name, player_id, type, info, location, equipo) VALUES (?,?,?,?,?,?)");
  33. $stmt->bind_param('ssssss',trim(urldecode($_REQUEST["player_name"])),$_REQUEST["player_id"],$_REQUEST["type"],$_REQUEST["info"],$location,$_REQUEST["equipo"]);
  34.  
  35. print_r($_REQUEST);
  36.  
  37. if (!$stmt->execute()) {
  38. echo "ERROR SQL";
  39. exit;
  40. }
  41.  
  42. $stmt->close();
  43. }else{
  44.  
  45. $p = 0;
  46. $items_per_page = 100;
  47.  
  48. if(isset($_REQUEST["p"])){
  49. $p = $_REQUEST["p"];
  50. }
  51.  
  52. $offset = $p*$items_per_page;
  53.  
  54. if(isset($_REQUEST["filter_type"])){
  55. $stmt = $mysqli->prepare("SELECT id, player_id, player_name, type, date, info, location, equipo FROM registro WHERE type = ? LIMIT ?,?");
  56. $stmt->bind_param('sdd', $_REQUEST["filter_type"], $offset, $items_per_page);
  57.  
  58. $stmt_total = $mysqli->prepare("SELECT count(player_id) as total FROM registro WHERE type = ?");
  59. $stmt_total->bind_param('s', $_REQUEST["filter_type"]);
  60. $stmt_total->execute();
  61. $result_total = $stmt_total->get_result();
  62. $row_total = $result_total->fetch_assoc();
  63.  
  64. $total_items = $row_total["total"];
  65. }else if(isset($_REQUEST["filter_id"])){
  66. $stmt = $mysqli->prepare("SELECT id, player_id, player_name, type, date, info, location, equipo FROM registro WHERE player_id = ? LIMIT ?,?");
  67. $stmt->bind_param('sdd', $_REQUEST["filter_id"], $offset, $items_per_page);
  68.  
  69. $stmt_total = $mysqli->prepare("SELECT count(player_id) as total FROM registro WHERE player_id = ?");
  70. $stmt_total->bind_param('s', $_REQUEST["filter_id"]);
  71. $stmt_total->execute();
  72. $result_total = $stmt_total->get_result();
  73. $row_total = $result_total->fetch_assoc();
  74.  
  75. $total_items = $row_total["total"];
  76. }else{
  77. $stmt = $mysqli->prepare("SELECT id, player_id, player_name, type, date, info, location, equipo FROM registro ORDER BY date DESC LIMIT ?,?");
  78. $stmt->bind_param('dd', $offset, $items_per_page);
  79.  
  80. $stmt_total = $mysqli->prepare("SELECT count(player_id) as total FROM registro");
  81. $stmt_total->execute();
  82. $result_total = $stmt_total->get_result();
  83. $row_total = $result_total->fetch_assoc();
  84.  
  85. $total_items = $row_total["total"];
  86. }
  87.  
  88. if (!$stmt->execute()) {
  89. echo "ERROR SQL";
  90. exit;
  91. }
  92.  
  93. $last_page = floor($total_items/$items_per_page);
  94.  
  95. $result = $stmt->get_result();
  96.  
  97. ?>
  98.  
  99. <a href="/registro.php"><h2>Inicio</h2></a>
  100.  
  101. Total de entradas <?php echo $total_items; ?>
  102.  
  103. <table border=1>
  104. <thead>
  105. <tr>
  106. <th>Player ID</th>
  107. <th>Player Name</th>
  108. <th>Tipo</th>
  109. <th>Fecha</th>
  110. <th>Info</th>
  111. <th>Ubicación</th>
  112. <th>Equipo</th>
  113. </tr>
  114. </thead>
  115. <tbody>
  116. <?php
  117. while($row = $result->fetch_assoc()){
  118. $dt = new DateTime($row["date"]);
  119. $dt->setTimezone(new DateTimeZone('Europe/Madrid'));
  120. ?>
  121. <tr>
  122. <td><a href="registro.php?filter_id=<?php echo $row["player_id"];?>"><?php echo $row["player_id"];?></a></td>
  123. <td><?php echo $row["player_name"];?></td>
  124. <td><a href="registro.php?filter_type=<?php echo $row["type"];?>"><?php echo $row["type"];?></a></td>
  125. <td><?php echo $dt->format('Y-m-d H:i:s');?></td>
  126. <td><?php echo $row["info"];?></td>
  127. <td><?php echo $row["location"];?></td>
  128. <td><?php echo $row["equipo"];?></td>
  129. </tr>
  130. <?php
  131. }
  132. ?>
  133. </tbody>
  134. </table>
  135.  
  136. <br>
  137.  
  138. <?php if(isset($_REQUEST["filter_type"])){ ?>
  139.  
  140. <a href="registro.php?p=0&filter_type=<?php echo $_REQUEST["filter_type"]; ?>"><<</a>
  141.  
  142. <?php
  143. if($p != 0){
  144. ?>
  145. <a href="registro.php?p=<?php echo $p-1; ?>&filter_type=<?php echo $_REQUEST["filter_type"]; ?>"><-Antrás</a>
  146. <?php
  147. }
  148. ?>
  149.  
  150. <?php
  151. if($p < $last_page){
  152. ?>
  153. <a href="registro.php?p=<?php echo $p+1; ?>&filter_type=<?php echo $_REQUEST["filter_type"]; ?>">Siguiente-></a>
  154. <?php
  155. }
  156. ?>
  157.  
  158. <a href="registro.php?p=<?php echo $last_page; ?>&filter_type=<?php echo $_REQUEST["filter_type"]; ?>">>></a>
  159.  
  160. <?php } elseif(isset($_REQUEST["filter_id"])){ ?>
  161.  
  162. <a href="registro.php?p=0&filter_id=<?php echo $_REQUEST["filter_id"]; ?>"><<</a>
  163.  
  164. <?php
  165. if($p != 0){
  166. ?>
  167. <a href="registro.php?p=<?php echo $p-1; ?>&filter_id=<?php echo $_REQUEST["filter_id"]; ?>"><-Antrás</a>
  168. <?php
  169. }
  170. ?>
  171.  
  172. <?php
  173. if($p < $last_page){
  174. ?>
  175. <a href="registro.php?p=<?php echo $p+1; ?>&filter_id=<?php echo $_REQUEST["filter_id"]; ?>">Siguiente-></a>
  176. <?php
  177. }
  178. ?>
  179.  
  180. <a href="registro.php?p=<?php echo $last_page; ?>&filter_id=<?php echo $_REQUEST["filter_id"]; ?>">>></a>
  181.  
  182. <?php }else{ ?>
  183.  
  184. <a href="registro.php?p=0"><<</a>
  185.  
  186. <?php
  187. if($p != 0){
  188. ?>
  189. <a href="registro.php?p=<?php echo $p-1; ?>"><-Antrás</a>
  190. <?php
  191. }
  192. ?>
  193.  
  194. <?php
  195. if($p < $last_page){
  196. ?>
  197. <a href="registro.php?p=<?php echo $p+1; ?>">Siguiente-></a>
  198. <?php
  199. }
  200. ?>
  201.  
  202. <a href="registro.php?p=<?php echo $last_page; ?>">>></a>
  203.  
  204. <?php } ?>
  205.  
  206. <br><br><br><br>
  207. <?php
  208.  
  209. $stmt->close();
  210. }
  211.  
  212. $mysqli->close();
  213.  
  214. ?>
  215. </body>
  216. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement