<?php
include "scrinit.php";
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:2px;font-size:11pt; }
<p style="font-size:11px;"></p>
</style>

</script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(function() {
 $("#tmimaid").bind("change", function() {
     $.ajax({
         url: "change.php",
         data: "tmimaid="+$("#tmimaid").val(),
         success: function(html) {
             $("#nameid").html(html);
         }
     });
 }); 
});

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=900, height=300, top='+top+', left='+left);
}
</script>




</head>
<body>
<h3> ΑΝΑΦΟΡΕΣ</h3>

<?php 

require("dbconnect.php");
$dt=$_SESSION['dt'];

?>
	
<form method="post" name = "form1">
ΗΜΕΡΟΜΗΝΙΑ: <input type="date"  name = 'dt' value= <?php echo $dt; ?> > 
<br />
ΕΠΙΛΟΓΗ ΑΝΑΦΟΡΑΣ:
<br />
  <select name="anaf" size="4"  >
  <option value=1>Εμφάνιση  Απουσιών  ημέρας</option> 
  <option value=2>Εμφάνιση  Απουσιών  κατα μαθητή</option>
  <option value=3>Εμφάνιση  Απουσιών  κατα καθηγητη/μάθημα</option>
  <option value=4>Εμφάνιση  Απουσιών  ημέρας detailed</option>
  </select>
  <br />
  <input type="submit" name="submit1" value="Επιβεβαίωση Επιλογής" >
</form>

<?php


