-
Notifications
You must be signed in to change notification settings - Fork 0
/
converti15.php
340 lines (329 loc) · 13.2 KB
/
converti15.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?php
include("config/local.php");
$i = mysql_connect ($mysql_host,$mysql_user,$mysql_password); $e=mysql_select_db ($mysql_db_name);
$query = "set character_set_client='cp1251'"; mysql_query ($query,$i);
$query = "set character_set_results='cp1251'"; mysql_query ($query,$i);
$query = "set collation_connection='cp1251_general_ci'"; mysql_query ($query,$i);
?>
<html><head>
<title>Êîíâåðòèðóåì èç áàçû "Ýíåðãîó÷åò" â MySQL</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<meta http-equiv="Pragma" content="no-cashe">
<meta http-equiv="refresh" content="6600,http://ce-chel.info:81/converti15.php">
<link rel="stylesheet" href="files/structure_collage_ektron.css" type="text/css">
<link rel="stylesheet" href="files/default.css" title="default" type="text/css">
<link rel="alternate stylesheet" href="files/default_larger.css" title="big" type="text/css">
<link rel="stylesheet" type="text/css" href="files/niftyCorners.css">
<link rel="stylesheet" type="text/css" href="files/quotetabs.css">
</head>
<body>
<?php
$first=1;
$value=0;
$host='mau';
$username='mau';
$password='110726';
$maxcnt=250;
$dbh=odbc_connect ($host, $username, $password);
//echo $dbh;
print '<table cellpadding=2 cellspacing=1 bgcolor=#82cc7f align=center>
<tr bgcolor="#476a94"><td align="center"><font color="white">id</font></td>
<td align="center"><font color="white">Íàçâàíèå</font></td>
<td align="center"><font color="white">Ñåðèéíèê</font></td>
<td align="center"><font color="white">Îáúåêò</font></td>
<td align="center"><font color="white">Àäðåñ</font></td>
<td align="center"><font color="white">Èäåíòèôèêàòîð</font></td>
<td align="center"><font color="white">Ñòàòóñ</font></td>
<td align="center"><font color="white">Óñòàíîâëåí</font></td>
</tr>';
$query='SELECT * FROM devices WHERE type=15';
//echo $query.'<br>';
$e2 = mysql_query ($query,$i);
if ($e2) $uo = mysql_fetch_row ($e2);
while ($uo)
{
print '<tr bgcolor="#ffffff">';
print '<td>'.$uo[0].'</td>';
print '<td>'.$uo[1].'</td>';
print '<td>'.$uo[6].'</td>';
print '<td>'.$uo[8].'</td>';
print '<td>'.$uo[10].'</td>';
print '<td>'.$uo[11].'</td>';
print '<td>'.$uo[12].'</td>';
print '<td>'.$uo[14].'</td>';
print '</tr>';
$uo = mysql_fetch_row ($e2);
}
print '</table>';
print '<table cellpadding=2 cellspacing=1 bgcolor=#82cc7f align=center>
<tr bgcolor="#476a94"><td align="center"><font color="white">id</font></td>
<td align="center"><font color="white">Óñòðîéñòâî</font></td>
<td align="center"><font color="white">Íàçâàíèå</font></td>
<td align="center"><font color="white">Èäåíò</font></td>
<td align="center"><font color="white">Ê-íò òð-ð</font></td>
<td align="center"><font color="white">Àäðåñ</font></td>
<td align="center"><font color="white">Êàíàë àêò.</font></td>
<td align="center"><font color="white">Ïàðàì</font></td>
<td align="center"><font color="white">Ïîäïð</font></td>
<td align="center"><font color="white">Òåê ìåòêà</font></td>
<td align="center"><font color="white">×àñ ìåòêà</font></td>
<td align="center"><font color="white">Äåíü ìåòêà</font></td>
<td align="center"><font color="white">Ìåñÿö ìåòêà</font></td></tr>';
$query='SELECT * FROM devices WHERE type=15';
//echo $query.'<br>';
$e2 = mysql_query ($query,$i);
if ($e2)
while ($uo = mysql_fetch_row ($e2))
{
$query='SELECT * FROM channels WHERE device='.$uo[11];
$e3 = mysql_query ($query,$i);
if ($e3)
while ($ui = mysql_fetch_array($e3, MYSQL_ASSOC))
{
print '<tr bgcolor="#ffffff">';
print '<td align="center">'.$ui["id"].'</td>';
print '<td>'.$uo[1].'</td>';
print '<td>'.$ui["name"].'</td>';
print '<td>'.$ui["device"].'</td>';
print '<td align="center">'.$ui["edizm"].'</td>';
print '<td align="center">'.$ui["adr"].'</td>';
print '<td align="center">'.$ui["addr1"].'</td>';
print '<td align="center">'.$ui["prm"].'</td>';
print '<td align="center">'.$ui["pipe"].'</td>';
print '<td>'.$ui["lastcurrents"].'</td>';
print '<td>'.$ui["lasthours"].'</td>';
print '<td>'.$ui["lastdays"].'</td>';
print '<td>'.$ui["lastmonth"].'</td>';
print '</tr>';
}
}
/*
$today=getdate();
if ($today["hours"]>16) $query='SELECT * FROM devices WHERE type=15 ORDER BY id';
else if ($today["hours"]%2) $query='SELECT * FROM devices WHERE type=15 AND ust=1 AND status=0 ORDER BY id';
else $query='SELECT * FROM devices WHERE type=15 AND ust=1 ORDER BY id';
$e2 = mysql_query ($query,$i);
if (0)
if ($e2)
while ($uo = mysql_fetch_row ($e2))
{
print '<table cellpadding=2 cellspacing=1 bgcolor=#82cc7f align=center>
<tr bgcolor="#476a94"><td align="center"><font color="white">'.$uo[1].'</font></td></tr></table>
<table cellpadding=2 cellspacing=1 bgcolor=#82cc7f align=center>
<tr bgcolor="#476a94"><td align="center"><font color="white">id</font></td>
<td align="center"><font color="white">Óñòðîéñòâî</font></td>
<td align="center"><font color="white">Íàçâàíèå</font></td>
<td align="center"><font color="white">ÈÄ</font></td>
<td align="center"><font color="white">Ê-íò òð-ð</font></td>
<td align="center"><font color="white">Àäðåñ</font></td>
<td align="center"><font color="white">Êàíàë àêò.</font></td>
<td align="center"><font color="white">Êàíàë ðåàêò.</font></td>
<td align="center"><font color="white">Ïàðàìåòð</font></td>
<td align="center"><font color="white">Ïîäïàðàìåòð</font></td>
<td align="center"><font color="white">Òåê ìåòêà</font></td>
<td align="center"><font color="white">×àñ ìåòêà</font></td>
<td align="center"><font color="white">Äåíü ìåòêà</font></td>
<td align="center"><font color="white">Ìåñÿö ìåòêà</font></td></tr>';
}*/
//---------------------------------------------------------------------------------------
// days
$today=getdate();
$ye=$today["year"];
$mn=$today["mon"];
$qnt=150;
$dy=31;
if (!checkdate ($mn,31,$ye)) { $dy=30; }
if (!checkdate ($mn,30,$ye)) { $dy=29; }
if (!checkdate ($mn,29,$ye)) { $dy=28; }
$tm=$dy=$today["mday"];
for ($tn=0; $tn<=$qnt; $tn++)
{
$date2[$tn]=sprintf ("%d-%02d-%02d",$ye,$mn,$tm);
$date3[$tn]=sprintf ("%d%02d%02d000000",$ye,$mn,$tm);
echo $tn.' '.$date3[$tn].'<br>';
$data[$tn]=0;
$tm--;
if ($tm==0)
{
$mn--;
if ($mn==0) { $mn=12; $ye--; }
$dy=31;
if (!checkdate ($mn,31,$ye)) { $dy=30; }
if (!checkdate ($mn,30,$ye)) { $dy=29; }
if (!checkdate ($mn,29,$ye)) { $dy=28; }
$tm=$dy;
}
}
print '</table>';
print '<table cellpadding=2 cellspacing=1 bgcolor=#82cc7f align=center>
<tr bgcolor="#476a94"><td align="center"><font color="white">'.$uo[1].'</font></td></tr></table>
<table cellpadding=2 cellspacing=1 bgcolor=#82cc7f align=center>
<tr bgcolor="#476a94"><td align="center"><font color="white">id</font></td>
<td align="center"><font color="white">Íàçâàíèå</font></td>
<td align="center"><font color="white">Óñòðîéñòâî</font></td>
<td align="center"><font color="white">Ê-íò òð-ð</font></td>
<td align="center"><font color="white">Àäðåñ</font></td>
<td align="center"><font color="white">Êàíàë àêò.</font></td>
<td align="center"><font color="white">Ïàðàìåòð</font></td>
<td align="center"><font color="white">Ïîäïàðàìåòð</font></td>
<td align="center"><font color="white">Òåê ìåòêà</font></td>
<td align="center"><font color="white">×àñ ìåòêà</font></td>
<td align="center"><font color="white">Äåíü ìåòêà</font></td>
<td align="center"><font color="white">Ìåñÿö ìåòêà</font></td></tr>';
//---------------------------------------------------------------------------------------
if ($today["hours"]>16) $query='SELECT * FROM devices WHERE type=15 ORDER BY id DESC';
else if ($today["hours"]%2) $query='SELECT * FROM devices WHERE type=15 AND ust=1 AND status=0 ORDER BY id DESC';
else $query='SELECT * FROM devices WHERE type=15 AND ust=1 ORDER BY id';
echo $query.'<br>';
$e2 = mysql_query ($query,$i);
if ($e2)
while ($uo = mysql_fetch_row ($e2))
{
$query='SELECT * FROM channels WHERE device='.$uo[11];
echo $query.'<br>'; $cnt=0;
$e3 = mysql_query ($query,$i);
if ($e3)
while ($ui = mysql_fetch_array($e3, MYSQL_ASSOC))
{
print '<tr bgcolor="#ffffff">';
print '<td align="center">'.$ui["id"].'</td>';
print '<td>'.$ui["name"].'</td>';
print '<td>'.$ui["device"].'</td>';
print '<td align="center">'.$ui["edizm"].'</td>';
print '<td align="center">'.$ui["adr"].'</td>';
print '<td align="center">'.$ui["addr1"].'</td>';
print '<td align="center">'.$ui["prm"].'</td>';
print '<td align="center">'.$ui["pipe"].'</td>';
print '<td>'.$ui["lastcurrents"].'</td>';
print '<td>'.$ui["lasthours"].'</td>';
print '<td>'.$ui["lastdays"].'</td>';
print '<td>'.$ui["lastmonth"].'</td>';
print '</tr>';
$device=$ui["device"];
if ($ui["lastdays"]=='0000-00-00 00:00:00') $datt='20110101000000';
else $datt=$ui["lastdays"][0].$ui["lastdays"][1].$ui["lastdays"][2].$ui["lastdays"][3].$ui["lastdays"][5].$ui["lastdays"][6].$ui["lastdays"][8].$ui["lastdays"][9].'000000';
for ($tn=0; $tn<=$qnt; $tn++) $data[$tn]='-';
$today=getdate();
$datt2 = sprintf ("%d%02d%02d000000",$today["year"],$today["mon"],$today["mday"]);
$query = 'SELECT * FROM data2 WHERE date>='.$datt.' AND date<'.$datt2.' AND type=1 AND channel='.$ui["id"].' ORDER BY date DESC LIMIT 30000';
$a = mysql_query ($query,$i);
echo $query.'<br>';
if ($a)
while ($uy = mysql_fetch_row ($a))
{
$datt=$uy[2][0].$uy[2][1].$uy[2][2].$uy[2][3].$uy[2][5].$uy[2][6].$uy[2][8].$uy[2][9].'000000';
$x=$qnt+1;
for ($tn=0; $tn<=$qnt; $tn++)
if ($datt==$date3[$tn]) $x=$tn;
$data[$x]+=$uy[3]; $dats[$x]=$datt;
//echo '['.$x.'] '.$datt.' '.$data[$x].'<br>';
}
$first=1;
for ($tn=0; $tn<=$qnt; $tn++)
if ($data[$tn]!='-')
{
$query = 'SELECT * FROM data2 WHERE date='.$date3[$tn].' AND type=2 AND channel='.$ui["id"];
echo $query.'<br>';
$a = mysql_query ($query,$i);
if ($a) $uy = mysql_fetch_row ($a);
if ($uy)
{
$query = 'UPDATE data2 SET date=date,value='.$data[$tn].' WHERE date='.$date3[$tn].' AND type=2 AND channel='.$ui["id"];
$e5 = mysql_query ($query,$i);
echo $query.'<br>';
}
else
{
$query = 'INSERT INTO data2 SET value='.$data[$tn].',date='.$date3[$tn].',type=2,channel='.$ui["id"];
$e5 = mysql_query ($query,$i);
echo $query.'<br>';
if ($first && $e)
{
$query='UPDATE channels SET lastcurrents=lastcurrents,lastdays='.$dats[$tn].' WHERE id='.$ui["id"];
$e5 = mysql_query ($query,$i);
echo $query.'<br>';
}
}
$first=0;
}
}
}
//---------------------------------------------------------------------------------------
// month
$today=getdate();
$ye=$today["year"]; $qnt=6;
$tm=$today["mon"];
$cn=0;
for ($tn=0; $tn<=$qnt; $tn++)
{
$tod=31;
if (!checkdate ($tm,31,$today["year"])) { $tod=30; }
if (!checkdate ($tm,30,$today["year"])) { $tod=29; }
if (!checkdate ($tm,29,$today["year"])) { $tod=28; }
$date1[$cn]=sprintf ("%d%02d01000000",$today["year"],$tm);
$dat[$cn]=sprintf ("%d-%02d-01 00:00:00",$today["year"],$tm);
if ($tm>1) $tm--;
else { $tm=12; $today["year"]--; }
$cn++;
}
//---------------------------------------------------------------------------------------
if ($today["hours"]>16) $query='SELECT * FROM devices WHERE type=15 ORDER BY id';
else if ($today["hours"]%2) $query='SELECT * FROM devices WHERE type=15 AND ust=1 AND status=0 ORDER BY id';
else $query='SELECT * FROM devices WHERE type=15 AND ust=1 ORDER BY id';
echo $query.'<br>';
$e2 = mysql_query ($query,$i);
if ($e2)
while ($uo = mysql_fetch_row ($e2))
{
$query='SELECT * FROM channels WHERE device='.$uo[11];
echo $query.'<br>'; $cnt=0;
$e = mysql_query ($query,$i);
if ($e)
while ($ui = mysql_fetch_array($e, MYSQL_ASSOC))
{
$device=$ui["device"];
$datt=$ui["lastmonth"][0].$ui["lastmonth"][1].$ui["lastmonth"][2].$ui["lastmonth"][3].'01000000';
for ($tn=0; $tn<=$qnt; $tn++) $data[$tn]='-';
$today=getdate();
$datt2 = sprintf ("%d%02d%02d000000",$today["year"],$today["mon"],$today["mday"]);
$query = 'SELECT * FROM data2 WHERE date<'.$datt2.' AND type=1 AND channel='.$ui["id"].' ORDER BY date DESC LIMIT 30000';
//$query = 'SELECT * FROM data2 WHERE date>='.$datt.' AND type=1 AND channel='.$ui["id"].' ORDER BY date DESC LIMIT 30000';
$a = mysql_query ($query,$i);
echo $query.'<br>';
if ($a)
while ($uy = mysql_fetch_row ($a))
{
$datt=$uy[2][0].$uy[2][1].$uy[2][2].$uy[2][3].$uy[2][5].$uy[2][6].'01000000';
$x=$qnt+1;
for ($tn=0; $tn<=$qnt; $tn++)
if ($datt==$date1[$tn]) $x=$tn;
$data[$x]+=$uy[3];
//echo '['.$x.'] '.$datt.' '.$data[$x].'<br>';
}
for ($tn=0; $tn<=$qnt; $tn++)
if ($data[$tn]!='-')
{
$query = 'SELECT * FROM data2 WHERE date='.$date1[$tn].' AND type=4 AND channel='.$ui["id"];
$a = mysql_query ($query,$i);
echo $query.'<br>';
if ($a) $uy = mysql_fetch_row ($a);
if ($uy)
{
$query = 'UPDATE data2 SET date=date,value='.$data[$tn].' WHERE date='.$date1[$tn].' AND type=4 AND channel='.$ui["id"];
$e5 = mysql_query ($query,$i);
echo $query.'<br>';
}
else
{
$query = 'INSERT INTO data2 SET value='.$data[$tn].',date='.$date1[$tn].',type=4,channel='.$ui["id"];
$e5 = mysql_query ($query,$i);
echo $query.'<br>';
}
}
}
}
// Free the query result
//odbc_free_result($query);
print '</table>';
?>