<?php
include "scrinit.php";
include $menu;
?><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</script>
<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, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=800, height=800, top='+top+', left='+left);
document.forms["carservice"].submit();	
}

function submitform()
{
    document.forms["carservice"].submit();
}

function pop_up(url){
window.open(url,'win2','status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=800,height=900,directories=no,location=no') 
}

</script>

<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:11px; }
<p style="font-size:09px;"></p>
</style>

<?php
require "dbconnect.php";
$usr=$_SESSION['usr'];
$dt=$_SESSION['dt'];
$t=date('H:i:s');

if (isset($_POST['nameid'])) {$mitr=$_POST['nameid'];}
else
{
   echo '<script type="text/javascript">';
   echo 'alert("ΔΕΝ ΕΧΕΤΕ ΕΠΙΛΕΞΕΙ ΜΑΘΗΤΗ ΓΙΑ ΤΗΝ ΑΔΕΙΑ")';
   echo '</script>';	
   $time = 1; //Time (in seconds) to wait. 
   $url = "adeiaeksodou.php"; //Location to send to. 
   header("Refresh: $time; url=$url");	
}
if (isset($_POST['submit1']))
{
	$papo=$_POST['ora'];
    $voithos=$_POST['voithos'];
	$reasonf=$_POST['reason'];
	$mitr=$_POST['nameid'];
	}
	
$sql = mysqli_query($con,"SELECT eponimo,onoma,tmima,kinito,pateras,mitera,kmiteras,kpatera,stathero FROM allstudentinfo WHERE mitroo='$mitr'  " );
$row = mysqli_fetch_array($sql);
$stname=$row['eponimo']." ".$row['onoma'];
$tmimaid=$row['tmima'];
$kinito=$row['kinito'];
$kpatera=$row['kpatera'];
$stathero=$row['stathero'];
$kmiteras=$row['kmiteras'];
$mitera=$row['mitera'];
$pateras=$row['pateras'];

$sqlx=mysqli_query($con,"SELECT Name  FROM teachers WHERE  PMP='$voithos' " );
$row = mysqli_fetch_array($sqlx);
$vdname=$row['Name'];

$sql = mysqli_query($con,"SELECT code FROM ekdilosistu WHERE pmp='$mitr' " );
$row = mysqli_fetch_array($sql);
$code=$row['code'];
if (!$sql) {die('Error: ' . mysqli_error($con));   }

$sql1 = "SELECT * FROM ekdilosi WHERE code='$code' AND onoma='ΑΔΕΙΑ ΕΞΟΔΟΥ' " ;
if (!mysqli_query($con,$sql1)) {die('Error: ' . mysqli_error($con));   }
$res=mysqli_query($con,$sql1);
$c=mysqli_num_rows($res);


if ($c>0){
	
echo " ΑΔΕΙΕΣ ΕΞΟΔΟΥ ΓΙΑ ". " "."<b>".$stname."</b>"." "." του τμήματος ".$tmimaid."<br>"."<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>
</tr>";	

$sql = mysqli_query($con,"SELECT code FROM ekdilosistu WHERE pmp='$mitr' " );
$i=1;
while ($row = mysqli_fetch_array($sql))
{
$code=$row['code'];
$tmima=$row['tmima'];
$sql1 =mysqli_query($con,"SELECT * FROM ekdilosi WHERE code='$code' AND onoma='ΑΔΕΙΑ ΕΞΟΔΟΥ' ") ;


   while ($row1 = mysqli_fetch_array($sql1))
     {
	  $date=$row1['date'];
	  $perapo=$row1['perapo'];
	  $permexri=$row1['permexri'];
	  $vd=$row1['teacher']; 
	  $reason=$row1['reason'];
	  echo "<tr>";
      echo "<td>" . $i. "</td>";
      echo "<td>". $date . "</td>";
      echo "<td>". $reason . "</td>";
      echo "<td>". $vd . "</td>";
      echo "<td>". $perapo . "</td>";
	  $i++;
	 }
echo "</tr>";
}
 
echo "</table>";
}
//check for diagonismata/////////////////////////////////////////////////////////
echo "<br>";
$in=0;
$dt1=date('Y-m-d',strtotime($dt));
$tdia=mysqli_query($con,"SELECT * FROM declarations WHERE testdate='$dt1'");
If (mysqli_num_rows($tdia) > 0)
{
$in=0;
while ($trow=mysqli_fetch_array($tdia))
{
	$class=$trow['class'];$fr=$trow['perapo'];$subj=$trow['subject'];
	$tdia1=mysqli_query($con,"SELECT s.mitroo FROM syndidaskalies as s,syndcodes as sc WHERE sc.synd='$class' and s.syndid=sc.syndid and s.mitroo='$mitr'");
    If (mysqli_num_rows($tdia1) > 0)
	{
		$in=1;
		$subjf=$subj;$frf=$fr;
    }
    else
    {		
	   $tdia2=mysqli_query($con,"SELECT mitroo FROM allstudentinfo WHERE tmima='$class' and mitroo='$mitr'");
	   If (mysqli_num_rows($tdia2) > 0){$in=1;$subjf=$subj;$frf=$fr;} 
	}
}
}
if ($in==1)	
{
echo "<font face='arial' size='4pt' color='#ff0000'>Ο μαθητής/τρια έχει διαγώνισμα ".$subjf." την ".$frf." περίοδο</font>";
}
else 
{
	echo "<font face='arial' size='4pt' color='#ff0000'>Ο μαθητής/τρια ΔΕΝ έχει διαγώνισμα </font>";
}	

