Changeset 31 for trunk/index.php


Ignore:
Timestamp:
Sep 21, 2019, 8:56:17 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Merged almost same code for teams and families.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/index.php

    r30 r31  
    318318  }
    319319
     320  function ShowTeams()
     321  {
     322    return $this->ShowTeamsInternal('Teams', 'Team', 'teams', 'team', 'Team', '(IsFamily=0)');
     323  }
     324
    320325  function ShowFamilies()
    321326  {
     327    return $this->ShowTeamsInternal('Families', 'Family', 'families', 'family', 'Team', '(IsFamily=1)');
     328  }
     329
     330  function ShowTeamsInternal($Title, $TitleItem, $UrlDir, $UrlDirItem, $Table, $Where = '1')
     331  {
    322332    $Output = '';
    323     $Output .= '<div class="page-title">Families</div>';
     333    $Output .= '<div class="page-title">'.$Title.'</div>';
    324334    $Year = $this->GetYear();
    325335
    326     $Output .= '<div class="section-title">'.$this->YearList('/families/', $Year).' Name: '.$this->ShowSearch().'</div>';
    327     $Where = '(IsFamily=1) AND (Year='.$Year.')';
     336    $Where = '(Year='.$Year.') AND '.$Where;
    328337    if (array_key_exists('query', $_GET) and ($_GET['query'] != ''))
    329338    {
    330339      $Where .= ' AND (Name LIKE "%'.addslashes($_GET['query']).'%")';
    331340    }
    332 
    333     $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Team` WHERE '.$Where);
     341    $Output .= '<div class="section-title">'.$this->YearList('/'.$UrlDir.'/', $Year, $Table).' Name: '.$this->ShowSearch().'</div>';
     342
     343    $DbResult = $this->Database->query('SELECT COUNT(*) FROM `'.$Table.'` WHERE '.$Where);
    334344    $DbRow = $DbResult->fetch_row();
    335345    $PageList = GetPageList($DbRow[0]);
     
    360370    while($Item = $DbResult->fetch_assoc())
    361371    {
    362       if ($Item['Name'] == '') $Item['Name'] = 'Family '.$Item['WebId'];
     372      if ($Item['Name'] == '') $Item['Name'] = $TitleItem.' '.$Item['WebId'];
    363373      $Output .= '<tr>'.
    364         '<td><a href="'.$this->Link('/family/'.$Item['Id'].'/').'">'.$Item['Name'].'</a></td>'.
     374        '<td><a href="'.$this->Link('/'.$UrlDirItem.'/'.$Item['Id'].'/').'">'.$Item['Name'].'</a></td>'.
    365375        '<td>'.$Item['RunnersCount'].'</td>'.
    366376        '<td>'.$Item['Distance'].'</td>'.
     
    378388  }
    379389
    380   function ShowFamily()
    381   {
    382     $Output = '';
    383 
    384     $TeamId = 1;
    385     if ((count($this->PathItems) > 0) and ($this->PathItems[count($this->PathItems) - 1] != ''))
    386       $TeamId = $this->PathItems[count($this->PathItems) - 1];
    387     if (!is_numeric($TeamId)) die('FamilyId needs to be numeric');
    388 
    389     $DbResult = $this->Database->query('SELECT Team.*, '.
    390       '(SELECT COUNT(*) FROM Runner WHERE Runner.Team=Team.Id) AS RunnerCount, '.
    391       '(SELECT TeamStat.Distance FROM TeamStat WHERE TeamStat.Team=Team.Id ORDER BY TeamStat.Time DESC LIMIT 1) AS Distance, '.
    392       '(SELECT TeamStat.Money FROM TeamStat WHERE TeamStat.Team=Team.Id ORDER BY Time DESC LIMIT 1) AS Money, '.
    393       '(SELECT TeamStat.Rank FROM TeamStat WHERE TeamStat.Team=Team.Id ORDER BY Time DESC LIMIT 1) AS Rank '.
    394       'FROM Team WHERE Id='.$TeamId.' AND IsFamily=1');
    395     $DbRow = $DbResult->fetch_assoc();
    396     $Output .= '<div class="page-title">Family '.$DbRow['Name'].'</div>';
    397     $Output .= '<div class="section-title">'.$this->ItemsYearList('/family/', $RunnerId, 'Team', 'Name="'.$DbRow['Name'].'"').'</div>';
    398     $Output .= '<div class="section-title">Runners: '.$DbRow['RunnerCount'].', Distance: '.$DbRow['Distance'].' km, Money: '.$DbRow['Money'].' Kč, Rank: '.$DbRow['Rank'].'</div>';
    399 
    400     $Where = 'Team='.$TeamId;
    401 
    402     $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Runner` WHERE '.$Where);
    403     $DbRow = $DbResult->fetch_row();
    404     $PageList = GetPageList($DbRow[0]);
    405 
    406     $Gender = array('', 'Man', 'Woman', 'Kid');
    407     $Output .= '<div id="list_content">';
    408     $Output .= $PageList['Output'];
    409     $TableColumns = array(
    410       array('Name' => 'Name', 'Title' => 'Name'),
    411       array('Name' => 'Gender', 'Title' => 'Category'),
    412       array('Name' => 'Distance', 'Title' => 'Distance'),
    413       array('Name' => 'Money', 'Title' => 'Money'),
    414       array('Name' => 'Rank', 'Title' => 'Rank'),
    415       array('Name' => 'Time', 'Title' => 'Last change'),
    416     );
    417     $Order = GetOrderTableHeader($TableColumns, 'Distance', 1);
    418     $Output .= '<table class="WideTable">';
    419     $Output .= $Order['Output'];
    420     $DbResult = $this->Database->select('Runner', '*, '.
    421       '(SELECT RunnerStat.Distance FROM RunnerStat WHERE RunnerStat.Runner=Runner.Id ORDER BY Time DESC LIMIT 1) AS Distance'.
    422       ', (SELECT RunnerStat.Money FROM RunnerStat WHERE RunnerStat.Runner=Runner.Id ORDER BY Time DESC LIMIT 1) AS Money'.
    423       ', (SELECT RunnerStat.Time FROM RunnerStat WHERE RunnerStat.Runner=Runner.Id ORDER BY Time DESC LIMIT 1) AS Time'.
    424       ', (SELECT RunnerStat.Rank FROM RunnerStat WHERE RunnerStat.Runner=Runner.Id ORDER BY Time DESC LIMIT 1) AS Rank',
    425       $Where.$Order['SQL'].$PageList['SQLLimit']);
    426     while($Item = $DbResult->fetch_assoc())
    427     {
    428       $Output .= '<tr>'.
    429         '<td><a href="'.$this->Link('/runner/'.$Item['Id'].'/').'">'.$Item['Name'].'</a></td>'.
    430         '<td>'.$Gender[$Item['Gender']].'</td>'.
    431         '<td>'.$Item['Distance'].'</td>'.
    432         '<td>'.$Item['Money'].'</td>'.
    433         '<td>'.$Item['Rank'].'</td>'.
    434         '<td>'.$this->RunningState(MysqlDateTimeToTime($Item['Time'])).'</td>'.
    435         '</tr>';
    436     }
    437     $Output .= '</table>';
    438     $Output .= $PageList['Output'];
    439     $Output .= '</div><br>';
    440 
    441     $Output .= $this->ShowDetailed('Team', $TeamId);
    442     $Output .= $this->ShowDaily('Team', $TeamId);
    443 
    444     return($Output);
    445   }
    446 
    447   function ShowTeams()
    448   {
    449     $Output = '';
    450     $Output .= '<div class="page-title">Teams</div>';
    451     $Year = $this->GetYear();
    452 
    453     $Where = '(IsFamily=0) AND (Year='.$Year.')';
    454     if (array_key_exists('query', $_GET) and ($_GET['query'] != ''))
    455     {
    456       $Where .= ' AND (Name LIKE "%'.addslashes($_GET['query']).'%")';
    457     }
    458     $Output .= '<div class="section-title">'.$this->YearList('/teams/', $Year, 'Team').' Name: '.$this->ShowSearch().'</div>';
    459 
    460     $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Team` WHERE '.$Where);
    461     $DbRow = $DbResult->fetch_row();
    462     $PageList = GetPageList($DbRow[0]);
    463 
    464     $Output .= '<div id="list_content">';
    465     $Output .= $PageList['Output'];
    466     $TableColumns = array(
    467       array('Name' => 'Name', 'Title' => 'Name'),
    468       array('Name' => 'RunnersCount', 'Title' => 'Runners'),
    469       array('Name' => 'Distance', 'Title' => 'Distance'),
    470       array('Name' => 'Money', 'Title' => 'Money'),
    471       array('Name' => 'DistanceRunner', 'Title' => 'Distance per runner'),
    472       array('Name' => 'MoneyRunner', 'Title' => 'Money per runner'),
    473       array('Name' => 'Rank', 'Title' => 'Rank'),
    474     );
    475     $Order = GetOrderTableHeader($TableColumns, 'Distance', 1);
    476     $Output .= '<table class="WideTable">';
    477     $Output .= $Order['Output'];
    478     $DbResult = $this->Database->select('Team', '*, '.
    479       '(SELECT COUNT(*) FROM Runner WHERE Runner.Team=Team.Id) AS RunnersCount, '.
    480       '(SELECT TeamStat.Distance FROM TeamStat WHERE TeamStat.Team=Team.Id ORDER BY TeamStat.Time DESC LIMIT 1) AS Distance, '.
    481       '(SELECT TeamStat.Money FROM TeamStat WHERE TeamStat.Team=Team.Id ORDER BY Time DESC LIMIT 1) AS Money, '.
    482       '(SELECT TeamStat.Time FROM TeamStat WHERE TeamStat.Team=Team.Id ORDER BY Time DESC LIMIT 1) AS Time, '.
    483       '(SELECT TeamStat.Rank FROM TeamStat WHERE TeamStat.Team=Team.Id ORDER BY Time DESC LIMIT 1) AS Rank, '.
    484       'ROUND((SELECT TeamStat.Distance FROM TeamStat WHERE TeamStat.Team=Team.Id ORDER BY TeamStat.Time DESC LIMIT 1) / (SELECT COUNT(*) FROM Runner WHERE Runner.Team=Team.Id), 1) AS DistanceRunner, '.
    485       'ROUND((SELECT TeamStat.Money FROM TeamStat WHERE TeamStat.Team=Team.Id ORDER BY Time DESC LIMIT 1) / (SELECT COUNT(*) FROM Runner WHERE Runner.Team=Team.Id)) AS MoneyRunner',
    486       $Where.$Order['SQL'].$PageList['SQLLimit']);
    487     while($Item = $DbResult->fetch_assoc())
    488     {
    489       if ($Item['Name'] == '') $Item['Name'] = 'Team '.$Item['WebId'];
    490       $Output .= '<tr>'.
    491         '<td><a href="'.$this->Link('/team/'.$Item['Id'].'/').'">'.$Item['Name'].'</a></td>'.
    492         '<td>'.$Item['RunnersCount'].'</td>'.
    493         '<td>'.$Item['Distance'].'</td>'.
    494         '<td>'.$Item['Money'].'</td>'.
    495         '<td>'.$Item['DistanceRunner'].'</td>'.
    496         '<td>'.$Item['MoneyRunner'].'</td>'.
    497         '<td>'.$Item['Rank'].'</td>'.
    498         '</tr>';
    499     }
    500     $Output .= '</table>';
    501     $Output .= $PageList['Output'];
    502     $Output .= '</div>';
    503 
    504     return($Output);
    505   }
    506 
    507390  function RunningState($Time)
    508391  {
     
    514397
    515398  function ShowTeam()
     399  {
     400    return $this->ShowTeamInternal('Team', 'team');
     401  }
     402
     403  function ShowFamily()
     404  {
     405    return $this->ShowTeamInternal('Family', 'family');
     406  }
     407
     408  function ShowTeamInternal($Title, $UrlDir)
    516409  {
    517410    $Output = '';
     
    529422      'FROM Team WHERE Id='.$TeamId);
    530423    $DbRow = $DbResult->fetch_assoc();
    531     $Output .= '<div class="page-title">Team '.$DbRow['Name'].'</div>';
    532     $Output .= '<div class="section-title">'.$this->ItemsYearList('/team/', $TeamId, 'Team', 'Name="'.$DbRow['Name'].'"').'</div>';
     424    $Output .= '<div class="page-title">'.$Title.' '.$DbRow['Name'].'</div>';
     425    $Output .= '<div class="section-title">'.$this->ItemsYearList('/'.$UrlDir.'/', $TeamId, 'Team', 'Name="'.$DbRow['Name'].'"').'</div>';
    533426    $Output .= '<div class="section-title">Runners: '.$DbRow['RunnerCount'].', Distance: '.$DbRow['Distance'].' km, Money: '.$DbRow['Money'].' Kč, Rank: '.$DbRow['Rank'].'</div>';
    534427
Note: See TracChangeset for help on using the changeset viewer.