Advertisement
Guest User

PHP + JS = bad ?

a guest
Feb 13th, 2022
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.81 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>STOCKPILER - Stockpile Listing</title>
  6.  
  7. <style type="text/css">
  8. .tg  {border-collapse:collapse;border-color:#ccc;border-spacing:0;margin:0px auto;}
  9. .tg td{background-color:#fff;border-color:#ccc;border-style:solid;border-width:1px;color:#333;
  10.   font-family:Arial, sans-serif;font-size:14px;overflow:hidden;padding:5px 5px;word-break:normal;}
  11. .tg th{background-color:#f0f0f0;border-color:#ccc;border-style:solid;border-width:1px;color:#333;
  12.   font-family:Arial, sans-serif;font-size:14px;font-weight:normal;overflow:hidden;padding:5px 5px;word-break:normal;}
  13. .tg .tg-baqh{text-align:center;vertical-align:middle;font-size:10px;}
  14. .tg .tg-dzk6{background-color:#f9f9f9;text-align:center;vertical-align:middle}
  15.  
  16. .tl {border-color:inherit;font-size:14px;text-align:center;vertical-align:middle;font-family:Arial, sans-serif}
  17.  
  18. </style>
  19.  
  20. </head>
  21. <body>
  22. <center>
  23. <h1>
  24. STOCKPILER - a Foxhole Stockpile Tracker
  25. </h1>
  26. </center>
  27. <center>
  28.  
  29. <?php
  30.  
  31. $servername = "redacted";
  32. $username = "redacted";
  33. $password = "redacted";
  34. $dbname = "redacted";
  35.  
  36. // Create connection
  37. $conn = new mysqli($servername, $username, $password, $dbname);
  38.  
  39. // Check connection
  40. if ($conn->connect_error) {
  41.   die("Connection failed: " . $conn->connect_error);
  42. }
  43. echo "Connected successfully to DB !<br><br>";
  44.  
  45. $table_info = "SELECT serial, map_hex, location, access_code, name, creator, date_created, date_refreshed, date_expire, comments FROM redacted";
  46. //$sql = "SELECT * FROM redacted";
  47. $result = $conn->query($table_info);
  48.  
  49. if ($result->num_rows > 0) {
  50.   // output data of each row
  51.   while($row = $result->fetch_assoc()) {
  52. /*     echo "<tr>";
  53.     echo "<td>".$row["serial"]."</td>";
  54.     echo "<td>".$row["map_hex"]."</td>";
  55.     echo "<td>".$row["location"]."</td>";
  56.     echo "<td>".$row["access_code"]."</td>";
  57.     echo "<td>".$row["name"]."</td>";
  58.     echo "<td>".$row["creator"]."</td>";
  59.     echo "<td>".$row["date_created"]."</td>";
  60.     echo "<td>".$row["date_refreshed"]."</td>";
  61.     echo "<td>".$row["date_expire"]."</td>";
  62.     echo "<td>".$row["comments"]."</td>";
  63.     echo "</tr>"; */
  64.  
  65. $d_c = $row["date_created"];
  66. $d_r = $row["date_refreshed"];
  67. $d_e = $row["date_expire"];
  68. $countdown = date("M j, Y G:i:s", $d_e);
  69. $serial = $row["serial"];
  70.  
  71. echo "<table class='tg' width='1000 px'>";
  72. echo "<tbody>";
  73.  
  74.   echo "<tr>";
  75.     echo "<td class='tg-baqh' width='200 px'>Creator :</td>";
  76.     echo "<td class='tg-baqh' width='200 px'>Date Created: </td>";
  77.     echo "<td class='tg-baqh' width='200 px'>Date Last Refreshed: </td>";
  78.     echo "<td class='tg-baqh' width='200 px'>Date of Expiry: </td>";
  79.     echo "<td class='tg-baqh' width='200 px'>Comments: </td>";
  80.   echo "</tr>";
  81.  
  82.   echo "<tr>";
  83.     echo "<td class='tg-dzk6' width='200 px'>".$row["creator"]."</td>";
  84.     echo "<td class='tg-dzk6' width='200 px'>";
  85.     echo date("H:i D d M Y e", $d_c);
  86.     echo "</td>";
  87.     echo "<td class='tg-dzk6' width='200 px'>";
  88.     echo date("H:i D d M Y e", $d_r);
  89.     echo "</td>";
  90.     echo "<td class='tg-dzk6' width='200 px'>";
  91.     echo date("H:i D d M Y e", $d_e);
  92.     echo "</td>";
  93.     echo "<td class='tg-dzk6' width='200 px'>".$row["comments"]."</td>";
  94.   echo "</tr>";
  95.  
  96.   echo "<tr>";
  97.     echo "<td class='tg-baqh' width='200 px'>Serial No. :</td>";
  98.     echo "<td class='tg-baqh' width='200 px'>Map Hex: </td>";
  99.     echo "<td class='tg-baqh' width='200 px'>Location: </td>";
  100.     echo "<td class='tg-baqh' width='200 px'>Access Code: </td>";
  101.     echo "<td class='tg-baqh' width='200 px'>Name: </td>";
  102.   echo "</tr>";  
  103.  
  104.  
  105.   echo "<tr>";
  106.     echo "<td class='tg-dzk6' width='200 px'>".$row["serial"]."</td>";
  107.     echo "<td class='tg-dzk6' width='200 px'>".$row["map_hex"]."</td>";
  108.     echo "<td class='tg-dzk6' width='200 px'>".$row["location"]."</td>";
  109.     echo "<td class='tg-dzk6' width='200 px'>".$row["access_code"]."</td>";
  110.     echo "<td class='tg-dzk6' width='200 px'>".$row["name"]."</td>";
  111.   echo "</tr>";
  112.  
  113.  
  114.  
  115. echo "</tbody>";
  116. echo "</table>";
  117.  
  118.  
  119. echo "<table class='tl' width='1000 px'>";
  120.  echo "<tbody>";
  121.    echo "<tr>";
  122.    echo "<td width='200 px'><input type='submit' name='submit' value='DELETE'></td>";
  123.    echo "<td width='600 px'>Time Remaining: <BR><timer id='demo'></timer></td>";
  124.    echo "<td width='200 px'><input type='submit' name='submit' value='REFRESH'></td>";
  125.    echo "</tr>";
  126.  echo "</tbody>";
  127. echo "</table>";
  128.  
  129. echo "<HR NOSHADE width='15%'>";
  130.    
  131.   }
  132. } else {
  133.   echo "0 results";
  134. }
  135.  
  136. $conn->close();
  137.  
  138. ?>
  139. </center>
  140. </body>
  141. <script>
  142.    
  143.     var countDownDate = <?php echo strtotime($countdown) ?> * 1000;
  144.     var now = <?php echo time() ?> * 1000;
  145.  
  146.  
  147.     var x = setInterval(function() {
  148.  
  149.         now = now + 1000;
  150.  
  151.         var distance = countDownDate - now;
  152.  
  153.         var days = Math.floor(distance / (1000 * 60 * 60 * 24));
  154.         var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  155.         var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
  156.         var seconds = Math.floor((distance % (1000 * 60)) / 1000);
  157.        
  158.         document.getElementById("demo").innerHTML = days + "d " + hours + "h " +
  159.             minutes + "m " + seconds + "s ";
  160.            
  161.         if (days == 2) {document.getElementById("demo").style.color = 'blue' ;}
  162.         else if (days == 1) {document.getElementById("demo").style.color = 'green' ;}
  163.         else if (days == 0 && hours <= 23 && hours >= 12) {document.getElementById("demo").style.color = 'yellow' ;}
  164.         else if (days == 0 && hours <= 11 && hours >= 6) {document.getElementById("demo").style.color = 'orange' ;}
  165.         else if (days == 0 && hours <= 5) {document.getElementById("demo").style.color = 'red' ;}
  166.        
  167.  
  168.         // If the count down is over, write some text
  169.         if (distance < 0) {
  170.             clearInterval(x);
  171.             document.getElementById("demo").innerHTML = "EXPIRED";
  172.         }
  173.     }, 1000);
  174. </script>
  175.  
  176. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement