This commit is contained in:
Flatlogic Bot 2025-10-02 02:55:03 +00:00
parent 7e31c79046
commit 4ed2abbf31
10 changed files with 413 additions and 146 deletions

50
assets/css/custom.css Normal file
View File

@ -0,0 +1,50 @@
:root {
--primary-color: #4F46E5;
--secondary-color: #10B981;
--bg-color: #F3F4F6;
--surface-color: #FFFFFF;
--text-color: #111827;
--gradient: linear-gradient(to right, var(--primary-color), var(--secondary-color));
}
body {
font-family: 'Inter', sans-serif;
background-color: var(--bg-color);
color: var(--text-color);
}
h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
font-family: 'Georgia', serif;
}
.navbar {
background: var(--gradient);
}
.card {
border-radius: 0.5rem;
border: 1px solid #e5e7eb;
box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}
.btn-primary {
background-color: var(--primary-color);
border-color: var(--primary-color);
padding: 0.75rem 1.5rem;
border-radius: 0.5rem;
font-weight: bold;
}
.btn-primary:hover {
background-color: #4338ca;
border-color: #4338ca;
}
.form-control:focus {
border-color: var(--primary-color);
box-shadow: 0 0 0 0.25rem rgba(79, 70, 229, 0.25);
}
.form-floating > .form-control:focus ~ label {
color: var(--primary-color);
}

20
assets/js/main.js Normal file
View File

@ -0,0 +1,20 @@
// assets/js/main.js
(function () {
'use strict'
// Fetch all the forms we want to apply custom Bootstrap validation styles to
var forms = document.querySelectorAll('.needs-validation')
// Loop over them and prevent submission
Array.prototype.slice.call(forms)
.forEach(function (form) {
form.addEventListener('submit', function (event) {
if (!form.checkValidity()) {
event.preventDefault()
event.stopPropagation()
}
form.classList.add('was-validated')
}, false)
})
})()

35
includes/common.php Normal file
View File

