<?php


$variable = $_GET['WineID'];
$listType = $_GET['listType'];
$listName = $_GET['listName'];
$linkCount = $_GET['linkCount'];
$food1 = trim($_GET['food1']);
$food2 = trim($_GET['food2']);
$food3 = trim($_GET['food3']);
$food4 = trim($_GET['food4']);
$wineNumber = 0;
$screenWidth = 1000;



if(wonderplugin_is_device('iPhone')){
$screenWidth = 400;
$device = "iPhone";
}
elseif(wonderplugin_is_device('Windows')){
$screenWidth = 1000;
$device = "Windows";
}
elseif(wonderplugin_is_device('iPad')){
$screenWidth = 1000;
$device = "iPad";
}
elseif(wonderplugin_is_device('Mac')){
$screenWidth = 1000;
$device = "Mac";

}
elseif(wonderplugin_is_device('Android')){
$screenWidth = 1000;
$device = "Android";
}

//echo "Width ",$screenWidth;


if($food1!=""){
$xfood1=substr($food1, (strlen($food1)-2)*-1);
}
if($food2!=""){
$xfood2=substr($food2, (strlen($food2)-2)*-1);
}
if($food3!=""){
$xfood3=substr($food3, (strlen($food3)-2)*-1);
}
if($food4!=""){
$xfood4=substr($food4, (strlen($food4)-2)*-1);
}


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


}

if (wonderplugin_is_device('iPhone')){
$singlePage="single-item/";
}
else{
$singlePage="single-item/";
}


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


if($listType=="byVarietal"){
      $sql="SELECT * FROM Wines WHERE (Category = '".$listName."' OR Category2 = '".$listName."' OR Category3 = '".$listName."') AND QtyInStock!=-1 AND WineType != 'Glass' ORDER BY WinePrice";
}
elseif($listType=="byCountry"){

      $sql="SELECT * FROM Wines WHERE WineCountry = '".$listName."' AND QtyInStock!=-1 AND WineType != 'Glass' ORDER BY CASE 
               WHEN WineType = 'Sparkling' THEN 1
               WHEN WineType = 'White' THEN 2
               WHEN WineType = 'Rose' THEN 3
               WHEN WineType = 'Red' THEN 4
               ELSE 5
         END,  WinePrice";
          

}
elseif($listType=="byProfile"){

      if($listName=="WhitesAZ"){
            $sql="SELECT * FROM Wines WHERE WineType = 'White' AND QtyInStock!=-1 ORDER BY WineName";
            $showName="All Whites A - Z";
            $listTypeName="White Wines";
      }
       elseif($listName=="WhitePrice"){
            $sql="SELECT * FROM Wines WHERE WineType = 'White' AND QtyInStock!=-1 ORDER BY WinePrice";
            $showName="All Whites by Price";
            $listTypeName="White Wines";
      }
      elseif($listName=="RedsAZ"){
            $sql="SELECT * FROM Wines WHERE WineType = 'Red' AND QtyInStock!=-1 ORDER BY WineName";
            $showName="All Reds A - Z";
            $listTypeName="Red Wines";
      }
      elseif($listName=="RedPrice"){
            $sql="SELECT * FROM Wines WHERE WineType = 'Red' AND QtyInStock!=-1 ORDER BY WinePrice";
            $showName="All Reds by Price";
            $listTypeName="Red Wines";
      }    
      
       else{
      
            $sql="SELECT * FROM Wines WHERE (WineProfile1 = '".$listName."' OR WineProfile2 = '".$listName."') AND QtyInStock!=-1 AND WineType != 'Glass' ORDER BY WinePrice";
     $showName="";
      } 
}
elseif($listType=="byGlass"){

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

//$sql="SELECT * FROM Wines WHERE (WineType = 'Glass' AND (AvailableToday = -1 OR AvailableOnRequest = -1 OR AvailablePremium = -1)) OR (WineType!='Glass' AND WineSize > 0 AND WineSize < 750) ORDER BY AvailableToday, AvailablePremium, AvailableOnRequest DESC, WinePrice";
            $showName="Wines by Glass";
            $listTypeName="Glass";

     
}
elseif($listType=="byFood"){

$foodList = "('".$food1."', '".$food2."', '".$food3."', '".$food4."')";

$sql="SELECT * FROM Wines WHERE ((WineType != 'Glass' AND QtyInStock!=-1) OR (WineType = 'Glass' AND AvailableToday = -1))  AND (FoodPairing1 IN ".$foodList." OR FoodPairing2 IN ".$foodList." OR FoodPairing3 IN ".$foodList." OR FoodPairing4 IN ".$foodList." OR FoodPairing5 IN ".$foodList." OR FoodPairing6 IN ".$foodList." OR FoodPairing7 IN ".$foodList." OR FoodPairing8 IN ".$foodList." OR FoodPairing9 IN ".$foodList." OR FoodPairing10 IN ".$foodList."  OR FoodPairing11 IN ".$foodList."  OR FoodPairing12 IN ".$foodList."  OR FoodPairing13 IN ".$foodList."  OR FoodPairing14 IN ".$foodList."  OR FoodPairing15 IN ".$foodList.")";

$showName="Food Pairings";
$listTypeName="Food Matches";
}