?>
<br /><br />
<h3> ΣΤΟΙΧΕΙΑ ΓΙΑ ΕΚΔΟΣΗ ΑΔΕΙΑΣ</h3>
ΒΟΗΘΟΣ:<input type='text'  name='bd' value="<?php echo $vdname; ?>" /> <br /><br />

<form name = "form1" action="printadeia.php" method="post" target="DoSubmit" onSubmit="DoSubmit = window.open('about:blank','DoSubmit','width=800,height=1000');">

<fieldset style="width: 950px; ">

HMEROMHNIA :<input type='text'   name='dat' value="<?php echo $dt; ?>" size=12  />
&nbsp;&nbsp;&nbspΠΕΡΙΟΔΟΣ :<input type='text'   name='perapo' value="<?php echo $papo; ?>" size=12  />
&nbsp;&nbsp;&nbspΩΡΑ :<input type='text'   name='tm' value="<?php echo $t; ?>" size=12  />
<br /><br />

ΑΡ. ΜΗΤΡΩΟΥ:<input type='text'  name= 'mitroo' value="<?php echo $mitr; ?>" size=8 /> 
ΤΝΗΜΑ :<input type='text'  name='tmimaid' value="<?php echo $tmimaid; ?>" size=6  />
ΟΝΟΜΑ ΜΑΘΗΤΗ :<input type='text'  name='stname' value="<?php echo $stname; ?>" size=50  /><br /><br />

ΛΟΓΟΣ ΓΙΑ ΑΔΕΙΑ:<textarea name="reason" rows="2" cols="60"><?php echo $reasonf;?></textarea><br /><br />

ΕΠΙΚΟΙΝΩΝΙΑ ΜΕ : <select name="kidemonas">
<option value="Μητέρα" >Μητέρα</option>
<option value="Πατέρας">Πατέρας</option>
<option value="Παππούς/Γιαγιά">Παππούς/Γιαγιά</option>
<option value="Αδελφός/Αδελφή">Αδελφός/Αδελφή</option>
<option value="Θεία/Θείος">Θεία/Θείος</option>
</select>

ΤΗΛΕΦΩΝΟ ΕΠΙΚΟΙΝΩΝΙΑΣ:<input type='text'  name='tel' size=12  />

ΠΑΡΑΛΑΒΗ ΑΠΟ : <select name="paralavi">
<option value="Μητέρα" >Μητέρα</option>
<option value="Πατέρας">Πατέρας</option>
<option value="Παππούς/Γιαγιά">Παππούς/Γιαγιά</option>
<option value="Αδελφός/Αδελφή">Αδελφός/Αδελφή</option>
<option value="Θεία/Θείος">Θεία/Θείος</option>
</select>
<br /><br />
<b>ΚΑΤΑΧΩΡΗΜΕΝΑ ΤΗΛΕΦΩΝΑ:</b>
<?php 
//echo "<br>"." Σταθερό τηλ:".$stathero."<br>";
echo "<br>";
echo "Πατέρας : ".$pateras. "  τηλ: ".$kpatera. "<br>";
echo "Μητέρα : ".$mitera. "  τηλ: ".$kmiteras."<br>";
?>
<input type='text'  name='voithos' HIDDEN value="<?php echo $voithos; ?>" />
<input type='text'  name='mitr' HIDDEN value="<?php echo $mitr; ?>" />
<input type='text'  name='tmimaid' HIDDEN value="<?php echo $tmimaid; ?>" />
<br><br>
<input type="submit" name="submit2" value="Ετοιμασία Άδειας για Εκτύπωση" > 

</fieldset>
</form>
<?php
//<input type=button name="submit2" onClick=pop_up("printadeia.php") value="Εκτύπωση Άδειας">
 ?>
<br><br> 
<input type="button" style="color:blue " onClick="document.location.href='adeiaeksodou.php'" value="Επόμενη Άδεια" />
<?php echo "&nbsp&nbsp&nbsp";?> 
<a  href=<?php echo $menu;?> style="color:blue "  > <button>Επιστροφή στο Μενού</button></a> 

</body>
</html>