<?php
ob_start();
error_reporting(0);
include("connect.php");
session_start(); 
$ver = $_SESSION["admin_id"];
$admin_id = $_SESSION["admin_id"];
$dis_id = $_SESSION["manager_id"];
$user_type = $_SESSION["user_type"];
$user_session = $_SESSION["user_session"];

$id1 = base64_decode($_GET['id']);
if(!isset($_SESSION["admin_id"])){
   header('location:http://www.btcover.appexperts.net');
}
date_default_timezone_set('Asia/Calcutta');
	$cdate  = date("Y-m-d");
?>
<!DOCTYPE html>
<html dir="ltr" lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- Tell the browser to be responsive to screen width -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- Favicon icon -->
    <link rel="icon" type="image/png" sizes="16x16" href="assets/images/favicon.png">
    <title>BTCOVER : Admin Dashboard</title>
    <!-- Custom CSS -->
    <link rel="stylesheet" type="text/css" href="assets/libs/select2/dist/css/select2.min.css">
    <link rel="stylesheet" type="text/css" href="assets/libs/jquery-minicolors/jquery.minicolors.css">
    <link rel="stylesheet" type="text/css" href="assets/libs/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
    <link rel="stylesheet" type="text/css" href="assets/libs/quill/dist/quill.snow.css">
    <link href="dist/css/style.min.css" rel="stylesheet">
   <script>
	
		function myFunction() {
			var txt;
		
			var r = confirm("Are you sure to reset!");
			if (r == true) {
				window.location.href="change-password.php";
			} 
		}
		</script>
</head>

