<?php

$response = array();

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

    
// check for required fields
if (isset($_POST['data']))  {
    
$json=json_decode($_POST['data'],true);

$mail= $json['mail'];
$cname=$json["cname"];
$role=$json["role"];

$name=$json["name"];
$des=$json["des"];
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_category(cat_companyname,cat_emailid,cat_type,task_categoryname, cat_description,cat_created_by_mailid,cat_created_by_type,cat_datetime) VALUES ('$cname','$admin','$ctype','$name','$des','$mail','$role','$dt')";
    $response["s"]=mysqli_query($con,$query);
    mysqli_close($con);
} 
    echo json_encode($response);

?>