prepare("SELECT org_id, name FROM Organization ORDER BY name"); $stmt_orgs->execute(); $organizations = $stmt_orgs->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { $message = '
Error loading organizations: ' . $e->getMessage() . '
'; } 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 = '
Error: ' . $e->getMessage() . '
'; } catch (Exception $e) { $message = '
Error: ' . $e->getMessage() . '
'; } } else { $message = '
Please fill in all required fields.
'; } } ?>
LWM
Projects
User Management
Settings
Create New Project
Back to Projects
Project Details
Project ID
Project Name
Description
Organization
0): ?>
-- Select Organization --
+ Create New Organization
New Organization
Organization Name
Organization ID will be auto-generated as UUID
Create Project