<?php 
session_start();
ob_start();
date_default_timezone_set("Europe/Athens");
$menu=$_SESSION['menu'];    
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
</head>

<?php
require "dbconnect.php"; 
$usr=$_SESSION['usr'];
echo  $usr;
		$datein=$_POST['datein'];
		$dateout=$_POST['dateout'];
		$flc=$_POST['flc'];
		if ($flc=='1') $taxi=$_POST['taxi'];
		$keimeno=$_POST['keimeno']." ".$_POST['acro'];
		$file_name = $_FILES['upfile']['name'];
		echo $file_name;
		$file_size =$_FILES['upfile']['size'];
		$file_tmp =$_FILES['upfile']['tmp_name'];
		$file_type=$_FILES['upfile']['type'];
		$ar=explode('.',$file_name);
		$file_ext=$ar[1];
		$errors= array();
		$extensions= array("pdf","docx","txt");
		if ($flc=='1')
		{
			$fn="../epiloges/files/".$file_name;
		}
		else
		{
			$fn="files/".$file_name;	
		}
		if(in_array($file_ext,$extensions)== false)
		{
			 $errors[]="Μόνο αρχεία κειμένου επιτρέπονται.";
		}
		if(empty($errors))
		  {
			 
			 move_uploaded_file($file_tmp,$fn);
			 
		  }
		if(!empty($_FILES['upfile']['name'][0]))
		{
			echo "<h1>" . "File ". $_FILES['upfile']['name'] ." uploaded successfully." . "</h1>";
		}

		if ($flc=='1')
		{
	 	$q1 = $dbcon->prepare("INSERT INTO anakoinosist (datein,dateout,keimeno,teacher,students,arxeio) 
						 VALUES (?,?,?,?,?,?)");
			$q1->execute([$datein,$dateout,$keimeno,$usr,$taxi,$file_name]);
		}
		if ($flc=='0')
		{
	 	$q1 = $dbcon->prepare("INSERT INTO anakoinosikid (datein,dateout,keimeno,ekdotis,arxeio) 
						 VALUES (?,?,?,?,?)");
			$q1->execute([$datein,$dateout,$keimeno,$usr,$file_name]);
		}
		echo 'alert()';
		?>
		  <script type="text/javascript">
		  alert("Η ανακοίνωση καταχωρήθηκε με επιτυχία");
		  window.location.href = '<?php echo $menu; ?>'
		  </script>
		 
		<?php 

			

