<?php
function filter($elmnt) 
{
    if ($elmnt != "null" && $elmnt != "" && $elmnt!='---' ) 
	{
        return $elmnt;
    }
}

function genselect($name = '', $options = array(), $default = '') 
{
    $html = '<select name="'.$name.'">';
    foreach ($options as $option => $value) {
        if ($option == $default) {
            $html .= '<option value='.$option.' selected="selected">'.$value.'</option>';
        } else {
            $html .= '<option value='.$option.'>'.$value.'</option>';
        }
    }

    $html .= '</select>';
    return $html;
}

function dispst($mitr)
{
?>
<style type="text/css">
table.mytab { border-collapse:collapse; }
table.mytab td, table.mytab th { border:1px solid black;padding:4px;font-size:14px; }
</style>
<?php
include "dbconnect.php";
echo "<table class='mytab' style='width:500px'  >
<tr style='border:1px solid black;padding:3px;font-size:14px' bgcolor='#81DAF5'  >
<th>ΣΤΟΙΧΕΙΑ ΜΑΘΗΤΗ/ΜΑΘΗΤΡΙΑΣ</th>
<th>ΤΜΗΜΑ</th>
<th>ΒΟΗΘΟΣ ΔΙΕΥΘ.</th>
<th>ΥΠΕΥΘΥΝΟΣ ΚΑΘ.</th>
</tr>";

$sql = mysqli_query($con,"SELECT * FROM allstudentinfo WHERE mitroo='$mitr'  " );
$row = mysqli_fetch_array($sql);
$stname=$row['eponimo']." ".$row['onoma'];
$tmimaid=$row['tmima'];
 echo "<tr>";
 echo "<td>".$stname." (".$row['mitroo'].") </td>";
 echo "<td>".$tmimaid. "</td>";
 $sql = mysqli_query($con,"SELECT v.voi_id,t.Name,v.yt FROM voithos as v,teachers as t WHERE v.Class_id='$tmimaid' AND v.voi_id=t.PMP  " );
 $row = mysqli_fetch_array($sql);
 $vdname=$row['Name'];
 $yt=$row['yt'];
 echo "<td>".$vdname. "</td>";
 $sql = mysqli_query($con,"SELECT Name FROM teachers WHERE PMP='$yt' " );
 $row = mysqli_fetch_array($sql);
 $ytname=$row['Name'];
 echo "<td>".$ytname. "</td>";
 echo "</tr>";
 echo "</table>";
 echo "<br>";	
}

function diagotm($tmima)
{
?><style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:4px;font-size:14px; }
</style>
<?php
include "dbconnect.php";
?><h3> ΔΙΑΓΩΝΙΣΜΑΤΑ ΓΙΑ ΤΟ ΤΜΗΜΑ <?php echo $tmima; ?> </h3>
<?php  
echo "<table class='myTable' >
<tr style='border:1px solid black;padding:4px;font-size:14px' bgcolor='#d6ff73' >
<th>ΗΜΕΡ. ΔΙΑΓΩΝ.</th>
<th>ΗΜΕΡΑ</th>
<th>ΤΜΗΜΑ</th>
<th>ΜΑΘΗΜΑ</th>
<th>ΔΙΑΡΚ.</th>
</tr>";	
$sql1 = mysqli_query($con,"SELECT * FROM declarations WHERE class='$tmima' or class like '".$tmima."%%%' ORDER BY testdate " );
$n=mysqli_num_rows($sql1);
while ($row = mysqli_fetch_array($sql1))
{
     $testdate=$row['testdate'];
	 $subject=$row['subject'];
	 $duration=$row['duration'];
     $datedisp= date('d-m-Y', strtotime($testdate));
	 echo "<tr>"; 
     echo "<td>" . $datedisp. "</td>";
	 $day = date('D', strtotime($testdate));
	 $daymap = array('Κυριακή', 'Δευτέρα', 'Τρίτη', 'Τετάρτη', 'Πέμπτη', 'Παρασκευή', 'Σάββατο');
     $d = $daymap[date('w', strtotime($testdate))];
     echo "<td>" . $d. "</td>";
	 echo "<td>" . $tmima. "</td>";
	 echo "<td>" . $subject. "</td>";
     echo "<td>" . $duration. "</td>";
	echo "</tr>";
	//.............................................
}
echo "</table>";
}
///////////////////// function tmima,ypeythinos,bd /////////////
function tmimaytbd($action)
{
	include "dbconnect.php";
	$sql = "SELECT t.Name,v.Class_id,v.voi_id FROM teachers as t,voithos as v WHERE v.yt=t.PMP ORDER BY v.Class_id ASC";
	$result = mysqli_query($con,$sql);
	$i=0;
	while ($row = mysqli_fetch_array($result)) 
	{
		$i++;
		$tmima[$i]=$row['Class_id'];
		$yt[$i]=$row['Name'];
		$vid=$row['voi_id'];
		$sql1 = "SELECT Name FROM teachers WHERE PMP='$vid'";
		$result1 = mysqli_query($con,$sql1);
		$row1 = mysqli_fetch_array($result1);
		$bd[$i]=$row1['Name'];
	}
	?>

	<?php
	echo "<table class='myTable' >
	<tr style='border:1px solid black' bgcolor='#d6ff73'  >
	<th>ΤΜΗΜΑ</th>
	<th>ΥΠΕΥΘΥΝΟΣ ΚΑΘΗΓΗΤΗΣ</th>
	<th>ΥΠΕΥΘΥΝΟΣ ΒΔ</th>
	</tr>";
	for ($k=1;$k<=$i;$k++)
	{
		echo "<tr>";
		?><td>
		<a href="#" onClick="popupCenter1('<?php echo $action; ?>?tmima=<?php echo $tmima[$k]; ?>')"><?php echo $tmima[$k]; ?></a>
		</td><?php
		echo "<td>". $yt[$k] . "</td>";
		echo "<td>". $bd[$k] . "</td>";
		echo "</tr>";
	}
	echo "</table>";
}
//////////////////////////////////
function getstlessons($mitroo)
{
include "dbconnect.php";
$res1=mysqli_query($con,"SELECT * FROM stutimetable WHERE mitroo='$mitroo'");
$rows1 = mysqli_fetch_array($res1,MYSQLI_NUM); 
$res2=mysqli_query($con,"SELECT * FROM stutimetable WHERE id = (SELECT id+1 FROM stutimetable WHERE mitroo='$mitroo')");
$rows2 = mysqli_fetch_array($res2,MYSQLI_NUM);

$x1=array_slice($rows1, 2);
$x2=array_slice($rows2, 2);

$fr=array_filter($x1,"filter");
$sr=array_filter($x2,"filter");

$i=0;
$tmx=array();
	foreach ($fr as $tm)
	{
		$tmima=trim($tm);
		$sall=explode("/",$sr[$i]);
		$less = trim($sall[1]);
		$teach= trim($sall[2]);
		$tmx[$i]=$tmima."/".$less."/".$teach;
		$i++;
	}
    $tmall=array_unique($tmx);
	
	return $tmall;
}