-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoffers.php
More file actions
165 lines (154 loc) · 6.13 KB
/
offers.php
File metadata and controls
165 lines (154 loc) · 6.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
require_once 'db.php';
function h(string $value): string
{
return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
}
$allowedRoles = ['Startup', 'Investor', 'Service Provider', 'Community Member'];
$allowedCategories = [
'Employee Search',
'Investor Search',
'Event Speaking',
'Marketing Materials Sharing',
'Sales Support',
'Client Search',
'Other',
];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$fullName = trim((string) ($_POST['full_name'] ?? ''));
$email = trim((string) ($_POST['email'] ?? ''));
$organization = trim((string) ($_POST['organization'] ?? ''));
$role = trim((string) ($_POST['role'] ?? ''));
$skillsDescription = trim((string) ($_POST['skills_description'] ?? ''));
$category = trim((string) ($_POST['category'] ?? ''));
$city = trim((string) ($_POST['city'] ?? ''));
$valid = $fullName !== ''
&& $email !== ''
&& filter_var($email, FILTER_VALIDATE_EMAIL)
&& in_array($role, $allowedRoles, true)
&& $skillsDescription !== ''
&& $city !== ''
&& ($category === '' || in_array($category, $allowedCategories, true));
if (!$valid) {
header('Location: offers.php?error=1');
exit;
}
try {
$insertStmt = $pdo->prepare(
'INSERT INTO offers (full_name, email, organization, role, skills_description, category, city, active)
VALUES (:full_name, :email, :organization, :role, :skills_description, :category, :city, 1)'
);
$insertStmt->execute([
':full_name' => $fullName,
':email' => $email,
':organization' => $organization !== '' ? $organization : null,
':role' => $role,
':skills_description' => $skillsDescription,
':category' => $category !== '' ? $category : null,
':city' => $city,
]);
header('Location: offers.php?success=1');
exit;
} catch (Exception $e) {
header('Location: offers.php?error=1');
exit;
}
}
$offersStmt = $pdo->query('SELECT id, full_name, organization, role, skills_description, category, city FROM offers WHERE active = 1 ORDER BY created_at DESC');
$offers = $offersStmt->fetchAll();
$success = isset($_GET['success']) && $_GET['success'] === '1';
$error = isset($_GET['error']) && $_GET['error'] === '1';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Community Offers</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div class="header-row">
<div>
<h1 class="title">Community Offers</h1>
<p class="subtitle">Share what you can offer to the 0100 ecosystem</p>
</div>
<div class="nav-links">
<a class="nav-link" href="index.php">Public Form</a>
<a class="nav-link" href="admin.php">Admin</a>
</div>
</div>
<?php if ($success): ?>
<div class="banner success">Offer submitted successfully.</div>
<?php elseif ($error): ?>
<div class="banner error">Offer submission failed. Check required fields.</div>
<?php endif; ?>
<div class="panel section">
<div class="meta-label muted">Submit an Offer</div>
<form method="POST" action="offers.php" class="form-grid section">
<div class="form-group">
<label for="full_name">Full Name *</label>
<input id="full_name" name="full_name" type="text" required>
</div>
<div class="form-group">
<label for="email">Email *</label>
<input id="email" name="email" type="email" required>
</div>
<div class="form-group">
<label for="organization">Organization</label>
<input id="organization" name="organization" type="text">
</div>
<div class="form-group">
<label for="role">Role *</label>
<select id="role" name="role" required>
<option value="">Select role</option>
<?php foreach ($allowedRoles as $role): ?>
<option value="<?php echo h($role); ?>"><?php echo h($role); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label for="category">Category</label>
<select id="category" name="category">
<option value="">Any</option>
<?php foreach ($allowedCategories as $category): ?>
<option value="<?php echo h($category); ?>"><?php echo h($category); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label for="city">City *</label>
<input id="city" name="city" type="text" required>
</div>
<div class="form-group" style="grid-column: 1 / -1;">
<label for="skills_description">Skills Description *</label>
<textarea id="skills_description" name="skills_description" rows="5" required></textarea>
</div>
<button type="submit" class="btn">Submit Offer</button>
</form>
</div>
<div class="panel section">
<div class="meta-label muted">Active Community Offers</div>
<?php if (empty($offers)): ?>
<p class="muted section">No active offers yet.</p>
<?php else: ?>
<div class="list section">
<?php foreach ($offers as $offer): ?>
<div class="list-item">
<div><strong><?php echo h((string) $offer['full_name']); ?></strong></div>
<div class="muted"><?php echo h((string) $offer['role']); ?></div>
<div class="muted"><?php echo h((string) ($offer['organization'] ?? '')); ?></div>
<div class="muted">City: <?php echo h((string) $offer['city']); ?></div>
<?php if (!empty($offer['category'])): ?>
<div class="section"><span class="pill"><?php echo h((string) $offer['category']); ?></span></div>
<?php endif; ?>
<p class="section"><?php echo nl2br(h((string) $offer['skills_description'])); ?></p>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
</body>
</html>