<?php


	function db_filter($value='')
	{
		global $DB_CONN;
		return mysqli_real_escape_string($DB_CONN,trim($value));
	}

	function slugify($str)
	{
		$slug = '';
		if(!empty($str))
		{
			$slug = strtolower(str_replace(array('  ', ' '), '_', preg_replace('/[^a-zA-Z0-9 s]/', '', trim($str))));
		}
		return $slug;
	}
	
	function getLink($name , $id,$for)
	{
		global $siteURL;
		return $siteURL.'/'.$for.'-'.$id.'-'.slugify($name);
	}


	function getItemRating($itemID)
	{
		global $DB_CONN;
		$rateStr = '';
		$query = mysqli_query($DB_CONN, "select avg(od.ratting) as avgR from orders_detail od
		join orders o on o.id=od.order_id
		where o.customer_id!='0' and od.item_id='{$itemID}'") or die(mysqli_error($DB_CONN));
		if($query && mysqli_num_rows($query)>0)
		{
			$result = mysqli_fetch_assoc($query);
			$ratting = (int)ceil($result['avgR']);
			
			for($i=1; $i<=5; $i++)
			{
				if($i <= $ratting)
				{
					$rateStr .= '<li><a href="#"><i class="fa fa-star"></i></a></li>';
				}
				else
				{
				
					$rateStr .= '<li><a href="#"><i class="fa fa-star-o"></i></a></li>';
				}
			}
		}
		return $rateStr;
	}
	
    function getBanners($limit=3)
    {
        global $DB_CONN;
        $baners='';
        $query="select * from banners where showOnPage='1'  order by id DESC limit $limit";
        $banner= mysqli_query($DB_CONN,$query)or die("fun-ln-14:".mysqli_error($DB_CONN));
        while ($b=mysqli_fetch_assoc($banner))
        {

        $baners.='<div class="col-lg-4 col-md-6">
                        <div class="single_banner fix">
                            <a href="'.$b["link"].'"><img src="'.show_img('banners', 'image', 'id', $b['id']).'" alt=""></a>
                        </div>
                    </div>';

        }
        return $baners;
    }
    

    function show_img($tbl_name='', $img_field='', $tbl_field='', $field_value='')
    {
        global $DB_CONN;
        $image_src = 'assets/images/sample.jpg';
        if(!empty($tbl_name) && !empty($img_field) && !empty($tbl_field) && !empty($field_value))
        {
            $img = mysqli_query($DB_CONN,"select {$img_field} from {$tbl_name} where {$tbl_field}='{$field_value}' limit 1") or die(mysqli_error($DB_CONN));
            if($img && mysqli_num_rows($img)>0)
            {
                $image = mysqli_fetch_assoc($img);
                if(!empty($image[$img_field]))
                {
                    $image_src = 'data:image/jpeg;base64,'.base64_encode($image[$img_field]);
                }
            }
        }
        return $image_src;
    }

	function RatingPoints($itemID)
	{
		global $DB_CONN;
		$rating=0;
		$query = mysqli_query($DB_CONN, "select avg(od.ratting) as avgR from orders_detail od
		join orders o on o.id=od.order_id
		where o.customer_id!='0' and od.item_id='{$itemID}'") or die(mysqli_error($DB_CONN));
		if($query && mysqli_num_rows($query)>0)
		{
			$result = mysqli_fetch_assoc($query);
			$ratting = (int)ceil($result['avgR']);
		}
		return $ratting;

	}


    function load_products($last_id,$cat_id,$for='')
    {
    	global $currPrefix;
    	global $currPostfix;
		global $DB_CONN;
		global $siteURL;
	
		$data=array();

		$lastStr=($last_id!=0 ? "AND id < ".$last_id."":"");

		if($for=='index')
		{
			$sql="SELECT * from items where  stock > 0  order by id DESC limit 12";
		}
	  elseif ($for=='product_extras')
	  {
			$sql ="select * from items order by rand() limit 15";		
		}	

	   elseif ($for=='category_Ajax')
        {
            $catStr=db_filter($cat_id);

            $sql="SELECT * from items  {$catStr} {$lastStr}   order by id DESC limit 12";
          }   
    
    	else
		{
           $catStr=($cat_id!=0 ? "AND category_id=".$cat_id."":"");

			$sql="SELECT * from items where  stock > 0 {$lastStr} {$catStr}  order by id DESC limit 12";
		}

		$items = mysqli_query($DB_CONN, $sql) or die(mysqli_error($DB_CONN));
		if($items && mysqli_num_rows($items)>0)
		{ 	$count=0;
			  while($item = mysqli_fetch_assoc($items))
			  { $count++;
				$data[$count]['id'] =$itemID= $item['id'];
				$data[$count]['itemOldPrice'] = '';
				$data[$count]['sale'] = '';
				$data[$count]['name'] = mb_convert_encoding(substr($item['name'],0,30), 'UTF-8', 'UTF-8');
				$data[$count]['Link'] = getLink($item['name'], $itemID,'i');
				$data[$count]['title'] = $item['title'];
                if($for=='category_Ajax')
                { $data[$count]['description'] = $item['de_description'];}

				$data[$count]['image'] = $siteURL.'/image_p.php?id='.$itemID.'&thumb&format=.jpg';
				$data[$count]['price'] = $currPrefix.number_format($item['price'], 2).$currPostfix;
				$data[$count]['new']=(strtotime($item['add_datetime']) > strtotime('-7 day')? "New":"");
				$data[$count]['rating']=RatingPoints($itemID);
				if(date('Y-m-d')<=$item['discount_date'])
				{
				    $data[$count]['sale'] = 'Sale';
					$data[$count]['itemOldPrice'] =  $currPrefix.number_format($itemPrice, 2).$currPostfix;;
					$data[$count]['itemPrice'] = $currPrefix.number_format($item['discount_price'], 2).$currPostfix;
         			
			     }
			       $data[$count]['sale_span']=(!empty($data[$count]['sale']) || !empty($data[$count]['new']) ? '<span>'.$data[$count]['sale'].' '.$data[$count]['new'].'</span>':'');
			  }	
				
			 $data['last_id']=$itemID;
			 $data['status']=true;
				return $data;
		}
		else
		 {
			return false;
		}
    
    }





    function product_details($itemID)
    {   global $currPrefix;
    	global $currPostfix;
		global $DB_CONN;
		global $siteURL;

    	$data=array();
        $data['itemID']=$itemID;
        
		$data['sale_span']='';
		$data['itemImages']=array();
		$data['itemImagesT']=array(); 
        $data['itemColorSelStr_id']=array();
        $data['sizes']=array();       
       $query = mysqli_query($DB_CONN, "select *,(select name from categories where id=items.category_id limit 1) as cat_name from items where id='{$itemID}' limit 1") or die(mysqli_error($DB_CONN));
        if($query && mysqli_num_rows($query)>0)
        {
            $result = mysqli_fetch_assoc($query);
            $data['itemName'] = $result['name'];
            $data['itemDescription'] = $result['full_description'];
            $data['ditemDescription'] = $result['description'];
            $data['catID'] = $result['category_id'];
            $data['cat_name'] = $result['cat_name'];
            $data['itemImageT'] = $siteURL.'/image_p.php?id='.$itemID.'&thumb&format=.jpg';
            $data['itemImage'] = $siteURL.'/image_p.php?id='.$itemID.'&format=.jpg';
            $data['itemOldPrice'] = '';
            $data['itemSale'] = '';
            $data['itemPrice']= $currPrefix.number_format($result['price'], 2).$currPostfix;
            $data['variation']=$result['variation'];
            $data['rating']=RatingPoints($itemID);
            if(date('Y-m-d')<=$result['discount_date'])
            {
                $data['itemSale'] = 'Sale';
                $data['itemOldPrice'] = $currPrefix.number_format($result['price'], 2).$currPostfix;;
                $data['itemPrice'] = $currPrefix.number_format($result['discount_price'], 2).$currPostfix;
            }
            $data['itemImgStr'] = '';
            $i = 1;
            $query2 = mysqli_query($DB_CONN, "select * from item_images where item_id='{$itemID}'") or die(mysqli_error($DB_CONN));
            while($result2 = mysqli_fetch_assoc($query2))
            {
                $data['itemImagesT'][] = $siteURL.'/image_pi.php?id='.$result2['id'].'&thumb&format=.jpg';
                $data['itemImages'][] = $siteURL.'/image_pi.php?id='.$result2['id'].'&format=.jpg';
            
            }

        
            $query3 = mysqli_query($DB_CONN, "select * from item_colors where item_id='{$itemID}'") or die(mysqli_error($DB_CONN));
            if(($query3 && mysqli_num_rows($query3)>0) && ($data['variation']!=NULL) && ($data['variation']!='0'))
            {
            
                while($result3 = mysqli_fetch_assoc($query3))
                {           
                    $color_name = mysqli_query($DB_CONN, "select * from colors where id={$result3['color_id']}") or die(mysqli_error($DB_CONN));
                    if($color_name && mysqli_num_rows($color_name)>0)
                    {
                        while($color= mysqli_fetch_assoc($color_name))
                        {


                            $data['itemColorSelStr_id'][$result3['color_id']]=$color['name'];
                            }

                     }

               }
            }
            
                  $size = mysqli_query($DB_CONN, "select sizes.id,sizes.name from sizes inner join item_sizes ON sizes.id=item_sizes.size_id where item_sizes.item_id='{$itemID}'") or die(mysqli_error($DB_CONN));
                    if($size && mysqli_num_rows($size)>0)
                    {
                        while($SIZE= mysqli_fetch_assoc($size))
                        {

                            $data['sizes'][$SIZE['id']]=$SIZE['name'];
                            }

                    }


              $data['sale_span']=(!empty($data['sale']) || !empty($data['new']) ? '<span>'.$dat['sale'].' '.$data['new'].'</span>':'');
       

       			return $data;      
         }
         else
         {
         	return false;
         }
         	

    }





    function getRelatedProducts($ItemID,$CatID)
    {
    	global $currPrefix;
    	global $currPostfix;
		global $DB_CONN;
		global $siteURL;
		$ProductStr='';
		$data=array();
		if(!empty($ItemID) && !empty($CatID))
		{
			$sql ="select * from items where id!='{$ItemID}' and category_id='{$CatID}' and stock > 0 order by rand() limit 8";


		$items = mysqli_query($DB_CONN, $sql) or die(mysqli_error($DB_CONN));
		if($items && mysqli_num_rows($items)>0)
		{ 	
			  while($item = mysqli_fetch_assoc($items))
			  { 
				$data['id'] =$itemID= $item['id'];
				$data['itemOldPrice'] = '';
				$data['title'] = $item['title'];
				$data['sale'] = '';
				$data['name'] = substr($item['name'],0,30);
				$data['Link'] = getLink($item['name'], $itemID,'i');
				$data['imageT'] = $siteURL.'/image_p.php?id='.$itemID.'&format=.jpg';
				$data['price']= $currPrefix.number_format($item['price'], 2).$currPostfix;
				$data['new']=(strtotime($item['add_datetime']) > strtotime('-7 day')? "New":"");
				$data['rating']=getItemRating($itemID);
				if(date('Y-m-d')<=$item['discount_date'])
				{
				    $data['sale'] = 'Sale';
					$data['itemOldPrice'] =  $currPrefix.number_format($data['price'], 2).$currPostfix;;
					$data['price'] = $currPrefix.number_format($item['discount_price'], 2).$currPostfix;
         			
			     }
			       $data['sale_span']=(!empty($data['sale']) || !empty($data['new']) ? '<span>'.$data['sale'].' '.$data['new'].'</span>':'');
			 
                         $ProductStr.= '<div class="col-lg-4">
                                <div class="single_product categorie">
                                    <div class="product_thumb">
                                        <a href="'.$data['Link'].'"><img class="thumb_" src="'.$data['imageT'].'" alt=""></a>
                                        <div class="product_discount">
                                           '.$data['sale_span'].'
                                        </div>
                                        <div class="product_action">
                                            <ul>
                                                <li><a onclick="wishlistAdd('.$itemID.')" title=" Add to Wishlist "><i class="fa fa-heart"></i></a></li>
                                                <li><a onclick="cartAdd('.$itemID.',0, 1)" title=" Add to cart "><i class="fa fa-shopping-cart"></i></a></li>
                                            </ul>
                                        </div>
                                        <div class="quick_view">
                                            <a onclick="quick_view('.$itemID.')" title="Quick view"><i class="fa fa-search"></i></a>
                                        </div>

                                    </div>
                                    <div class="product_content">
                                        <div class="samll_product_ratting">
                                            <ul>'.$data['rating'].'</ul>
                                        </div>
                                        <div class="small_product_name">
                                            <a title="'.$data['title'].'" href="'.$data['Link'].'">'.$data['name'].'</a>
                                        </div>
                                        <div class="small_product_price">
                                            <span class="new_price"> '.$data['price'].'</span>
                                            <span class="old_price"> '.$data['itemOldPrice'].' </span>
                                        </div>
                                    </div>
                                <div class="product_d_quantity mb-20">  <button type="submit" onclick="cartAdd('.$itemID.',0, 1,0)" ><i class="fa fa-shopping-cart"></i> add to cart</button></div>
                                </div>
                            </div>';

			  }	
				
 
	     	}
    
         }
     	return $ProductStr;
     } 





	function Category_products($whereStr,$for,$last_id=0)
	{  
		global $DB_CONN;
		global $currPrefix;
		global $currPostfix;
		global $siteURL;
		$data = array();
		$data['gridProductStr'] = '';
    	$data['largeProductStr'] = '';
		$data['lastItemID'] = '';
		$productStr = '';
		$productCru ='';
		$lastItemID = '0';
		$lastStr=($last_id!=0 ? "AND id < ".$last_id."":"");
		
		$sql=$query = "select * from items {$whereStr} {$lastStr} order by id desc limit 12";

		$items = mysqli_query($DB_CONN, $sql) or die(mysqli_error($DB_CONN));
		if($items && mysqli_num_rows($items)>0)
		{
				
		    while($item = mysqli_fetch_assoc($items))
        	{   $discount_percentage='';
                $lastItemID = $itemID = $item['id'];
                $itemName = substr($item['name'],0,30);
                $itemDescription = $item['de_description'];
                $itemLink = getLink($itemName, $itemID,'i');
                $itemTitle=$item['title'];
                $itemImage = $siteURL.'/image_p.php?id='.$itemID.'&thumb&format=.jpg';
                $itemImage_ = $siteURL.'/image_p.php?id='.$itemID.'&format=.jpg';
                $itemQV = $siteURL.'/quickview.php?id='.$itemID;
                $itemOldPrice = '';
                $itemNew = '';
                if(strtotime($item['add_datetime']) > strtotime('-7 day'))
                {
                    $itemNew = 'New';
                }
                $itemSale = '';
                
                $last_item_price = $item['price'];
                $itemPrice = $currPrefix.number_format($item['price'], 2).$currPostfix;
                 if(date('Y-m-d')<=$item['discount_date'])
                  {
                    $itemSale = 'Sale';
                    $ds=$item['price']-$item['discount_price'];
                    
                    $discount_percentage=($ds/$item['price'])*100 ."%";                    
                    $itemPrice = $currPrefix.number_format($item['discount_price'], 2).$currPostfix;

                      $itemOldPrice = $currPrefix.number_format($item['price'], 2).$currPostfix;
                    }
                   	$sale_span=(!empty($itemNew) || !empty($itemSale) || !empty($discount_percentage)? '<span>'.$itemNew.' '.$itemSale.' '.$discount_percentage.'</span>':'');

                           $rateStr=getItemRating($itemID);

                            if($for=="category")
		              	   	{

                                     $data['gridProductStr'].= '<div class="col-lg-3 col-md-4 col-sm-6">
                                            <div class="single_product categorie">
                                                <div class="product_thumb">
                                                    <a href="'.$itemLink.'">
                                                <img class="thumb_" src="'.$itemImage_.'" alt="">
                                                </a>
                                                    <div class="product_discount">'.
                               							                 
                                                    	$sale_span
                                                    .'</div>
                                                    <div class="product_action">
                                                        <ul>
                                                            <li><a onclick="wishlistAdd('.$itemID.')" title=" Add to Wishlist "><i class="fa fa-heart"></i></a></li>
                                                            <li><a onclick="cartAdd('.$itemID.',0, 1)" title=" Add to cart "><i class="fa fa-shopping-cart"></i></a></li>
                                                        </ul>
                                                    </div>
                                                    <div class="quick_view">
                                                        <a onclick="quick_view('.$itemID.')" title="Quick view"><i class="fa fa-search"></i></a>
                                                    </div>

                                                </div>
                                                <div class="product_content">
                                                    <div class="samll_product_ratting">
                                                        <ul>'.
                                                        $rateStr
                                                        .'</ul>
                                                    </div>
                                                    <div class="small_product_name">
                                                        <a title="'.$itemTitle.'" href="'.$itemLink.'">'.$itemName.'</a>
                                                    </div>
                                                    <div class="small_product_price">
                                                        <span class="new_price"> '.$itemPrice.' </span>
                                                        <span class="old_price">  '.$itemOldPrice.'  </span>
                                                    </div>
                                                </div>
                                    <div class="product_d_quantity mb-20">  <button type="submit" onclick="cartAdd('.$itemID.',0, 1,0)" ><i class="fa fa-shopping-cart"></i> add to cart</button></div>
                                            
                                            </div>
                                        </div>';


                     $data['largeProductStr'].='<div class="single_product categorie">   
                                        <div class="row cate_tab_product">
                                            <div class="col-lg-4 col-md-6 col-sm-6">
                                                <div class="product_thumb">
                                                    <a href="'.$itemLink.'"><img src="'.$itemImage_.'" alt=""></a>
                                                    <div class="product_discount">
                                                       '.$sale_span.'
                                                    </div>

                                                    <div class="quick_view categorie_view">
                                                        <a onclick="quick_view('.$itemID.')" title="Quick view"><i class="fa fa-search"></i></a>
                                                    </div>

                                                </div>
                                            </div>
                                            <div class="col-lg-8 col-md-6 col-sm-6">
                                                <div class="product_content">
                                                    <div class="samll_product_ratting">
                                                        <ul>'.$rateStr.'</ul>
                                                    </div>
                                                    <div class="small_product_name categorie_name">
                                                        <a title="Printed Summer Dress" href="single-product.html"> Faded Short Sleeves T-shirt </a>
                                                    </div>
                                                    <div class="small_product_price categorie_prie mb-10">
                                                        <span class="new_price"> '.$itemPrice.'</span>
                                                        <span class="old_price">'.$itemOldPrice.'</span>
                                                    </div>
                                                    <div class="single__product_drsc" style="max-width:90%">
                                                        '.$itemDescription.'
                                                    </div>
                                                    <div class="product_action action_categorie mb-10">
                                                        <ul>
                                                            <li><a onclick="wishlistAdd('.$itemID.')" title=" Add to Wishlist "><i class="fa fa-heart"></i></a></li>
                                                            <li><a onclick="cartAdd('.$itemID.',0, 1)" title=" Add to cart "><i class="fa fa-shopping-cart"></i></a></li>
                                                        </ul>
                                                    </div>
                                                    <div class="product_in_stock">
                                                        <span> In stock </span>
                                                    </div>
                                                </div>
                                     <div class="product_d_quantity mb-20">  <button type="submit" onclick="cartAdd('.$itemID.',0, 1,0)" ><i class="fa fa-shopping-cart"></i> add to cart</button></div>
                                       
                                            </div>
                                        </div> 
                                    </div>';

            				}

            
       					   
			}
		 }
     
     	$data['lastItemID'] = $lastItemID;
		return $data;

     }






    function cart_total()
    {
        $total=0;
        if(isset($_SESSION["cart"]) && !empty($_SESSION["cart"]))
        {
            foreach ($_SESSION["cart"] as $item)
            {
                $total += ($item["qty"]*$item["price"]);
            }
        }
        return $total;
    }



    function getCartStr()
    {
        global $currPrefix;
        global $currPostfix;
        global $siteURL;
        global $DB_CONN;
        $cartStr = '';

        $cartTotal = $currPrefix.number_format(cart_total(), 2).$currPostfix;
        $cartLink = $siteURL.'/cart.php';
        $checkOutLink = $siteURL.'/checkout.php';
        $cartStr = '';
        
        $cartStr .= ' 
        <span class="cart__quantity"> '.count($_SESSION['cart']).'</span>
        <div class="mini_cart cart_left">';
        
        foreach($_SESSION['cart'] as $index => $value)
        {
            $itemLink = getLink($value['name'], $value['id'],'i');
            $itemImg = $siteURL.'/image_p.php?id='.$value['id'].'&thumb';
       
            $itemPrice = $currPrefix.($value['price'] * $value['qty']).$currPostfix;
            
                          $cartStr .= ' 
                                        <div class="cart_item">
                                           <div class="cart_img">
                                               <a href="'.$cartLink.'"> <img src="'.$itemImg.'" alt="'.$value['name'].'" title="'.$value['name'].'" ></a>
                                           </div>
                                            <div class="cart_info">
                                                <a href="'.$itemLink.'">'.$value['name'].'</a>
                                                <span class="cart_price">'.$itemPrice.'</span>
                                                <span class="quantity">Qty: '.$value['qty'].'</span>
                                            </div>
                                            <div class="cart_remove">
                                                <a title="Remove this item" href="#" onclick="cartDel('.$index.')"><i class="fa fa-times-circle"></i></a>
                                            </div>
                                        </div>';
                                         }
                            
        $cartStr .= '               <div class="cart_total">
                                            <span> Total </span>
                                            <span class="prices"> '.$cartTotal.'  </span>
                                        </div>
                                        <div class="cart_button pt-20">
                                            <a href="'.$checkOutLink.'"> Check out</a>
                                        </div></div>';


        return $cartStr;
    
    }






    function getSCart()
    {
        global $currPrefix;
        global $currPostfix;
        global $siteURL;
        //$colorArr = getColorArr();
        $cartTotal = $currPrefix.number_format(cart_total(), 2).$currPostfix;
        $cartStr = '';
        $cartStr = '';
    
        if(isset($_SESSION["cart"]) && !empty($_SESSION["cart"]))
        {
            foreach($_SESSION['cart'] as $index => $value)
            {
                $itemLink = getLink($value['name'], $value['id'],'i');
                $itemImg = $siteURL.'/image_p.php?id='.$value['id'].'&thumb';
                $itemPrice = $currPrefix.($value['price'] * $value['qty']).$currPostfix;
                $cartStr .= '
                   <tr id="'.$index.'">
                                                   <td class="product_remove"><a  onclick="cartDel('.$index.','.$index.')"><i class="fa fa-trash-o"></i></a></td>
                                                    <td class="product_thumb"><a href="'.$itemLink.'"><img src="'.$itemImg.'" alt="'.$value['name'].'" title="'.$value['name'].'" /></a></td>
                                                    <td class="product_name"><a href="'.$itemLink.'">'.$value['name'].'</a></td>
                                                    <td class="product-price">'.$currPrefix.$value['price'].$currPostfix.'</td>
                                                    <td class="product_quantity">
                                                    <input min="0" max="100" type="number" name="quantity[]" id="product_qty'.$index.'"  value="'.$value['qty'].'">
                                                     <a  title="Update Cart" onClick="cartUpd('.$index.')">
                                                    <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTzDyBnYgfGBKgTeZdwBcC4_hY5TrtH-WV9LcOvP6sy7XeUTvoA" style="width:40px;height:50px" /></a>
                                                   
                                 <input type="hidden" name="product_id[]" id="product_id'.$index.'" value="'.$value['id'].'" />
                                <input type="hidden" name="product_color_id[]" id="pcolor_id'.$index.'" value="'.$value['color_id'].'" />
                                 <input type="hidden" name="itemSize[]" id="itemSize_id'.$index.'" value="'.$value['size_id'].'" />
                                
                                                    </td>
                                                    <td class="product_total">'.$itemPrice.'</td>


                                                </tr>';

                            }
        }
        
        else
        {
            $cartStr .= '<tr><td colspan="6" class="text-center">You don\'t have any items in your cart yet!</td></tr>';
        }
        return $cartStr;
    }


        function get_quick_view($ID)
        { $product=array();
          $data=array();
           $Product=product_details($ID);
            if (!$Product) {
             $data['status']=false;
             $data['STR']='';
            }
            else
            {   $i=2;
                $tmb_img='';
                $img_='';
                $data['STR']='
                                    <div class="col-lg-5 col-md-5 col-sm-12">
                                        <div class="modal_tab">  
                                            <div class="tab-content" id="pills-tabContent">

            
                                           <div class="tab-pane fade show active" id="tab1" role="tabpanel" >
                                                    <div class="modal_tab_img">
                                                        <a href="#"><img src="'.$Product['itemImage'].'" alt=""></a>    
                                                    </div>
                                                </div>

                                            ';
                                             

                                            foreach ($Product['itemImages'] as $key => $value) {
                                            $tmb_img.='
                                                    <li>
                                                         <a class="nav-link" data-toggle="tab" href="#tab'.$i.'" role="tab" aria-controls="tab2" aria-selected="false"><img src="'.$Product['itemImagesT'][$key].'" alt=""></a>
                                                    </li>';

                                            $img_.= '<div class="tab-pane fade" id="tab'.$i++.'" role="tabpanel">
                                                    <div class="modal_tab_img">
                                                        <a href="#"><img src="'.$value.'" alt=""></a>    
                                                    </div>
                                                </div>';        


                                            }
                 
                                           $data['STR'].= $img_.'  </div>
                                            

                                            <div class="modal_tab_button">    
                                                <ul class="nav product_navactive" role="tablist">
                                                    <li >
                                                        <a class="nav-link active" data-toggle="tab" href="#tab1" role="tab" aria-controls="tab1" aria-selected="false"><img src="'.$Product['itemImageT'].'" alt=""></a>
                                                    </li>
                                                    '.$tmb_img.'                      

                                                </ul>
                                            </div>    
                                        </div>  
                                    </div> 
                                    <div class="col-lg-7 col-md-7 col-sm-12">
                                        <div class="modal_right">
                                            <div class="modal_title mb-15">
                                                <h2 id="quick_view_name">'.$Product['itemName'].'</h2> 
                                            </div>
                                            <div class="modal_price mb-10">
                                                <span class="new_price" id="quick_view_price">'.$Product['itemPrice'].'</span>    
                                                <span class="old_price" id="quick_view_oldPrice">'.$Product['itemOldPrice'].'</span>    
                                            </div>
                                            <div class="modal_content mb-10">
                                                <p id="quick_view_detail">'.$Product['ditemDescription'].'</p>    
                                            </div>';

                                            if (count($Product['sizes'])>0) 
                                            {
                                              $data['STR'].=  '<div class="product_d_size mb-20">
                                               <label for="group_1">Size</label>
                                                <div class="col-sm-4">
                                                <select name="size_id"   id="group_1_size" onchange="set_size_id_quick()">
                                                <option value="0">Select Size</option>';


                                                    foreach ($Product['sizes'] as $key => $value) 
                                                    { 
                                                      $data['STR'].='<option value="'.$key.'">'.$value.'</option>';

                                                     }
                                                 $data['STR'].='</select>
                                                                </div></div>';

                                              }

                    $variations='';
                    $color_id=0;
                     if(($Product['variation']!=NULL) && ($Product['variation'] !='0') && count($Product['itemColorSelStr_id'])>0){
                           
                           $variations.= '<div class="product_d_size mb-20">
                                <label for="group_1">'.$Product['variation'].'</label>';

                                $variations.= '<div class="col-sm-4">
                                <select name="color_id"  id="group_1" onchange="set_color_id_quick()"> 
                                <option value="0">Select '.$Product['variation'].'</option>';
                                $start=true;
                                foreach ($Product['itemColorSelStr_id'] as $key => $value) 
                                {  
                                    if($start)
                                        {$color_id=$key;
                                         $start=false;}

                                    $variations.= '<option value="'.$key.'">'.$value.'</option>';
                                
                                    
                                }
                                $variations.= '</select></div>';

                            $variations.= '</div>'; 
                        }



                                           $data['STR'].= $variations

                                           .'<div class="modal_add_to_cart mb-15">
                                                <form onsubmit="return submit_()">
                                                    <input min="0" max="100" step="1" id="quick_view_qty"   value="1" type="number">
                                                    <button  onclick="cartAdd_quick('.$Product['itemID'].')">add to cart</button>
                                                </form>
                                            </div>   
                                            <div class="modal_description mb-15">
                                                <p>'.$Product['itemDescription'].'</p>    
                                            </div> 
                                        </div>    
                                    </div>';    
                                

            }

           return $data;
        }






    function getWishlist()
    {
        global $currPrefix;
        global $currPostfix;
        global $siteURL;
  
        $wishlistStr = '';
    
        if(isset($_SESSION["wishlist"]) && !empty($_SESSION["wishlist"]))
        {
            foreach($_SESSION['wishlist'] as $index => $value)
            {
                $itemLink = getLink($value['name'], $value['id'],'i');
                $itemImg = $siteURL.'/image_p.php?id='.$value['id'].'&thumb';
                $itemPrice = $currPrefix.$value['price'].$currPostfix;
                $wishlistStr .= '
                        <tr id="'.$index.'">
                                           <td class="product_remove"><a onclick="wishlistDel('.$index.','.$index.')">×</a></td>
                                            <td class="product_thumb"><a href="'.$itemLink.'"><img src="'.$itemImg.'" alt="'.$value['name'].'" title="'.$value['name'].'" /></a></td>
                                            <td class="product_name"><a href="'.$itemLink.'">'.$value['name'].'</a></td>
                                            <td class="product-price">'.$itemPrice.'</td>
                                            <td class="product_quantity stock">In Stock</td>
                                            <td class="product_add_cart "><a onclick="cartAdd('.$value['id'].',0, 1,0)">Add To Cart</a></td>
                                            

                                        </tr>';
                                

                 

                            }
        }
        
        else
        {
            $wishlistStr .= '<tr><td colspan="6" class="text-center">You don\'t have any items in your Wishlist yet!</td></tr>';
        }
        return $wishlistStr;
    }



?>