<?php
session_start();
ob_start();
if ($_SESSION['islogin']=='' ) { 
  echo "ΠΡΕΠΕΙ ΝΑ ΕΓΓΡΑΦΕΙΤΕ ΓΙΑ ΝΑ ΧΡΗΣΙΜΟΠΟΙΗΣΕΤΕ ΤΟ ΣΥΣΤΗΜΑ"."<BR>";
  sleep(3);
  header("Location: loginall.php"); /* Redirect browser */
  exit();
  }
$menu = $_SESSION['menu'];
include $menu;
?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">

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);
}
</script>
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:9pt; }
<p style="font-size:09px;"></p>


body {
    font: 0.8em/1.1em Verdana, Geneva, Arial, Helvetica, sans-serif;
    background-color:#FFF; }


</script>


</head>
<body>


<?php

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

if (isset($_POST['Submit']))
{
$error = false;
if (!strlen(trim($_POST['perigrafi']))) {
    $error = true;
  }

if ($error) { // DISPALY A MESSAGE BOX IF FIELDS ARE EMPTY
   echo '<script type="text/javascript">';
   echo 'alert("ΠΡΕΠΕΙ ΑΠΑΡΑΙΤΗΤΑ ΝΑ ΔΩΣΕΤΕ ΠΕΡΙΓΡΑΦΗ ΓΙΑ ΤΗΝ ΕΓΚΥΚΛΙΟ")';
   echo '</script>';	
   $time = 1; //Time (in seconds) to wait. 
   $url = "egkiklioi.php?anaf=".$aranaf; //Location to send to. 
   header("Refresh: $time; url=$url");
} 
else 
{
$type= $_POST['type'];	
$perigrafi= $_POST['perigrafi'];
$datein= $_POST['datein'];
$aranaf=$_POST['arnum'];
$datedue=$_POST['datedue'];
$bdresp = $_POST['bdres'];
$tresp = $_POST['tres'];
$url1=$_POST['url1'];
$status=0;
////////////////
foreach ($tresp as $t)
{
	echo $t;
$sql="INSERT INTO egkiklioi (id,datein,datedue,type,perigrafi,bdres,tres,url,user,status) 
VALUES (NULL,'$datein','$datedue','$type','$perigrafi','','$t','$url1','$usr','$status') ";

if (!mysqli_query($con,$sql)){ die('Error: ' . mysqli_error($con));}
   /*
   if (!$sql) 
   { 
   echo "error";
   }
  else
   {
	echo "<br>"."Η εγκύκλιος καταχωρήθηκε με αριθμό: ".$aranaf;
    echo "<br>"."<br>";
   }
   */
}
foreach ($bdresp as $vd)
{
	echo $vd;
$sql="INSERT INTO egkiklioi (id,datein,datedue,type,perigrafi,bdres,tres,url,user,status) 
VALUES (NULL,'$datein','$datedue','$type','$perigrafi','$vd','','$url1','$usr','$status') ";

if (!mysqli_query($con,$sql)){ die('Error: ' . mysqli_error($con));}
   /*
   if (!$sql) 
   { 
   echo "error";
   }
  else
   {
	echo "<br>"."Η εγκύκλιος καταχωρήθηκε με αριθμό: ".$aranaf;
    echo "<br>"."<br>";
   }
   */
}
}

}  


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