if(isset($_POST['anaf']))
{

$dt=$_POST['dt'];
$_SESSION['dt']=$dt;
$anaf=$_POST['anaf'];

if ($anaf==1) {
$sql = mysqli_query($con,"SELECT apousies.dateout, apousies.mitroo, apousies.period,al.tmima,al.eponimo,al.onoma FROM apousies,allstudentinfo as al 
WHERE apousies.apousia=1 AND apousies.dateout='$dt' AND apousies.mitroo=al.mitroo 
ORDER BY al.tmima,apousies.dateout,apousies.mitroo,apousies.period " );
echo "Για εντοπισμό μαθητή/τριας να κάνετε κλικ στην αντίστοιχη περίοδο";	

echo "<table class='myTable' >
<tr style='border:1px solid black' >
<tr>
<th>Α/Α</th>
<th>Α.Μητρ</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>
</tr>";

$row = mysqli_fetch_array($sql);
$cc=1;
while(!empty($row)) {
	$j=1;
    while($j<=7){$per1[$j]="";$j++;}
	  $pmp=$row['mitroo'];
	  $tmima=$row['tmima'];
	  $eponimo=$row['eponimo'];
	  $onoma=$row['onoma'];
	  echo "<td>". $cc . "</td>";
	  echo "<td>". $pmp . "</td>";
	  echo "<td>". $tmima . "</td>";
	  echo "<td>". $eponimo."  ".$onoma . "</td>";
	  while ($pmp==$row['mitroo']){
	     $per1[$row['period']]=$row['period'].$pmp;
	     $row = mysqli_fetch_array($sql);
      }

     $i=1;    
     while($i<=7){
		 if (empty($per1[$i])){ $per2[$i]="  ";} else { $per2[$i]=" xxxx ";}
		 ?>
		 <td>
   <a href="#" onClick="popupCenter('locate2.php?per=<?php echo $per1[$i]; ?>')"><?php echo $per2[$i]; ?></a>
   </td>
<?php
		 //echo "<td>" . "<a href=\"locate2.php."\">".$per1[$i]. "</a>". "</td>";
		 
		 $i++;}
     echo "</tr>";
	 $cc++;
   
}
echo "</table>";	 
}

if ($anaf==2)
{
	?>
	<br><h4> ΕΠΙΛΟΓΗ ΤΜΗΜΑΤΟΣ ΚΑΙ ΜΑΘΗΤΗ/ΤΡΙΑΣ</h4> 
     <?php
    $sql2 = mysqli_query($con,"SELECT DISTINCT tmima FROM allstudentinfo ");
    ?>
    <form action='epmath1.php' 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[tmima]'>$row2[tmima]</option>";
      }
      ?>
     </select>
  

<label> Μαθητής/τρια:</label>

      <select name='nameid' id='nameid' value= ></select>

<input type="submit" name="submit1" value="Επιβεβαίωση Επιλογής" >
    </form>
<?php

}

if ($anaf==3)
{

include "allday.php";
}


//..................................................  .................     4
if ($anaf==4)
{
$dt=$_POST['dt'];
$_SESSION['dt']=$dt;

$sqlz = mysqli_query($con,"SELECT apousies.dateout, apousies.mitroo, apousies.period, apousies.mathima,
 al.tmima,al.eponimo,al.onoma FROM apousies,allstudentinfo as al WHERE apousies.apousia=1 
 AND apousies.dateout='$dt' AND apousies.mitroo=al.mitroo ORDER BY apousies.dateout,al.tmima,apousies.mitroo,apousies.period " );

echo "<br>";
echo "<table class='myTable' >
<tr style='border:1px solid black' >
<tr>
<th>A/A</th>
<th>Α.Μητρ</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>
</tr>";
$dd=date('D', strtotime($dt));
$row = mysqli_fetch_array($sqlz);
$plithos=1;
while(!empty($row)) {
	  $mathima=array();$ekd=array();$teacher1=array();$subject=array();$room1=array();$kath=array();
	  $mitroo=$row['mitroo'];
	  $tmima=$row['tmima']; 
	  $eponimo=$row['eponimo'];
	  $onoma=$row['onoma'];
	 
	  $cper=1;
	  while ($mitroo == $row['mitroo']){
		 $mathima[$row['period']]=$row['mathima'];
		 $kath[$row['period']]=$row['teacher'];
		 $row = mysqli_fetch_array($sqlz);
		 $cper++;
	  }
	  $cper--;
	  //////////////
	  if ($cper < 7) 
	  {
	  echo "<td>". $plithos . "</td>";
	  echo "<td>". $mitroo . "</td>";
	  echo "<td>". $tmima . "</td>";
	  echo "<td>". $eponimo."  ".$onoma . "</td>";
	  $plithos++;  
	   $sqls = mysqli_query($con,"SELECT e.*,ek.onoma FROM ekdilosistu as e,ekdilosi as ek WHERE e.pmp='$mitroo' AND e.code=ek.code  AND ek.date='$dt' ");
	   $numsqls=mysqli_num_rows($sqls);
	   $rows = mysqli_fetch_array($sqls);
	   $ekname=" ";
	   if($numsqls > 0) {
	      $ekname=$rows['onoma'];
	      if($ekname=="ΑΔΕΙΑ ΕΞΟΔΟΥ") {$ae="**ΑΔ**";} else {$ae="**ΕΚΔ**";}
	   }
	  ////////////////////////
for ($i=1;$i<=7;$i++){
	 $day =$dd.$i;
	 
	 require ("mathitisprog.php");
	 
	 $teacher1[$i]=$name;
	 $arr = explode("/", $room);
	 $subject[$i]=$mathimax;
     $room1[$i] = $arr[1];
	 $oldname=$name; 
	 
 }//for

	for ($j=1;$j<=7;$j++){
		$ds=$teacher1[$j]."/".$room1[$j];
		
		  if($numsqls > 0) {
			 $p="p".$j; 
		     if ($rows["$p"]==1) {$ds=$ds.$ae;} } 
		  if (($mathima[$j] == $subject[$j]) OR !empty($mathima[$j])) { echo "<td bgcolor='#CCFFFF'>"."<b>".$ds."</b>"."</td>";} 
		else { echo "<td>". $ds . "</td>";   }
	}

     echo "</tr>";
	  }
     }
echo "</table>";	 
//..............	
}// end while
}//if anaf = 4

?>

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