<?php
session_start();
ob_start();
if ($_SESSION['islogin']=='' ) { 
  echo "ΠΡΕΠΕΙ ΝΑ ΕΓΓΡΑΦΕΙΤΕ ΓΙΑ ΝΑ ΧΡΗΣΙΜΟΠΟΙΗΣΕΤΕ ΤΟ ΣΥΣΤΗΜΑ"."<BR>";
  sleep(3);
  header("Location: loginall.php"); /* Redirect browser */
  exit();
  }
$menu = $_SESSION['menu'];
include $menu;
?><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:5px;font-size:11px; }
<p style="font-size:09px;"></p>
</style>

<h4>ΑΝΑΦΟΡΑ ΠΑΡΑΠΤΩΜΑΤΩΝ/ΤΙΜΩΡΙΩΝ</h4>
<?php
require "dbconnect.php";
$usr=$_SESSION['usr'];
$access=$_SESSION['access'];
$fl=1;
switch ($access) 
{
  case 1 :
  $sql2 = mysqli_query($con,"SELECT  Class_id FROM voithos where yt='$usr' ");
  if( mysqli_num_rows($sql2) == 0)
  {$fl=0;}
  break;
  case 2 :
  $sql2 = mysqli_query($con,"SELECT  Class_id FROM voithos where voi_id='$usr' ");
  break;
  case 3 :
  case 4 :
  case 8 :
  $sql2 = mysqli_query($con,"SELECT  Class_id FROM voithos ORDER BY Class_id ");
  break;
  default:
  echo "Μη εξουσιοδοτημένος χρήστης";
  break;
	  
}

if ($fl==0)
{
	echo "Μη εξουσιοδοτημένος χρήστης";	
}
else
{
    ?>
    
    <form  method='post'>
    
    <label>Τμήμα:</label><select name='tmimaid' id='tmimaid'>
     
      <?php
	//echo "<option value='---'>select</option>";
    while($row2 = mysqli_fetch_array($sql2) ) {
          echo "<option value='$row2[Class_id]'>$row2[Class_id]</option>";
      }
      ?>
     </select>
  

<input type="submit" name="submit" value="Επέλεξε Τμήμα" >
    
    </form>
<?php
If (isset($_POST['tmimaid'])){
	$tmima=$_POST['tmimaid'];

$sqltv=mysqli_query($con,"SELECT t.Name,v.voi_id FROM voithos as v,teachers as t 
         WHERE v.Class_id='$tmima' AND t.PMP=v.voi_id");	
$rowv=mysqli_fetch_array($sqltv);
$usr=$rowv['voi_id'];
$vdname=$rowv['Name'];  

$sqlt=mysqli_query($con,"SELECT * FROM allstudentinfo  WHERE tmima='$tmima' ");		  
$sql = mysqli_query($con,"SELECT k.*,a.tmima FROM kataggelia as k,allstudentinfo as a WHERE k.bd='$usr' AND k.mitroo=a.mitroo AND a.tmima='$tmima' AND k.datetimo >'0000-00-00' " );
$c=mysqli_num_rows($sql);

$sql1 = mysqli_query($con,"SELECT t.*,a.tmima  FROM timoria as t,allstudentinfo as a  WHERE t.stu_id=a.mitroo AND t.vd='$usr' AND a.tmima='$tmima' AND t.dateappl >'0000-00-00'" );
$c1=mysqli_num_rows($sql1);

if ($c =0 AND $c1==0){ 
      echo " ΔΕΝ ΥΠΑΡΧΟΥΝ ΠΕΙΘΑΡΧΙΚΑ";}
else
{
	mysqli_query($con,'TRUNCATE TABLE timoreport;'); 
	
while ($row=mysqli_fetch_array($sql)){
$mitroo=$row['mitroo'];
$anafora= $row['aranaforas'];	
$datetimo = $row['datetimo'];
$timo = $row['periodoi'];


$sqlin = "INSERT INTO timoreport (mitroo,anafora,datetimo,timo)
VALUES ('$mitroo','$anafora','$datetimo','$timo')";

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


while ($row=mysqli_fetch_array($sql1)){
	$mitroo=$row['stu_id'];
	$datetimo=$row['dateappl'];
	$anafora=" ";
	
	$timo=$row['peramount'];
	
	$sqlin = "INSERT INTO timoreport (mitroo,anafora,datetimo,timo)
VALUES ('$mitroo','$anafora', '$datetimo','$timo')";

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

//////////////////////////


echo "<br>"."ΚΑΤΑΛΟΓΟΣ ΓΙΑ ΤΟ ΤΜΗΜΑ : ".$tmima."<br>";
echo "<br>"."ΒΟΗΘΟΣ : ".$vdname."<br>"."<br>";
echo "<table class='myTable' >
<tr style='border:1px solid black;font-size:9px' bgcolor='#ffcc00'  >
<th>Α/A</th>
<th>ΜΗΤΡΏΟ</th>
<th>ΟΝΟΜΑ</th>
<th>ΠΑΡ1</th>
<th>ΠΑΡ2</th>
<th>ΠΑΡ3</th>
<th>ΠΑΡ4</th>
<th>ΠΑΡ5</th>
<th>ΠΑΡ6</th>
<th>ΠΑΡ7</th>
<th>ΠΑΡ8</th>
<th>ΠΑΡ9</th>
<th>ΠΑΡ10</th>
<th>ΠΑΡ11</th>
<th>ΠΑΡ12</th>
<th>ΣΥΝ.</th>
</tr>";	

$i=1;
while ($rowt = mysqli_fetch_array($sqlt)){
$student=$rowt['eponimo']." ".$rowt['onoma'];
$mitroo= $rowt['mitroo'];	

echo "<tr>";
echo "<td>" .$i. "</td>";
echo "<td>". $mitroo. "</td>";
echo "<td>". $student . "</td>";
$sql=mysqli_query($con,"SELECT * FROM timoreport WHERE mitroo='$mitroo' ORDER BY datetimo " );
$c=mysqli_num_rows($sql);
if ($c > 0)
{
	$tim=array();$timoria=array();
	$j=1;
	while ($row = mysqli_fetch_array($sql))
	{
	  $newd = date("d-m", strtotime($row['datetimo']));
	  $timoria[$j]=$row['timo'];
	  $tim[$j]=$newd."/".$timoria[$j];
	  $j++;
	}
    $sum=0;
     for ($k=1;$k<=12;$k++)
    {
		echo "<td>". $tim[$k] . "</td>";
        $sum=$sum+$timoria[$k];
    }
    echo "<td>". $sum . "</td>";
	}
else
{
	for ($k=1;$k<=13;$k++)
    {
		echo "<td>". " " . "</td>";
		}	
}
echo "</tr>"; 

$i++;

}

echo "</table>";
//............
echo "<br>";



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