<?php
 
include('sql_details.php');
 
?>

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto|Varela+Round">
	<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
	<link rel="stylesheet" href="style.css">
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
	<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
	<script src="index.js"></script>
 

	<p id="success"></p>
  <section class="content">
<div class="container-fluid">
  
    <div class="col-lg-12 col-12">
      <div class="small-box bg-secondry shadow_block" style = " height: auto; width: 100%;" >
				
					</div>
					<div class="col-sm-6">
						<!--<a href="#addEmployeeModal" class="btn btn-success" data-toggle="modal"><i class="material-icons"></i> <span>Add New Student</span></a> -->
						<a href="JavaScript:void(0);" class="btn btn-danger" id="delete_multiple"><i class="material-icons"></i> <span>Delete All Selected</span></a>						
					</div>
                </div>
            </div>


   <section class="content">
<div class="container-fluid">
  
    <div class="col-lg-12 col-12">
      <div class="small-box bg-secondry shadow_block" style = " height: auto; width: 100%;" >
        <div class="inner">
            <h4 style="mx-auto" >
            Manage <b>Accounts</b> 
        </h4>


                <table id="example1" class="table table-bordered table-hover">
             
                <thead>
                    <tr>
						<th>
							<span class="custom-checkbox">
								<input type="checkbox" id="selectAll">
								<label for="selectAll"></label>
							</span>
						</th> 
            <th  >#</th>
            <th  >username</th>
                   
                   <th >Full name</th>
                   <th >Pkg.</th>
                   
                 
                   <th >Sponsor</th>
                   <th >Status</th>
                   <th >Products</th>
                   <th >Action</th>
                    </tr>
                </thead>
				<tbody>
				
				<?php
				$result = mysqli_query($conn,"SELECT * FROM users order by date_activation desc");
					$i=1;
					while($row = mysqli_fetch_array($result)) {
				?>
				<tr id="<?php echo $row["id"]; ?>">
				<td>
							<span class="custom-checkbox">
								<input type="checkbox" class="user_checkbox" data-user-id="<?php echo $row["id"]; ?>">
								<label for="checkbox2"></label>
							</span>
						</td>
					<td><?php echo $i; ?></td>


   <!--START OLD TABLE-->

          <td><?php echo $row['uname'] ?></td>
                      <!-- <td  ><?php 
                      if ($row['email'] == NULL) {
                        echo '-';
                      }else {
                        echo $row['email'] ;

                      } ?></td> -->
                      <td  ><?php echo $row['fname'] . ' ' .$row['lname'] ?></td>
                      <td  >
                        
                        <?php 
                      $email =  $row['email'];
                      $theusername = $row['uname'];
                      $sponsorid =  $row['sid'];

                      $active_status =  $row['active_status'];
                      $acq_pkg =  $row['package'];
                      $product_claim = $row['product_claim_status'];

    
                      if ($acq_pkg == 0) {
 
                        echo '<a href="upgrade.php?mid='.$row['id'].'&&pkg='.$row['package'].'" class="btn btn-outline-success " style="color: #fff;border-color: #ffffff; background: #CD7F32;
                           border-radius: 10px; font-weight: bold; font-size: 10px;    ">Bronze | Upgrade Account</a>';
                       
                       
                       
                       }elseif  ($acq_pkg== 1) {
                        
                         echo '<a   href="upgrade.php?mid='.$row['id'].'&&pkg='.$row['package'].'" class="btn btn-outline-success " style="color: #fff;border-color: #ffffff; background: #C0C0C0;
                         border-radius: 10px; font-weight: bold; font-size: 10px;   ">Silver | Upgrade Account</a>';
                       
                       
                       }elseif  ($acq_pkg == 2) {
                        
                         echo '<a   href="upgrade.php?mid='.$row['id'].'&&pkg='.$row['package'].'" class="btn btn-outline-success " style="color: #fff;border-color: #ffffff; background: #FFD700;
                         border-radius: 10px; font-weight: bold; font-size: 10px;    ">Gold | Upgrade Account</a>';
                       
                          }else {
                            
                                   echo '<a  href="upgrade.php?mid='.$row['id'].'&&pkg='.$row['package'].'" class="btn btn-outline-success " style="color: #fff;border-color: #ffffff; background: #404040;
                         border-radius: 10px; font-weight: bold; font-size: 10px;  ">Platinum</a>';
                       
                       
                                 }

                               //  echo '<b style=" height: 20px; font-size: 10px; padding: 0px 5px 0px 5px; " class="btn btn-success">Active </b>';
                        

                   
                     
                          ?>
             
                      
                    
                    </td>
                  
                     
                     
                     <td><?php
                      if ( $row['sid']==1 )
                      {
                            echo "Root user" ;
                      }
                      else
                      {
                        $sdata = base64_decode( $row['sid']);
                        $sid = explode(',', $sdata);
                        $semail = $sid[0];
                         $email = $semail;
                         $result2 = mysqli_query($conn , "SELECT sid FROM users WHERE uname = '$theusername'");
                         $user_data = mysqli_fetch_array($result2);
                         echo $user_data['sid']; 
                      }
                         ?>
                    
                      </td>
                      <td style="width:10%" >
                      <?php 
                      if ($row['active_status']  == 1) {

                        echo '<b style=" height: 20px; font-size: 10px; padding: 0px 5px 0px 5px; " class="btn btn-success">Active </b>';
                        
                      }else {
                          echo '<b style=" height: 20px; font-size: 10px; padding: 0px 5px 0px 5px; " class="btn btn-warning">Inactive</b>';

                      }
                         ?></td>

                         <td>

                         <?php
                          
                         if ($product_claim == 0) {
 
 echo '<a href="upgrade.php?mid='.$row['id'].'&&pkg='.$row['package'].'" class="btn btn-outline-success btn-radius" style="color: #fff;border-color: #ffffff; background: #CD7F32;
    border-radius: 10px; font-weight: bold; font-size: 10px;    ">Unclaim</a>';



}elseif  ($product_claim== 1) {
  echo '<a href="#" class="btn btn-outline-success btn-radius" style="color: #fff;border-color: #ffffff; background: #09a31d;
  border-radius: 10px; font-weight: bold; font-size: 10px;    ">Claimed</a>';


}
  ?>
  </td>



                      <!--END OLD TABLE-->
					<td>
						<a href="#editaccount" class="edit" data-toggle="modal">
							<i class="material-icons update" data-toggle="tooltip" 
							data-id="<?php echo $row["id"]; ?>"
							data-name="<?php echo $row["uname"]; ?>"
              data-fname="<?php echo $row["fname"]; ?>"
              data-lname="<?php echo $row["lname"]; ?>"
							data-email="<?php echo $row["email"]; ?>"
							data-sponsor="<?php echo $row["sid"]; ?>"
							data-city="<?php echo $row["city"]; ?>"
              data-id-p="<?php echo $row["id"]; ?>"
							title="Edit"></i>
						</a>


                                
<?php  if ($row['active_status']  == 1) {
  ?>
      <a href="#printcheq" data-toggle="modal" class="btn btn-outline-danger btn-radius printchq"> 
      <i class="fas fa-print printcheq" data-toggle="tooltip" 
							data-id-p="<?php echo $row["id"]; ?>"
					 
							title="printchq"></i>
             
						</a>
            
           
      <?php
  }else {?>
                  
<?php
}
?>
 





            <?php if ($active_status==1) {

              }else {
                
            ?>
						<a href="#deleteaccount" class="delete btn btn-outline-danger btn-radius" data-id="<?php echo $row["id"]; ?>" data-toggle="modal">
            <i class="material-icons" data-toggle="tooltip" 
						 title="Delete"></i></a>

           
            <?php  if ($row['active_status']  == 1) {
              ?>
               
                  <?php
              }else {?>
                              
            <?php
            }
            ?>
               
            
            <?php 
              }?>
                <a href="pageRefer.php?recentPage=index&&uname=<?php echo $row['uname'] ?>" 
                      class="btn btn-outline-success btn-radius" > <i class="fas fa-link"></i></a>
                    </td>
				</tr>
				<?php
				$i++;
				}
				?>
				</tbody>
			</table>
	 
        </div>
    </div>

    <!--print-->
    

    <div class="modal" id="printcheq">
            <div class="modal-dialog">
              <div class="modal-content btn-radius">
                <div class="modal-header pb-0" style="border: 0px;">

                  <h6 class="modal-title" style="font-weight: bold;">Print Cheque Format for: <br><p style="color:#f50d0d;font-size:18px;"> <?php
                   echo $row['fname'] . ' ' .$row['lname']  
                  ?> </p></h6>
                  
                </div> 
               
                <div class="modal-body pt-0 pb-0">
                <div class="col-12">

                <form method="POST" action="print.php?mid=<?php echo $row['id'] ?>" class="form-horizontal" id="quickForm" enctype="multipart/form-data">
                            
                
             	<input type="text" id="id_p" name="idp" class="form-control" >		



                <label for="datepost">Enter Cheque Date:</label>
            <input type="date" class="form-control"  id="postdate" name="postdate">
          

            <label for="datepost">Enter Amount:</label>
            <input type="number" class="form-control" id="inputName" name="check_numberformat" value="<?php echo $username; ?>" placeholder="">
                                  
                    
                                  </div> 
                          </div>

             
                <div class="modal-footer pr-0 pl-0 pb-2 pt-0" style="display: block; border: 0px">
                  <div class="row">
                    <div class="col-6">
                      <button type="button" class="btn btn-default btn-block btn-save bg-white" data-dismiss="modal">Cancel</button>
                    </div>
                    <div class="col-6">
                   <form>
                    <input type="hidden" name="save_data" value="<?php echo $row['id'] ?>">
                  
                      <input type="hidden" name="save_data" value="save">
                      <button type="submit" id="action" class="btn btn-warning btn-save btn-block">
                        <span id="button-text">Generate</span>
                      </button>
      </form>
      </div>
      </div>
      </div>
      </div>
      </div>
      </div>
    <!--end print--->
	 
	<!-- Edit Modal HTML -->
	<div id="editaccount" class="modal fade">
		<div class="modal-dialog">
			<div class="modal-content">
				<form id="update_form">
					<div class="modal-header">						
						<h4 class="modal-title">Edit Account</h4>
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					</div>
					<div class="modal-body">
						<input type="text" id="id_u" name="id" class="form-control" required>					
						<div class="form-group">
							<label>First Name</label>
							<input type="text" id="fname_u" name="fname" class="form-control" required>
						</div>
            <div class="form-group">
							<label>Last Name</label>
							<input type="text" id="lname_u" name="lname" class="form-control" required>
						</div>
						<div class="form-group">
							<label>Email</label>
							<input type="email" id="email_u" name="email" class="form-control" required>
						</div>
						<div class="form-group">
							<label>Sponsor</label> 
              <a href="profile.php?mid=" onclick="this.href = this.href + document.getElementById('id_u').value;">[Change Sponsor]</a>
			
							<input type="text" id="sponsor_u" name="sponsors" class="form-control" readonly>
						</div>

           
<!--<a href="test.php" onclick="this.href = this.href +'?' + document.getElementById('myText').value;">test</a>-->
					 

					</div>
					<div class="modal-footer">
					<input type="hidden" value="2" name="type">
						<input type="button" class="btn btn-default" data-dismiss="modal" value="Cancel">
						<button type="button" class="btn btn-info" id="update">Update</button>
					</div>
				</form>
			</div>
		</div>
	</div>
	

</body>
</html>   