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

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Παιδαγωγικές Ομάδες</title>
<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, 'win1', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=1500, height=500, top='+top+', left='+left);
}
function popupCenter1(pageURL, title, w, h) {
    var left = (screen.width / 2)  - (w / 2);
    var top  = (screen.height / 2) - (h / 2);
    var targetWin = window.open(pageURL, 'win1', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=1500, height=800, top='+top+', left='+left);
}
</script>
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid green;padding:2px;font-size:10pt; }
<p style="font-size:10px;"></p>
</style>

</head>

<body>

<?php
require "dbconnect.php"; 
$dt=$_SESSION['dt'];
$name = $_SESSION['n'];
$usr=$_SESSION['usr'];
$lsn=$_GET['math'];
$ar=explode('/',$lsn);
$lesson=$ar[1];
$tmima=$ar[0];

$tmimas=mb_substr($tmima,0,3);

$result = mysqli_query($con,"SELECT s.mitroo,al.eponimo,al.onoma,al.tmima 
FROM syndidaskalies as s,allstudentinfo as al, syndcodes as sc 
WHERE sc.synd = '$tmima' AND s.mitroo=al.mitroo AND sc.syndid=s.syndid ORDER BY al.eponimo,al.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]=$row['tmima'];
		$cr++;
}

if ($crow1==0)
{		
	$result = mysqli_query($con,"SELECT mitroo,eponimo,onoma FROM allstudentinfo WHERE tmima='$tmima' ORDER BY eponimo,onoma  ");
	$crow1=mysqli_num_rows($result);
    $i=1;
    while($row = mysqli_fetch_array($result))
     {
	 $mt[$i]=$row['mitroo'];
	 $epo[$i]=$row['eponimo']." ".$row['onoma'];
	 $tmim[$i]=$tmima;
	 $i++;
	 }
}
//....................................
$sql=mysqli_query($con,"SELECT id FROM pedamaster WHERE lesson='$lesson' AND teacher='$usr' and tmima='$tmima' ");
$c=mysqli_num_rows($sql);
if ($c > 0) 
{
   $row = mysqli_fetch_array($sql);
   $code=$row['id'];
   $sql1=mysqli_query($con,"SELECT * FROM pedanew WHERE code='$code'");
   while($row1 = mysqli_fetch_array($sql1))
   {
    $k=	$row1['mitroo'];
    $p[$k][0]= $row1['sinepia'];
	$p[$k][1]=$row1['pitharxia'];
	$p[$k][2]=$row1['beltiosi'];
	$p[$k][3]=$row1['grade'];
   }
}
else
{
	mysqli_query($con,"INSERT INTO pedamaster (teacher,lesson,tmima,date) values ('$usr','$lesson','$tmima','$dt')");
    $code = mysqli_insert_id($con);
}
echo "<TABLE>";
echo "<tr><td>";
echo "ΠΟΙΟΤΙΚΗ ΑΞΙΟΛΟΓΗΣΗ ΓΙΑ ΤΟ: "."<b>".$tmima." / ".$lesson."</b>";
echo "</td><td></td><td>". "ΚΡΙΤΗΡΙΑ ΑΞΙΟΛΟΓΗΣΗΣ"."</td></tr>";

?>

<TR>
<TD>
<form method="POST" name = "eggrafi" action= >
 
<?php
echo "<table class='myTable' >
<tr style='border:1px solid green' bgcolor='#d6ff73'  >
<th>α/α</th>
<th>Α.Μ</th>
<th>Τμήμα</th>
<th>Όνοματεπώνυμο</th>"."<th>".wordwrap('ΣΥΝΕΠΕΙΑ',15,"<br>\n")."</th>"."<th>".wordwrap('ΠΕΙΘΑΡΧΙΑ',15,"<br>\n")."</th>"."<th>".wordwrap('ΠΡΟΣΠΑΘΕΙΑ ΣΥΝΕΙΣΦΟΡΑ',20,"<br>\n")."</th>".
"<th>".wordwrap('ΕΚΤΙΜΗΣΗ ΕΠΙΔΟΣΗΣ',15,"<br>\n")."</th>"."<th>".wordwrap('ΘΕΜΑΤΑ ΣΕΑ',30,"<br>\n")."</th>"."<th>".wordwrap('ΑΠΟΥΣΙΕΣ',15,"<br>\n")."</th>"."</tr>";

echo "<tr bgcolor=#F5F89B>
<th colspan='4'>"."<th>".wordwrap('1-4',15,"<br>\n")."</th>"."<th>".wordwrap('1-4',15,"<br>\n")."</th>"."<th>".wordwrap('1-5',15,"<br>\n")."</th>".
"<th>".wordwrap('1-20',15,"<br>\n")."</th>"."<th>".wordwrap('Π,Σ,Α',15,"<br>\n")."</th>"."<th>".wordwrap(' ',15,"<br>\n")."</th>"."</tr>";

