v1.incomplete4

This commit is contained in:
Flatlogic Bot 2025-12-05 20:00:32 +00:00
parent 4a8a75e6db
commit 3f3c2f83af
6 changed files with 197 additions and 98 deletions

View File

@ -1,85 +1,42 @@
<?php <?php
require_once 'includes/header.php';
require_once 'db/config.php';
if (!isset($_SESSION['user_id'])) { if (!isset($_SESSION['user_id'])) {
header('Location: login.php'); header('Location: login.php');
exit; exit();
} }
require_once 'includes/header.php'; $user_id = $_SESSION['user_id'];
$p = db()->prepare('SELECT s.name, s.description FROM services s JOIN user_services us ON s.id = us.service_id WHERE us.user_id = ?');
$p->execute([$user_id]);
$services = $p->fetchAll();
?> ?>
<div class="container mt-5"> <div class="container">
<?php <h1 class="mt-5">Dashboard</h1>
if (isset($_SESSION['message'])) { <p class="lead">Welcome to your dashboard. Here are the services you are subscribed to:</p>
echo "<div class='alert alert-success'>" . $_SESSION['message'] . "</div>";
unset($_SESSION['message']);
}
if (isset($_SESSION['error'])) {
echo "<div class='alert alert-danger'>" . $_SESSION['error'] . "</div>";
unset($_SESSION['error']);
}
?>
<div class="row">
<div class="col-md-12">
<h1>Welcome to your Dashboard, <?php echo htmlspecialchars($_SESSION['user_name']); ?>!</h1>
<p>This is your central hub to manage your account and services. More features will be added soon.</p>
</div>
</div>
<div class="row mt-5">
<div class="col-md-12">
<h2>Your Subscribed Services</h2>
<?php
require_once 'db/config.php';
$pdo = db();
$stmt = $pdo->prepare("SELECT s.name, s.description, us.id as user_service_id FROM services s JOIN user_services us ON s.id = us.service_id WHERE us.user_id = ? AND us.status = 'active'");
$stmt->execute([$_SESSION['user_id']]);
$user_services = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (count($user_services) > 0) {
echo "<ul class='list-group'>";
foreach ($user_services as $service) {
echo "<li class='list-group-item d-flex justify-content-between align-items-center'>";
echo "<div><strong>" . htmlspecialchars($service['name']) . "</strong>: " . htmlspecialchars($service['description']) . "</div>";
echo "<a href='cancel_subscription.php?user_service_id=" . $service['user_service_id'] . "' class='btn btn-danger btn-sm' onclick='return confirm("Are you sure you want to cancel this subscription?")'>Cancel</a>";
echo "</li>";
}
echo "</ul>";
} else {
echo "<p>You are not subscribed to any services yet.</p>";
}
?>
</div>
</div>
<div class="row mt-5">
<div class="col-md-12">
<h2>Available Services</h2>
</div>
</div>
<div class="row"> <div class="row">
<?php <?php if (empty($services)): ?>
require_once 'db/config.php'; <div class="col-12">
$pdo = db(); <p>You are not subscribed to any services yet.</p>
$stmt = $pdo->query("SELECT * FROM services"); </div>
$services = $stmt->fetchAll(PDO::FETCH_ASSOC); <?php else: ?>
<?php foreach ($services as $service): ?>
foreach ($services as $service) { <div class="col-md-4">
?> <div class="card mb-4">
<div class="col-md-4 mb-4">
<div class="card">
<div class="card-body"> <div class="card-body">
<h5 class="card-title"><?php echo htmlspecialchars($service['name']); ?></h5> <h5 class="card-title"><?php echo htmlspecialchars($service['name']); ?></h5>
<p class="card-text"><?php echo htmlspecialchars($service['description']); ?></p> <p class="card-text"><?php echo htmlspecialchars($service['description']); ?></p>
<p class="card-text"><strong>$<?php echo htmlspecialchars($service['price']); ?></strong> / <?php echo htmlspecialchars($service['billing_cycle']); ?></p> <a href="services/<?php echo strtolower(str_replace(' ', '', $service['name'])); ?>.php" class="btn btn-primary">Go to service</a>
<a href="subscribe.php?service_id=<?php echo $service['id']; ?>" class="btn btn-primary">Subscribe</a>
</div> </div>
</div> </div>
</div> </div>
<?php <?php endforeach; ?>
} <?php endif; ?>
?>
</div> </div>
</div> </div>

View File

@ -68,6 +68,9 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="dashboard.php">Dashboard</a> <a class="nav-link" href="dashboard.php">Dashboard</a>
</li> </li>
<li class="nav-item">
<a class="nav-link" href="subscribe.php">Subscribe</a>
</li>
<li class="nav-item dropdown"> <li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false"> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Hi, <?php echo htmlspecialchars($_SESSION['user_name']); ?> Hi, <?php echo htmlspecialchars($_SESSION['user_name']); ?>

View File

@ -0,0 +1,40 @@
<?php
require_once '../includes/header.php';
require_once '../db/config.php';
if (!isset($_SESSION['user_id'])) {
header('Location: ../login.php');
exit();
}
$user_id = $_SESSION['user_id'];
// Get the service ID for 'Email Newsletters'
$p = db()->prepare('SELECT id FROM services WHERE name = ?');
$p->execute(['Email Newsletters']);
$service = $p->fetch();
if (!$service) {
die('Email service not found.');
}
$service_id = $service['id'];
// Check if the user is subscribed to this service
$p = db()->prepare('SELECT * FROM user_services WHERE user_id = ? AND service_id = ?');
$p->execute([$user_id, $service_id]);
$subscription = $p->fetch();
if (!$subscription) {
die('You are not subscribed to this service. <a href="../subscribe.php">Subscribe now</a>');
}
?>
<div class="container">
<h1 class="mt-5">Email Newsletters</h1>
<p class="lead">This is where the email newsletter functionality would be.</p>
<p>You could have a list of past newsletters here, or a form to manage your subscription preferences.</p>
</div>
<?php require_once '../includes/footer.php'; ?>