// Read all wines to determine length of list.
// Need to sort items based on match score (desc) then price (asc). Wines by the glass will appear first as they have 6 added
// to the base score whereas other wines start at 0

       $IDarray=array();
       $wineCount=0;
      $foodWines = array();      //two dimensional array 1= name, 2 = food1, 3 = food2, 4 = food3, 5 = food4, 6 = score, 7 = country, 8 = varietal, 9 = btl or glass, 10 = WineID, 11 = Price. 12 = Desc1, 13 = Desc2, 14= Desc3, 15 = Desc 4, 16 = Image1, 17= Image2, 18 = QtyInStock, 19 = Eyes, 20 = Nose, 21 = Mouth, 22 = Vintage, 23 = Alcohol Content, 24 = Pairing Suggestion , 25=Cases Produced, 26 = WineRegion, 27 = Wine Subregion, 28 = Nationality


       $records1=mysqli_query($con, $sql);
       while ($row1 = mysqli_fetch_assoc($records1)) {
            
      $wineCount = $wineCount+1;

      $foodWines[$wineCount][1] = $row1['WineName'];
      $foodWines[$wineCount][6] = 0;
      $foodWines[$wineCount][7]  = $row1['WineCountry'];
      $foodWines[$wineCount][8] = $row1['WineVarietal'];
      $foodWines[$wineCount][10] = $row1['ID'];
      $foodWines[$wineCount][11] = $row1['WinePrice'];
      //$foodWines[$wineCount][12] = $row1['PairingValue1'];
      //$foodWines[$wineCount][13] = $row1['PairingValue2'];
      //$foodWines[$wineCount][14] = $row1['PairingValue3'];
      //$foodWines[$wineCount][15] = $row1['PairingValue4'];
      $foodWines[$wineCount][32] = $row1['Desc1'];
      $foodWines[$wineCount][33] = $row1['Desc2'];
      $foodWines[$wineCount][34] = $row1['Desc3'];
      $foodWines[$wineCount][35] = $row1['Desc4'];
      $foodWines[$wineCount][16] = $row1['Image1'];
      $foodWines[$wineCount][17] = $row1['Image2'];
      $foodWines[$wineCount][18] = $row1['QtyInStock'];
      $foodWines[$wineCount][19] = $row1['Eyes'];
      $foodWines[$wineCount][20] = $row1['Nose'];
      $foodWines[$wineCount][21] = $row1['Mouth'];
      $foodWines[$wineCount][22] = $row1['WineVintage'];
      $foodWines[$wineCount][23] = $row1['AlcoholContent'];
      $foodWines[$wineCount][24] = $row1['PairingSuggestion'];
      $foodWines[$wineCount][25] = $row1['CasesProduced'];
      $foodWines[$wineCount][26] = $row1['WineRegion'];
      $foodWines[$wineCount][27] = $row1['WineSubregion'];
      $foodWines[$wineCount][28] = $row1['WineNationality'];  
      $foodWines[$wineCount][29] = $row1['WineType']; 
      $foodWines[$wineCount][30] = $row1['WineSize']; 
      $foodWines[$wineCount][36] = $row1['AvailableToday'];
      $foodWines[$wineCount][37] = $row1['AvailablePremium'];
      $foodWines[$wineCount][38] = $row1['AvailableOnRequest'];  
       $foodWines[$wineCount][39] = $row1['SoldAs'];

      if( $foodWines[$wineCount][29] == "Glass"){
          $foodWines[$wineCount][6] = 100;
          $foodWines[$wineCount][9] = 0;
          }
      else{
            $foodWines[$wineCount][9] = 1;
            $foodWines[$wineCount][6] = 0;
      }
if($listType == 'byFood'){

// only sort the array if this is a food match selection

$minPairing = 0;

for($x = 1; $x <= 15; $x++){

if($food1!=""){
         if($row1['FoodPairing'.$x]==$food1){
          
          $foodWines[$wineCount][12] = $row1['PairingValue'.$x] * -1 + 6; 
          if($foodWines[$wineCount][12]==6){
           $foodWines[$wineCount][12]=5;
          } 
          if($foodWines[$wineCount][12]==0 OR is_null($foodWines[$wineCount][12])){
             $foodWines[$wineCount][12]=5; 
          }
         $foodWines[$wineCount][6] =$foodWines[$wineCount][6]+$foodWines[$wineCount][12];
         }   
}

if($food2!=""){
         if($row1['FoodPairing'.$x]==$food2){
         $foodWines[$wineCount][13] = $row1['PairingValue'.$x] * -1 + 6; 
         if($foodWines[$wineCount][13]==6){
           $foodWines[$wineCount][13]=5;
          } 
         if($foodWines[$wineCount][13]==0 OR is_null($foodWines[$wineCount][13])){
             $foodWines[$wineCount][13]=1; 
          }
         $foodWines[$wineCount][6] =$foodWines[$wineCount][6]+$foodWines[$wineCount][13];
         }   
}

if($food3!=""){
         if($row1['FoodPairing'.$x]==$food3){
         $foodWines[$wineCount][14] = $row1['PairingValue'.$x] * -1 + 6; 
          if($foodWines[$wineCount][14]==6){
           $foodWines[$wineCount][14]=5;
          } 
         if($foodWines[$wineCount][14]==0 OR is_null($foodWines[$wineCount][14])){
             $foodWines[$wineCount][14]=1; 
          }
        $foodWines[$wineCount][6] =$foodWines[$wineCount][6]+$foodWines[$wineCount][14];
         }   
}
if($food4!=""){
         if($row1['FoodPairing'.$x]==$food4){
         $foodWines[$wineCount][15] = $row1['PairingValue'.$x] * -1 + 6;
          if($foodWines[$wineCount][15]==6){
           $foodWines[$wineCount][15]=5;
          } 
          if($foodWines[$wineCount][15]==0 OR is_null($foodWines[$wineCount][15])){
             $foodWines[$wineCount][15]=1; 
          }
         $foodWines[$wineCount][6] =$foodWines[$wineCount][6]+$foodWines[$wineCount][15];
         }   
   }   

}  

//echo $foodWines[$wineCount][1]." ".$foodWines[$wineCount][12]." ".$foodWines[$wineCount][13]." ".$foodWines[$wineCount][14]." ".$foodWines[$wineCount][15]."<br>";

if($foodWines[$wineCount][12] <3  AND  $foodWines[$wineCount][13] < 3 AND $foodWines[$wineCount][14] < 3 AND $foodWines[$wineCount][15] < 3){
//echo "Skipping".$foodWines[$wineCount][1]."<br>";
$wineCount=$wineCount - 1;

}

}
       
}

