Advertisement
Jakolcz

Michani cisel a jejich hadani

Dec 15th, 2011
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.12 KB | None | 0 0
  1. <?php
  2. $pole = array(1,2,3,4,5,6,7,8,9,0);
  3. $form = "<form method='POST' action='shuffle.php'>\n";
  4.  
  5. if(isset($_POST["shuffle"]))
  6. {
  7.     $form = $form."<input type='hidden' name='shuffled' value='shuffled' />\n";
  8. }else if(!isset($_POST["list"])){
  9.     $form = $form."<input type='text' name='userInput' value='' />\n";
  10.     $form = $form."<input type='submit' name='shuffle' value='Start!' />\n";
  11. }
  12.  
  13. if(!isset($_POST["showed"])||isset($_POST["new"]))
  14. {
  15.     shuffle($pole);
  16.     echo "<table border='1'>\n";
  17.     for($i=0; $i<count($pole); $i++)
  18.     {
  19.         echo "<tr><td>".($i+1)."</td><td>".$pole[$i]."</td></tr>\n";
  20.     }
  21.     echo "</table>\n";
  22.     $numz = "";
  23.     for($i=0; $i<count($pole); $i++)
  24.     {
  25.         $numz = $numz.$pole[$i].",";
  26.     }
  27.     $form = $form."<input type='hidden' name='list' value='$numz' />\n";
  28.     $form = $form."<input type='hidden' name='showed' value='showed' />\n";
  29. }else{
  30.     $oldInputs = array();
  31.     if(isset($_POST["userInput"])&&!isset($_POST["userInputs"]))
  32.         $oldInputs[0] = $_POST["userInput"];
  33.     else if(isset($_POST["userInputs"]))
  34.         $oldInputs = explode(",", $_POST["userInputs"]);
  35.     else
  36.         echo "Error!<br />";
  37.     echo "oldInputs<br />\n";
  38.     print_r($oldInputs);
  39.     $form = $form."<input type='hidden' name='showed' value='showed' />\n";
  40. }
  41.  
  42. if(isset($_POST["list"]))
  43. {
  44.     $listValue = $_POST["list"];
  45.     $form = $form."<input type='hidden' name='list' value='$listValue' />\n";
  46.     $form = $form."<input type='text' name='userInput' value='' />\n";
  47. }
  48. if(isset($_POST["userInput"]))
  49. {
  50.     $userInput = $_POST["userInput"];
  51.     $oldInputs = "";
  52.     if(isset($_POST["userInputs"]))
  53.         $oldInputs = $_POST["userInputs"].$userInput.",";
  54.     else
  55.         $oldInputs = $userInput.",";    
  56.     $form = $form."<input type='hidden' name='userInputs' value='$oldInputs' />\n";
  57. }
  58.  
  59. if(isset($_POST["shuffle"])||isset($_POST["list"]))
  60.     $form = $form."<input type='submit' value='Odeslat' />\n";
  61.    
  62. if(isset($_POST["counter"])){
  63.     $counter = $_POST["counter"];
  64.     $form = $form."<input type='hidden' name='counter' value='".($counter+1)."' />\n";
  65. }else
  66.     $form = $form."<input type='hidden' name='counter' value='0' />\n";
  67.    
  68. if(isset($_POST["counter"]))
  69. {
  70.     echo "<table border='1'>";
  71.     $counter = (int)$_POST["counter"];
  72.     if(isset($_POST["list"]))
  73.         $list = explode(",", $_POST["list"]);
  74.     echo "counter = $counter<br />\n";
  75.     if(isset($_POST["userInputs"]))
  76.         $oldInputs = explode(",", $_POST["userInputs"]);
  77.     for($i=0; $i<$counter; $i++)
  78.     {
  79.         if($list[$i]==$oldInputs[$i])
  80.             echo "<tr><td>".($i+1)."</td><td bgcolor='green'>".$oldInputs[$i]."</td></tr>\n";
  81.         else
  82.             echo "<tr><td>".($i+1)."</td><td bgcolor='red'>".$oldInputs[$i]."</td></tr>\n";
  83.     }
  84. }
  85.  
  86. if(isset($_POST["counter"]))
  87. {
  88.     $counter = (int)$_POST["counter"];
  89.     /*if($counter == 10)
  90.     {
  91.         $pattern = "/<form.+
  92.         preg_replace("<input type='submit' name='shuffle' value='Start!' />\n",
  93.     }*/
  94. }
  95.  
  96. //$form = $form."<input type='submit' />\n";
  97. $form = $form."</form>\n";
  98. echo $form;
  99. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement