Compare commits

..

2 Commits

Author SHA1 Message Date
Flatlogic Bot
08b1b2f044 Auto commit: 2025-11-02T20:12:50.034Z 2025-11-02 20:12:50 +00:00
Flatlogic Bot
1d5ec407b8 Auto commit: 2025-11-02T19:50:28.947Z 2025-11-02 19:50:28 +00:00
24 changed files with 1406 additions and 148 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();
}
}
?>

56
add_member.php Normal file
View File

@ -0,0 +1,56 @@
<?php
session_start();
require_once 'db/config.php';
$status = 'error';
$message = 'An unexpected error occurred.';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = trim($_POST['name'] ?? '');
$email = trim($_POST['email'] ?? '');
$role = trim($_POST['role'] ?? '');
if (empty($name) || empty($email) || empty($role)) {
$message = 'Please fill in all required fields.';
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$message = 'Please provide a valid email address.';
} else {
try {
$db = db();
// Check if email already exists
$stmt = $db->prepare("SELECT id FROM team_members WHERE email = :email");
$stmt->bindParam(':email', $email);
$stmt->execute();
if ($stmt->fetch()) {
$message = 'A member with this email address already exists.';
} else {
// Insert new member
$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';
$message = 'New team member added successfully!';
} else {
$message = 'Failed to add new member. Please try again.';
}
}
} catch (PDOException $e) {
// In a real app, log the error instead of showing it to the user
// error_log($e->getMessage());
$message = 'Database error. Could not add member.';
}
}
} else {
$message = 'Invalid request method.';
}
header('Location: team.php?status=' . $status . '&msg=' . urlencode($message));
exit();

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();
}
}
?>

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

@ -0,0 +1,79 @@
/*
* Custom Styles for TEST-CRM-APLIKACIJA
* Palette:
* Primary: #3B82F6
* Secondary: #6B7280
* Background: #F9FAFB
* Surface/Card: #FFFFFF
*/
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
background-color: #F9FAFB;
color: #374151; /* Gray 700 */
}
.navbar {
background-color: #FFFFFF;
border-bottom: 1px solid #E5E7EB; /* Gray 200 */
}
.btn-primary {
background-color: #3B82F6;
border-color: #3B82F6;
font-weight: 500;
}
.btn-primary:hover {
background-color: #2563EB;
border-color: #2563EB;
}
.card {
border: 1px solid #E5E7EB; /* Gray 200 */
border-radius: 0.5rem; /* rounded-lg */
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}
.table {
background-color: #FFFFFF;
}
.table thead th {
border-bottom-width: 1px;
border-color: #E5E7EB; /* Gray 200 */
font-weight: 600;
color: #4B5563; /* Gray 600 */
text-transform: uppercase;
letter-spacing: 0.05em;
font-size: 0.75rem;
}
.badge {
font-weight: 500;
font-size: 0.75rem;
padding: 0.3em 0.6em;
}
.modal-content {
border-radius: 0.5rem;
border: none;
}
.form-label {
font-weight: 500;
color: #374151; /* Gray 700 */
}
.toast {
width: 350px;
max-width: 100%;
font-size: .875rem;
background-color: rgba(255,255,255,.85);
background-clip: padding-box;
border: 1px solid rgba(0,0,0,.1);
box-shadow: 0 0.5rem 1rem rgba(0,0,0,.15);
border-radius: .25rem;
}

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'; ?>

120
db/setup.php Normal file
View File

@ -0,0 +1,120 @@
<?php
// db/setup.php
require_once 'config.php';
try {
// 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);
// 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();
}
?>

45
includes/footer.php Normal file
View File

@ -0,0 +1,45 @@
</main>
<!-- Toast Container -->
<div class="position-fixed bottom-0 end-0 p-3" style="z-index: 11">
<div id="notificationToast" class="toast hide" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<strong class="me-auto" id="toastTitle"></strong>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body" id="toastBody">
</div>
</div>
</div>
<!-- Bootstrap 5 JS Bundle -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
const urlParams = new URLSearchParams(window.location.search);
const status = urlParams.get('status');
const msg = urlParams.get('msg');
if (status && msg) {
const toastEl = document.getElementById('notificationToast');
const toastTitleEl = document.getElementById('toastTitle');
const toastBodyEl = document.getElementById('toastBody');
toastTitleEl.textContent = status === 'success' ? 'Success' : 'Error';
toastBodyEl.textContent = decodeURIComponent(msg);
toastEl.classList.remove('hide');
toastEl.classList.add('show');
if(status === 'success') {
toastEl.classList.add('bg-success-subtle');
} else {
toastEl.classList.add('bg-danger-subtle');
}
const toast = new bootstrap.Toast(toastEl);
toast.show();
}
});
</script>
</body>
</html>

88
includes/header.php Normal file
View File

