Suvodip 2025-03-04 20:24:41 +05:30
parent d0ba11be1c
commit ce1dace3fb
14 changed files with 426 additions and 30 deletions

View File

@ -1,3 +1,7 @@
<div class="container mt-4">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quibusdam mollitia quidem sint dolores nostrum, similique nulla consequuntur. Animi neque labore praesentium ratione a? Facere, quasi ea reprehenderit eum tempora voluptatum.
</div>
</div>
<?php
var_dump($_SESSION);
// echo $_SESSION['userName'] . $_SESSION['userEmail'] . $_SESSION['userType'] . $_SESSION['isLogedin'];
?>

View File

@ -21,6 +21,15 @@
<li class="nav-item">
<a class="nav-link" href="/contact-us">Contact</a>
</li>
<li class="nav-item">
<?php
if (isset($_SESSION['isLogedin']) && $_SESSION['isLogedin'] === true) {
echo '<a class="nav-link" href="/logout">Logout</a>';
} else {
echo '<a class="nav-link" href="/login">Login</a>';
}
?>
</li>
</ul>
</div>
</div>

54
.hta_slug/login.php Normal file
View File

@ -0,0 +1,54 @@
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['email']) && isset($_POST['password'])) {
$userPassword = md5($_POST['password']);
try {
$db = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $db->prepare("SELECT * FROM users WHERE email = :email AND password = :password");
$stmt->bindParam(':email', $_POST['email'], PDO::PARAM_STR);
$stmt->bindParam(':password', $userPassword, PDO::PARAM_STR);
$stmt->execute();
$user = $stmt->fetch(PDO::FETCH_ASSOC); // Fetch a single record
if ($user) {
$_SESSION['userName'] = $user['name'];
$_SESSION['userEmail'] = $user['email'];
$_SESSION['userType'] = $user['type'];
$_SESSION['isLogedin'] = true;
$_SESSION['customerId'] = $user['customerId'];
var_dump($_SESSION);
echo "Login successful! Welcome, " . htmlspecialchars($user['email']);
// var_dump($_SESSION);
} else {
echo "Invalid email or password.";
}
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
?>
<div class="d-flex justify-content-center align-items-center vh-100 bg-light">
<div class="card p-4 shadow-lg" style="max-width: 400px; width: 100%;">
<h3 class="text-center mb-4">Login</h3>
<form method="post">
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Enter your email" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" placeholder="Enter your password" required>
</div>
<div class="mb-3 form-check">
<input type="checkbox" class="form-check-input" id="rememberMe">
<label class="form-check-label" for="rememberMe">Remember me</label>
</div>
<button type="submit" class="btn btn-primary w-100">Login</button>
</form>
<p class="text-center mt-3"><a href="#">Forgot password?</a></p>
</div>
</div>

13
.hta_slug/logout.php Normal file
View File

@ -0,0 +1,13 @@
<?php
session_start(); // Start the session
// Unset all session variables
$_SESSION = [];
// Destroy the session
session_destroy();
// Redirect to login page
header("Location: /");
exit;
?>

View File

@ -6,28 +6,41 @@
<h4>Customer Registration</h4>
</div>
<div class="card-body">
<?php
require('../.hta_config/conf.php');
<?php
require('../.hta_config/conf.php');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
try {
$customerId = str_replace('.', '', uniqid('cust_', true));
$userPassword = md5($_POST['password']);
$db = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
try {
$db = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $db->prepare("INSERT INTO customers (name, mobile, email) VALUES (:name, :mobile, :email)");
$stmt->bindParam(':name', $_POST['name']);
$stmt->bindParam(':mobile', $_POST['mobile']);
$stmt->bindParam(':email', $_POST['email']);
$stmt = $db->prepare("INSERT INTO customers (name, mobile, email, customerId) VALUES (:name, :mobile, :email, :customerId)");
$stmt->bindParam(':name', $_POST['name']);
$stmt->bindParam(':mobile', $_POST['mobile']);
$stmt->bindParam(':email', $_POST['email']);
$stmt->bindParam(':customerId', $customerId);
if ($stmt->execute()) {
echo '<div class="alert alert-success">New Customer <strong>' . htmlspecialchars($_POST['name']) . '</strong> created successfully.</div>';
} else {
echo '<div class="alert alert-danger">Error executing statement: ' . $stmt->errorInfo()[2] . '</div>';
}
} catch (PDOException $e) {
echo '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
$stmt2 = $db->prepare("INSERT INTO users (name, mobile, email, type, password, customerId) VALUES (:name, :mobile, :email, :type, :password, :customerId)");
$stmt2->bindParam(':name', $_POST['name']);
$stmt2->bindParam(':mobile', $_POST['mobile']);
$stmt2->bindParam(':email', $_POST['email']);
$stmt2->bindParam(':type', $_POST['type']);
$stmt2->bindParam(':password', $userPassword);
$stmt2->bindParam(':customerId', $customerId);
if ($stmt->execute()) {
$stmt2->execute();
echo '<div class="alert alert-success">New Customer <strong>' . htmlspecialchars($_POST['name']) . '</strong> created successfully.</div>';
} else {
echo '<div class="alert alert-danger">Error inserting into customers table: ' . $stmt->errorInfo()[2] . '</div>';
}
} catch (PDOException $e) {
echo '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
}
}
?>
<form method="POST">
<div class="form-group">
<label for="name">Name:</label>
@ -42,6 +55,20 @@
<label for="email">Email:</label>
<input type="email" id="email" name="email" class="form-control" required>
</div>
<div class="form-group">
<label for="type">User Type:</label>
<select class="form-control" name="type" id="type" require>
<option value="">-Select-</option>
<option value="user">User</option>
<option value="admin">Admin</option>
</select>
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" id="password" name="password" class="form-control" required>
</div>
<button type="submit" class="btn btn-success btn-block mt-2">Save Customer</button>
</form>
</div>

View File

@ -1,18 +1,25 @@
<?php
session_start();
require('../.hta_slug/_header.php');
require('../.hta_slug/_nav.php');
require_once('../.hta_config/var.php');
if(isset($_SESSION['isLogedin']) && $_SESSION['isLogedin'] === true && isset($_SESSION['userType']) && $_SESSION['userType'] === 'admin'){
require_once('../.hta_config/var.php');
$url = explode('/', $_SERVER['REQUEST_URI']);
if (strpos($url[1], "?") !== false) {
$url2 = explode('?', $url[1]);
$slug=$url2[0];
} else $slug=$url[2];
require_once('../.hta_slug/_header.php');
if($slug=="") require_once('.hta_slug/_home.php');
elseif(file_exists(".hta_slug/".$slug.".php")) include ".hta_slug/".$slug.".php";
else require_once('.hta_slug/_404.php');
} else{
header("location:/");
}
$url = explode('/', $_SERVER['REQUEST_URI']);
if (strpos($url[1], "?") !== false) {
$url2 = explode('?', $url[1]);
$slug=$url2[0];
} else $slug=$url[2];
require_once('../.hta_slug/_header.php');
if($slug=="") require_once('.hta_slug/_home.php');
elseif(file_exists(".hta_slug/".$slug.".php")) include ".hta_slug/".$slug.".php";
else require_once('.hta_slug/_404.php');
require_once('../.hta_slug/_footer.php');

View File

@ -1,4 +1,5 @@
<?php
session_start();
require_once('.hta_config/var.php');
$url = explode('/', $_SERVER['REQUEST_URI']);

View File

View File

@ -0,0 +1,94 @@
<?php
require('../.hta_config/conf.php');
?>
<div class="container mt-4">
<h2 class="mb-3 text-center">Customer List</h2>
<div class="table-responsive">
<table class="table table-bordered table-striped table-hover">
<thead class="bg-primary text-white text-center">
<tr>
<th>Sl No</th>
<th>Name</th>
<th>Mobile</th>
<th>Email</th>
<th>Invoice Id</th>
<th>Invoice Date</th>
<th>Amount</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
echo $_SESSION['customerId'];
try {
// Connect to the database
$db = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Fetch customer data
$stmt = $db->prepare("SELECT * FROM customers WHERE customerId = :customerId ORDER BY regDate DESC");
$stmt->bindParam(':customerId', $_SESSION['customerId']);
$stmt->execute();
$content = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Fetch invoice data
$stmt2 = $db->prepare("SELECT * FROM invoice");
$stmt2->execute();
$invoiceContent = $stmt2->fetchAll(PDO::FETCH_ASSOC);
// Loop through each customer
$customerSerial = 1;
foreach ($content as $customer) {
// Find all invoices for the current customer
$matchingInvoices = array_filter($invoiceContent, function ($invoice) use ($customer) {
return $invoice['customerId'] === $customer['customerId'];
});
// If there are matching invoices, loop through them
if (!empty($matchingInvoices)) {
foreach ($matchingInvoices as $invoice) {
?>
<tr>
<td><?php echo $customerSerial++; ?></td>
<td><?php echo htmlspecialchars($customer['name']); ?></td>
<td><?php echo htmlspecialchars($customer['mobile']); ?></td>
<td><?php echo htmlspecialchars($customer['email']); ?></td>
<!-- Invoice Data -->
<td><?php echo htmlspecialchars($invoice['invoiceId']); ?></td>
<td><?php echo htmlspecialchars($invoice['invoiceDate']); ?></td>
<td><?php echo htmlspecialchars($invoice['totalAmount']); ?></td>
<td>
<a href="/my-account/emi-details/?customerId=<?php echo $customer['customerId'] . '&invoiceId=' . $invoice['invoiceId']; ?>" class="btn btn-primary btn-sm">EMI Details</a>
<a href="/customers/print-invoice/?customerId=<?php echo $customer['customerId'] . '&invoiceId=' . $invoice['invoiceId']; ?>" class="btn btn-primary btn-sm">Print</a>
</td>
</tr>
<?php
}
} else {
// For customers without an invoice, you can still display their info but leave invoice data empty
?>
<tr>
<td><?php echo $customerSerial++; ?></td>
<td><?php echo htmlspecialchars($customer['name']); ?></td>
<td><?php echo htmlspecialchars($customer['mobile']); ?></td>
<td><?php echo htmlspecialchars($customer['email']); ?></td>
<td colspan="3">No invoice available</td>
<td>
<a href="/customers/billing-details/?customerId=<?php echo $customer['customerId']; ?>" class="btn btn-primary btn-sm">EMI Details</a>
</td>
</tr>
<?php
}
}
} catch (PDOException $e) {
echo '<tr><td colspan="5" class="text-danger text-center">Error: ' . $e->getMessage() . '</td></tr>';
}
?>
</tbody>
</table>
</div>
</div>

View File

@ -0,0 +1,99 @@
<?php
require('../.hta_config/conf.php');
try {
$db = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['emiId'], $_POST['payStatus'])) {
header('Content-Type: application/json');
ob_end_clean(); // Clears any accidental HTML output
try {
$stmt = $db->prepare("UPDATE emi SET payStatus = :payStatus WHERE customerId = :customerId AND id = :emiId");
$stmt->bindParam(':customerId', $_GET['customerId']);
$stmt->bindParam(':payStatus', $_POST['payStatus'], PDO::PARAM_INT);
$stmt->bindParam(':emiId', $_POST['emiId'], PDO::PARAM_INT);
$stmt->execute();
echo json_encode(['status' => 'success']);
} catch (PDOException $e) {
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
}
exit;
}
// Fetch EMI data
$stmt = $db->prepare("SELECT * FROM emi WHERE customerId = :customerId AND invoiceId = :invoiceId ORDER BY emiDate ASC");
$stmt->bindParam(':customerId', $_GET['customerId']);
$stmt->bindParam(':invoiceId', $_GET['invoiceId']);
$stmt->execute();
$emiPlans = $stmt->fetchAll(PDO::FETCH_ASSOC);
// var_dump($emiPlans);
$stmt = $db->prepare("SELECT * FROM customers WHERE customerId = :customerId");
$stmt->bindParam(':customerId', $_GET['customerId']);
$stmt->execute();
$customer = $stmt->fetch(PDO::FETCH_ASSOC);
// var_dump($customer);
} catch (PDOException $e) {
die('<div class="alert alert-danger text-center">Error: ' . $e->getMessage() . '</div>');
}
?>
<div class="container mt-4">
<h2 class="mb-3">EMI Details</h2>
<div class="d-flex justify-content-between">
<div>
<p>Customer Name: <strong><?php echo $customer['name']; ?></strong></p>
<p>Mobile Number: <strong><?php echo $customer['mobile']; ?></strong></p>
<p>EMI Booking Date: <strong><?php echo $emiPlans[0]['bookingDate']; ?></strong></p>
<p>EMI Booking Date: <strong><?php echo $emiPlans[0]['invoiceId']; ?></strong></p>
</div>
<div>
<?php
$currentOutstanding = 0;
$totalAmount = 0;
foreach ($emiPlans as $emi) {
$totalAmount = $emi['totalAmount'];
if ($emi['payStatus'] == 0) {
$currentOutstanding += $emi['emiAmount'];
}
}
?>
<p>Total Amount: <strong><?php echo $totalAmount; ?></strong></p>
<p>Outstanding: <strong><?php echo round($currentOutstanding); ?></strong></p>
<p>Tenure: <strong><?php echo $emiPlans[0] ? $emiPlans[0]['tenure'] : 0; ?></strong></p>
<p>Frequency: <strong><?php echo $emiPlans[0] ? $emiPlans[0]['frequency'] : 0; ?></strong></p>
</div>
</div>
<table class="table table-striped table-bordered">
<thead class="bg-primary text-white text-center">
<tr>
<th>Number of EMI</th>
<th>EMI Amount</th>
<th>EMI Date</th>
<th>Payment Status</th>
<th>Outstanding</th>
</tr>
</thead>
<tbody>
<?php foreach ($emiPlans as $emi) { ?>
<tr id="row-<?= $emi['id']; ?>">
<td><?= $emi['emiNumber']; ?></td>
<td><?= number_format($emi['emiAmount'], 2); ?></td>
<td><?= date('d-m-Y', strtotime($emi['emiDate'])); ?></td>
<td>
<span id="status-<?= $emi['id']; ?>" class="badge <?= $emi['payStatus'] == 0 ? 'bg-danger' : 'bg-success'; ?>">
<?= $emi['payStatus'] == 0 ? 'Unpaid' : 'Paid'; ?>
</span>
</td>
<td><?= number_format($emi['outstanding'], 2); ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>

View File

@ -0,0 +1,60 @@
<?php
require('../.hta_config/conf.php');
try {
$db = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$currentMonth = date('Y-m');
$stmt = $db->prepare(" SELECT e.customerId, c.name, e.emiAmount, e.emiDate, e.payStatus, e.outstanding FROM emi e JOIN customers c ON e.customerId = c.customerId WHERE DATE_FORMAT(e.emiDate, '%Y-%m') = :currentMonth ORDER BY e.emiDate ASC");
$stmt->bindParam(':currentMonth', $currentMonth);
$stmt->execute();
$emiPlans = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Calculate total demand amount
$totalDemand = array_sum(array_column($emiPlans, 'emiAmount'));
} catch (PDOException $e) {
die("Database error: " . $e->getMessage());
}
?>
<div class="container mt-5">
<h2 class="mb-4">Pending EMIs for <?php echo date('F Y'); ?></h2>
<table class="table table-bordered table-striped table-hover">
<thead class="bg-primary text-white text-center">
<tr>
<th>Customer Name</th>
<th>EMI Amount</th>
<th>EMI Date</th>
<th>Pay Status</th>
<th>Outstanding</th>
</tr>
</thead>
<tbody>
<?php if (!empty($emiPlans)) : ?>
<?php foreach ($emiPlans as $emi) : ?>
<tr>
<td><?php echo htmlspecialchars($emi['name']); ?></td>
<td><?php echo number_format($emi['emiAmount'], 2); ?></td>
<td><?php echo date('d M Y', strtotime($emi['emiDate'])); ?></td>
<td>
<?php if ($emi['payStatus'] == 0) : ?>
<span class="badge bg-danger">Pending</span>
<?php else : ?>
<span class="badge bg-success">Paid</span>
<?php endif; ?>
</td>
<td><?php echo number_format($emi['outstanding'], 2); ?></td>
</tr>
<?php endforeach; ?>
<?php else : ?>
<tr>
<td colspan="5" class="text-center">No pending EMIs this month</td>
</tr>
<?php endif; ?>
</tbody>
</table>
<div class="mt-3">
<h4>Total Demand EMI Amount: <?php echo number_format($totalDemand, 2); ?></h4>
</div>
</div>

8
my-account/.htaccess Normal file
View File

@ -0,0 +1,8 @@
RewriteEngine On
#RewriteCond %{HTTPS} !=on
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php

19
my-account/index.php Normal file
View File

@ -0,0 +1,19 @@
<?php
session_start();
require('../.hta_slug/_header.php');
require('../.hta_slug/_nav.php');
require_once('../.hta_config/var.php');
$url = explode('/', $_SERVER['REQUEST_URI']);
if (strpos($url[1], "?") !== false) {
$url2 = explode('?', $url[1]);
$slug=$url2[0];
} else $slug=$url[2];
require_once('../.hta_slug/_header.php');
if($slug=="") require_once('.hta_slug/_home.php');
elseif(file_exists(".hta_slug/".$slug.".php")) include ".hta_slug/".$slug.".php";
else require_once('.hta_slug/_404.php');
require_once('../.hta_slug/_footer.php');

View File

@ -0,0 +1 @@
sample-page