<?php
include "scrinit.php";
include "logo.php";
?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style1.css" rel="stylesheet" type="text/css" />
<title>Βαθμολόγιο Καθηγητή</title>
<script type="text/javascript" src="https://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=800, height=800, top='+top+', left='+left);
}

function submitform()
{
    document.forms["bath"].submit();
}

function pop_up(url){
window.open(url,'win2','status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=800,height=800,directories=no,location=no') 
}

</script>

<script type="text/javascript">
var prompt=true;

		$(document).ready(function() {

				$('input:not(:button,:submit),textarea,select').change(function () {
					window.onbeforeunload = function () {
						if (prompt == true) 
							return 'Δεν έχετε αποθηκεύσει τους βαθμούς που έχετε καταχωρίσει';
						}
					});


				$('input:submit').click(function(e) {
					prompt = false;
					});
	    });
		
</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:1px;font-size:9pt; }
.fieldset
{
    width:900px;
	background: #F5F9F0;
	border:2px solid green;
    -moz-border-radius:4px;
    -webkit-border-radius:4px;	
    border-radius:4px;	
}
</style>

</head>
  
<body>
<p class='p1'>ΚΑΤΑΧΩΡΗΣΗ ΔΕΔΟΜΕΝΩΝ ΑΞΙΟΛΟΓΗΣΗΣ </p>
<?php
require "dbconnect.php"; 
$dt=$_SESSION['dt'];
$name = $_SESSION['n'];
$teacher=$_SESSION['usr'];
$tetramino=$_SESSION['tetramino'];
$maxmark=20;
$cde=$_GET['data'];
$arr = explode("/", $cde);
$code=$arr[0];
if ($code == 0 )
 {  
	$testdate=$arr[1];
	$tmima = $arr[2];
	$subject = $arr[3];
	$did = $arr[4];
	$diarkia=$arr[5];
	$datein=$dt;
	$sql="insert into aksinfo (pmpteacher,tmima,subject,tetramino,type,date,dateaks,declaid) 
	values ('$teacher','$tmima','$subject','$tetramino','','$datein','$testdate','$did')";	
    
	if (mysqli_query($con, $sql)) 
		{
			
        } 
		else 
		{
            echo "Error: " . $sql . "<br>" . mysqli_error($con);
        }
	$code= $con->insert_id;	
	
}
else
{
	$sql=mysqli_query($con,"select * from aksinfo where code='$code'");
	$row=mysqli_fetch_array($sql);
	$typex=$row['type'];
	$maxmark=$row['maxmark'];
	$tmima = $row['tmima'];
	$subject = $row['subject'];
	$percent=$row['percent'];
	$dat=$row['date'];
	$diarkia=$row['diarkia'];
	$datein=$row['date'];
	$testdate=$row['dateaks'];
	$did=$row['declaid'];
}
    
$sql1=mysqli_query($con,"select type,code from aksiologiseis where subject='ΟΛΑ' and id < 5");
	
?>
<form action="bathpop1.php" method="post" name="bath" target="DoSubmit" onSubmit="DoSubmit = window.open('about:blank','DoSubmit','width=600,height=500');"> 
<fieldset class="fieldset" >
<legend> ΔΕΔΟΜΕΝΑ ΑΞΙΟΛΟΓΗΣΗΣ</legend>
<?php
echo " Κωδικός Αξιολόγησης:<input type='text' name='code' value='$code' size='3' readonly='readonly' />  ";
echo "&nbsp&nbsp&nbsp Καθηγητής/τρια:<input type='text' name='teachname' value='$name' /> ".
     "&nbsp&nbsp&nbsp Ημερ. Καταχώρισης/Διόρθωσης:<input type='date' value='$datein' readonly='readonly'/> "."<br /><br />";
echo "Ημερ. Διεξαγωγής:<input type='date' name='$testdate' value='$testdate' readonly='readonly'/>&nbsp&nbsp&nbsp  Τμήμα/Συνδ.:<input type='text' name='tmima' value='$tmima' readonly='readonly' />"; 
echo "&nbsp&nbsp&nbsp Μάθημα:<input type='text' name='subject' value='$subject' readonly='readonly' /> ";
echo "&nbsp&nbsp&nbsp Tετράμηνο:<input type='text' name='tetramino' value='$tetramino' size='1' readonly='readonly' /> <br /> <br />";
echo "<input type='hidden' name='aksioid' value='$did'>";
?>

