<?php session_start();
include ('../inc/dbcon.php');
include ('../inc/functions.php');
if(isset($_SESSION["axeslogin"]) && $_SESSION["axeslogin"] == true){
get_pagesecurity('18','creates','R');    
$_SESSION['cuPages']='mas_currencycreate.php';   
$cuPage='mas_currencycreate.php';    
$aid=$_SESSION['uid'];    
}else{
header('Location:../index.php');
exit;    
}
$mhead='master';
$menuh='Master Process';
$phead='curcre';
$page='Add Currency';
$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_curency'])){
	$name = remove_junk(escape($_POST['name']));
    $sort = strtoupper(remove_junk(escape($_POST['sort'])));
    $symbol = remove_junk(escape($_POST['symbol']));
    $exrate = remove_junk(escape($_POST['exrate']));
	$status = remove_junk(escape($_POST['status']));
    
	if(isset($_POST['name'])){
	$ducode = mysqli_query($con,"SELECT * FROM tbl_currency WHERE name = '$name'");
	}
	
	if($ducode->num_rows > 0) {
		save_msg('i','Currency name alrady used! Plz try another');
		echo "<script>window.location='mas_currencycreate.php'</script>";
	}else{
    $sql="INSERT INTO tbl_currency(name,sortn,symbol,xrate,status,uid,date) VALUES ('$name','$sort','$symbol','$exrate','$status','$aid','$dtnow')";    
	$result = mysqli_query($con,$sql) or die(mysqli_error($con));
    $sid=$con->insert_id;    
    $efid=mysqli_affected_rows($con);    
    if($efid>0){
    $act =remove_junk(escape('Currency name: '.$name));    
    write_activity($aid,'CUR','New currency has been Added',$act);
    if($status==1){    
    $sql="UPDATE tbl_currency SET status='0' WHERE id!='$sid'";
    mysqli_query($con,$sql) or die(mysqli_error($con));
    }
    save_msg('s','Data Successfully Saved!');
    echo "<script>window.location='mas_currencycreate.php'</script>";
    }else{
    save_msg('w','Data Fail to Saved!');
    echo "<script>window.location='mas_currencycreate.php'</script>";    
    }    
	}  
}
?>
<div class="content-wrapper">
<?php include('../layout/page_head.php'); ?>
<!-- Main content -->
<section class="content">
    
<div class="row">
<div class="col-md-8">
<div class="box box-solid">
<div class="box-header with-border">
<h3 class="box-title">Add Currency</h3>
</div>
<div class="box-body">
<?php echo display_msg();?>  
<form action="mas_currencycreate.php" onsubmit="return validate()" enctype="multipart/form-data" method="post" accept-charset="utf-8">
<div class="col-md-12 popup_details_div">

<div class="row ">
<div class="col-md-12">
<div class="col-md-2"></div>
<div class="col-md-8">
<div class="col-md-12">
<div class="row">
<div class="col-md-8">    
<div class="form-group">
<label>Name</label>
<input type="text" name="name" maxlength="25" value="" id="name" class="form-control" placeholder="e.g. Taka" />
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label>Sort</label>
<input type="text" name="sort" maxlength="3" value="" id="sort" class="form-control" placeholder="e.g. BDT" />
</div>    
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label>Symbol</label>
<input type="text" name="symbol" maxlength="11" value="" id="symbol" class="form-control" placeholder="e.g. ৳" />
</div>    
</div>
<div class="col-md-4">
<div class="form-group">
<label>Ex-Rate</label>
<input type="text" name="exrate" maxlength="6" value="" id="exrate" class="form-control" onkeypress="return isNumberKey(event)" placeholder="e.g. 1" />
</div>    
</div>    
<div class="col-md-4">
<div class="form-group" >
<label>Default</label> 
<select class="form-control" name="status" id="status">
<option value="0">No</option>
<option value="1">Yes</option>    
</select>    
</div>    
</div>       
</div>        
</div>
</div>    
<div class="col-md-2"></div>    
</div>    
</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_curency" id="submit" class="btn btn-flat bg-purple btn-sm " value="Save"/> <a href="mas_currencylist.php" class="btn btn-flat bg-gray  ">Close</a>
</div> 
</div>     
</form>    
</div>
</div>
</div>
<div class="col-md-4">
<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,'CUR','A');}else{echo read_activity($aid,'CUR','U');}?>
</div>
</div>
</div>
</div>
</div>
</div>
    
</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 sort = new LiveValidation('sort');
sort.add(Validate.Presence);
var symbol = new LiveValidation('symbol');
symbol.add(Validate.Presence);
var exrate = new LiveValidation('exrate');
exrate.add(Validate.Presence);
var status = new LiveValidation('status');
status.add(Validate.Presence);    
});
</script>    
<!-- /page script -->
</html>    