<?php
include "scrinit.php";
include "logo.php";
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style1.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
function validate () {
  if(document.getElementById('perigrafi').value=="") {
    alert("Η καταγγελία δεν γίνεται να είναι άδεια!!!");
    return false;
  }
  return true;
}
$(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);
}
</script>

<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:09px;"></p>
</style>


</head>

<body>

<?php
require "dbconnect.php";
$usr=$_SESSION['usr'];
$dat=$_SESSION['dt'];

if (isset($_GET['data'])) 
{
	$cd=$_GET['data'];
	$arr=explode("/",$cd);
	$code=$arr[0];
	$eidikotita=$arr[1];
	$sql = mysqli_query($con,"SELECT * FROM sintonismos WHERE code='$code'" );
	$c=mysqli_num_rows($sql);
	if ($c>0)
	{
	  $k=0;
	  while($row = mysqli_fetch_array($sql))
	  {
		$k++;
		$date=$row['date'];
		$per=$row['per'];
		$apon=$row['apon'];
		$keyw=$row['keywords'];
		$thema[$k]=$row['thema'];
		$lepto[$k]=$row['leptomeries'];
		
	  }
	  
		?>
		<form method="post">
		<fieldset style="width:1000px">
		<legend><b>ΑΝΑΘΕΩΡΗΣΗ ΣΥΝΤΟΝΙΣΜΟΥ ΕΙΔΙΚΟΤΗΤΑΣ</b> </legend>
		<p><b>ΕΙΔΙΚΟΤΗΤΑ:</b>:<input type='text' name= 'eidik' value="<?php echo $eidikotita; ?>"  readonly />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp<b>ΑΡ. ΣΥΝΤΟΝΙΣΜΟΥ:</b><input type='text' name= 'code' value="<?php echo $code; ?>" size="3" readonly />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp<b>ΗΜΕΡΟΜΗΝΙΑ:</b><input type='date'  name= 'date' value="<?php echo $dat; ?>"  /> 
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp<b>ΠΕΡΙΟΔΟΣ:</b><input type='text'  name= 'per' value="<?php echo $per; ?>" size='3' readonly /> 
		</p>
		<p><b>ΛΕΞΕΙΣ/ΦΡΑΣΕΙΣ ΚΛΕΙΔΙΑ:</b> <input type='text' name= 'keyw' value="<?php echo $keyw; ?>"  readonly /> </p>
		<b>ΑΠΟΝΤΕΣ ΕΚΠΑΙΔΕΥΤΙΚΟΙ:</b>
		<br>
		<?php
		$aponx=unserialize($apon);
		$n=count($aponx);$apond="";
		for ($i=0;$i<$n;$i++)
		{
		    $r=mysqli_query($con,"select Name from teachers where PMP='$aponx[$i]'");
			$rowy=mysqli_fetch_array($r);
			$apond=$apond.$rowy['Name'].",  ";
		}
		echo "<p>".trim($apond,', ')."</p>";
		include "sinto.php";
		include "sintylh.php";	
		?>
		<br /><br /> 
		<input type='Submit' name='subsint' value='ΚΑΤΑΧΩΡΗΣΗ ΣΥΝΤΟΝΙΣΜΟΥ' >

		</fieldset>
		</form>	
		<?php
	}
	else
	{
		
		?>
		<form method="post" >
		<fieldset style="width:1000px">
		<legend><b>ΚΑΤΑΧΩΡΗΣΗ ΣΥΝΤΟΝΙΣΜΟΥ ΕΙΔΙΚΟΤΗΤΑΣ</b> </legend>
		<p><b>ΕΙΔΙΚΟΤΗΤΑ:</b>:<input type='text' name= 'eidik' value="<?php echo $eidikotita; ?>"  readonly />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp<b>ΑΡ. ΣΥΝΤΟΝΙΣΜΟΥ:</b><input type='text' name= 'code' value="<?php echo $code; ?>" size="3" readonly />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp<b>ΗΜΕΡΟΜΗΝΙΑ:</b><input type='date'  name= 'date' value="<?php echo $dat; ?>"  /> 
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp<b>ΠΕΡΙΟΔΟΣ:</b><input type='text'  name= 'per' value="<?php echo $per; ?>" size='3' required /> 
		</p>
		<p><b>ΛΕΞΕΙΣ/ΦΡΑΣΕΙΣ ΚΛΕΙΔΙΑ:</b> <input type='text' name= 'keyw' value="<?php echo $keyw; ?>" size='103'  /> </p>
		<b>ΑΠΟΝΤΕΣ ΕΚΠΑΙΔΕΥΤΙΚΟΙ:</b>
		<br>
		<?php
		$r=mysqli_query($con,"select Name,PMP from teachers where idikotita='$eidikotita' order by Name");
		
		while($rowx = mysqli_fetch_array($r))
			{
				echo '<input type="checkbox" name="teach[]" value="'.$rowx['PMP'].'">'.$rowx['Name'].'<br>';
				
				
			}
		$did=array();
		include "sinto.php";
		include "sintylh.php";		
		?>
		<br /><br /> 
		<input type='Submit' name='subsint' value='ΚΑΤΑΧΩΡΗΣΗ ΣΥΝΤΟΝΙΣΜΟΥ' >

		</fieldset>
		</form>	

		<?php
	}
	if (isset($_POST['subsint'])) 
	{
		$dat=$_POST['date'];
		$eidikotita=$_POST['eidik'];
		$per=$_POST['per'];
		$code=$_POST['code'];
		$keyw=$_POST['keyw'];
		$themax=$_POST['thema'];
		$perg=$_POST['perig'];
		$ylix=$_POST['yli'];
		echo "xxx";print_r($ylix);echo "xxx";
		$apontes=serialize($_POST['teach']);
		$c=count($themax);
		$i=0;
		foreach ($themax as $thema)
		{
			if (!empty(trim($thema)))
			{
				$pg=$perg[$i];
				
				$q="insert into sintonismos (code,date,per,eidikotita,bd,apon,thema,leptomeries,keywords)
				values ('$code','$dat','$per','$eidikotita','$usr','$apontes','$thema','$pg','$keyw')";
				if (mysqli_query($con, $q)) 
				{
				   echo "";
				} 
				else 
				{
				   echo "Error: " . $q. "<br>" . mysqli_error($con);
				}
			}
			$i++;			
		}
		foreach ($ylix as $key1=>$dixt)
		{

			foreach ($dixt as $key=>$value)
			{
				$q="insert into sintdeiktes (sintcode,deiktes,pmp,subj)
				values ('$code','$value','$key1','$key')";
				
				if (mysqli_query($con, $q)) 
				{
				   echo "";
				} 
				else 
				{
				   echo "Error: " . $q. "<br>" . mysqli_error($con);
				}
			}

			 			
		}
		echo "<script>
			alert('Η καταχώριση έγινε με επιτυχία!');
			</script>";
			$time = 0; //Time (in seconds) to wait. 
			$url = "sintonismos.php"; //Location to send to. 
			header("Refresh: $time; url=$url");

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

</body>
</html>