Advertisement
Guest User

Untitled

a guest
Jun 18th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.33 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * MyLeagues 1.0 for MyBB
  5.  * Main page
  6.  * @author Filip Klar <[email protected]>
  7.  */
  8.  
  9. define("IN_MYBB", 1);
  10. define("THIS_SCRIPT", "myleagues.php");
  11.  
  12. require_once "./global.php";
  13. require_once "./inc/class_myleagues.php";
  14. $myleagues = new myleagues;
  15. $lang->load("myleagues");
  16.  
  17. if($mybb->settings['myleagues'] == 0) { // Checks if it's activated.
  18.     error_no_permission(); 
  19. }
  20.  
  21. // Gets the informations about the league from the database.
  22.    
  23. $lid = intval($mybb->input['lid']);
  24. $league = $db->fetch_array($db->simple_select("myleagues_leagues", "*", "`lid` = {$lid}"));
  25. $number_of_matches = $db->num_rows($db->simple_select("myleagues_matches", "`mid`", "`league` = {$lid}"));
  26. $list_of_teams = array_filter(explode(";", $league['teams']));
  27. $number_of_teams = count($list_of_teams);
  28.  
  29. $title = $league['name']." ".$league['season'];
  30.  
  31. if(empty($league) || ($league['public'] == "no" && $mybb->user['ismoderator'] !== 1) || ($number_of_matches == 0 && $mybb->input['action'] !== "teams") || ($number_of_teams == 0 && $mybb->input['action'] == "teams")) {
  32.     error_no_permission(); 
  33. }
  34.  
  35.  
  36. // Shows the league table.
  37.  
  38. if($mybb->input['action'] == "ranking") {
  39.    
  40.     if($league['wordforgoals']) {
  41.         $wordforgoals = $league['wordforgoals'];
  42.     }
  43.     else {
  44.         $wordforgoals = $lang->myleagues_goals;
  45.     }
  46.    
  47.    
  48.     // Processes the colors.
  49.    
  50.     $colors_array = explode("\n", $league['colors']);
  51.    
  52.     foreach($colors_array as $value) {
  53.         $temp = explode("|", $value);
  54.         $colors[$temp[0]] = trim($temp[1]);
  55.     }
  56.    
  57.     $columns = explode(",", $league['columns']);
  58.    
  59.    
  60.     // Prints the header of the table. 
  61.    
  62.     $content .= "<table border=\"0\" cellspacing=\"{$theme['borderwidth']}\" cellpadding=\"{$theme['tablespace']}\" class=\"tborder\">\n";
  63.     $content .= "<thead>\n";
  64.     $content .= "<tr><td class=\"thead\" colspan=\"10\"><strong>{$lang->myleagues_table} - {$league['name']} {$league['season']}</strong></td></tr>\n";
  65.     $content .= "</thead>\n";
  66.    
  67.     $content .= "<tr>\n";
  68.     $content .= "<td class=\"tcat\" align=\"center\"><span class=\"smalltext\"><strong>{$lang->myleagues_place}</strong></span></td>\n";
  69.     $content .= "<td class=\"tcat\"><span class=\"smalltext align_left\"><strong>{$lang->myleagues_team}</strong></span></td>\n";
  70.    
  71.     if(in_array("points", $columns)) {
  72.         $content .= "<td class=\"tcat\" align=\"center\"><span class=\"smalltext\"><strong>{$lang->myleagues_points}</strong></span></td>\n";
  73.     }
  74.    
  75.     if(in_array("goals", $columns)) {
  76.         $content .= "<td class=\"tcat\" align=\"center\"><span class=\"smalltext\"><strong>{$wordforgoals}</strong></span></td>\n";
  77.     }
  78.    
  79.     if(in_array("difference", $columns)) {
  80.         $content .= "<td class=\"tcat\" align=\"center\"><span class=\"smalltext\"><strong>{$lang->myleagues_difference}</strong></span></td>\n";
  81.     }
  82.    
  83.     if(in_array("matches", $columns)) {
  84.         $content .= "<td class=\"tcat\" align=\"center\"><span class=\"smalltext\"><strong>{$lang->myleagues_matches}</strong></span></td>\n";
  85.     }
  86.    
  87.     if(in_array("wins", $columns)) {
  88.         $content .= "<td class=\"tcat\" align=\"center\"><span class=\"smalltext\"><strong>{$lang->myleagues_wins}</strong></span></td>\n";
  89.     }
  90.    
  91.     if(in_array("draws", $columns)) {
  92.         $content .= "<td class=\"tcat\" align=\"center\"><span class=\"smalltext\"><strong>{$lang->myleagues_draws}</strong></span></td>\n";
  93.     }
  94.    
  95.     if(in_array("losses", $columns)) {
  96.         $content .= "<td class=\"tcat\" align=\"center\"><span class=\"smalltext\"><strong>{$lang->myleagues_losses}</strong></span></td>\n";
  97.     }
  98.    
  99.     $content .= "</tr>\n";
  100.    
  101.    
  102.     // Gets the rows of the league table from the database.    
  103.    
  104.     if($league['sort'] == "goals") {
  105.         $query = $db->query("SELECT `team`, `points`, `goalsfor`, `goalsagainst`, `goalsdifference`, `matches`, `wins`, `draws`, `losses` FROM `".TABLE_PREFIX."myleagues_rows` WHERE `league` = {$lid} ORDER BY `points` DESC, `goalsdifference` DESC, `goalsfor` DESC, `goalsagainst` ASC");
  106.     }
  107.     else {
  108.         $query = $db->query("SELECT `team`, `points`, `goalsfor`, `goalsagainst`, `goalsdifference`, `matches`, `wins`, `draws`, `losses` FROM `".TABLE_PREFIX."myleagues_rows` WHERE `league` = {$lid} ORDER BY `points` DESC, `points2` DESC, `goalsdifference2` DESC, `goalsfor2` DESC, `goalsagainst2` ASC, `goalsdifference` DESC, `goalsfor` DESC, `goalsagainst` ASC");
  109.     }
  110.    
  111.     while($row = $db->fetch_array($query)) {
  112.         foreach($row as $name => $value) {
  113.             $teams[$row['team']][$name] = $value;  
  114.         }
  115.     }
  116.    
  117.     $place = 0;
  118.    
  119.     foreach($teams as $tid => $team) {
  120.        
  121.         $place++;
  122.         $class = $myleagues->trow();
  123.         $team['name'] = $myleagues->get_name($team['team'], "teams");
  124.        
  125.        
  126.         // Processes the color of the current row.
  127.        
  128.         unset($style);
  129.         if(isset($colors[$place])) {
  130.             $style = "style=\"background: {$colors[$place]};\"";
  131.         }
  132.        
  133.        
  134.         // Prints the row.
  135.        
  136.         $content .= "<tr>\n";
  137.         $content .= "<td class=\"{$class}\" align=\"right\" width=\"20px\" {$style}>{$place}.</td>\n";
  138.         $content .= "<td class=\"{$class}\" {$style}>{$team['name']}</td>\n";
  139.        
  140.         if(in_array("points", $columns)) {
  141.             $content .= "<td class=\"{$class}\" align=\"center\" width=\"7%\" {$style}>{$team['points']}</td>\n";
  142.         }
  143.        
  144.         if(in_array("goals", $columns)) {
  145.             $content .= "<td class=\"{$class}\" align=\"center\" width=\"7%\" {$style}>{$team['goalsfor']}:{$team['goalsagainst']}</td>\n";
  146.         }
  147.        
  148.         if(in_array("difference", $columns)) {
  149.             $content .= "<td class=\"{$class}\" align=\"center\" width=\"7%\" {$style}>{$team['goalsdifference']}</td>\n";
  150.         }
  151.        
  152.         if(in_array("matches", $columns)) {
  153.             $content .= "<td class=\"{$class}\" align=\"center\" width=\"7%\" {$style}>{$team['matches']}</td>\n";
  154.         }
  155.        
  156.         if(in_array("wins", $columns)) {
  157.             $content .= "<td class=\"{$class}\" align=\"center\" width=\"7%\" {$style}>{$team['wins']}</td>\n";
  158.         }
  159.        
  160.         if(in_array("draws", $columns)) {
  161.             $content .= "<td class=\"{$class}\" align=\"center\" width=\"7%\" {$style}>{$team['draws']}</td>\n";
  162.         }
  163.        
  164.         if(in_array("losses", $columns)) {
  165.             $content .= "<td class=\"{$class}\" align=\"center\" width=\"7%\" {$style}>{$team['losses']}</td>\n";
  166.         }
  167.        
  168.         $content .= "</tr>\n";
  169.        
  170.     }
  171.    
  172.     $content .= "</table>\n";
  173.    
  174. }
  175.  
  176.  
  177. // Shows the league schedule.
  178.  
  179. elseif($mybb->input['action'] == "schedule") {
  180.    
  181.     // Prints the header of the table. 
  182.    
  183.     $content .= "<table border=\"0\" cellspacing=\"{$theme['borderwidth']}\" cellpadding=\"{$theme['tablespace']}\" class=\"tborder\">\n";
  184.     $content .= "<thead>\n";
  185.     $content .= "<tr><td class=\"thead\" colspan=\"4\"><strong>{$lang->myleagues_schedule} - {$league['name']} {$league['season']}</strong></td></tr>\n";
  186.     $content .= "</thead>\n";
  187.  
  188.    
  189.     // Loads all of the matchdays and matches.
  190.    
  191.     $query = $db->simple_select("myleagues_matchdays", "`mid`, `name`, `startdate`, `enddate`", "`league` = {$lid}", array('order_by' => "no", 'order_dir' => "ASC"));
  192.    
  193.     while($temp_matchday = $db->fetch_array($query)) {
  194.         foreach($temp_matchday as $name => $value) {       
  195.             $matchdays[$temp_matchday['mid']][$name] = $value;
  196.         }  
  197.     }
  198.    
  199.     $query = $db->simple_select("myleagues_matches", "`mid`, `matchday`, `dateline`, `hometeam`, `awayteam`, `homeresult`, `awayresult`", "`league` = {$lid}", array('order_by' => "dateline", 'order_dir' => "ASC"));
  200.    
  201.     while($temp_match = $db->fetch_array($query)) {
  202.         foreach($temp_match as $name => $value) {      
  203.             $matches[$temp_match['matchday']][$temp_match['mid']][$name] = $value;
  204.         }  
  205.     }
  206.    
  207.    
  208.     // Show the matchdays.
  209.    
  210.     foreach($matchdays as $matchday) {
  211.        
  212.         $start = my_date($mybb->settings['dateformat'], $matchday['startdate']);
  213.         $end   = my_date($mybb->settings['dateformat'], $matchday['enddate']);
  214.        
  215.         if($start == $end) {
  216.             $time = $start;
  217.         }
  218.         else {
  219.             $time = $start." - ".$end;
  220.         }
  221.    
  222.         $content .= "<tr>\n";
  223.         $content .= "<td class=\"tcat\" colspan=\"3\"><strong>{$matchday['name']}</strong></td><td class=\"tcat\" align=\"center\">{$time}</span></td>\n";
  224.         $content .= "</tr>\n";
  225.        
  226.         foreach((array) $matches[$matchday['mid']] as $match) {
  227.            
  228.             $class = $myleagues->trow();
  229.        
  230.             $content .= "<tr cellspacing=\"0\">\n";
  231.             $content .= "<td class=\"{$class}\" align=\"right\" width=\"35%\" style=\"padding-right: 10px;\">".$myleagues->get_name($match['hometeam'], "teams")."</td>\n";
  232.             $content .= "<td class=\"{$class}\" align=\"center\">{$match['homeresult']}:{$match['awayresult']}</td>\n";
  233.             $content .= "<td class=\"{$class}\" align=\"left\" width=\"35%\" style=\"padding-left: 10px;\">".$myleagues->get_name($match['awayteam'], "teams")."</td>\n";
  234.             $content .= "<td class=\"{$class}\" align=\"center\">".my_date($mybb->settings['dateformat'], $match['dateline'])." ".my_date($mybb->settings['timeformat'], $match['dateline'])."</td>\n";
  235.             $content .= "</tr>\n";
  236.                
  237.         }
  238.        
  239.     }
  240.    
  241.     $content .= "</table>\n";
  242.    
  243. }
  244.  
  245.  
  246. // Shows the list of the teams.
  247.  
  248. elseif($mybb->input['action'] == "teams") {
  249.  
  250.     $content .= "<table border=\"0\" cellspacing=\"{$theme['borderwidth']}\" cellpadding=\"{$theme['tablespace']}\" class=\"tborder\">\n";
  251.     $content .= "<thead>\n";
  252.     $content .= "<tr><td class=\"thead\" colspan=\"6\"><strong>{$lang->myleagues_list_of_teams} - {$league['name']} {$league['season']}</strong></td></tr>\n";
  253.     $content .= "</thead>\n";
  254.    
  255.     $content .= "<tr>\n";
  256.     $content .= "<td class=\"tcat\" align=\"center\"><span class=\"smalltext\"><strong>{$lang->myleagues_crest}</strong></span></td>\n";
  257.     $content .= "<td class=\"tcat\" align=\"center\"><span class=\"smalltext\"><strong>{$lang->myleagues_name}</strong></span></td>\n";
  258.     $content .= "<td class=\"tcat\" align=\"center\"><span class=\"smalltext\"><strong>{$lang->myleagues_coach}</strong></span></td>\n";
  259.     $content .= "<td class=\"tcat\" align=\"center\"><span class=\"smalltext\"><strong>{$lang->myleagues_ground}</strong></span></td>\n";
  260.     $content .= "<td class=\"tcat\" align=\"center\"><span class=\"smalltext\"><strong>{$lang->myleagues_address}</strong></span></td>\n";
  261.     $content .= "<td class=\"tcat\" align=\"center\"><span class=\"smalltext\"><strong>{$lang->myleagues_website}</strong></span></td>\n";
  262.     $content .= "</tr>\n";
  263.  
  264.    
  265.     $query_teams = "SELECT * FROM `".TABLE_PREFIX."myleagues_teams` WHERE `tid` = 0";
  266.    
  267.     foreach($list_of_teams as $teamid) {
  268.         $query_teams .= " OR `tid` = {$teamid}";   
  269.     }
  270.    
  271.     $query_teams .= " ORDER BY `name` ASC";
  272.    
  273.     $query = $db->query($query_teams);
  274.    
  275.     while($team = $db->fetch_array($query)) {
  276.        
  277.         unset($crest);
  278.         unset($website);
  279.    
  280.         $class = $myleagues->trow();
  281.         $crest_url = $myleagues->crest_url($team['tid']);
  282.        
  283.         if($crest_url) {
  284.             $crest = "<img src=\"{$crest_url}\" alt=\"crest\" style=\"max-width: 70px; max-height: 70px;\" />";
  285.         }
  286.        
  287.         if($team['website']) {
  288.             $website = "<a href=\"{$team['website']}\">{$team['website']}</a>";
  289.         }
  290.        
  291.         $content .= "<tr valign=\"middle\">\n";
  292.         $content .= "<td class=\"{$class}\" align=\"center\">{$crest}</td>\n";
  293.         $content .= "<td class=\"{$class}\">{$team['name']}</td>\n";
  294.         $content .= "<td class=\"{$class}\">{$team['coach']}</td>\n";
  295.         $content .= "<td class=\"{$class}\">{$team['ground']}</td>\n";
  296.         $content .= "<td class=\"{$class}\">{$team['address']}</td>\n";
  297.         $content .= "<td class=\"{$class}\">{$website}</td>\n";
  298.         $content .= "</tr>\n"; 
  299.        
  300.     }
  301.    
  302.     $content .= "</table>\n";
  303.    
  304. }
  305.  
  306. // Prints the ready page.
  307.  
  308. add_breadcrumb($title);
  309. output_page("<html>\n<head>\n<title>{$mybb->settings['bbname']} - {$title}</title>\n{$headerinclude}\n</head>\n<body>\n{$header}\n{$content}\n{$boardstats}\n{$footer}\n</body>\n</html>");
  310.  
  311. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement