<?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='sellercre';
$page='Exchange Create';
$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['save_seller'])){
	$name = ucwords(remove_junk(escape($_POST['name'])));
    $code = get_genid('SU');
    $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_supplier WHERE cnumber = '$mobile'");
        }
        
        if($ducode->num_rows > 0) {
            save_msg('i','Mobile Number alrady used! Plz try another');
            echo "<script>window.location='main_suppliercreate.php'</script>";
        }else{
        $sql="INSERT INTO tbl_supplier(code,name,cperson,cnumber,address,status,uid,date) VALUES ('$code','$name','$cname','$mobile','$address','1','$aid','$dtnow')";    
        $result = mysqli_query($con,$sql) or die(mysqli_error($con));
        $efid=mysqli_affected_rows($con);    
        if($efid>0){
        $act =remove_junk(escape('Supplier name: '.$name));    
        write_activity($aid,'SUP','New supplier has been Added',$act);
        save_msg('s','Data Successfully Saved!');    
        }else{
        save_msg('w','Data Fail to Saved!');    
        }
    }  
    
	
	if(isset($_POST['mobile'])){
	$ducode = mysqli_query($con,"SELECT * FROM tbl_seller WHERE mobile = '$mobile'");
	}
	
	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="INSERT INTO tbl_seller(name,cname,mobile,telephone,date,nid,imei,price,address,statement,password,uid,brid,created_at) VALUES 
    ('$name','$cname','$mobile','$telephone','$date','$nid','$imei','$price','$address','$statement','$password',$aid,$brid,'$dtnow')";    
	$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_upload($cid,$_FILES['mimage'],'M');
        }
    if (!empty($_FILES["nimage"]["name"])){
        get_upload($cid,$_FILES['nimage'],'N');
        }
    $act =remove_junk(escape('Exchanger name: '.$name));    
    write_activity($aid,'SLR','New Exchanger has been Added',$act);
    save_msg('s','Data Successfully Saved!');    
    }else{
    save_msg('w','Data Fail to Saved!');    
    }
    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_sellercreate.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">

<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Name</label>    
<input type="text" name="name" maxlength="45" value="" id="name" class="form-control" placeholder="e.g. Md.Sumon Rahman"/>
</div>    
</div>
<div class="col-md-6">
    <div class="form-group">
        <label>Father/Mother Name</label>    
        <input type="text" name="cname" maxlength="45" value="" 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 if(isset($_SESSION['axes_joudata']['date'])){echo $_SESSION['axes_joudata']['date'];}else{echo date('Y-m-d');}?>" 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="" id="cnumber" 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="" id="cnumber" 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="" 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="" 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="" 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="" 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"></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"></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/emp/demp.jpg" 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/emp/demp.jpg" 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> 


</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="save_seller" id="submit" class="btn btn-flat bg-purple btn-sm" value="Save"/> <a href="main_cutomerlist.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>