Auto commit: 2025-11-02T20:12:50.034Z

This commit is contained in:
Flatlogic Bot 2025-11-02 20:12:50 +00:00
parent 1d5ec407b8
commit 08b1b2f044
20 changed files with 1051 additions and 33 deletions

27
add_client.php Normal file
View File

@ -0,0 +1,27 @@
<?php
require_once 'db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = $_POST['name'] ?? null;
$website = $_POST['website'] ?? null;
$status = $_POST['status'] ?? 'Active';
if ($name) {
try {
$pdo = db();
$sql = "INSERT INTO clients (name, website, status) VALUES (?, ?, ?)";
$stmt = $pdo->prepare($sql);
$stmt->execute([$name, $website, $status]);
header("Location: clients.php?success=1");
exit();
} catch (PDOException $e) {
header("Location: clients.php?error=" . urlencode($e->getMessage()));
exit();
}
} else {
header("Location: clients.php?error=invalid_input");
exit();
}
}
?>

29
add_contact.php Normal file
View File

@ -0,0 +1,29 @@
<?php
require_once 'db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$client_id = $_POST['client_id'] ?? null;
$name = $_POST['name'] ?? null;
$email = $_POST['email'] ?? null;
$phone = $_POST['phone'] ?? null;
$role = $_POST['role'] ?? null;
if ($client_id && $name && $email) {
try {
$pdo = db();
$sql = "INSERT INTO contacts (client_id, name, email, phone, role) VALUES (?, ?, ?, ?, ?)";
$stmt = $pdo->prepare($sql);
$stmt->execute([$client_id, $name, $email, $phone, $role]);
header("Location: contacts.php?success=1");
exit();
} catch (PDOException $e) {
header("Location: contacts.php?error=" . urlencode($e->getMessage()));
exit();
}
} else {
header("Location: contacts.php?error=invalid_input");
exit();
}
}
?>

31
add_expense.php Normal file
View File

@ -0,0 +1,31 @@
<?php
require_once 'db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$expense_date = $_POST['expense_date'] ?? null;
$description = $_POST['description'] ?? null;
$amount = $_POST['amount'] ?? null;
$category = $_POST['category'] ?? null;
if ($expense_date && $description && $amount) {
try {
$pdo = db();
$sql = "INSERT INTO expenses (expense_date, description, amount, category) VALUES (?, ?, ?, ?)";
$stmt = $pdo->prepare($sql);
$stmt->execute([$expense_date, $description, $amount, $category]);
// Redirect back to the expenses page with a success message
header("Location: expenses.php?success=1");
exit();
} catch (PDOException $e) {
// Handle error, maybe redirect with an error message
header("Location: expenses.php?error=" . urlencode($e->getMessage()));
exit();
}
} else {
// Handle invalid input
header("Location: expenses.php?error=invalid_input");
exit();
}
}
?>

27
add_item.php Normal file
View File

@ -0,0 +1,27 @@
<?php
require_once 'db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = $_POST['name'] ?? null;
$description = $_POST['description'] ?? null;
$price = $_POST['price'] ?? null;
if ($name && $price) {
try {
$pdo = db();
$sql = "INSERT INTO items (name, description, price) VALUES (?, ?, ?)";
$stmt = $pdo->prepare($sql);
$stmt->execute([$name, $description, $price]);
header("Location: items.php?success=1");
exit();
} catch (PDOException $e) {
header("Location: items.php?error=" . urlencode($e->getMessage()));
exit();
}
} else {
header("Location: items.php?error=invalid_input");
exit();
}
}
?>

View File

