LeaderboardURL = 'https://registrace.teribear.cz/Leaderboard';
$this->LeaderboardURL = 'https://leaderboard.teribear.cz/';
$this->BaseURL = '';
$this->LinkLocaleExceptions = array();
$this->Title = '';
$this->LapLength = 0; // km
$this->MoneyKm = 0; // Kč
$this->MaxRunnerSpeed = 20; // km/hour
$this->MinRunnerSpeed = 2; // km/hour
}
function GetLatestYear()
{
$Year = 0;
$DbResult = $this->Database->query('SELECT DISTINCT(Year) AS Year FROM `Runner` ORDER BY Year DESC');
if ($DbResult->num_rows > 0)
{
$DbRow = $DbResult->fetch_assoc();
$Year = $DbRow['Year'];
}
return $Year;
}
function YearList($Path, $SelectedYear, $Table = 'Runner', $Where = '1')
{
$Output = T('Year').': ';
$DbResult = $this->Database->query('SELECT DISTINCT(Year) AS Year FROM `'.$Table.'` WHERE '.$Where.' ORDER BY Year ASC');
while ($DbRow = $DbResult->fetch_assoc())
{
$Year = $DbRow['Year'];
$Item = ''.$Year.'';
if ($SelectedYear == $Year) $Item = ''.$Item.'';
$Output .= $Item.' ';
}
return $Output;
}
function ItemsYearList($Path, $SelectedId, $Table = 'Runner', $Where = '1')
{
$Output = T('Year').': ';
$DbResult = $this->Database->query('SELECT T1.Id AS Id, T2.Year AS Year FROM (SELECT DISTINCT(Id) AS Id FROM `'.$Table.'` WHERE '.$Where.' ORDER BY Year ASC) AS T1 '.
'LEFT JOIN '.$Table.' AS T2 ON T1.Id=T2.Id');
while ($DbRow = $DbResult->fetch_assoc())
{
$Item = ''.$DbRow['Year'].'';
if ($SelectedId == $DbRow['Id']) $Item = ''.$Item.'';
$Output .= $Item.' ';
}
return $Output;
}
function ShowMenu()
{
$Output = '
'.$this->YearList('/runners/', $Year, 'Runner').' '.T('Name').': '.$this->ShowSearch().'
';
$Where .= ' AND (Year='.$Year.') AND (Hidden=0)';
if (array_key_exists('query', $_GET) and ($_GET['query'] != ''))
{
$Where .= ' AND (Name LIKE "%'.addslashes($_GET['query']).'%")';
}
$DbResult = $this->Database->query('SELECT COUNT(*) FROM `Runner` WHERE '.$Where);
$DbRow = $DbResult->fetch_row();
$PageList = GetPageList($DbRow[0]);
$Gender = array('', T('Man'), T('Woman'), T('Kid'));
$Output .= '';
$Output .= $PageList['Output'];
$TableColumns = array(
array('Name' => 'Name', 'Title' => T('Name')),
array('Name' => 'Gender', 'Title' => T('Category')),
array('Name' => 'Distance', 'Title' => T('Distance')),
array('Name' => 'Money', 'Title' => T('Money')),
array('Name' => 'Rank', 'Title' => T('Rank')),
array('Name' => 'Time', 'Title' => T('Last change')),
);
$Order = GetOrderTableHeader($TableColumns, 'Distance', 1);
$Output .= '
';
$Output .= $Order['Output'];
$DbResult = $this->Database->select('Runner', '*, '.
'(SELECT RunnerStat.Distance FROM RunnerStat WHERE RunnerStat.Runner=Runner.Id ORDER BY Time DESC LIMIT 1) AS Distance'.
', (SELECT RunnerStat.Money FROM RunnerStat WHERE RunnerStat.Runner=Runner.Id ORDER BY Time DESC LIMIT 1) AS Money'.
', (SELECT RunnerStat.Time FROM RunnerStat WHERE RunnerStat.Runner=Runner.Id ORDER BY Time DESC LIMIT 1) AS Time'.
', (SELECT RunnerStat.Rank FROM RunnerStat WHERE RunnerStat.Runner=Runner.Id ORDER BY Time DESC LIMIT 1) AS Rank',
$Where.$Order['SQL'].$PageList['SQLLimit']);
while ($Item = $DbResult->fetch_assoc())
{
$Output .= ''.
''.$Item['Name'].' | '.
''.$Gender[$Item['Gender']].' | '.
''.$Item['Distance'].' | '.
''.$Item['Money'].' | '.
''.$Item['Rank'].' | '.
''.$this->RunningState(MysqlDateTimeToTime($Item['Time'])).' | '.
'
';
}
$Output .= '
';
$Output .= $PageList['Output'];
$Output .= '
';
return $Output;
}
function ShowRunner()
{
$PrefixMultiplier = new PrefixMultiplier();
$Output = '';
$RunnerId = 0;
if ((count($this->PathItems) > 0) and ($this->PathItems[count($this->PathItems) - 1] != ''))
$RunnerId = $this->PathItems[count($this->PathItems) - 1];
if (!is_numeric($RunnerId)) die(T('Runner id needs to be numeric'));
$DbResult = $this->Database->query('SELECT Runner.Name, Team.Name AS TeamName, Team.Id AS TeamId, Runner.Year FROM Runner '.
'LEFT JOIN Team ON Team.Id=Runner.Team WHERE (Runner.Hidden=0) AND (Runner.Id='.$RunnerId.')');
if ($DbResult->num_rows > 0)
{
$DbRow = $DbResult->fetch_assoc();
$this->Title = T('Runner').' '.$DbRow['Name'].' - '.$this->Title;
$Output .= ''.$this->ItemsYearList('/runner/', $RunnerId, 'Runner', 'Name="'.$this->Database->real_escape_string($DbRow['Name']).'"').'
';
$this->LoadYearParameters($DbRow['Year']);
$Output .= $this->ShowDetailed('Runner', $RunnerId);
//$Output .= $this->ShowDetailedChart('Runner', $RunnerId);
$Output .= $this->ShowDaily('Runner', $RunnerId);
//$Output .= $this->ShowDailyChart('Runner', $RunnerId);
} else $Output .= T('Runner not found.');
return $Output;
}
function GetTotals($Where = '1', $Table = 'Runner')
{
$DbResult = $this->Database->query('SELECT (SELECT COUNT(*) FROM '.$Table.' WHERE '.$Where.') AS TotalCount, '.
'(SELECT SUM(T1.Distance) FROM (SELECT (SELECT Distance FROM '.$Table.'Stat WHERE '.$Table.'Stat.'.$Table.' = '.$Table.'.Id ORDER BY Time DESC LIMIT 1) AS Distance FROM '.$Table.' WHERE '.$Where.') AS T1) AS TotalDistance, '.
'(SELECT SUM(T2.Money) FROM (SELECT (SELECT Money FROM '.$Table.'Stat WHERE '.$Table.'Stat.'.$Table.' = '.$Table.'.Id ORDER BY Time DESC LIMIT 1) AS Money FROM '.$Table.' WHERE '.$Where.') AS T2) AS TotalMoney');
$DbRow = $DbResult->fetch_assoc();
return $DbRow;
}
function GetYear()
{
$Year = 0;
if (count($this->PathItems) > 0)
{
$Param = $this->PathItems[count($this->PathItems) - 1];
if (is_numeric($this->PathItems[count($this->PathItems) - 1]))
$Year = $this->PathItems[count($this->PathItems) - 1] * 1;
}
if ($Year == 0) $Year = $this->GetLatestYear();
$this->LoadYearParameters($Year);
return $Year;
}
function ShowMain()
{
$Output = '';
$Output .= '