<?php
$categories = $this->db->query("SELECT * FROM wps_categories WHERE status = '1' AND parent_id = 0 order by sort_order")->result_array();

$adminRes = get_site_email();
?>
<!-- New code start from here -->
<header id="rs-header" class="rs-header menuFxd">
<!--    <div class="header-top-area">
        <div class="container">
            <div class="row">
                <div class="col-lg-8">
                    <div class="header-top-item">
                        <div class="header-left">
                            <ul>
                                <li>
                                    <a href="mailto:<?= $adminRes->admin_email; ?>">
                                        <i class="fa fa-envelope" aria-hidden="true"></i>
<?= $adminRes->admin_email; ?>
                                    </a>
                                </li>
                                <li>
                                    <a href="tel:<?= $adminRes->phone; ?>">
                                        <i class="fa fa-phone"></i> <?= $adminRes->phone; ?>
                                    </a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>-->
    <div class="container">
        <div class="row">
            <div class="mainnavwrap">
                <div class="logo">
                    <a title="Logo" href="<?php echo site_url(); ?>"> <img src="<?php echo theme_url(); ?>images/logo.png" alt="<?php echo SITENAME; ?>" title="<?php echo SITENAME; ?>"></a>
                </div>
                <div class="mainmenu">
                    <div class="menu-area menu-sticky">
                        <div class="row y-middle">
                            <div class="rs-menu-area">
                                <div class="main-menu">
                                    <div class="mobile-menu">
                                        <a class="rs-menu-toggle">
                                            <i class="fa fa-bars"></i>
                                        </a>
                                    </div>
                                    <nav class="rs-menu">
                                        <ul class="nav-menu">
                                            <li><a href="<?php echo site_url(); ?>" title="Home"> Home</a> </li>
                                            <li><a href="<?php echo base_url(); ?>about-us" title="About Us"> About Us</a> </li>