@ -27,11 +27,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$message = 'A member with this email address already exists.';
} else {
// Insert new member
$sql = "INSERT INTO team_members (name, email, role) VALUES (:name, :email, :role)";
$password = password_hash('password', PASSWORD_DEFAULT);
$sql = "INSERT INTO team_members (name, email, role, password) VALUES (:name, :email, :role, :password)";
$stmt = $db->prepare($sql);
$stmt->bindParam(':name', $name);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':role', $role);
$stmt->bindParam(':password', $password);
if ($stmt->execute()) {
$status = 'success';

36
add_project.php Normal file
View File

@ -0,0 +1,36 @@
<?php
require_once 'db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = $_POST['name'] ?? null;
$description = $_POST['description'] ?? null;
$client_id = $_POST['client_id'] ?? null;
$status = $_POST['status'] ?? 'Not Started';
$start_date = $_POST['start_date'] ?? null;
$end_date = $_POST['end_date'] ?? null;
if ($name) {
try {
$pdo = db();
$sql = "INSERT INTO projects (name, description, client_id, status, start_date, end_date) VALUES (?, ?, ?, ?, ?, ?)";
$stmt = $pdo->prepare($sql);
// Handle empty dates
$client_id = empty($client_id) ? null : $client_id;
$start_date = empty($start_date) ? null : $start_date;
$end_date = empty($end_date) ? null : $end_date;
$stmt->execute([$name, $description, $client_id, $status, $start_date, $end_date]);
header("Location: projects.php?success=1");
exit();
} catch (PDOException $e) {
header("Location: projects.php?error=" . urlencode($e->getMessage()));
exit();
}
} else {
header("Location: projects.php?error=invalid_input");
exit();
}
}
?>

28
add_ticket.php Normal file
View File

@ -0,0 +1,28 @@
<?php
require_once 'db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = $_POST['title'] ?? null;
$description = $_POST['description'] ?? null;
$status = $_POST['status'] ?? 'Open';
$priority = $_POST['priority'] ?? 'Medium';
if ($title) {
try {
$pdo = db();
$sql = "INSERT INTO tickets (title, description, status, priority) VALUES (?, ?, ?, ?)";
$stmt = $pdo->prepare($sql);
$stmt->execute([$title, $description, $status, $priority]);
header("Location: tickets.php?success=1");
exit();
} catch (PDOException $e) {
header("Location: tickets.php?error=" . urlencode($e->getMessage()));
exit();
}
} else {
header("Location: tickets.php?error=invalid_input");
exit();
}
}
?>

94
clients.php Normal file
View File

@ -0,0 +1,94 @@
<?php
require_once 'db/config.php';
require_once 'includes/header.php';
try {
$pdo = db();
$stmt = $pdo->query("SELECT id, name, website, status, created_at FROM clients ORDER BY name ASC");
$clients = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo '<div class="alert alert-danger">Error fetching clients: ' . $e->getMessage() . '</div>';
$clients = [];
}
?>
<div class="container mt-4">
<div class="d-flex justify-content-between align-items-center mb-3">
<h1 class="h2">Clients</h1>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addClientModal">
Add Client
</button>
</div>
<div class="card">
<div class="card-body">
<table class="table table-hover">
<thead class="table-light">
<tr>
<th>Name</th>
<th>Website</th>
<th>Status</th>
<th>Created At</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($clients)): ?>
<tr>
<td colspan="5" class="text-center">No clients found.</td>
</tr>
<?php else: ?>
<?php foreach ($clients as $client): ?>
<tr>
<td><?php echo htmlspecialchars($client['name']); ?></td>
<td><a href="<?php echo htmlspecialchars($client['website']); ?>" target="_blank"><?php echo htmlspecialchars($client['website']); ?></a></td>
<td><span class="badge bg-<?php echo strtolower($client['status']) == 'active' ? 'success' : 'secondary'; ?>"><?php echo htmlspecialchars($client['status']); ?></span></td>
<td><?php echo htmlspecialchars($client['created_at']); ?></td>
<td>
<!-- Actions like edit/delete can be added here -->
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Add Client Modal -->
<div class="modal fade" id="addClientModal" tabindex="-1" aria-labelledby="addClientModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addClientModalLabel">Add New Client</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="add_client.php" method="POST">
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="mb-3">
<label for="website" class="form-label">Website</label>
<input type="url" class="form-control" id="website" name="website">
</div>
<div class="mb-3">
<label for="status" class="form-label">Status</label>
<select class="form-select" id="status" name="status">
<option value="Active" selected>Active</option>
<option value="Inactive">Inactive</option>
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save Client</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php require_once 'includes/footer.php'; ?>

110
contacts.php Normal file
View File

