$variable = $_GET['Listing'];

$connection = mysql_connect('localhost', 'root', 'admin');
mysql_query("SET NAMES 'utf8'");
mysql_select_db('WineList'); 
mysqli_set_charset($connection, 'utf8');

//$backButton = "[maxbutton id='12']";
//echo "<div class='fixedBack'>";
 //      echo do_shortcode($backButton);   
//echo "</div>";
$sortButton="";
      if($variable=="WhitePrice" || $variable=="RedPrice" ||  $variable=="WhitesAZ" ||  $variable=="RedsAZ" ){

           if($variable=="WhitePrice"){
                 $winetype="White";
                 $sorttype="WinePrice";
                 $winetitle="White Wines (by price)";
                 $sortButton="[maxbutton id='10' url='http://192.168.104.254/wordpress/byProfile/?Listing=WhitesAZ']";
           }
           elseif($variable=="RedPrice"){
                $winetype="Red";
                $sorttype = "WinePrice";
               $winetitle="Red Wines (by price)";
               $sortButton="[maxbutton id='10' url='http://192.168.104.254/wordpress/byProfile/?Listing=RedsAZ']";
           } 
           elseif($variable=="WhitesAZ"){
                $winetype="White";
                $sorttype="WineName";
               $winetitle="White Wines (A - Z)"; 
               $sortButton="[maxbutton id='11' url='http://192.168.104.254/wordpress/byProfile/?Listing=WhitePrice']";
           }
           elseif($variable=="RedsAZ"){
                $winetype="Red";
                $sorttype="WineName";
               $winetitle="Red Wines (A - Z)"; 
               $sortButton="[maxbutton id='11' url='http://192.168.104.254/wordpress/byProfile/?Listing=RedPrice']";
           }
           
           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 QtyInStock>0 AND WineType = '".$winetype."' ORDER BY ".$sorttype;
      	   $records=mysql_query($sql);
      	
      	   while($wines=mysql_fetch_assoc($records)){
        
        	
          
          if($wines['WineVintage']==0){
          	
            $vintage=NULL;	

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

            if($wines['WineSize']<750){
                $sizeinfo="&nbsp;(small bottle)";
          }
          else{
               $sizeinfo="";
          }


           $wineID="<b><a href='http://192.168.104.254/wordpress/single-item?WineID=".$wines['ID']."&listType=byProfile&listName=".$variable."&linkCount=1'>".$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>0 AND WineType!='Glass' ORDER BY WinePrice";
      	$records1=mysql_query($sql);

      	 echo "<p><b><font size='+2'>".$variable."</font></b></p>";
      	while($wines=mysql_fetch_assoc($records1)){
        
        	
          
          if($wines['WineVintage']==0){
          	
            $vintage=NULL;	
          }
          else{
          	$vintage=$wines['WineVintage'];
          }
            if($wines['QtyInStock'] < 3){
          $lowStock = "* ";
          }
          else{
          $lowStock = "";
           }
          if($wines['WineSize']<750){
                $sizeinfo="&nbsp;(small bottle)";
          }
          else{
               $sizeinfo="";
          }	
	        $wineID="<b><a href='http://192.168.104.254/wordpress/single-item?WineID=".$wines['ID']."&listType=byProfile&listName=".$variable."&linkCount=1'>".$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>"; 
    
                  

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