<?php
if(!isset($_GET['screen_check']))
{
 /* This code will be executed if screen resolution has not been detected.*/
 echo "<script language='JavaScript'>
 <!-- 
 document.location=\"$PHP_SELF?screen_check=done&Width=\"+screen.width+\"&Height=\"+screen.height;
 //-->
 </script>";
}
else 
{    
 /* This code will be executed after screen resolution is detected.*/
    if(isset($_GET['Width']) && isset($_GET['Height'])) {
 // Resolution  detected
 //echo "<h1>Your screen resolution is ".$_GET['Width']." x ".$_GET['Height'].".</h1><br />";
 //Display page as per resolution
 if(($_GET['Width']>1024)&&($_GET['Height']>768)) {
 //echo "<b>This will be displayed when screen resolution is greater than 1024x768.</b>";
 }
 else {
 //Display page as per resolution
 //echo "<b>This will be displayed when screen resolution is either equal to or less than 1024x768.</b>";
 }
     }
     else {
               // Resolution not detected
     }
}

echo "<meta http-equiv='refresh' content='30'>";
$screenWidth = $_GET['Width'];
$screenHeight = $_GET['Height'];
//echo $screenWidth;
//echo "<br>";
//echo $screenHeight;
//echo "<br>";



$variable = 'Glass';

  $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="";
$wineCount=0;
for($x=1; $x<=3; $x++){ 

$wineCount1=0;
if($x==1){
$sql="SELECT * FROM Wines WHERE WineType='Glass' AND AvailableToday = -1 AND AvailableOnRequest = 0 AND AvailablePremium = 0 ORDER BY WineType2, WinePrice";
      	

}
elseif($x==2){

$sql="SELECT * FROM Wines WHERE WineType='Glass' AND AvailableToday = 0 AND AvailableOnRequest = 0 AND AvailablePremium = -1 ORDER BY WineType2, WinePrice";

}
elseif($x==3){
$sql="SELECT * FROM Wines WHERE WineSize >0 AND WineSize < 750  AND WineType!='Glass' ORDER BY WineType2, WinePrice";

}
else{
$sql="SELECT * FROM Wines WHERE WineType='Glass' AND AvailableToday = 0 AND AvailableOnRequest = -1 AND AvailablePremium = 0 ORDER BY WineType2, WinePrice";


}
echo "<div class='container'>";
 echo   "<table id='table1'>";

$records1=mysqli_query($con, $sql);
while($wines=mysqli_fetch_assoc($records1)){
        $wineCount=$wineCount+1;
        $wineCount1=$wineCount1+1;
        if($wineCount1 == 1){
            if($x==1){
                      $prevType= 0;
                      echo "<tr><td style='width: 90%; opacity: 1.0; font-weight: bold; font-size: 1.75em;'>Today's Wine By the Glass (5 oz pour)</td><td></td></tr>";
                    $opacity = 1.0;
             }
             elseif($x==2){
                       $prevType= 0;
                        echo "<tr><td style='width: 90%; opacity: 1.0; font-weight: bold; font-size: 1.75em;'>Premium Wines By the Glass</td><td></td></tr>";
                     $opacity = 1.0;
             }
             elseif($x==3){
                  $prevType= 0;
                   //echo "<tr><td style='width: 90%; opacity: 1.0; font-weight: bold; font-size: 1.75em;'>Sparkling (small bottles)</td><td></td></tr>";
                   echo "<tr><td style='width: 90%; opacity: 1.0; font-weight: bold; font-size: 1.75em;'>Sparkling</td><td></td></tr>";
                  $opacity = 1.0;

             }

              else{
                    $prevType= 0;
                     echo "<tr><td style='width: 90%; opacity: 1.0; font-weight: bold; font-size: 1.75em;'>By the Glass - On Request (2 glass minimum)</td><td></td></tr>";
                    $opacity = 0.5;
              }
         } 	
          




          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){
                 $sizeinfo="";    //$sizeinfo="&nbsp;(small bottle)";
          }
          else{
               $sizeinfo="";
          }	

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

           $wineID="<b><span style= 'opacity: ".$opacity.";'><a  href='http://www.bistrowinelist.com/".$singlePage."?WineID=".$wines['ID']."&listType=byGlass&listName=".$variable."&linkCount=1#wine".$wineCount."'>".$lowStock.$wines['WineName'].$sizeinfo."&emsp;".$vintage."</a></span></b>";
   
   if($prevID != $wines['WineType2']){
      $prevID = $wines['WineType2'];
      if($prevID == 1){

         echo "<tr><td style='opacity: ".$opacity."; font-weight: bold; font-size: 1.25em; line-height: 50%;'>White</td><td></td></tr>";
       }
       elseif($prevID == 2){

         echo "<tr><td style='opacity: ".$opacity."; font-weight: bold; font-size: 1.25em; line-height: 50%;'>Red</td><td></td></tr>";
       }
       elseif($prevID == 3){

           echo "<tr><td style='opacity: ".$opacity."; font-weight: bold; font-size: 1.25em; line-height: 50%;'>Sparkling</td><td></td></tr>";
       }
       elseif($prevID == 4){

              echo "<tr><td style='opacity: ".$opacity."; font-weight: bold; font-size: 1.25em; line-height: 50%;'>Rosé</td><td></td></tr>";
       }
    }
echo "</table></div>";

   echo "<span style='font-size: 1.25em; text-align: left; width:85%; line-height: 100%; 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>"; 
    
                
        }
        echo "<br>";
}



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