-
Notifications
You must be signed in to change notification settings - Fork 2
/
submitted.php
154 lines (141 loc) · 4.16 KB
/
submitted.php
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
<!DOCTYPE html>
<html>
<head>
<title>Opera Omnia</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8"/>
<link rel="stylesheet" type="text/css"
href="https://cdn.rawgit.com/dreampulse/computer-modern-web-font/master/fonts.css">
</head>
<header>
<?php include("header.php"); ?>
</header>
<body>
<?php
if (isset($_FILES['paperSubmitted']) && $_FILES['paperSubmitted']['error'] == 0)
{
if ($_FILES['paperSubmitted']['size'] <= 10000000)
{
if (pathinfo($_FILES['paperSubmitted']['name'])['extension'] == 'pdf')
{
try
{
$db = new PDO('mysql:host=localhost;dbname=operaomnia v2;charset=utf8', 'root', '');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(Exception $e)
{
die('Error : '.$e->getMessage());
}
if ($_POST['authorID'][sizeof($_POST['authorID'])-1] == 'unspecified')
{
$usedIDs = $db->query('SELECT ID FROM authors');
$definitiveID=sprintf('%010d', rand(0,9999999999));
while ($usedID = $usedIDs->fetch())
{
if ($usedID==$definitiveID)
{
$usedID = $db->query('SELECT * FROM papers');
$definitiveID=rand(0,9999999999);
$definitiveID=sprintf('%10d', $ID);
}
}
$fields="";
foreach ($_POST['Fields'] as $field)
{
$fields.=(string)$field;
$fields.="_";
}
$fields=substr($fields, 0, -1);
$req = $db->prepare('INSERT INTO autsubmits(FirstName, LastName, DateBirth, DateDeath, Bio, Fields, definitiveID)
VALUES(:FirstName, :LastName, :DateBirth, :DateDeath, :Bio, :Fields, :definitiveID)');
$req->execute(array(
'FirstName' => $_POST['FirstName'],
'LastName' => $_POST['LastName'],
'DateBirth' => $_POST['DateBirth'],
'DateDeath' => $_POST['DateDeath'],
'Bio' => $_POST['Bio'],
'Fields' => $fields,
'definitiveID' => $definitiveID));
$numSubmitted=0;
$reponse=$db->query('SELECT * FROM submits');
while ($data = $reponse->fetch())
{
if($data['ID']>$numSubmitted)
{
$numSubmitted=$data['ID'];
}
}
$numSubmitted=$numSubmitted+1;
$req = $db->prepare('INSERT INTO submits(ID,AuthorID, Title, FileTitle, Summary, Type, Language, Date, Fields) VALUES(:ID,:AuthorID, :Title, :FileTitle, :Summary, :Type, :Language, :Date, :Fields)');
$req->execute(array(
'ID' => $numSubmitted,
'AuthorID' => $definitiveID,
'Title' => $_POST['originalTitle'],
'FileTitle'=>$_POST['fileTitle'],
'Summary' => $_POST['summary'],
'Type' => $_POST['type'],
'Language' => $_POST['language'],
'Date' => $_POST['date'],
'Fields' => $_POST['field']));
}
else
{
$authorlist="";
foreach ($_POST['authorID'] as $authorID)
{
$authorlist.=(string)$authorID;
$authorlist.="_";
}
$authorlist=substr($authorlist, 0, -1);
$numSubmitted=0;
$reponse=$db->query('SELECT * FROM submits');
while ($data = $reponse->fetch())
{
if($data['ID']>$numSubmitted)
{
$numSubmitted=$data['ID'];
}
}
$numSubmitted=$numSubmitted+1;
$req = $db->prepare('INSERT INTO submits(ID,AuthorID, Title, FileTitle, Summary, Type, Language, Date, Fields) VALUES(:ID,:AuthorID, :Title, :FileTitle, :Summary, :Type, :Language, :Date, :Fields)');
$req->execute(array(
'ID' => $numSubmitted,
'AuthorID' => $authorlist,
'Title' => $_POST['originalTitle'],
'FileTitle'=>$_POST['fileTitle'],
'Summary' => $_POST['summary'],
'Type' => $_POST['type'],
'Language' => $_POST['language'],
'Date' => $_POST['date'],
'Fields' => $_POST['field']));
}
move_uploaded_file($_FILES['paperSubmitted']['tmp_name'], 'submits/paper' .basename($numSubmitted) .'.pdf');
echo "<section>
<h1>Thank you for submitting a paper</h1>
<p>You can now go back <a href='operaomnia.php'>home</a>. Or whatever, you do you...</p>
</section>
<div id='space'></div>";
}
else
{
$error = 1;
}
}
else {
$error = 2;
}
}
else
{
$error = 3;
}
if (isset($error))
{
header('Location: submit.php?error='.$error);
exit();
}
?>
<?php include("footer.php"); ?>
</body>
</html>