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