This repository has been archived by the owner on Oct 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadd_weatherdata2.php
executable file
·129 lines (106 loc) · 3.23 KB
/
add_weatherdata2.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
<?php
session_start();
require("include/functions.php");
$config_file = 'config.php';
if (file_exists($config_file)) {
require("config.php");
} else {
header("Location: error.php?e=config");
die();
}
require("include/apply_config.php");
$force_admin = TRUE;
require("include/check_admin.php");
$WeatherSiteID=filter_var($_POST["WeatherSiteID"], FILTER_SANITIZE_NUMBER_INT);
$commadata=$_POST["commadata"];
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
<head>
<title>$app_custom_name - Add weather data</title>";
require("include/get_css.php");
require("include/get_jqueryui.php");
if ($use_googleanalytics){
echo $googleanalytics_code;
}
#Execute custom code for head, if set
if (is_file("$absolute_dir/customhead.php")) {
include("customhead.php");
}
?>
</head>
<body>
<!--Blueprint container-->
<div class="container">
<?php
require("include/topbar.php");
?>
<div class="span-24 last">
<hr noshade>
</div>
<div class="span-24 last">
</div>
<div class="span-24 last">
<?php
echo "<h3>Add weather data</h3>";
$commadata=explode("\n", $commadata);
$commadata_count=count($commadata);
$file_errors=0;
for ($i=0;$i<$commadata_count;$i++){
$this_row=$commadata[$i];
$this_row1=explode("," , $this_row);
$j=$i+1;
#Check that the number of fields match
$this_row_counter=count($this_row1);
if ($this_row_counter!=10){
echo "<div class=\"error\">The number of fields ($this_row_counter) in line $j does not match the number of fields to import (10). Empty fields can be designated as \"NULL\". Please go back and try again.</div><br><br>";
die();
}
}
### All checks passed
$success_counter=0;
for ($k=0;$k<$commadata_count;$k++){
$this_row=$commadata[$k];
$this_row=filter_var($this_row, FILTER_SANITIZE_STRING);
$this_row_imploded="";
$this_row_exploded=explode(",", $this_row);
$this_file=$this_row_exploded[0];
for ($t=0;$t<1;$t++){
$this_value=trim($this_row_exploded[$t]);
if ($this_value=="NULL"||$this_value==""){
$this_row_imploded="NULL";
}
else{
$this_row_imploded="'$this_value'";
}
}
for ($t=1;$t<count($this_row_exploded);$t++){
$this_value=trim($this_row_exploded[$t]);
if ($this_value=="NULL"||$this_value==""){
$this_row_imploded=$this_row_imploded . ",NULL";
}
else{
$this_row_imploded=$this_row_imploded . ",'$this_value'";
}
}
#Insert to MySQL
$query_to_insert="INSERT INTO WeatherData (WeatherSiteID, WeatherDate, WeatherTime, Temperature, Precipitation, RelativeHumidity, DewPoint, WindSpeed, WindDirection, LightIntensity, BarometricPressure) VALUES ('$WeatherSiteID',$this_row_imploded);";
$result = mysqli_query($connection, $query_to_insert)
or die (mysqli_error($connection));
$success_counter+=1;
}
echo "<br><div class=\"success\">$success_counter data points were addedd successfully to the database.</div>
<p><a href=\"admin.php?t=6\">Return to the admin page</a>.";
?>
</div>
<div class="span-24 last">
</div>
<div class="span-24 last">
<?php
require("include/bottom.php");
?>
</div>
</div>
</body>
</html>