<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <?php
            $this->load->view('user/common_style');
 ?>
<link rel="stylesheet" href="<?php echo base_url();?>styles/fonts/Socialico/stylesheet.css">
<link rel="stylesheet" href="<?php echo base_url();?>styles/css/set1.css">
<link href="<?php echo base_url();?>/assets/boots/css/bootstrap-switch.css" rel="stylesheet" type="text/css">
<script src="<?php echo base_url();?>styles/js/modernizr.js"></script>
<style>
  .contact_one .contact_left_content form input[type="text"]{border:0px;}
  .prfledit label, .prfledit label {
  padding-top: 10px;
}
.profilesub ul li label{
  display: inline;
  /*color: #eb5055;*/
}
.help-block {
    color: #eb5055;
    margin: 0em 0em 0em !important;
}
p.frgtpwd {

text-transform: none;
  }

.control-error > p {
  color: rgb(255, 0, 0) !important;
}

  </style>
        
</head>
<body>

           <?php
                $this->load->view('user/header');
                $this->load->view('user/login_header');
                // $this->load->view('user/profileboard');
            ?>
    <?php 
      $us_data = userMinPass();
    ?> 
    <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
      <div class="table-list clearfix">
              <form class="steps-validation change_trpwd" method="post" action="<?php echo base_url();?>enable">
                      <h4 class="other-title theme-color"><?php echo $this->lang->line('change_pwd_title'); ?> <span><?php echo $this->lang->line('profile_chan_auth'); ?></span></h4>
                        <?php if($this->session->flashdata('success_message')) {?>
                             <div class="row"><div class="col-lg-12 "><p class="frgtpwd frgtpwd1"><i class="fa fa-thumbs-up"></i><?php echo $this->session->flashdata('success_message');?></p></div></div>
                              <?php } elseif ($this->session->flashdata('error_message')) { ?>
                                <div class="row"><div class="col-lg-12">  <p class="frgtpwd frgtpwd1 frgtpwdred"><i class="fa fa-thumbs-down"></i><?php echo $this->session->flashdata('error_message');?></p></div></div>
                              <?php } else { }?>

                              <div class="row"><div class="col-lg-12"><p class="frgtpwd frgtpwd1"><i class="fa fa-thumbs-up"></i><?php echo $this->lang->line('activat_otp');?></p></div>
                              </div>

                              <?php
                                 $condition = "uusersid = '".$this->session->userdata('uusersid')."'";
                                 $uemail = $this->common_model->GetRow('uusers', $condition);
                                 $getfactor = $this->common_model->GetRow('uusers_security', $condition);

                              ?>
                              <!-- <div class="order-block-inp"> -->
                                <div class="order-block-inp form-group">
                                  <h6 class="other-title theme-color">Two Factor Authentication 
                                  <?php
                                    if($getfactor->two_factor=='enabled')
                                    {?>
                                      <a href="javascript:void(0);" class="pl-15 pr-15 pt-10 pb-10 ml-15 mb-15" style="position:absolute;background:rgb(85, 160, 70);"><?php echo $this->lang->line('security_two_on');?></a>
                                      <?php
                                    }
                                    else
                                    {?>
                                      <a href="javascript:void(0);" class="pl-15 pr-15 pt-10 pb-10 ml-15 mb-15" style="position:absolute;background:rgb(245, 171, 53);"><?php echo $this->lang->line('security_two_off');?></a>
                                    <?php
                                    }?>
                                    </h6>
                                </div>    
                              
                                  <?php 
                                      $flags="";                                     
                                      $secret =  $uemail->secret_key;
                                      

                                      if($uemail->secret_key!="" && $uemail->secret_key!="0" &&  $uemail->new_entry=='0')
                                      {
                                        $styl = 'display:block';
                                        $secret =  $uemail->secret_key;
                                        $condition = "site_key = 'factor_title'";  
                                        $title = $this->common_model->GetRow('site_controls',$condition);
                                        $condition = "site_key = 'factor_website'";  
                                        $siteweb = $this->common_model->GetRow('site_controls',$condition);    
                                        $authenticator = new PHPGangsta_GoogleAuthenticator();
                                        $otp_code = $authenticator->getCode($secret); 
                                        $website =  $siteweb->site_value; //Your Website
                                        $title= $title->site_value;
                                        $qrCodeUrl = $authenticator->getQRCodeGoogleUrl($title,$secret,$website);
                                        $flag='1';
                                        $flags="5";
                                        // echo $otp_code.'<br>';
                                      }
                                      else
                                      {
                                        $styl = 'display:none'; 
                                        $flag='2';
                                        if($uemail->secret_key!="" && $uemail->secret_key!="0")
                                        {
                                          $flags="5";                                                                                
                                        }  
                                      }

                                      $authenticator = new PHPGangsta_GoogleAuthenticator();
                                      $otp_code = $authenticator->getCode($secret); 

                                      // echo $otp_code;
                                    if($flag=='1')                                              
                                    {?>                                                   
                                    <div class="form-group" id="enable_dat" style="<?php echo $styl;?>;text-align:center;">
                                     <label class="control-label col-lg-12 text-semibold"><?php echo $this->lang->line('secret_key'); ?> :  <b><?php if(isset($uemail->secret_key)){ echo $secret;}else{ echo ''; };?></b></label>
                                        <note><?php echo  $this->lang->line('scan_code');?></note>
                                        <div class="col-lg-12">
                                                <?php
                                                    echo '<img style="text-align:center;" src="'.$qrCodeUrl.'">';
                                                ?>
                                        </div>
                                      </div> 
                                     <?
                                     }
                                     else
                                     {?>
                                        <div class="form-group" id="enable_dat" style="<?php echo $styl;?>">
                                        </div> 

                                     <?}


                                     if($flags!="")
                                     {
                                     ?> 
                                        <div class="col-lg-12 mt-10">
                                            <label class="col-lg-3 other-title theme-color mt-15"><?php echo $this->lang->line('authenticate_key');?></label>
                                            <div class="col-lg-9"><input type="text" name="authenticate" id="authenticate" placeholder="<?php echo $this->lang->line('plac_authenticate_code')?>"></div>
                                            <label class="control-error" style="color:#f00 !important"><?php echo form_error('authenticate');?></label> 
                                        </div>
                                      <?
                                      }?>    
                             <!-- </div> -->
                            
                      <div class="col-lg-12"> 
                             <?php
                                      if($getfactor->two_factor=='enabled')
                                      {?>
                                          <div class="contact_page_btn">
                                              <button class="yellow-btn" type="submit" name="disable" id="disable"><?php echo $this->lang->line('secuirty_disabled_lbl'); ?></button>
                                          </div>
                                      <?php
                                      }
                                      else
                                      {?>
                                          <div class="contact_page_btn" >
                                          <button class="yellow-btn" type="submit" name="enable" value="1" id="enable" onclick="javascript:enable()"><?php echo $this->lang->line('secuirty_enabled_lbl');?></button>
                                          </div>
                                      <?php
                                       }?>   
                      </div>
            </div>
            </form>
            
        </div>
    </div>
        </div>
    </div>

  <?php
                $this->load->view('user/footer');

            ?>