@ -0,0 +1,110 @@
<?php
require_once 'db/config.php';
require_once 'includes/header.php';
try {
$pdo = db();
$stmt_contacts = $pdo->query("SELECT contacts.*, clients.name as client_name FROM contacts JOIN clients ON contacts.client_id = clients.id ORDER BY contacts.name ASC");
$contacts = $stmt_contacts->fetchAll(PDO::FETCH_ASSOC);
$stmt_clients = $pdo->query("SELECT id, name FROM clients ORDER BY name ASC");
$clients = $stmt_clients->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo '<div class="alert alert-danger">Error fetching data: ' . $e->getMessage() . '</div>';
$contacts = [];
$clients = [];
}
?>
<div class="container mt-4">
<div class="d-flex justify-content-between align-items-center mb-3">
<h1 class="h2">Contacts</h1>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addContactModal">
Add Contact
</button>
</div>
<div class="card">
<div class="card-body">
<table class="table table-hover">
<thead class="table-light">
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Client</th>
<th>Role</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($contacts)): ?>
<tr>
<td colspan="6" class="text-center">No contacts found.</td>
</tr>
<?php else: ?>
<?php foreach ($contacts as $contact): ?>
<tr>
<td><?php echo htmlspecialchars($contact['name']); ?></td>
<td><?php echo htmlspecialchars($contact['email']); ?></td>
<td><?php echo htmlspecialchars($contact['phone']); ?></td>
<td><?php echo htmlspecialchars($contact['client_name']); ?></td>
<td><?php echo htmlspecialchars($contact['role']); ?></td>
<td>
<!-- Actions like edit/delete can be added here -->
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Add Contact Modal -->
<div class="modal fade" id="addContactModal" tabindex="-1" aria-labelledby="addContactModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addContactModalLabel">Add New Contact</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="add_contact.php" method="POST">
<div class="mb-3">
<label for="client_id" class="form-label">Client</label>
<select class="form-select" id="client_id" name="client_id" required>
<option value="">Select a client</option>
<?php foreach ($clients as $client): ?>
<option value="<?php echo $client['id']; ?>"><?php echo htmlspecialchars($client['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<label for="phone" class="form-label">Phone</label>
<input type="tel" class="form-control" id="phone" name="phone">
</div>
<div class="mb-3">
<label for="role" class="form-label">Role</label>
<input type="text" class="form-control" id="role" name="role">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save Contact</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php require_once 'includes/footer.php'; ?>

View File

@ -1,33 +1,120 @@
<?php
// db/setup.php
require_once 'config.php';
try {
$db = db();
$sql = "
CREATE TABLE IF NOT EXISTS `team_members` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(255) NOT NULL,
`email` VARCHAR(255) NOT NULL UNIQUE,
`role` VARCHAR(100) NOT NULL,
`status` VARCHAR(50) DEFAULT 'active',
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);";
$db->exec($sql);
echo "Table 'team_members' created successfully (if it didn't exist).<br>";
// 1. Connect to MySQL without specifying a database
$dsn_nodb = "mysql:host=" . DB_HOST;
$pdo_nodb = new PDO($dsn_nodb, DB_USER, DB_PASS);
$pdo_nodb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Optional: Seed with some data
$stmt = $db->query("SELECT COUNT(*) FROM team_members");
if ($stmt->fetchColumn() == 0) {
$seed_sql = "
INSERT INTO `team_members` (name, email, role, status) VALUES
('John Doe', 'john.doe@example.com', 'Admin', 'active'),
('Jane Smith', 'jane.smith@example.com', 'Project Manager', 'active'),
('Peter Jones', 'peter.jones@example.com', 'Team Member', 'inactive');
";
$db->exec($seed_sql);
echo "Seeded 'team_members' table with initial data.<br>";
// 2. Create the database if it doesn't exist
$pdo_nodb->exec("CREATE DATABASE IF NOT EXISTS `" . DB_NAME . "`");
// 3. Now connect to the newly created database
$dsn_db = "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME;
$pdo = new PDO($dsn_db, DB_USER, DB_PASS);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// 4. Create the table
$sql = "CREATE TABLE IF NOT EXISTS team_members (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
role VARCHAR(100),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)";
$pdo->exec($sql);
$sql_expenses = "CREATE TABLE IF NOT EXISTS expenses (
id INT AUTO_INCREMENT PRIMARY KEY,
expense_date DATE NOT NULL,
description VARCHAR(255) NOT NULL,
amount DECIMAL(10, 2) NOT NULL,
category VARCHAR(100),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)";
$pdo->exec($sql_expenses);
$sql_items = "CREATE TABLE IF NOT EXISTS items (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
description TEXT,
price DECIMAL(10, 2) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)";
$pdo->exec($sql_items);
$sql_tickets = "CREATE TABLE IF NOT EXISTS tickets (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
description TEXT,
status ENUM('Open', 'In Progress', 'Closed') NOT NULL DEFAULT 'Open',
priority ENUM('Low', 'Medium', 'High') NOT NULL DEFAULT 'Medium',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)";
$pdo->exec($sql_tickets);
$sql_clients = "CREATE TABLE IF NOT EXISTS clients (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
website VARCHAR(255),
status ENUM('Active', 'Inactive') NOT NULL DEFAULT 'Active',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)";
$pdo->exec($sql_clients);
$sql_contacts = "CREATE TABLE IF NOT EXISTS contacts (
id INT AUTO_INCREMENT PRIMARY KEY,
client_id INT NOT NULL,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
phone VARCHAR(50),
role VARCHAR(100),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (client_id) REFERENCES clients(id) ON DELETE CASCADE
)";
$pdo->exec($sql_contacts);
$sql_projects = "CREATE TABLE IF NOT EXISTS projects (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
description TEXT,
client_id INT,
status ENUM('Not Started', 'In Progress', 'Completed') NOT NULL DEFAULT 'Not Started',
start_date DATE,
end_date DATE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (client_id) REFERENCES clients(id) ON DELETE SET NULL
)";
$pdo->exec($sql_projects);
// Check if there are any users in the team_members table
$stmt = $pdo->query("SELECT COUNT(*) FROM team_members");
$user_count = $stmt->fetchColumn();
if ($user_count == 0) {
// Insert a default admin user if no users exist
$admin_email = 'admin@example.com';
$admin_password = 'password123';
$hashed_password = password_hash($admin_password, PASSWORD_DEFAULT);
$insert_stmt = $pdo->prepare("INSERT INTO team_members (name, email, password, role) VALUES (?, ?, ?, ?)");
$insert_stmt->execute(['Admin', $admin_email, $hashed_password, 'Admin']);
echo "Default admin user created.\n";
}
echo "Database and table setup completed successfully.";
} catch (PDOException $e) {
die("DB setup failed: " . $e->getMessage());
}
?>