Τύπος αξιολόγησης:
<select name="typea">
   <?php
   while ($row=mysqli_fetch_array($sql1)) 
   {
	$tp=$row['type'];
	if($tp==$typex)
	 {
	  $selected = "selected";
	 }
	else
	  {$selected = "";}
	echo "<option ".$selected." value='$tp' >$tp</option> ";  
   }

  ?>
</select>
<?php

echo " &nbsp&nbsp&nbsp Χρόνος :<input type='text' name='diarkia' value='$diarkia' size='4' readonly='readonly'/>  ";
echo " &nbsp&nbsp&nbsp Μέγιστος Βαθμός:<input type='text' name='maxmark' value='$maxmark' size='4'/>  ";
echo "<br />";
echo "</fieldset>";
echo "<br />";

$result = mysqli_query($con,"SELECT DISTINCT s.mitroo,a.eponimo,a.onoma,a.tmima 
FROM syndidaskalies as s,allstudentinfo as a, syndcodes as sc 
WHERE sc.synd = '$tmima' AND s.mitroo=a.mitroo AND sc.syndid=s.syndid ORDER BY a.eponimo,a.onoma");
$crow1=mysqli_num_rows($result);

if ($crow1 > 0)
{
	$cr=1;
	while($row=mysqli_fetch_array($result))
	{	
		$mt[$cr]=$row['mitroo'];
	    $epo[$cr]=$row['eponimo']." ".$row['onoma'];	
		$tmim[$cr]=$row['tmima'];
		$cr++;
	}
}
else
{	
$result = mysqli_query($con,"SELECT mitroo,eponimo,onoma FROM allstudentinfo WHERE tmima='$tmima' ORDER BY eponimo,onoma  ");
$crow1=mysqli_num_rows($result);
    $cr=1;
    while($row = mysqli_fetch_array($result))
     {
	 $mt[$cr]=$row['mitroo'];
	 $epo[$cr]=$row['eponimo']." ".$row['onoma'];
	 $tmim[$cr]=$tmima;
	 $cr++;
	 } 
}
// number of students
$ns=$cr-1;	
//....................................
echo '<p style="color: red;">
      ΓΙΑ ΜΑΘΗΤΕΣ ΠΟΥ ΔΙΚΑΙΟΛΟΓΗΜΕΝΑ ΕΧΑΣΑΝ ΤΗΝ ΑΞΙΟΛΟΓΗΣΗ ΝΑ ΒΑΖΕΤΕ ΒΑΘΜΟ -1 !
	  ΓΙΑ ΔΕΚΑΔΙΚΟΥΣ ΑΡΙΘΜΟΥΣ ΧΡΗΣΙΜΟΠΟΙΕΙΣΤΕ ΤΗΝ (.) {18.5 ΟΧΙ 18,5}
      </p>';
$sql=mysqli_query($con,"SELECT * FROM aksiologisi WHERE code='$code' ");
$c=mysqli_num_rows($sql);
if ($c == 0) 
{ 
$bathmos=array();
}
else
{
	$i=1;
	while($row=mysqli_fetch_array($sql))
	{
	   $m=$row['mitroo'];
	   $bathmos[$m]=$row['bathmos'];	
	   $i++;
    }
}	
echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>α/α</th>
<th>Α.Μ</th>
<th>Τμήμα</th>
<th>Όνοματεπώνυμο</th>
<th>Βαθμός</th>
</tr>";
$i=1;
while($i <=$ns){
  echo "<tr>";
  echo "<td>" .$i;
  echo "<td>". $mt[$i] . "</td>";
  $m=$mt[$i];
  echo "<td>". $tmim[$i] . "</td>";
  echo "<td>". $epo[$i] . "</td>";
  echo "<td>". "<input class='right' type='text'  name='grade[$i]' value='$bathmos[$m]' min=0 max='$maxmark' step='0.1' size='3' >" ."</td>"; 
  echo "</tr>";
  $i++;
}
echo "</table>";
$i--;

echo "<br>";

echo "<input type='hidden' name='mt' value='$mt' >";
echo "<input type='hidden' name='epo' value='$epo' >";
?>
<input type="Submit" name="bathmos" value="Καταχώρηση Βαθμολογίας" class="sb">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp<a  href='<?php echo $menu;?>' ><button  type="button" class="sb1" >Επιστροφή</button> </a>
</form>




</body>
</html>