<?php
require "dbconnect.php";
$sqlren = $dbcon->prepare("SELECT * FROM parameters " );
$sqlren->execute();
	$rowren=$sqlren->fetch(PDO::FETCH_ASSOC);
	$atetrs=$rowren['atetrs'];
	$atetre=$rowren['atetre'];
	$btetrs=$rowren['btetrs'];
	$btetre=$rowren['btetre'];
	$year = date('Y', strtotime($dt));
    $day = date('d', strtotime($dt));
	$month = date('m', strtotime($dt));

	$result  = $dbcon->prepare("SHOW TABLES LIKE 'timetablea'");
	$result->execute();
        $tableyes = $result !== false && $result->rowCount() > 0;
		echo $tableyes;
	if ( $dt >= $atetrs and $dt <= $atetre ) 
	{
		$tetramino = 'Α';
		
		if($tableyes)
		{
		$oldn="timetable";
		$newn="timetableb";
		mysqli_query($con,"RENAME TABLE `" . $oldn . "` TO `" . $newn . "`");
		$oldn="timetablea";
		$newn="timetable";
		mysqli_query($con,"RENAME TABLE `" . $oldn . "` TO `" . $newn . "`");
		}
	} 
	elseif ( $dt >= $btetrs and $dt <= $btetre ) 
	{
		$tetramino = 'Β';
		
		if(!$tableyes)
		{
		$oldn="timetable";
		$newn="timetablea";
		mysqli_query($con,"RENAME TABLE `" . $oldn . "` TO `" . $newn . "`");
		$oldn="timetableb";
		$newn="timetable";
		mysqli_query($con,"RENAME TABLE `" . $oldn . "` TO `" . $newn . "`");
		}
	}
	else
		$tetramino = '**';
	
	$result  = $dbcon->prepare("SHOW TABLES LIKE 'stutimetabla'");
	$result->execute();
        $tableyes = $result !== false && $result->rowCount() > 0;
		echo $tableyes;
	if ( $dt >= $atetrs and $dt <= $atetre ) 
	{
		$tetramino = 'Α';
		
		if($tableyes)
		{
		$oldn="stutimetable";
		$newn="stutimetableb";
		mysqli_query($con,"RENAME TABLE `" . $oldn . "` TO `" . $newn . "`");
		$oldn="stutimetablea";
		$newn="stutimetable";
		mysqli_query($con,"RENAME TABLE `" . $oldn . "` TO `" . $newn . "`");
		}
	} 
	elseif ( $dt >= $btetrs and $dt <= $btetre ) 
	{
		$tetramino = 'Β';
		
		if(!$tableyes)
		{
		$oldn="stutimetable";
		$newn="stutimetablea";
		mysqli_query($con,"RENAME TABLE `" . $oldn . "` TO `" . $newn . "`");
		$oldn="stutimetableb";
		$newn="stutimetable";
		mysqli_query($con,"RENAME TABLE `" . $oldn . "` TO `" . $newn . "`");
		}
	}
	/////////////////////////////////////// GLOBAL VARIABLES //////////////////
	$_SESSION['tetramino']=$tetramino;



?>
<br /><br />

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