<?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["tid"]))
 { 
 $tid=addslashes($_POST["tid"]);
 $pid=addslashes($_POST["pid"]);
 $amt=addslashes($_POST["amt"]);
 $dat=addslashes($_POST["dat"]);
 $bnk=addslashes($_POST["bnk"]);
 $rno=addslashes($_POST["rno"]);
 $trm=addslashes($_POST["trm"]);

 $yrr=substr($dat, 0, 4);
 $mm=substr($dat, 5, 2);

if($mm=='01'){$mm='January';}
if($mm=='02'){$mm='February';}
if($mm=='03'){$mm='March';}
if($mm=='04'){$mm='April';}
if($mm=='05'){$mm='May';}
if($mm=='06'){$mm='June';}
if($mm=='07'){$mm='July';}
if($mm=='08'){$mm='August';}
if($mm=='09'){$mm='September';}
if($mm=='10'){$mm='October';}
if($mm=='11'){$mm='November';}
if($mm=='12'){$mm='December';}

$claz='';
$sql = "SELECT * FROM pupils where count='$pid'";
$result = $con->query($sql);
while($row = $result->fetch_assoc()) 
{
 $claz=$row['Claz'];   
}

$sql=mysqli_query($con,"INSERT INTO Gradpayment(pid,Gid,Amount,Bank,Dat,User,Month,Year,EntryDate,Term,Grad,Receipt) values ('$pid','$tid','$amt','$bnk','$dat','$iduser','$mm','$yrr','$timenow2','$trm','$claz','$rno')");
if($sql)
{
$msgg='added graduation payment amount';
$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 in saving data";
}
 }else if(isset($_POST["did"]))
 {
$id =addslashes($_POST['did']);
$sql=mysqli_query($con,"DELETE from TourPayment where idd='$id'");
if($sql)
{
    $msg='deleted a tour payment entry';
 $sql2=mysqli_query($con,"INSERT INTO activity(user,Action,Tim,Dat,shortmsg,Month) VALUES('$iduser','$msg','$timenow','$timenow2','delete','$month') ");
 if($sql2)
 {
    echo 'success'; 
 }
}else
{
    echo 'Sorry. Error occured while saving data';
}  
 }
?>