<?php
    require_once 'check_security.php';

    
           
           
       if(isset($_GET['game']) or isset($_GET['join']) ){
        $gamecode=$_GET['game'];
        $matchid= $_GET['join'];
         $resultmat = mysqli_query($conn,"SELECT * FROM matches WHERE m_id='$matchid'"); 
        if(isset($_GET['joinii'])){
            if($_GET['joinii']==$_GET['join']){
                    $m_id=$matchid;
          $joinmatch = mysqli_query($conn,"SELECT * FROM matches WHERE m_id = '$m_id' and match_status='1'");
          $arra=array();
      while($rowss=mysqli_fetch_assoc($joinmatch)){
          $arra=$rowss;
      }
      if(sizeof($arra)<=0){
        header("Location: /fairb/match.php?game=$gamecode");
      }else{

        header("Location: /fairb/match.php?join=$m_id");
      }
            }else{
                header("Location: /fairb/");
            }
      
      

        }
       }
        
        if($gamecode==1){
               $gamename="Bgmi Match";
               $logogg="unnamed.webp";
           }else if($gamecode==2){
              $gamename="free Fire Match"; 
              $logogg="unnamed(1).webp";
           }else if($gamecode==3){
                $gamename="Ludo King"; 
                 $logogg="unnamed(2).webp";
           }else{
                 header("Location: /fairb/");
           }
        ?>
        <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Fair Battle Match</title>
</head>
<style>
    body{
  background-color: aliceblue;
  display: block;
}
*{
  padding: 0;
margin: 0;

box-sizing: border-box;
font-family: Canva Sans,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;;
text-decoration: none;

}
div.bodycondener{
     background-color: aliceblue;
}
div.bodycondener div.headcontener{
    align-items: center;
box-shadow: 10px;
box-shadow: 0px 5px 10px cadetblue;
border: 1px solid #ccc;
background-color: darkturquoise;
}
div.bodycondener div.headcontener div.backbtn{
    display: flex;
}
div.bodycondener div.headcontener div.backbtn h3{
    align-self: center;
    color: black;
}
div.bodycondener div.headcontener div.backbtn a img{
width: 40px;
height: 40px;
margin: 10px;
}

div.bodycondener div.allmatchdiv{
  padding: 10px;
      display: block;
    
}

    

div.bodycondener div.allmatchdiv div.singlematchdiv{
  padding: 7px;
  width: var(--s-full);
  align-items: center;
box-shadow: 10px;
border-radius: 10px;
box-shadow: 0px 5px 10px cadetblue;
border: 1px solid #ccc;
background-color: white;

  
}
div.bodycondener div.allmatchdiv div.singlematchdiv div.haderbanner{
display: flex;
padding: 2px;
margin: 10px;
margin-left: 10px;


}
div.bodycondener div.allmatchdiv div.singlematchdiv div.haderbanner div.imgdiv{
  margin-left: 10px;
  margin-right: 10px;
  border-radius: 50%;


}
div.bodycondener div.allmatchdiv div.singlematchdiv div.haderbanner div.imgdiv img{
  border-radius: 50%;
}
div.bodycondener div.allmatchdiv div.singlematchdiv div.haderbanner div.titletime h3{
  margin-bottom: 5px;
}
div.bodycondener div.allmatchdiv div.singlematchdiv div.haderbanner div.totALJOIN{
  text-align: right;
  width: max-content;
  margin: auto;
 
} 
div.bodycondener div.allmatchdiv div.singlematchdiv  div.matchbody{
  margin: 0px;
}
div.bodycondener div.allmatchdiv div.singlematchdiv  div.matchbody div.threemain1{
  margin-bottom: 15px;
  display: flex;
}
div.bodycondener div.allmatchdiv div.singlematchdiv  div.matchbody div.threemain1 div.winpri{
  margin: auto;
  text-align: center;
}
div.bodycondener div.allmatchdiv div.singlematchdiv  div.matchbody div.threemain1 div.winpri h3{
  font-style:unset;
  color: #616161;
  font-size: 17px;
}
div.bodycondener div.allmatchdiv div.singlematchdiv  div.matchbody div.threemain1 div.winpri p{
  margin: 5px;
 font-size: 20px;
}
div.bodycondener div.allmatchdiv div.singlematchdiv div.footerbtn{
  margin: 10px;
   display: grid;
      grid-template-columns: repeat(1, 1fr);
      grid-gap: 2rem;
}
div.bodycondener div.allmatchdiv div.singlematchdiv div.footerbtn a {
    text-align: center;
}

