1 | <?php
|
---|
2 |
|
---|
3 | class PageMain extends Page
|
---|
4 | {
|
---|
5 | var $Months;
|
---|
6 | var $GrafTimeRanges;
|
---|
7 |
|
---|
8 | function __construct(System $System)
|
---|
9 | {
|
---|
10 | parent::__construct($System);
|
---|
11 | $this->Months = array('', 'Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 'Červenec', 'Srpen', 'Září',
|
---|
12 | 'Říjen', 'Listopad', 'Prosinec');
|
---|
13 |
|
---|
14 | $this->GrafTimeRanges = array(
|
---|
15 | 'hour' => array(
|
---|
16 | 'caption' => 'Hodina',
|
---|
17 | 'period' => 3600,
|
---|
18 | ),
|
---|
19 | 'day' => array(
|
---|
20 | 'caption' => 'Den',
|
---|
21 | 'period' => 3600 * 24,
|
---|
22 | ),
|
---|
23 | 'week' => array(
|
---|
24 | 'caption' => 'Týden',
|
---|
25 | 'period' => 3600 * 24 * 7,
|
---|
26 | ),
|
---|
27 | 'month' => array(
|
---|
28 | 'caption' => 'Měsíc',
|
---|
29 | 'period' => 3600 * 24 * 30,
|
---|
30 | ),
|
---|
31 | 'year' => array(
|
---|
32 | 'caption' => 'Rok',
|
---|
33 | 'period' => 3600 * 24 * 365,
|
---|
34 | ),
|
---|
35 | 'years' => array(
|
---|
36 | 'caption' => 'Desetiletí',
|
---|
37 | 'period' => 3600 * 24 * 365 * 10,
|
---|
38 | ),
|
---|
39 | );
|
---|
40 | }
|
---|
41 |
|
---|
42 | function EditTime($Time)
|
---|
43 | {
|
---|
44 | $Output = '<form style="display: inline;" action="?Operation=SetTime&Time='.$Time.'" method="post">';
|
---|
45 | $TimeParts = getdate($_SESSION[$Time]);
|
---|
46 |
|
---|
47 | // Day selection
|
---|
48 | $Output .= '<select name="Day">';
|
---|
49 | for($I = 1; $I < 32; $I++)
|
---|
50 | {
|
---|
51 | if($I == $TimeParts['mday']) $Selected = ' selected="1"'; else $Selected = '';
|
---|
52 | $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
|
---|
53 | }
|
---|
54 | $Output .= '</select>. ';
|
---|
55 |
|
---|
56 | // Month selection
|
---|
57 | $Output .= '<select name="Month">';
|
---|
58 | foreach($this->Months as $Index => $Month)
|
---|
59 | {
|
---|
60 | if($Index == $TimeParts['mon']) $Selected = ' selected="1"'; else $Selected = '';
|
---|
61 | if($Index > 0) $Output .= '<option value="'.$Index.'"'.$Selected.'>'.$Month.'</option>';
|
---|
62 | }
|
---|
63 | $Output .= '</select>. ';
|
---|
64 |
|
---|
65 | // Year selection
|
---|
66 | $Output .= '<select name="Year">';
|
---|
67 | for($I = 2000; $I <= date("Y"); $I++)
|
---|
68 | {
|
---|
69 | if($I == $TimeParts['year']) $Selected = ' selected="1"'; else $Selected = '';
|
---|
70 | $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
|
---|
71 | }
|
---|
72 | $Output .= '</select> ';
|
---|
73 |
|
---|
74 | // Hour selection
|
---|
75 | $Output .= '<select name="Hour">';
|
---|
76 | for($I = 0; $I < 24; $I++)
|
---|
77 | {
|
---|
78 | if($I == $TimeParts['hours']) $Selected = ' selected="1"'; else $Selected = '';
|
---|
79 | $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
|
---|
80 | }
|
---|
81 | $Output .= '</select> : ';
|
---|
82 |
|
---|
83 | // Minute selection
|
---|
84 | $Output .= '<select name="Minute">';
|
---|
85 | for($I = 0; $I < 60; $I++)
|
---|
86 | {
|
---|
87 | if($I == $TimeParts['minutes']) $Selected = ' selected="1"'; else $Selected = '';
|
---|
88 | $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
|
---|
89 | }
|
---|
90 | $Output .= '</select> ';
|
---|
91 |
|
---|
92 | $Output .= '<input type="submit" value="Nastavit">';
|
---|
93 | $Output .= '</form>';
|
---|
94 | $Output .= ' <form style="display: inline;" action="?Operation=SetTimeNow&Time='.$Time.'" method="post">';
|
---|
95 | $Output .= '<input type="submit" value="Aktuální čas">';
|
---|
96 | $Output .= '</form>';
|
---|
97 |
|
---|
98 | return($Output);
|
---|
99 | }
|
---|
100 |
|
---|
101 | /* Produce table with available measures */
|
---|
102 | function ShowMeasureTable()
|
---|
103 | {
|
---|
104 | $PrefixMultiplier = new PrefixMultiplier();
|
---|
105 | $Output = '<table border="1" cellspacing="0" cellpadding="2" style="font-size: small; margin: 0px auto;">';
|
---|
106 | $Output .= '<tr><th>Měřená veličina</th><th>Poslední hodnota</th><th>Čas posledního měření</th><th>Interpolace</th><th>Poznámky</th>';
|
---|
107 | if(array_key_exists('Debug', $_GET)) $Output .= '<th>Počet položek</th><th>Čas vykonání</th>';
|
---|
108 | $Output .= '</tr>';
|
---|
109 | $Result = $this->Database->select('Measure', '*', '( `Enabled`=1) AND ((`PermissionView`="all") OR (`PermissionView`="'.gethostbyaddr($_SERVER['REMOTE_ADDR']).'")) ORDER BY `Description`');
|
---|
110 | while($Measure = $Result->fetch_array())
|
---|
111 | {
|
---|
112 | $StopWatchStart = GetMicrotime();
|
---|
113 | if(array_key_exists('Debug', $_GET))
|
---|
114 | {
|
---|
115 | $DbResult = $this->Database->select($Measure['DataTable'], 'COUNT(*)', '`measure`='.$Measure['Id']);
|
---|
116 | $RowCount = $DbResult->fetch_array();
|
---|
117 | $RowCount = $RowCount[0];
|
---|
118 | }
|
---|
119 | $Result2 = $this->Database->select($Measure['DataTable'], 'time, avg', '(`measure`='.$Measure['Id'].') AND (`level`=0) ORDER BY time DESC LIMIT 1');
|
---|
120 | if($Result2->num_rows > 0)
|
---|
121 | {
|
---|
122 | $Row = $Result2->fetch_array();
|
---|
123 | $LastMeasureTime = date('j.n.Y G:i:s', MysqlDateTimeToTime($Row['time']));
|
---|
124 | $LastMeasureValue = $PrefixMultiplier->Add($Row['avg'], $Measure['Unit']);
|
---|
125 | } else {
|
---|
126 | $LastMeasureTime = ' ';
|
---|
127 | $LastMeasureValue = ' ';
|
---|
128 | }
|
---|
129 | if($Measure['Continuity'] == 1) $Interpolate = 'Ano'; else $Interpolate = 'Ne';
|
---|
130 | if($Measure['Info'] == '') $Measure['Info'] = ' ';
|
---|
131 | $GenerationTime = floor((GetMicrotime() - $StopWatchStart) * 1000 ) / 1000;
|
---|
132 | $Output .= '<tr><td style="text-align: left"><a href="?Measure='.$Measure['Id'].'&Differential=0">'.$Measure['Description'].'</a></td><td align="center">'.$LastMeasureValue.'</td><td align="center">'.$LastMeasureTime.'</td><td align="center">'.$Interpolate.'</td><td>'.$Measure['Info'].'</td>';
|
---|
133 | if(array_key_exists('Debug', $_GET)) $Output .= '<td>'.$RowCount.'</td><td>'.$GenerationTime.'</td>';
|
---|
134 | $Output .= '</tr>';
|
---|
135 | }
|
---|
136 | $Output .= '</table>';
|
---|
137 | return($Output);
|
---|
138 | }
|
---|
139 |
|
---|
140 | function ShowGraph()
|
---|
141 | {
|
---|
142 | $Output = '<strong>Graf:</strong><br>';
|
---|
143 | $Output .= '<img alt="Graf" src="Graph.php?Measure='.$_SESSION['Measure'].'&From='.
|
---|
144 | $_SESSION['TimeStart'].'&To='.$_SESSION['TimeEnd'].
|
---|
145 | '&Width=750&Height=200&Differential='.
|
---|
146 | $_SESSION['Differential'].'" width="750" height="200"><br>';
|
---|
147 | $Output .= '<a href="?Measure='.$_SESSION['Measure'].'&TimeStart='.
|
---|
148 | $_SESSION['TimeStart'].'&TimeEnd='.$_SESSION['TimeEnd'].
|
---|
149 | '&TimeSpecify=1&Differential='.$_SESSION['Differential'].
|
---|
150 | '">Odkaz na vybraný graf</a><br/>';
|
---|
151 | return($Output);
|
---|
152 | }
|
---|
153 |
|
---|
154 | function ShowTimeRange()
|
---|
155 | {
|
---|
156 | $Output = '';
|
---|
157 | if($_SESSION['TimeSpecify'] == 0)
|
---|
158 | {
|
---|
159 | $_SESSION['TimeEnd'] = time() - 60;
|
---|
160 | $_SESSION['TimeStart'] = $_SESSION['TimeEnd'] - $this->GrafTimeRanges[$_SESSION['Period']]['period'];
|
---|
161 | }
|
---|
162 |
|
---|
163 | if(!array_key_exists('Operation', $_GET)) $_GET['Operation'] = '';
|
---|
164 | switch($_GET['Operation'])
|
---|
165 | {
|
---|
166 | case 'SetTime':
|
---|
167 | if(array_key_exists('Time', $_GET) and array_key_exists('Month', $_POST) and array_key_exists('Day', $_POST) and
|
---|
168 | array_key_exists('Year', $_POST) and array_key_exists('Hour', $_POST) and array_key_exists('Minute', $_POST))
|
---|
169 | {
|
---|
170 | if(($_GET['Time'] == 'TimeStart') or ($_GET['Time'] == 'TimeEnd'))
|
---|
171 | {
|
---|
172 | $_SESSION[$_GET['Time']] = mktime($_POST['Hour'], $_POST['Minute'], 0, $_POST['Month'],
|
---|
173 | $_POST['Day'], $_POST['Year']);
|
---|
174 | $$_GET['Time'] = $_SESSION[$_GET['Time']];
|
---|
175 | }
|
---|
176 | }
|
---|
177 | break;
|
---|
178 | case 'SetTimeNow':
|
---|
179 | if(array_key_exists('Time', $_GET))
|
---|
180 | {
|
---|
181 | if(($_GET['Time'] == 'TimeStart') or ($_GET['Time'] == 'TimeEnd'))
|
---|
182 | {
|
---|
183 | $_SESSION[$_GET['Time']] = time();
|
---|
184 | $$_GET['Time'] = $_SESSION[$_GET['Time']];
|
---|
185 | }
|
---|
186 | }
|
---|
187 | break;
|
---|
188 |
|
---|
189 | }
|
---|
190 | $Output .= '<strong>Časový úsek:</strong><br>';
|
---|
191 |
|
---|
192 | // Show graph time range menu
|
---|
193 | if($_SESSION['TimeSpecify'] == 0)
|
---|
194 | {
|
---|
195 | $Output .= 'Délka úseku: ';
|
---|
196 | foreach($this->GrafTimeRanges as $Index => $Item)
|
---|
197 | $Output .= '<a href="?Period='.$Index.'">'.$Item['caption'].'</a> ';
|
---|
198 | $Output .= '<br>';
|
---|
199 | $Output .= '<a href="?TimeSpecify=1">Přesnější nastavení...</a><br>';
|
---|
200 | } else {
|
---|
201 | $Output .= '<table cellspacing="0" cellpadding="2" border="0" style="margin: 0px auto;">';
|
---|
202 | $Output .= '<tr><td>Počátek:</td><td>'.$this->EditTime('TimeStart').'</td></tr>';
|
---|
203 | $Output .= '<tr><td>Konec:</td><td>'.$this->EditTime('TimeEnd').'</td></tr>';
|
---|
204 | $Output .= '</table>';
|
---|
205 | $Output .= '<a href="?TimeSpecify=0">Jednoduché nastavení...</a><br>';
|
---|
206 | }
|
---|
207 | $Output .= '<br/>';
|
---|
208 | return($Output);
|
---|
209 |
|
---|
210 | }
|
---|
211 |
|
---|
212 | function Show()
|
---|
213 | {
|
---|
214 | global $Config;
|
---|
215 |
|
---|
216 | $Debug = 0;
|
---|
217 | foreach($Config['DefaultVariables'] as $Index => $Variable)
|
---|
218 | {
|
---|
219 | if(!array_key_exists($Index, $_SESSION)) $_SESSION[$Index] = $Variable;
|
---|
220 | if(array_key_exists($Index, $_GET)) $_SESSION[$Index] = $_GET[$Index];
|
---|
221 | if(array_key_exists($Index, $_POST)) $_SESSION[$Index] = $_POST[$Index];
|
---|
222 | //$$Index = $_SESSION[$Index];
|
---|
223 | }
|
---|
224 |
|
---|
225 | $Output = '<div style="text-align: center"><div class="Title">'.$Config['Web']['Title'].'</div>';
|
---|
226 |
|
---|
227 | $Result = $this->Database->select('Measure', 'Id', '(`Enabled`=1) AND '.
|
---|
228 | '((`PermissionView`="all") OR (`PermissionView`="'.gethostbyaddr($_SERVER['REMOTE_ADDR']).'")) '.
|
---|
229 | 'AND (`Id`='.($_SESSION['Measure'] * 1).')');
|
---|
230 | if($Result->num_rows == 0)
|
---|
231 | $_SESSION['Measure'] = $Config['DefaultVariables']['Measure'];
|
---|
232 |
|
---|
233 | $Output .= $this->ShowTimeRange();
|
---|
234 | $Output .= $this->ShowGraph();
|
---|
235 | $Output .= '<br/>';
|
---|
236 | $Output .= $this->ShowMeasureTable();
|
---|
237 | $Output .= '</div>';
|
---|
238 | return($Output);
|
---|
239 | }
|
---|
240 | }
|
---|