@ -0,0 +1,35 @@
<?php
// includes/common.php
ini_set('session.cookie_httponly', 1);
ini_set('session.use_only_cookies', 1);
ini_set('session.cookie_secure', isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on');
session_start();
require_once __DIR__ . '/../db/config.php';
function is_logged_in() {
return isset($_SESSION['user_id']);
}
function require_login() {
if (!is_logged_in()) {
header('Location: login.php');
exit;
}
}
function require_guest() {
if (is_logged_in()) {
header('Location: index.php');
exit;
}
}
function get_user_id() {
return $_SESSION['user_id'] ?? null;
}
function get_user_name() {
return $_SESSION['username'] ?? null;
}
?>

12
includes/footer.php Normal file
View File

@ -0,0 +1,12 @@
</main>
<footer class="text-center mt-4 py-3 text-muted">
<p>&copy; <?= date('Y') ?> TimeSheet App. All rights reserved.</p>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://unpkg.com/feather-icons"></script>
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
<script>
feather.replace()
</script>
</body>
</html>

41
includes/header.php Normal file
View File

@ -0,0 +1,41 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?= htmlspecialchars($title ?? 'TimeSheet') ?></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&family=Georgia&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body class="bg-light">
<nav class="navbar navbar-expand-lg navbar-dark">
<div class="container">
<a class="navbar-brand" href="index.php">TimeSheet</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">
<?php if (is_logged_in()): ?>
<li class="nav-item">
<span class="navbar-text me-3">Welcome, <?= htmlspecialchars(get_user_name()) ?></span>
</li>
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout</a>
</li>
<?php else: ?>
<li class="nav-item">
<a class="nav-link" href="login.php">Login</a>
</li>
<li class="nav-item">
<a class="nav-link" href="register.php">Register</a>
</li>
<?php endif; ?>
</ul>
</div>
</div>
</nav>
<main class="container mt-4">

172
index.php
View File

@ -1,150 +1,30 @@
<?php <?php
declare(strict_types=1); require_once __DIR__ . '/includes/common.php';
@ini_set('display_errors', '1'); require_login();
@error_reporting(E_ALL);
@date_default_timezone_set('UTC');
$phpVersion = PHP_VERSION; $title = 'Dashboard';
$now = date('Y-m-d H:i:s');
require_once __DIR__ . '/includes/header.php';
?> ?>
<!doctype html>
<html lang="en"> <div class="px-4 py-5 my-5 text-center">
<head> <h1 class="display-5 fw-bold">Welcome to Your TimeSheet</h1>
<meta charset="utf-8" /> <div class="col-lg-6 mx-auto">
<meta name="viewport" content="width=device-width, initial-scale=1" /> <p class="lead mb-4">This is your dashboard. The timesheet entry table will be displayed here soon.</p>
<title>New Style</title> <p class="lead mb-4">You are logged in as <strong><?= htmlspecialchars(get_user_name()) ?></strong>.</p>
<?php <div class="d-grid gap-2 d-sm-flex justify-content-sm-center">
// Read project preview data from environment <a href="#" class="btn btn-primary btn-lg px-4 gap-3">Enter Hours</a>
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? ''; <a href="#" class="btn btn-outline-secondary btn-lg px-4">View Reports</a>
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? ''; </div>
?>
<?php if ($projectDescription): ?>
<!-- Meta description -->
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
<!-- Open Graph meta tags -->
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
<!-- Twitter meta tags -->
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
<?php endif; ?>
<?php if ($projectImageUrl): ?>
<!-- Open Graph image -->
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
<!-- Twitter image -->
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
<?php endif; ?>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-color-start: #6a11cb;
--bg-color-end: #2575fc;
--text-color: #ffffff;
--card-bg-color: rgba(255, 255, 255, 0.01);
--card-border-color: rgba(255, 255, 255, 0.1);
}
body {
margin: 0;
font-family: 'Inter', sans-serif;
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
color: var(--text-color);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
text-align: center;
overflow: hidden;
position: relative;
}
body::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
animation: bg-pan 20s linear infinite;
z-index: -1;
}
@keyframes bg-pan {
0% { background-position: 0% 0%; }
100% { background-position: 100% 100%; }
}
main {
padding: 2rem;
}
.card {
background: var(--card-bg-color);
border: 1px solid var(--card-border-color);
border-radius: 16px;
padding: 2rem;
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
}
.loader {
margin: 1.25rem auto 1.25rem;
width: 48px;
height: 48px;
border: 3px solid rgba(255, 255, 255, 0.25);
border-top-color: #fff;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.hint {
opacity: 0.9;
}
.sr-only {
position: absolute;
width: 1px; height: 1px;
padding: 0; margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap; border: 0;
}
h1 {
font-size: 3rem;
font-weight: 700;
margin: 0 0 1rem;
letter-spacing: -1px;
}
p {
margin: 0.5rem 0;
font-size: 1.1rem;
}
code {
background: rgba(0,0,0,0.2);
padding: 2px 6px;
border-radius: 4px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
footer {
position: absolute;
bottom: 1rem;
font-size: 0.8rem;
opacity: 0.7;
}
</style>
</head>
<body>
<main>
<div class="card">
<h1>Analyzing your requirements and generating your website…</h1>
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
<span class="sr-only">Loading…</span>
</div>
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
<p class="hint">This page will update automatically as the plan is implemented.</p>
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
</div> </div>
</main> </div>
<footer>
Page updated: <?= htmlspecialchars($now) ?> (UTC) <div class="alert alert-info">
</footer> <h4 class="alert-heading">Under Construction!</h4>
</body> <p>The main functionality for logging hours and viewing reports is currently being built. Check back soon!</p>
</html> </div>
<?php
require_once __DIR__ . '/includes/footer.php';
?>

76
login.php Normal file
View File

@ -0,0 +1,76 @@
<?php
require_once __DIR__ . '/includes/common.php';
require_guest();
$title = 'Login';
$errors = [];
$username = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = trim($_POST['username'] ?? '');
$password = $_POST['password'] ?? '';
if (empty($username) || empty($password)) {
$errors[] = 'Username and password are required.';
} else {
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT id, username, password_hash FROM users WHERE username = ?");
$stmt->execute([$username]);
$user = $stmt->fetch();
if ($user && password_verify($password, $user['password_hash'])) {
$_SESSION['user_id'] = $user['id'];
$_SESSION['username'] = $user['username'];
header('Location: index.php');
exit;
} else {
$errors[] = 'Invalid username or password.';
}
} catch (PDOException $e) {
$errors[] = 'Database error. Please try again later.';
}
}
}
require_once __DIR__ . '/includes/header.php';
?>
<div class="row justify-content-center">
<div class="col-lg-5 col-md-7">
<div class="card">
<div class="card-body p-5">
<h1 class="card-title text-center mb-4">Login</h1>
<?php if (!empty($errors)): ?>
<div class="alert alert-danger">
<p class="mb-0"><?= htmlspecialchars($errors[0]) ?></p>
</div>
<?php endif; ?>
<form action="login.php" method="POST" class="needs-validation" novalidate>
<div class="form-floating mb-3">
<input type="text" class="form-control" id="username" name="username" placeholder="Username" value="<?= htmlspecialchars($username) ?>" required>
<label for="username">Username</label>
<div class="invalid-feedback">Please enter your username.</div>
</div>
<div class="form-floating mb-3">
<input type="password" class="form-control" id="password" name="password" placeholder="Password" required>
<label for="password">Password</label>
<div class="invalid-feedback">Please enter your password.</div>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary btn-lg">Login</button>
</div>
</form>
<p class="text-center mt-4">
Don't have an account? <a href="register.php">Register here</a>.
</p>
</div>
</div>
</div>
</div>
<?php
require_once __DIR__ . '/includes/footer.php';
?>

