<?php
  if (!isset($_SESSION['nazwa'])) {
      header('Location: ../login.php');
      exit();
  }
  if ($_SESSION['status']<3) {
?>
<script type="text/javascript">
<?php
  echo "var s = 'http://".$_SERVER['HTTP_HOST']."/index.php?m=0';";
?>
  window.location.href = s;
</script>
<?php
    exit();
  }
?>

<link rel="stylesheet" href="adwasznet/css/test.css" />

<?php
  
  require_once('wiras_php/wa_baza/wa_polacz.php');
  $zap = "SELECT * FROM admin_test ORDER BY data ASC";
  $pobierz = mysqli_query($db, $zap);
  $wynik_at = array();
  while ($wiersz = mysqli_fetch_row($pobierz)) 
  {
    $wynik_at[] = $wiersz;
  }
  $lrat = count($wynik_at);
  
  $zap = "SELECT * FROM test ORDER BY id_test ASC";
  if ($result=mysqli_query($db, $zap))
    {
      $lrwt=mysqli_num_rows($result);
      mysqli_free_result($result);
    }
  
  $zap = "SELECT * FROM test ORDER BY id_test ASC LIMIT $lrat, 5";
  $pobierz = mysqli_query($db, $zap);
  $wynik_t = array();
  while ($wiersz = mysqli_fetch_row($pobierz)) 
  {
    $wynik_t[] = $wiersz;
  }
  $lrdt = count($wynik_t);
?>

<div id="test_tlo">
  <div id="test_formularz">
    Formularze - Test, które zostały już dodane
    <div id="test_dodane">
<?php
  if ($lrat>0) {
    for ($i=0; $i<$lrat; $i++) {
      echo 'ID: '.$wynik_at[$i][1].' Data: '.$wynik_at[$i][2].' &nbsp;&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;&nbsp; ';
    }
  } else {
    echo 'Brak dodanych formularzy typu: test';
  }
?>
    </div>
    <form id="formularz_test" method="post" action="adwasznet/test_wyslij.php">
    <select  id="w_test" name="w_test" style="padding: 3px 5px">
<?php
  for ($i=0; $i<$lrdt; $i++) {
    echo '<option value="'.$wynik_t[$i][0].'">'.'ID: '.$wynik_t[$i][0].' &nbsp;&nbsp;/ &nbsp;&nbsp;Pytanie: '.$wynik_t[$i][1].'</option>';
  }
  echo '</select>';
  echo '&nbsp;&nbsp;&nbsp;&nbsp;';
  $dt[0] = date_format(new DateTime(), 'Y-m-d');
  $dt[1] = date_format((new DateTime())->modify('+1 day'), 'Y-m-d');
  $dt[2] = date_format((new DateTime())->modify('+2 day'), 'Y-m-d');
  $dt[3] = date_format((new DateTime())->modify('+3 day'), 'Y-m-d');
  $dt[4] = date_format((new DateTime())->modify('+4 day'), 'Y-m-d');
  $dt[5] = date_format((new DateTime())->modify('+5 day'), 'Y-m-d');
  $dt[6] = date_format((new DateTime())->modify('+6 day'), 'Y-m-d');
  
  echo '<select  id="w_testd" name="w_testd" style="padding: 3px 5px">';
  for ($i=0; $i<7; $i++) {
    echo '<option value="'.$dt[$i].'">'.$dt[$i].'</option>';
  }
  echo '</select>';
  
?>  
    &nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" id="button_menu2" name="zapisz_test" value="Zapisz">
  </form>
  </div>
<?php

  if (isset($_SESSION['addu_kom'])) {
    echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Info: '.$_SESSION['addu_kom'];
    unset($_SESSION['addu_kom']);
  }
?> 

<div style="width: 780px; margin: 5px 0 0 10px; padding: 10px 20px; background: #048">
<h3 style="margin: 10px auto; text-align: center">Dodaj pytanie do bazy</h3>
  <form method="post" action="adwasznet/pytanie_test_wyslij.php">
     Pytanie
      <input type="text" id="pytanie" name="pytanie" style="width: 600px"/><br>
           
      Odpowiedź - 1
      <input type="text" id="odp1" name="odp1" style="width: 250px"/>

      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Odpowiedź - 2
      <input type="text" id="odp2" name="odp2" style="width: 250px"/><br>

      Odpowiedź - 3
      <input type="text" id="odp3" name="odp3" style="width: 250px"/>
      
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Odpowiedź - 4
      <input type="text" id="odp4" name="odp4" style="width: 250px"/>
      <br>
      <input type="submit" value="Wyślij" id="button_menu2" name="wyslij_pytanie" style="margin: 10px 0 5px 370px;"/>
     
  </form>
</div>   
      
</div>

<script type="text/javascript">

    
$(document).ready(function(){
  
  /*
  $('.zapisz_test').click(function() { 
    alert ($('#w_test').val());
    alert ($('#w_testd').val());
   });
  */
});

</script>