<body>
    <!-- ============================================================== -->
    <!-- Preloader - style you can find in spinners.css -->
    <!-- ============================================================== -->
  
	 <div id="main-wrapper">
   <?php include("header.php"); ?>
    
     <?php include("menu.php"); ?>
	
        <div class="page-wrapper">
            <!-- ============================================================== -->
            <!-- Bread crumb and right sidebar toggle -->
            <!-- ============================================================== -->
            <div class="page-breadcrumb">
                <div class="row">
                    <div class="col-12 d-flex no-block align-items-center">
                        <h4 class="page-title">Change Password</h4>
                        <div class="ml-auto text-right">
                            <nav aria-label="breadcrumb">
                                <ol class="breadcrumb">
                                    <li class="breadcrumb-item"><a href="dashboard.php">Dashboard</a></li>
									
									<li class="breadcrumb-item active" aria-current="page">Change Password</li>
                                </ol>
                            </nav>
                        </div>
                    </div>
                </div>
            </div>
            <!-- ============================================================== -->
            <!-- End Bread crumb and right sidebar toggle -->
            <!-- ============================================================== -->
            <!-- ============================================================== -->
            <!-- Container fluid  -->
            <!-- ============================================================== -->
            <div class="container-fluid">
                <!-- ============================================================== -->
                <!-- Start Page Content -->
                <!-- ============================================================== -->
                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <form class="form-horizontal" method="post" name="form"  enctype="multipart/form-data">
                                <div class="card-body">
                                   
                                   <div class="form-group row">
                                   <div class="col-md-4">	
									<div class="form-group ">
                                        <label for="fname" class=" text-left control-label col-form-label"><b>Old Password</b></label>
                                        
                                            <input type="password" class="form-control" id="aname" name="oldpass" placeholder="Old Password " required>
                                    
                                    </div>
                                </div>
								<div class="col-md-4">	
									<div class="form-group ">
                                        <label for="fname" class=" text-left control-label col-form-label"><b>New Password</b></label>
                                        
                                            <input type="password" class="form-control" id="aphone" name="newpass"   placeholder="New Password " required>
                                        
                                    </div>
                                </div>
                          <!--   <div class="col-sm-1" style="padding-left:0px; margin-top:31px;">
										  <div class="form-group">  
                                           <button type="submit" class="form-control" name="searchd"> <i class="fa fa-search"></i></button>
										  </div>
										</div>
								-->
								<div class="col-md-4">	
									<div class="form-group ">
                                        <label for="fname" class="text-left control-label col-form-label"><b>Confirm Password</b></label>
                                        
                                            <input type="password" class="form-control" id="acode" name="cpass" placeholder="Confirm Password " required>
                                        
                                    </div>
                                    </div>
                               
								
                                </div>
								<div class="form-group row">
                                 <div class="col-md-4">   
                                <div class="border-top">
                                    <div class="card-body">
                                       <div class="card-body">
                                    <button type="submit" name="sub" class="btn btn-success">Save</button>
                                    <button type="button" onclick="myFunction()" name="subcancel" class="btn btn-primary">Reset</button>
                                    
                                </div>
                                    </div>
                                </div>
                                </div>
                                </div>
                            </form>
							
							<?php 
			
			if(isset($_POST['sub']))
				{
		 		
		date_default_timezone_set('Asia/Calcutta');
	$cdate11  = date("Y-m-d")." ".date("H:i:s");
	
		$ver=$_SESSION["manager_id"];

	$oldpass=$_POST['oldpass'];
	$newpass=$_POST['newpass'];	
	$cpass=$_POST['cpass'];	
	
	$rs=mysqli_query($con,"select manager_id from tbl_manager where manager_id='$ver' and password ='$oldpass'");
	$num=mysqli_num_rows($rs);
	if($num>0)
	{
		if($cpass==$newpass)
	{
		$rs_data=mysqli_query($con,"select * from tbl_manager where manager_id='$ver'");
		while($fetch_dis_check=mysqli_fetch_assoc($rs_data))
		{
			$adminid=$fetch_dis_check['admin_id'];
			$pname1=$fetch_dis_check['manager_name'];
			$distri_email1=$fetch_dis_check['manager_email'];
			$dis_password=$fetch_dis_check['password'];
			$dis_phone=$fetch_dis_check['manager_phone'];
			$dis_address=$fetch_dis_check['address'];
			$query = mysqli_query($con,"INSERT INTO `tbl_manager_history`(`manager_id`, `admin_id`, `manager_name`, `manager_phone`, `manager_email`, `address`, `password`, `insert_datetime`, `remark`, `update_by`) VALUES ('$ver','$adminid','$pname1','$dis_phone','$distri_email1','$dis_address','$dis_password','$cdate11','Password Changed','$ver')");									
		}
		echo "update tbl_manager set password='$newpass',update_datetime='$cdate11',imei_no='',session_id='' where manager_id='$ver'";
		$uq1=mysqli_query($con,"update tbl_manager set password='$newpass',update_datetime='$cdate11',imei_no='',session_id='' where manager_id='$ver'");  
		
		if($uq1)
			{
				
				
				?>
				<script> alert("Password changed successfully"); </script>
				<?php
				
			}
	}
	else
	{
	?>
				<script> alert("new password and confirm password not matched"); </script>
				<?php	
	}
	}
	else
			{
				?>
				<script> alert("Password not changed..Please check and try again later!!"); </script>
				<?php
			}
		
	
	
				}
			
			
							?>
							
							
                        </div>
                    
          

                    </div>
              
                </div>
                <!-- editor -->
               
                <!-- ============================================================== -->
                <!-- End PAge Content -->
                <!-- ============================================================== -->
                <!-- ============================================================== -->
                <!-- Right sidebar -->
                <!-- ============================================================== -->
                <!-- .right-sidebar -->
                <!-- ============================================================== -->
                <!-- End Right sidebar -->
                <!-- ============================================================== -->
            </div>
            </div>
            </div>
            <!-- ============================================================== -->
            <!-- End Container fluid  -->
            <!-- ============================================================== -->
            <!-- ============================================================== -->
            <!-- footer -->
            <!-- ============================================================== -->
             <footer class="footer text-center">
                  2019 &copy; All Rights Reserved by BTCOVER. Designed and Developed by <a href="http://www.belltechnology.in/">Bell Technology</a>.
            </footer>
          
            <!-- ============================================================== -->
            <!-- End footer -->
            <!-- ============================================================== -->
        </div>
        <!-- ============================================================== -->
        <!-- End Page wrapper  -->
        <!-- ============================================================== -->
    </div>
    <!-- ============================================================== -->
    <!-- End Wrapper -->
    <!-- ============================================================== -->
    <!-- ============================================================== -->
    <!-- All Jquery -->
    <!-- ============================================================== -->
    <script src="assets/libs/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap tether Core JavaScript -->
    <script src="assets/libs/popper.js/dist/umd/popper.min.js"></script>
    <script src="assets/libs/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- slimscrollbar scrollbar JavaScript -->
    <script src="assets/libs/perfect-scrollbar/dist/perfect-scrollbar.jquery.min.js"></script>
    <script src="assets/extra-libs/sparkline/sparkline.js"></script>
    <!--Wave Effects -->
    <script src="dist/js/waves.js"></script>
    <!--Menu sidebar -->
    <script src="dist/js/sidebarmenu.js"></script>
    <!--Custom JavaScript -->
    <script src="dist/js/custom.min.js"></script>
    <!-- This Page JS -->
    <script src="assets/libs/inputmask/dist/min/jquery.inputmask.bundle.min.js"></script>
    <script src="dist/js/pages/mask/mask.init.js"></script>
    <script src="assets/libs/select2/dist/js/select2.full.min.js"></script>
    <script src="assets/libs/select2/dist/js/select2.min.js"></script>
    <script src="assets/libs/jquery-asColor/dist/jquery-asColor.min.js"></script>
    <script src="assets/libs/jquery-asGradient/dist/jquery-asGradient.js"></script>
    <script src="assets/libs/jquery-asColorPicker/dist/jquery-asColorPicker.min.js"></script>
    <script src="assets/libs/jquery-minicolors/jquery.minicolors.min.js"></script>
    <script src="assets/libs/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
    <script src="assets/libs/quill/dist/quill.min.js"></script>
    <script>
        //***********************************//
        // For select 2
        //***********************************//
        $(".select2").select2();

        /*colorpicker*/
        $('.demo').each(function() {
        //
        // Dear reader, it's actually very easy to initialize MiniColors. For example:
        //
        //  $(selector).minicolors();
        //
        // The way I've done it below is just for the demo, so don't get confused
        // by it. Also, data- attributes aren't supported at this time...they're
        // only used for this demo.
        //
        $(this).minicolors({
                control: $(this).attr('data-control') || 'hue',
                position: $(this).attr('data-position') || 'bottom left',

                change: function(value, opacity) {
                    if (!value) return;
                    if (opacity) value += ', ' + opacity;
                    if (typeof console === 'object') {
                        console.log(value);
                    }
                },
                theme: 'bootstrap'
            });

        });
        /*datwpicker*/
        jQuery('.mydatepicker').datepicker();
        jQuery('#datepicker-autoclose').datepicker({
            autoclose: true,
            todayHighlight: true
        });
        var quill = new Quill('#editor', {
            theme: 'snow'
        });

    </script>
</body>

</html>