18
logout.php Normal file
View File

@ -0,0 +1,18 @@
<?php
require_once __DIR__ . '/includes/common.php';
$_SESSION = [];
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
session_destroy();
header('Location: login.php');
exit;
?>

102
register.php Normal file
View File

@ -0,0 +1,102 @@
<?php
require_once __DIR__ . '/includes/common.php';
require_guest();
$title = 'Register';
$errors = [];
$username = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = trim($_POST['username'] ?? '');
$password = $_POST['password'] ?? '';
$password_confirm = $_POST['password_confirm'] ?? '';
if (empty($username)) {
$errors[] = 'Username is required.';
} elseif (strlen($username) < 3) {
$errors[] = 'Username must be at least 3 characters long.';
}
if (empty($password)) {
$errors[] = 'Password is required.';
} elseif (strlen($password) < 6) {
$errors[] = 'Password must be at least 6 characters long.';
}
if ($password !== $password_confirm) {
$errors[] = 'Passwords do not match.';
}
if (empty($errors)) {
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT id FROM users WHERE username = ?");
$stmt->execute([$username]);
if ($stmt->fetch()) {
$errors[] = 'Username is already taken.';
} else {
$password_hash = password_hash($password, PASSWORD_DEFAULT);
$stmt = $pdo->prepare("INSERT INTO users (username, password_hash) VALUES (?, ?)");
$stmt->execute([$username, $password_hash]);
// Log the user in
$_SESSION['user_id'] = $pdo->lastInsertId();
$_SESSION['username'] = $username;
header('Location: index.php');
exit;
}
} catch (PDOException $e) {
$errors[] = 'Database error. Please try again later.';
}
}
}
require_once __DIR__ . '/includes/header.php';
?>
<div class="row justify-content-center">
<div class="col-lg-6 col-md-8">
<div class="card">
<div class="card-body p-5">
<h1 class="card-title text-center mb-4">Create an Account</h1>
<?php if (!empty($errors)): ?>
<div class="alert alert-danger">
<?php foreach ($errors as $error): ?>
<p class="mb-0"><?= htmlspecialchars($error) ?></p>
<?php endforeach; ?>
</div>
<?php endif; ?>
<form action="register.php" method="POST" class="needs-validation" novalidate>
<div class="form-floating mb-3">
<input type="text" class="form-control" id="username" name="username" placeholder="Username" value="<?= htmlspecialchars($username) ?>" required>
<label for="username">Username</label>
<div class="invalid-feedback">Please enter a username.</div>
</div>
<div class="form-floating mb-3">
<input type="password" class="form-control" id="password" name="password" placeholder="Password" required>
<label for="password">Password</label>
<div class="invalid-feedback">Please enter a password.</div>
</div>
<div class="form-floating mb-3">
<input type="password" class="form-control" id="password_confirm" name="password_confirm" placeholder="Confirm Password" required>
<label for="password_confirm">Confirm Password</label>
<div class="invalid-feedback">Please confirm your password.</div>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary btn-lg">Register</button>
</div>
</form>
<p class="text-center mt-4">
Already have an account? <a href="login.php">Login here</a>.
</p>
</div>
</div>
</div>
</div>
<?php
require_once __DIR__ . '/includes/footer.php';
?>

33
setup.php Normal file
View File

@ -0,0 +1,33 @@
<?php
require_once __DIR__ . '/db/config.php';
try {
$pdo = db();
$pdo->exec("
CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL UNIQUE,
password_hash VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
");
$pdo->exec("
CREATE TABLE IF NOT EXISTS timesheets (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
work_date DATE NOT NULL,
hours DECIMAL(4, 2) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
UNIQUE KEY user_date (user_id, work_date)
);
");
echo "Database setup completed successfully.";
} catch (PDOException $e) {
die("Database setup failed: " . $e->getMessage());
}
?>