<?php
$variable = $_GET['Listing'];
$callingPage = $_GET['listType'];
$callingType = $_GET['identifier'];
$callingurl = $_GET['url'];
$WineID = $_GET['WineID'];
$WineNum = $_GET['wine'];

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


}
$variable = str_replace('%20',' ', $variable);


if(wonderplugin_is_device('Windows, Mac, Linux')){
$leftPad = 40; //$screenWidth/2-400;
$rightPad = 40; //$screenWidth/2-400;
}
elseif(wonderplugin_is_device('iPad')){
$leftPad = 20; 
$rightPad = 20;
}
else{
$leftPad = 0; 
$rightPad = 0;
}

//echo $leftPad;
//$leftPad = 40; //$screenWidth/2-400;
//$rightPad = 40; //$screenWidth/2-400;
//$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>";

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

$sql="SELECT * FROM ".$tableName." WHERE OutOfStock=0 AND Archived=0 AND LeaveOffMenu=0 AND (QtyInStock>0 OR SoldAs = 1) AND WhosFavorite='".$variable."'";
$records1=mysqli_query($con, $sql);
while($wines=mysqli_fetch_assoc($records1)){
$favoriteicon = $wines['FavoriteImage'];           
}
  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."'s Favorites &emsp;".$favoriteicon."</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 ".$tableName." WHERE OutOfStock=0 AND Archived=0 AND LeaveOffMenu=0 AND (QtyInStock>0 OR SoldAs = 1) AND WhosFavorite='".$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['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 (wonderplugin_is_device('Windows,Mac,Linux,iPad')){
$singlePage="single-item/";
}
else{
$singlePage="singleitem-smallscreen/";
}


           $wineID="<b><a href='/".$singlePage."?WineID=".$wines['ID']."&listType=byPerson&listName=".$variable."&linkCount=1&identifier=".$callingType."&returnPage=".$callingPage."#wine".$wineCount."'>".$lowStock.$wines['WineName'].$sizeinfo."&emsp;".$vintage."</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>";
        }
      
  
}


if($callingType=="WhitePrice"){
$returnPage = "White Wines";
}
elseif($callingType=="WhitesAZ"){
$returnPage = "White Wines";
}
elseif($callingType=="RedPrice"){
$returnPage = "Red Wines";
}
elseif($callingType=="RedsAZ"){
$returnPage = "Red Wines";
}
else{
$returnPage = $callingType;
}


if(!empty ($WineNum)){
$returnCall = " href='/single-item/?WineID=".$WineID."&listType=".$callingPage."&listName=".$callingType."&linkCount=1&#wine".$WineNum."'" ;
}
else{
$returnCall = " href='/".$callingPage."/?Listing=".$callingType."'";
}

echo "<br><p class = 'listView' style='line-spacing: 90%; font-size: 1em; padding-top: 0px; padding-bottom: 0px;'><a".$returnCall.">Back to &nbsp;".$returnPage." Listing</a></p>";

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