1
db/setup_done.flag Normal file
View File

@ -0,0 +1 @@
done

96
expenses.php Normal file
View File

@ -0,0 +1,96 @@
<?php
require_once 'db/config.php';
require_once 'includes/header.php';
try {
$pdo = db();
$stmt = $pdo->query("SELECT id, expense_date, description, amount, category FROM expenses ORDER BY expense_date DESC");
$expenses = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
// Handle error, for now just display a message
echo '<div class="alert alert-danger">Error fetching expenses: ' . $e->getMessage() . '</div>';
$expenses = [];
}
?>
<div class="container mt-4">
<div class="d-flex justify-content-between align-items-center mb-3">
<h1 class="h2">Expenses</h1>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addExpenseModal">
Add Expense
</button>
</div>
<div class="card">
<div class="card-body">
<table class="table table-hover">
<thead class="table-light">
<tr>
<th>Date</th>
<th>Description</th>
<th>Amount</th>
<th>Category</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($expenses)): ?>
<tr>
<td colspan="5" class="text-center">No expenses found.</td>
</tr>
<?php else: ?>
<?php foreach ($expenses as $expense): ?>
<tr>
<td><?php echo htmlspecialchars($expense['expense_date']); ?></td>
<td><?php echo htmlspecialchars($expense['description']); ?></td>
<td><?php echo htmlspecialchars(number_format($expense['amount'], 2)); ?></td>
<td><?php echo htmlspecialchars($expense['category']); ?></td>
<td>
<!-- Actions like edit/delete can be added here -->
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Add Expense Modal -->
<div class="modal fade" id="addExpenseModal" tabindex="-1" aria-labelledby="addExpenseModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addExpenseModalLabel">Add New Expense</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="add_expense.php" method="POST">
<div class="mb-3">
<label for="expense_date" class="form-label">Date</label>
<input type="date" class="form-control" id="expense_date" name="expense_date" required>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<input type="text" class="form-control" id="description" name="description" required>
</div>
<div class="mb-3">
<label for="amount" class="form-label">Amount</label>
<input type="number" step="0.01" class="form-control" id="amount" name="amount" required>
</div>
<div class="mb-3">
<label for="category" class="form-label">Category</label>
<input type="text" class="form-control" id="category" name="category">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save Expense</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php require_once 'includes/footer.php'; ?>

