<?php
switch ($access) 
{
case 3:
case 4:
case 5:
$sql = mysqli_query($con,"SELECT kataggelia.*,allstudentinfo.onoma,allstudentinfo.eponimo,allstudentinfo.tmima FROM kataggelia,allstudentinfo WHERE  kataggelia.mitroo=allstudentinfo.mitroo  " );
$c=mysqli_num_rows($sql);

$sql1 = mysqli_query($con,"SELECT timoria.*,allstudentinfo.onoma,allstudentinfo.eponimo,allstudentinfo.tmima  FROM timoria,allstudentinfo  WHERE timoria.stu_id=allstudentinfo.mitroo  " );
$c1=mysqli_num_rows($sql1);
break;

case 2:
$sql = mysqli_query($con,"SELECT kataggelia.*,allstudentinfo.onoma,allstudentinfo.eponimo,allstudentinfo.tmima FROM kataggelia,allstudentinfo WHERE bd='$usr' AND kataggelia.mitroo=allstudentinfo.mitroo  " );
$c=mysqli_num_rows($sql);

$sql1 = mysqli_query($con,"SELECT timoria.*,allstudentinfo.onoma,allstudentinfo.eponimo,allstudentinfo.tmima  FROM timoria,allstudentinfo  WHERE timoria.stu_id=allstudentinfo.mitroo AND vd='$usr' " );
$c1=mysqli_num_rows($sql1);
break;

case 1:
$sql2 = mysqli_query($con,"SELECT  Class_id FROM voithos where yt='$usr' ");
$rw=mysqli_fetch_array($sql2);
$tmima=$rw['Class_id'];
$sql = mysqli_query($con,"SELECT kataggelia.*,allstudentinfo.onoma,allstudentinfo.eponimo,allstudentinfo.tmima FROM kataggelia,allstudentinfo WHERE kataggelia.tmima='$tmima' AND kataggelia.mitroo=allstudentinfo.mitroo  " );
$c=mysqli_num_rows($sql);

$sql1 = mysqli_query($con,"SELECT t.*,a.onoma,a.eponimo,a.tmima  FROM timoria as t,allstudentinfo as a   
        WHERE t.stu_id=a.mitroo AND a.tmima='$tmima' " );
$c1=mysqli_num_rows($sql1);
break;
}

if ($c =0 AND $c1==0)
{ 
      echo " ΔΕΝ ΥΠΑΡΧΟΥΝ ΠΕΙΘΑΡΧΙΚΑ";}
else
{
	mysqli_query($con,'TRUNCATE TABLE timoreport;'); 
	
while ($row=mysqli_fetch_array($sql))
{
$mitroo=$row['mitroo'];
$tmima=$row['tmima'];
$student=$row['eponimo']." ".$row['onoma'];
$anafora= $row['aranaforas'];	
$kataggelon= $row['kataggelon'];
$perigrafi=$row['perigrafi'];
$datetimo = $row['datetimo'];
$timo = $row['periodoi'];
$eidos=$row['eidostimo'];
$sql3 = mysqli_query($con,"SELECT Name FROM teachers  WHERE  PMP='$kataggelon'" );
$row3 = mysqli_fetch_array($sql3);
$apovd = $row3['Name'];

$sqlin = "INSERT INTO timoreport (mitroo,anafora, tmima, datetimo,student,perigrafi,apovd,timo,eidostimo)
VALUES ('$mitroo','$anafora', '$tmima', '$datetimo','$student','$perigrafi','$apovd','$timo','$eidos')";

    if (!mysqli_query($con, $sqlin)) {
       echo "Error: " . $sqlin . "<br>" . mysqli_error($con);}
}


while ($row=mysqli_fetch_array($sql1)){
	$tmima=$row['tmima'];
	$mitroo=$row['stu_id'];
	$student=$row['eponimo']." ".$row['onoma'];
	$datetimo=$row['dateappl'];
	$anafora=" ";
	$apovd=" ";
	$timo=$row['peramount'];
	$eidos=$row['eidostimo'];
	$perigrafi="Συχνή καθυστέρηση και παρενόχληση μαθήματος";
	$sqlin = "INSERT INTO timoreport (mitroo,anafora, tmima, datetimo,student,perigrafi,apovd,timo,eidostimo)
VALUES ('$mitroo','$anafora', '$tmima', '$datetimo','$student','$perigrafi','$apovd','$timo','$eidos')";

    if (!mysqli_query($con, $sqlin)) {
       echo "Error: " . $sqlin . "<br>" . mysqli_error($con);}
}
}