//sort Array
if($listType=='byFood'){
foreach ($foodWines as $key => $row) {
    $score[$key]  = $row[6];
    $winePrice[$key] = $row[11];
}

// With the use of the column keys you can now sort entire array by these columns and keep the row index value intact if they are non-numeric. This is good if your using some kind of hashed index.

array_multisort($score, SORT_DESC, $winePrice, SORT_DESC, $foodWines);
}


     // echo $wineCount;
       
if($listType == 'byFood'){
$xstart = 0;
$totalWines = $wineCount-1;
}
else{
$xstart = 1;
$totalWines = $wineCount;

}



 for($x = $xstart; $x <= $totalWines; $x++){

if($listType == 'byFood'){
$y=$x+1;
}
else{
$y=$x;
}       

   if($listType=="byCountry"){

               $listTypeName=$foodWines[$x][28];
          

         }
         elseif($listType=="byProfile" AND $listTypeName!=""){


         }
        elseif($listType=="byProfile" AND $listTypeName==""){

          $listTypeName=$listName;
         }
        elseif($listType=="byVarietal"){
          $listTypeName=$listName;
        }


       if($listType=='byCountry'){

              $browsing=$y." of ".$wineCount."&nbsp;<a href='http://www.bistrowinelist.com/".$listType."/?Listing=".$listName."'><b>".$listTypeName." Wines</b></a>";


           
             if($foodWines[$x][29]=='Rose'){
             $showName=$listName."&nbsp;(Rosé)";
             }
             else{
             $showName=$listName."&nbsp;(".$foodWines[$x][29]. " Wines)";
             }
        }
        elseif($listType=='byVarietal'){
                  $browsing=$y." of ".$wineCount."&nbsp;<a href='http://www.bistrowinelist.com/".$listType."/?Listing=".$listName."'><b>".$listTypeName."</b></a>";

                  $showName=$listName;
         }
         elseif($listType=='byProfile'){
            $browsing=$y." of ".$wineCount."&nbsp;<a href='http://www.bistrowinelist.com/".$listType."/?Listing=".$listName."'><b>".$listTypeName." </b></a>";

            $showName=$listName;
         }
         elseif($listType=="byGlass"){
         $browsing=$y." of ".$wineCount."&nbsp;<a href='http://www.bistrowinelist.com/".$listType."/?Listing=".$listName."'><b> Wines By The Glass</b></a>";

         }
         
         elseif($listType=="byFood"){

           $browsing=$y." of ".$wineCount."&nbsp;<a href='http://www.bistrowinelist.com/foodmatches/?food1=".$food1."&food2=".$food2."&food3=".$food3."&food4=".$food4."'><b> Food Matches</b></a>";
           
          }

if($browsing==""){

        $browsing=$y." of ".$wineCount."&nbsp;<a href='http://www.bistrowinelist.com/".$listType."/?Listing=".$listName."'><b>".$listTypeName."</b></a>";
}

        
        echo "<body>";


echo "<a class='anchor' id='wine".$y."'></a>";

//set to 500 now so it does not change - effectively disabling

        if(strlen($foodWines[$x][1]."&emsp".$foodWines[$x][22])>500){
         $nameFont="1.1em";
         }
        else{
        $nameFont="1.35em";
        }

  if($foodWines[$x][29] == 'Glass' OR $foodWines[$x][39] == 1){
        $winePrice = "<b>$".$foodWines[$x][11]."/glass</b>"; 
        }
        else{
        $winePrice= "<b>$".$foodWines[$x][11]."</b>";
        }


      
if ($device == 'Windows' OR $device == 'Mac' OR $device == 'Linux'){
        $bodytext="justify";
        
       echo "<table>";
       echo "<colgroup>";
        echo "<col span='1' style='width: 15%;'>";
        echo "<col span='1' style='width: 84%;'>";
        echo "</colgroup>";


      


  echo "<tr><td style='text-align: center; font-size: 1.5em;  font-weight: bold;'>".$winePrice."</td><td style='text-align: left; font-size: 1.0em;  font-weight: normal;'>".$browsing."</td></tr>";

echo"<tr>";
   
 echo "<td style='vertical-align: top; text-align: center;'><img style='width: 28vw; height: 60vh; object-fit: contain;' src='".$foodWines[$x][16]."' alt='WineImage'></td>";
       
         

         if($foodWines[$x][22] != 0){
  	         echo "<td style='vertical-align:top; font-weight: normal; text-align: ".$bodytext."; line-height: 1.25em; padding-right: 20px; font-size: 1.35em'><span style='font-weight: bold'>".$foodWines[$x][1]."&emsp; ".$foodWines[$x][22]."</span><br>";
        }
        else{
               echo "<td style='vertical-align:top; font-weight: normal; text-align: ".$bodytext."; line-height: 1.25em; padding-right: 20px; font-size: 1.35em'><span style='font-weight: bold'>".$foodWines[$x][1]."</span><br>";
         }


        }

elseif($device == 'iPad' OR $device == 'Android'){
   
  $bodytext="left";

      echo "<table>";

       echo "<colgroup>";
        echo "<col span='1' style='width: 30%;'>";
        echo "<col span='1' style='width: 69%;'>";
        echo "</colgroup>";


  
  echo "<tr><td style='text-align: center; font-size: 1.5em;  font-weight: normal;'>".$winePrice."</td><td style='text-align: left; font-size: 1.0em;  font-weight: normal;'>".$browsing."</td></tr>";

 echo"<tr>";
   
      echo "<td style='vertical-align: top; text-align: center;'><img style='width: 37vw; height: 65vh; object-fit: contain;' src='".$foodWines[$x][16]."' alt='WineImage'></td>";
       
         

     if($foodWines[$x][22] != 0){
  	         echo "<td style='vertical-align:top; font-weight: normal; text-align: ".$bodytext."; line-height: 1.25em; padding-right: 20px; font-size: 1.35em'><span style='font-weight: bold'>".$foodWines[$x][1]."&emsp; ".$foodWines[$x][22]."</span><br>";
        }
        else{
               echo "<td style='vertical-align:top; font-weight: normal; text-align: ".$bodytext."; line-height: 1.25em; padding-right: 20px; font-size: 1.35em'><span style='font-weight: bold'>".$foodWines[$x][1]."</span><br>";
         }


        }

      elseif($device == 'iPhone'){

   $bodytext="left";
   


 
 echo "<table>";

echo "<tr><td style='display:block-inline; text-align: center; font-size: 1.1em;  font-weight: normal;'>".do_shortcode($prevWine)."&emsp;".$browsing."&emsp;".do_shortcode($nextWine)."</td></tr></table>";

 
      
      echo "<table>";
       echo "<colgroup>";
        echo "<col span='1' style='width: 35%;'>";
        echo "<col span='1' style='width: 64%;'>";
        echo "</colgroup>";  

         echo"<tr>";
   
      echo "<td style='vertical-align: top; text-align: center; font-size: 1.25em;'><span style='font-weight:bold'>".$winePrice."</span><br><br><img style='width: 30vw; height: 70vh; object-fit: contain;' src='".$foodWines[$x][16]."' alt='WineImage'></td>";
       
         

     if($foodWines[$x][22] != 0){
  	         echo "<td style='vertical-align:top; font-weight: normal; text-align: ".$bodytext."; line-height: 1.25em; padding-right: 20px; font-size: 1.35em'><span style='font-weight: bold'>".$foodWines[$x][1]."&emsp; ".$foodWines[$x][22]."</span><br>";
        }
        else{
               echo "<td style='vertical-align:top; font-weight: normal; text-align: ".$bodytext."; line-height: 1.25em; padding-right: 20px; font-size: 1.35em'><span style='font-weight: bold'>".$foodWines[$x][1]."</span><br>";
         }


        }
         

         //  ///Common Code Here
        

         
  	if($listType=="byFood"){

 $foodarray = array($row['FoodPairing1'], $row['FoodPairing2'], $row['FoodPairing3'], $row['FoodPairing4'], $row['FoodPairing5'], $row['FoodPairing6'], $row['FoodPairing7'], );
         $goodfoods = "";
         $badfoods = "";

          if(in_array($food1, $foodarray)) {
           
                $goodfoods = $goodfoods.", ".$xfood1;
           }
           elseif($food1!='none'){
                  $badfoods = $badfoods.", ".$xfood1;
            }

           if(in_array($food2, $foodarray)) {
           
                $goodfoods = $goodfoods.", ".$xfood2;
           }
           elseif($food2!='none'){
                  $badfoods = $badfoods.", ".$xfood2;
            }

   if(in_array($food3, $foodarray)) {
           
                $goodfoods = $goodfoods.", ".$xfood3;
           }
           elseif($food4!='none'){
                  $badfoods = $badfoods.", ".$xfood3;
            }

   if(in_array($food4, $foodarray)) {
           
                $goodfoods = $goodfoods.", ".$xfood4;
           }
           elseif($food4!='none'){
                  $badfoods = $badfoods.", ".$xfood4;
            }
            
        if($goodfoods!=""){
        $goodfoods=substr($goodfoods, (strlen($goodfoods)-2)*-1);
         echo "<font size='+1'><b>We suggest with: </b>".$goodfoods."<br><font>";
        }

//alternate good food list - show all food listed as pairing with this wine
      





        if($badfoods!=""){
        $badfoods=substr($badfoods, (strlen($badfoods)-2)*-1);
 // leave off for now    echo "<font size='+1'><b>Mabye not so good with: </b>".$badfoods."<br><font>";
        }


          

         }
       
        
        $varietalText=$foodWines[$x][8];
        if ($varietalText != ""){
            if (strpos($foodWines[$x][1], $varietalText) > 0){
                $varietalText="";
            }
        }

            // echo $foodWines[$x][8]."<br>";

         if($varietalText != ""){
               echo "<span style='font-weight: normal font-size: 1.25em'>".$varietalText."</span>";
               echo "<br>";
         }
   
    
 if($foodWines[$x][7] != ""){

    if($foodWines[$x][26] != ""){
        echo "<span style='font-weight: normal font-size: 1.25em'>".$foodWines[$x][7].">".$foodWines[$x][26]."</span><br><br>";
    }
    else{
        echo "<span style='font-weight: normal font-size: 1.25em'>".$foodWines[$x][7]."</span><br><br>";
    }
}
else{
    echo "<br>";
}
// echo "<span style='font-weight: normal font-size: 1.25em'>".$foodWines[$x][7].">".$foodWines[$x][26]."</span><br><br>";
    
//if($foodWines[$x][29]!='Glass' AND $foodWines[$x][18] > 0){   
// echo "<font size='+1'><span style='font-weight: bold'>In our Cellar: &nbsp;</span><span style='font-weight: normal'>".$foodWines[$x][18]."</span><br><font>";
//}

    if (!empty($foodWines[$x][19])) {
       echo "<font size='+1'><span style='font-weight: bold'>Eyes: &nbsp;</span><span style='font-weight: normal'>".$foodWines[$x][19]."</span><br><font>";
      }
  
  	if (!empty($foodWines[$x][20])) {
       echo "<font size='+1'><span style='font-weight: bold'>Nose: &nbsp;</span><span style='font-weight: normal'>".$foodWines[$x][20]."</span><br><font>";
      }
  
  	if (!empty($foodWines[$x][21])) {
       echo "<font size='+1'><span style='font-weight: bold'>Mouth: &nbsp;</span><span style='font-weight: normal'>".$foodWines[$x][21]."</span><br><font>";
      }
   
      if (!empty($foodWines[$x][23]) AND $foodWines[$x][23]!=0) {
       echo "<font size='+1'><span style='font-weight: bold'>Alcohol Content: &nbsp;</span><span style='font-weight: normal'>".$foodWines[$x][23]."%</span><br><font>";
      }
  	if (!empty($foodWines[$x][34])) {
       echo "<font size='+1'><span style='font-weight: bold'>Ratings: &nbsp;</span><span style='font-weight: normal'>".$foodWines[$x][34]."</span><br><font>";
      }
    
  	if (!empty($foodWines[$x][33])) {
       echo "<font size='+1'><text align='justify'><span style='font-weight: bold'>Why we like it: &nbsp;</span><span style='font-weight: normal'>".$foodWines[$x][33]."</span><br><font>";
      }
   if($screenWidth > 500){     
  	if (!empty($foodWines[$x][24])) {
       echo "<br><font size='+1'><span style='font-weight: bold'>Pairs with: &nbsp;</span><span style='font-weight: normal'>".$foodWines[$x][24]."</span><br><font>";
      }
}
if($screenWidth > 500){    
  	if (!empty($foodWines[$x][32])) {
       echo "<br><font size='+1'><span style='font-weight: bold'>From the Winemaker: &nbsp;</span><span style='font-weight: normal'>".$foodWines[$x][32]."</span><br><font>";
      }
}
      echo "<br><font size='-1'><span style='font-weight: normal'>All prices are in Belize Dollars and include 12.5% GST (Sales Tax). BZ$2 = US$1</span><font>";
    
    echo "</td>";

    // echo "<td valign='top' align='left'>";
    // echo do_shortcode($nextWine);
    // echo "</td>";

  	echo "</tr>";
	echo "</table>";
     echo "<br><br><br><br>";
}
echo "</body>";