36
handle_login.php Normal file
View File

@ -0,0 +1,36 @@
<?php
session_start();
require_once 'db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = $_POST['email'] ?? null;
$password = $_POST['password'] ?? null;
if ($email && $password) {
try {
$pdo = db();
$sql = "SELECT * FROM team_members WHERE email = ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$email]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
if ($user && password_verify($password, $user['password'])) {
$_SESSION['user_id'] = $user['id'];
$_SESSION['user_name'] = $user['name'];
$_SESSION['user_role'] = $user['role'];
header("Location: index.php");
exit();
} else {
header("Location: login.php?error=Invalid credentials");
exit();
}
} catch (PDOException $e) {
header("Location: login.php?error=" . urlencode($e->getMessage()));
exit();
}
} else {
header("Location: login.php?error=Email and password are required");
exit();
}
}
?>

14
includes/auth.php Normal file
View File

@ -0,0 +1,14 @@
<?php
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
// Allow access to login, logout, and setup scripts without authentication
$allowed_pages = ['login.php', 'handle_login.php', 'logout.php', 'db/setup.php'];
$current_page = basename($_SERVER['PHP_SELF']);
if (!isset($_SESSION['user_id']) && !in_array($current_page, $allowed_pages)) {
header('Location: login.php');
exit();
}
?>

View File

@ -1,5 +1,17 @@
<?php
session_start();
$allowed_pages = ['login.php', 'handle_login.php', 'logout.php', 'db/setup.php'];
$current_page = basename($_SERVER['PHP_SELF']);
if (!isset($_SESSION['user_id']) && !in_array($current_page, $allowed_pages)) {
// also check for setup.php in db folder
if (strpos($_SERVER['REQUEST_URI'], 'db/setup.php') === false) {
header('Location: login.php');
exit();
}
}
?>
<!DOCTYPE html>
<html lang="en">
@ -31,15 +43,44 @@ session_start();
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<?php if(isset($_SESSION['user_id'])): ?>
<?php $activePage = basename($_SERVER['PHP_SELF']); ?>
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="index.php">Dashboard</a>
<a class="nav-link <?= ($activePage == 'index.php') ? 'active':''; ?>" href="index.php">Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="team.php">Team</a>
<a class="nav-link <?= ($activePage == 'team.php') ? 'active':''; ?>" href="team.php">Team</a>
</li>
<li class="nav-item">
<a class="nav-link <?= ($activePage == 'clients.php') ? 'active':''; ?>" href="clients.php">Clients</a>
</li>
<li class="nav-item">
<a class="nav-link <?= ($activePage == 'contacts.php') ? 'active':''; ?>" href="contacts.php">Contacts</a>
</li>
<li class="nav-item">
<a class="nav-link <?= ($activePage == 'tickets.php') ? 'active':''; ?>" href="tickets.php">Tickets</a>
</li>
<li class="nav-item">
<a class="nav-link <?= ($activePage == 'items.php') ? 'active':''; ?>" href="items.php">Items</a>
</li>
<li class="nav-item">
<a class="nav-link <?= ($activePage == 'expenses.php') ? 'active':''; ?>" href="expenses.php">Expenses</a>
</li>
<!-- Other links will go here -->
</ul>
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<?php echo htmlspecialchars($_SESSION['user_name']); ?>
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="#">Profile</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="logout.php">Logout</a></li>
</ul>
</li>
</ul>
<?php endif; ?>
</div>
</div>
</nav>

