-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathequipment_log.php
executable file
·191 lines (163 loc) · 5.07 KB
/
equipment_log.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
183
184
185
186
187
188
189
190
191
<?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 `'.$table.'`';
if(!$result_table=mysql_query($sql_table,$link)){echo mysql_error();return FALSE;}
if(!$result_field=mysql_query($sql_field,$link)){echo mysql_error();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']=='equipment-log')
{
echo ' <td>
<table><tr>
<td>
<input readonly type=text name=\''.$array_table['Field'].'_'.$counter.'\' value=\''.$array_field['equipment-log'].'\'>
</td>
<td><font size=0>
[Acceptable:'.$array_field['acceptable'].']
</font>
</td>
</tr></table>
</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]=='equipment-log' && strlen($post['observation_'.$tkn[1]])>0)
{
$insert_str=' insert into `equipment-log-monitor` (`equipment-log`,time,observation,observer,comment) values(
\''.$post['equipment-log_'.$tkn[1]].'\',
\''.$post['time_'.$tkn[1]].'\',
\''.$post['observation_'.$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 `equipment-log`';
if(!$result_field=mysql_query($sql_field,$link)){echo mysql_error();return FALSE;}
while($array_field=mysql_fetch_assoc($result_field))
{
$sql_table='select * from `equipment-log-monitor` where `equipment-log`=\''.$array_field['equipment-log'].'\' and time like \''.$time_str.'\'';
//echo $sql_table;
if(!$result_table=mysql_query($sql_table,$link)){echo mysql_error();}
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>equipment log chart</th></tr>';
echo '<tr><th bgcolor=lightblue colspan=10>'.$array_field['equipment-log'].'</th></th></tr><tr></tr></th><th bgcolor=lightpink>Period:</th><th bgcolor=lightpink colspan=2>'.$time_str.'</th></tr>';
echo '<tr><th bgcolor=lightgreen colspan=10>Acceptable: '.$array_field['acceptable'].'</th></tr><tr><th colspan=5 bgcolor=lightblue>'.$array_field['contract'].':'.$array_field['start'].' to '.$array_field['end'].'</th></tr>';
foreach($array_table as $key=>$value)
{
if($key!='equipment-log')
{
echo '<th>'.$key.'</th>';
}
}
echo '</tr>';
if(!$result_table=mysql_query($sql_table,$link)){echo mysql_error();}
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!='equipment-log')
{
echo '<td>'.$value.'</td>';
}
}
echo '</tr>';
}
echo '</table>';
echo '<h2 style="page-break-before: always;"></h2>';
}
}
}
main_menu();
mk_form_from_table('equipment-log','equipment-log-monitor');
echo '<form method=post>';
echo 'Show equipment log 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')
{
//echo $_POST['year'].'-'.$_POST['month'].'-%';
show_refrigerator($_POST['year'].'-'.$_POST['month'].'-%');
}
else
{
//echo '3333';
show_refrigerator(strftime('%Y-%m-%%'));
}
}
else
{
//echo '3333';
show_refrigerator(strftime('%Y-%m-%%'));
}
?>