<?php

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');

$zdb = $_SESSION["zdbyear_" . $dbname];
$admin = $_SESSION["admin_" . $dbname];
$user = $_SESSION['username_' . $dbname];


mysqli_select_db($conn,$zdb);
if (isset($_REQUEST['newuser'])) {

    $leadvouch = $_REQUEST[vouchno1];
    $newuser = $_REQUEST[newuser];
    $date = date("Y-m-d");
//    for new user 
    mysqli_query($conn,"UPDATE `leadenq` set `newuser`='$newuser' where `vouchno`='$leadvouch' ") or die(mysqli_error($conn));

    
//    for transfer data
    $getdet = mysqli_query($conn,"Select * from `leadenq` where vouchno = '$leadvouch'") or die(mysqli_error($conn));
    $det = mysqli_fetch_array($getdet);

    $gen1 = mysqli_query($conn,"SELECT MAX(vouchno) AS maxcode FROM `trnfmain` LIMIT 0,1 ") or die(mysqli_error($conn));

    if (mysqli_num_rows($gen1) > 0) {
        $vvouch = mysqli_fetch_assoc($gen1);
        $qlevouch = $vvouch["maxcode"] + 1;
    } else {
        $qlevouch = '1';
    }
    
    mysqli_query($conn,"INSERT INTO `trnfmain` (vouchno, `vouchdt`, `leadvouch`, `mobile`, `email`, `name`, `lastname`, `destination`, `deptdate`, 
                                               `username`, `newuser`, `status`)
                            VALUES($qlevouch, '$date', '$leadvouch', '$det[mobile]', '$det[email]', '$det[name]', '$det[lastname]', '$det[destination]', '$det[deptdate]',
                                               '$user', '$newuser', '$det[status]')") or die(mysqli_error($conn));
    
    echo "success";
}
?>