</section>



<script src="<?php echo base_url();?>styles/js/jquery-1.12.2.min.js"></script>

<!-- <script src="<?php echo base_url();?>styles/js/bootstrap.min.js"></script> -->
<!-- Bootsrap form validation JS files -->
        <script type="text/javascript" src="<?php echo base_url();?>assets/js/formValidation.js"></script>
        <script type="text/javascript" src="<?php echo base_url();?>assets/js/bootstrap.js"></script>
        
         <script src="<?php echo base_url();?>/assets/boots/js/select_min.js"></script>
    
       <link rel="stylesheet" type="text/css" href="<?php echo base_url();?>/assets/boots/css/select2.css">


<script>
      (function() {

         $('.change_trpwd').formValidation({
                    framework: 'bootstrap',
                    excluded: [':disabled'],
                    
                    fields: {

                        newpin: {
                            validators: {
                                notEmpty: {
                                    message: '<?php echo $this->lang->line("trans_empty_err");?>'
                                },
                                digits: {
                                    message: '<?php echo $this->lang->line("registration_trans_digit_err");?>'
                                } 

                            }
                        },
                        confirmpin: {
                            validators: {
                                notEmpty: {
                                    message: '<?php echo $this->lang->line("confirm_trans_empty_err");?>'
                                },
                                identical: {
                                    field: "newpin",
                                    message: '<?php echo $this->lang->line("transpin_mismatch");?>'
                                },
                                digits: {
                                    message: '<?php echo $this->lang->line("registration_trans_digit_err");?>'
                                } 

                            }
                        },
                       
                         currentpin: {
                            validators: {
                                notEmpty: {
                                    message: '<?php echo $this->lang->line("trans_empty_err");?>'
                                },
                                digits: {
                                    message: '<?php echo $this->lang->line("registration_trans_digit_err");?>'
                                },
                                remote: {
                                    url: function(validator, $field, value) {
                                        
                                        return '<?php echo base_url();?>user/profile/validtranspassword';
                                    },
                                    type: 'POST',
                                    delay: 1000,
                                    message: '<?php echo $this->lang->line("trans_pin_error"); ?>'
                                }

                            }
                        }
                       
                }
                })
               
        // trim polyfill : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim
        if (!String.prototype.trim) {
          (function() {
            // Make sure we trim BOM and NBSP
            var rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
            String.prototype.trim = function() {
              return this.replace(rtrim, '');
            };
          })();
        }

        [].slice.call( document.querySelectorAll( 'input.input__field' ) ).forEach( function( inputEl ) {
          // in case the input is already filled..
          if( inputEl.value.trim() !== '' ) {
            classie.add( inputEl.parentNode, 'input--filled' );
          }

          // events:
          inputEl.addEventListener( 'focus', onInputFocus );
          inputEl.addEventListener( 'blur', onInputBlur );
        } );

        function onInputFocus( ev ) {
          classie.add( ev.target.parentNode, 'input--filled' );
        }

        function onInputBlur( ev ) {
          if( ev.target.value.trim() === '' ) {
            classie.remove( ev.target.parentNode, 'input--filled' );
          }
        }
      })();
    </script>
    </script>
<script src="<?php echo base_url();?>styles/js/main.js"></script>

<script src="<?php echo base_url();?>assets/boots/js/bootstrap-switch.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>assets/js/plugins/notifications/jgrowl.min.js"></script>


<script type="text/javascript" src="<?php echo base_url();?>styles/js/owl.carousel.min.js"></script>
 <script src="<?php echo base_url();?>styles/js/classie.js"></script>
<script type="text/javascript">
  $(document).ready(function($) {


$(".switch").bootstrapSwitch();

});

function enable(str)
{
  var cek= document.getElementById('switch1').checked;
  if(cek===true)
  {
      $("#enable_dat").css('display','block');
          $.ajax({
                    'method': 'POST',
                    'url': '<?php echo base_url();?>user/profile/create/',
                    dataType: 'json',
                    success:function(resp)
                    {
                       if(resp['exist']=='exist')
                       {

                       }
                       else
                       {
                        $('#enable_dat').html(resp['success']);
                       }
                        
                    }
                })


  }
  else
  {
   $("#enable_dat").css('display','none'); 
  }

}
  
   
</script>
<?php
$this->load->view('user/common_script');    
?>


</body>
</html>
