Mortgage App

This commit is contained in:
Flatlogic Bot 2025-12-14 19:49:54 +00:00
parent cddd17cc44
commit 1e905f9245
11 changed files with 473 additions and 3 deletions

69
admin/create.php Normal file
View File

@ -0,0 +1,69 @@
<?php
session_start();
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
header('Location: index.php');
exit;
}
require_once __DIR__ . '/../db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = $_POST['title'] ?? '';
$content = $_POST['content'] ?? '';
if (empty($title) || empty($content)) {
$error = 'Title and content are required';
} else {
$pdo = db();
$stmt = $pdo->prepare('INSERT INTO posts (title, content) VALUES (?, ?)');
$stmt->execute([$title, $content]);
header('Location: dashboard.php');
exit;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add New Post</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="dashboard.php">Admin</a>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container py-5">
<h1>Add New Post</h1>
<?php if (isset($error)): ?>
<div class="alert alert-danger"><?php echo $error; ?></div>
<?php endif; ?>
<form method="post">
<div class="mb-3">
<label for="title" class="form-label">Title</label>
<input type="text" class="form-control" id="title" name="title" required>
</div>
<div class="mb-3">
<label for="content" class="form-label">Content</label>
<textarea class="form-control" id="content" name="content" rows="10" required></textarea>
</div>
<button type="submit" class="btn btn-primary">Save Post</button>
<a href="dashboard.php" class="btn btn-secondary">Cancel</a>
</form>
</div>
</body>
</html>

73
admin/dashboard.php Normal file
View File

@ -0,0 +1,73 @@
<?php
session_start();
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
header('Location: index.php');
exit;
}
require_once __DIR__ . '/../db/config.php';
$pdo = db();
$stmt = $pdo->query('SELECT * FROM posts ORDER BY created_at DESC');
$posts = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="#">Admin</a>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container py-5">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1>Blog Posts</h1>
<a href="create.php" class="btn btn-primary">Add New Post</a>
</div>
<table class="table table-bordered">
<thead>
<tr>
<th>Title</th>
<th>Created At</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($posts)): ?>
<tr>
<td colspan="3" class="text-center">No posts found.</td>
</tr>
<?php else: ?>
<?php foreach ($posts as $post): ?>
<tr>
<td><?php echo htmlspecialchars($post['title']); ?></td>
<td><?php echo date('F j, Y', strtotime($post['created_at'])); ?></td>
<td>
<a href="edit.php?id=<?php echo $post['id']; ?>" class="btn btn-sm btn-outline-primary">Edit</a>
<a href="delete.php?id=<?php echo $post['id']; ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('Are you sure you want to delete this post?')">Delete</a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</body>
</html>

21
admin/delete.php Normal file
View File

@ -0,0 +1,21 @@
<?php
session_start();
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
header('Location: index.php');
exit;
}
require_once __DIR__ . '/../db/config.php';
if (!isset($_GET['id'])) {
header('Location: dashboard.php');
exit;
}
$pdo = db();
$stmt = $pdo->prepare('DELETE FROM posts WHERE id = ?');
$stmt->execute([$_GET['id']]);
header('Location: dashboard.php');
exit;

85
admin/edit.php Normal file
View File

