<?php
 include 'connection.php';
date_default_timezone_set('Asia/Calcutta');
$today = date("Y-m-d");
$time = date("h:i A"); 
$currentyear = date("Y");
  $first_name=$_POST['name'];
function randomPassword() {
    $alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $pass = array(); //remember to declare $pass as an array
    $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
    for ($i = 0; $i < 5; $i++) {
        $n = rand(0, $alphaLength);
        $pass[] = $alphabet[$n];
    }
    return implode($pass); //turn the array into a string
}
$unique_id = randomPassword();

$querylogin = "select * from  mst_users where user_name = '". $_SESSION["LOGIN_NAME"]."' AND password = '".$_SESSION["EMPLOYEE_PASSWORD"]."'";
$resultlogin = mysqli_query($conn,$querylogin);
while($row=mysqli_fetch_array($resultlogin))
{
$user_name = $row['user_name'];
$user_id = $row['user_id'];
$first_name = $row['first_name'];
$login_type=$row['login_type'];
 $login_type_admin=$row['login_type'];
}


$quotation_id=$_REQUEST['quotation_id'];
$customer_id=$_REQUEST['customer_id'];
?> 
<? 

$product_details=$_POST['product_details'];
$unit=$_POST['unit'];
$price=$_POST['price'];
$vendor_source = $_POST['vendor_source'];
$vendor_id = $_REQUEST['vendor_id'];

if($_POST['product_id']=='other_product_name')
{
$product_name = $_POST['other_product_name'];

$search_product_name = preg_replace('/[^A-Za-z0-9-()]/', '', $product_name);

$qrycall8 = "insert into vendor_products(product_name,search_product_name,status,entry_date,entry_by,unique_id) values ('$product_name','$search_product_name','1','$today','$user_id','$unique_id')";
$rcall8=mysqli_query($conn,$qrycall8);


$qry9enq = "select * from vendor_products where unique_id='$unique_id'";
$re9enq = mysqli_query($conn,$qry9enq);
while($row=mysqli_fetch_array($re9enq))
{  
$product_id = $row['product_id'];
}

}else{

$product_id=$_POST['product_id'];

$qry9enq = "select * from vendor_products where product_id='$product_id'";
$re9enq = mysqli_query($conn,$qry9enq);
while($row=mysqli_fetch_array($re9enq))
{  
$product_name = $row['product_name'];
}

}

$search_vproduct_name = preg_replace('/[^A-Za-z0-9-()]/', '', $product_name);

$qrycallan = "insert into vendor_product_master(product_name,product_details,unit,price,vendor_id,product_id,status,search_vproduct_name) values ('$product_name','$product_details','$unit','$price','$vendor_id','$product_id','1','$search_vproduct_name')";
$rcallan=mysqli_query($conn,$qrycallan);


//$c_id = $_REQUEST['customer_id'];



//exit();


?>

<script>
javascript:window.location.href="edit_vendor.php?vendor_id=<?php echo $_REQUEST['vendor_id']?>";
</script>