@ -0,0 +1,88 @@
<?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">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TEST-CRM-APLIKACIJA</title>
<meta name="description" content="Built with Flatlogic Generator">
<meta name="keywords" content="crm, customer relationship management, project management, team collaboration, invoicing, sales, leads, flatlogic">
<meta property="og:title" content="TEST-CRM-APLIKACIJA">
<meta property="og:description" content="Built with Flatlogic Generator">
<meta property="og:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? ''); ?>">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? ''); ?>">
<!-- Bootstrap 5 CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Bootstrap Icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<!-- Custom CSS -->
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
<div class="container-fluid">
<a class="navbar-brand fw-bold text-primary" href="index.php">CRM</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">
<?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 <?= ($activePage == 'index.php') ? 'active':''; ?>" href="index.php">Dashboard</a>
</li>
<li class="nav-item">
<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>
</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>
<main class="container-fluid mt-4">

169
index.php
View File

@ -1,150 +1,23 @@
<?php <?php require_once 'includes/header.php'; ?>
declare(strict_types=1);
@ini_set('display_errors', '1');
@error_reporting(E_ALL);
@date_default_timezone_set('UTC');
$phpVersion = PHP_VERSION; <div class="px-4 py-5 my-5 text-center">
$now = date('Y-m-d H:i:s'); <h1 class="display-5 fw-bold">Welcome to your CRM</h1>
?> <div class="col-lg-6 mx-auto">
<!doctype html> <p class="lead mb-4">This is the starting point for your new application. We've set up a sample "Team Members" page for you to get started.</p>
<html lang="en"> <div class="d-grid gap-2 d-sm-flex justify-content-sm-center">
<head> <a href="team.php" class="btn btn-primary btn-lg px-4 gap-3">Manage Team Members</a>
<meta charset="utf-8" /> <button type="button" class="btn btn-outline-secondary btn-lg px-4">Learn More</button>
<meta name="viewport" content="width=device-width, initial-scale=1" /> </div>
<title>New Style</title>
<?php
// Read project preview data from environment
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
?>
<?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) <?php
</footer> // This will run the setup script one time
</body> if (!file_exists('db/setup_done.flag')) {
</html> echo '<div class="container"><div class="alert alert-info">Running one-time database setup...</div></div>';
include 'db/setup.php';
file_put_contents('db/setup_done.flag', 'done');
}
?>
<?php require_once 'includes/footer.php'; ?>

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'; ?>

109
team.php Normal file
View File

@ -0,0 +1,109 @@
<?php
require_once 'includes/header.php';
require_once 'db/config.php';
// Fetch team members
$members = [];
try {
$db = db();
$stmt = $db->query("SELECT id, name, email, role, status, created_at FROM team_members ORDER BY created_at DESC");
$members = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
// In a real app, you'd log this error. For now, we'll just show a message.
echo '<div class="alert alert-danger">Could not connect to the database.</div>';
}
?>
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<h1 class="h4 mb-0">Team Members</h1>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addMemberModal">
<i class="bi bi-plus-lg"></i> Add Member
</button>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<thead class="table-light">
<tr>
<th scope="col">Name</th>
<th scope="col">Email</th>
<th scope="col">Role</th>
<th scope="col">Status</th>
<th scope="col">Joined</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($members)): ?>
<tr>
<td colspan="6" class="text-center text-muted">No team members found. Add one to get started!</td>
</tr>
<?php else: ?>
<?php foreach ($members as $member): ?>
<tr>
<td class="fw-medium"><?php echo htmlspecialchars($member['name']); ?></td>
<td><?php echo htmlspecialchars($member['email']); ?></td>
<td><?php echo htmlspecialchars($member['role']); ?></td>
<td>
<?php
$status_class = $member['status'] === 'active' ? 'bg-success-subtle text-success-emphasis' : 'bg-secondary-subtle text-secondary-emphasis';
echo '<span class="badge ' . $status_class . '">' . htmlspecialchars(ucfirst($member['status'])) . '</span>';
?>
</td>
<td><?php echo date('M d, Y', strtotime($member['created_at'])); ?></td>
<td>
<a href="#" class="btn btn-sm btn-outline-secondary"><i class="bi bi-pencil"></i></a>
<a href="#" class="btn btn-sm btn-outline-danger"><i class="bi bi-trash"></i></a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Add Member Modal -->
<div class="modal fade" id="addMemberModal" tabindex="-1" aria-labelledby="addMemberModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addMemberModalLabel">Add New Team Member</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="add_member.php" method="POST">
<div class="modal-body">
<div class="mb-3">
<label for="name" class="form-label">Full 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 address</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<label for="role" class="form-label">Role</label>
<select class="form-select" id="role" name="role" required>
<option selected disabled value="">Choose...</option>
<option value="Admin">Admin</option>
<option value="Project Manager">Project Manager</option>
<option value="Team Member">Team Member</option>
<option value="Sales/Lead Manager">Sales/Lead Manager</option>
<option value="Finance">Finance</option>
<option value="Support Agent">Support Agent</option>
<option value="Client">Client</option>
</select>
</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 Member</button>
</div>
</form>
</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'; ?>