<?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 
{

if ($flag==0 or $flag==3)
{
	
$sql="INSERT INTO kataggelia (mitroo, tmima, kataggelon, datekata, perigrafi, sxolia, arsimperiforas, datetimo, eidostimo, periodoi,timoriacode)
 VALUES ('$mitroo', '$tmimaid','$kataggelon', '$datekata', '$perigrafi', '$sxolia', '$arsimpx', '$datetimo', '$etimo', '$periodoi', '$metrox') ";
if (!mysqli_query($con, $sql)) 
		{
            echo "Error: " . $sql . "<br>" . mysqli_error($con);
        }
   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="UPDATE kataggelia SET sxolia='$sxolia',perigrafi='$perigrafi',
	 periodoi='$periodoi',datetimo='$datetimo',eidostimo='$etimo',arsimperiforas='$arsimpx',timoriacode='$metrox' 
WHERE aranaforas='$aranaforas'";
if (!mysqli_query($con, $sql)) 
		{
            echo "Error: " . $sql . "<br>" . mysqli_error($con);
        }

  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");
   }
   
 
}
}