<?php
$vdtmima=0;
$sqlx=mysqli_query($con,"select Class_id from voithos where voi_id='$vdidk' and Class_id='$tmimaid'");
if (mysqli_num_rows($sqlx) > 0 ) {$vdtmima=1;}
$error = false;
if ($vdtmima==0)
{
  if (!strlen(trim($_POST['sxolia']))) 
  {
	$error = true;
  }
}
else
{
   if (!strlen(trim($_POST['perigrafi'])) and $flag<> 3) {
    $error = true;
   }	
}
if ($error) 
{ // DISPALY A MESSAGE BOX IF FIELDS ARE EMPTY
   echo '<script type="text/javascript">';
   if ($vdtmima==0)
   {
   echo 'alert("ΠΡΕΠΕΙ ΑΠΑΡΑΙΤΗΤΑ ΝΑ ΔΩΣΕΤΕ ΑΙΤΙΟΛΟΓΗΣΗ ΓΙΑ ΤΗΝ ΠΟΙΝΗ")';
   }
   else
   {
	echo 'alert("ΠΡΕΠΕΙ ΑΠΑΡΑΙΤΗΤΑ ΝΑ ΔΩΣΕΤΕ ΠΕΡΙΓΡΑΦΗ ΓΙΑ ΤΟ ΠΑΡΑΠΤΩΜΑ")';  
	   }
   echo '</script>';	
   $time = 1; //Time (in seconds) to wait. 
   $url = "pitharxika.php"; //Location to send to.
   //$url = "dispkataggelia.php?pmp=".$mitr; //Location to send to. 
   header("Refresh: $time; url=$url");
} 
else 
{
$mitr= $_POST['mitroo'];	
$kataggelon= $_POST['kathig'];
$datekata= $_POST['datekata'];
$_SESSION['datekata']=$datekata;
$perigrafi=$_POST['perigrafi'];
$sxolia=$_POST['sxolia'];
if ($flag==3) $perigrafi=$sxolia;

$_SESSION['sxolia']=$sxolia;
$arsimpx = $_POST['arsimpx'];
$metrox=$_POST['metrox'];
$datetimo = $_POST['datetimo'];
$etimo = $_POST['etimo'];
$eidostimo=$etimo;
$periodoi = $_POST['periodoi'];
$_SESSION['pini']=$periodoi;
$katastasi = 2;
$flag=$_POST['flag'];
$aranaforas=$_POST['aranaforas'];
$_SESSION['aranaforas']=$aranaforas;
$_SESSION['mitr']=$mitr;

if ($flag==0 or $flag==3)
{
$sql=mysqli_query($con,"INSERT INTO kataggelia (mitroo, tmima, bd, kataggelon, datekata, perigrafi, sxolia, arsimperiforas, datetimo, eidostimo, periodoi, katastasi,timoriacode)
 VALUES ('$mitr', '$tmimaid', '$vdidk', '$kataggelon', '$datekata', '$perigrafi', '$sxolia', '$arsimpx', '$datetimo', '$etimo', '$periodoi', '$katastasi','$metrox') ");

   if (!$sql) 
   { 
   		echo '<script type="text/javascript">';
     	echo 'alert("ΚΑΤΙ ΠΗΓΕ ΣΟΒΑΡΑ ΛΑΘΟΣ")';  
	    echo '</script>';	
        $time = 1; //Time (in seconds) to wait. 
        $url = "pitharxika.php"; //Location to send to.
         //$url = "dispkataggelia.php?pmp=".$mitr; //Location to send to. 
         header("Refresh: $time; url=$url");
   }
  
}
else
{
$sql=mysqli_query($con,"UPDATE kataggelia SET sxolia='$sxolia',perigrafi='$perigrafi',
	 periodoi='$periodoi',datetimo='$datetimo',eidostimo='$etimo',arsimperiforas='$arsimpx',timoriacode='$metrox' WHERE aranaforas='$aranaforas'");

 if (!$sql) 
  { 
        echo '<script type="text/javascript">';
     	echo 'alert("ΚΑΤΙ ΠΗΓΕ ΣΟΒΑΡΑ ΛΑΘΟΣ")';  
	    echo '</script>';	
        $time = 1; //Time (in seconds) to wait. 
        $url = "pitharxika.php"; //Location to send to.
         //$url = "dispkataggelia.php?pmp=".$mitr; //Location to send to. 
         header("Refresh: $time; url=$url");
   }

$sql=mysqli_query($con,"SELECT timoriacode,periodoi FROM kataggelia WHERE  aranaforas='$aranaforas'");
$row=mysqli_fetch_array($sql);
$timoriacode=$row['timoriacode'];
$periodoi=$row['periodoi'];
$sql=mysqli_query($con,"UPDATE timoria SET peramount='$periodoi' WHERE timoriacode='$timoriacode'  ");   
}
}