<?php $maincat = $this->db->query("SELECT * FROM wps_categories WHERE status = '1' AND parent_id = '0' order by sort_order asc")->result_array();
foreach ($maincat as $key => $vals) {
    ?>
                                                <li class="menu-item-has-children">

                                                    <a href="<?= site_url($vals['friendly_url']); ?>"><?php echo $vals['category_name']; ?></a>
                                                    <ul class="sub-menu">
                                                        <?php
                                                        $res1 = $this->db->query("SELECT * FROM wps_categories WHERE status = '1' AND parent_id = '" . $vals['category_id'] . "' order by category_id asc")->result_array();
                                                        foreach ($res1 as $key => $val) {
                                                            $subcat = $this->db->query("SELECT * FROM wps_categories WHERE status = '1' AND parent_id = '" . $val['category_id'] . "'")->result_array();
                                                            ?>
                                                            <li><a href="<?= site_url($val['friendly_url']); ?>"><?php echo $val['category_name']; ?></a> </li>
    <?php } ?>

                                                    </ul>
                                                </li>
<?php } ?>
                                             <li><a href="<?php echo site_url(); ?>" title="Support"> Support</a> </li>
                                             <li><a href="<?php echo base_url(); ?>faq" title="FAQ's"> FAQ's</a> </li>
                                             <li><a href="<?php echo base_url(); ?>contact-us" title="Contact Us"> Contact Us</a> </li>
                                             <li><a href="<?php echo site_url(); ?>" title="How to assemble"> How to assemble</a> </li>
                                        </ul> <!-- //.nav-menu -->
                                    </nav>
                                </div> <!-- //.main-menu -->
                            </div>
                        </div>
                    </div>
                </div>
                <div class="cartwrap">
                    <ul class="cartitem">
                        <div id="myOverlay" class="overlay">
                            <span class="closebtn" onclick="closeSearch()" title="Close Overlay">×</span>
                            <div class="overlay-content">
                                <form action="<?php echo base_url(); ?>search" method="post">
                                    <input type="text" placeholder="Search.." name="keywordSearch" required autocomplete="off">
                                    <button type="submit"><i class="fa fa-search"></i></button>
                                </form>
                            </div>
                        </div>
                        <li>
                            <div class="search-button openBtn" onclick="openSearch()">
                                <img class="showInput icon-img" src="<?php echo theme_url(); ?>images/search-icon.svg" alt="Search Products">
                            </div>
                        </li>
                        <?php if ($this->session->userdata('user_id') > 0) { ?> 
                        <li class="icon-bar cart-inner no-border mini-cart-active">
                            <div class="accounts">
                                <span class="side-cart cart">
                                    <a href="<?= base_url('login'); ?>"><img class="icon-img" src="<?php echo theme_url(); ?>images/user.png" alt="account"> </a>                   
                                    <div class="woocommerce-mini-cart text-left cart-bottom-part my-account-drops">
                                        <ul>
                                            <li><a href="<?php echo base_url('contact-us');?>">Help Center</a></li>
                                            <li><a href="<?php echo base_url('my-account');?>">My Account</a></li>
                                            <li><a href="<?php echo base_url('cart');?>">My cart</a></li>
                                            <li><a href="<?php echo base_url('my-orders');?>">Order Tracking</a></li>
                                              <li><a href="<?php echo base_url(); ?>users/logout">Log Out</a></li>
                                        </ul>
                                    </div>
                                </span>
                            </div>
                        </li>
                        <?php } else { ?>
                            <li class="icon-bar cart-inner no-border mini-cart-active">
                            <div class="accounts">
                                <span class="side-cart cart">
                                    <a href="<?= base_url('login'); ?>"><img class="icon-img" src="<?php echo theme_url(); ?>images/account-icon.svg" alt="account"> </a>                   
                                    <div class="woocommerce-mini-cart text-left cart-bottom-part my-account-drops">
                                        <ul>
                                            <li><a href="<?php echo base_url('contact-us');?>">Help Center</a></li>
                                            <li><a href="<?= base_url('login'); ?>">Login</a></li>
                                            <li><a href="<?= base_url('register'); ?>">Register</a></li>
                                           
                                        </ul>
                                    </div>
                                </span>
                            </div>
                        </li>
                        <?php } ?>
                     
                        <?php   $iscart = count($this->cart->contents()) > 0  ? true : false; ?>
                        <li class="icon-bar cart-inner no-border mini-cart-active">
                            <span class="side-cart cart">
                                <a class="cart-icon" data-react="true" href="#">
                                <img class="icon-img" src="<?php echo theme_url(); ?>images/cart-bag.svg" alt="cart"><span class="count"><?php echo $iscart; ?></span></a>
                                <div class="woocommerce-mini-cart text-left">
                                    <?php
                                    if (count($this->cart->contents()) > 0) {
                                        ?>
                                        <div class="cart-bottom-part">
                                            <ul class="cart-icon-product-list">
                                                <?php
                                                $cart = $this->cart->contents();
                                                $totalAmount = $pprice = 0;
                                                foreach ($cart as $items) {
//trace($items);
                                                    $pprice = $items['discount_price'] * $items['qty'];
                                                    $product_name = $items['origname'];
                                                    $totalAmount += $pprice;
                                                    $img = get_db_field_value("wps_products_media", "media", "WHERE products_id='" . $items['pid'] . "'");
                                                    ?>
                                                    <li class="display-flex">
                                                        <div class="icon-cart">
                                                            <a href="<?php echo base_url(); ?>cart/remove_item/<?php echo $items['rowid']; ?>" title="Remove Item"><i class="fa fa-times"></i></a>
                                                        </div>
                                                        <div class="product-info">
                                                            <a href="<?php echo base_url($items['name']); ?>" title="<?php echo $product_name; ?>"><?php echo $product_name; ?></a><br>
                                                            <span class="quantity"><?php echo $items['qty']; ?> × <i class="fa fa-inr" aria-hidden="true"></i> <?php echo $pprice; ?></span>
                                                        </div>
                                                        <div class="product-image">
                                                            <a href="<?php echo base_url($items['name']); ?>" title="<?php echo $product_name; ?>"><img src="<?php echo get_image('products', $img, '70', '70', 'R'); ?>" alt="Product Image"></a>
                                                        </div>
                                                    </li>
    <?php } ?>



                                            </ul>

                                            <div class="total-price text-center">
                                                <span class="subtotal">Subtotal:</span>
                                                <span class="current-price"><i class="fa fa-inr" aria-hidden="true"></i> <?php echo $totalAmount; ?></span>
                                            </div>

                                            <div class="cart-btn text-center">
                                                <a class="crt-btn btn1" href="<?= base_url('cart'); ?>" title="View Cart">View Cart</a>
                                                <a class="crt-btn btn2" href="<?php echo base_url(); ?>cart/delivery_info" title="Check Out">Check Out</a>
                                            </div>
                                        </div>
<?php } else { ?>
                                        <div class="cart-bottom-part text-center">
                                            <img src="<?php echo theme_url(); ?>images/cartempty.png" alt="Cart Empty" title="Cart Empty"/>
                                            <div class="actions">
                                                <div class="a-inner"> <a class="default-btn local" href="index.html">Continue Shopping </a>

                                                </div>             
<?php } ?>

                                        </div>

                                        </span>
                                        </li>



                                        </ul>
                                    </div>
                                </div>
                                </div>
                                </div>
                                </header>