div.bodycondener div.allmatchdiv div.singlematchdiv div.footerbtn a div.joindivbtn{
  margin: auto;


}
div.bodycondener div.allmatchdiv div.singlematchdiv div.footerbtn a div.joindivbtn button{
padding: 10px;
padding-left: 40px;
padding-right: 40px;
border-radius: 10px;
box-shadow: 10px;
border-radius: 10px;
border: 1px solid #e9dd36;
background-color: rgb(39, 187, 71);
color: white;
font-size: 19px;
text-align: center;
}
div.bodycondener div.divbtn{
    display: flex;
    align-items: center;
box-shadow: 10px;

box-shadow: 0px 5px 10px cadetblue;
border: 1px solid #ccc;
background-color: darkturquoise;
}
div.bodycondener div.divbtn div.singlebtn{
    margin: auto;
    width: 100%;
    
    text-align: center;
}
div.bodycondener div.divbtn div.singlebtn button{
    border: none;
    background-color: transparent;
    font-size: 19px;
    margin: 10px;
    color: white;
    cursor: pointer;
}
div.bodycondener div.divbtn div.singlebtn:hover{
    background-color: blue;
}
 .bodydivlist table{
        width: 100%;
     }
    .bodydivlist table .trtop{
        background-color: #ccc;
   
    }
    td, th {
  border: 1px solid #dddddd;
  text-align: left;
  padding: 8px;
  text-align: center;
}

tr:nth-child(even) {
  background-color: #dddddd;
}
    .bodydivlist table .trtop td{
        
        margin: 0;
        padding: 7px;
        text-align: center;
        border: 1px solid #000;
   
        background-color: #ccc;
      
      
    }
