Changeset 22
- Timestamp:
- Sep 6, 2019, 10:15:26 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/index.php
r21 r22 401 401 ', (SELECT RunnerStat.Rank FROM RunnerStat WHERE RunnerStat.Runner=Runner.Id ORDER BY Time DESC LIMIT 1) AS Rank', 402 402 $Where.$Order['SQL'].$PageList['SQLLimit']); 403 while($ MeetItem = $DbResult->fetch_assoc())403 while($Item = $DbResult->fetch_assoc()) 404 404 { 405 405 $Output .= '<tr>'. 406 '<td><a href="'.$this->Link('/runner/'.$ MeetItem['Id'].'/').'">'.$MeetItem['Name'].'</a></td>'.407 '<td>'.$Gender[$ MeetItem['Gender']].'</td>'.408 '<td>'.$ MeetItem['Distance'].'</td>'.409 '<td>'.$ MeetItem['Money'].'</td>'.410 '<td>'.$ MeetItem['Rank'].'</td>'.411 '<td>'.HumanDateTime(MysqlDateTimeToTime($ MeetItem['Time'])).'</td>'.406 '<td><a href="'.$this->Link('/runner/'.$Item['Id'].'/').'">'.$Item['Name'].'</a></td>'. 407 '<td>'.$Gender[$Item['Gender']].'</td>'. 408 '<td>'.$Item['Distance'].'</td>'. 409 '<td>'.$Item['Money'].'</td>'. 410 '<td>'.$Item['Rank'].'</td>'. 411 '<td>'.HumanDateTime(MysqlDateTimeToTime($Item['Time'])).'</td>'. 412 412 '</tr>'; 413 413 } 414 414 $Output .= '</table>'; 415 415 $Output .= $PageList['Output']; 416 $Output .= '</div>'; 416 $Output .= '</div><br>'; 417 418 $Output .= $this->ShowDetailed('Team', $TeamId); 419 $Output .= $this->ShowDaily('Team', $TeamId); 417 420 418 421 return($Output); … … 484 487 $Output = ''; 485 488 486 $TeamId = 1;489 $TeamId = 0; 487 490 if ((count($this->PathItems) > 0) and ($this->PathItems[count($this->PathItems) - 1] != '')) 488 491 $TeamId = $this->PathItems[count($this->PathItems) - 1]; 489 492 if (!is_numeric($TeamId)) die('TeamId needs to be numeric'); 490 493 491 $DbResult = $this->Database->query('SELECT * FROM Team WHERE Id='.$TeamId); 494 $DbResult = $this->Database->query('SELECT Team.*, '. 495 '(SELECT COUNT(*) FROM Runner WHERE Runner.Team=Team.Id) AS RunnerCount, '. 496 '(SELECT TeamStat.Distance FROM TeamStat WHERE TeamStat.Team=Team.Id ORDER BY TeamStat.Time DESC LIMIT 1) AS Distance, '. 497 '(SELECT TeamStat.Money FROM TeamStat WHERE TeamStat.Team=Team.Id ORDER BY Time DESC LIMIT 1) AS Money, '. 498 '(SELECT TeamStat.Rank FROM TeamStat WHERE TeamStat.Team=Team.Id ORDER BY Time DESC LIMIT 1) AS Rank '. 499 'FROM Team WHERE Id='.$TeamId); 492 500 $DbRow = $DbResult->fetch_assoc(); 493 501 $Output .= '<div class="page-title">Team '.$DbRow['Name'].'</div>'; 494 502 $Output .= '<div class="section-title">Runners: '.$DbRow['RunnerCount'].', Distance: '.$DbRow['Distance'].' km, Money: '.$DbRow['Money'].' Kč, Rank: '.$DbRow['Rank'].'</div>'; 495 503 496 504 $Where = 'Team='.$TeamId; 497 505 506 // Show runners 498 507 $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Runner` WHERE '.$Where); 499 508 $DbRow = $DbResult->fetch_row(); … … 501 510 502 511 $Gender = array('', 'Men', 'Woman', 'Kid'); 503 $Output .= '<div id="list_content">';504 $Output .= $PageList['Output'];505 $TableColumns = array(506 array('Name' => 'Name', 'Title' => 'Name'),507 array('Name' => 'Gender', 'Title' => 'Category'),508 array('Name' => 'Distance', 'Title' => 'Distance'),509 array('Name' => 'Money', 'Title' => 'Money'),510 array('Name' => 'Rank', 'Title' => 'Rank'),511 array('Name' => 'Time', 'Title' => 'Last change'),512 );513 $Order = GetOrderTableHeader($TableColumns, 'Distance', 1);514 $Output .= '<table class="WideTable">';515 $Output .= $Order['Output'];516 $DbResult = $this->Database->select('Runner', '*, '.517 '(SELECT RunnerStat.Distance FROM RunnerStat WHERE RunnerStat.Runner=Runner.Id ORDER BY Time DESC LIMIT 1) AS Distance'.518 ', (SELECT RunnerStat.Money FROM RunnerStat WHERE RunnerStat.Runner=Runner.Id ORDER BY Time DESC LIMIT 1) AS Money'.519 ', (SELECT RunnerStat.Time FROM RunnerStat WHERE RunnerStat.Runner=Runner.Id ORDER BY Time DESC LIMIT 1) AS Time'.520 ', (SELECT RunnerStat.Rank FROM RunnerStat WHERE RunnerStat.Runner=Runner.Id ORDER BY Time DESC LIMIT 1) AS Rank',521 $Where.$Order['SQL'].$PageList['SQLLimit']);522 while($MeetItem = $DbResult->fetch_assoc())523 {524 $Output .= '<tr>'.525 '<td><a href="'.$this->Link('/runner/'.$MeetItem['Id'].'/').'">'.$MeetItem['Name'].'</a></td>'.526 '<td>'.$Gender[$MeetItem['Gender']].'</td>'.527 '<td>'.$MeetItem['Distance'].'</td>'.528 '<td>'.$MeetItem['Money'].'</td>'.529 '<td>'.$MeetItem['Rank'].'</td>'.530 '<td>'.HumanDateTime(MysqlDateTimeToTime($MeetItem['Time'])).'</td>'.531 '</tr>';532 }533 $Output .= '</table>';534 $Output .= $PageList['Output'];535 $Output .= '</div>';536 537 return($Output);538 }539 540 function ShowRunners()541 {542 $Output = '<div class="page-title">Runners</div>';543 544 $Year = 0;545 if ((count($this->PathItems) > 0) and ($this->PathItems[count($this->PathItems) - 1] != ''))546 $Year = $this->PathItems[count($this->PathItems) - 1] * 1;547 if ($Year == 0) $Year = $this->GetLatestYear();548 549 $Output .= $this->YearList('/runners/', $Year);550 551 $Where = 'Year='.$Year;552 $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Runner` WHERE '.$Where);553 $DbRow = $DbResult->fetch_row();554 $PageList = GetPageList($DbRow[0]);555 556 $Gender = array('', 'Man', 'Woman', 'Kid');557 512 $Output .= '<div id="list_content">'; 558 513 $Output .= $PageList['Output']; … … 577 532 { 578 533 $Output .= '<tr>'. 579 '<td><a href="'.$this->Link('/runner/'.$ Item['Id'].'/').'">'.$Item['Name'].'</a></td>'.534 '<td><a href="'.$this->Link('/runner/'.$tem['Id'].'/').'">'.$Item['Name'].'</a></td>'. 580 535 '<td>'.$Gender[$Item['Gender']].'</td>'. 581 536 '<td>'.$Item['Distance'].'</td>'. … … 587 542 $Output .= '</table>'; 588 543 $Output .= $PageList['Output']; 589 $Output .= '</div>'; 544 $Output .= '</div><br/>'; 545 546 $Output .= $this->ShowDetailed('Team', $TeamId); 547 $Output .= $this->ShowDaily('Team', $TeamId); 590 548 591 549 return($Output); 592 550 } 593 551 594 function Show Runner()552 function ShowDetailed($Table, $Id) 595 553 { 596 554 $PrefixMultiplier = new PrefixMultiplier(); 597 $Output = ''; 598 599 $RunnerId = 1; 600 if ((count($this->PathItems) > 0) and ($this->PathItems[count($this->PathItems) - 1] != '')) 601 $RunnerId = $this->PathItems[count($this->PathItems) - 1]; 602 if (!is_numeric($RunnerId)) die('Runner id needs to be numeric'); 603 604 $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); 605 $DbRow = $DbResult->fetch_assoc(); 606 $Output .= '<div class="page-title">Runner '.$DbRow['Name'].'</div>'; 607 if ($DbRow['TeamName'] != '') 608 $Output .= '<div class="section-title"><a href="'.$this->Link('/team/'.$DbRow['TeamId']).'">'.$DbRow['TeamName'].'</a></div>'; 609 610 $Where = 'RunnerStat.Runner='.$RunnerId; 611 612 // Show detailed stats 613 $Output .= '<div class="section-title">Detailed</div>'; 614 $DbResult = $this->Database->query('SELECT COUNT(*) FROM `RunnerStat` WHERE '.$Where); 555 556 $Output = '<div class="section-title">Detailed</div>'; 557 $Where = $Table.'Stat.'.$Table.'='.$Id; 558 $DbResult = $this->Database->query('SELECT COUNT(*) FROM `'.$Table.'Stat` WHERE '.$Where); 615 559 $DbRow = $DbResult->fetch_row(); 616 560 $PageList = GetPageList($DbRow[0]); … … 631 575 $Output .= $Order['Output']; 632 576 $DbResult = $this->Database->query('SELECT *'. 633 ', (SELECT TIME_TO_SEC(TIMEDIFF( RunnerStat.Time, B.Time)) FROM RunnerStat AS B WHERE (B.Time < RunnerStat.Time) AND (B.Runner = RunnerStat.Runner) ORDER BY B.Time DESC LIMIT 1) AS Duration'.634 ', (SELECT RunnerStat.Distance - B.Distance FROM RunnerStat AS B WHERE (B.Time < RunnerStat.Time) AND (B.Runner = RunnerStat.Runner) ORDER BY B.Time DESC LIMIT 1) AS Length'.577 ', (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'. 578 ', (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'. 635 579 ', NULL AS Speed'. 636 ' FROM RunnerStat'.580 ' FROM '.$Table.'Stat'. 637 581 ' WHERE '.$Where.$Order['SQL'].$PageList['SQLLimit']); 638 while($ MeetItem = $DbResult->fetch_assoc())582 while($Item = $DbResult->fetch_assoc()) 639 583 { 640 584 $Output .= '<tr>'. 641 '<td>'.HumanDateTime(MysqlDateTimeToTime($ MeetItem['Time'])).'</td>'.642 '<td>'.$ MeetItem['Distance'].'</td>'.643 '<td>'.$ MeetItem['Money'].'</td>'.644 '<td>'.$ MeetItem['Rank'].'</td>';645 if ($ MeetItem['Duration'] != null) $Output .= '<td>'.$PrefixMultiplier->Add($MeetItem['Duration'], '', 4, 'Time').'</td>';585 '<td>'.HumanDateTime(MysqlDateTimeToTime($Item['Time'])).'</td>'. 586 '<td>'.$Item['Distance'].'</td>'. 587 '<td>'.$Item['Money'].'</td>'. 588 '<td>'.$Item['Rank'].'</td>'; 589 if ($Item['Duration'] != null) $Output .= '<td>'.$PrefixMultiplier->Add($Item['Duration'], '', 4, 'Time').'</td>'; 646 590 else $Output .= '<td> </td>'; 647 $Output .= '<td>'.$ MeetItem['Length'].'</td>';648 if ($ MeetItem['Duration'] > 0) $Output .= '<td>'.$PrefixMultiplier->Add($MeetItem['Length'] / $MeetItem['Duration'] * 3600, '', 4, 'Decimal').'</td>';591 $Output .= '<td>'.$Item['Length'].'</td>'; 592 if ($Item['Duration'] > 0) $Output .= '<td>'.$PrefixMultiplier->Add($Item['Length'] / $Item['Duration'] * 3600, '', 4, 'Decimal').'</td>'; 649 593 else $Output .= '<td> </td>'; 650 594 $Output .= '</tr>'; … … 653 597 $Output .= $PageList['Output']; 654 598 $Output .= '</div><br/>'; 655 656 // Show daily stats 599 return $Output; 600 } 601 602 function ShowDaily($Table, $Id) 603 { 604 $PrefixMultiplier = new PrefixMultiplier(); 657 605 $Where = '1'; 658 606 659 $DailyTableMaxId = 'SELECT * FROM (SELECT MAX(Id) AS MaxId FROM ` RunnerStat` AS T1 WHERE T1.Runner='.$RunnerId.' GROUP BY DATE(Time)) AS T2 LEFT JOIN RunnerStat AS T3 ON T3.Id=T2.MaxId';660 $DailyTableMinId = 'SELECT * FROM (SELECT MIN(Id) AS MinId FROM ` RunnerStat` AS T1 WHERE T1.Runner='.$RunnerId.' GROUP BY DATE(Time)) AS T2 LEFT JOIN RunnerStat AS T3 ON T3.Id=T2.MinId';607 $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'; 608 $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'; 661 609 $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$DailyTableMaxId.') AS B'); 662 610 $DbRow = $DbResult->fetch_row(); 663 611 $PageList = GetPageList($DbRow[0]); 664 612 665 $Output .= '<div class="section-title">Daily</div>';613 $Output = '<div class="section-title">Daily</div>'; 666 614 $Output .= '<div id="list_content">'; 667 615 $Output .= $PageList['Output']; … … 679 627 $Output .= $Order['Output']; 680 628 $DbResult = $this->Database->query('SELECT * '. 681 ', (SELECT T4.Distance - B.Distance + 1.5 FROM ('.$DailyTableMinId.') AS B WHERE (DATE(B.Time) = DATE(T4.Time)) AND (B. Runner = T4.Runner) ORDER BY B.Time DESC LIMIT 1) AS Length'.682 ', (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. Runner = T4.Runner) ORDER BY B.Time DESC LIMIT 1) AS Duration'.629 ', (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'. 630 ', (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'. 683 631 ', NULL AS Speed'. 684 632 ' FROM ('.$DailyTableMaxId.') AS T4'. 685 633 ' WHERE '.$Where.$Order['SQL'].$PageList['SQLLimit']); 686 while($ MeetItem = $DbResult->fetch_assoc())634 while($Item = $DbResult->fetch_assoc()) 687 635 { 688 636 $Output .= '<tr>'. 689 '<td>'.HumanDateTime(MysqlDateTimeToTime($ MeetItem['Time'])).'</td>'.690 '<td>'.$ MeetItem['Distance'].'</td>'.691 '<td>'.$ MeetItem['Money'].'</td>'.692 '<td>'.$ MeetItem['Rank'].'</td>';693 if ($ MeetItem['Duration'] != null) $Output .= '<td>'.$PrefixMultiplier->Add($MeetItem['Duration'], '', 4, 'Time').'</td>';637 '<td>'.HumanDateTime(MysqlDateTimeToTime($Item['Time'])).'</td>'. 638 '<td>'.$Item['Distance'].'</td>'. 639 '<td>'.$Item['Money'].'</td>'. 640 '<td>'.$Item['Rank'].'</td>'; 641 if ($Item['Duration'] != null) $Output .= '<td>'.$PrefixMultiplier->Add($Item['Duration'], '', 4, 'Time').'</td>'; 694 642 else $Output .= '<td> </td>'; 695 $Output .= '<td>'.$ MeetItem['Length'].'</td>';696 if ($ MeetItem['Duration'] > 0) $Output .= '<td>'.$PrefixMultiplier->Add($MeetItem['Length'] / $MeetItem['Duration'] * 3600, '', 4, 'Decimal').'</td>';643 $Output .= '<td>'.$Item['Length'].'</td>'; 644 if ($Item['Duration'] > 0) $Output .= '<td>'.$PrefixMultiplier->Add($Item['Length'] / $Item['Duration'] * 3600, '', 4, 'Decimal').'</td>'; 697 645 else $Output .= '<td> </td>'; 698 646 $Output .= '</tr>'; … … 701 649 $Output .= $PageList['Output']; 702 650 $Output .= '</div>'; 703 651 return $Output; 652 } 653 654 function ShowRunners() 655 { 656 $Output = '<div class="page-title">Runners</div>'; 657 658 $Year = 0; 659 if ((count($this->PathItems) > 0) and ($this->PathItems[count($this->PathItems) - 1] != '')) 660 $Year = $this->PathItems[count($this->PathItems) - 1] * 1; 661 if ($Year == 0) $Year = $this->GetLatestYear(); 662 663 $Output .= $this->YearList('/runners/', $Year); 664 665 $Where = 'Year='.$Year; 666 $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Runner` WHERE '.$Where); 667 $DbRow = $DbResult->fetch_row(); 668 $PageList = GetPageList($DbRow[0]); 669 670 $Gender = array('', 'Man', 'Woman', 'Kid'); 671 $Output .= '<div id="list_content">'; 672 $Output .= $PageList['Output']; 673 $TableColumns = array( 674 array('Name' => 'Name', 'Title' => 'Name'), 675 array('Name' => 'Gender', 'Title' => 'Category'), 676 array('Name' => 'Distance', 'Title' => 'Distance'), 677 array('Name' => 'Money', 'Title' => 'Money'), 678 array('Name' => 'Rank', 'Title' => 'Rank'), 679 array('Name' => 'Time', 'Title' => 'Last change'), 680 ); 681 $Order = GetOrderTableHeader($TableColumns, 'Distance', 1); 682 $Output .= '<table class="WideTable">'; 683 $Output .= $Order['Output']; 684 $DbResult = $this->Database->select('Runner', '*, '. 685 '(SELECT RunnerStat.Distance FROM RunnerStat WHERE RunnerStat.Runner=Runner.Id ORDER BY Time DESC LIMIT 1) AS Distance'. 686 ', (SELECT RunnerStat.Money FROM RunnerStat WHERE RunnerStat.Runner=Runner.Id ORDER BY Time DESC LIMIT 1) AS Money'. 687 ', (SELECT RunnerStat.Time FROM RunnerStat WHERE RunnerStat.Runner=Runner.Id ORDER BY Time DESC LIMIT 1) AS Time'. 688 ', (SELECT RunnerStat.Rank FROM RunnerStat WHERE RunnerStat.Runner=Runner.Id ORDER BY Time DESC LIMIT 1) AS Rank', 689 $Where.$Order['SQL'].$PageList['SQLLimit']); 690 while($Item = $DbResult->fetch_assoc()) 691 { 692 $Output .= '<tr>'. 693 '<td><a href="'.$this->Link('/runner/'.$Item['Id'].'/').'">'.$Item['Name'].'</a></td>'. 694 '<td>'.$Gender[$Item['Gender']].'</td>'. 695 '<td>'.$Item['Distance'].'</td>'. 696 '<td>'.$Item['Money'].'</td>'. 697 '<td>'.$Item['Rank'].'</td>'. 698 '<td>'.HumanDateTime(MysqlDateTimeToTime($Item['Time'])).'</td>'. 699 '</tr>'; 700 } 701 $Output .= '</table>'; 702 $Output .= $PageList['Output']; 703 $Output .= '</div>'; 704 705 return($Output); 706 } 707 708 function ShowRunner() 709 { 710 $PrefixMultiplier = new PrefixMultiplier(); 711 $Output = ''; 712 713 $RunnerId = 0; 714 if ((count($this->PathItems) > 0) and ($this->PathItems[count($this->PathItems) - 1] != '')) 715 $RunnerId = $this->PathItems[count($this->PathItems) - 1]; 716 if (!is_numeric($RunnerId)) die('Runner id needs to be numeric'); 717 718 $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); 719 $DbRow = $DbResult->fetch_assoc(); 720 $Output .= '<div class="page-title">Runner '.$DbRow['Name'].'</div>'; 721 if ($DbRow['TeamName'] != '') 722 $Output .= '<div class="section-title"><a href="'.$this->Link('/team/'.$DbRow['TeamId']).'">'.$DbRow['TeamName'].'</a></div>'; 723 724 $Output .= $this->ShowDetailed('Runner', $RunnerId); 725 $Output .= $this->ShowDaily('Runner', $RunnerId); 704 726 return($Output); 705 727 } … … 779 801 $this->Database->charset($this->Config['Database']['Charset']); 780 802 //$this->Database->ShowSQLError = true; 803 //$this->Database->ShowSQLQuery = true; 781 804 $this->PathItems = $this->ProcessURL(); 782 805
Note:
See TracChangeset
for help on using the changeset viewer.