<?php
require_once "../../admin/private/initialize.php";

if(is_post_request()){


    if(isset($_POST['product_name'])){
 
        $vendor = Vendor::find_by_cat_url($_POST['vendor_name']);
    
        $name =  htmlentities(trim($database->escape_string($_POST['name'])));
        $product =  decrypt_data($_POST['product_name']);
        $email =  htmlentities(trim($database->escape_string($_POST['email'])));
        $contact_number =  htmlentities(trim($database->escape_string($_POST['number'])));
        $message =  htmlentities(trim($database->escape_string($_POST['message'])));
        $company =  htmlentities(trim($database->escape_string($_POST['company'])));
        $unit =  htmlentities(trim($_POST['unit']));
        $quantity =  htmlentities(trim($database->escape_string($_POST['quantity'])));
    
        $p_inquiry = new ProductEnquiry();
        $p_inquiry->product_id = $product;
        $p_inquiry->vendor_id = $vendor->id;
        $p_inquiry->email = $email;
        $p_inquiry->name = $name;
        $p_inquiry->product_unit = $unit;
        $p_inquiry->mobile_number = $contact_number;
        $p_inquiry->company = $company;
        $p_inquiry->description = $message;
        $p_inquiry->is_verify = '0';
        $p_inquiry->created_at = $time;
        $result = $p_inquiry->save();
    
        if($result == true){
    
            $session->message('Your Product Enquiry submitted successfully');
    
            redirect_to($base_url . $_POST['vendor_name'] . '/contact');
        }
        
    }


     if(isset($_POST['quote_request'])){
         $vendor = Vendor::find_by_cat_url($_POST['vendor_company_name']);

         $name =  htmlentities(trim($database->escape_string($_POST['name'])));
         $email =  htmlentities(trim($database->escape_string($_POST['email'])));
         $contact_number =  htmlentities(trim($database->escape_string($_POST['number'])));
         $message =  htmlentities(trim($database->escape_string($_POST['message'])));
         $company_name =  htmlentities(trim($database->escape_string($_POST['company_name'])));
         $subject =  htmlentities(trim($database->escape_string($_POST['subject'])));

         $send_mail = decrypt_data($_POST['send_mail']);
         
         $c_inquiry = new CatalogContact();
        $c_inquiry->vendor_id = $vendor->id;
        $c_inquiry->email = $email;
        $c_inquiry->name = $name;
        $c_inquiry->subject = $subject;
        $c_inquiry->phone = $contact_number;
        $c_inquiry->company = $company;
        $c_inquiry->description = $message;
        $c_inquiry->status = '0';
        $c_inquiry->created_at = $time;
        $result = $c_inquiry->save();
    
        if($result == true){
            $session->message('Your Enquiry submitted successfully');
    
            redirect_to($base_url . $_POST['vendor_company_name'] . '/contact');
        }
     }


}