<?php
require_once("../app/config.php");
require_once("../vendor/autoload.php");
$g=new \Sonata\GoogleAuthenticator\GoogleAuthenticator();
$secret=$g->generateSecret();
$site=$set['site_name'];
$title="2fa Security";
require_once('include/user_header.php');
require_once('include/user_navbar.php');
require_once('include/user_sidebar.php');
$email=$row['email'];
?>
<div class="content-wrapper">

      <!-- Page header -->
      <div class="page-header">
        <div class="page-header-content header-elements-md-inline">
          <div class="page-title d-flex">
            <h4><i class="icon-key mr-2"></i> <span class="font-weight-semibold">Google 2fa Security</span></h4>
          </div>
        </div>
      </div>
      <div class="content">
<?php if(!empty($_SESSION['offshore_2fa'])){?>
    <div class="row">
        <div class="col-lg-12">
          <div class="alert <?php if($_SESSION['offshore_2fa']=='invalid') {echo 'bg-danger-800';}else{echo 'bg-success-800';}?> text-white alert-styled-left alert-dismissible">
            <button type="button" class="close" data-dismiss="alert"><span>&times;</span></button>
      <?php 
      if($_SESSION['offshore_2fa']=='invalid') {echo'Invalid code.';}
      elseif($_SESSION['offshore_2fa']=='disables') {echo'2fa is now disabled.';}
      elseif($_SESSION['offshore_2fa']=='success') {echo'2fa is now active.';}
        unset($_SESSION['offshore_2fa']);
      ?>                 
            </div>
          </div>
      </div>
<?php }?>
          <div class="row">
    <div class="col-md-12">
      <!-- Basic layout-->
      <div class="card">
        <div class="card-header header-elements-inline">
              <div class="header-elements">
                <div class="list-icons text-orange-600">

              </div>
            </div>
        </div>

        <div class="card-body">
          <form action="../app/user/2fa" method="post" id="modal-details"> 
              <div class="form-group row">
                <label class="col-form-label col-lg-2">Status <span class="text-danger">*</span></label>
                <div class="col-lg-10">
                                    <input type="hidden" value="<?php echo $row['id'];?>" name="user_id">
                  <div class="form-check form-check-inline form-check-switchery">
                    <label class="form-check-label">
              <?php if($row['2fa_status']=='1'){
                  echo'<input type="checkbox" name="status" class="form-check-input-switchery" value="1" checked>';
              }else{
                  echo'<input type="checkbox" name="status" class="form-check-input-switchery" value="1">';
              }?>     
                      </label>
                  </div>
                </div>
              </div> 
            <?php if($row['2fa_status']=='1'){?>                
            <div class="text-right">
              <button href="#" data-toggle="modal" data-target="#22modal_mini" class="btn bg-green-800">Disable<i class="icon-paperplane ml-2"></i></button>
            </div>
            <div id="22modal_mini" class="modal fade" tabindex="-1">
              <div class="modal-dialog modal-xs">
                <div class="modal-content">
                  <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                  </div>
                  <div class="modal-body">
                    <h6 class="font-weight-semibold">Enter 2fa code to disable security</h6>
                      <div class="form-group row">
                        <div class="col-lg-12">
                          <div class="input-group">
                            <input type="number" class="form-control" placeholder="" name="code" required>
                            <input type="hidden"  name="vv" value="disable">
                          </div>
                        </div>
                      </div>                   
                  </div>
                  <div class="modal-footer">
                    <button type="submit" class="btn bg-success" form="modal-details">Submit</button>
                  </div>
                </div>
              </div>
            </div>
            <?php }else{?>
            <div class="text-right">
              <a href="#" data-toggle="modal" data-target="#3modal_mini" class="btn bg-green-800">Enable<i class="icon-paperplane ml-2"></i></a>
            </div>
            <div id="3modal_mini" class="modal fade" tabindex="-1">
              <div class="modal-dialog modal-xs">
                <div class="modal-content">
                  <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                  </div>
                  <div class="modal-body">
                    <h6 class="font-weight-semibold">Set up Google 2fa</h6>
                    <img src="<?php echo \Sonata\GoogleAuthenticator\GoogleQrUrl::generate($email, $secret, $site);?>" style="max-width:100%; height:auto;" class="">
                      <div class="form-group row">
                        <div class="col-lg-12">
                          <div class="input-group">
                            <input type="number" class="form-control" placeholder="" name="code" required>
                            <input type="hidden"  name="vv" value="<?php echo $secret;?>">
                          </div>
                        </div>
                      </div>                   
                  </div>
                  <div class="modal-footer">
                    <button type="submit" class="btn bg-success" form="modal-details">Submit</button>
                  </div>
                </div>
              </div>
            </div>
            <?php }?>
          </form>
        </div>
      </div>
      <!-- /basic layout -->
      </div>
    </div>
  </div>
<?php require_once('include/user_footer.php');?>