<?php
// Enable CORS headers
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, POST");
header("Access-Control-Allow-Headers: Content-Type");
// Get the current date and time in the Asia/Kolkata timezone
date_default_timezone_set('Asia/Kolkata');
$current_date = date('Y-m-d H:i:s');
require_once 'db.php';
$type= $_GET['type'];
$recharge_id = $_GET['recharge_id'];
$plan = $_GET['plan'];
if($plan == '3 Days Plan'){
$recharge_amount = '99';
$questions = '10';
$end_date = date('Y-m-d H:i:s', strtotime($current_date . ' + 3 days'));
}if($plan == '6 Months Plan'){
$recharge_amount = '799';
$questions = '30';
$end_date = date('Y-m-d H:i:s', strtotime($current_date . ' + 6 months'));
}if($plan == '1 Year Plan'){
$recharge_amount = '999';
$questions = '999';
$end_date = date('Y-m-d H:i:s', strtotime($current_date . ' + 1 year'));
}
if (isset($_POST['submit'])) {
try {
$plan_name = $_POST['plan_name'];
$plan_recharge = $_POST['plan_recharge'];
$plan_mode = $_POST['plan_mode'];
$plan_user_id = $_GET['id'];
$plan_user_phone = $_GET['phone'];
$plan_mem_start_date = $current_date;
$plan_mem_end_date = $end_date;
$plan_status = 'Pending';
$user_email = $user_phone . "@agriexpertt.com";
$user_district = $_POST['user_district'];
$user_dob = $_POST['user_password'];
$user_role = 'Farmar';
$user_password = md5($_POST['user_password']);
$sql = "INSERT INTO membership (mem_mobile, mem_mem_id, mem_start_date, mem_end_date, status)
VALUES (:mem_mobile, :mem_mem_id, :mem_start_date, :mem_end_date, :status)";
$pdo1 = $pdo->prepare($sql); // Use $pdo instead of $conn
$pdo1->bindParam(':mem_mobile', $plan_user_phone);
$pdo1->bindParam(':mem_mem_id', $plan_user_id);
$pdo1->bindParam(':mem_start_date', $plan_mem_start_date);
$pdo1->bindParam(':mem_end_date', $plan_mem_end_date);
$pdo1->bindParam(':status', $plan_status);
$pdo1->execute();
echo "Successful";
$lastInsertId = $pdo->lastInsertId();
header("Location: recharge.php?type=$plan_mode&recharge_id=$lastInsertId");
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
if (isset($_POST['payment_proof'])) {
// File Upload Codes
$allow = array("jpg", "JPG", "jpeg", "JPEG", "gif", "GIF", "png", "PNG", "pdf", "PDF");
// Check if a file was uploaded
if ($_FILES['photo1']['name'] != "") {
$photo1 = basename($_FILES['photo1']['name']);
$extension = pathinfo($photo1, PATHINFO_EXTENSION);
if (in_array($extension, $allow)) {
$target_path = "assets/uploads/payment_proof/";
$photo1 = md5(rand() * time()) . '.' . $extension;
$target_path = $target_path . $photo1;
move_uploaded_file($_FILES['photo1']['tmp_name'], $target_path);
}
}
if ($_FILES['photo1']['error'] > 0) {
echo "Error: " . $_FILES['photo1']['error'];
}
try {
$user_email = $user_phone . "@agriexpertt.com";
$recharge_id = $_GET['recharge_id'];
// Update the membership table to include the payment proof
$sql = "UPDATE membership SET membership_payment_proof = :payment_proof
WHERE id = :recharge_id";
$pdo1 = $pdo->prepare($sql);
$pdo1->bindParam(':payment_proof', $photo1); // Assuming $photo1 contains the filename
$pdo1->bindParam(':recharge_id', $recharge_id);
$pdo1->execute();
echo "Successful Upload";
header("Location: recharge.php?type=Thankyou");
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Recharge Now</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
</head>
<body>
<?php
if($type == 'Thankyou'){
?>
<div class="container">
<div class="row pt-5">
<div class="col-md-12" style="text-align: center">
<h3>Congratulations</h3>
Your Recharge Request Has Been Uploaded Successfully.
<br>
Your Account Will Be Activated Within Shortly!
</div>
</div>
</div>
<?php
}
if($type == 'Offline'){
?>
<div class="container">
<div class="row">
<div class="col-md-12" style="text-align: center">
QR CODE WILL COME HERE
<br>
---------------------
<br>
Or Transfer To Below Mentioned Account
<br>
A/C NAME: M/S AGRIEXPERT
<br>
A/C No: 99900015022023
<br>
IFSC CODE: HDFC0005221
<br>
Branch: GUWAHATI, SIXMILE
<br>
<br>
<strong> After Transferring Your Recharge Amount <br> Kindly Upload The Payment Proof Below</strong>
<br>
</div>
</div>
<div class="row">
<form method="POST" enctype="multipart/form-data">
<div class="col-md-12" style="text-align:left">
<br>
<label style="text-align:left">Upload Screenshot / Payment Proof</label>
<br>
<input type="file" class="form-control" name="photo1">
</div>
<br>
<div class="col-md-12" style="text-align:center">
<button name="payment_proof" style="width:200px; border-radius: 50px" class="btn btn-success">Submit</button>
</div>
</form>
</div>
</div>
</div>
<?php
}
if($type == 'Online'){
?>
<div class="container">
<div class="row pt-5">
<div class="col-md-12" style="text-align: center">
<h3>Redirecting To Payment Gateway</h3>
<?php
$recharge_id = $_GET['recharge_id'];
header("Location: https://agriexpertt.com/mobile/Flutter/insta_request.php?recharge_id=$recharge_id");
recharge_id
?>
<br>
</div>
</div>
</div>
<?php
}
if($type == ''){
?>
<div class="container-fluid" >
<div class="row">
<form method="POST" >
<div class="col-md-12" style="text-align:left">
<label style="text-align:left">Recharge Plan</label>
<input readonly type="text" class="form-control" name="plan_name" value="<?php echo $_GET['plan']?>">
</div>
<br>
<div class="col-md-12" style="text-align:left">
<label style="text-align:left">Recharge Amount</label>
<input readonly type="text" class="form-control" name="plan_recharge" value="<?php echo $recharge_amount?>">
</div>
<br>
<div class="col-md-12" style="text-align:left">
<label style="text-align:left">Recharge Mode</label>
<br>
<select required name="plan_mode" class="form-control">
<option value="">---Select Plan---</option>
<option value="Online">Online Recharge</option>
<option value="Offline">Offline Recharge</option>
</select>
</div>
<br>
<div class="col-md-12" style="text-align:center">
<button name="submit" style="width:200px; border-radius: 50px" class="btn btn-success">Submit</button>
</div>
</form>
</div>
</div>
</div>
<?php
}
?>
</body>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
</html>