forked from eckama11/air_quality
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Data.php
182 lines (164 loc) · 6.94 KB
/
Data.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
171
172
173
174
175
176
177
178
179
180
181
182
<?php
require_once("common.php");
if (!isset($loginSession))
doUnauthenticatedRedirect();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="<?php echo htmlentities(BASE_URL); ?>">
<title>Login</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- StyleSheet -->
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/custom.css" />
<style>
input { max-width: 100%; }
</style>
<script>
function requiredField(elem, errorMsg) {
var rv = elem.val();
if (rv == "") {
elem.tooltip("destroy")
.addClass("error")
.data("title", errorMsg)
.tooltip();
} else {
elem.tooltip("destroy")
.removeClass("error")
.data("title", "");
}
return rv;
}
function showError(message) {
$("#message").text(message);
$("#messageAlert").show().delay(3000).fadeOut("slow");
}
function addData(form) {
var id = requiredField($(form.elements.id), "You must enter an id");
var imp = requiredField($(form.elements.imp), "You must enter an imp");
var time = requiredField($(form.elements.time), "You must enter a time");
var temp = requiredField($(form.elements.newTemp), "You must enter an temperature");
var humidity = requiredField($(form.elements.newHum), "You must enter an humidity");
var pressure = requiredField($(form.elements.pressure), "You must enter a pressure");
var altitude = requiredField($(form.elements.altitude), "You must enter a altitude");
var latitude = requiredField($(form.elements.latitude), "You must enter a latitude");
var longitude = requiredField($(form.elements.longitude), "You must enter a longitude");
var particles = requiredField($(form.elements.particles), "You must enter a particles");
if ((id == "") || (imp == "") || (time == "") || (temp == "") || (humidity == "")
|| (pressure == "") || (altitude == "") || (latitude == "") || (longitude == "") || (particles == "")) {
showError("You must enter id, imp, time, temp, humidity, pressure, altitude, latitude, longitude, particles information.");
return false;
}
$("#loginDiv").hide();
$("#spinner").show();
$.ajax({
"type" : "POST",
"url" : "doData.php",
"data" : $(form).serialize(),
"dataType" : "json"
})
.done(function(data) {
$("#spinner").hide();
if (data.error != null) {
showError(data.error);
$("#content").show();
} else
$("#successDiv").show();
})
.fail(function( jqXHR, textStatus, errorThrown ) {
console.log("Error: "+ textStatus +" (errorThrown="+ errorThrown +")");
console.log(jqXHR);
$("#spinner").hide();
$("#loginDiv").show();
showError("Request failed, unable to add data: "+ errorThrown);
})
return false;
} // doLogin
</script>
</head>
<body>
<div id="messageAlert" class="alert alert-danger" style="display:none;position:fixed;left:20px;right:20px">
<span id="message"></span>
</div>
<div class="container padded">
<div class="row" >
<div id="spinner" class="col-md-2 col-md-offset-5" style="padding-bottom:10px;text-align:center;display:none">
<div style="color:black;padding-bottom:32px;">Adding reading to our Records...</div>
<img src="spinner.gif">
</div>
<div id="successDiv" style="padding:10px; outline:10px solid black; display:none">
Your reading has been added. Thank you.
</div>
<div id="dataDiv" class="col-md-3 col-md-offset-5" style="padding-bottom:10px; outline: 10px solid black;">
<form class="form-horizontal" method="post" onsubmit="return addData(this)">
<fieldset>
<legend style="color:black;">Add Reading</legend>
<div class="control-group">
<label class="control-label" for="id">Id</label>
<div class="controls">
<input name="id" maxlength="50" placeholder="Enter your id..." type="text" class="form-control" id="id" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="imp">Imp</label>
<div class="controls">
<input name="imp" maxlength="50" placeholder="Enter an imp..." type="text" class="form-control" id="imp" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="newTemp">Temperature</label>
<div class="controls">
<input name="newTemp" maxlength="50" placeholder="Enter a temperature..." type="text" class="form-control" id="newTemp" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="newHum">Humidity</label>
<div class="controls">
<input name="newHum" maxlength="50" placeholder="Enter a humidity..." type="text" class="form-control" id="newHum" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="pressureA">Pressure</label>
<div class="controls">
<input name="pressureA" maxlength="50" placeholder="Enter a pressure..." type="text" class="form-control" id="pressureA" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="altitude">Altitude</label>
<div class="controls">
<input name="altitude" maxlength="50" placeholder="Enter your altitude..." type="text" class="form-control" id="altitude" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="latitude">Latitude</label>
<div class="controls">
<input name="latitude" maxlength="50" placeholder="Enter your latitude..." type="text" class="form-control" id="latitude" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="longitude">Longitude</label>
<div class="controls">
<input name="longitude" maxlength="50" placeholder="Enter your longitide..." type="text" class="form-control" id="longitude" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="particles">Particles</label>
<div class="controls">
<input name="particles" maxlength="50" placeholder="Enter your particles..." type="text" class="form-control" id="particles" />
</div>
</div>
</br>
<div>
<button type="submit" class="btn btn-default">Submit</button>
</div>
</fieldset>
</form>
</div>
</div>
</div>
<!-- JavaScript -->
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="js/bootstrap.js"></script>
</body>
</html>