<!DOCTYPE html>
<html lang="en">
<head>
	<!-- header -->
		<?php echo view('admin/common_header'); ?>
	<!-- /header -->

	<!-- 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 type="text/javascript" src="<?php echo base_url('assets/js/plugins/notifications/pnotify.min.js');?>"></script>
	<script type="text/javascript" src="<?php echo base_url('assets/js/plugins/notifications/noty.min.js');?>"></script>
	<script type="text/javascript" src="<?php echo base_url('assets/js/plugins/notifications/jgrowl.min.js');?>"></script>

	<!-- Theme JS files -->
	<script type="text/javascript" src="<?php echo base_url('assets/js/core/app.js');?>"></script>
	<!-- /theme JS files -->

	

</head>

<body class="login-cover">

	<!-- Page container -->
	<div class="page-container login-container">

		<!-- Page content -->
		<div class="page-content">

			<!-- Main content -->
			<div class="content-wrapper">
				
				
				<!-- Form with validation -->
				<form action="<?php echo base_url('admin/twofactor');?>" class="form-validate confirm" method="post">
					<div class="panel panel-body login-form">
						<div class="text-center">
							<div class="icon-object border-slate-300 text-slate-300"><i class="icon-mobile"></i></div>
							<h5 class="content-group"><?php echo lang('language_lang.second_verification_title'); ?> <small class="display-block">OTP will be change for every 30 seconds</small></h5>
						</div>

						<?php 
							 $condition = "id = '".$this->session->userdata('ad_id')."'";
                            $uemail = $this->common_model->GetRow('admin', $condition);                                  
                            $secret =  $uemail->secret_key;
                            if($secret=='0' || $secret=='')
                            {
                            	$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();
								$secret = $authenticator->createSecret();
                                $otp_code = $authenticator->getCode($secret); 

                                $website =  $siteweb->site_value; //Your Website
                                $title= $title->site_value;
                                $qrCodeUrl = $authenticator->getQRCodeGoogleUrl($title,$secret,$website);
                                //echo '<img style="text-align:center;" src="'.$qrCodeUrl.'">';
                               ?>
                               	<div align="center">
                               	<p>Scan Your QR Code</p>
                               	<img src="<?php echo $qrCodeUrl;?>" width="200" height="200" >
                               	</div>
                               	<div style="clear:both;"><br></div>
                               <?php 

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

                            }
                            //echo $otp_code;
                            //echo "<br>";
                            //echo $secret;
						?>

						<div class="form-group has-feedback has-feedback-left">
							<input type="password" class="form-control" placeholder="<?php echo lang('language_lang.plac_emailconfirm_title'); ?>" name="confirmcode" required="required">
							<div class="form-control-feedback">
								<i class="icon-user text-muted"></i>
							</div>
							<?php echo form_error('confirmcode');?>
						</div>
						<input type="hidden" name="secret" id="secret" value="<?php echo $secret;?>">
						
						<div class="form-group">
							<button type="submit" class="btn bg-blue btn-block"><?php echo lang('language_lang.button_Login');?> <i class="icon-arrow-right14 position-right"></i></button>
						</div>
						
					</div>
				</form>
				<!-- /form with validation -->

				

			</div>
			<!-- /main content -->

		</div>
		<!-- /page content -->


		<!-- Footer -->
		<div class="footer text-white">
			<?php echo site_footer();?>
		</div>
		<!-- /footer -->

	</div>
	<!-- /page container -->

	<script type="text/javascript">
	jQuery.noConflict();
	(function( $ ) {
	$(function() {

		$(document).ready(function() {

			 $.jGrowl.defaults.closer = false;


			<?php if($this->session->flashdata('error_message')) { ?>

			// $('#jgrowl-warning').on('click', function () {
		        $.jGrowl('<?php echo $this->session->flashdata('error_message');?>', {
		            header: 'Attention Here!',
		            theme: 'bg-warning'
		        });
		    // });

		    <?php } ?>
			

		    $('.confirm').formValidation({
		    	framework: 'bootstrap',
		    	excluded: [':disabled'],
		        
		        fields: {
		            confirmcode: {
		                message: '<?php echo lang("language_lang.email_confirm_mismatch");?>',
		                validators: {
		                    notEmpty: {
		                        message: '<?php echo lang("language_lang.email_confirm_required");?>'
		                    }
		                    
		                }
		            }
                                
		            
		        }
		    })
			
		});
	    
	   

	});
	})(jQuery);

	</script>

</body>
</html>
