-
Notifications
You must be signed in to change notification settings - Fork 0
/
createEvent.php
147 lines (113 loc) · 5.06 KB
/
createEvent.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
<html>
<body>
<?php
session_start();
?>
<form name="riders" method=POST action=createEvent.php>
<div id="test">
<p>Date of Event:</p>
<input type=text placeholder="Enter date for event" name="date">
<br></br>
<p>Destination:</p>
<input type=text placeholder="Address of event" name="destination">
<br></br>
</div>
<div id="users">
<p>Friend's Username:</p>
<input type=text placeholder="Username" name="name" id=input>
<br></br>
<input type='button' value="Add" onclick='processWritein()'>
<br></br>
<input type='button' value="Create Event" onclick='finalize()'>
</div>
</form>
<script>
nameArray = [];
dbReady = [];
function processData() {
var httpRequest;
var name = arguments[0]; // get name of friend
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
//alert('XMLHttpRequest');
httpRequest = new XMLHttpRequest();
if (httpRequest.overrideMimeType) {
httpRequest.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) { // Older versions of IE
//alert('IE -- XMLHTTP');
try {
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!httpRequest) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
// Set data to submit to server, based on the type of the action
var data;
data = 'name=' + name;
// I have used POST here because GET requests may be cached. For more
// details about this problem, see:
// http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp
// Note that for POST, the Content-Type must be set accordingly
httpRequest.open('POST', 'checkFriend.php', true);
httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
/*send the name of the friend to a showUser function which will check the user's name against the database and if it is true then the friend will be displayed underneath their car*/
httpRequest.onreadystatechange = function () {
showUser(httpRequest, name);
};
httpRequest.send(data);
}
//function that happens on click but i'm not sure this is really needed as a separate function??
function processWritein() {
var name = document.riders.name.value;
var date = document.riders.date.value;
var destination = document.riders.destination.value;
dbReady.push(date);
dbReady.push(destination);
nameArray.push(name);
processData(name);
}
function showUser(httpRequest, name) {
if (httpRequest.readyState == 4) {
if (httpRequest.status == 200) {
test = document.getElementById("test");
test.style.display = 'none';
var confirmed = httpRequest.responseText;
}
}
}
function finalize() {
var httpRequest2
if (window.XMLHttpRequest) {
httpRequest2 = new XMLHttpRequest();
if (httpRequest2.overrideMimeType) {
httpRequest2.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) {
try {
httpRequest2 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
httpRequest2 = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!httpRequest2) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
var pushThis;
pushThis = 'names=' + this.nameArray + '&rest=' + this.dbReady;
httpRequest2.open('POST', 'finalize.php', true);
httpRequest2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
httpRequest2.send(pushThis);
window.location = "/HackPrinceton/views/index.php";
}
</script>
</body>
</html>