-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.php
executable file
·159 lines (159 loc) · 6.53 KB
/
config.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
<?PHP
include 'db.php';
if(isset($_GET['action'])){
$action = $_GET['action'];
$a = mysql_fetch_assoc(mysql_query("SELECT * FROM config"));
if($action == "start_clock"){
if($a[time] == "0000-00-00 00:00:00"){
mysql_query("UPDATE config SET time = CURRENT_TIMESTAMP, time_status = 1, time_stopped_at = '0000-00-00 00:00:00'");
}else if($a[time_stopped_at] != "0000-00-00 00:00:00"){
$now = date("U");
$last_start = strtotime($a[time]);
$stopped_at = strtotime($a[time_stopped_at]);
$new_date = date("Y-m-d H:i:s", $last_start+($now-$stopped_at));
mysql_query("UPDATE config SET time_status = 1, time_stopped_at = '0000-00-00 00:00:00', time = '".$new_date."'");
}else{
mysql_query("UPDATE config SET time_status = 1, time_stopped_at = '0000-00-00 00:00:00'");
}
}else if($action == "stop_clock"){
if($a[time] != "0000-00-00 00:00:00"){
mysql_query("UPDATE config SET time_status = 0, time_stopped_at = CURRENT_TIMESTAMP");
}
}else if($action == "reset_clock"){
mysql_query("UPDATE config SET time_status = 0, time_stopped_at = '0000-00-00 00:00:00', time = '0000-00-00 00:00:00'");
mysql_query("UPDATE laps SET time = NULL");
mysql_query("UPDATE realcps SET visited = 0, visited_at = '0000-00-00 00:00:00'");
}
return;
}
if(isset($_GET['emptylog'])){
mysql_query("TRUNCATE table log");
}
?>
<html>
<head>
<title>Config eco</title>
</head>
<body>
<?php
include 'db.php';
if(isset($_POST[config])){
foreach($_POST[config] as $key => $val){
mysql_query("UPDATE config SET ".$key." = '".$val."'");
}
}
if(isset($_POST[laps])){
foreach($_POST[laps] as $key => $val){
mysql_query("UPDATE laps SET planned_time = ".$val." WHERE id = ".$key);
}
}
if(isset($_POST[sensor])){
foreach($_POST[sensor] as $key => $val){
foreach($_POST[sensor][$key] as $n => $name){
mysql_query("UPDATE type_sensor SET name='".$name[0]."', min =".$name[1].", max=".$name[2]." WHERE n = ".$n." AND type_id = ".$key);
}
}
}
$config = mysql_query("SELECT * FROM config");
//mysql_query("INSERT INTO config VALUES('http://org.ntnu.no/eitecov11/values2.php', NULL)");
$config = mysql_fetch_assoc($config);
$laps = mysql_query("SELECT * FROM laps");
?>
<form method="get">
<input type="submit" value="Empty log" name="emptylog">
</form>
<form method="post">
<div style="float:left">
<h3>Edit sensor names:</h3>
<table >
<tr><th colspan="2">Cell voltages:</th></tr>
<tr><td>#</td><td>Text</td><td>Min</td><td>Max</td></tr>
<?PHP
$names = mysql_query("SELECT * FROM type_sensor WHERE type_id = 0");
while($name = mysql_fetch_assoc($names)){
echo "<tr>";
echo "<td>".$name[n]."</td><td><input type=\"text\" name=\"sensor[".$name[type_id]."][".$name[n]."][0]\" value=\"".$name[name]."\" size=8></td>";
echo "<td><input type=\"text\" name=\"sensor[".$name[type_id]."][".$name[n]."][1]\" value=\"".$name[min]."\" size=2></td>";
echo "<td><input type=\"text\" name=\"sensor[".$name[type_id]."][".$name[n]."][2]\" value=\"".$name[max]."\" size=2></td>";
echo "</tr>";
}
?>
</table>
</div>
<div style="float:left">
<h3> </h3>
<table>
<tr><th colspan="2">Sum Cell Voltage:</th></tr>
<tr><td>#</td><td>Text</td><td>Min</td><td>Max</td></tr>
<?PHP
$names = mysql_query("SELECT * FROM type_sensor WHERE type_id = 1");
while($name = mysql_fetch_assoc($names)){
echo "<tr>";
echo "<td>".$name[n]."</td><td><input type=\"text\" name=\"sensor[".$name[type_id]."][".$name[n]."][0]\" value=\"".$name[name]."\" size=8></td>";
echo "<td><input type=\"text\" name=\"sensor[".$name[type_id]."][".$name[n]."][1]\" value=\"".$name[min]."\" size=2></td>";
echo "<td><input type=\"text\" name=\"sensor[".$name[type_id]."][".$name[n]."][2]\" value=\"".$name[max]."\" size=2></td>";
echo "</tr>";
}
?>
<tr><th colspan="2">Temperature:</th></tr>
<tr><td>#</td><td>Text</td><td>Min</td><td>Max</td></tr>
<?PHP
$names = mysql_query("SELECT * FROM type_sensor WHERE type_id = 2");
while($name = mysql_fetch_assoc($names)){
echo "<tr>";
echo "<td>".$name[n]."</td><td><input type=\"text\" name=\"sensor[".$name[type_id]."][".$name[n]."][0]\" value=\"".$name[name]."\" size=8></td>";
echo "<td><input type=\"text\" name=\"sensor[".$name[type_id]."][".$name[n]."][1]\" value=\"".$name[min]."\" size=2></td>";
echo "<td><input type=\"text\" name=\"sensor[".$name[type_id]."][".$name[n]."][2]\" value=\"".$name[max]."\" size=2></td>";
echo "</tr>";
}
?>
<tr><th colspan="2">Pressure:</th></tr>
<tr><td>#</td><td>Text</td><td>Min</td><td>Max</td></tr>
<?PHP
$names = mysql_query("SELECT * FROM type_sensor WHERE type_id = 3");
while($name = mysql_fetch_assoc($names)){
echo "<tr>";
echo "<td>".$name[n]."</td><td><input type=\"text\" name=\"sensor[".$name[type_id]."][".$name[n]."][0]\" value=\"".$name[name]."\" size=8></td>";
echo "<td><input type=\"text\" name=\"sensor[".$name[type_id]."][".$name[n]."][1]\" value=\"".$name[min]."\" size=2></td>";
echo "<td><input type=\"text\" name=\"sensor[".$name[type_id]."][".$name[n]."][2]\" value=\"".$name[max]."\" size=2></td>";
echo "</tr>";
}
?>
<tr><th colspan="2">Output:</th></tr>
<tr><td>#</td><td>Text</td><td>Min</td><td>Max</td></tr>
<?PHP
$names = mysql_query("SELECT * FROM type_sensor WHERE type_id = 4");
while($name = mysql_fetch_assoc($names)){
echo "<tr>";
echo "<td>".$name[n]."</td><td><input type=\"text\" name=\"sensor[".$name[type_id]."][".$name[n]."][0]\" value=\"".$name[name]."\" size=8></td>";
echo "<td><input type=\"text\" name=\"sensor[".$name[type_id]."][".$name[n]."][1]\" value=\"".$name[min]."\" size=2></td>";
echo "<td><input type=\"text\" name=\"sensor[".$name[type_id]."][".$name[n]."][2]\" value=\"".$name[max]."\" size=2></td>";
echo "</tr>";
}
?>
</table>
</div>
<div style="float:left">
<h3>Other stuff:</h3>
<table>
<tr>
<td>Adress:</td>
<td><input type="text" name="config[adress_for_data]" value="<?PHP echo $config[adress_for_data];?>"></td>
</tr>
</table>
<table>
<tr><th>Lap #</th><th>Planned time (in seconds)</th></tr>
<?PHP
while($l = mysql_fetch_assoc($laps)){
?>
<tr><td><?PHP echo $l[id];?></td><td><input type="text" name="laps[<?PHP echo $l[id];?>]" value="<?PHP echo $l[planned_time];?>"></td></tr>
<?PHP
}
?>
<tr><td colspan=2><input type="submit" value="Save"></td></tr>
</table>
</div>
</form>
</body>
</html>
<?PHP mysql_close($conn);?>