<?php

$response = array();

// include db connect class
require_once __DIR__ . '/db_config.php';

    
// check for required fields
if (isset($_POST['mail']))  {
    
$mail= $_POST['mail'];
$cname=$_POST["cname"];
$role=$_POST["role"];
$name=$_POST["name"];
$mobile=$_POST["mobile"];
$phone=$_POST["phone"];
$email=$_POST["email"];
$address=$_POST["address"];
$web=$_POST["web"];
$rnmae=$_POST["rnmae"];
$rmobile=$_POST["rmobile"];
$rmail=$_POST["rmail"];
$clientid=$cname.$name;
date_default_timezone_set('Asia/Calcutta');
$dt=date('Y-m-d H:i:s');
$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE) or die(mysql_error());


$companyQuery="SELECT adminemailid,CompanyType FROM b2lcustomers WHERE companyname='$cname'";
$companyResult=mysqli_query($con,$companyQuery);
if(!empty($companyResult) && mysqli_num_rows($companyResult) > 0){
    $row = mysqli_fetch_array($companyResult,MYSQLI_ASSOC);
    $admin=$row["adminemailid"];
    $ctype=$row["CompanyType"];
}


$query="INSERT INTO task_client_company(c_companyname,c_emailid,c_type, c_created_by_id,c_created_by_type,c_company_name,c_company_id,c_responsible_person,c_company_mobile,c_company_phone,c_responsible_mobile, c_responsible_mailid,c_company_mailid,c_company_address, c_company_webaddress,c_datetime) VALUES ('$cname','$admin','$ctype','$mail','$role','$name','$clientid','$rnmae','$mobile','$phone','$rmobile','$rmail','$email','$address','$web','$dt')";
    $response["s"]=mysqli_query($con,$query);
    mysqli_close($con);
} 
    echo json_encode($response);

?>