This repository was archived by the owner on Mar 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplicationForm.php
More file actions
372 lines (347 loc) · 18.7 KB
/
applicationForm.php
File metadata and controls
372 lines (347 loc) · 18.7 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
<?php
require_once($_SERVER["DOCUMENT_ROOT"] . '/../Support/configEnglishContest.php');
require_once($_SERVER["DOCUMENT_ROOT"] . '/../Support/basicLib.php');
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if (isset($_POST['upload'])) {
$contestID = htmlspecialchars($_POST['contestID']); //Get id passed, this is the contests id
// this comes from the radio buttons on submission for selecting category name ie. fiction, poetry, screenplay etc
$categoryID = htmlspecialchars($_POST['categoryName']);
$title = $db->real_escape_string(htmlspecialchars($_POST["title"]));
//if the contest requires enter the value otherwise enter default NoValue
$courseNameNum = (strlen($db->real_escape_string(htmlspecialchars($_POST["courseNameNum"]))) > 0 ? $db->real_escape_string(htmlspecialchars($_POST["courseNameNum"])) : "NoValue" );
$instrName = (strlen($db->real_escape_string(htmlspecialchars($_POST["instrName"]))) > 0 ? $db->real_escape_string(htmlspecialchars($_POST["instrName"])) : "NoValue" );
$termYear = (strlen($db->real_escape_string(htmlspecialchars($_POST["termYear"]))) > 0 ? $db->real_escape_string(htmlspecialchars($_POST["termYear"])) : "NoValue" );
$recLetter1Name = (strlen($db->real_escape_string(htmlspecialchars($_POST["recLetter1Name"]))) > 0 ? $db->real_escape_string(htmlspecialchars($_POST["recLetter1Name"])) : "NoValue" );
$recLetter2Name = (strlen($db->real_escape_string(htmlspecialchars($_POST["recLetter2Name"]))) > 0 ? $db->real_escape_string(htmlspecialchars($_POST["recLetter2Name"])) : "NoValue" );
$sqlApplicant = "SELECT id, classLevel FROM tbl_applicant WHERE uniqname = '$login_name' ";
if(!$resApplicant = $db->query($sqlApplicant)){
unset($_POST['upload']);
db_fatal_error("data lookup issue", $db->error, $sqlApplicant, $login_name);
exit($user_err_message);
}
if ($resApplicant->num_rows > 0) {
// output data of each row
while ($row = $resApplicant->fetch_assoc()) {
$applicantID = $row["id"];
$classLevelID = $row["classLevel"];
}
} else {
//no contest matched ID so go back to index to allow user to reselect a contest
non_db_error("no applicant matched ID! Exited application - Username=> " . $login_name, $login_name);
exit();
}
if ((!empty($_FILES["fileToUpload"])) && ($_FILES['fileToUpload']['error'] == 0) && (strlen(basename($_FILES["fileToUpload"]["name"])) < 250)) {
$target_dir = $_SERVER["DOCUMENT_ROOT"] . '/../contestfiles/';
$filename = basename($_FILES["fileToUpload"]["name"]);
$filename = preg_replace("/[^A-Za-z0-9\.]/", '', $filename);
$target_file = getUTCTime() . "_" . $filename;
//added 111215 to fix upload error due to special chars in name
$target_file = $db->real_escape_string(htmlspecialchars($target_file));
$target_full = $target_dir . $target_file;
$ext = strtolower(substr($filename, strrpos($filename, '.') + 1));
$fileType = $_FILES['fileToUpload']['type'];
$max_file_size = 20971520; //20M
$uploadOk = 0; //if this value is 0 the file will not upload. After all check pass it will set to 1.
$fileErrMessage = "<strong>Use your browser's back button and correct the following errors: </strong>";
// Check if file already exists
if (file_exists($target_full)) {
$fileErrMessage = $fileErrMessage . " <br />=>Sorry, that file already exists.";
}
// Check file size is not larger than allowable
if ($_FILES["fileToUpload"]["size"] > $max_file_size) {
$fileErrMessage = $fileErrMessage . " <br />=>Sorry, your file was too large.";
}
// Allow only pdf file format and change uploadOK to 1 if TRUE
if ((($fileType == "application/pdf") || ($fileType == "application/vnd.adobe.pdf")) && ($ext == 'pdf')) {
$uploadOk = 1;
} else {
$fileErrMessage = $fileErrMessage . " <br />=>Sorry, only PDF files are allowed. This is a " . $fileType . " with the extension of " . $ext;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
$fileErrMessage = $fileErrMessage . " <br />=>Your file was not uploaded. Confirm the file is 20 megabytes or less and in PDF format.";
$target_file = "empty";
non_db_error($fileErrMessage . "Username=> " . $login_name, $login_name);
exit($user_err_message . "<br />" . $fileErrMessage);
} else {
// if everything is ok, try to upload file
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_full)) {
echo "The file ". $target_file . " has been uploaded.";
$sqlInsert = <<<SQL
INSERT INTO `tbl_entry`
(`contestID`,
`applicantID`,
`categoryID`,
`classLevelID`,
`title`,
`documentName`,
`courseNameNum`,
`instrName`,
`termYear`,
`recLetter1Name`,
`recLetter2Name`,
`created_by`)
VALUES
($contestID,
$applicantID,
$categoryID,
$classLevelID,
'$title',
'$target_file',
'$courseNameNum',
'$instrName',
'$termYear',
'$recLetter1Name',
'$recLetter2Name',
'$login_name')
SQL;
if (!$result = $db->query($sqlInsert)) {
db_fatal_error("Data insert issue- " . $fileErrMessage, $db->error, $sqlInsert, $login_name);
exit($user_err_message);
} else {
unset($_POST['upload']);
$_SESSION['flashMessage'] = "<span class='text-success'>- Successful submission -</span>";
safeRedirect('index.php');
exit();
}
} else {
$target_file = "empty";
$fileErrMessage = $fileErrMessage . " - Sorry, there was an error uploading your file.";
non_db_err($fileErrMessage . " - Username=> " . $login_name);
exit();
}
}
} else {
$target_file = "empty";
$fileErrMessage = $fileErrMessage . " - no file information - ";
non_db_error($fileErrMessage . " Username=> " . $login_name, $login_name);
exit($user_err_message);
}
}
//Since $_POST is not set this page display the contest entry form so Get id passed, this is the contests id
if (!empty($_GET['id'])) {
$contestID = htmlspecialchars($_GET['id']);
$sqlSelect = <<<SQL
SELECT lk_contests.name, lk_contests.id
FROM lk_contests where lk_contests.id = (
SELECT contestsid
FROM tbl_contest
WHERE tbl_contest.id = '{$contestID}'
)
SQL;
if(!$res = $db->query($sqlSelect)){
db_fatal_error("Error: Could not resolve (get) contest name", $db->error, $sqlSelect, $login_name);
exit($user_err_message);
}
if ($res->num_rows > 0) {
// output data of each row
while ($row = $res->fetch_assoc()) {
$contestName = $row["name"];
$contestsID = $row["id"]; //get the tbl_contests id of the contest
}
} else {
//no contest matched ID so go back to index to allow user to reselect a contest
non_db_error("no contest matched ID! sent user back to index to allow them to reselect a contest. Username=> " . $login_name, $login_name);
safeRedirect('index.php');
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>LSA-<?php echo "$deptLngName";?> Writing Contests</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="LSA-English Writing Contests">
<meta name="keywords" content="LSA-English, Hopwood, Writing, UniversityofMichigan">
<meta name="author" content="LSA-MIS_rsmoke">
<link rel="icon" href="img/favicon.ico">
<script type='text/javascript' src='js/webforms2.js'></script>
<link type="text/css" rel="stylesheet" href="css/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="css/normalize.css" media="all">
<link type="text/css" rel="stylesheet" href="css/default.css" media="all">
<!-- <link href="css/form.css" rel="stylesheet" type="text/css"> -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<nav class="navbar navbar-default navbar-fixed-top navbar-inverse" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button> <a class="navbar-brand" href="index.php">
<?php echo "$contestTitle";?></a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Signed in as <?php echo $login_name;?><strong class="caret"></strong></a>
<ul class="dropdown-menu">
<li>
<a href="detailEdit.php">Profile</a>
</li>
<li class="divider">
</li>
<li>
<a href="https://weblogin.umich.edu/cgi-bin/logout">logout</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<div class="row clearfix">
<div class="col-md-12">
<section>
<header>
<h3><?php echo $contestName; ?></h3>
</header>
<article>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" enctype="multipart/form-data">
<input class="form-control" type="hidden" required name="contestID" value="<?php echo $contestID; ?>" >
<?php
switch ($contestsID) {
case 1: //falls through
case 2: //falls through
case 3: //falls through
case 17: //falls through
case 18: //falls through
case 19: //falls through
case 20: //falls through
case 21: //falls through
case 22: //falls through
case 23: //falls through
case 24: //falls through
case 25: //falls through
case 26: //falls through
echo '<div id="hopwoodTemplate">';
echo '<h5>ACADEMICS</h5>';
echo '<h5 class="bg-warning"><span class="text-info">NOTICE:</span> There is no longer a requirement to upload transcripts</h5><br>';
echo '<label for="courseNameNumber">Qualifying Course (DEPARTMENT AND COURSE #)</label>';
echo '<input class="form-control" type="text" required name="courseNameNum" placeholder="example: eng216" />';
echo '<label for="instrName">Name of Instructor</label>';
echo '<input class="form-control" type="text" required name="instrName" placeholder="example: Petra Kuppers" />';
echo '<label for="termYear">Term and Year Taken</label>';
echo '<input class="form-control" type="text" required name="termYear" placeholder="example: Fall-2014" />';
echo '</div>';
break;
case 12:
echo '<div id="millerTemplate">';
echo '<label for="recLetter1">Name of faculty submitting first letter of recommendation (or e-mail)</label>';
echo '<input class="form-control" type="text" required name="recLetter1Name" placeholder="example: Petra Kuppers" />';
echo '<label for="recLetter2">Name of faculty submitting second letter of recommendation (or e-mail)</label>';
echo '<input class="form-control" type="text" required name="recLetter2Name" placeholder="example: Alisse Portnoy" />';
echo '</div>';
break;
// Do I need a default here?
}
?>
<label for="title">Title of submission</label>
<input class="form-control" type="text" required name="title" />
<label for="categoryName">Please select a manuscript type:</label>
<div id="radioSelectFor<?php echo $contestName; ?>">
<?php //select what the application category(novel, poetry, fiction etc) is for the submission by
//taking the contests id and doing a lookup on link_contestsTocategory
switch ($contestsID) { //What contests id is being submitted to
case 17: //falls through
case 21: //falls through
case 24: //falls through
case 27: // it would be categoryID 3
case 34:
echo '<label class="radio-inline"><input type="radio" name="categoryName" value="3" checked required >Nonfiction</label>';
break;
case 18:
case 31:
case 32: // it would be categoryID 4
echo '<label class="radio-inline"><input type="radio" name="categoryName" value="4" checked required >Fiction</label>';
break;
case 2: //it would be categoryID 2
echo '<label class="radio-inline"><input type="radio" name="categoryName" value="2" checked required >Screenplay</label>';
break;
case 30: //it would be categoryID 1 2
echo '<label class="radio-inline"><input type="radio" name="categoryName" value="1" required >Drama</label>';
echo '<label class="radio-inline"><input type="radio" name="categoryName" value="2" required >Screenplay</label>';
break;
case 10: // it would be categoryID 1 2 3 4 5
echo '<label class="radio-inline"><input type="radio" name="categoryName" value="1" required >Drama</label>';
echo '<label class="radio-inline"><input type="radio" name="categoryName" value="4" required >Fiction</label>';
echo '<label class="radio-inline"><input type="radio" name="categoryName" value="3" required >Nonfiction</label>';
echo '<label class="radio-inline"><input type="radio" name="categoryName" value="5" required >Poetry</label>';
echo '<label class="radio-inline"><input type="radio" name="categoryName" value="2" required >Screenplay</label>';
break;
case 11: //it would be categoryID 1 or 2 build select statement
echo '<label class="radio-inline"><input type="radio" name="categoryName" value="1" required >Drama</label>';
echo '<label class="radio-inline"><input type="radio" name="categoryName" value="2" required >Screenplay</label>';
break;
case 12: //it would be categoryID 1 2 4 or 5 build select statement
echo '<label class="radio-inline"><input type="radio" name="categoryName" value="1" required >Drama</label>';
echo '<label class="radio-inline"><input type="radio" name="categoryName" value="4" required >Fiction</label>';
echo '<label class="radio-inline"><input type="radio" name="categoryName" value="5" required >Poetry</label>';
echo '<label class="radio-inline"><input type="radio" name="categoryName" value="2" required >Screenplay</label>';
break;
case 19: //it would be categoryID 6
echo '<label class="radio-inline"><input type="radio" name="categoryName" value="6" checked required >Novel</label>';
break;
case 20: //it would be categoryID 1
echo '<label class="radio-inline"><input type="radio" name="categoryName" value="1" checked required >Drama</label>';
break;
case 22: // falls through
case 25: // falls through
case 28: //it would be categoryID 7
echo '<label class="radio-inline"><input type="radio" name="categoryName" value="7" checked required >Shortfiction</label>';
break;
case 35: //it would be categoryID 8
echo '<label class="radio-inline"><input type="radio" name="categoryName" value="8" checked required >Text-Image_Composition</label>';
break;
default: //5,6,7,8,9,15,29,33 are all poetry only apps so they are default setting it would be categoryID 5
echo '<label class="radio-inline"><input type="radio" name="categoryName" value="5" checked required >Poetry</label>';
};
?>
</div>
<div class="form-group fileUpload-group">
<label class="control-label" for="fileToUpload">Select file to upload (it must be in PDF format):</label>
<input type="hidden" name="MAX_FILE_SIZE" value="20971520" />
<input type="file" name="fileToUpload" id="fileToUpload" required />
<span id="helpBlock2" class="help-block">Title (or first) page of pdf should be <strong><em>title of your manuscript, pen-name</em></strong> and <strong><em>contest and division entered (e.g. Hopwood Poetry)</em></strong> only.</span>
</div>
<div class='text-center'>
<input class="btn btn-success" type="submit" name="upload" value="Upload Application">
</div>
</form>
</article>
</section>
</div>
</div>
</div><!-- class="container" -->
<!-- if there is not a record display this stuff -->
<?php include("footer.php");?>
<script>
var uploadField = document.getElementById("fileToUpload");
uploadField.onchange = function() {
if(this.files[0].size > 20971520){
alert("Your file is too big!");
this.value = "";
};
};
</script>
</body>
</html>
<?php
} else {
//"no ID in url so go back to index to allow user to reselect a contest"
non_db_error("no ID in url! sent user back to index to allow them to reselect a contest. Username=> " . $login_name, $login_name);
safeRedirect('index.php');
exit();
}
?>