<?php
include "scrinit.php";
include "logo.php";
date_default_timezone_set("Europe/Athens");
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:14px; }
<p style="font-size:11px;"></p>
</style>
</head>
<body>
<br > <br >
<h3>ΑΔΕΙΑ ΕΙΣΟΔΟΥ ΣΤΗΝ ΤΑΞΗ</h3>

<?php 
require("dbconnect.php");
$usr=$_SESSION['usr'];
$name=$_SESSION['n'];
$gym=$_SESSION['gym'];
$dt=date('Y-m-d');
$daymap = array('Κυριακή', 'Δευτέρα', 'Τρίτη', 'Τετάρτη', 'Πέμπτη', 'Παρασκευή', 'Σάββατο');
$datedisp= date('d-m-Y', strtotime($dt)); 
$day = date('D', strtotime($dt));
$d = $daymap[date('w', strtotime($dt))];
if (isset($_POST['subargo'])) 
{

	$mitr=$_POST['nameid'];
	echo "<table style='width:500px' class='myTable' >
	<tr style='border:1px solid black' 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. "</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>";
	
	if (empty($mitr))
	{
		echo '<script type="text/javascript">';
	    echo 'alert("ΔΕΝ ΕΧΕΤΕ ΕΠΙΛΕΞΕΙ ΜΑΘΗΤΗ ΓΙΑ ΤΗΝ ΑΔΕΙΑ")';
	    echo '</script>';	
	    $time = 1; //Time (in seconds) to wait. 
	    $url = "argoporia.php"; //Location to send to. 
	    header("Refresh: $time; url=$url");	
	}
//***********************
	$sql = mysqli_query($con,"SELECT * FROM argoporia WHERE mitroo='$mitr' " );
	if (mysqli_num_rows($sql) > 0)
	{	
		echo " ΠΡΟΗΓΟΥΜΕΝΕΣ ΑΡΓΟΠΟΡΙΕΣ"."<br>";	
		echo "<table class='myTable' >
		<tr style='border:1px solid black;font-size:9px'  >
		<tr>
		<th>Αρ.</th>
		<th>Ημερομ.</th>
		<th>Βοηθός Διευθ.</th>
		<th>Περίοδος</th>
		<th>Λεπτά</th>
		<th>Λόγος</th>
		</tr>";	


		$i=1;
		while ($row = mysqli_fetch_array($sql))
		{
			
			  $date=$row['date'];
			  $lepta=$row['lepta'];
			  $per=$row['period'];
			  $vd=$row['bd']; 
			  $logos=$row['logos'];
			  
			  echo "<tr>";
			  echo "<td>" . $i. "</td>";
			  echo "<td>". $date . "</td>";
			  echo "<td>". $vd . "</td>";
			  echo "<td>". $per . "</td>";
			  echo "<td>". $lepta . "</td>";
			  echo "<td>". $logos. "</td>";
			  $i++;
			  echo "</tr>";
		}
		echo "</table>";
	}
 
//*************************************  
	$lepta=$_POST['arg'];
	$per=$_POST['ora'];
	$logos=$_POST['reason'];
	$log1=$_POST['allos'];
	if ($logos=='') $logos=$log1;
	echo "<br>"."<br>";
	echo "ΣΗΜΕΡΙΝΗ ΑΡΓΟΠΟΡΙΑ";
	$sql="insert into argoporia (mitroo,date,period,lepta,logos,bd) values ('$mitr','$dt','$per','$lepta','$logos','$usr') ";
	if (!mysqli_query($con, $sql)) 
		{
            echo "Error: " . $sql . "<br>" . mysqli_error($con);
		}

echo "<table class='myTable' >
<tr style='border:1px solid black;font-size:12px'  >
<tr>
<th>ΗΜΕΡΟΜΗΝΙΑ</th><th>ΠΕΡΙΟΔΟΣ</th><th>ΛΕΠΤΑ</th>
</tr>";
echo "<tr>";	
echo "<td>".$d." , ".$datedisp."</td>";
echo "<td>".str_repeat('&nbsp;',7).$per."</td>";
echo "<td>".str_repeat('&nbsp;',3).$lepta."</td>";
echo "</tr>";
echo "</table>";
echo "<br>";
//**************************************************
echo "<br>";echo "<br>";
echo "O Bοηθός Διευθυντής "."<br>"."<br>"."<br>";
echo "............................"."<br>";
echo $name."<br>"."<br>"."<br>";
echo "-----------------------------------------------------------------------------------------------";
	
  
}

?>
<br ><br ><br >
<button onClick="window.print()">Εκτύπωση Άδειας</button>&nbsp;&nbsp;&nbsp
<a  href=<?php echo $menu;?>  style="color:blue "  > <button> Επιστροφή στο Μενού  </a>
</body>
</html>