@ -0,0 +1,85 @@
<?php
session_start();
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
header('Location: index.php');
exit;
}
require_once __DIR__ . '/../db/config.php';
if (!isset($_GET['id'])) {
header('Location: dashboard.php');
exit;
}
$pdo = db();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = $_POST['title'] ?? '';
$content = $_POST['content'] ?? '';
$id = $_GET['id'];
if (empty($title) || empty($content)) {
$error = 'Title and content are required';
} else {
$stmt = $pdo->prepare('UPDATE posts SET title = ?, content = ? WHERE id = ?');
$stmt->execute([$title, $content, $id]);
header('Location: dashboard.php');
exit;
}
} else {
$stmt = $pdo->prepare('SELECT * FROM posts WHERE id = ?');
$stmt->execute([$_GET['id']]);
$post = $stmt->fetch();
if (!$post) {
header('Location: dashboard.php');
exit;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edit Post</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="dashboard.php">Admin</a>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container py-5">
<h1>Edit Post</h1>
<?php if (isset($error)): ?>
<div class="alert alert-danger"><?php echo $error; ?></div>
<?php endif; ?>
<form method="post">
<div class="mb-3">
<label for="title" class="form-label">Title</label>
<input type="text" class="form-control" id="title" name="title" value="<?php echo htmlspecialchars($post['title']); ?>" required>
</div>
<div class="mb-3">
<label for="content" class="form-label">Content</label>
<textarea class="form-control" id="content" name="content" rows="10" required><?php echo htmlspecialchars($post['content']); ?></textarea>
</div>
<button type="submit" class="btn btn-primary">Save Changes</button>
<a href="dashboard.php" class="btn btn-secondary">Cancel</a>
</form>
</div>
</body>
</html>

57
admin/index.php Normal file
View File

@ -0,0 +1,57 @@
<?php
session_start();
// If already logged in, redirect to dashboard
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
header('Location: dashboard.php');
exit;
}
// Hardcoded password for now
$password = 'password';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['password']) && $_POST['password'] === $password) {
$_SESSION['loggedin'] = true;
header('Location: dashboard.php');
exit;
} else {
$error = 'Invalid password';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Login</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-6 mt-5">
<div class="card">
<div class="card-header">
Admin Login
</div>
<div class="card-body">
<?php if (isset($error)): ?>
<div class="alert alert-danger"><?php echo $error; ?></div>
<?php endif; ?>
<form method="post">
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<button type="submit" class="btn btn-primary">Login</button>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

5
admin/logout.php Normal file
View File

@ -0,0 +1,5 @@
<?php
session_start();
session_destroy();
header('Location: index.php');
exit;

73
blog.php Normal file
View File

@ -0,0 +1,73 @@
<?php
require_once 'db/config.php';
$pdo = db();
$stmt = $pdo->query('SELECT * FROM posts ORDER BY created_at DESC');
$posts = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Blog - Ontario Custom Mortgages</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="/">Ontario Custom Mortgages</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item"><a class="nav-link" href="/#portfolio">Portfolio</a></li>
<li class="nav-item"><a class="nav-link" href="/#about">About</a></li>
<li class="nav-item"><a class="nav-link" href="/blog.php">Blog</a></li>
<li class="nav-item"><a class="nav-link" href="/#contact">Contact</a></li>
</ul>
</div>
</div>
</nav>
<header class="py-5">
<div class="container text-center">
<h1 class="display-4">Blog</h1>
<p class="lead">News and updates from Ontario Custom Mortgages.</p>
</div>
</header>
<main class="container py-5">
<div class="row">
<?php if (empty($posts)): ?>
<div class="col-12 text-center">
<p>No blog posts yet. Check back soon!</p>
</div>
<?php else: ?>
<?php foreach ($posts as $post): ?>
<div class="col-md-8 offset-md-2 mb-4">
<div class="card">
<div class="card-body">
<h2 class="card-title"><?php echo htmlspecialchars($post['title']); ?></h2>
<p class="card-text"><small class="text-muted">Posted on <?php echo date('F j, Y', strtotime($post['created_at'])); ?></small></p>
<p class="card-text"><?php echo nl2br(htmlspecialchars(substr($post['content'], 0, 200))); ?>...</p>
<a href="post.php?id=<?php echo $post['id']; ?>" class="btn btn-primary">Read More</a>
</div>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</main>
<footer class="bg-light text-center py-4">
<p>&copy; <?php echo date("Y"); ?> Ontario Custom Mortgages. All Rights Reserved.</p>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

13
db/migrate.php Normal file
View File

@ -0,0 +1,13 @@
<?php
require_once __DIR__ . '/config.php';
$pdo = db();
$migrations = glob(__DIR__ . '/migrations/*.sql');
foreach ($migrations as $migration) {
$sql = file_get_contents($migration);
$pdo->exec($sql);
echo "Applied migration: " . basename($migration) . "\n";
}

View File

@ -0,0 +1,6 @@
CREATE TABLE IF NOT EXISTS posts (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

View File

@ -15,7 +15,7 @@
<nav class="navbar navbar-expand-lg navbar-light bg-light sticky-top">
<div class="container">
<a class="navbar-brand" href="#">My Portfolio</a>
<a class="navbar-brand" href="/">Ontario Custom Mortgages</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
@ -24,7 +24,7 @@
<li class="nav-item"><a class="nav-link" href="#intro">Intro</a></li>
<li class="nav-item"><a class="nav-link" href="#portfolio">Portfolio</a></li>
<li class="nav-item"><a class="nav-link" href="#about">About</a></li>
<li class="nav-item"><a class="nav-link" href="#blog">Blog</a></li>
<li class="nav-item"><a class="nav-link" href="/blog.php">Blog</a></li>
<li class="nav-item"><a class="nav-link" href="#contact">Contact</a></li>
</ul>
</div>
@ -130,7 +130,7 @@
</section>
<footer class="text-center py-4">
<p>&copy; <?php echo date("Y"); ?> Your Name. All Rights Reserved.</p>
<p>&copy; <?php echo date("Y"); ?> Ontario Custom Mortgages. All Rights Reserved.</p>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>

68
post.php Normal file
View File

@ -0,0 +1,68 @@
<?php
require_once 'db/config.php';
if (!isset($_GET['id'])) {
header('Location: blog.php');
exit;
}
$pdo = db();
$stmt = $pdo->prepare('SELECT * FROM posts WHERE id = ?');
$stmt->execute([$_GET['id']]);
$post = $stmt->fetch();
if (!$post) {
header('Location: blog.php');
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo htmlspecialchars($post['title']); ?> - Ontario Custom Mortgages</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="/">Ontario Custom Mortgages</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item"><a class="nav-link" href="/#portfolio">Portfolio</a></li>
<li class="nav-item"><a class="nav-link" href="/#about">About</a></li>
<li class="nav-item"><a class="nav-link" href="/blog.php">Blog</a></li>
<li class="nav-item"><a class="nav-link" href="/#contact">Contact</a></li>
</ul>
</div>
</div>
</nav>
<main class="container py-5">
<div class="row">
<div class="col-md-8 offset-md-2">
<h1 class="mb-4"><?php echo htmlspecialchars($post['title']); ?></h1>
<p class="text-muted">Posted on <?php echo date('F j, Y', strtotime($post['created_at'])); ?></p>
<hr>
<div class="post-content">
<?php echo nl2br(htmlspecialchars($post['content'])); ?>
</div>
<hr>
<a href="blog.php" class="btn btn-secondary">Back to Blog</a>
</div>
</div>
</main>
<footer class="bg-light text-center py-4 mt-5">
<p>&copy; <?php echo date("Y"); ?> Ontario Custom Mortgages. All Rights Reserved.</p>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>