<?php
include "scrinit.php";
include $menu;
?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

</script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">

function popupCenter(pageURL, title, w, h) {
    var left = (screen.width / 2)  - (w / 2);
    var top  = (screen.height / 2) - (h / 2);
    var targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=900, height=300, top='+top+', left='+left);
}

function calculateTotal()
{
   var theForm = document.forms["theform"];
    //Get a reference to the TextBox
    var q = theForm.elements["pr"];
    var tot =0;
    //If the textbox is not blank
    if(q.value!="")
    {
        tot = parseInt(quantity.value);
    }
return howmany;alert("Να επιλέξετε μόνο 1 μάθημα");
}
</script>


<style type="text/css">
input.right{  text-align:right;  }
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:10pt; }
</style>
</head>
<body>

<br><h3> ΑΞΙΟΛΟΓΗΣΗ ΜΑΘΗΜΑΤΟΣ </h3>
<?php
require "dbconnect.php"; 
$dt=$_SESSION['dt'];
$name = $_SESSION['n'];
$usr=$_SESSION['usr'];
$access=$_SESSION['access'];
//$sub=$_SESSION['sub'];

echo "<b>"." ΗΜΕΡΟΜΗΝΙΑ : "."</b>".$dt."<br>";

echo "<br>";echo "<br>";echo "<br>";

If (isset($_POST['subper']))
{
   $percent=$_POST['pr'];
   $subj=ltrim($_POST['subj']);
   echo  "Τα ποσοτά έχουν ενημερωθεί για το μάθημα:".$subj;
   
   $sql1=mysqli_query($con,"select code,type from aksiologiseis where subject='ΟΛΑ'");
   $i=1;
   while ($row=mysqli_fetch_array($sql1)) 
   {
	$tpt[$i]=$row['type'];
	$tpc[$i]=$row['code'];
	$i++;
   }
   $result = mysqli_query($con,"SELECT * FROM aksiologiseis WHERE BINARY ltrim(subject)='$subj'  ");
   $c=mysqli_num_rows($result);
   if ($c > 0)
   {
	   mysqli_query($con,"delete from aksiologiseis WHERE BINARY ltrim(subject)='$subj' ");
   }
   $i=1;
   foreach ($percent as $p)
   { 
      //if ($p > 0)
      //{		  
	  mysqli_query($con,"insert into aksiologiseis (type,code,percent,subject) values ('$tpt[$i]','$tpc[$i]','$p','$subj')" );
	  //}
	  $i++;
   }	
}
else
{
 require "selectmath.php";
?>
<form method='post'> 
  <label><b>Επιλογή Μαθήματος : </b></label>
  <select name='mathsub' >
  <?php
  echo "<option value=' '>Επέλεξε Μάθημα</option>";
  foreach ($sub as $m){ 		  
    echo "<option value='$m'>$m</option>";
  }
?>
</select>
<input type="submit" name="subsubj" value="Επιβεβαίωση Επιλογής" >
</form>

<?php
If (isset($_POST['mathsub']))
{
   $subj=ltrim($_POST['mathsub']);
   echo "<br>"."ΜΑΘΗΜΑ: ".$subj."<br>";  
   $result = mysqli_query($con,"SELECT * FROM aksiologiseis WHERE BINARY ltrim(subject)='$subj'  " ); 
   $c = mysqli_num_rows($result);
   if ($c == 0)
   {
	 $result=mysqli_query($con,"select * from aksiologiseis where BINARY subject='ΟΛΑ'");   
   }
  ?>
 <form method='post' name='theform' id='theform'> 
 <?php
   echo "<table class='myTable' >
   <tr style='border:1px solid black' >
   <tr>
   <th>ΤΥΠΟΣ ΑΞΙΟΛΟΓΗΣΗΣ</th>
   <th>ΚΩΔΙΚΟΣ</th>
   <th>ΠΟΣΟΣΤΟ %</th>
   <th>ΕΠΕΞΗΓΗΣΕΙΣ</th>
   </tr>";
    $i=1;
   while ($row=mysqli_fetch_array($result)) 
   {
	$tp=$row['type'];
	$prc=$row['percent'];
    echo "<tr>";
	echo "<td>" .$tp."</td>";
	echo "<td>" .$row['code']."</td>";
    echo "<td>". "<input class='right' type='text'  name='pr[$i]' value='$prc' min=0 max=100 size='3' >"."</td>";
	echo "<td>". "<input class='right' type='text'  name='pr[$i]' value='$prc' min=0 max=100 size='3' >"."</td>";
    $i++;
   }
 echo "</tr>";
echo "</table>"; 

?>

<input type="hidden" name="subj" value='<?php echo $subj; ?>'>
<br>
<input type="submit" name="subper" value="Καταχώρηση Ποσοστών" onclick="calculateTotal()" /> 
</form>
<?php
If (isset($_POST['subper']))
{
   $percent=$_POST['pr'];
    foreach ($pr as $p){ 		  
	echo "<br>"."ΜΑΘΗΜΑ: ".$p."<br>";}	
}
}
}
?>
<br><br>
<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού   </a>

</body>
</html>