-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmit.php
170 lines (155 loc) · 6.16 KB
/
submit.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<!--
This file contains the markup for the form_submit webpage
Authors: Hunter Ahlquist, Cesar Escalona, Aubrey Davies, Zahrah Alsamach
File: form_submit.html
Date: 1/25/2021
-->
<?php
// Turn on Error Reporting
ini_set('display_errors', 1);
error_reporting(E_ALL);
require("include/db_setup.php");
include ('include/head.html');
include ('include/php_functions.php');
?>
<body>
<?php
include('include/navbar.php');
?>
<div class="container bg-light main-form border rounded align-middle">
<?php
//about company
$companyName = $_POST['companyName'];
$category = $_POST['category'];
$website = $_POST['website'];
$about = $_POST['about'];
$areaServed = $_POST['geo'];
$keywords = $_POST['keywords'];
//geo loc
$streetAddress = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$country = $_POST['country'];
$locCombined = $streetAddress . ". " . $city . ", " . $state . ". " . $zip . ". " . $country . ".";
//public contact
$pubEmail = $_POST['pubEmail'];
$pubPhone = $_POST['pubPhone'];
//priv contact
$contactName = $_POST['privFName'] . " " . $_POST['privLName'];
$privEmail = $_POST['privEmail'];
$privPhone = $_POST['privPhone'];
//upload image
$targetDir = "images/user_upload/";
$targetFile = $targetDir . basename(hash("md5", getGUID()));
$uploadOk = true;
$imageFileType = strtolower(pathinfo($_FILES["image"]["name"],PATHINFO_EXTENSION));
$targetFile .= "." . $imageFileType;
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["image"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = true;
} else {
echo "File is not an image.";
$uploadOk = false;
}
}
if ($uploadOk) {
// Check if file already exists
if (file_exists($targetFile)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
}
if ($uploadOk){
// Check file size
if ($_FILES["image"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
}
if ($uploadOk){
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg") {
echo "Sorry, only JPG, JPEG, PNG files are allowed.";
$uploadOk = 0;
}
}
if (!$uploadOk) {
echo "Sorry, your file was not uploaded.";
} else {
if (!move_uploaded_file($_FILES["image"]["tmp_name"], $targetFile)) {
echo "Sorry, there was an error uploading your file. Codec call Otacon for tech-support, Snake!";
}
// Write to DB
$sql = "INSERT INTO " . $activeTable . " (name, image, category, tag_cloud, about, url, street, city, state, country, scale, email, phone, privName, privEmail, privPhone)
VALUES('$companyName', '$targetFile', '$category', '$keywords', '$about', '$website', '$streetAddress' , '$city', '$state', '$country', '$areaServed', '$pubEmail', '$pubPhone', '$contactName' , '$privEmail', '$privPhone');";
$success = mysqli_query($db, $sql) or die(mysqli_error($db));
$newResult = mysqli_query($db, "SELECT * FROM " . $activeTable . " ORDER BY id DESC LIMIT 1") or die(mysqli_error($db));
}
echo "
<div class=\"container text-center\"><br>
<h1 class=\"display-6\">Thank you for providing your information! An email has been sent to the Coneybeare Sustainability team for review.</h1>
<br>
<h1>Information Submitted:</h1>
<img class='img-thumbnail' width='25%' src='$targetFile'/>
<br>Company Name: <strong>$companyName</strong>
<br>Category: <strong>$category</strong>
<br>Website: <strong>$website</strong>
<br>About: <strong>$about</strong>
<br>Company hashtags: <strong>$keywords</strong>
<br>Location: <strong>$locCombined</strong>
<br>Public Email: <strong>$pubEmail</strong>
<br>Public Phone Number: <strong>$pubPhone</strong>
<h1>Point of Contact:</h1>
<br>Person to contact: <strong>$contactName</strong>
<br>Contact's Email Address: <strong>$privEmail</strong>
<br>Contact's Phone Number: <strong>$privPhone</strong>
</div>
";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
if (isset($success)){
foreach ($newResult as $row){
$appID = $row['id'];
$mailImgPreview = addScheme($_SERVER['SERVER_NAME'] . "/" . $targetFile);
$imgTagEmail = "<img width='25%' src='$mailImgPreview'/>";
$mailTemplate = "
<html>
<body>
<h1>Company Application Approval</h1>
<br>
<h1>Information Submitted:</h1>
" . $imgTagEmail . "
<br>Company Name: <strong>$companyName</strong>
<br>Category: <strong>$category</strong>
<br>Website: <strong>$website</strong>
<br>About: <strong>$about</strong>
<br>Company tags: <strong>$keywords</strong>
<br>Location: <strong>$locCombined</strong>
<br>Public Email: <strong>$pubEmail</strong>
<br>Public Phone Number: <strong>$pubPhone</strong>
<h1>Point of Contact:</h1>
<br>Person to contact: <strong>$contactName</strong>
<br>Contact's Email Address: <strong>$privEmail</strong>
<br>Contact's Phone Number: <strong>$privPhone</strong>
<br><a href='". addScheme($_SERVER['SERVER_NAME']) ."/admin.php?findID=$appID'>Login to approve or reject.</a>
</body>
</html>
";
$mailSubject = "
Application Review Request for: $companyName
";
mail($newEntryMailbox, $mailSubject, wordwrap($mailTemplate, 50), $headers);
}
}
?>
</div>
<!-- Footer of the Page -->
<?php
include ('include/footer.html');
?>
</body>
</html>