Advertisement
Guest User

Leper's Colony - Nuke all mods edition

a guest
Jan 29th, 2014
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.48 KB | None | 0 0
  1. <?php
  2. /*
  3.     filename: mods.php
  4.     [there's a <form> tag with the action "mods.php" (this file) so replace that if you use another filename]
  5.     don't host this on a website, it's not protected against SQL injection etc.
  6.  */
  7. // this line is eventually used to convert month numbers into month names
  8. $month_array = array(
  9.         "1"  => "January",
  10.         "2"  => "February",
  11.         "3"  => "March",
  12.         "4"  => "April",
  13.         "5"  => "May",
  14.         "6"  => "June",
  15.         "7"  => "July",
  16.         "8"  => "August",
  17.         "9"  => "September",
  18.         "10" => "October",
  19.         "11" => "November",
  20.         "12" => "December",
  21. );
  22. if (!is_numeric($_GET['width']))
  23. {
  24.     $width = 500; // if the URL variable "width" is not a number, the width is 500 px
  25. }
  26. elseif($_GET['width'] == "")
  27. {
  28.     $width = 500; // if it's not defined, it defaults to 500 px
  29. }
  30. else
  31. {
  32.     $width = $_GET['width']; // this is when you input a proper number
  33. }
  34. ?>
  35. <html>
  36. <head>
  37. <title>Leper's Colony &bull; Nuke all mods edition</title>
  38. <style type="text/css">
  39. body
  40. {
  41.     background-color: black;
  42.     color: white;
  43. }
  44. div
  45. {
  46.     height: 22px;
  47. }
  48. </style>
  49. </head>
  50. <body>
  51. <?php
  52.     // Connect to MySQL database
  53.     $db = mysqli_connect("localhost","USERNAME","PASSWORD","sa") or die("The database has stopped working. :(");
  54.     $sql = "SELECT DISTINCT type FROM lc ORDER BY type ASC"; // this query eliminates all duplicates
  55.     $result = mysqli_query($db,$sql);
  56. ?>
  57. <form action="mods.php" method="get">
  58. <label>Type:
  59. <select name="type">
  60. <option value=''>None</option>
  61. <?php
  62. // this will create an option for every unique type (ban, probation, etc.) that exists
  63.     while($row = mysqli_fetch_assoc($result))
  64.     {
  65.         extract($row);
  66.         ?>
  67.             <option value='"<?php echo $row['type']; ?>"'><?php echo $row['type']; ?></option>
  68.         <?php
  69.     }
  70.     mysqli_close($result); // close this
  71. ?>
  72. <option value='1'>BANS + AUTOBANS</option>
  73. </select>
  74. </label>
  75. <?php
  76.     $db = mysqli_connect("localhost","USERNAME","PASSWORD","sa") or die("The database has stopped working. :(");
  77.     $sql = "SELECT DISTINCT day FROM lc ORDER BY day ASC";
  78.     $result = mysqli_query($db,$sql);
  79. ?>
  80. <label>Day:
  81. <select name="day">
  82. <option value=''>None</option>
  83. <?php
  84.     while($row = mysqli_fetch_assoc($result))
  85.     {
  86.         extract($row);
  87.         ?>
  88.             <option value='<?php echo $row['day']; ?>'><?php echo $row['day']; ?></option>
  89.         <?php
  90.     }
  91.     mysqli_close($result);
  92. ?>
  93. </select>
  94. </label>
  95. <?php
  96.     $db = mysqli_connect("localhost","USERNAME","PASSWORD","sa") or die("The database has stopped working. :(");
  97.     $sql = "SELECT DISTINCT month FROM lc ORDER BY month ASC"; // this query eliminates all duplicate attention-seekers!
  98.     $result = mysqli_query($db,$sql);
  99. ?>
  100. <label>Month:
  101. <select name="month">
  102. <option value=''>None</option>
  103. <?php
  104.     while($row = mysqli_fetch_assoc($result))
  105.     {
  106.         extract($row);
  107.         // convert month numbers into month names
  108.         $month2 = $row['month'];
  109.         $month  = $month_array[$month2];
  110.         ?>
  111.             <option value='<?php echo $row['month']; ?>'><?php echo $month; ?></option>
  112.         <?php
  113.     }
  114.     mysqli_close($result);
  115. ?>
  116. </select>
  117. </label>
  118. <?php
  119.     $db = mysqli_connect("localhost","USERNAME","PASSWORD","sa") or die("The database has stopped working. :(");
  120.     $sql = "SELECT DISTINCT year FROM lc ORDER BY year ASC"; // this query eliminates all duplicate attention-seekers!
  121.     $result = mysqli_query($db,$sql);
  122. ?>
  123. <label>Year:
  124. <select name="year">
  125. <option value=''>None</option>
  126. <?php
  127.     while($row = mysqli_fetch_assoc($result))
  128.     {
  129.         extract($row);
  130.         ?>
  131.             <option value='<?php echo $row['year']; ?>'><?php echo 2000 + $row['year']; ?></option>
  132.         <?php
  133.     }
  134.     mysqli_close($result);
  135. ?>
  136. </select>
  137. </label>
  138. <label>Graph width:
  139. <input type="text" name="width" value="500" size="4" />
  140. </label>
  141. <br />
  142. <label>Look for mods with over:
  143. <input type="text" name="num_requests" value="1000" size="4" />
  144. requests</label>
  145. <input type="submit" value="Search!" />
  146. </form>
  147. <?php
  148.    
  149.     /*
  150.     End of form input fields. Now enter the actual data table!
  151.  
  152.     the following query will find some values needed for upcoming queries
  153.      */
  154.      
  155.     $db = mysqli_connect("localhost","USERNAME","PASSWORD","sa") or die("The database has stopped working. :(");
  156.     $sql = "SELECT DISTINCT requestor FROM lc ORDER BY requestor ASC";
  157.     $result = mysqli_query($db,$sql);
  158.     // variable max stores number of mods
  159.     $max = mysqli_num_rows($result);
  160.     /*
  161.     array mod_array stores each row into an array
  162.     mysqli_fetch_all is only available starting PHP 5.3.0 so keep that in mind,
  163.     no, mysqli_fetch_array does not do the job: it only picks up the first row
  164.      */
  165.     $mod_array = mysqli_fetch_all($result,MYSQLI_NUM);
  166.     mysqli_close($result);
  167. ?>
  168. <table>
  169.     <tr>
  170.         <th>MOD</th>
  171.         <th>NO. OF REQUESTS MADE</th>
  172.         <th>&nbsp;</th>
  173.     </tr>
  174. <?php
  175.     $db = mysqli_connect("localhost","USERNAME","PASSWORD","sa") or die("The database has stopped working. :(");
  176.     $i = 0; // increment value for while loop
  177.     $x = 0; // eventually stores highest result
  178.     while($i < $max)
  179.     {
  180.         if($_GET['type'] == 1)
  181.         {
  182.             $sql = "SELECT * FROM lc WHERE requestor = '".$mod_array[$i][0]."' AND type NOT LIKE 'P%'"; // Bans + autobans
  183.         }
  184.         else
  185.         {
  186.             $sql = "SELECT * FROM lc WHERE requestor = '".$mod_array[$i][0]."'"; // sets up for upcoming AND queries
  187.             if ($_GET['type'] != "")
  188.             {
  189.                 $sql .= " AND type = ".$_GET['type']; // individual type of request
  190.             }
  191.         }
  192.         if ($_GET['day'] != "")
  193.         {
  194.             $sql .= " AND day = ".$_GET['day']; // day, month, etc.
  195.         }
  196.         if ($_GET['month'] != "")
  197.         {
  198.             $sql .= " AND month = ".$_GET['month'];
  199.         }
  200.         if ($_GET['year'] != "")
  201.         {
  202.             $sql .= " AND year = ".$_GET['year'];
  203.         }
  204.         $result = mysqli_query($db,$sql);
  205.         // we're gonna set the highest limit for the graph.
  206.         $num = mysqli_num_rows($result);
  207.         if ($num > $x)
  208.         {
  209.             $x = $num;
  210.         }
  211.         ++$i; // we do this at the end because array starts at 0
  212.         mysqli_close($result);
  213.     }
  214.     $i = 0;
  215.     while($i < $max)
  216.     {
  217.         ?><tr><?php
  218.         if($_GET['type'] == 1)
  219.         {
  220.             $sql = "SELECT * FROM lc WHERE requestor = '".$mod_array[$i][0]."' AND type NOT LIKE 'P%'";
  221.         }
  222.         else
  223.         {
  224.             $sql = "SELECT * FROM lc WHERE requestor = '".$mod_array[$i][0]."'"; // sets up for upcoming AND queries
  225.             if ($_GET['type'] != "")
  226.             {
  227.                 $sql .= " AND type = ".$_GET['type'];
  228.             }
  229.         }
  230.         if ($_GET['day'] != "")
  231.         {
  232.             $sql .= " AND day = ".$_GET['day'];
  233.         }
  234.         if ($_GET['month'] != "")
  235.         {
  236.             $sql .= " AND month = ".$_GET['month'];
  237.         }
  238.         if ($_GET['year'] != "")
  239.         {
  240.             $sql .= " AND year = ".$_GET['year'];
  241.         }
  242.         $result = mysqli_query($db,$sql);
  243.         // okay, now we should get the results
  244.         $num = mysqli_num_rows($result);
  245.         // are we looking for mods who deliver over y results?
  246.         if ($_GET['num_requests'] != "")
  247.         {
  248.             if ($num < $_GET['num_requests'])
  249.             {
  250.                 ++$i; // if it doesn't match, just go on to the next row
  251.             }
  252.             else
  253.             {
  254.                 ?>
  255.                 <td><?php echo $mod_array[$i][0]; ?></td>
  256.                 <td><?php echo $num; ?></td>
  257.                 <td style="width: <?php echo $width; ?>px;"><div style="width: <?php echo ($num / $x)*100; ?>%; background-color: #<?php echo dechex(16777215 - $num); ?>">&nbsp;</div></td><?php echo "\n";
  258.                 ?></tr><?php echo "\n";
  259.                 ++$i; // ok, it matches, do all that stuff
  260.                 mysqli_close($result);
  261.             }
  262.         }
  263.         else
  264.         // no, we're not
  265.         {
  266.             ?>
  267.             <td><?php echo $mod_array[$i][0]; ?></td>
  268.             <td><?php echo $num; ?></td>
  269.             <td style="width: <?php echo $width; ?>px;"><div style="width: <?php echo ($num / $x)*100; ?>%; background-color: #<?php echo dechex(16777215 - $num); ?>">&nbsp;</div></td><?php echo "\n";
  270.             ?></tr><?php echo "\n";
  271.             ++$i; //
  272.             mysqli_close($result);
  273.         }
  274.     }
  275. ?>
  276. </table>
  277. </body>
  278. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement