<?php
$variable = $_GET['Listing'];

  $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{


}
$variable = str_replace('%20',' ', $variable);
 
if (wonderplugin_is_device('Windows, Mac, Linux')){
$leftPad = 75; //$screenWidth/2-400;
$rightPad = 0; //$screenWidth/2-400;
}
else{
$leftPad = 0; 
$rightPad = 0;
}
//echo $leftPad;

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>";


mysqli_query($con, "SET NAMES 'utf8'");
     echo "<body>";
      echo "<p class='listView'><span style=' padding-top: 0px; display: inline-block; font-weight: bold; text-align: left; width:85%; line-height: 150%; font-size: 200%'>".$variable."</span></p>";
       $wineTypes = array();
       $wineTypes[1] = "Sparkling";
       $wineTypes[2] = "White";
       $wineTypes[3] = "Rose";
       $wineTypes[4] = "Red";
       $wineTypes[5] = "Dessert";
       $wineTypes[6] = "Port";
       $wineCount=0;
        for ($x = 1; $x <= 6; $x++) {
	

     	$sql="SELECT * FROM Wines WHERE AvailableForSale = -1 AND (QtyInStock>0 OR SoldAs = 1) AND WineCountry='".$variable."' AND WineType ='".$wineTypes[$x]."' ORDER BY WinePrice";
      	$records1=mysqli_query($con, $sql);
 
      	$recordcount=1;
        
      	while($wines=mysqli_fetch_assoc($records1)){
              $wineCount=$wineCount+1;
               if($recordcount == 1){
               
              if($wineTypes[$x]=="Rose"){
                 $wineType2="Rosé";
               }
               elseif($wineTypes[$x]=="Sparkling"){
               $wineType2="Sparkling and Champagne";
                }
                elseif($wineTypes[$x]=="Dessert"){
               $wineType2="Dessert Wines, Port & Liqueurs"; 
                }
               else{
               $wineType2=$wineTypes[$x];
               }

                 echo "<b><p class='listView'><span style='font-size: 1.5em; text-align: left; width:85%; line-height: 150%; padding-top: 0px; display: inline-block;'>".$wineType2."</span></p></b>";  

	       $recordcount = 2;
               }
          //echo "<div style='line-height: 100%;'>";
          if($wines['WineVintage']==0){
          	
            $vintage=NULL;	
          }
          else{
          	$vintage=$wines['WineVintage'];
          }
         if($wines['QtyInStock'] < 3 AND $wines['WineType']!='Glass' AND $wines['WineType']!='Dessert' AND $wines['QtyInStock'] !=0 ){  
          $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(is_null($wines['WhosFavorite'])){
         	$favorite="";
          	}   
          else{
          $favorite="<a href='http://www.bistrowinelist.com/byperson/?Listing=".$wines['WhosFavorite']."&listType=byCountry&identifier=".$variable."'>".$wines['FavoriteImage']."</a>";
          	}

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

           $wineID="<b><a href='http://www.bistrowinelist.com/".$singlePage."?WineID=".$wines['ID']."&listType=byCountry&listName=".$variable."&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; padding-top: 0px; width:85%;'>".$wineID."</span>";
             echo "<a class='anchor' id='wine".$wineCount."'></a>"; 
                $winePrice="<b>$".$wines['WinePrice']."</b>";
                echo "<span style='padding-top: 0px; font-size: 1.25em; text-align: right; width:15%;'>".$winePrice."</span></p>"; 
             
               $wineCountry=$wines['WineRegion'];

               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>";