Changeset 84 for trunk/Modules/Measure/Page.php
- Timestamp:
- Jan 20, 2018, 11:33:54 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Measure/Page.php
r72 r84 4 4 { 5 5 var $Months; 6 var $Gra fTimeRanges;6 var $GraphTimeRanges; 7 7 8 8 function __construct(System $System) … … 12 12 'Říjen', 'Listopad', 'Prosinec'); 13 13 14 $this->Gra fTimeRanges = array(14 $this->GraphTimeRanges = array( 15 15 'hour' => array( 16 16 'caption' => 'Hodina', … … 37 37 'period' => 3600 * 24 * 365 * 10, 38 38 ), 39 'all' => array( 40 'caption' => 'Vše', 41 'period' => -1, 42 ), 39 43 ); 44 $this->Time = time(); 45 } 46 47 function GetTimeRange() 48 { 49 $Result = $this->GraphTimeRanges[$_SESSION['Period']]['period']; 50 if ($Result == -1) 51 { 52 $Measure = $this->LoadMeasure($_SESSION['Measure']); 53 $FirstValue = $this->GetFirstMeasure($Measure); 54 $LastValue = $this->GetLastMeasure($Measure); 55 $Result = $LastValue['Time'] - $FirstValue['Time']; 56 } 57 return $Result; 40 58 } 41 59 … … 98 116 return($Output); 99 117 } 100 118 119 function GetFirstMeasure($Measure) 120 { 121 $Result2 = $this->Database->select($Measure['DataTable'], '`Time`, `Avg`', '(`Measure`='.$Measure['Id'].') AND (`Level`=0) ORDER BY `Time` ASC LIMIT 1'); 122 if($Result2->num_rows > 0) 123 { 124 $Row = $Result2->fetch_array(); 125 $LastMeasureTime = MysqlDateTimeToTime($Row['Time']); 126 $LastMeasureValue = $Row['Avg']; 127 } else { 128 $LastMeasureTime = $this->Time - $this->GetTimeRange(); 129 $LastMeasureValue = 0; 130 } 131 return(array('Time' => $LastMeasureTime, 'Value' => $LastMeasureValue)); 132 } 133 134 function GetLastMeasure($Measure) 135 { 136 $Result2 = $this->Database->select($Measure['DataTable'], '`Time`, `Avg`', '(`Measure`='.$Measure['Id'].') AND (`Level`=0) ORDER BY `Time` DESC LIMIT 1'); 137 if($Result2->num_rows > 0) 138 { 139 $Row = $Result2->fetch_array(); 140 $LastMeasureTime = MysqlDateTimeToTime($Row['Time']); 141 $LastMeasureValue = $Row['Avg']; 142 } else { 143 $LastMeasureTime = $this->Time; 144 $LastMeasureValue = 0; 145 } 146 return(array('Time' => $LastMeasureTime, 'Value' => $LastMeasureValue)); 147 } 148 149 function LoadMeasure($Id) 150 { 151 $DbResult = $this->Database->select('Measure', '*', '( `Enabled`=1) AND (`Id`='.$Id.') AND ((`PermissionView`="all") OR (`PermissionView`="'. 152 gethostbyaddr($_SERVER['REMOTE_ADDR']).'"))'); 153 $DbRow = $DbResult->fetch_array(); 154 return $DbRow; 155 } 156 101 157 /* Produce table with available measures */ 102 158 function ShowMeasureTable() … … 107 163 if(array_key_exists('Debug', $_GET)) $Output .= '<th>Počet položek</th><th>Čas vykonání</th>'; 108 164 $Output .= '</tr>'; 109 $Result = $this->Database->select('Measure', '*', '( `Enabled`=1) AND ((`PermissionView`="all") OR (`PermissionView`="'.gethostbyaddr($_SERVER['REMOTE_ADDR']).'")) ORDER BY `Description`'); 165 $Result = $this->Database->select('Measure', '*', '( `Enabled`=1) AND ((`PermissionView`="all") OR (`PermissionView`="'. 166 gethostbyaddr($_SERVER['REMOTE_ADDR']).'")) ORDER BY `Description`'); 110 167 while($Measure = $Result->fetch_array()) 111 168 { … … 113 170 if(array_key_exists('Debug', $_GET)) 114 171 { 115 $DbResult = $this->Database->select($Measure['DataTable'], 'COUNT(*)', '` measure`='.$Measure['Id']);172 $DbResult = $this->Database->select($Measure['DataTable'], 'COUNT(*)', '`Measure`='.$Measure['Id']); 116 173 $RowCount = $DbResult->fetch_array(); 117 174 $RowCount = $RowCount[0]; 118 175 } 119 $Result2 = $this->Database->select($Measure['DataTable'], 'time, avg', '(`measure`='.$Measure['Id'].') AND (`level`=0) ORDER BY time DESC LIMIT 1'); 176 $Result2 = $this->Database->select($Measure['DataTable'], '`Time`, `Avg`', '(`Measure`='. 177 $Measure['Id'].') AND (`Level`=0) ORDER BY `Time` DESC LIMIT 1'); 120 178 if($Result2->num_rows > 0) 121 179 { 122 180 $Row = $Result2->fetch_array(); 123 $LastMeasureTime = date('j.n.Y G:i:s', MysqlDateTimeToTime($Row[' time']));124 $LastMeasureValue = $PrefixMultiplier->Add($Row[' avg'], $Measure['Unit']);181 $LastMeasureTime = date('j.n.Y G:i:s', MysqlDateTimeToTime($Row['Time'])); 182 $LastMeasureValue = $PrefixMultiplier->Add($Row['Avg'], $Measure['Unit']); 125 183 } else { 126 184 $LastMeasureTime = ' '; … … 130 188 if($Measure['Info'] == '') $Measure['Info'] = ' '; 131 189 $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>'; 190 $Output .= '<tr><td style="text-align: left"><a href="?Measure='.$Measure['Id']. 191 '&Differential=0">'.$Measure['Description'].'</a></td><td align="center">'. 192 $LastMeasureValue.'</td><td align="center">'.$LastMeasureTime.'</td><td align="center">'. 193 $Interpolate.'</td><td>'.$Measure['Info'].'</td>'; 194 if(array_key_exists('Debug', $_GET)) 195 $Output .= '<td>'.$RowCount.'</td><td>'.$GenerationTime.'</td>'; 134 196 $Output .= '</tr>'; 135 197 } … … 155 217 { 156 218 $Output = ''; 157 if($_SESSION['TimeSpecify'] == 0)158 {159 $_SESSION['TimeEnd'] = time() - 60;160 $_SESSION['TimeStart'] = $_SESSION['TimeEnd'] - $this->GrafTimeRanges[$_SESSION['Period']]['period'];161 }162 219 163 220 if(!array_key_exists('Operation', $_GET)) $_GET['Operation'] = ''; … … 180 237 if(($_GET['Time'] == 'TimeStart') or ($_GET['Time'] == 'TimeEnd')) 181 238 { 182 $_SESSION[$_GET['Time']] = time();239 $_SESSION[$_GET['Time']] = $this->Time; 183 240 } 184 241 } … … 192 249 { 193 250 $Output .= 'Délka úseku: '; 194 foreach($this->Gra fTimeRanges as $Index => $Item)251 foreach($this->GraphTimeRanges as $Index => $Item) 195 252 $Output .= '<a href="?Period='.$Index.'">'.$Item['caption'].'</a> '; 196 253 $Output .= '<br>'; … … 203 260 $Output .= '<a href="?TimeSpecify=0">Jednoduché nastavení...</a><br>'; 204 261 } 262 $Output .= 'Posun: <a href="?Move=LeftEnd">|<</a> <a href="?Move=Left"><</a> '. 263 '<a href="?Move=Right">></a> <a href="?Move=RightEnd">>|</a> <a href="?Move=Now">Nyní</a><br>'; 205 264 $Output .= '<br/>'; 206 265 return($Output); 207 266 208 267 } 268 269 function HandleURL() 270 { 271 global $Config; 272 273 foreach ($Config['DefaultVariables'] as $Index => $Variable) 274 { 275 if (!array_key_exists($Index, $_SESSION)) $_SESSION[$Index] = $Variable; 276 //if(array_key_exists($Index, $_GET)) $_SESSION[$Index] = $_GET[$Index]; 277 //if(array_key_exists($Index, $_POST)) $_SESSION[$Index] = $_POST[$Index]; 278 //$$Index = $_SESSION[$Index]; 279 } 280 if (array_key_exists('Period', $_GET)) 281 { 282 $_SESSION['Period'] = $_GET['Period']; 283 // Update time start according time period 284 if ($_SESSION['Period'] == 'all') 285 { 286 $Measure = $this->LoadMeasure($_SESSION['Measure']); 287 $FirstValue = $this->GetFirstMeasure($Measure); 288 $LastValue = $this->GetLastMeasure($Measure); 289 $_SESSION['TimeStart'] = $FirstValue['Time']; 290 $_SESSION['TimeEnd'] = $LastValue['Time']; 291 } else 292 { 293 $_SESSION['TimeStart'] = $_SESSION['TimeEnd'] - $this->GetTimeRange(); 294 } 295 } 296 if (array_key_exists('TimeStart', $_GET)) 297 { 298 $_SESSION['TimeStart'] = $_GET['TimeStart']; 299 } 300 if (array_key_exists('TimeEnd', $_GET)) 301 { 302 $_SESSION['TimeStart'] = $_GET['TimeEnd']; 303 } 304 if (array_key_exists('Differential', $_GET)) 305 { 306 $_SESSION['Differential'] = $_GET['Differential']; 307 } 308 if (array_key_exists('Measure', $_GET)) 309 { 310 $_SESSION['Measure'] = $_GET['Measure']; 311 } 312 if (array_key_exists('TimeSpecify', $_GET)) 313 { 314 if (($_SESSION['TimeSpecify'] == 1) and ($_GET['TimeSpecify'] == 0)) 315 { 316 $_SESSION['TimeEnd'] = $this->Time - 60; 317 $_SESSION['TimeStart'] = $_SESSION['TimeEnd'] - $this->GetTimeRange(); 318 } 319 $_SESSION['TimeSpecify'] = $_GET['TimeSpecify']; 320 } 321 322 if (array_key_exists('Move', $_GET)) 323 { 324 $Move = $_GET['Move']; 325 if ($Move == 'Left') 326 { 327 $_SESSION['TimeStart'] = $_SESSION['TimeStart'] - $this->GetTimeRange(); 328 $_SESSION['TimeEnd'] = $_SESSION['TimeEnd'] - $this->GetTimeRange(); 329 } else 330 if ($Move == 'Right') 331 { 332 $_SESSION['TimeStart'] = $_SESSION['TimeStart'] + $this->GetTimeRange(); 333 $_SESSION['TimeEnd'] = $_SESSION['TimeEnd'] + $this->GetTimeRange(); 334 } else 335 if ($Move == 'Now') 336 { 337 $_SESSION['TimeEnd'] = $this->Time - 60; 338 $_SESSION['TimeStart'] = $_SESSION['TimeEnd'] - $this->GetTimeRange(); 339 } else 340 if ($Move == 'LeftEnd') 341 { 342 $Measure = $this->LoadMeasure($_SESSION['Measure']); 343 $FirstValue = $this->GetFirstMeasure($Measure); 344 $_SESSION['TimeStart'] = $FirstValue['Time']; 345 $_SESSION['TimeEnd'] = $_SESSION['TimeStart'] + $this->GetTimeRange(); 346 } else 347 if ($Move == 'RightEnd') 348 { 349 $Measure = $this->LoadMeasure($_SESSION['Measure']); 350 $LastValue = $this->GetLastMeasure($Measure); 351 $_SESSION['TimeEnd'] = $LastValue['Time']; 352 $_SESSION['TimeStart'] = $_SESSION['TimeEnd'] - $this->GetTimeRange(); 353 } 354 } 355 } 209 356 210 357 function Show() … … 213 360 214 361 $Debug = 0; 215 foreach($Config['DefaultVariables'] as $Index => $Variable) 216 { 217 if(!array_key_exists($Index, $_SESSION)) $_SESSION[$Index] = $Variable; 218 if(array_key_exists($Index, $_GET)) $_SESSION[$Index] = $_GET[$Index]; 219 if(array_key_exists($Index, $_POST)) $_SESSION[$Index] = $_POST[$Index]; 220 //$$Index = $_SESSION[$Index]; 221 } 222 362 $this->HandleURL(); 363 223 364 $Output = '<div style="text-align: center"><div class="Title">'.$Config['Web']['Title'].'</div>'; 224 365 225 366 $Result = $this->Database->select('Measure', 'Id', '(`Enabled`=1) AND '. 226 227 367 '((`PermissionView`="all") OR (`PermissionView`="'.gethostbyaddr($_SERVER['REMOTE_ADDR']).'")) '. 368 'AND (`Id`='.($_SESSION['Measure'] * 1).')'); 228 369 if($Result->num_rows == 0) 229 370 $_SESSION['Measure'] = $Config['DefaultVariables']['Measure'];
Note:
See TracChangeset
for help on using the changeset viewer.