<?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"];

$customer_id= 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 Cancel!");
			if (r == true) {
				window.location.href="edit-agent.php?id="+<?php echo $agent_id;?>;
			} 
		}
		</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">Edit Customer</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"><a href="customer.php">View Customer</a></li>
									<li class="breadcrumb-item active" aria-current="page">Edit Customer</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">
                                    <h4 class="card-title">Edit Customer</h4>
									
									<?php
									
									$res1= mysqli_query($con,"SELECT * FROM  tbl_customer where customer_id='$customer_id'");
									$fetch_detail=mysqli_fetch_assoc($res1);
								?>
                                   <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">Customer Name</label>
                                        
                                            <input type="text" class="form-control" id="aname" name="aname" value="<?=$fetch_detail['customer_name']?>" placeholder="Customer Name" required>
                                    
                                    </div>
                                </div>
								<div class="col-md-4">	
									<div class="form-group ">
                                        <label for="fname" class=" text-left control-label col-form-label">Customer Phone</label>
                                        
                                            <input type="text" class="form-control" id="aphone" name="aphone" onkeypress='return event.charCode >= 48 && event.charCode <= 57' minlength="10" maxlength="10" size="10" placeholder="Customer Phone Here" value="<?=$fetch_detail['phone_no']?>" required>
                                        
                                    </div>
                                </div>
                                </div>
								 <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">Customer Email</label>
                                        
                                            <input type="text" class="form-control" id="acode" name="acode" value="<?=$fetch_detail['email']?>" placeholder="Customer Code Here" required>
                                        
                                    </div>
                                </div>
								<div class="col-md-4">	
									<div class="form-group ">
                                        <label for="fname" class="text-left control-label col-form-label">Customer Address</label>
                                        <textarea class="form-control" name="address" required><?php echo $fetch_detail['address']?>"</textarea>
                                    </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-danger">Cancel</button>
                                    
                                </div>
                                    </div>
                                </div>
                                </div>
                                </div>
                            </form>
							
							<?php 
			
			if(isset($_POST['sub']))
				{
					
					$cust_id= base64_decode($_GET['id']);
		 $m_name= $_POST['aname'];
		 $m_phone= $_POST['aphone'];
		 $address= $_POST['address'];
		 $email= $_POST['email'];
		 $admin_id=base64_decode($_GET['id']);					
		$ver = $_SESSION['manager_id'];
	date_default_timezone_set('Asia/Calcutta');
	$cdate  = date("Y-m-d")." ".date('h:i:s');
	$res_product_stock = mysqli_query($con,"SELECT customer_name FROM  tbl_customer where customer_id='$cust_id'");
	if(mysqli_num_rows($res_product_stock)>0)
	{	
		$res_customer = mysqli_query($con,"SELECT * FROM  tbl_customer where customer_id='$cust_id'");
		while($fetch_detail=mysqli_fetch_assoc($res_customer))
		{
			$query = mysqli_query($con,"INSERT INTO `tbl_customer_history`(`customer_id`,`manager_id`, `customer_name`, `phone_no`, `email`, `address`, `insert_datetime`,`update_by`) VALUES ('$cust_id','".$fetch_detail['manager_id']."','".$fetch_detail['customer_name']."','".$fetch_detail['phone_no']."','".$fetch_detail['email']."','".$fetch_detail['address']."','$cdate','$ver')");	
			
			$uq2=mysqli_query($con,"update tbl_customer set customer_name='$m_name',phone_no='$m_phone',address='$address',email='$email',update_datetime='$cdate' where customer_id='$cust_id'"); 
		}
		if($uq2)
		{
		header('location:customer.php');	
		}
	}
	else
		{
			?>
			<script> alert("Customer Already Exist"); </script>
			<?php
		}
		
	if($query && $uq2)
		{
				
		header('location:agent.php');	
				
		}
			
}	
				
							?>
							
							
                        </div>
                    
          

                    </div>
              
                </div>
                <!-- editor -->
               
                <!-- ============================================================== -->
                <!-- End PAge Content -->
                <!-- ============================================================== -->
                <!-- ============================================================== -->
                <!-- Right sidebar -->
                <!-- ============================================================== -->
                <!-- .right-sidebar -->
                <!-- ============================================================== -->
                <!-- End Right sidebar -->
                <!-- ============================================================== -->
            </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>