223 lines
8.9 KiB
PHP
223 lines
8.9 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Create Project - Lab Workflow Manager</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
|
|
<style>
|
|
:root {
|
|
--primary-color: #2a3f54;
|
|
--secondary-color: #73879C;
|
|
--background-color: #F7F7F7;
|
|
--surface-color: #FFFFFF;
|
|
--accent-color: #1ABB9C;
|
|
}
|
|
body {
|
|
display: flex;
|
|
background-color: var(--background-color);
|
|
font-family: "Helvetica Neue", Roboto, Arial, sans-serif;
|
|
}
|
|
.sidebar {
|
|
width: 250px;
|
|
height: 100vh;
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
background-color: var(--primary-color);
|
|
color: #ECF0F1;
|
|
padding-top: 20px;
|
|
}
|
|
.sidebar h3 {
|
|
text-align: center;
|
|
margin-bottom: 30px;
|
|
font-weight: bold;
|
|
}
|
|
.sidebar .nav-link {
|
|
color: #ECF0F1;
|
|
padding: 10px 20px;
|
|
transition: background-color 0.3s;
|
|
}
|
|
.sidebar .nav-link:hover, .sidebar .nav-link.active {
|
|
background-color: var(--accent-color);
|
|
color: var(--surface-color);
|
|
}
|
|
.sidebar .nav-link .fa {
|
|
margin-right: 10px;
|
|
}
|
|
.main-content {
|
|
margin-left: 250px;
|
|
padding: 20px;
|
|
width: calc(100% - 250px);
|
|
}
|
|
.header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 20px;
|
|
}
|
|
.header h1 {
|
|
font-weight: bold;
|
|
color: var(--primary-color);
|
|
}
|
|
.card {
|
|
border: none;
|
|
border-radius: 8px;
|
|
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<?php
|
|
require_once 'db/config.php';
|
|
$message = '';
|
|
$organizations = [];
|
|
|
|
// Fetch all organizations
|
|
try {
|
|
$pdo = db();
|
|
$stmt_orgs = $pdo->prepare("SELECT org_id, name FROM Organization ORDER BY name");
|
|
$stmt_orgs->execute();
|
|
$organizations = $stmt_orgs->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
$message = '<div class="alert alert-danger">Error loading organizations: ' . $e->getMessage() . '</div>';
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$project_id = $_POST['project_id'] ?? '';
|
|
$name = $_POST['name'] ?? '';
|
|
$description = $_POST['description'] ?? '';
|
|
$org_id = $_POST['org_id'] ?? '';
|
|
$new_org_name = $_POST['new_org_name'] ?? '';
|
|
|
|
if (!empty($project_id) && !empty($name) && !empty($description)) {
|
|
try {
|
|
$pdo = db();
|
|
|
|
// If creating a new organization (org_id is "__NEW__" or empty and new_org_name is provided)
|
|
if (($org_id === '__NEW__' || empty($org_id)) && !empty($new_org_name)) {
|
|
// Generate UUID for org_id
|
|
$new_org_id = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
|
|
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
|
|
mt_rand(0, 0xffff),
|
|
mt_rand(0, 0x0fff) | 0x4000,
|
|
mt_rand(0, 0x3fff) | 0x8000,
|
|
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
|
|
);
|
|
|
|
// Insert organization FIRST
|
|
$sql_org = "INSERT INTO Organization (org_id, name) VALUES (?, ?)";
|
|
$stmt_org = $pdo->prepare($sql_org);
|
|
$stmt_org->execute([$new_org_id, $new_org_name]);
|
|
$org_id = $new_org_id;
|
|
} elseif (empty($org_id) || $org_id === '__NEW__') {
|
|
throw new Exception("Please select an organization or enter a new organization name");
|
|
}
|
|
|
|
// Insert project AFTER organization is created
|
|
$sql = "INSERT INTO Project (project_id, name, description, org_id, `Start Date`) VALUES (?, ?, ?, ?, CURDATE())";
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute([$project_id, $name, $description, $org_id]);
|
|
header("Location: index.php");
|
|
exit();
|
|
} catch (PDOException $e) {
|
|
$message = '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
|
|
} catch (Exception $e) {
|
|
$message = '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
|
|
}
|
|
} else {
|
|
$message = '<div class="alert alert-warning">Please fill in all required fields.</div>';
|
|
}
|
|
}
|
|
?>
|
|
|
|
<div class="sidebar">
|
|
<h3><i class="fa fa-flask"></i> LWM</h3>
|
|
<ul class="nav flex-column">
|
|
<li class="nav-item">
|
|
<hr>
|
|
<a href="index.php" class="nav-link active"><i class="fa fa-tasks"></i> Projects</a>
|
|
<a href="users.php" class="nav-link"><i class="fa fa-users"></i> User Management</a>
|
|
<a href="#" class="nav-link"><i class="fa fa-cogs"></i> Settings</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="main-content">
|
|
<div class="header">
|
|
<h1>Create New Project</h1>
|
|
<a href="index.php" class="btn btn-secondary"><i class="fa fa-arrow-left"></i> Back to Projects</a>
|
|
</div>
|
|
|
|
<?php echo $message; ?>
|
|
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Project Details</h5>
|
|
<form action="create_project.php" method="POST">
|
|
<div class="mb-3">
|
|
<label for="project_id" class="form-label">Project ID</label>
|
|
<input type="text" class="form-control" id="project_id" name="project_id" required>
|
|
</div>
|
|
<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" rows="3" required></textarea>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label">Organization</label>
|
|
<?php if (count($organizations) > 0): ?>
|
|
<select class="form-control mb-2" id="org_id" name="org_id" onchange="toggleNewOrgFields()">
|
|
<option value="">-- Select Organization --</option>
|
|
<?php foreach ($organizations as $org): ?>
|
|
<option value="<?php echo htmlspecialchars($org['org_id']); ?>">
|
|
<?php echo htmlspecialchars($org['name'] . ' (' . $org['org_id'] . ')'); ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
<option value="__NEW__">+ Create New Organization</option>
|
|
</select>
|
|
<?php endif; ?>
|
|
<div class="mb-3" id="new_org_fields" style="display: <?php echo count($organizations) === 0 ? 'block' : 'none'; ?>;">
|
|
<div class="card bg-light">
|
|
<div class="card-body">
|
|
<h6 class="card-title">New Organization</h6>
|
|
<div class="mb-3">
|
|
<label for="new_org_name" class="form-label">Organization Name</label>
|
|
<input type="text" class="form-control" id="new_org_name" name="new_org_name" placeholder="Enter organization name">
|
|
<small class="form-text text-muted">Organization ID will be auto-generated as UUID</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary" style="background-color: var(--accent-color); border-color: var(--accent-color);">Create Project</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script>
|
|
function toggleNewOrgFields() {
|
|
const orgSelect = document.getElementById('org_id');
|
|
const newOrgFields = document.getElementById('new_org_fields');
|
|
const newOrgNameInput = document.getElementById('new_org_name');
|
|
|
|
if (orgSelect && orgSelect.value === '__NEW__') {
|
|
newOrgFields.style.display = 'block';
|
|
newOrgNameInput.required = true;
|
|
} else {
|
|
newOrgFields.style.display = 'none';
|
|
newOrgNameInput.required = false;
|
|
newOrgNameInput.value = '';
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|