-
Notifications
You must be signed in to change notification settings - Fork 0
/
country.php
executable file
·186 lines (168 loc) · 5.16 KB
/
country.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php include("header.php");
$_SESSION['returnPage'] = $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
?>
<div id="xsnazzy">
<b class="xtop"><b class="xb1"></b><b class="xb2"></b><b class="xb3"></b><b class="xb4"></b></b>
<div class="xboxcontent">
<p> </p>
<?
function showLeagues($country_id,$season_id)
{
// Include language file for translations
//include("./lang/lang-en.php");
?>
<div style="margin:0 auto 0 auto;">
<?
$mysqli = new mysqli('DATABASE SERVER','DATABASE USERNAME','DATABASE PASSWORD','DATABASE NAME');
$mysqli->set_charset("utf8");
$level=0;
$query = "
SELECT
l.level, l.id, l.name, l.timestamp
FROM
league l
WHERE l.season = '".$season_id."' AND l.countryid='".$country_id."'
ORDER BY l.level,l.id
";
$items = $mysqli->query($query) or die("Database Query Failed!<pre>".$query."</pre>".mysqli_error($mysqli));
while ($return = mysqli_fetch_array($items))
{
if ($return['level'] != $level)
{
$level=$return['level'];
?>
</tbody>
</table>
<table class="sortable">
<thead>
<tr><td colspan=3 style="text-align:center; font-weight:bold;">Level <? echo $level; ?></td></tr>
<tr>
<th class="header"><a href="#">League ID</a></th>
<th class="header"><a href="#">League Name</a></th>
<th class="header"><a href="#">Last Update</a></th>
</tr>
</thead>
<tbody>
<? } ?>
<tr>
<td align="center"><a href="league.php?league=<? echo $return['id']; ?>&season=<? echo $season_id; ?>"><? echo $return['id']; ?></a></td>
<td align="center"><a href="league.php?league=<? echo $return['id']; ?>&season=<? echo $season_id; ?>"><? echo $return['name']; ?></a></td>
<td><?
if ($return['timestamp']) echo date('Y-m-d', $return['timestamp']);
else echo 'never'; ?></td>
</tr>
<?
}
$mysqli->close();
?>
</tbody>
</table>
</div>
<?
}
if ($_SESSION['loggedin'] == true)
{
if ($_GET['country'])
{
$country_id = $_GET['country'];
}
else
{
$country_id = $_SESSION['countryId'];
}
if ($_GET['season'])
{
$season_id = $_GET['season'];
}
else
{
$season_id = $_SESSION['defaultSeason'];
}
$session_id=$_SESSION['id'];
$session_username=$_SESSION['bbusername'];
$session_key=$_SESSION['bbaccesskey'];
}
else
{
?>
<center>
Please login <a href="bblogin.php">HERE</a>.<br>
<?
if ($_GET['country'])
{
$country_id=$_GET['country'];
}
else
{
echo "<br><i>Below is a random country to demonstrate the site's content.</i><br>";
$country_id=rand(1,90);
}
if ($_GET['season'])
{
$season_id=$_GET['season'];
}
else
{
$season_id=$_SESSION['defaultSeason'];
}
$session_id=session_id();
$session_username='API USERNAME';
$session_key='API KEY';
$mysqli = new mysqli('DATABASE SERVER','DATABASE USERNAME','DATABASE PASSWORD','DATABASE NAME');
$mysqli->set_charset("utf8");
//get name
$query="SELECT id, name, divisions FROM countries WHERE id='".$country_id."'";
$items = $mysqli->query($query) or die("Country Check Failed!");
while($return = mysqli_fetch_array($items))
{
$country_name=$return['name'];
}
$mysqli->close();
?></center><?
}
echo '<div id="loader"><center>Please Wait ... BBStats is updating the leagues in this country<br>
<img id="loader" src="/themes/'.$_SESSION['theme'].'/images/ajax-loader.gif" alt="Loading"></center></div>';
flush(); //flush everything to the browser that has been loaded so far
$mysqli = new mysqli('DATABASE SERVER','DATABASE USERNAME','DATABASE PASSWORD','DATABASE NAME');
$mysqli->set_charset("utf8");
$query =
"SELECT
timestamp
FROM
latest_posting lpd
WHERE lpd.type='country'
AND id='".$country_id."'";
$items = $mysqli->query($query) or die("Database Query Failed!<pre>".$query."</pre>".mysqli_error($mysqli));
$country = mysqli_fetch_array($items);
//$difference = date("U", strtotime(date("Y-m-d H:i:s"))) - date("U", strtotime($player['update']));
$difference = date('U') - $country['timestamp'];
$update_time=date('U');
$manager = new ThreadManager; // create thread manager
$query="SELECT id, name, divisions FROM countries WHERE id='".$country_id."'";
$items = $mysqli->query($query) or die("Country Check Failed!");
while($return = mysqli_fetch_array($items))
{
$country_name=$return['name'];
if($difference > 86400)
{
for($i=1;$i<=$return['divisions'];$i++)
{
//Update leagues in a country
//$manager->create_thread('updateAllLeagues', array($return['id'],$i,$season_id,$update_time,$session_id,$session_username,$session_key,$_SESSION['buzzWebsite']));
updateAllLeagues($return['id'],$i,$season_id,$update_time,$session_id,$session_username,$session_key,$_SESSION['buzzWebsite']);
}
}
}
while ($manager->query());
$mysqli->close();
echo '<script type="text/javascript">document.getElementById("loader").style.display="none"</script>';
?><center><h2>League Listing</h2>
<h3>Country: <? echo $country_name; ?></h3><?
showLeagues($country_id,$season_id);
?>
</center>
<p> </p>
</div>
<b class="xbottom"><b class="xb4"></b><b class="xb3"></b><b class="xb2"></b><b class="xb1"></b></b>
</div>
<?php include("footer.php"); ?>