</style>
<body>
    <div class="bodycondener">
        <div class="headcontener">
            <div class="backbtn">
                <a href="/fairb/match.php?game=">
             <img src="https://fairbattle.earnmoreapp.in/adminnh/assist/icon/left.png"/>
            
             </a>
              <h3><?php echo $gamename; ?></h3>
            </div>
        </div>

        <div class="allmatchdiv">
            <?php
 while($row=mysqli_fetch_assoc($resultmat)){
     $match_statusvc=$row["match_status"];
     $match_desc=$row["match_desc"];
     $prize_description=$row["prize_description"];
     $room_descriptionuhui=$row["room_description"];
     
 ?>
   <div class="singlematchdiv">
         
   <div class="haderbanner">
     <div class="imgdiv">
       <img src="<?php echo $logogg; ?>" />
     </div>
     <div class="titletime">
       <h3><?php echo $row["match_name"]; ?></h3>
       <p><?php echo $row["match_time"]; ?></p>
     </div>
     <div class="totALJOIN">
       <p><?php echo $row["total_player"]; ?>/<?php echo $row["no_of_player"]; ?></p>
     </div>
   </div>
   
   <div class="matchbody">
     <div class="threemain1">
       <div class="winpri">
         <h3>WIN PRICE</h3>
         <p>₹<?php echo $row["win_prize"]; ?></p>
       </div>
       <div class="winpri">
         <h3>PER KILL</h3>
         <p>₹<?php echo $row["per_kill"]; ?></p>
       </div>
       <div class="winpri">
         <h3>ENTRY FEE</h3>
         <p>₹<?php echo $row["entry_fee"]; ?></p>
       </div>
     </div>
   
     <div class="threemain1">
       <div class="winpri">
         <h3>TYPE</h3>
         <p><?php echo $row["type"]; ?></p>
       </div>
       <div class="winpri">
         <h3>VERSION</h3>
         <p><?php echo $row["match_type"]; ?></p>
       </div>
       <div class="winpri">
         <h3>MAP</h3>
         <p><?php echo $row["MAP"]; ?></p>
       </div>
     </div>
   
   </div>
    <?php
     $matchid=$row['m_id'];
      $join=false;
       $jrecomatjo = mysqli_query($conn,"SELECT * FROM match_join_member WHERE member_id = '$id' and match_id='$matchid'");
           $recomarra=array();
       while($rowsre=mysqli_fetch_assoc($jrecomatjo)){
           $recomarra[]=$rowsre;
             $joinhh="";
       }
       if(sizeof($recomarra)<=0){
        
        if($match_statusvc==1){
          $rejointxt="JOIN";  
        }else{
            $rejointxt="NOT JOIN";
        }
        $rejoinhh="";
        $joinvc=true;
       }else{
  $rejointxt="JOINED";
  $rejoinhh="full";
  $joinvc=false;
        
       }
     
     ?>
   <div class="footerbtn">
    <a href="<?php echo $rejoinhh; ?>match.php?game=<?php echo $gamecode;?>&join=<?php echo $row['m_id'];?>&joinii=<?php echo $row['m_id'];?>">
       <div class="joindivbtn" >
       <button><?php echo $rejointxt; ?></button>
     </div>
     </a>
    
   
   </div>
   
               </div>
 <?php
 }
 
 ?>
 
 
 
 
            
           </div>
           <?php if($match_statusvc==1){
               
           }else{   if(sizeof($recomarra)<=0){}else{?>
<div class="dddgd" style="margin-left:50%;">
    <h3><?php echo $room_descriptionuhui ?></h3>
</div>
<?php }} ?>
           <div class="divbtn">
            <div class="singlebtn"  class="tablinks" onclick="openCity(event, 'rule')">
              <button>Rule</button>
            </div>
            <div class="singlebtn" id="up"  class="tablinks" onclick="openCity(event, 'price')">
              <button>Price</button>
            </div>
            <div class="singlebtn"  class="tablinks" onclick="openCity(event, 'player')">
              <button>Player</button>
            </div>
          
          
          </div>
          <div class="tabcontent" id="rule">
            <h3>Rules </h3>
            <?php echo $match_desc; ?>
          </div>
          <div class="tabcontent" id="price">
<h3>Poll Prices</h3>
  <?php echo $prize_description; ?>
          </div>
          <div class="tabcontent" id="player">
               <div class="bodydivlist">
        <table>
            <tbody>
        <tr class="trtop">
            <td>No.</td>
            <td>Player</td>
            <td>Won</td>
        </tr>
        <?php
        $iiii=1;
         $oooo = mysqli_query($conn,"SELECT * FROM match_join_member ORDER BY win DESc ");
          while($rowssss=mysqli_fetch_assoc($oooo)){
              if($rowssss["match_id"]==$matchid){
        ?>
        <tr >
            <td><?php echo $iiii;  $iiii=$iiii+1; ?></td>
            <td> <?php
        
        $merifh=$rowssss["member_id"];
        
         $ooogcythfo = mysqli_query($conn,"SELECT * FROM userdataa WHERE id = '$merifh'");
          while($rowssssjghj=mysqli_fetch_assoc($ooogcythfo)){
              echo $rowssssjghj["username"];
          }
              
        ?></td>
            <td>₹<?php echo $rowssss["win"]; ?></td>
        </tr>
        
        <?php      }} ?>
    </tbody>
    </table>
    </div>
    
          </div>

    </div>
</body>
<script>
    document.getElementById("up").click();
     function openCity(evt, cityName) {
        
       var i, tabcontent, tablinks;
     tabcontent = document.getElementsByClassName("tabcontent");
     for (i = 0; i < tabcontent.length; i++) {
       tabcontent[i].style.display = "none";
     }
     tablinks = document.getElementsByClassName("singlebtn");
     for (i = 0; i < tablinks.length; i++) {
       tablinks[i].className = tablinks[i].className.replace(" active", "");
     }
     document.getElementById(cityName).style.display = "block";
     evt.currentTarget.className += " active";
    
     }
     </script>
</html>