<?php
//$variable = $_GET['Listing'];
$variable = "Beer";
$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'");
$leftPad=30;
$rightPad=0;

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


     	$sql="SELECT * FROM ".$tableName." WHERE OutOfStock=0 AND Archived=0 AND LeaveOffMenu=0 AND (Category ='".$variable."' OR Category2 = '".$variable."' OR Category3 ='".$variable."' OR Category4 ='".$variable."' OR Category5 = '".$variable."' OR Category6 ='".$variable."') AND WineType != 'Glass' ORDER BY WineCountry, SortOrder";
      	$records1=mysqli_query($con, $sql);
      	
    
        $wineCount = 0;
      	while($wines=mysqli_fetch_assoc($records1)){
        $wineCount=$wineCount+1;	          
          if($wines['WineVintage']==0){
          	
            $vintage=NULL;	
          }
          else{
          	$vintage=$wines['WineVintage'];
          }
            if($wines['QtyInStock'] < -10000){  
          $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="";
          }
$sizeinfo="";
$singlePage="Beer/";
/*
  if (wonderplugin_is_device('Windows,Mac,Linux,iPad')){
$singlePage="Beer/";
}
else{
$singlePage="Beer/";
}
  */

if($wineCount==1){

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

}
else{

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

if($prevCountry != $wines['WineCountry']){
   if($wines['WineCountry'] == 'Belize'){
          echo "<b><p class='listView'><span style='display: inline-block; text-align: left; width:100%; line-height: 100%; font-size: 150%; padding-bottom: 0px;'>Belizean Beers</span></p></b>";
    }
    elseif($importCount==0){
          echo "<b><p class='listView'><span style='display: inline-block; text-align: left; width:100%; line-height: 100%; font-size: 150%; padding-bottom: 0px; padding-top: 15px;'>Imported Beers</span></p></b>";
          $importCount = $importCount + 1;
     }
}

$prevCountry = $wines['WineCountry'];

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

               if($importCount > 0 AND $wines['WineCountry']!=""){
                              
                       $wineCountry=$wines['WineCountry'];
                      
                      echo "<p class = 'listView' style = 'font-size:1.1em; padding-top: 0px; padding-bottom: 0px;  line-height: 100%'>".$wineCountry."</p>";  

                  }
                  else{
                      $wineRegion=$wines['WineRegion'];
                    echo "<p class = 'listView' style = 'font-size:1.1em; padding-top: 0px; padding-bottom: 0px;  line-height: 100%'>".$wineRegion."</p>";  
                   }

		//echo "<p style='line-height: 10%'></p>";
                
                
               //echo "<br>";
                        	
      	 // echo "</div>";
}

      	echo "<br><p class='listView'><font size='-1'>All prices are in Belize Dollars and include 12.5% GST (Sales Tax).&nbsp; BZ$2 = US$1<font></p>";