This repository has been archived by the owner on Jun 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
submit-volunteer.php
139 lines (123 loc) · 3.67 KB
/
submit-volunteer.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
<?php
include('include/Database.inc.php');
include('include/Mail.inc.php');
include('include/autoresponse.inc.php');;
$firstname = $_POST['firstname'];
$middlename = $_POST['middlename'];
$lastname = $_POST['lastname'];
$organization = $_POST['organization'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$street = $_POST['street'];
//$street2 = $_POST['street2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
//$group_number = $_POST['group-number'];
//$group_age = $_POST['group-age'];
//$group_availability = $_POST['group-avail'];
//$group_note = $_POST['group-notes'];
if(!ISSET($_POST['source']))
$source = 1; // Default to "Others"
else
$source = $_POST['source'];
$comments = $_POST['comments'];
$errorMessage = "";
if(empty($firstname)) {
$errorMessage .= "<li>No First Name!</li>";
}
if(empty($middlename)) {
$middlename = "";
}
if(empty($lastname)) {
$errorMessage .= "<li>No Last Name!</li>";
}
if(empty($email)) {
$errorMessage .= "<li>No Email!</li>";
}
if(empty($phone)) {
$errorMessage .= "<li>Phone number required!</li>";
} else {
$phone = preg_replace('/\D/', '', $phone); // strip out all chars except numbers
if (strlen($phone) != 10)
$errorMessage .= '<li>Phone number must be exactly 10 numbers!</li>';
else
$phone = '(' . substr($phone, 0, 3) . ') ' . substr($phone, 3, 3) . '-' . substr($phone, 6, 4); // (949) 555-1234
}
if(empty($street)) {
$street = "";
}
if(empty($city)) {
$errorMessage .= "<li>City required!</li>";
}
if(empty($state)) {
$errorMessage .= "<li>State required!</li>";
}
if(empty($zip)) {
$errorMessage .= "<li>Zip code required!</li>";
}
if(!is_numeric($zip) || strlen($zip) != 5) {
$errorMessage .= "<li>Zip code must be 5 numbers!</li>";
}
if(!empty($errorMessage)) {
die($errorMessage);
}
$r = $db->startTransaction();
if (!$r->isValid())
die('Transaction could not start.');
$sql = "INSERT INTO volunteers (first_name, middle_name, last_name, organization, phone, email, street, city, state, zip, notes, source_id, signed_up)
VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s',CURDATE()); ";
$inputs = array($firstname, $middlename, $lastname, $organization, $phone, $email, $street, $city, $state, $zip, $comments, $source);
$r = $db->q($sql, $inputs);
echo($db->error());
if (!$r->isValid()) {
echo $db->error();
}
$volunteerID = $db->getInsertId();
if(!empty($_POST['roles']))
{
foreach($_POST['roles'] as $role) {
$sql = "INSERT INTO volunteer_roles (volunteer_id, volunteer_type_id) VALUES ('%s', '%s');";
$inputs = array($volunteerID, $role);
$r = $db->q($sql, $inputs);
if (!$r->isValid()) {
echo $db->error();
$r = $db->rollback();
if ($r->isValid())
echo 'Rollback succeeded!';
else
echo 'Rollback failed!';
}
}
}
if(!empty($_POST['days']))
{
foreach($_POST['days'] as $day) {
$sql = "INSERT INTO volunteer_prefers (volunteer_id, day_id) VALUES ('%s', '%s');";
$inputs = array($volunteerID, $day);
$r = $db->q($sql, $inputs);
if (!$r->isValid()) {
echo $db->error();
$r = $db->rollback();
if ($r->isValid())
echo 'Rollback succeeded!';
else
echo 'Rollback failed!';
}
}
}
$r = $db->commit();
if ($r->isValid()) {
$sent = $mail->send('Registration Confirmed', volunteerResponse($firstname, $lastname), $email);
echo "$firstname $lastname, Thank you for registering!";
if ($sent)
echo "<br/>An email has been sent to: $email";
} else {
echo 'Failed to commit transaction. Attempting to rollback...';
$r = $db->rollback();
if ($r->isValid())
echo 'Rollback succeeded!';
else
echo 'Rollback failed!';
}
?>