View File

@ -0,0 +1,40 @@
<?php
require_once '../includes/header.php';
require_once '../db/config.php';
if (!isset($_SESSION['user_id'])) {
header('Location: ../login.php');
exit();
}
$user_id = $_SESSION['user_id'];
// Get the service ID for 'SMS Notifications'
$p = db()->prepare('SELECT id FROM services WHERE name = ?');
$p->execute(['SMS Notifications']);
$service = $p->fetch();
if (!$service) {
die('SMS service not found.');
}
$service_id = $service['id'];
// Check if the user is subscribed to this service
$p = db()->prepare('SELECT * FROM user_services WHERE user_id = ? AND service_id = ?');
$p->execute([$user_id, $service_id]);
$subscription = $p->fetch();
if (!$subscription) {
die('You are not subscribed to this service. <a href="../subscribe.php">Subscribe now</a>');
}
?>
<div class="container">
<h1 class="mt-5">SMS Notifications</h1>
<p class="lead">This is where the SMS notification functionality would be.</p>
<p>You could have a form here to send an SMS, or view a history of sent messages.</p>
</div>
<?php require_once '../includes/footer.php'; ?>

40
services/voicecalls.php Normal file
View File

@ -0,0 +1,40 @@
<?php
require_once '../includes/header.php';
require_once '../db/config.php';
if (!isset($_SESSION['user_id'])) {
header('Location: ../login.php');
exit();
}
$user_id = $_SESSION['user_id'];
// Get the service ID for 'Voice Calls'
$p = db()->prepare('SELECT id FROM services WHERE name = ?');
$p->execute(['Voice Calls']);
$service = $p->fetch();
if (!$service) {
die('Voice service not found.');
}
$service_id = $service['id'];
// Check if the user is subscribed to this service
$p = db()->prepare('SELECT * FROM user_services WHERE user_id = ? AND service_id = ?');
$p->execute([$user_id, $service_id]);
$subscription = $p->fetch();
if (!$subscription) {
die('You are not subscribed to this service. <a href="../subscribe.php">Subscribe now</a>');
}
?>
<div class="container">
<h1 class="mt-5">Voice Calls</h1>
<p class="lead">This is where the voice call functionality would be.</p>
<p>You could have a feature to initiate calls, or view your call history.</p>
</div>
<?php require_once '../includes/footer.php'; ?>

View File

@ -4,42 +4,61 @@ require_once 'db/config.php';
if (!isset($_SESSION['user_id'])) { if (!isset($_SESSION['user_id'])) {
header('Location: login.php'); header('Location: login.php');
exit; exit();
} }
if (isset($_GET['service_id'])) {
$service_id = $_GET['service_id'];
$user_id = $_SESSION['user_id']; $user_id = $_SESSION['user_id'];
try { if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['service_id'])) {
$pdo = db(); $service_id = $_POST['service_id'];
// Check if the user is already subscribed
$stmt = $pdo->prepare("SELECT * FROM user_services WHERE user_id = ? AND service_id = ? AND status = 'active'");
$stmt->execute([$user_id, $service_id]);
if ($stmt->rowCount() > 0) { $p = db()->prepare('SELECT * FROM user_services WHERE user_id = ? AND service_id = ?');
$message = "You are already subscribed to this service."; $p->execute([$user_id, $service_id]);
} else { $existing_subscription = $p->fetch();
// Add the subscription
$stmt = $pdo->prepare("INSERT INTO user_services (user_id, service_id) VALUES (?, ?)"); if (!$existing_subscription) {
$stmt->execute([$user_id, $service_id]); $p = db()->prepare('INSERT INTO user_services (user_id, service_id) VALUES (?, ?)');
$message = "You have successfully subscribed to the service!"; $p->execute([$user_id, $service_id]);
} }
} catch (PDOException $e) {
$message = "An error occurred: " . $e->getMessage(); header('Location: subscribe.php');
} exit();
} else {
header('Location: dashboard.php');
exit;
} }
$p = db()->prepare('SELECT * FROM services');
$p->execute();
$services = $p->fetchAll();
$p = db()->prepare('SELECT service_id FROM user_services WHERE user_id = ?');
$p->execute([$user_id]);
$subscribed_services = $p->fetchAll(PDO::FETCH_COLUMN);
?> ?>
<div class="container mt-5"> <div class="container">
<div class="alert alert-info"> <h1 class="mt-5">Subscribe to Services</h1>
<?php echo htmlspecialchars($message); ?> <p class="lead">Browse our available services and subscribe to the ones you need.</p>
<div class="row">
<?php foreach ($services as $service): ?>
<div class="col-md-4">
<div class="card mb-4">
<div class="card-body">
<h5 class="card-title"><?php echo htmlspecialchars($service['name']); ?></h5>
<p class="card-text"><?php echo htmlspecialchars($service['description']); ?></p>
<?php if (in_array($service['id'], $subscribed_services)): ?>
<button class="btn btn-secondary" disabled>Subscribed</button>
<?php else: ?>
<form action="subscribe.php" method="POST">
<input type="hidden" name="service_id" value="<?php echo $service['id']; ?>">
<button type="submit" class="btn btn-primary">Subscribe</button>
</form>
<?php endif; ?>
</div>
</div>
</div>
<?php endforeach; ?>
</div> </div>
<a href="dashboard.php" class="btn btn-primary">Back to Dashboard</a>
</div> </div>
<?php require_once 'includes/footer.php'; ?> <?php require_once 'includes/footer.php'; ?>