Changeset 41 for trunk/index.php
- Timestamp:
- Sep 14, 2020, 12:22:36 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/index.php
r40 r41 6 6 include_once('Run.php'); 7 7 include_once('Packages/Common/Base.php'); 8 include_once('Packages/Common/Locale.php'); 8 9 include_once('Packages/Common/PrefixMultiplier.php'); 9 include_once('Packages/Common/Locale.php');10 10 11 11 session_start(); … … 29 29 var $LinkLocaleExceptions; 30 30 var $Title; 31 var $LapLength; 32 var $MoneyKm; 33 var $MaxRunnerSpeed; 34 var $MinRunnerSpeed; 31 35 32 36 function __construct() … … 36 40 $this->LinkLocaleExceptions = array(); 37 41 $this->Title = ''; 42 $this->LapLength = 0; // km 43 $this->MoneyKm = 0; // Kč 44 $this->MaxRunnerSpeed = 20; // km/hour 45 $this->MinRunnerSpeed = 2; // km/hour 38 46 } 39 47 … … 468 476 $Output .= '<div class="page-title">'.$Title.' '.$DbRow['Name'].'</div>'; 469 477 $Output .= '<div class="section-title">'.$this->ItemsYearList('/'.$UrlDir.'/', $TeamId, 'Team', 'Name="'.$DbRow['Name'].'"').'</div>'; 478 $this->LoadYearParameters($DbRow['Year']); 470 479 $Output .= '<div class="section-title">'. 471 480 T('Runners').': '.$DbRow['RunnerCount'].', '. … … 546 555 $Output .= '<table class="WideTable">'; 547 556 $Output .= $Order['Output']; 557 $TableStat = $Table.'Stat'; 548 558 $DbResult = $this->Database->query('SELECT *'. 549 ', (SELECT TIME_TO_SEC(TIMEDIFF('.$Table.'Stat.Time, B.Time)) FROM '.$Table.'Stat AS B WHERE (B.Time < '.$Table.'Stat.Time) AND (B.'.$Table.' = '.$Table.'Stat.'.$Table.') ORDER BY B.Time DESC LIMIT 1) AS Duration'.550 ', (SELECT '.$Table.'Stat.Distance - B.Distance FROM '.$Table.'Stat AS B WHERE (B.Time < '.$Table.'Stat.Time) AND (B.'.$Table.' = '.$Table.'Stat.'.$Table.') ORDER BY B.Time DESC LIMIT 1) AS Length'.559 ', (SELECT '.$TableStat.'.Distance - B.Distance FROM '.$TableStat.' AS B WHERE (B.Time < '.$TableStat.'.Time) AND (B.'.$Table.' = '.$TableStat.'.'.$Table.') ORDER BY B.Time DESC LIMIT 1) AS Length'. 560 ', (SELECT TIME_TO_SEC(TIMEDIFF('.$TableStat.'.Time, B.Time)) FROM '.$TableStat.' AS B WHERE (B.Time < '.$TableStat.'.Time) AND (B.'.$Table.' = '.$TableStat.'.'.$Table.') ORDER BY B.Time DESC LIMIT 1) AS Duration'. 551 561 ', NULL AS Speed'. 552 ' FROM '.$Table .'Stat'.562 ' FROM '.$TableStat. 553 563 ' WHERE '.$Where.$Order['SQL'].$PageList['SQLLimit']); 554 564 while ($Item = $DbResult->fetch_assoc()) … … 559 569 '<td>'.$Item['Money'].'</td>'. 560 570 '<td>'.$Item['Rank'].'</td>'; 561 if ( $Item['Duration'] != null) $Output .= '<td>'.$PrefixMultiplier->Add($Item['Duration'], '', 4, 'Time').'</td>';571 if (($Item['Duration'] != null) and ($Item['Duration'] < $Item['Length'] / $this->MinRunnerSpeed * 3600)) $Output .= '<td>'.$PrefixMultiplier->Add($Item['Duration'], '', 4, 'Time').'</td>'; 562 572 else $Output .= '<td> </td>'; 563 573 $Output .= '<td>'.$Item['Length'].'</td>'; 564 if ($Item['Duration'] > 0) $Output .= '<td>'.$PrefixMultiplier->Add($Item['Length'] / $Item['Duration'] * 3600, '', 4, 'Decimal').'</td>'; 574 $Speed = $Item['Length'] / $Item['Duration'] * 3600; 575 if (($Item['Duration'] > 0) and ($Item['Duration'] < $Item['Length'] * 3600 / $this->MinRunnerSpeed)) 576 $Output .= '<td>'.$PrefixMultiplier->Add($Speed, '', 4, 'Decimal').'</td>'; 565 577 else $Output .= '<td> </td>'; 566 578 $Output .= '</tr>'; … … 577 589 $Where = '1'; 578 590 579 $DailyTableMaxId = 'SELECT * FROM (SELECT MAX(Id) AS MaxId FROM `'.$Table.'Stat` AS T1 WHERE T1.'.$Table.'='.$Id.' GROUP BY DATE(Time)) AS T2 LEFT JOIN '.$Table.'Stat AS T3 ON T3.Id=T2.MaxId'; 580 $DailyTableMinId = 'SELECT * FROM (SELECT MIN(Id) AS MinId FROM `'.$Table.'Stat` AS T1 WHERE T1.'.$Table.'='.$Id.' GROUP BY DATE(Time)) AS T2 LEFT JOIN '.$Table.'Stat AS T3 ON T3.Id=T2.MinId'; 591 $TableStat = $Table.'Stat'; 592 $DailyTableMaxId = 'SELECT * FROM (SELECT MAX(Id) AS MaxId FROM '.$TableStat.' AS T1 WHERE T1.'.$Table.'='.$Id.' GROUP BY DATE(Time)) AS T2 LEFT JOIN '.$TableStat.' AS T3 ON T3.Id=T2.MaxId'; 593 $DailyTableMinId = 'SELECT * FROM (SELECT MIN(Id) AS MinId FROM '.$TableStat.' AS T1 WHERE T1.'.$Table.'='.$Id.' GROUP BY DATE(Time)) AS T2 LEFT JOIN '.$TableStat.' AS T3 ON T3.Id=T2.MinId'; 581 594 $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$DailyTableMaxId.') AS B'); 582 595 $DbRow = $DbResult->fetch_row(); … … 598 611 $Output .= '<table class="WideTable">'; 599 612 $Output .= $Order['Output']; 600 $DbResult = $this->Database->query('SELECT * '. 601 ', (SELECT T4.Distance - B.Distance + 1.5 FROM ('.$DailyTableMinId.') AS B WHERE (DATE(B.Time) = DATE(T4.Time)) AND (B.'.$Table.' = T4.'.$Table.') ORDER BY B.Time DESC LIMIT 1) AS Length'. 602 ', (SELECT TIME_TO_SEC(TIMEDIFF(T4.Time, B.Time)) / (Length - 1.5) * Length FROM ('.$DailyTableMinId.') AS B WHERE (DATE(B.Time) = DATE(T4.Time)) AND (B.'.$Table.' = T4.'.$Table.') ORDER BY B.Time DESC LIMIT 1) AS Duration'. 603 ', NULL AS Speed'. 604 ' FROM ('.$DailyTableMaxId.') AS T4'. 605 ' WHERE '.$Where.$Order['SQL'].$PageList['SQLLimit']); 613 614 if ($this->LapLength == 0) 615 { 616 $DbResult = $this->Database->query('SELECT * '. 617 ', COALESCE((SELECT T4.Distance - B.Distance FROM ('.$DailyTableMaxId.') AS B WHERE (DATE(B.Time) < DATE(T4.Time)) AND (B.'.$Table.' = T4.'.$Table.') ORDER BY B.Time DESC LIMIT 1), T4.Distance) AS Length'. 618 ', NULL AS Duration'. 619 ', NULL AS Speed'. 620 ' FROM ('.$DailyTableMaxId.') AS T4'. 621 ' WHERE '.$Where.$Order['SQL'].$PageList['SQLLimit']); 622 } else 623 { 624 $DbResult = $this->Database->query('SELECT * '. 625 ', COALESCE((SELECT T4.Distance - B.Distance FROM ('.$DailyTableMaxId.') AS B WHERE (DATE(B.Time) < DATE(T4.Time)) AND (B.'.$Table.' = T4.'.$Table.') ORDER BY B.Time DESC LIMIT 1), T4.Distance) AS Length'. 626 //', (SELECT COUNT(*) * '.$this->LapLength.' FROM '.$TableStat.' AS B WHERE (DATE(B.Time) = DATE(T4.Time)) AND (B.'.$Table.' = T4.'.$Table.')) AS LapLength'. 627 ', (SELECT TIME_TO_SEC(TIMEDIFF(T4.Time, B.Time)) / (Length - '.$this->LapLength.') * Length FROM ('.$DailyTableMinId.') AS B WHERE (DATE(B.Time) = DATE(T4.Time)) AND (B.'.$Table.' = T4.'.$Table.') ORDER BY B.Time DESC LIMIT 1) AS Duration'. 628 ', NULL AS Speed'. 629 ' FROM ('.$DailyTableMaxId.') AS T4'. 630 ' WHERE '.$Where.$Order['SQL'].$PageList['SQLLimit']); 631 } 606 632 while ($Item = $DbResult->fetch_assoc()) 607 633 { … … 700 726 if (!is_numeric($RunnerId)) die(T('Runner id needs to be numeric')); 701 727 702 $DbResult = $this->Database->query('SELECT Runner.Name, Team.Name AS TeamName, Team.Id AS TeamId FROM Runner LEFT JOIN Team ON Team.Id=Runner.Team WHERE Runner.Id='.$RunnerId);728 $DbResult = $this->Database->query('SELECT Runner.Name, Team.Name AS TeamName, Team.Id AS TeamId, Team.Year FROM Runner LEFT JOIN Team ON Team.Id=Runner.Team WHERE Runner.Id='.$RunnerId); 703 729 $DbRow = $DbResult->fetch_assoc(); 704 730 $this->Title = T('Runner').' '.$DbRow['Name'].' - '.$this->Title; … … 707 733 $Output .= '<div class="section-title"><a href="'.$this->Link('/team/'.$DbRow['TeamId']).'">'.$DbRow['TeamName'].'</a></div>'; 708 734 $Output .= '<div class="section-title">'.$this->ItemsYearList('/runner/', $RunnerId, 'Runner', 'Name="'.$DbRow['Name'].'"').'</div>'; 735 $this->LoadYearParameters($DbRow['Year']); 709 736 710 737 $Output .= $this->ShowDetailed('Runner', $RunnerId); … … 732 759 } 733 760 if ($Year == 0) $Year = $this->GetLatestYear(); 761 $this->LoadYearParameters($Year); 734 762 return $Year; 735 763 } … … 876 904 } 877 905 906 function LoadYearParameters($Year) 907 { 908 $DbResult = $this->Database->query('SELECT * FROM `Year` WHERE `Year`.`Year`='.$Year); 909 if ($DbResult->num_rows > 0) 910 { 911 $DbRow = $DbResult->fetch_assoc(); 912 $this->LapLength = $DbRow['LapLength']; 913 $this->MoneyKm = $DbRow['MoneyKm']; 914 } 915 } 916 878 917 function Run() 879 918 { … … 917 956 $this->LocaleManager->LoadLocale($this->LocaleManager->LangCode); 918 957 } 958 InitPrefixMultipliers(); 919 959 920 960 if (GetRemoteAddress() != '')
Note:
See TracChangeset
for help on using the changeset viewer.