Changeset 40 for trunk/index.php


Ignore:
Timestamp:
Aug 28, 2009, 10:05:03 PM (15 years ago)
Author:
george
Message:
  • Upraveno: Struktura souborů projektu přepracována na systém MVC.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/index.php

    r37 r40  
    11<?php
    2 include('global.php');
    32
    4 $Debug = 0;
     3include('Include.php');
     4if(array_key_exists('argv', $_SERVER))
     5  $_GET = array_merge($_GET, ParseCommandLineArgs($_SERVER['argv']));
    56
    6 function EditTime($Time)
     7// SQL injection hack protection
     8foreach($_POST as $Index => $Item) $_POST[$Index] = addslashes($Item);
     9foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($Item);
     10
     11if(isset($_SERVER['REMOTE_ADDR'])) session_start();
     12
     13$System = new System();
     14$ScriptTimeStart = $System->GetMicrotime();
     15$System->Database = new Database($Config['Database']['Host'], $Config['Database']['User'], $Config['Database']['Password'], $Config['Database']['Database']);
     16$System->Database->Prefix = $Config['Database']['Prefix'];
     17$System->Database->charset($Config['Database']['Charset']);
     18$System->Config = $Config;
     19$System->AddModule(new Log($System));
     20$System->AddModule(new User($System));
     21$System->AddModule(new Permission($System));
     22if(isset($_SERVER['REMOTE_ADDR'])) $System->Modules['User']->Check();
     23  else $System->Modules['User']->Data['Id'] = $Config['Web']['UserConsoleId'];
     24$System->Modules['Permission']->LoadForUser($System->Modules['User']->Data['Id']);
     25//print_r($System->Modules['Permission']->Data);
     26
     27if(array_key_exists('Module', $_GET)) $Module = $_GET['Module'];
     28  else $Module = 'HomePage';
     29if(array_key_exists('Action', $_GET)) $Action = $_GET['Action'];
     30  else $Action = 'Show';
     31
     32$ControllerName = $Module.'Controller';
     33if(class_exists($ControllerName))
    734{
    8       global $Months;
     35  $Controller = new $ControllerName($System);
     36  if(method_exists($Controller, $Action)) $Output = $Controller->$Action();
     37    else $Output = 'Metoda '.$Action.' modulu '.$Module.' neexistuje.';
     38} else $Output = 'Třída '.$ControllerName.' neexistuje.';
    939
    10       $Output = '<form style="display: inline;" action="?Operation=SetTime&amp;Time='.$Time.'" method="post">';
    11 
    12       $TimeParts = getdate($_SESSION[$Time]);
    13       //print_r($TimeParts);
    14 
    15       // Day selection
    16       $Output .= '<select name="Day">';
    17       for($I = 1; $I < 32; $I++)
    18       {
    19         if($I == $TimeParts['mday']) $Selected = ' selected="1"'; else $Selected = '';
    20         $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
    21       }
    22       $Output .= '</select>. ';
    23 
    24       // Month selection
    25       $Output .= '<select name="Month">';
    26       foreach($Months as $Index => $Month)
    27       {
    28         if($Index == $TimeParts['mon']) $Selected = ' selected="1"'; else $Selected = '';
    29         if($Index > 0) $Output .= '<option value="'.$Index.'"'.$Selected.'>'.$Month.'</option>';
    30       }
    31       $Output .= '</select>. ';
    32 
    33       // Day selection
    34       $Output .= '<select name="Year">';
    35       for($I = 2000; $I < 2010; $I++)
    36       {
    37         if($I == $TimeParts['year']) $Selected = ' selected="1"'; else $Selected = '';
    38         $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
    39       }
    40       $Output .= '</select> &nbsp;&nbsp; ';
    41 
    42       // Hour selection
    43       $Output .= '<select name="Hour">';
    44       for($I = 0; $I < 24; $I++)
    45       {
    46         if($I == $TimeParts['hours']) $Selected = ' selected="1"'; else $Selected = '';
    47         $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
    48       }
    49       $Output .= '</select> : ';
    50 
    51       // Minute selection
    52       $Output .= '<select name="Minute">';
    53       for($I = 0; $I < 60; $I++)
    54       {
    55         if($I == $TimeParts['minutes']) $Selected = ' selected="1"'; else $Selected = '';
    56         $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
    57       }
    58       $Output .= '</select> ';
    59       $Output .= '<input type="submit" value="Nastavit">';
    60       $Output .= '</form>';
    61 
    62       $Output .= ' <form style="display: inline;" action="?Operation=SetTimeNow&amp;Time='.$Time.'" method="post">';
    63       $Output .= '<input type="submit" value="Aktuální čas">';
    64       $Output .= '</form>';
    65 
    66       return($Output);
    67 }
    68 
    69 $Months = array('', 'Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec');
    70 
    71 $GrafTimeRanges = array
    72 (
    73   'hour' => array(
    74     'caption' => 'Hodina',
    75     'period' => 3600,
    76   ),
    77   'day' => array(
    78     'caption' => 'Den',
    79     'period' => 3600 * 24,
    80   ),
    81   'week' => array(
    82     'caption' => 'Týden',
    83     'period' => 3600 * 24 * 7,
    84   ),
    85   'month' => array(
    86     'caption' => 'Měsíc',
    87     'period' => 3600 * 24 * 30,
    88   ),
    89   'year' => array(
    90     'caption' => 'Rok',
    91     'period' => 3600 * 24 * 365,
    92   ),
    93   'years' => array(
    94     'caption' => 'Desetiletí',
    95     'period' => 3600 * 24 * 365 * 10,
    96   ),
    97 );
    98 
    99 foreach($Config['DefaultVariables'] as $Index => $Variable)
    100 {
    101   if(!array_key_exists($Index, $_SESSION)) $_SESSION[$Index] = $Variable;
    102   if(array_key_exists($Index, $_GET)) $_SESSION[$Index] = $_GET[$Index];
    103   if(array_key_exists($Index, $_POST)) $_SESSION[$Index] = $_POST[$Index];
    104   //$$Index = $_SESSION[$Index];
    105 }
    106 
    107 if($_SESSION['TimeSpecify'] == 0)
    108 {
    109   $_SESSION['TimeEnd'] = time() - 60;
    110   $_SESSION['TimeStart'] = $_SESSION['TimeEnd'] - $GrafTimeRanges[$_SESSION['Period']]['period'];
    111 }
    112 
    113 $Output = '<div class="Title">Statistiky</div>';
    114 
    115 if(!array_key_exists('Operation', $_GET)) $_GET['Operation'] = '';
    116 switch($_GET['Operation'])
    117 {
    118   case 'SetTime':
    119     if(array_key_exists('Time', $_GET) and array_key_exists('Month', $_POST) and array_key_exists('Day', $_POST) and
    120       array_key_exists('Year', $_POST) and array_key_exists('Hour', $_POST) and array_key_exists('Minute', $_POST))
    121       {
    122         if(($_GET['Time'] == 'TimeStart') or ($_GET['Time'] == 'TimeEnd'))
    123         {
    124           $_SESSION[$_GET['Time']] = mktime($_POST['Hour'], $_POST['Minute'], 0, $_POST['Month'],
    125             $_POST['Day'], $_POST['Year']);
    126           $$_GET['Time'] = $_SESSION[$_GET['Time']];
    127         }
    128       }
    129     break;
    130   case 'SetTimeNow':
    131     if(array_key_exists('Time', $_GET))
    132     {
    133       if(($_GET['Time'] == 'TimeStart') or ($_GET['Time'] == 'TimeEnd'))
    134       {
    135         $_SESSION[$_GET['Time']] = time();
    136         $$_GET['Time'] = $_SESSION[$_GET['Time']];
    137       }
    138     }
    139     break;
    140 
    141     }
    142     $Output .= '<strong>Časový úsek:</strong><br>';
    143     // Show graf time range menu
    144     if($_SESSION['TimeSpecify'] == 0)
    145     {
    146       $Output .= 'Délka úseku: ';
    147       foreach($GrafTimeRanges as $Index => $Item)
    148         $Output .= '<a href="?Period='.$Index.'">'.$Item['caption'].'</a>&nbsp;';
    149       $Output .= '<br>';
    150       $Output .= '<a href="?TimeSpecify=1">Přesnější nastavení...</a><br>';
    151     } else {
    152       $Output .= '<table cellspacing="0" cellpadding="2" border="0">';
    153       $Output .= '<tr><td>Počátek:</td><td>'.EditTime('TimeStart').'</td></tr>';
    154       $Output .= '<tr><td>Konec:</td><td>'.EditTime('TimeEnd').'</td></tr>';
    155       $Output .= '</table>';
    156       $Output .= '<a href="?TimeSpecify=0">Jednoduché nastavení...</a><br>';
    157     }
    158 $Output .= '<br>';
    159 
    160 $Output .= '<strong>Graf:</strong><br>';
    161 $Output .= '<img alt="Graf" src="graph.php?Measure='.$_SESSION['Measure'].'&amp;From='.$_SESSION['TimeStart'].'&amp;To='.$_SESSION['TimeEnd'].'&amp;Width=750&amp;Height=200&amp;Differential='.$_SESSION['Differential'].'" width="750" height="200"><br>';
    162 $Output .= '<a href="?Measure='.$_SESSION['Measure'].'&amp;TimeStart='.$_SESSION['TimeStart'].'&amp;TimeEnd='.$_SESSION['TimeEnd'].'&amp;TimeSpecify=1&amp;Differential='.$_SESSION['Differential'].'">Odkaz na vybraný graf</a><br>';
    163 //print_r(GetValues($Measure, $TimeStart, $TimeEnd));
    164 
    165 $Output .= '<br>';
    166 
    167 $Output .= '<table border="1" cellspacing="0" cellpadding="2" style="font-size: small;">';
    168 $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>';
    169 if(array_key_exists('Debug', $_GET)) $Output .= '<th>Počet položek</th><th>Čas vykonání</th>';
    170 $Output .= '</tr>';
    171 $Database->select_db('measure');
    172 $Result = $Database->select('measure', '*', 'Enabled=1 AND PermissionView="all" OR PermissionView="'.gethostbyaddr($_SERVER['REMOTE_ADDR']).'" ORDER BY Description');
    173 //echo($Database->error);
    174 
    175 while($Measure = $Result->fetch_array())
    176 {
    177   $StopWatchStart = GetMicrotime();
    178   if(array_key_exists('Debug', $_GET))
    179   {
    180     $DbResult = $Database->select($Measure['DataTable'], 'COUNT(*)', 'measure='.$Measure['Id']);
    181     $RowCount = $DbResult->fetch_array();
    182     $RowCount = $RowCount[0];
    183   }
    184   $Result2 = $Database->select($Measure['DataTable'], 'time, avg', 'measure='.$Measure['Id'].' AND level=0 ORDER BY time DESC LIMIT 1');
    185   if($Result2->num_rows > 0)
    186   {
    187     $Row = $Result2->fetch_array();
    188     $LastMeasureTime = date('j.n.Y G:i:s', MysqlDateTimeToTime($Row['time']));
    189     $LastMeasureValue = AddPrefixMultipliers($Row['avg'], $Measure['Unit']);
    190   } else
    191   {
    192     $LastMeasureTime = '&nbsp;';
    193     $LastMeasureValue = '&nbsp;';
    194   }
    195   if($Measure['Continuity'] == 1) $Interpolate = 'Ano'; else $Interpolate = 'Ne';
    196   if($Measure['Info'] == '') $Measure['Info'] = '&nbsp;';
    197   $GenerationTime = floor((GetMicrotime() - $StopWatchStart) * 1000  ) / 1000;
    198   $Output .= '<tr><td><a href="?Measure='.$Measure['Id'].'&amp;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>';
    199   if(array_key_exists('Debug', $_GET)) $Output .= '<td>'.$RowCount.'</td><td>'.$GenerationTime.'</td>';
    200   $Output .= '</tr>';
    201 }
    202 $Output .= '</table>';
    203 $Output .= '<br><a href="http://game.zdechov.net/statistic/development/">Sekce vývoje systému</a>';
    204 //echo(time());
    205 //print_r(gd_info());
    206 $Output .= '</body></html>';
    207 //print_r($_SESSION);
    208 
    209 ShowPage($Output);
    210 
    211 //echo(AddPrefixMultipliers('-0.000000071112345', 'B'));
     40echo($Output);
    21241
    21342?>
Note: See TracChangeset for help on using the changeset viewer.