89
items.php Normal file
View File

@ -0,0 +1,89 @@
<?php
require_once 'db/config.php';
require_once 'includes/header.php';
try {
$pdo = db();
$stmt = $pdo->query("SELECT id, name, description, price FROM items ORDER BY name ASC");
$items = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo '<div class="alert alert-danger">Error fetching items: ' . $e->getMessage() . '</div>';
$items = [];
}
?>
<div class="container mt-4">
<div class="d-flex justify-content-between align-items-center mb-3">
<h1 class="h2">Items</h1>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addItemModal">
Add Item
</button>
</div>
<div class="card">
<div class="card-body">
<table class="table table-hover">
<thead class="table-light">
<tr>
<th>Name</th>
<th>Description</th>
<th>Price</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($items)): ?>
<tr>
<td colspan="4" class="text-center">No items found.</td>
</tr>
<?php else: ?>
<?php foreach ($items as $item): ?>
<tr>
<td><?php echo htmlspecialchars($item['name']); ?></td>
<td><?php echo htmlspecialchars($item['description']); ?></td>
<td><?php echo htmlspecialchars(number_format($item['price'], 2)); ?></td>
<td>
<!-- Actions like edit/delete can be added here -->
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Add Item Modal -->
<div class="modal fade" id="addItemModal" tabindex="-1" aria-labelledby="addItemModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addItemModalLabel">Add New Item</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="add_item.php" method="POST">
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" name="description"></textarea>
</div>
<div class="mb-3">
<label for="price" class="form-label">Price</label>
<input type="number" step="0.01" class="form-control" id="price" name="price" required>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save Item</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php require_once 'includes/footer.php'; ?>

40
login.php Normal file
View File

@ -0,0 +1,40 @@
<?php
require_once 'includes/header.php';
if (isset($_SESSION['user_id'])) {
header('Location: index.php');
exit();
}
$error = $_GET['error'] ?? null;
?>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-6 col-lg-4">
<div class="card mt-5">
<div class="card-body">
<h3 class="card-title text-center mb-4">Login</h3>
<?php if ($error): ?>
<div class="alert alert-danger"><?php echo htmlspecialchars($error); ?></div>
<?php endif; ?>
<form action="handle_login.php" 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" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary">Login</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<?php require_once 'includes/footer.php'; ?>

7
logout.php Normal file
View File

@ -0,0 +1,7 @@
<?php
session_start();
session_unset();
session_destroy();
header("Location: login.php");
exit();
?>

120
projects.php Normal file
View File

