
<?php 
session_start();
require_once 'includes/database.php';
$db=new MySQLDatabase();
$db->open_connection(); 
	    
	$insno = $_POST['insno'];	$renewtxt = $_POST['renewtxt'];
	$inst1 = $_POST['inst1'];	$inst2 = $_POST['inst2'];	$inst3 = $_POST['inst3'];
	$rdate = substr($_REQUEST['rdate'],6,4)."-".substr($_REQUEST['rdate'],3,2)."-".substr($_REQUEST['rdate'] ,0,2);
	$ndate = substr($_REQUEST['ndate'],6,4)."-".substr($_REQUEST['ndate'],3,2)."-".substr($_REQUEST['ndate'] ,0,2);
	
	$endosav = 0;
	$user = $_SESSION['reusername'];	$ts = date("Y-m-d H:i:s");
	$sql = mysqli_query($db->connection, "SELECT * FROM renewals WHERE insno = '$insno';") or die (mysqli_error($db->connection) );
	if ($row = mysqli_fetch_array($sql, MYSQLI_ASSOC)){ $endosav = 1;  }
	if($endosav){ $qry = "UPDATE renewals SET ndate='$ndate', rdate='$rdate', renewtxt='$renewtxt', inst1='$inst1', inst2='$inst2', inst3='$inst3', us='$user', ts = '$ts' WHERE insno='$insno';";  }
	else { $qry = "INSERT INTO renewals (insno, ndate, rdate, renewtxt, inst1, inst2, inst3, us, ts) VALUES ('$insno','$ndate','$rdate', '$renewtxt','$inst1','$inst2','$inst3','$user', '$ts');"; }
	$sql = mysqli_query($db->connection, $qry) or die (mysqli_error($db->connection) );
	echo '<script type="text/javascript"> window.close();</script>';

?>