<?php require_once('includes/check-login.php');
require_once('includes/config.php');
$tablename="payment_settings";
$viewurl="payment-settings.php";
if(isset($_POST['Add'])){
        $created=date("Y-m-d H:i:s");
        $query = "insert into ".$tablename." SET api_key='".$_POST['api_key']."',salt_key='".$_POST['salt_key']."',created='".$created."'";
		$exe = mysqli_query( $con, $query );		
		if( $exe ) {				
			$_SESSION[$tablename.'succ_msg'] = 'Settings added successfully';
		}else{				
			$_SESSION[$tablename.'err_msg'] = 'Error occured';
		}
        //header("Location:".$base_url.$viewurl."");
}
if(isset($_POST['Update'])){	
    $id=$_POST['id']; 
	$modified=date("Y-m-d H:i:s");
     $query = "update ".$tablename." SET api_key='".$_POST['api_key']."',salt_key='".$_POST['salt_key']."',modified='".$modified."' WHERE id='".$id."'";
	$exe = mysqli_query( $con, $query );		
	if( $exe ) {				
			$_SESSION[$tablename.'succ_msg'] = 'Settings updated successfully';
	}else{				
			$_SESSION[$tablename.'err_msg'] = 'Error occured';
	}
    //header("Location:".$base_url.$viewurl."");
  
}	  
$sql=$con->query("SELECT * from ".$tablename."");
if(mysqli_num_rows($sql)>0){
$display       = "Update";
$row=mysqli_fetch_array($sql);
$id            = $row['id']; 
$api_key       = $row['api_key'];
$salt_key      = $row['salt_key'];
$status        = $row['status'];     
}else{
$id            = ""; 
$api_key       = "";
$salt_key       = "";
$status        = "";
$display = "Add";
}	  
require_once('includes/header.php');
require_once('includes/menu.php'); ?>
<!------ Include the above in your HEAD tag ---------->
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
      <!-- Content Header (Page header) -->
            <section class="content-header">                               
                    <ol class="breadcrumb">
                        <li><a href="<?php echo $base_url;?>"><i class="fa fa-dashboard"></i>Home</a></li>                    
                        <li class="active"><a href="#">Payment Settings</a></li>           
                    </ol>                
            </section>
<form id="serviceData" method="POST" enctype="multipart/form-data">
    <div class="row setup-content">
      <div class="col-xs-6 col-md-offset-3">
        <div class="col-md-12">
            <center><h3>Payment Settings</h3></center>
            <center><?php if(isset($_SESSION[$tablename."succ_msg"])) {?>
                 <div class="alert alert-success">
                 <a href="#" class="close" data-dismiss="alert" aria-label="close" title="close">×</a>
                 <?php echo $_SESSION[$tablename."succ_msg"];  unset($_SESSION[$tablename."succ_msg"]);?>
                 </div>
                <?php }?>   
                <?php if(isset($_SESSION[$tablename."err_msg"])) {?>
                <div class="alert alert-success">
                <a href="#" class="close" data-dismiss="alert" aria-label="close" title="close">×</a>
                <?php echo $_SESSION[$tablename."err_msg"]; unset($_SESSION[$tablename."err_msg"]);?>
                </div>
               <?php }?></center>
              <div class="form-group">
                <label class="control-label">Api Key</label>
                <input type="hidden" name="id" value="<?php echo $id;?>">
                <input  id="api_key" name="api_key" value="<?php echo $api_key; ?>" type="text" class="form-control" placeholder="Api Key"  />
              </div>  
              <div class="form-group">
                <label class="control-label">Salt Key</label>
                <input  id="salt_key" name="salt_key" value="<?php echo $salt_key; ?>" type="text" class="form-control" placeholder="Salt Key"  />
              </div>  
              <button class="btn btn-success btn-lg" type="submit" name="<?php echo $display;?>"><?php echo $display;?></button>
        </div>
      </div>
    </div>
  </form>
</div>
<script src="js/common.js"></script>  
<script src="<?php echo $base_url;?>js/jquery-3.4.1.min.js"></script>
<script src="<?php echo $base_url;?>js/jquery.validate.min.js"></script>
<script type="text/javascript">
$(function(){
       $("#serviceData").validate({
          rules: {
               api_key: 'required',
               salt_key: 'required',
           },
            messages: {
                                  
            },
            submitHandler: function(form) {
              form.submit();
           }
    });        
});
</script>
<?php require_once('includes/footer.php'); ?>