$i=1;
while($i<=$crow1)
     {
	echo "<tr>";
	echo "<td>" .$i;
	?><td>
    <a href="#" onClick="popupCenter('poiotika2.php?am=<?php echo $mt[$i]; ?>')"><?php echo $mt[$i]; ?></a>
    </td><?php
	$sqla=mysqli_query($con,"select grade from pedanew where mitroo='$mt[$i]'");
	$pl=mysqli_num_rows($sqla);
	$sqlX = mysqli_query($con,"SELECT apousiestotal FROM apousiesabakio WHERE mitroo='$mt[$i]' ");
	$row1=mysqli_fetch_array($sqlX);
	$apou[$i]=$row1['apousiestotal'];	
	$pr=mysqli_query($con,"select problima,stiriksi,aporos from problimata where mitroo='$mt[$i]'");
	//$pr=mysqli_query($con,"select mitroo from stiriksi where mitroo='$mt[$i]'");
	$psa[$i]="";
	if (mysqli_num_rows($pr) > 0)
	{
		$rowpr=mysqli_fetch_array($pr);
		if (!empty($rowpr['problima']) )$psa[$i]=$psa[$i]."Π,";
		if (strval($rowpr['stiriksi']) > 0){$psa[$i]=$psa[$i]."Σ,";}
		if (strval($rowpr['aporos']) > 0){$psa[$i]=$psa[$i]."Α";}
	}
	$psa[$i]=trim($psa[$i],',');
//.........................................	 
	 echo "<td>". $tmim[$i] . "</td>";
	 echo "<td>".$epo[$i] . "</td>"; 
	 $mitroo= $mt[$i];
	 if ($c > 0) 
	 {
	   $a0=$p[$mitroo][0];
	   $a1=$p[$mitroo][1];
	   $a2=$p[$mitroo][2];
	   $a3=$p[$mitroo][3];
	 }
	 else
	 {
	   $a0=null;
	   $a1=null;
	   $a2=null;
	   $a3=null;
	 }
	
	 echo "<td align='center'>". "<input type='number' name='att[$mitroo][0]' value='$a0' size='4' min=0 max=4>" ."</td>"; 
	 echo "<td align='center'>". "<input type='number' name='att[$mitroo][1]' value='$a1' size='4' min=0 max=4>" ."</td>";
	 echo "<td align='center' >". "<input type='number' name='att[$mitroo][2]' value='$a2'  size='4' min=0 max=6>" ."</td>";
	 echo "<td align='center'>". "<input type='number' name='att[$mitroo][3]' value='$a3' size='4' min=0 max=20>" ."</td>";
	 echo "<td align='center'>". $psa[$i] ."</td>";
	 echo "<td>".$apou[$i] ."</td>";
	 
     
	 echo "</tr>";
     $i++;
}
echo "</table>";
$i--;
?>
<input type='hidden' name='code' value=<?php echo $code; ?> >
<input type='hidden' name='lsn' value=<?php echo $lsn; ?> >
<br>
<input type="Submit" name="pedag" value="Καταχώρηση">
<button onClick="popupCenter('poiotika3v3.php?tmima=<?php echo $tmimas; ?>')">ΠΑΙΔΑΓΩΓΙΚΗ ΤΜΗΜΑΤΟΣ</button>

</form>
</TD>
<td></td><td>
<?PHP
echo "<b>"."ΣΥΝΕΠΕΙΑ"."</b><br>";
?><pre>
1. Καθόλου 
2. Λίγη
3. Ικανοποιητική
4. Εξαίρετη

Φέρνει βιβλία, τετράδια κλπ
Κάνει την κατ οίκον εργασία
Τηρά τα χρονοδιαγράμματα
</pre><br>
<?php
echo "<b>"."ΠΕΙΘΑΡΧΙΑ"."</b><br>";
?><pre>
1. Μη αποδεχτή 
2. Ικανοποιητική
3. Καλή
4. Εξαίρετη

Ακολουθεί οδηγίες
Δεν ενοχλεί
Δε διακόπτει το μάθημα
Δεν καθυστερεί
</pre><br>
<?php
echo "<b>"."ΠΡΟΣΠΑΘΕΙΑ/ΣΥΝΕΙΣΦΟΡΑ"."</b><br>";
?><pre>
 1. Καθόλου 
 2. Λίγη
 3. Ικανοποιητική
 4. Εξαίρετη
 5. Μείωση 

Συμμετέχει και συνεισφέρει στο μάθημα
Καταβάλλει προσπάθεια
Αναλαμβάνει πρωτοβουλίες
</pre>
</TD>
</TR>
</TABLE>
<?php
if (isset($_POST['pedag'])){
$p=$_POST['att'];
$code=$_POST['code'];
$lsn=$_POST['lsn'];

mysqli_query($con,"DELETE FROM pedanew WHERE code='$code'  ");

$i=1;
while($i<=$crow1){
  $k=$mt[$i];
  $a0=$p[$k][0];$a1=$p[$k][1];$a2=$p[$k][2];$a3=$p[$k][3];
  if (empty($a0)) $a0=0;if (empty($a1)) $a1=0;if (empty($a2)) $a2=0;if (empty($a3)) $a3=0;
  
  $sql="INSERT INTO pedanew (mitroo,sinepia,pitharxia,beltiosi,grade,code) VALUES ('$k','$a0','$a1','$a2','$a3','$code' )";
  if (!mysqli_query($con,$sql)) {die('Error: ' . mysqli_error($con));}
  $i++;
}
$i--;
echo $i." records added";
$sql=mysqli_query($con,"SELECT * FROM pedamaster WHERE id='$code'");
$row=mysqli_fetch_array($sql);
$lsn=$row['tmima']."/".$row['lesson'] ;
echo $lsn;
header("Location:poiotiki1.php?math=".$lsn);	
}

?>
<br />


<input type="button" name="epistrofi" value="Επιστροφή" onClick="window.opener.location.reload(true); window.close();">
</body>
</html>