<?php

if (session_status() === PHP_SESSION_NONE) session_start();
if (!isset($_SESSION['reid'])) header('location:index.php');

require_once("../dashboard/conn.php");

require_once '../dashboard/dbconfig4.php';

if(isset($_SESSION['reid'])){

	$user_qury=mysqli_query($conn,"SELECT * FROM ormsregister WHERE reid='$_SESSION[reid]'");

	$user_resalt=mysqli_fetch_array($user_qury);

	$customer = $user_resalt['reid'];
	
	$addbycustomer = $user_resalt['userid'];

	if($user_resalt['image']==""){

		$image_path="../dashboard/images/empty.jpg";

	}

	else{

		$image_path="../dashboard/images/sellers/".$user_resalt['image'];

	}

}

$msg5 = '';	

if(isset($_POST['add_customers']))

	{

        $title = $_POST['title'];
		$fname = $_POST['fname'];
		$lname = $_POST['lname'];
		$shopname = $_POST['shopname'];
		$sellertype = $_POST['sellertype'];
		$sellerpackage = $_POST['sellerpackage'];
		$username = $_POST['username'];
		$email = $_POST['email'];
		$mobilenumber=(int)mysqli_real_escape_string($conn,$_POST['mobilenumber	']);
		$to="0".(int)mysqli_real_escape_string($conn,$_POST['mobilenumber	']);
		$nicnumber = $_POST['nicnumber'];
		$shopaddress = $_POST['shopaddress'];
		$country = $_POST['country'];
		$province = $_POST['province'];
		$district = $_POST['district'];
		$division = $_POST['division'];
		$creditadd = $_POST['creditadd'];	
		$password=md5(mysqli_real_escape_string($con,$_POST['password']));
		$confirm_password=md5(mysqli_real_escape_string($con,$_POST['confirm_password']));
		$status = $_POST['status'];	
		
		if(empty($title)){			
		$errMSG = "Please Select Title.";
		}else if(empty($fname)){			
		$errMSG = "Please Enter First Name.";
		}else if(empty($lname)){			
		$errMSG = "Please Enter Last Name.";
		}else if(empty($shopname)){
		$errMSG = "Please Enter Shop Name.";
		}else if(empty($sellertype)){			
		$errMSG = "Please Select Seller Type.";
		}else if(empty($sellerpackage)){
		$errMSG = "Please Select Seller Package.";
		}else if(empty($username)){			
		$errMSG = "Please Enter Username.";
		}else if(empty($email)){
		$errMSG = "Please Enter Email Address.";
		}else if(empty($mobilenumber)){			
		$errMSG = "Please Enter Mobile Number.";
		}else if(empty($nicnumber)){
		$errMSG = "Please Enter Nic Number.";
		}else if(empty($shopaddress)){
		$errMSG = "Please Enter Shop Address.";
		}else if(empty($country)){
		$errMSG = "Please Select Country.";
		}else if(empty($province)){
		$errMSG = "Please Select Province.";
		}else if(empty($district)){
		$errMSG = "Please Select District.";
		}else if(empty($division)){
		$errMSG = "Please Select $division.";
		}else if(empty($creditadd)){
		$errMSG = "Please Enter Credit Add.";
		}else if(empty($status)){
		$errMSG = "Please Select Status.";
		}

		// if no error occured, continue ....
		if(!isset($errMSG))
		{
			$stmt = $DB_con->prepare('INSERT INTO ormsregister(fname,lname,shopname,sellertype,sellerpackage,username,email,mobilenumber,nicnumber,shopaddress,country,province,district,division,creditadd,password,status) VALUES(:fname,:lname,:shopname,:sellertype,:sellerpackage,:username,:email,:mobilenumber,:nicnumber,:shopaddress,:country,:province,:district,:division,:creditadd,:password,:status)');
			$stmt->bindParam(':title',$title);						
			$stmt->bindParam(':fname',$fname);						
			$stmt->bindParam(':lname',$lname);
			$stmt->bindParam(':shopname',$shopname);
			$stmt->bindParam(':sellertype',$sellertype);
			$stmt->bindParam(':sellerpackage',$sellerpackage);
			$stmt->bindParam(':username',$username);						
			$stmt->bindParam(':email',$email);						
			$stmt->bindParam(':mobilenumber',$mobilenumber);
			$stmt->bindParam(':nicnumber',$nicnumber);
			$stmt->bindParam(':shopaddress',$shopaddress);
			$stmt->bindParam(':country',$country);
			$stmt->bindParam(':province',$province);						
			$stmt->bindParam(':district',$district);						
			$stmt->bindParam(':division',$division);
			$stmt->bindParam(':creditadd',$creditadd);
			$stmt->bindParam(':password',$password);
			$stmt->bindParam(':status',$status);

			if($stmt->execute())

			{

				$successMSG = "Sellers/Customers Successfully Added.";

				header("refresh:2;customers.php"); // redirects image view page after 5 seconds.

			}

			else

			{

				$errMSG = "error while inserting....";

			}
		
}
		
}

