Advertisement
polectron

Sistema Registro

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