<?php
session_start();
ob_start();
$menu=$_SESSION['menu'];
include $menu;
?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Βαθμολόγιο Καθηγητή</title>

</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=800, height=800, top='+top+', left='+left);
}

function submitform()
{
    document.forms["carservice"].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">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:10pt; }
<p style="font-size:10px;"></p>
</style>

</head>
  
<body>

<?php
require "dbconnect.php"; 
$dt=$_SESSION['dt'];
$name = $_SESSION['n'];
$tetramino=$_SESSION['tetramino'];

if (isset($_GET['math'])){
$lesson=$_GET['math'];}
elseif (isset($_POST['submitb']))
{
$lesson=$_POST['mathsubid'];}

$arr = explode("/", $lesson);
$lesson = $arr[0];
$subject = $arr[1];
$_SESSION['lesson']=$lesson;
$_SESSION['subject']=$subject;
$fl=1;
$ms=$lesson."/".$subject;
$_SESSION['ms']=$ms;
$tdate=$_POST['dateid'];
$_SESSION['tdate']=$tdate;


$fl++;

echo "ΒΑΘΜΟΛΟΓΙΟ  ";
echo " Τμήμα/Συνδ.:<input type='text' name='lesson' value='$lesson' />   ";
echo " Μάθημα:<input type='text' name='subject' value='$subject'  />  ";
echo " Τετράμηνο:<input type='text' name='tetramino' value='$tetramino' size='4'/> <br /><br />  ";

$result = mysqli_query($con,"SELECT syndidaskalies.pmp,allstudentinfo.eponimo,allstudentinfo.onoma,allstudentinfo.tmima FROM syndidaskalies,allstudentinfo WHERE synd = '$lesson' AND syndidaskalies.pmp=allstudentinfo.mitroo ORDER BY allstudentinfo.eponimo,allstudentinfo.onoma");
	$crow1=mysqli_num_rows($result);
	$cr=1;
	while($row=mysqli_fetch_array($result))
	{	
		$mt[$cr]=$row['pmp'];
		
	    $epo[$cr]=$row['eponimo']." ".$row['onoma'];	
		$tmim[$cr]=$row['tmima'];
		$cr++;
	}
	
if ($crow1==0){	
     $tm3b=mb_substr($lesson, 1, 1, 'utf-8');
	 $tm3='Α0'.$tm3b;
	
$result = mysqli_query($con,"SELECT mitroo,eponimo,onoma FROM allstudentinfo WHERE tmima='$lesson' OR tmima = '$tm3' 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]=$lesson;
	 $cr++;
	 }
	 
}
$cr=$cr-1;	
//....................................

$sql=mysqli_query($con,"SELECT * FROM bathmologio WHERE mathima='$lesson' AND subject='$subject' AND tetramino='$tetramino' ");
$c=mysqli_num_rows($sql);

if ($c > 0) {

while($row = mysqli_fetch_array($sql)){
$k=	$row['mitroo'];
$p[$k][0]= $row['aks1'];
$p[$k][1]=$row['aks2'];
$p[$k][2]=$row['aks3'];
$p[$k][3]=$row['aks4'];
$p[$k][4]=$row['aks5'];
$p[$k][5]=$row['aks6'];
$p[$k][6]=$row['aks7'];
$p[$k][6]=$row['aks8'];
$p[$k][6]=$row['aks9'];
$p[$k][6]=$row['aks10'];
}}


?>

<form action="bathpop.php" method="post" target="DoSubmit" onSubmit="DoSubmit = window.open('about:blank','DoSubmit','width=600,height=500');"> 
<?php
echo "<table class='myTable' >
<tr style='border:1px solid black' >
<tr>
<th>α/α</th>
<th>Α.Μ</th>
<th>Τμήμα</th>
<th>Όνοματεπώνυμο</th>"."<th>".'Αξλγ1'."</th>"."<th>".'Αξλγ2'."</th>"."<th>".wordwrap('Αξλγ3',10,"<br>\n")."</th>"."<th>".wordwrap('Αξλγ4',10,"<br>\n")."</th>"."<th>".wordwrap('Αξλγ5',10,"<br>\n")."</th>". "<th>".wordwrap('Αξλγ6',10,"<br>\n")."</th>"."<th>".wordwrap('Αξλγ7.',10,"<br>\n")."</th>"."<th>".wordwrap('Αξλγ8.',10,"<br>\n")."</th>"."<th>".wordwrap('Αξλγ9.',10,"<br>\n")."</th>"."<th>".wordwrap('Αξλγ10.',10,"<br>\n")."</th>"."<th>".wordwrap('ΜΕΣΟΣ',10,"<br>\n")."</th>"."</tr>";

echo "<tr>
<th></th>
<th></th>
<th></th>
<th></th>";

$sqlp=mysqli_query($con,"SELECT * from baros WHERE mathima='$lesson' AND subject='$subject' AND tetramino='$tetramino' ");
$row1=mysqli_fetch_array($sqlp);
$pc1=$row1['poso1'];
$pc2=$row1['poso2'];
$pc3=$row1['poso3'];
$pc4=$row1['poso4'];	
$pc5=$row1['poso5'];
$pc6=$row1['poso6'];
$pc7=$row1['poso7'];
$pc7=$row1['poso8'];
$pc7=$row1['poso9'];
$pc7=$row1['poso10'];

echo "<th>". "<input type='text' name='pc1' value='$pc1' min=0 max=100 size='3' >" ."%"."</th>"; 
echo "<th>". "<input type='text' name='pc2' value='$pc2' min=0 max=100 size='3' >" ."%"."</th>";
echo "<th>". "<input type='text' name='pc3' value='$pc3' min=0 max=100 size=3 >" ."%"."</th>";
echo "<th>". "<input type='text' name='pc4' value='$pc4' min=0 max=100 size=3 >" ."%"."</th>";
echo "<th>". "<input type='text' name='pc5' value='$pc5' min=0 max=100 size=3 >" ."%"."</th>";
echo "<th>". "<input type='text' name='pc6' value='$pc6' min=0 max=100 size=3 >" ."%"."</th>";
echo "<th>". "<input type='text' name='pc7' value='$pc7' min=0 max=100 size=3 >" ."%"."</th>";
echo "<th>". "<input type='text' name='pc8' value='$pc8' min=0 max=100 size=3 >" ."%"."</th>";
echo "<th>". "<input type='text' name='pc9' value='$pc9' min=0 max=100 size=3 >" ."%"."</th>";
echo "<th>". "<input type='text' name='pc10' value='$pc10' min=0 max=100 size=3 >" ."%"."</th>";
echo "<th>"." "."</th>";

$i=1;
 while($i<=$cr)
     {
	 echo "<tr>";
	 echo "<td>" .$i;
	 echo "<td>". $mt[$i] . "</td>";
	 echo "<td>". $tmim[$i] . "</td>";

if ( strlen($epo[$i]) >30 ) 
{ 
echo "<td>".substr($epo[$i], 0, 45) . "</td>";
}
else
{
echo "<td>".$epo[$i].str_repeat(' ', max(0, 45 - strlen($epo[$i]))) . "</td>";	
}

	 
	 $pmp= $mt[$i];
	 if ($c > 0) {
	 $a0=$p[$pmp][0];
	 $a1=$p[$pmp][1];
	 $a2=$p[$pmp][2];
	 $a3=$p[$pmp][3];
	 $a4=$p[$pmp][4];
	 $a5=$p[$pmp][5];
	 $a6=$p[$pmp][6];
	 $a7=$p[$pmp][7];
	 $a8=$p[$pmp][8];
	 $a9=$p[$pmp][9];
	 }
	 else
	 {
	 $a0=" ";
	 $a1=" ";
	 $a2=" ";
	 $a3=" ";
	 $a4=" ";
	 $a5=" "; 
	 $a6=" ";
	 $a7=" ";
	 $a8=" ";
	 $a9=" ";
	 }
	
	 echo "<input type='text' name='mit[]' value='$pmp' HIDDEN >" ;
	 echo "<td>". "<input type='text' name='att[$pmp][0]' value='$a0' min=0 max=20 size=3 >" ."</td>"; 
	 echo "<td>". "<input type='text' name='att[$pmp][1]' value='$a1' min=0 max=20  size=3 >" ."</td>";
	 echo "<td>". "<input type='text' name='att[$pmp][2]' value='$a2' min=0 max=20 size=3>" ."</td>";
	 echo "<td>". "<input type='text' name='att[$pmp][3]' value='$a3' min=0 max=20 size=3>" ."</td>";
	 echo "<td>". "<input type='test' name='att[$pmp][4]' value='$a4' min=0 max=20 size=3>" ."</td>";
	 echo "<td>". "<input type='text' name='att[$pmp][5]' value='$a5' min=0 max=20 size=3>" ."</td>";
	 echo "<td>". "<input type='text' name='att[$pmp][6]' value='$a6' min=0 max=20 size=3>" ."</td>";
	 echo "<td>". "<input type='test' name='att[$pmp][7]' value='$a7' min=0 max=20 size=3>" ."</td>";
	 echo "<td>". "<input type='text' name='att[$pmp][8]' value='$a8' min=0 max=20 size=3>" ."</td>";
	 echo "<td>". "<input type='text' name='att[$pmp][9]' value='$a9' min=0 max=20 size=3>" ."</td>";
	 
	 $num[$i]=($a0*$pc1+$a1*$pc2+$a2*$pc3+$a3*$pc4+$a4*$pc5+$a5*$pc6+$a6*$pc7+$a7*$pc8+$a8*$pc9+$a9*$pc10)/100;
	 echo "<input type='text' name='num[]' value='$num[$i]' HIDDEN >" ; 
	 echo "<td>". number_format($num[$i],2)  ."</td>";
	 echo "<td>". " " ."</td>";
	 echo "</tr>";
$i++;
}

echo "</table>";
$i--;

echo "<br>";
echo str_repeat('&nbsp;', 60);
//<a href='bathmologio1.php' style="color:blue " >  Επαναφόρτωση Οθόνης  </a>
?>

<input type="Submit" name="bath" value="aks1" style="width:70px;">
<input type="Submit" name="bath" value="aks2" style="width:65px;">
<input type="Submit" name="bath" value="aks3" style="width:65px;" >
<input type="Submit" name="bath" value="aks4" style="width:65px;" >
<input type="Submit" name="bath" value="aks5" style="width:65px;">
<input type="Submit" name="bath" value="aks6" style="width:63px;">
<input type="Submit" name="bath" value="aks7" style="width:63px;">
<input type="Submit" name="bath" value="aks8" style="width:63px;">
<input type="Submit" name="bath" value="aks9" style="width:63px;">
<input type="Submit" name="bath" value="aks10" style="width:63px;">
</form>
<h3> Για να αποθηκευτούν οι βαθμοί και να υπολογιστούν τα στατιστικά πρέπει να πατήσετε το κουμπί που αντιστοιχει στην αξιολόγηγη που έχετε καταχωρίσει (aks1 ... aks10) </h3>
<br />
<?php $ms=$_SESSION['ms'];?>
<a href='bathmologio.php' style="color:blue " > <button>  Επιστροφή  </a>

<?php
echo  "<a href=\"bathmologio1.php?math=".$ms."\"> <button>"." Επαναφόρτωση Οθόνηs". "</a>";
?>

<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού   </a>

</body>
</html>