<?php 
session_start();
$iduser=$_SESSION['user_idd'];
$date = new DateTime("now", new DateTimeZone('Africa/Nairobi') );
$timenow=$date->format('Y-m-d H:i:s');
$timenow2=$date->format('Y-m-d');
$month=$date->format('M');
//$finaldate='Today: '.$date->format('l d M Y - H:i:s');

include('../include/config.php');

 
 if(isset($_POST["id"]))
 { 
 $id=addslashes($_POST["id"]);
 $claz=addslashes($_POST["claz"]);
 $tam=addslashes($_POST["tam"]);
 $pesa=addslashes($_POST["pesa"]);
 $yr=addslashes($_POST["yr"]);
 
 $months=$_POST['monn'];
 $trm='';
 if($tam=='Term One')
 {
     $trm='01';
 }else if($tam=='Term Two')
 {
     $trm='02';
 }else if($tam=='Term Three')
 {
     $trm='03';
 }
 

$year=substr($yr, -2,2);
$cod=$year.$trm;

 $queryy=mysqli_query($con,"select * from Fees2 where Year='$yr' AND 
 Term='$tam' AND pid='$id'");
$num=mysqli_fetch_array($queryy);
if($num>0)
{
  echo 'Learner already exist in the selected period';  
    
}else
{
$sql=mysqli_query($con,"INSERT INTO Fees2(Year,Term,Grad,TutionF,pid,AutoNa) values ('$yr','$tam','$claz','$pesa','$id','$cod')");
if($sql)
{
$msgg='added learners to fee period '.$cod;
$sql3=mysqli_query($con,"INSERT INTO activity(user,Action,Tim,Dat,shortmsg,Month)values('$iduser','$msgg','$timenow','$timenow2','update','$month')");
if($sql3){ } 
echo 'success';
}else
{
echo "Error occurred in saving the data";
}
}
 }
?>