<?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:11px; }
<p style="font-size:11px;"></p>
</style>

</script>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(function() {
 $("#tmimaid").bind("change", function() {
     $.ajax({
         url: "change3.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=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=800,directories=no,location=no') 
}

</script>

</head>
<body>
<br > <br >
<h3>ΚΑΤΑΧΩΡΗΣΗ ΠΡΩΙΝΗΣ ΑΡΓΟΠΟΡΙΑΣ</h3>

<?php 
date_default_timezone_set("Europe/Athens");
require("dbconnect.php");
$usr=$_SESSION['usr'];
$gym=$_SESSION['gym'];
$dt=date('Y-m-d');
 
$sql2 = mysqli_query($con,"SELECT DISTINCT tmima FROM allstudentinfo order by tmima ASC ");

$daymap = array('Κυριακή', 'Δευτέρα', 'Τρίτη', 'Τετάρτη', 'Πέμπτη', 'Παρασκευή', 'Σάββατο');
$datedisp= date('d-m-Y', strtotime($dt)); 
$day = date('D', strtotime($dt));
$d = $daymap[date('w', strtotime($dt))];
$time=date("H:i:s");
echo "ΗΜΕΡΟΜΗΝΙΑ : "."<b>".$d. " , ".$datedisp.str_repeat('&nbsp;',5).", ΩΡΑ: ".$time."</b>"."<br>";


?>
<br ><br >  
 
<form method='post' action='printargo.php'>
<fieldset style="width:1000px; ">
<legend><b> ΣΤΟΙΧΕΙΑ ΑΡΓΟΠΟΡΙΑΣ ΜΑΘΗΤΗ/ΤΡΙΑΣ </b></legend>
<?php
include "selectst.php";
?>
<br><br>
 ΑΡΓΟΠΟΡΙΑ ΣΕ ΛΕΠΤΑ:<input type="text" name="arg" value='<?php echo $arg;?>'  size='3' required>&nbsp;&nbsp;&nbsp
 ΑΙΤΙΟΛΟΓΗΣΗ:<select name='reason'>
<?php
$sql3=mysqli_query($con,"SELECT * FROM reasons where code=2");
echo "<option value=''>"."Άλλος Λόγος"."</option>";
while ($row3 = mysqli_fetch_array($sql3)) 
{
	$reason = $row3['reason'];
	echo "<option value ='".$reason."'>".$reason."</option>";
}
echo "</select>"; 
?>
<br ><br >
ΑΛΛΟΣ ΛΟΓΟΣ: <input type="text" name="allos" value='<?php echo $allos;?>' size='60'>
<br><br>
<input type="submit" name="subargo" value="Καταχώρηση Αργοπορίας" > 
</fieldset>
</form>
<?php
if (isset($_POST['subargo'])) 
{

	$mitr=$_POST['nameid'];
	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;
	
	
	$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);
	}
	else
	{
		//sms gia argoporia
		$t=time();
		$dy = date('D', strtotime($dt));
		if ( ($t >= strtotime('07:30') and $t < strtotime('13:30')) and (($dy <>"Sat" or $dy <> "Sun")) ) 
		{
				$sqs=$dbcon->prepare("select mitroo from smsdb where mitroo=? and date=? ");
				$sqs->execute([$mitr,$dt]);
				if ($sqs->rowCount()==0)
				 {
					 
				 $sqs=$dbcon->prepare("insert into smsdb (mitroo,date) values (?,?)");
				 $sqs->execute([$mitr,$dt]);
				 $sqt=$dbcon->prepare("select kinito,onoma from allstudentinfo where mitroo=?");
				 $sqt->execute([$mitr]);
				 $rowt=$sqt->fetch(PDO::FETCH_ASSOC);
				 $tele=array($rowt['kinito']);
				 $name=$rowt['onoma'];
				 $mess="ΤΟ ΠΑΙΔΙ ΣΑΣ ".$name." ΚΑΘΥΣΤΕΡΗΣΕ ".$lepta." ΛΕΠΤΑ ΤΗΝ ".$per." περ. ΠΑΡΑΚΑΛΟΥΜΕ ΓΙΑ ΤΗ ΣΥΝΕΡΓΑΣΙΑ ΣΑΣ";
				 $_SESSION['tel']=$tele;
				 $_SESSION['sms1']=$mess;
				 include "sendsmskath.php";
				 }
				//............................
			  
		 }
		
		
		//***************************
	}
	
echo "<br>"."<br>";
echo " ΑΔΕΙΑ ΕΙΣΟΔΟΥ ΣΤΗΝ ΤΑΞΗ ";
echo "<table class='myTable' >
<tr style='border:1px solid black;font-size:12px'  >
<tr>
<th>ΗΜΕΡΟΜΗΝΙΑ</th><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 "<td>".str_repeat('&nbsp;',3).$vd."</td>";
echo "</tr>";
echo "</table>";
echo "<br>";
//**************************************************
echo "<br>";echo "<br>";
echo "O Bοηθός Διευθυντής "."<br>"."<br>"."<br>";
echo "............................"."<br>";
echo $namevd."<br>"."<br>"."<br>";
echo "-----------------------------------------------------------------------------------------------";
	
  
}

?>
<br ><br ><br >

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