<?php session_start();
require_once '../inc/dbcon.php';
include ('../inc/dbcon.php');
include ('../inc/functions.php');
include ('../inc/imgpro.php');
if(isset($_SESSION["axeslogin"]) && $_SESSION["axeslogin"] == true){
get_pagesecurity('9','creates','R');     
$_SESSION['cuPages']='main_sellercreate.php';   
$cuPage='main_sellercreate.php';    
$aid=$_SESSION['uid'];
$brid=$_SESSION['abrid'];     
}else{
header('Location:../index.php');
exit;    
}
$mhead='client';
$menuh='Client Setup';
$phead='sellerlist';
$page='Exchange Edit';
$dtnow = date("Y-m-d h:i:s", time());
?>
<?php
include('../layout/head.php');
include('../layout/header.php');
include('../layout/side_nav.php');
?>
<?php 
if(isset($_POST['update_seller'])){
    $selid = remove_junk(escape($_POST['selid']));
	$name = ucwords(remove_junk(escape($_POST['name'])));
    $cname = remove_junk(escape($_POST['cname']));
    $mobile = remove_junk(escape($_POST['mobile']));
    $telephone = remove_junk(escape($_POST['telephone']));
    $address = remove_junk(escape($_POST['address']));
    $statement = remove_junk(escape($_POST['statement']));
    $imei = remove_junk(escape($_POST['imei']));
    $price = remove_junk(escape($_POST['price']));
    $password = remove_junk(escape($_POST['password']));
    $date = remove_junk(escape($_POST['date']));
    $nid = remove_junk(escape($_POST['nid']));

    
    $item = PATHINFO($_FILES["item"]["name"]);
    $nimage = PATHINFO($_FILES["nimage"]["name"]);

   
	
	if(isset($_POST['mobile'])){
	$ducode = mysqli_query($con,"SELECT * FROM tbl_seller WHERE mobile = '$mobile' AND id!='$selid'");
	}
	
	if($ducode->num_rows > 0) {
		save_msg('i','Contact number alrady exists! Plz try another');
		echo "<script>window.location='main_sellercreate.php'</script>";
	}else{
    $sql="UPDATE tbl_seller SET name='$name',cname='$cname',mobile='$mobile',telephone='$telephone',date='$date',nid='$nid',imei='$imei',price='$price',address='$address',statement='$statement',password='$password',updated_date='$dtnow' WHERE id=$selid";
	$result = mysqli_query($con,$sql) or die(mysqli_error($con));
    $cid=$con->insert_id; 
    $efid=mysqli_affected_rows($con);    
    if($efid>0){
    
    if (!empty($_FILES["mimage"]["name"])){
        get_destroy($cid,'M');    
        get_upload($cid,$_FILES['mimage'],'M');
        }
    if (!empty($_FILES["nimage"]["name"])){
        get_destroy($cid,'N');    
        get_upload($cid,$_FILES['nimage'],'N');
        }
    $act =remove_junk(escape('Exchanger name: '.$name));    
    write_activity($aid,'SLR','Exchanger has been Updated',$act);
    save_msg('s','Data Successfully Updated!');    
    }else{
    save_msg('w','Data Fail to Updated!');    
    }
    echo "<script>window.location='main_sellerlist.php'</script>";  
	} 
}
?>
<div class="content-wrapper">
<?php include('../layout/page_head.php'); ?>
<!-- Main content -->
<section class="content">
    
