-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrefrigerator_temperature.php
executable file
·181 lines (149 loc) · 4.61 KB
/
refrigerator_temperature.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
<?php
session_start();
echo '<html>';
echo '<head>';
echo '</head>';
echo '<body>';
//audit data: ip,user,database,table,primary-key,what: trigger
//cron: delete everyday- data of >30 days old
/*
echo '<pre>';
print_r($GLOBALS);
echo '</pre>';
*/
include 'common.php';
function mk_form_from_table($field,$table)
{
$link=start_nchsls();
$sql_field='select * from '.$field;
$sql_table='desc refrigerator_temperature';
if(!$result_table=mysql_query($sql_table,$link)){return FALSE;}
if(!$result_field=mysql_query($sql_field,$link)){return FALSE;}
echo '<table border=1><form method=post>';
echo '<tr>';
while($array_table=mysql_fetch_assoc($result_table))
{
echo '<th>'.$array_table['Field'].'</th>';
}
echo '</tr>';
$counter=1;
while($array_field=mysql_fetch_assoc($result_field))
{
echo '<tr>';
if(!$result_table=mysql_query($sql_table,$link)){return FALSE;}
while($array_table=mysql_fetch_assoc($result_table))
{
if($array_table['Field']=='refrigerator')
{
echo '<td><input readonly type=text name=\''.$array_table['Field'].'_'.$counter.'\' value=\''.$array_field['refrigerator'].'\'> [Target \'C:'.$array_field['low_target'].'-'.$array_field['high_target'].']</td>';
}
elseif($array_table['Field']=='time')
{
echo '<td><input type=text name=\''.$array_table['Field'].'_'.$counter.'\' value=\''.strftime('%Y-%m-%d %H:%M').'\'></td>';
}
elseif($array_table['Field']=='observer')
{
echo '<td><input type=text name=\''.$array_table['Field'].'_'.$counter.'\' value=\''.$_SESSION['login'].'\'></td>';
}
else
{
echo '<td><input type=text name=\''.$array_table['Field'].'_'.$counter.'\'></td>';
}
}
echo '</tr>';$counter++;
}
echo '<input type=submit name=submit value=save>';
echo '</form></table>';
return TRUE;
}
function save_temperature($post)
{
foreach($post as $key=>$value)
{
$tkn=explode('_',$key);
//echo $tkn[1];
if($tkn[0]=='refrigerator' && strlen($post['temperature_'.$tkn[1]])>0)
{
$insert_str=' insert into refrigerator_temperature (refrigerator,time,temperature,observer,comment) values(
\''.$post['refrigerator_'.$tkn[1]].'\',
\''.$post['time_'.$tkn[1]].'\',
\''.$post['temperature_'.$tkn[1]].'\',
\''.$post['observer_'.$tkn[1]].'\',
\''.$post['comment_'.$tkn[1]].'\')';
//echo $insert_str.'<br>';
$link=start_nchsls();
mysql_query($insert_str,$link);
}
}
}
if(!login_varify())
{
exit();
}
function show_refrigerator($time_str)
{
$link=start_nchsls();
$sql_field='select * from refrigerator';
if(!$result_field=mysql_query($sql_field,$link)){return FALSE;}
while($array_field=mysql_fetch_assoc($result_field))
{
$sql_table='select * from refrigerator_temperature where refrigerator=\''.$array_field['refrigerator'].'\' and time like \''.$time_str.'\'';
if(!$result_table=mysql_query($sql_table,$link)){}
if(mysql_num_rows($result_table)>=1)
{
$array_table=mysql_fetch_assoc($result_table);
echo '<table border=1>';
echo '<tr><th colspan=10 bgcolor=lightgreen>Refrigerator temperature chart</th></tr>';
echo '<tr><th colspan=10 bgcolor=lightblue>'.$array_field['refrigerator'].'</th></tr>';
echo '<tr><th bgcolor=lightgreen>Target:'.$array_field['low_target'].'-'.$array_field['high_target'].'</th><th bgcolor=lightpink>Period:</th><th bgcolor=lightpink>'.$time_str.'</th></tr>';
foreach($array_table as $key=>$value)
{
if($key!='refrigerator')
{
echo '<th>'.$key.'</th>';
}
}
echo '</tr>';
if(!$result_table=mysql_query($sql_table,$link)){}
if(mysql_num_rows($result_table)<1){echo mysql_error();}
while($array_table=mysql_fetch_assoc($result_table))
{
echo '<tr>';
foreach($array_table as $key=>$value)
{
if($key!='refrigerator')
{
echo '<td>'.$value.'</td>';
}
}
echo '</tr>';
}
echo '</table>';
echo '<h2 style="page-break-before: always;"></h2>';
}
}
}
main_menu();
mk_form_from_table('refrigerator','refrigerator_temperature');
echo '<form method=post>';
echo 'Show temperature chart of following year and month';
read_date_time(2);
echo '<input type=submit name=submit value=show>';
echo '</form>';
save_temperature($_POST);
if(isset($_POST['submit']))
{
if($_POST['submit']=='show')
{
show_refrigerator($_POST['year'].'-'.$_POST['month'].'-%');
}
else
{
show_refrigerator(strftime('%Y-%m-%%'));
}
}
else
{
show_refrigerator(strftime('%Y-%m-%%'));
}
?>