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


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

$sortButton="";

      if($variable=="WhitePrice" || $variable=="RedPrice" ||  $variable=="WhitesAZ" ||  $variable=="RedsAZ" ){

           if($variable=="WhitePrice"){
                 $winetype="White";
                 $sorttype="WinePrice";
                 $winetitle="White Wines (by price)&emsp;<a href='http://www.bistrowinelist.com/byProfile/?Listing=WhitesAZ'>Sort A-Z</a>";
                 //$sortButton="[maxbutton id='5' url='http://www.bistrowinelist.com/byProfile/?Listing=WhitesAZ']";
                 $newvariable = "WhitePrice";
           }
           elseif($variable=="RedPrice"){
                $winetype="Red";
                $sorttype = "WinePrice";
               $winetitle="Red Wines (by price)&emsp;<a href='http://www.bistrowinelist.com/byProfile/?Listing=RedsAZ'>Sort A-Z</a>";
               //$sortButton="[maxbutton id='5' url='http://www.bistrowinelist.com/byProfile/?Listing=RedsAZ']";
               $newvariable = "RedPrice";
           } 
           elseif($variable=="WhitesAZ"){
                $winetype="White";
                $sorttype="WineName";
               $winetitle="White Wines (A - Z)&emsp;<a href='http://www.bistrowinelist.com/byProfile/?Listing=WhitePrice'>Sort by Price</a>";
               //$sortButton="[maxbutton id='4' url='http://www.bistrowinelist.com/byProfile/?Listing=WhitePrice']";
               $newvariable = "WhitesAZ";
           }
           elseif($variable=="RedsAZ"){
                $winetype="Red";
                $sorttype="WineName";
               $winetitle="Red Wines (A - Z)&emsp;<a href='http://www.bistrowinelist.com/byProfile/?Listing=RedPrice'>Sort by Price</a>";
               //$sortButton="[maxbutton id='4' url='http://www.bistrowinelist.com/byProfile/?Listing=RedPrice']";
               $newvariable = "RedsAZ";
           }
           
           echo "<p><b><font size='+2'>".$winetitle."</font></b>";
            
            

            //if(!empty($sortButton)){          
            //echo "&emsp;";
            //echo do_shortcode($sortButton);
            //}           
            echo "</p>";

           
           $sql="SELECT * FROM Wines WHERE AvailableForSale = -1 AND QtyInStock>0 AND WineType = '".$winetype."' ORDER BY ".$sorttype;
      	   $records=mysqli_query($con, $sql);
      	   $wineCount = 0;
      	   while($wines=mysqli_fetch_assoc($records)){
           $wineCount=$wineCount+1;
        	
          
          if($wines['WineVintage']==0){
          	
            $vintage=NULL;	

          }
          else{
          	$vintage=$wines['WineVintage'];
              
          }
         if($wines['QtyInStock'] < 3 AND $wines['WineType']!='Glass'){
          $lowStock = "* ";
          }
          else{
          $lowStock = "";
           }

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


         

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

           $wineID="<b><a href='http://www.bistrowinelist.com/".$singlePage."?WineID=".$wines['ID']."&listType=byProfile&listName=".$newvariable."&linkCount=1#wine".$wineCount."'>".$lowStock.$wines['WineName'].$sizeinfo."&emsp;".$vintage."</a></b>";

         
             echo "<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><br>";
                echo "<span style='font-size: 1.25em; text-align: right; width:15%; line-height: 150%; display: inline-block;'>".$winePrice."</span><br>"; 
               if($wines['WineVarietal']!=""){
                              
                       $wineVarietal=$wines['WineVarietal']."<br>";
                       echo "<span style='text-align: left; width:85%; line-height: 120%; display: inline-block;'>".$wineVarietal."</span><br>";

                  }
               $wineCountry=$wines['WineCountry'].">".$wines['WineRegion'];
               
                if(substr($wineCountry, strlen($wineCountry)-1,1)==">"){

                       $wineCountry=substr($wineCountry, 0, strlen($wineCountry)-1);
                }
                      $wineCountry=$wineCountry."<br>";

		echo "<span style='text-align: left; width:85%; line-height: 120%; display: inline-block;'>".$wineCountry."</span><br>";
             
              
               echo "<br>";

         }
 

          
             

         

}
elseif($variable=="Glass"){

$sql="SELECT * FROM Wines WHERE WineType='Glass' ORDER BY WinePrice";
      	$records1=mysqli_query($con, $sql);

      	 echo "<p><b><font size='+2'>".$variable."</font></b></p>";
         $wineCount=0;
         while($wines=mysqli_fetch_assoc($records1)){
        $wineCount=$wineCount+1;
        	
          
          if($wines['WineVintage']==0){
          	
            $vintage=NULL;	
          }
          else{
          	$vintage=$wines['WineVintage'];
          }
            if($wines['QtyInStock'] < 3 AND $wines['WineType']!='Glass'){
          $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="single-item/";
}
     

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

   echo "<span style='font-size: 1.25em; text-align: left; width:85%; line-height: 150%; display: inline-block;'>".$wineID."</span>";
	        
                 $winePrice="<b>$".$wines['WinePrice']."</b><br>";
                 echo "<span style='font-size: 1.25em; text-align: right; width:15%; line-height: 150%; display: inline-block;'>".$winePrice."</span><br>"; 
  		   if($wines['WineVarietal']!=""){
                              
                       $wineVarietal=$wines['WineVarietal']."<br>";
                       echo "<span style='text-align: left; width:85%; line-height: 120%; display: inline-block;'>".$wineVarietal."</span><br>";

                  }
	
  		$wineCountry=$wines['WineCountry'].">".$wines['WineRegion'];
             
                 if(substr($wineCountry, strlen($wineCountry)-1,1)==">"){

                       $wineCountry=substr($wineCountry, 0, strlen($wineCountry)-1);
                }
                      $wineCountry=$wineCountry."<br>";

		echo "<span style='text-align: left; width:85%; line-height: 120%; display: inline-block;'>".$wineCountry."</span><br>";
                        
             
                  echo "<br>"; 
    
                  

        }

}


