<?php
$variable = $_GET['Listing'];
$variable1 = str_replace("&","%26",$variable); 

$tableName="Wines2";

$con = mysqli_connect('localhost', 'mayabeac_wine', '3]eGo-r(Scru',"mayabeac_WineList");
        if (mysqli_connect_errno()) {
            echo"
                Failed to connect to the MySQL DB:".mysqli_connect_error();
            }
           else{


}
 
mysqli_query($con, "SET NAMES 'utf8'");

if(wonderplugin_is_device('Windows, Mac, Linux')){
$leftPad = 40; 
$rightPad = 40;
}

elseif(wonderplugin_is_device('iPad')){
$leftPad = 20; 
$rightPad = 20;
}
else{
$leftPad = 0; 
$rightPad = 0;
}
//echo $leftPad;

//$leftPad = 20; 
//$rightPad = 20;
//$singlePage="single-item/";

echo"<style> .listView {width: 100%; max-width: 800px; text-align: left; padding-right: ".$rightPad."px; padding-left: ".$leftPad."px; padding-top: 0px; padding-bottom: 0px; margin: auto; }</style>";


 	echo "<body>";
        echo "<p class='listView'><span style=' padding-top: 0px; padding-bottom: 10px; display: inline-block; font-weight: bold; text-align: left; width:85%; line-height: 150%; font-size: 200%'>".$variable."</span></p>";

     	$sql="SELECT * FROM ".$tableName." WHERE OutOfStock=0 AND Archived=0 AND LeaveOffMenu=0 AND QtyInStock > 0 AND (Category ='".$variable."' OR Category2 = '".$variable."' OR Category3 ='".$variable."' OR Category4 ='".$variable."' OR Category5 = '".$variable."' OR Category6 ='".$variable."') AND WineType != 'Glass' ORDER BY WinePrice";
      	$records1=mysqli_query($con, $sql);
      	
    
        $wineCount = 0;
      	while($wines=mysqli_fetch_assoc($records1)){
       
 if(is_null($wines['WhosFavorite'])){
         	$favorite="";
          	}   
          else{
          $favorite="<a href='/byperson/?Listing=".$wines['WhosFavorite']."&listType=byVarietal&identifier=".$variable."'>".$wines['FavoriteImage']."</a>";
          	}
          $wineCount=$wineCount+1;	          
          if($wines['WineVintage']==0){
          	
            $vintage=NULL;	
          }
          else{
          	$vintage=$wines['WineVintage'];
          }
            if($wines['QtyInStock'] < 3){  
          $lowStock = "* ";
          }
          else{
          $lowStock = "";
           }  

          if($wines['WineSize']<750 AND $wines['WineSize']!=0){
          if($wines['WineSize']==375){                
                $sizeinfo="&nbsp;(half bottle)";
             }
             else{
              $sizeinfo="&nbsp;(small bottle)";
               }          
           }
          else{
               $sizeinfo="";
          }

  if (wonderplugin_is_device('Windows,Mac,Linux,iPad')){
$singlePage="single-item/";
}
else{
$singlePage="singleitem-smallscreen/";
}
        

           $wineID="<b><a href='/".$singlePage."?WineID=".$wines['ID']."&listType=byVarietal&listName=".$variable1."&linkCount=1#wine".$wineCount."'>".$lowStock.$wines['WineName'].$sizeinfo."&emsp;".$vintage."&emsp;".$favorite."</a></b>";


// echo "<div style='line-height: 140%;'>";
             echo "<p class='listView'><span style='display: inline-block; font-size: 1.25em; text-align: left; width:85%;'>".$wineID."</span>";
             echo "<a class='anchor' id='wine".$wineCount."'></a>"; 
                $winePrice="<b>$".$wines['WinePrice']."</b>";
                echo "<span style='display: inline-block; font-size: 1.25em; text-align: right; width:15%;'>".$winePrice."</span></p>"; 
             
               
               $wineCountry=$wines['WineCountry'];
               if(!empty($wines['WineRegion'])){
                  $wineCountry = $wineCountry.">".$wines['WineRegion'];
                  if(!empty($wines['WineSubRegion'])){
                  $wineCountry = $wineCountry.">".$wines['WineSubRegion']; 
                  }
                }
               

               if($wines['WineVarietal']!=""){
                              
                       $wineVarietal=$wines['WineVarietal'];
                      
                      echo "<p  class = 'listView' style = 'font-size:1.1em; padding-top: 0px; line-height: 120%'>".$wineVarietal."</p>";

                  }

		echo "<p class = 'listView' style = 'font-size:1.1em; padding-top: 0px; padding-bottom: 15px;  line-height: 120%'>".$wineCountry."</p>"; 
                
                
              // echo "<br>";
                        	
      	//  echo "</div>";
}

echo "<br><p class = 'listView' style='line-spacing: 90%; font-size: .8em; padding-top: 0px; padding-bottom: 0px;'>All prices are in Belize Dollars and include 12.5% GST (Sales Tax).  BZ$2 = US$1</p>";
echo "<p class = 'listView' style='line-spacing: 90%; font-size: .8em; padding-top: 0px; padding-bottom: 0px;'>* Limited Quantities Available</p>";
echo "</body>";