<div class="row">
<div class="col-md-9">
<div class="box box-solid">
<div class="box-header with-border">
<h3 class="box-title">Add New Exchanger</h3>
</div>
<div class="box-body">
<?php echo display_msg();?>    
<form action="main_selleredit.php" onsubmit="return validate()" enctype="multipart/form-data" method="post" accept-charset="utf-8">
<div class="col-md-12 popup_details_div">
<div class="col-md-1"></div>
<div class="col-md-10">
<div class="col-md-12">
<?php
if(isset($_POST['editseller'])){
$ids = $_POST['editseller'];
$sql="SELECT * FROM tbl_seller WHERE id='".$ids."' ORDER BY id ASC LIMIT 1";    
$admin=mysqli_query($con,$sql) or die(mysqli_error($con));    
$adm=mysqli_fetch_array($admin);
?>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Name</label>    
<input type="text" name="name" maxlength="45" value="<?php echo $adm['name'];?>" id="name" class="form-control" placeholder="e.g. Md.Sumon Rahman"/>
<input type="hidden" maxlength="11" value="<?php echo $adm['id'];?>" class="form-control" name="selid" autocomplete="off" readonly>    
</div>    
</div>
<div class="col-md-6">
    <div class="form-group">
        <label>Father/Mother Name</label>    
        <input type="text" name="cname" maxlength="45" value="<?php echo $adm['cname'];?>" id="cname" class="form-control" placeholder="e.g. Md.Rahman Sumon(CEO)"/>
    </div>    
</div>   
</div>

<div class="row">
        <div class="col-md-4">
            <div class="form-group">
                <label>Date</label>    
                <input type="text" class="form-control datetimepicker" name="date" id="date" value="<?php echo $adm['date'];?>" placeholder="Date:" autocomplete="off" readonly>    
            </div>    
        </div>
        
        <div class="col-md-4">
            <div class="form-group">
                <label>Mobile No.</label>    
                <input type="text" name="mobile" maxlength="14" value="<?php echo $adm['mobile'];?>" id="mobile" class="form-control" placeholder="e.g. +8801705645150"/>
            </div>
        </div>  
        <div class="col-md-4">
            <div class="form-group">
                <label>Telephone No.</label>    
                <input type="text" name="telephone" maxlength="14" value="<?php echo $adm['telephone'];?>" id="telephone" class="form-control" placeholder="e.g. +8801705645150"/>
            </div>
        </div>   
</div> 
<div class="row">
        
    <div class="col-md-6">
        <div class="form-group">
            <label>National ID/Passport/Driving Licence No. </label>    
            <input type="text" name="nid" maxlength="17" value="<?php echo $adm['nid'];?>" id="nid" class="form-control" placeholder="e.g. 1982145678956"/>
        </div>    
    </div>   
    <div class="col-md-6">
        <div class="form-group">
            <label>IMEI/SN.</label>    
            <input type="text" name="imei" maxlength="45" value="<?php echo $adm['imei'];?>" id="imei" class="form-control" placeholder="e.g. 1982145678956"/>
        </div>    
    </div>  
</div>  
<div class="row">
        
    <div class="col-md-6">
        <div class="form-group">
            <label>Password</label>    
            <input type="text" name="password" maxlength="17" value="<?php echo $adm['password'];?>" id="password" class="form-control" placeholder="e.g. 1982145678956"/>
        </div>    
    </div>   
    <div class="col-md-6">
        <div class="form-group">
            <label>Price</label>    
            <input type="text" name="price" maxlength="45" value="<?php echo $adm['price'];?>" id="price" class="form-control" placeholder="e.g. 1000"/>
        </div>    
    </div>  
</div> 
</div>      
<div class="row">
<div class="col-md-6"> 
<div class="form-group">    
<label>Statement</label>
<textarea class="form-control" name="statement" id="statement" maxlength="200" rows="4" placeholder="Statement"><?php echo $adm['statement'];?></textarea>    
</div>
</div>    
<div class="col-md-6">    
<div class="form-group">
<label>Address</label>
<textarea class="form-control" name="address" id="address" maxlength="200" rows="4" placeholder="Address"><?php echo $adm['address'];?></textarea>   
</div>
</div>    
</div> 
 


<div class="row">
    <div class="col-md-6"> 
        <div class="form-group">    
            <label>Seller Image</label>
            <div style="width:120px; height:145px;">
            <img src="../img/member/<?php if(empty($adm['mimage'])){echo 'no_image.png';}else{echo $adm['mimage'];} ?> " id="profile-img-tag" style="width: 100%; height: 100%; object-fit: contain;">
            </div>
            <br>    
            <input type="file" class="btn btn-file bg-purple btn-sm" name="mimage" id="profile-img" accept=".png, .gif, .jpg, .jpeg">
                
        </div> 
    </div>    
    <div class="col-md-6">    
        <div class="form-group">    
            <label>NID Image</label>
            <div style="width:120px; height:145px;">
            <img src="../img/nid/<?php if(empty($adm['nimage'])){echo 'no_image.png';}else{echo $adm['nimage'];} ?> " id="profile-img-tag1" style="width: 100%; height: 100%; object-fit: contain;">
            </div>
            <br>    
            <input type="file" class="btn btn-file bg-purple btn-sm" name="nimage" id="profile-img1" accept=".png, .gif, .jpg, .jpeg">
                
        </div> 
    </div>    
</div> 

<?php } ?>
</div>    
<div class="col-md-1"></div>    
</div>
<div class="clearfix" ></div>
<div class="col-md-12 nopadding widgets_area"></div>    
<div class="row"style="margin-top: 15px" >
<div class="col-md-8 ">
</div>
<div class="col-md-4 text-right" >
<input type="submit" name="update_seller" id="submit" class="btn btn-flat bg-purple btn-sm" value="Update"/> <a href="main_sellerlist.php" class="btn btn-flat bg-gray  ">Close</a>
</div> 
</div>     
</form>    
</div>
</div>
</div>
<div class="col-md-3">
<div class="row">
<div class="col-md-12">
<div class="box box-solid">
<div class="box-header">
<h3 class="box-title">History </h3>
</div>
<!-- /.box-header -->
<div class="box-body" >
<?php if($_SESSION['access']=='1'){echo read_activity($aid,'SLR','A');}else{echo read_activity($aid,'SLR','U');}?>
</div>
</div>
</div>
</div>
</div>
</div>

<?php include('../layout/quick.php');?>     
</section>
<!-- /.main content -->    
</div>

<?php 
include('../layout/footer.php');
?>
<!-- page script -->
<script type="text/javascript">
$(document).ready(function () {
var name = new LiveValidation('name');
name.add(Validate.Presence);  
var mobile = new LiveValidation('mobile');
mobile.add(Validate.Presence);
var address = new LiveValidation('address');
address.add(Validate.Presence);
   
});
    
  

function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
            
reader.onload = function (e) {
$('#profile-img-tag').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#profile-img").change(function(){
readURL(this);
});
$("#profile-img-tag").click(function() {
$("#profile-img").click();
}); 

// function readURL1(input) {
// if (input.files && input.files[1]) {
// var reader1 = new FileReader();
            
// reader1.onload = function (e) {
// $('#profile-img-tag1').attr('src', e.target.result);
// }
// reader1.readAsDataURL1(input.files[1]);
// }
// }
// $("#profile-img1").change(function(){
// readURL1(this);
// });
// $("#profile-img-tag1").click(function() {
// $("#profile-img1").click();
// }); 
</script>    
<!-- /page script -->
</html>