else{

      

     	$sql="SELECT * FROM Wines WHERE (WineProfile1='".$variable."' OR WineProfile2='".$variable."') AND QtyInStock>-1 AND WineType!='Glass' AND AvailableForSale = -1 ORDER BY WinePrice";
$printBottleHeader = False;
      	$records1=mysqli_query($con, $sql);

         if($variable=='Rose'){
            $winetitle = "Rosé";
          }
         elseif($variable=='Sparkling'){
          $winetitle = "Sparkling & Champagne";
         }
         else{
          $winetitle = $variable;
         }
      	 echo "<p><b><font size='+2'>".$winetitle."</font></b></p>";
        $wineCount = 0;
        $headerPrinted = False;

      	while($wines=mysqli_fetch_assoc($records1)){
        $wineCount=$wineCount+1;
        	
          
          if($wines['WineVintage']==0){
          	
            $vintage=NULL;	
          }
          else{
          	$vintage=$wines['WineVintage'];
          }
            if($wines['QtyInStock'] < 3 AND $wines['WineType']!='Glass' 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)";
          }
          }
           elseif($wines['ServingSize'] != 0 AND $wines['ServingSize'] !=5){
            
               $sizeinfo=" (".$wines['ServingSize']." oz)";
            }
          else{
               $sizeinfo="";
          }	

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

if($headerPrinted==False AND $wines['SoldAs'] == 1){
$printBottleHeader = True;
$headerPrinted=True;
echo "<span style='font-size: 1.5em; text-align: left; font-weight: bold; width:85%; line-height: 150%; display: inline-block;'>By The Glass</span>";
}
elseif($wines['SoldAs'] == 0 AND $printBottleHeader==True){
$printBottleHeader=False;
echo "<span style='font-size: 1.5em; text-align: left; font-weight: bold; width:85%; line-height: 150%; display: inline-block;'>By The Bottle</span>";
}
           $wineID="<b><a href='http://www.bistrowinelist.com/".$singlePage."?WineID=".$wines['ID']."&listType=byProfile&listName=".$variable."&linkCount=1#wine".$wineCount."'>".$lowStock.$wines['WineName'].$sizeinfo."&emsp;".$vintage."</a></b>";

   echo "<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><br>";
                 echo "<span style='font-size: 1.25em; text-align: right; width:15%; line-height: 150%; display: inline-block;'>".$winePrice."</span><br>"; 
  		   if($wines['WineVarietal']!=""){
                              
                       $wineVarietal=$wines['WineVarietal']."<br>";
                       echo "<span style='text-align: left; width:85%; line-height: 120%; display: inline-block;'>".$wineVarietal."</span><br>";

                  }
	
  		$wineCountry=$wines['WineCountry'].">".$wines['WineRegion'];
             
                 if(substr($wineCountry, strlen($wineCountry)-1,1)==">"){

                       $wineCountry=substr($wineCountry, 0, strlen($wineCountry)-1);
                }
                      $wineCountry=$wineCountry."<br>";

		echo "<span style='text-align: left; width:85%; line-height: 120%; display: inline-block;'>".$wineCountry."</span><br>";
                        
             
                  echo "<br>"; 
    
                  

        }
    
  }
echo "<br><font size='-1'>All prices are in Belize Dollars and include 12.5% GST (Sales Tax).&nbsp;BZ$2 = US$1<font>";
echo "<br><font size='-1'>* Limited Quantities Available<font>";