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

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

//$getemail = mysqli_query($conn,"Select email from company") or die(mysqli_error($conn));
//$memail = mysqli_fetch_array($getemail);
//$myemailid = $memail[email];
mysqli_select_db($conn,$zdb);
if (isset($_REQUEST['name1'])) {
//    $link       = "cepheisys.com/fab";
    
    $leadvouch    = $_REQUEST[vouchno1];
    $name         = $_REQUEST[name1];
    $lastname     = $_REQUEST[lastname1];
    $vouchdt      = $_REQUEST[vouchdt1];
    $mobile       = $_REQUEST[mobile1];
    $deptdate     = $_REQUEST[deptdate1];
    $newdest     = $_REQUEST[newdest];
    
    
//    $deptdate1    = DATE_FORMAT($deptdate, '%d-%m-%Y');
    $genlst = mysqli_query($conn,"SELECT MAX(vouchno) AS maxcode FROM `leadenq` LIMIT 0,1 ") or die(mysqli_error($conn));
    $vvouch = mysqli_fetch_assoc($genlst);
    $qlvouch = $vvouch["maxcode"] + 1;
    
    $getdtls = mysqli_query($conn,"SELECT tel, tel2, mobile2,email, username, city  FROM `leadenq` where vouchno='$leadvouch'") or die(mysqli_error($conn));
    $dtlsav = mysqli_fetch_array($getdtls);
    
    mysqli_query($conn,"INSERT INTO `leadenq`(vouchno, `vouchdt`, `oldvouch`, `destination`, `mobile`, `name`, `lastname`, `deptdate`, 
                                        `username`, tel, tel2, mobile2, email, city)
                                VALUES ($qlvouch, '$vouchdt', '$leadvouch', '$newdest', '$mobile', '$name', '$lastname', '$deptdate', 
                                        '$dtlsav[username]', '$dtlsav[tel]', '$dtlsav[tel2]', '$dtlsav[mobile]', '$dtlsav[email]', '$dtlsav[city]')") or die(mysqli_error($conn));
    
    mysqli_query($conn,"UPDATE `leadenq` set `newvouch`='$qlvouch', `status`='Destination Change' where `vouchno`='$leadvouch' ") or die(mysqli_error($conn));
    
    echo "$qlvouch";
}
?>
