-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
244 lines (230 loc) · 8.19 KB
/
index.php
File metadata and controls
244 lines (230 loc) · 8.19 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<?php
session_start();
include 'db.php';
/* 🔐 FORCE LOGIN FIRST (no output before this) */
if (!isset($_SESSION['applicant_id'])) {
header("Location: applicant_login.php");
exit();
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$full_name = $_POST['full_name'];
$contact_number = $_POST['contact_number'];
$email = $_POST['email'];
$address = $_POST['address'];
$position_applying = $_POST['position_applying'];
$education_level = $_POST['education_level'];
$major = $_POST['major'];
$units_earned = $_POST['units_earned'];
$accronym = "";
$assignment = "";
$id_hiringsched = 0;
$stmt = $conn->prepare("
SELECT accronym, schooloffice, id
FROM hiring_schedule
WHERE position_name = ?
ORDER BY start_date DESC
LIMIT 1
");
$stmt->bind_param("s", $position_applying);
$stmt->execute();
$res = $stmt->get_result();
if ($row = $res->fetch_assoc()) {
$accronym = $row['accronym'];
$assignment = $row['schooloffice'];
$id_hiringsched = $row['id'];
}
$stmt->close();
if ($accronym === "" || $assignment === "") {
echo "<script>
alert('This position currently has no active hiring schedule.');
window.history.back();
</script>";
exit;
}
function uploadPDF($fieldName) {
$file = $_FILES[$fieldName];
if ($file['type'] !== 'application/pdf') {
die("Only PDF files allowed for $fieldName");
}
$target = "uploads/" . time() . "_" . basename($file["name"]);
move_uploaded_file($file["tmp_name"], $target);
return $target;
}
$education_pdf = uploadPDF("education_pdf");
$training_pdf = uploadPDF("training_pdf");
$experience_pdf = uploadPDF("experience_pdf");
$eligibility_pdf = uploadPDF("eligibility_pdf");
$stmt = $conn->prepare("
INSERT INTO applicants
(
full_name, contact_number, email, address,
position_applying, hiring_schedule_id, accronym, assignment,
education_level, major, units_earned,
training_pdf, experience_pdf, eligibility_pdf, education_pdf
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
");
$stmt->bind_param(
"sssssisssssssss",
$full_name,
$contact_number,
$email,
$address,
$position_applying,
$id_hiringsched,
$accronym,
$assignment,
$education_level,
$major,
$units_earned,
$training_pdf,
$experience_pdf,
$eligibility_pdf,
$education_pdf
);
if ($stmt->execute()) {
// Redirect to the same page to prevent resubmission
header("Location: " . strtok($_SERVER['REQUEST_URI'], '?') . "?submitted=1");
exit();
} else {
echo "Error: " . $stmt->error;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Recruitment Selection Process (RSP)</title>
<link rel="stylesheet" href="style.css">
<style>
/* ===== HEADER ===== */
.header {
color: white;
padding: 20px;
}
</style>
</head>
<body>
<?php
if (isset($_GET['submitted'])) {
echo "<script>
alert('Application submitted successfully!');
window.history.replaceState({}, document.title, window.location.pathname);
</script>";
}
?>
<div>
<h2>Welcome, <?= htmlspecialchars($_SESSION['applicant_name']) ?></h2>
<a class="logout" href="applicant_logout.php">Logout</a>
<div class="form-container">
<h2>Recruitment Selection Process (RSP)</h2>
<form method="POST" enctype="multipart/form-data" required>
<h3>Personal Information</h3>
<div class="form-grid">
<div class="form-group">
<label>Full Name:</label>
<input type="text" name="full_name" required>
</div>
<div class="form-group">
<label>Contact Number:</label>
<input type="text" name="contact_number" required>
</div>
<div class="form-group">
<label>Email:</label>
<input type="email" name="email" required>
</div>
<div class="form-group">
<label>Address:</label>
<textarea name="address" required></textarea>
</div>
<div class="form-group">
<label>Position Applying:</label>
<div style="display:flex; gap:10px; align-items:center;">
<select name="position_applying" id="position_applying" required>
<option value="">-- Select Position --</option>
</select>
</div>
</div>
<div class="form-group">
<label>School / Office Assignment:</label>
<div style="display:flex; gap:10px; align-items:center;">
<span id="schooloffice_display" style="font-weight:bold; color:#444;"></span>
</div>
</div>
</div>
<h3>Qualifications</h3>
<div class="form-grid">
<div class="form-group">
<label>Education Level:</label>
<select name="education_level" required>
<option value="">-- Select --</option>
<option value="ASSOCIATE'S DEGREE">ASSOCIATE'S DEGREE</option>
<option value="BACHELOR'S DEGREE">BACHELOR'S DEGREE</option>
<option value="MASTER'S DEGREE">MASTER'S DEGREE</option>
<option value="DOCTORAL">DOCTORAL</option>
</select>
</div>
<div class="form-group">
<label>Major:</label>
<input type="text" name="major">
</div>
<div class="form-group">
<label>Units Earned:</label>
<input type="text" name="units_earned">
</div>
<div class="form-group">
<label></label>
</div>
<div class="form-group">
<label>Upload Education PDF:</label>
<input type="file" name="education_pdf" accept="application/pdf" required>
</div>
<div class="form-group">
<label>Upload Training PDF:</label>
<input type="file" name="training_pdf" accept="application/pdf" required>
</div>
<div class="form-group">
<label>Upload Experience PDF:</label>
<input type="file" name="experience_pdf" accept="application/pdf" required>
</div>
<div class="form-group">
<label>Upload Eligibility PDF:</label>
<input type="file" name="eligibility_pdf" accept="application/pdf" required>
</div>
</div>
<div class="submit-btn">
<button type="submit">Submit Application</button>
</div>
</form>
</div>
</div>
<script>
window.onload = function() {
fetch('get_position.php')
.then(response => response.json())
.then(data => {
const select = document.getElementById("position_applying");
const officeSpan = document.getElementById("schooloffice_display");
data.forEach(item => {
let option = document.createElement("option");
option.value = item.position_name;
option.textContent =
item.position_name +
(item.position_type === 'NT' ? ' (Non-Teaching)' : ' (Teaching)');
// store schooloffice
option.dataset.schooloffice = item.schooloffice;
select.appendChild(option);
});
// when position changes
select.addEventListener("change", function () {
const selected = this.options[this.selectedIndex];
officeSpan.textContent = selected.dataset.schooloffice
? "📍 " + selected.dataset.schooloffice
: "";
});
})
.catch(error => console.error('Error loading positions:', error));
};
</script>
</body>
</html>