?>

<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Reload Api Credentials | Recharge and Billing System | ORMS | Dashbaord</title>
	
	<?php
	require_once 'headercss.php';
	?>

</head>

<body>

    <!--**********************************
        Main wrapper start
    ***********************************-->
    <div id="main-wrapper">

    <?php
	require_once 'header.php';
	?>

        <!--**********************************
            Sidebar start
        ***********************************-->
        <div class="deznav">
            <div class="deznav-scroll">
	<?php

	require_once 'sidebarmenu.php';

	?>
            </div>
        </div>
        <!--**********************************
            Sidebar end
        ***********************************-->
		
        <!--**********************************
            Content body start
        ***********************************-->
        <div class="content-body">
            <!-- row -->
            <div class="container-fluid">
				<div class="row">
				<div class="col-xl-12 col-xxl-12 col-sm-12">
				<div class="alert alert-danger bg-danger text-white" role="alert">
				<strong>Alert!</strong> ඔබගේ ගිනුම තහවුරු කිරීම අසම්පුර්නයි.<a href="identity_verify.php" class="btn btn-success float-right" style="background-color:#0847cb;font-weight:bold;font-size:18px;color:#ffffff;padding:4px 4px;">සම්පුර්න කරන්න</a>
				</div>
				</div>
				</div> 
                <div class="row page-titles mx-0">
                    <div class="col-sm-6 p-md-0">
                        <div class="welcome-text">
                            <h4>Reload Api Credentials</h4>
                        </div>
                    </div>
                    <div class="col-sm-6 p-md-0 justify-content-sm-end mt-2 mt-sm-0 d-flex">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="index.php">Home</a></li>
                            <li class="breadcrumb-item"><a href="javascript:void(0);">Reload Api Credentials</a></li>
                            <li class="breadcrumb-item active"><a href="javascript:void(0);">Reload Api Credentials</a></li>
                        </ol>
                    </div>
                </div>
				
				<div class="row">
					<div class="col-lg-12">
					<div class="container" style="max-width: 50rem">
			<div class="card">
				<div class="card-body">
					<h3 class="text-center">Reload Api Credentials</h3>
					<hr>
					<form class="pt-4 pl-3 pr-3" action="" method="post">
						<div class="form-group row">
							<label for="user_name" class="col-sm-3 col-form-label">API User Name</label>
							<div class="col-sm-9">
								<input type="text" class="form-control" id="user_name" value="NDIwNjAw" readonly="">
							</div>
						</div>
						<div class="form-group row">
							<label for="api_key" class="col-sm-3 col-form-label">API Key</label>
							<div class="col-sm-9">
								<div class="input-group addon">
									<input type="text" class="form-control" id="api_key" name="api_key" readonly="" value="50b664cd0ad4ae4688a1">
									<button class="btn btn-info" title="Click Here to Generate a New API Key"><i class="fas fa-redo-alt"></i></button>
								</div>
							</div>
						</div>
					</form>
					<form class="pt-4 pl-4 pr-4" method="post" action="https://manager.quickpaylanka.com/ManagerAPI/addNewIP" id="frm_ip">
						<table class="table">
							<thead>
								<tr><th>ALLOWED IP ADDRESS</th>
								<th class="text-center">ACTION</th>
							</tr></thead>
							<tbody>
																	<tr>
										<td>50b664cd0ad4ae4688a1</td>
										<td class="text-center">
											<button type="button" class="btn btn-danger" onclick="del_ip('69')"><i class="fas fa-trash"></i></button>
										</td>
									</tr>
																	<tr>
										<td>2</td>
										<td class="text-center">
											<button type="button" class="btn btn-danger" onclick="del_ip('73')"><i class="fas fa-trash"></i></button>
										</td>
									</tr>
																	<tr>
										<td>116.206.245.90</td>
										<td class="text-center">
											<button type="button" class="btn btn-danger" onclick="del_ip('74')"><i class="fas fa-trash"></i></button>
										</td>
									</tr>
																	<tr>
										<td>123.231.84.59</td>
										<td class="text-center">
											<button type="button" class="btn btn-danger" onclick="del_ip('75')"><i class="fas fa-trash"></i></button>
										</td>
									</tr>
																<tr>
									<td><input type="text" class="form-control" id="ip_adress" name="ip_adress"></td>
									<td class="text-center"><button class="btn btn-primary" onclick="add_ip()" id="btn_add_ip" type="button"><i class="fas fa-plus"></i></button></td>
								</tr>
							</tbody>
						</table>
					</form>
				</div>
			</div>
		</div>
					</div>
				</div>
				
            </div>
        </div>
        <!--**********************************
            Content body end
        ***********************************-->

		<?php
		require_once 'footer.php';
		?>

		<!--**********************************
           Support ticket button start
        ***********************************-->

        <!--**********************************
           Support ticket button end
        ***********************************-->

    </div>
    <!--**********************************
        Main wrapper end
    ***********************************-->

    <?php
	require_once 'footerjs.php';
	?>
    
</body>
</html>