<?php
session_start();
require_once 'includes/database.php';
include 'includes/funcs.php';
$db=new MySQLDatabase();
$db->open_connection();
$user = $_SESSION['reusername'];

if(isset($_REQUEST['cname'])){	
$cname = strtoupper($_REQUEST['cname']);
$auct = strtoupper($_REQUEST['auct']);
$floc = strtoupper($_REQUEST['floc']);	
$vehmod = strtoupper($_REQUEST['vehmod']);
$regno = strtoupper($_REQUEST['regno']);
$chasis = strtoupper($_REQUEST['chasis']);
$vcolor = strtoupper($_REQUEST['vcolor']);
$odate = substr($_REQUEST['odate'],6,4)."-".substr($_REQUEST['odate'],3,2)."-".substr($_REQUEST['odate'] ,0,2);
$rmks = trim($_REQUEST['rmks']);	
																		// add inv															
if($_REQUEST['e'] === '0') {
$repono = getnewno("repono");
$query = "INSERT INTO reporders (cname, repono, odate, vehmod, vcolor, regno, chasis, rmks, floc, auct, us, ts) VALUES ('"
.$cname."', ".$repono.", '".$odate."', '".$vehmod."', '".$vcolor."', '".$regno."', '".$chasis."', '".$rmks."', '".$floc."', '".$auct."', '".$user."', '".date("Y-m-d H:i:s")."');";
}
else {
$repono = $_REQUEST['repono'];
$ddate = substr($_REQUEST['ddate'],6,4)."-".substr($_REQUEST['ddate'],3,2)."-".substr($_REQUEST['ddate'] ,0,2);
$query = "UPDATE reporders SET cname = '$cname', odate = '$odate', ddate = '$ddate', vehmod = '$vehmod', vcolor = '$vcolor', regno = '$regno', floc = '$floc', chasis = '$chasis', rmks = '$rmks', auct = '$auct' WHERE repono = '$repono';"; 													
}
$result = mysqli_query($db->connection, $query) or die(mysqli_error($db->connection) ); 
$db->close_connection();
echo ($_REQUEST['e'] === '0') ? ('Order Booked with No. '.$repono.' !') :('Reposession Order Updated!');  
}


?>