<?php
include "scrinit.php";
$menu = $_SESSION['menu'];
require "dbconnect.php";

 function rangeWeek($datestr) {
    date_default_timezone_set(date_default_timezone_get());
    $dt = strtotime($datestr);
    $res['start'] = date('N', $dt)==1 ? date('Y-m-d', $dt) : date('Y-m-d', strtotime('last monday', $dt));
    $res['end'] = date('N', $dt)==7 ? date('Y-m-d', $dt) : date('Y-m-d', strtotime('next sunday', $dt));
    return $res;
    }
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(function() {
 $("#arsimperiforas").bind("changepara", function() {
     $.ajax({
         url: "changepara.php",
         data: "arsimperiforas="+$("#arsimperiforas").val(),
         success: function(html) {
             $("#eidostimo").html(html);
         }
     });
 }); 
});

function confirmDelete(delcode) { 
//display confirmation window which returns true or false 
if(!window.confirm("Να προχωρήσει η ακύρωση της διεκπεραίωσης της καταγγελίας?")) return false; 
  
//user clicked 'OK' 
window.location.href="akirosikat.php?id=" + delcode; 
}  
$(function() {
 $("#arsimperiforas").bind("changepara", function() {
     $.ajax({
         url: "changepara.php",
         data: "arsimperiforas="+$("#arsimperiforas").val(),
         success: function(html) {
             $("#eidostimo").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=800, height=200, top='+top+', left='+left);
}

function confirm_update() {
        check=false;
        var aCheckbox = document.getElementById('apoboli').elements;
        for(i=0;i<aCheckbox.length;++i)
        {
            if(aCheckbox[i].type=='checkbox' && aCheckbox[i].checked)
           {
               check=true;
           }
         }
         if(check==true)
         {
             
        }
        else
            {alert("ΠΡΕΠΕΙ ΝΑ ΕΠΙΛΕΞΕΤΕ ΗΜΕΡΑ ΓΙΑ ΤΗΝ ΑΠΟΒΟΛΗ");
            return false;
            }

    }
    </script>
</script>
<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:14px;"></p>
</style>
</head>

<body>

<?php
$nbd=$_SESSION['n'];
$usr=$_SESSION['usr'];
$dt=$_SESSION['dt'];
$gym=$_SESSION['gym'];
$ac=$_SESSION['access'];
$mitroo=$_SESSION['mitr'];
$pini=$_SESSION['pini'];
$aranaforas=$_SESSION['aranaforas'];
echo "xxxx".$mtim;
if ($flag=='argoporia')
{
	
	echo "ddddddddddd";
	$tcode=$mtim;
	$sql = $dbcon->prepare("SELECT * FROM timoria WHERE timoriacode = ? ");
	$sql->execute([$tcode]);
	$row=$sql->fetch(PDO::FETCH_ASSOC);
	$mitroo=$row['stu_id'];
	$pini=$row['peramount'];
	$eidostimo=$row['eidostimo'];
	$aranaforas=$tcode;
	$_SESSION['aranaforas']=$aranaforas;
}
$flag="";
/*$sql = $dbcon->prepare("SELECT timocode FROM apobolientypo WHERE timocode = ? ");
$sql->execute([$aranaforas]);
$row=$sql->fetch(PDO::FETCH_ASSOC);
$count=$sql->rowCount();
if ($count <> 0)
{
	echo "Η ΚΑΤΑΓΓΕΛΙΑ ΈΧΕΙ ΔΙΕΚΠΕΡΑΙΩΘΕΙ - ΠΡΕΠΕΙ ΝΑ ΑΚΥΡΩΣΕΤΕ ΤΗΝ ΔΙΕΚΠΕΡΑΙΩΣΗ";
}
else
{*/
$sql = "SELECT tmima,eponimo,onoma  FROM allstudentinfo WHERE mitroo='$mitroo'";
$result = mysqli_query($con,$sql);
$row = mysqli_fetch_array($result);
$tmima = $row['tmima'];
$nm=$row['eponimo']." ".$row['onoma'];

if ($eidostimo==1)
{
	$dp=floor($pini/$gym);
}
if ($eidostimo==2)
{
	$dp=ceil($pini/$gym);
}

echo  " Ποινή σε περιόδους = ".$pini." ( ".$dp." μέρες )"."<br>";

//ebdomadiaio programma mathiti
$dayf=array(" ","Mon","Tue","Wed","Thu","Fri");
$resultx = mysqli_query($con,"SELECT * FROM stutimetable WHERE mitroo='$mitroo' ");
	$c=mysqli_num_rows($resultx);
	$rowx = mysqli_fetch_array($resultx);
	$id=$rowx['id'];
	$nid=$id+1;
	$res1 = mysqli_query($con,"SELECT * FROM stutimetable WHERE id='$nid'  " ); 
	$rows1 = mysqli_fetch_array($res1); 
	
	for ($x=1;$x<=5;$x++)
	{
		for ($per=1;$per<=$gym;$per++)
		{
			$day1=$dayf[$x].$per;
			$day=$dayf[$x];
			//$math[$x][$per]=$rowx["$day1"];
			$srow= $rows1["$day1"];
			$sall=explode("/",$srow);
			$room =$sall[0];
			$less = $sall[1];
			$teach= $sall[2];
			$rest = mysqli_query($con,"SELECT Name FROM teachers WHERE PMP='$teach'  " ); 
			$rowrest = mysqli_fetch_array($rest);
			$teacher= $rowrest['Name'];
			
			$math1[$x][$per]=$less."/".$teacher;
			//$room1[$x][$per] =$room;
		}
	}

//************************************

$x = strtotime("+1 day", strtotime($dt));
$d = date('w', $x);
if ($d==0)
{
	$x = strtotime("+2 day", strtotime($dt));
	$sd=1; 
}	
else if ($d==6)
{
	$x = strtotime("+3 day", strtotime($dt));	
	$sd=1; 
}
else
{
	$sd=$d;
}	
$xd=$x;//starting date;
$i=1;
while ($i<=10)
{
	$dayar[$i]=date('d-m-Y',$x);
	$x = strtotime("+1 day", $x);
	$d = date('w', $x);
	if ($d==0)
	{
		$x = strtotime("+1 day", $x);
	}	
	else if ($d==6)
	{
		$x = strtotime("+2 day", $x);	
	}
	$i++;
}

$daymap = array('Κυριακή', 'Δευτέρα', 'Τρίτη', 'Τετάρτη', 'Πέμπτη', 'Παρασκευή', 'Σάββατο');
$daytext = $daymap[date('w', strtotime($date))];

//.....................................................	
echo "<table class='myTable' >
<tr style='border:2px solid black;font-size:10px'  >
<tr>
<th>Περ.</th>";
for ($i=1;$i<=10;$i++)
{
   echo "<th>".$daymap[date('w', strtotime($dayar[$i]))]."</td>";
}
echo "</tr>";

echo "<tr>";
echo "<td>"."ΗΜΕΡΟΜ."."</td>";
for ($i=1;$i<=10;$i++)
{
    echo "<td>".$dayar[$i]."</td>";
}
echo "</tr>";
$index=array();
?>
<form  id="apoboli" name="apoboli" method="post" action="apobolieggrafi.php" onsubmit="return confirm_update();">
<tr>
<td></td>
<?php
$nd=10;
for ($i=1;$i<=$nd;$i++)
{
?>

<td>
<input type='checkbox'  name='index[]'  value=<?php echo $i; ?>  onClick='return KeepCount()' > <?php echo ""; ?>
</td>
<?php
}
echo "</tr>";
$j=0;$les=$mth=array();
$start=date('w', strtotime($dayar[1]));
$end=$start+$nd-1;
$_SESSION['dayar']=$dayar;
for ($per=1;$per<=$gym;$per++)
{
	echo "<tr>";
	
	echo "<td>".$per."</td>";
	for ($m=$start;$m<=$end;$m++)
	{
		$k = $m % 5;
		if ($k==0){$k=5;}
		
		$s1=$math1[$k][$per];
		$value1=($k-1)+($per-1)*$nd;  
		$les[$j]=$s1;
		$j++;
		echo "<td>".$s1."</td>";
		  ?>
		<input type='hidden' name='dates[]' value=<?php echo $dayar[$m]; ?> >  
		<input type='hidden' name='mth[]' value=<?php echo $mathima; ?> >
		<input type='hidden' name='pini' value=<?php echo $pini; ?> >
		<input type='hidden' name='mitroo' value=<?php echo $mitroo; ?> >
		<input type='hidden' name='nd' value=<?php echo $nd; ?> >
		<input type='hidden' name='ar' value=<?php echo $aranaforas; ?> >
       </td>
       <?php
	   
	}
	echo "</tr>";
}
echo "</table>";
$_SESSION['xx1']=$les;
?>
<input type='hidden' name='les' value=<?php echo $les; ?> >
<br>
<input type="submit" name= "apoboli1" value='Υποβολή Δελτίου Αποβολής' >

<?php


?>
</body>
</html>