<?php
session_start();
ob_start();
include('../include/config.php');
$_SESSION['user_idd']=$id;

$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');

if($_POST['pid'] != '')
{
$pid =addslashes($_POST['pid']);
$pn =addslashes($_POST['pn']);
$eco =addslashes($_POST['eco']);
$std = $_POST['std'];
$ecd =addslashes($_POST['ecd']);
$cont = addslashes($_POST['cont']);
$des = addslashes($_POST['des']);

$sql=mysqli_query($con,"INSERT INTO projects(ProCode,ECost,Pname,SDate,EDate, Contractor,EntryDate,Description) VALUES('$pid','$eco','$pn','$std','$ecd','$cont','$timenow2','$des') ");
if($sql)
{
    $msg='added new project';
 $sql2=mysqli_query($con,"INSERT INTO activity(user,Action,Tim,Dat,shortmsg,Month) VALUES('$id','$msg','$timenow','$timenow2','save','$month') ");
 if($sql2)
 {
    echo 'success'; 
 }
}else
{
    echo 'Sorry. Error occured while saving data';
}
}else if($_POST['id'] != '')
{
$id =addslashes($_POST['id']);
$pn =addslashes($_POST['pn']);
$eco =addslashes($_POST['eco']);
$std = $_POST['std'];
$ecd =addslashes($_POST['ecd']);
$cont = addslashes($_POST['cont']);
$des = addslashes($_POST['des']);
$cdate = addslashes($_POST['cdate']);
$stat = addslashes($_POST['stat']);

//$sql=mysqli_query($con,"UPDATE projects SET ECost='$eco',Pname='$pn',SDate='$std',EDate='$ecd',Contractor='$cont WHERE id='$id'");
$sql=mysqli_query($con,"UPDATE projects SET ECost='$eco',Pname='$pn',SDate='$std',EDate='$ecd', Contractor='$cont',LastUpdate='$timenow2',Description='$des',CompDate='$cdate',Status='$stat' WHERE id='$id'");
if($sql)
{
    $msg='Updated project data';
 $sql2=mysqli_query($con,"INSERT INTO activity(user,Action,Tim,Dat,shortmsg,Month) VALUES('$id','$msg','$timenow','$timenow2','update','$month') ");
 if($sql2)
 {
    echo 'success'; 
 }
}else
{
    echo 'Sorry. Error occured while updating data';
}  
   
   
   
    
}
?>