<?php
require_once "../admin/private/initialize.php";
$_SESSION['url'] = $_SERVER['REQUEST_URI'];

if (isset($_GET['company'])) {

    $vendors = Vendor::find_by_cat_url($_GET['company']);

    $contact = ContactProfile::find_vendor($vendors->id);

    $business = BusinessProfile::find_vendor_id($vendors->id);

    $others = OtherProfile::find_vendor_id($vendors->id);

    $plans = Order::find_vender($vendors->id);

    $s_p = Product::find_vendor_id($vendors->id);

    if ($plans) {

        $plan_details = Plan::find_by_id($plans->premium_id);
    }

    $title = ucfirst(strtolower($vendors->vendor_company)) . ' in ' . strtolower($vendors->city) . ', ' . strtolower($vendors->vendor_state) . ', india - Worldsindia';

    $s_description = ucfirst(strtolower($vendors->vendor_company)) . ' is registered company with Worldsindia.' . ' ' . ucfirst(strtolower($vendors->vendor_company)) . ' is a leading suppliers, exporters, wholesaler, & manufacturers of ' . strtolower($s_p->product_name) . ' in ' . strtolower($vendors->city) . ', ' . strtolower($vendors->vendor_state) . ', india.';
    $s_keywords = strtolower($vendors->vendor_company) . ', suppliers, manufacturers, exporters, ' . strtolower($s_p->product_name) . ', india, ' . strtolower($vendors->vendor_state);
}

 if(isset($_POST['inquiry_submit'])){
        echo 'hi';
        $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 Enquiry submitted successfully');
    
            redirect_to($base_url . $_POST['vendor_name'] . '/contact');
        }
    }

?>
<!DOCTYPE html>

<html lang="en">

<head>
    <base href="<?php echo $v ?>">
    <title><?php echo $title ?></title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta content="width=device-width, initial-scale=1.0" name="viewport" />
    <meta name="description" content="" />
    <meta name="keywords" content="">
    <meta name="author" content="" />
    <meta name="MobileOptimized" content="320">
    <!-- favicon links -->
   <link rel="icon" href="../../assets/images/favicon.png" type="image/png" />
    <!-- main css -->
    <link rel="stylesheet" href="css/fonts.css" />
    <link rel="stylesheet" href="css/flaticon.css" />
    <link rel="stylesheet" href="css/bootstrap.css" />
    <link rel="stylesheet" href="css/custom_animation.css" />
    <link rel="stylesheet" href="css/font-awesome.css" />
    <link rel="stylesheet" href="css/jquery.fancybox.min.css" />
    <link rel="stylesheet" href="js/plugin/owl/owl.carousel.css" />
    <link rel="stylesheet" href="css/style.css" media="screen" />
    <link rel="stylesheet" href="css/colors/default.css" id="colors" />
    <link rel="stylesheet" href="css/extra.css" rel="stylesheet" type="text/css" />
    
       <link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Audiowide|Sofia|DM+Serif+Display:ital@1">
</head>

<body>

    <!--main wrapper start-->
    <div id="wrapper">
        <div class="hm_home_style1">
            <!--top_header start-->
            <?php include 'includes/top-bar.php' ?>
            <!--menu start-->
            <?php include 'includes/header.php' ?>
            <!--banner start-->
            <div class="hm_bread_wrapper">
                <div class="container">
                    <div class="row">
                    <input type="hidden" id="company_name" value="<?php echo $_GET['company'] ?>">
                        <div class="col-lg-12 col-md-12">
                            <h1 style="color: #272d58;">Products</h1>
                            <ol class="breadcrumb">
                                <li class="breadcrumb-item"><a style="color: #272d58;" href="<?php echo $base_url . $_GET['company'] ?>">Home</a></li>
                                <li class="breadcrumb-item active">Products</li>
                            </ol>
                        </div>
                    </div>
                </div>
            </div>
            <style>
    .hm_btn:before, .cart_icon a:before{
        background-color: #272d58;
    }
</style>
            <!--Products section start-->
            <div class="hm_product_wrapper">
                <div class="container">
                    <div class="row">
                        <div class="new_pro_inner">
                        <?php $vendor_products = Product::find_by_vendor($vendors->id);
                            foreach($vendor_products as $v_pro){
                        ?>
                            <div class="col-lg-4 col-md-4 col-sm-6">
                                <div class="new_pro_box">
                                    <div class="new_pro_img new-set-img">
                                        <img src="../../vender/<?php echo $v_pro->picture_path() ?>" alt="Product_Name" class="img-responsive" />
                                    </div>
                                    <div class="new_pro_data" style="height: 140px;">
                                        <h3><a href="<?php echo $base_url?>product-detail/<?php echo $v_pro->product_url ?>"><?php echo $v_pro->product_name ?></a></h3>
                                        <p><?php echo substr($v_pro->product_description,0,75) ?></p>
                                        <span class="pro_price" style="color: #272d58;">Inquiry Now</span>
                                        <span class="cart_icon" ><a href="javascript:;" class="popup-with-form" id="<?php echo encrypt_data($v_pro->id) ?>"><i class="fa fa-mail-forward" aria-hidden="true"></i></a></span>
                                    </div>
                                </div>
                            </div>
                            <!--2-->
                            <?php } ?>
                        </div>
                    </div>
                </div>
            </div>

            <!--footer start-->
            <?php include 'includes/footer.php' ?>
            <!-- Footer End -->
            <!--popup inquiry form-->
            <div class="hm_login_form_overlay">
                <div class="hm_login_form" id="m_details">

                </div>
            </div>
            
        </div>
        <!--main wrapper-->
    </div>
    <!--script-->
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/bootstrap.js"></script>
    <script type="text/javascript" src="js/wow.min.js"></script>
    <script type="text/javascript" src="js/plugin/owl/owl.carousel.min.js"></script>
    <script type="text/javascript" src="js/switcher.js"></script>
    <script type="text/javascript" src="js/custom.js"></script>
    <script>
        $(document).ready(function() {
            $('.popup-with-form').on('click', function() {
                
                var p_d = $(this).attr("id");
                var v_c = $("#company_name").val();
                $.ajax({

                    type: 'post',
                    url: 'send_inquiry',
                    data: {
                        id: p_d,
                        v_c: v_c,
                    },
                    success: function(data) {
                        $('#m_details').html(data);
                       $('.hm_login_form_overlay').addClass('login_open');
                $('body').addClass('login_overflow');
                    }
                });
            });
            
        });
    </script>
</body>

</html>