/
mobile-application.php
144 lines (117 loc) · 4.84 KB
/
mobile-application.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
<?php
date_default_timezone_set('UTC');
session_start();
// Create connection
$con=mysqli_connect("analytics.carvertise.com","macnag","penguinads!","penguinads_drivers");
$Statecon= mysqli_connect("analytics.carvertise.com", "stak_scott", "t87565342","carvertise_analytics");
$driverID = -1;
if (isset($_POST['first_name'])
&&isset($_POST['last_name'])
&&isset($_POST['phone'])
&&isset($_POST['email'])
&&isset($_POST['year'])
&&isset($_POST['make'])
&&isset($_POST['model'])
&&isset($_POST['color'])
&&isset($_POST['condition'])
&&isset($_POST['work_city'])
&&isset($_POST['work_zip'])
&&isset($_POST['home_city'])
&&isset($_POST['home_zip'])
&&isset($_POST['avg'])
&&isset($_POST['avg_weekend'])) {
$first_name = mysqli_real_escape_string($con,$_POST['first_name']);
$last_name = mysqli_real_escape_string($con,$_POST['last_name']);
$phone = mysqli_real_escape_string($con,$_POST['phone']);
$email= mysqli_real_escape_string($con,$_POST['email']);
$year= mysqli_real_escape_string($con,$_POST['year']);
$make= mysqli_real_escape_string($con,$_POST['make']);
$model= mysqli_real_escape_string($con,$_POST['model']);
$color= mysqli_real_escape_string($con,$_POST['color']);
$condition= mysqli_real_escape_string($con,$_POST['condition']);
$work_city = mysqli_real_escape_string($con,$_POST['work_city']);
$work_zip = mysqli_real_escape_string($con,$_POST['work_zip']);
$home_city = mysqli_real_escape_string($con,$_POST['home_city']);
$home_zip = mysqli_real_escape_string($con,$_POST['home_zip']);
$avg= mysqli_real_escape_string($con,$_POST['avg']);
$avg_weekend= mysqli_real_escape_string($con,$_POST['avg_weekend']);
$comments = mysqli_real_escape_string($con,$_POST['comments']);
$_SESSION['firstName'] = mysqli_real_escape_string($con,$first_name);
$_SESSION['email'] = mysqli_real_escape_string($con,$email);
$date = date("m/d/Y H:i:s");
// $sql="INSERT INTO DriverInfo (FirstName, LastName, Email, Phone, Referral,Referral_Person, dateSubmitted)
// VALUES ('$first_name', '$last_name', '$email', '$phone', NULL,NULL, '$date')";
$getWorkState = mysqli_query($Statecon,"SELECT * FROM zipcode WHERE zip = '$work_zip'");
//$setWorkState = mysqli_fetch_array($getWorkState);
while($row = mysqli_fetch_array($getWorkState))
{
$workState=$row['state'];
}
$getHomeState = mysqli_query($Statecon,"SELECT * FROM zipcode WHERE zip = '$home_zip'");
//$setWorkState = mysqli_fetch_array($getWorkState);
while($row = mysqli_fetch_array($getHomeState))
{
$homeState=$row['state'];
}
//avgmonthly = (weekday miles * 22) + (weekend miles * 4.3)
$avgMonthlyMiles = $avg*22 + $avg_weekend*4.3;
$sql="INSERT INTO DriverInfo (FirstName, LastName, Email, Phone, dateSubmitted, HomeState, WorkState)
VALUES ('$first_name', '$last_name', '$email', '$phone', '$date', '$homeState','$workState')";
error_log ($sql, 3, 'mobile_bug.txt');
if (!mysqli_query($con,$sql))
{
error_log ('Error: '.mysqli_error($con), 3, 'mobile_bug.txt');
die('Error: ' . mysqli_error($con));
}
else
{
$driverID = mysqli_insert_id($con);
$sql="INSERT INTO DriverHabits (DriverID, Home_Zip, Home_City, Work_Zip, Work_City, Avg_Weekday_Miles,Avg_Weekend_Miles, Avg_Monthly_Miles,Comments, Home_State, Work_State)
VALUES ($driverID,'$home_zip', '$home_city','$work_zip', '$work_city', '$avg', $avg_weekend, $avgMonthlyMiles,'$comments','$homeState', '$workState')";
error_log ($sql, 3, 'mobile_bug.txt');
if (!mysqli_query($con,$sql))
{
error_log ('Error: '.mysqli_error($con), 3, 'mobile_bug.txt');
echo $sql;
die('Error: ' . mysqli_error($con));
}
else
{
$sql="INSERT INTO VehicleInfo (DriverID,Year, Make, Model, Color,Current_Condition)
VALUES ($driverID,$year, '$make', '$model', '$color', '$condition')";
error_log ($sql, 3, 'mobile_bug.txt');
if (!mysqli_query($con,$sql))
{
error_log ('Error: '.mysqli_error($con), 3, 'mobile_bug.txt');
die('Error: ' . mysqli_error($con));
}
else
{
sendConfirmationEmail();
echo "succeed";
}
}
}
}
function sendConfirmationEmail(){
$firstName = $_SESSION['firstName'];
$email = $_SESSION['email'];
//recipient - change this to your name and email
$to = $email;
//sender
$from = '<breyla@carvertise.com>';
//subject and the html message
$subject = 'Thanks For Signing up!';
$headers = "From: " . strip_tags('breyla@carvertise.com') . "\r\n";
$headers .= "Reply-To: ". strip_tags('breyla@carvertise.com') . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = file_get_contents('admin/email_template.html');
//Insert Users name into email
$message = str_replace('{{name}}', $firstName, $message);
//send the mail
//$result = sendmail($to, $subject, $message, $from);
$result = mail($to, $subject, $message,$headers);
}
mysqli_close($con);
?>