@ -0,0 +1,120 @@
<?php
require_once 'db/config.php';
require_once 'includes/header.php';
try {
$pdo = db();
$stmt_projects = $pdo->query("SELECT projects.*, clients.name as client_name FROM projects LEFT JOIN clients ON projects.client_id = clients.id ORDER BY projects.name ASC");
$projects = $stmt_projects->fetchAll(PDO::FETCH_ASSOC);
$stmt_clients = $pdo->query("SELECT id, name FROM clients ORDER BY name ASC");
$clients = $stmt_clients->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo '<div class="alert alert-danger">Error fetching data: ' . $e->getMessage() . '</div>';
$projects = [];
$clients = [];
}
?>
<div class="container mt-4">
<div class="d-flex justify-content-between align-items-center mb-3">
<h1 class="h2">Projects</h1>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addProjectModal">
Add Project
</button>
</div>
<div class="card">
<div class="card-body">
<table class="table table-hover">
<thead class="table-light">
<tr>
<th>Name</th>
<th>Client</th>
<th>Status</th>
<th>Start Date</th>
<th>End Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($projects)): ?>
<tr>
<td colspan="6" class="text-center">No projects found.</td>
</tr>
<?php else: ?>
<?php foreach ($projects as $project): ?>
<tr>
<td><?php echo htmlspecialchars($project['name']); ?></td>
<td><?php echo htmlspecialchars($project['client_name'] ?? 'N/A'); ?></td>
<td><span class="badge bg-<?php echo strtolower(str_replace(' ', '-', $project['status'])) == 'in-progress' ? 'primary' : (strtolower($project['status']) == 'completed' ? 'success' : 'secondary'); ?>"><?php echo htmlspecialchars($project['status']); ?></span></td>
<td><?php echo htmlspecialchars($project['start_date']); ?></td>
<td><?php echo htmlspecialchars($project['end_date']); ?></td>
<td>
<!-- Actions like edit/delete can be added here -->
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Add Project Modal -->
<div class="modal fade" id="addProjectModal" tabindex="-1" aria-labelledby="addProjectModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addProjectModalLabel">Add New Project</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="add_project.php" method="POST">
<div class="mb-3">
<label for="name" class="form-label">Project Name</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" name="description"></textarea>
</div>
<div class="mb-3">
<label for="client_id" class="form-label">Client</label>
<select class="form-select" id="client_id" name="client_id">
<option value="">Select a client</option>
<?php foreach ($clients as $client): ?>
<option value="<?php echo $client['id']; ?>"><?php echo htmlspecialchars($client['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="mb-3">
<label for="status" class="form-label">Status</label>
<select class="form-select" id="status" name="status">
<option value="Not Started" selected>Not Started</option>
<option value="In Progress">In Progress</option>
<option value="Completed">Completed</option>
</select>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="start_date" class="form-label">Start Date</label>
<input type="date" class="form-control" id="start_date" name="start_date">
</div>
<div class="col-md-6 mb-3">
<label for="end_date" class="form-label">End Date</label>
<input type="date" class="form-control" id="end_date" name="end_date">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save Project</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php require_once 'includes/footer.php'; ?>

103
tickets.php Normal file
View File

@ -0,0 +1,103 @@
<?php
require_once 'db/config.php';
require_once 'includes/header.php';
try {
$pdo = db();
$stmt = $pdo->query("SELECT id, title, status, priority, created_at FROM tickets ORDER BY created_at DESC");
$tickets = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo '<div class="alert alert-danger">Error fetching tickets: ' . $e->getMessage() . '</div>';
$tickets = [];
}
?>
<div class="container mt-4">
<div class="d-flex justify-content-between align-items-center mb-3">
<h1 class="h2">Tickets</h1>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addTicketModal">
Add Ticket
</button>
</div>
<div class="card">
<div class="card-body">
<table class="table table-hover">
<thead class="table-light">
<tr>
<th>Title</th>
<th>Status</th>
<th>Priority</th>
<th>Created At</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($tickets)): ?>
<tr>
<td colspan="5" class="text-center">No tickets found.</td>
</tr>
<?php else: ?>
<?php foreach ($tickets as $ticket): ?>
<tr>
<td><?php echo htmlspecialchars($ticket['title']); ?></td>
<td><span class="badge bg-<?php echo str_replace(' ', '-', strtolower($ticket['status'])) == 'open' ? 'success' : (strtolower($ticket['status']) == 'in-progress' ? 'warning' : 'secondary'); ?>"><?php echo htmlspecialchars($ticket['status']); ?></span></td>
<td><span class="badge bg-<?php echo strtolower($ticket['priority']) == 'high' ? 'danger' : (strtolower($ticket['priority']) == 'medium' ? 'warning' : 'success'); ?>"><?php echo htmlspecialchars($ticket['priority']); ?></span></td>
<td><?php echo htmlspecialchars($ticket['created_at']); ?></td>
<td>
<!-- Actions like edit/delete can be added here -->
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Add Ticket Modal -->
<div class="modal fade" id="addTicketModal" tabindex="-1" aria-labelledby="addTicketModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addTicketModalLabel">Add New Ticket</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="add_ticket.php" 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="description" class="form-label">Description</label>
<textarea class="form-control" id="description" name="description"></textarea>
</div>
<div class="mb-3">
<label for="status" class="form-label">Status</label>
<select class="form-select" id="status" name="status">
<option value="Open">Open</option>
<option value="In Progress">In Progress</option>
<option value="Closed">Closed</option>
</select>
</div>
<div class="mb-3">
<label for="priority" class="form-label">Priority</label>
<select class="form-select" id="priority" name="priority">
<option value="Low">Low</option>
<option value="Medium" selected>Medium</option>
<option value="High">High</option>
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save Ticket</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php require_once 'includes/footer.php'; ?>