Parašė Narysx· 2009 Vas. 23 16:02:05
#8
4.
<?php
class NBAM {
public function __construct() {
$this->db = $GLOBALS["db"];
}
public function importDBF($teams_dbf, $players_dbf) {
// players
$dbf = new dbf_class($players_dbf);
$arrRec = $dbf->dbf_record;
foreach($arrRec as $key => $value) {
$pl_id = $value["PLAYERID"];
$player[$pl_id]["pl_id"] = (int)$pl_id;
$player[$pl_id]["pl_team_id"] = (int)$value["TEAM"];
$player[$pl_id]["pl_name"] = $value["NAME"];
$player[$pl_id]["pl_fname"] = $value["FNAME"];
$player[$pl_id]["pl_position"] = (int)$value["POSITION"];
$player[$pl_id]["pl_position1"] = (int)$value["POSITION2"];
$player[$pl_id]["pl_number"] = (int)$value["NUMBER"];
$player[$pl_id]["pl_rosterpos"] = (int)$value["ROSTERPOS"];
$player[$pl_id]["pl_overall"] = (int)$value["OVERALLRTG"];
$player[$pl_id]["pl_speed"] = (int)$value["SPEED"];
$player[$pl_id]["pl_quick"] = (int)$value["QUICK"];
$player[$pl_id]["pl_dribble"] = (int)$value["DRIBBLE"];
$player[$pl_id]["pl_offreb"] = (int)$value["OREABILITY"];
$player[$pl_id]["pl_defreb"] = (int)$value["DREABILITY"];
$player[$pl_id]["pl_dunk"] = (int)$value["DNKABILITY"];
$player[$pl_id]["pl_3pt"] = (int)$value["THREEPTBAS"];
$player[$pl_id]["pl_fg"] = (int)$value["FGPBASE"];
$player[$pl_id]["pl_ft"] = (int)$value["FTPBASE"];
$player[$pl_id]["pl_steal"] = (int)$value["STLABILITY"];
$player[$pl_id]["pl_block"] = (int)$value["BLKABILITY"];
$player[$pl_id]["pl_pass"] = (int)$value["BALABILITY"];
$player[$pl_id]["pl_nr"] = (int)$value["NUMBER"];
$player[$pl_id]["pl_exp"] = (int)$value["YEARSEXP"];
$player[$pl_id]["pl_hand"] = (int)$value["HAND"];
$player[$pl_id]["pl_birth"] = (int)$value["BIRTHDATE"];
$player[$pl_id]["pl_year"] = (int)$value["DRAFTYEAR"];
$player[$pl_id]["pl_draft"] = $value["DRAFTEDBY"];
$player[$pl_id]["pl_dps"] = (int)$value["DPLACE"];
$player[$pl_id]["pl_stam"] = (int)$value["FATIGUE"];
$this->db->insertArray($player[$pl_id], TABLE_PLAYERS);
}
unset($player, $arrRec);
// teams
$dbf = new dbf_class($teams_dbf);
$arrRec = $dbf->dbf_record;
foreach($arrRec as $key => $value) {
$te_id = $value["TEAMNUM"];
$team[$te_id]["te_id"] = (int)$te_id;
$team[$te_id]["te_name"] = $value["TEAMNAME"];
$team[$te_id]["te_city"] = $value["CITYNAME"];
$team[$te_id]["te_abbrev"] = $value["ABBREV"];
$team[$te_id]["te_abbrev1"] = $value["TEAMABR2"];
$team[$te_id]["te_abbrev2"] = $value["TEAMABR4"];
$team[$te_id]["te_division"] = (int)$value["DIVISION"];
$team[$te_id]["te_overall"] = (int)$value["OVERALL"];
$this->db->insertArray($team[$te_id], TABLE_TEAMS);
}
unset($team, $arrRec);
}
public function importGames($data_dir) {
$this->db->query("TRUNCATE ".TABLE_GAMES);
$this->db->query("TRUNCATE ".TABLE_GAMESTATS);
if ($handle = opendir($data_dir)) {
while (false !== ($dir = readdir($handle))) {
if ($dir != "." && $dir != ".." && filetype($data_dir."/".$dir) == "dir") {
$dir = realpath($data_dir."/".$dir);
$this->addGame2($dir);
}
}
closedir($handle);
}
}
public function addGame2($dir) {
$game["date"] = (int)substr($dir, strrpos($dir, "/")+1);
$game["home"] = $this->fetchStats("$dir/home.txt");
$game["away"] = $this->fetchStats("$dir/away.txt");
$sql = "SELECT * FROM ".TABLE_TEAMS." WHERE te_city='".$game["home"]["team"]."'";
$home = $this->db->getRow($sql);
$sql = "SELECT * FROM ".TABLE_TEAMS." WHERE te_city='".$game["away"]["team"]."'";
$away = $this->db->getRow($sql);
$sql = "INSERT INTO ".TABLE_GAMES." (ga_home_id, ga_away_id, ga_home_score, ga_away_score, ga_date) VALUES ($home[te_id], $away[te_id],".$game["home"]["Pts"].",".$game["away"]["Pts"].", $game[date])";
$this->db->query($sql);
$game_id = $this->db->lastID();
foreach ($game["home"]["players"] as $param => $value) {
$s[0] = $value["Pos."]; // pos to int
if ($value["Pos."] == "C") $s[0] = 0;
if ($value["Pos."] == "PF") $s[0] = 1;
if ($value["Pos."] == "SF") $s[0] = 2;
if ($value["Pos."] == "SG") $s[0] = 3;
if ($value["Pos."] == "PG") $s[0] = 4;
$s[1] = addslashes($value["Name"]); //pl_id to int
$sql = "SELECT pl_id FROM ".TABLE_PLAYERS." WHERE pl_team_id=".$home["te_id"]." AND CONCAT(SUBSTRING(pl_fname,1,1),'. ',pl_name) LIKE '%".addslashes($value["Name"])."%' AND (pl_position=$s[0] OR pl_position1=$s[0])";
$s[1] = $this->db->getOne($sql);
$s[2] = (int)$value["Pts"];
$s[3] = (int)$value["Rebs"];
$s[4] = (int)$value["Ast"];
$s[5] = (int)$value["Blk"];
$s[6] = (int)$value["Stl"];
$s[7] = (int)$value["TO"];
$s[8] = (int)$value["Fouls"];
$s[9] = (int)$value["Mins"];
$s[10] = (int)$value["FG/Att"];
$s[11] = (int)substr($value["FG/Att"], strpos($value["FG/Att"], "/")+1);
$s[12] = (int)str_replace(".", "", $value["FG%"]);
$s[13] = (int)$value["3P/Att"];
$s[14] = (int)substr($value["3P/Att"], strpos($value["3P/Att"], "/")+1);
$s[15] = (int)str_replace(".", "", $value["3P%"]);
$s[16] = (int)$value["FT/Att"];
$s[17] = (int)substr($value["FT/Att"], strpos($value["FT/Att"], "/")+1);
$s[18] = (int)str_replace(".", "", $value["FT%"]);
$s[19] = (int)$value["O. Reb"];
$s[20] = (int)$value["D. Reb"];
$sql = "INSERT INTO ".TABLE_GAMESTATS." (st_ga_id,st_te_id,st_pl_id,st_pts,st_rebs,st_ast,st_blk,st_stl,st_to,st_fouls,st_mins,st_fgm,st_fga,st_fgp,st_3pm,st_3pa,st_3pp,st_ftm,st_fta,st_ftp,st_oreb,st_dreb)VALUES ($game_id,$home[te_id],$s[1],$s[2],$s[3],$s[4],$s[5],$s[6],$s[7],$s[8],$s[9],$s[10],$s[11],$s[12],$s[13],$s[14],$s[15],$s[16],$s[17],$s[18],$s[19],$s[20])";
if($s[1]) {
$this->db->query($sql);
}
}
foreach ($game["away"]["players"] as $param => $value) {
$s[0] = $value["Pos."]; // pos to int
if ($value["Pos."] == "C") $s[0] = 0;
if ($value["Pos."] == "PF") $s[0] = 1;
if ($value["Pos."] == "SF") $s[0] = 2;
if ($value["Pos."] == "SG") $s[0] = 3;
if ($value["Pos."] == "PG") $s[0] = 4;
$s[1] = addslashes($value["Name"]); //pl_id to int
$sql = "SELECT pl_id FROM ".TABLE_PLAYERS." WHERE pl_team_id=".$away["te_id"]." AND CONCAT(SUBSTRING(pl_fname,1,1),'. ',pl_name) LIKE '%".addslashes($value["Name"])."%' AND (pl_position=$s[0] OR pl_position1=$s[0])";
$s[1] = $this->db->getOne($sql);
$s[2] = (int)$value["Pts"];
$s[3] = (int)$value["Rebs"];
$s[4] = (int)$value["Ast"];
$s[5] = (int)$value["Blk"];
$s[6] = (int)$value["Stl"];
$s[7] = (int)$value["TO"];
$s[8] = (int)$value["Fouls"];
$s[9] = (int)$value["Mins"];
$s[10] = (int)$value["FG/Att"];
$s[11] = (int)substr($value["FG/Att"], strpos($value["FG/Att"], "/")+1);
$s[12] = (int)str_replace(".", "", $value["FG%"]);
$s[13] = (int)$value["3P/Att"];
$s[14] = (int)substr($value["3P/Att"], strpos($value["3P/Att"], "/")+1);
$s[15] = (int)str_replace(".", "", $value["3P%"]);
$s[16] = (int)$value["FT/Att"];
$s[17] = (int)substr($value["FT/Att"], strpos($value["FT/Att"], "/")+1);
$s[18] = (int)str_replace(".", "", $value["FT%"]);
$s[19] = (int)$value["O. Reb"];
$s[20] = (int)$value["D. Reb"];
$sql = "INSERT INTO ".TABLE_GAMESTATS." (st_ga_id,st_te_id,st_pl_id,st_pts,st_rebs,st_ast,st_blk,st_stl,st_to,st_fouls,st_mins,st_fgm,st_fga,st_fgp,st_3pm,st_3pa,st_3pp,st_ftm,st_fta,st_ftp,st_oreb,st_dreb)VALUES ($game_id,$away[te_id],$s[1],$s[2],$s[3],$s[4],$s[5],$s[6],$s[7],$s[8],$s[9],$s[10],$s[11],$s[12],$s[13],$s[14],$s[15],$s[16],$s[17],$s[18],$s[19],$s[20])";
if($s[1]) {
$this->db->query($sql);
}
}
return $game_id;
}
public function addGame($dir) {
$game["date"] = (int)substr($dir, strrpos($dir, "/")+1);
$game["home"] = $this->fetchStats("$dir/home.txt");
$game["away"] = $this->fetchStats("$dir/away.txt");
$sql = "SELECT * FROM ".TABLE_TEAMS." WHERE te_city='".$game["home"]["team"]."'";
$home = $this->db->getRow($sql);
$sql = "SELECT * FROM ".TABLE_TEAMS." WHERE te_city='".$game["away"]["team"]."'";
$away = $this->db->getRow($sql);
$sql = "INSERT INTO ".TABLE_GAMES." (ga_home_id, ga_away_id, ga_home_score, ga_away_score, ga_date) VALUES ($home[te_id], $away[te_id],".$game["home"]["Pts"].",".$game["away"]["Pts"].", $game[date])";
$this->db->query($sql);
$game_id = $this->db->lastID();
if($game["home"]["Pts"] > $game["away"]["Pts"])
{
list($win_name) = mysql_fetch_array(mysql_query("SELECT user_name FROM qwerty813asd1_users WHERE user_te_id='$home[te_id]'"));
list($lose_name) = mysql_fetch_array(mysql_query("SELECT user_name FROM qwerty813asd1_users WHERE user_te_id='$away[te_id]'"));
}
else
{
list($win_name) = mysql_fetch_array(mysql_query("SELECT user_name FROM qwerty813asd1_users WHERE user_te_id='$away[te_id]'"));
list($lose_name) = mysql_fetch_array(mysql_query("SELECT user_name FROM qwerty813asd1_users WHERE user_te_id='$home[te_id]'"));
}
if($win_name)
{
if(!mysql_fetch_array(mysql_query("SELECT * FROM qwerty813asd1_users_points WHERE owner_name='$win_name'")))
{
list($idas) = mysql_fetch_array(mysql_query("SELECT user_id FROM qwerty813asd1_users WHERE user_name='$win_name'"));
mysql_query("INSERT INTO qwerty813asd1_users_points (owner_name,owner_id) value('$win_name','$idas')");
}
}
if($lose_name)
{
if(!mysql_fetch_array(mysql_query("SELECT * FROM qwerty813asd1_users_points WHERE owner_name='$lose_name'")))
{
list($idas) = mysql_fetch_array(mysql_query("SELECT user_id FROM qwerty813asd1_users WHERE user_name='$lose_name'"));
mysql_query("INSERT INTO qwerty813asd1_users_points (owner_name,owner_id) value('$lose_name','$idas')");
}
mysql_query("UPDATE qwerty813asd1_users_points SET points_total=points_total+100 WHERE owner_name='$win_name'");
mysql_query("UPDATE qwerty813asd1_users_points SET points_total=points_total+50 WHERE owner_name='$lose_name'");
}
foreach ($game["home"]["players"] as $param => $value) {
$s[0] = $value["Pos."]; // pos to int
if ($value["Pos."] == "C") $s[0] = 0;
if ($value["Pos."] == "PF") $s[0] = 1;
if ($value["Pos."] == "SF") $s[0] = 2;
if ($value["Pos."] == "SG") $s[0] = 3;
if ($value["Pos."] == "PG") $s[0] = 4;
$s[1] = addslashes($value["Name"]); //pl_id to int
$sql = "SELECT pl_id FROM ".TABLE_PLAYERS." WHERE pl_team_id=".$home["te_id"]." AND CONCAT(SUBSTRING(pl_fname,1,1),'. ',pl_name) LIKE '%".addslashes($value["Name"])."%' AND (pl_position=$s[0] OR pl_position1=$s[0])";
$s[1] = $this->db->getOne($sql);
$s[2] = (int)$value["Pts"];
$s[3] = (int)$value["Rebs"];
$s[4] = (int)$value["Ast"];
$s[5] = (int)$value["Blk"];
$s[6] = (int)$value["Stl"];
$s[7] = (int)$value["TO"];
$s[8] = (int)$value["Fouls"];
$s[9] = (int)$value["Mins"];
$s[10] = (int)$value["FG/Att"];
$s[11] = (int)substr($value["FG/Att"], strpos($value["FG/Att"], "/")+1);
$s[12] = (int)str_replace(".", "", $value["FG%"]);
$s[13] = (int)$value["3P/Att"];
$s[14] = (int)substr($value["3P/Att"], strpos($value["3P/Att"], "/")+1);
$s[15] = (int)str_replace(".", "", $value["3P%"]);
$s[16] = (int)$value["FT/Att"];
$s[17] = (int)substr($value["FT/Att"], strpos($value["FT/Att"], "/")+1);
$s[18] = (int)str_replace(".", "", $value["FT%"]);
$s[19] = (int)$value["O. Reb"];
$s[20] = (int)$value["D. Reb"];
$sql = "INSERT INTO ".TABLE_GAMESTATS." (st_ga_id,st_te_id,st_pl_id,st_pts,st_rebs,st_ast,st_blk,st_stl,st_to,st_fouls,st_mins,st_fgm,st_fga,st_fgp,st_3pm,st_3pa,st_3pp,st_ftm,st_fta,st_ftp,st_oreb,st_dreb)VALUES ($game_id,$home[te_id],$s[1],$s[2],$s[3],$s[4],$s[5],$s[6],$s[7],$s[8],$s[9],$s[10],$s[11],$s[12],$s[13],$s[14],$s[15],$s[16],$s[17],$s[18],$s[19],$s[20])";
if($s[1]) {
$this->db->query($sql);
}
}
foreach ($game["away"]["players"] as $param => $value) {
$s[0] = $value["Pos."]; // pos to int
if ($value["Pos."] == "C") $s[0] = 0;
if ($value["Pos."] == "PF") $s[0] = 1;
if ($value["Pos."] == "SF") $s[0] = 2;
if ($value["Pos."] == "SG") $s[0] = 3;
if ($value["Pos."] == "PG") $s[0] = 4;
$s[1] = addslashes($value["Name"]); //pl_id to int
$sql = "SELECT pl_id FROM ".TABLE_PLAYERS." WHERE pl_team_id=".$away["te_id"]." AND CONCAT(SUBSTRING(pl_fname,1,1),'. ',pl_name) LIKE '%".addslashes($value["Name"])."%' AND (pl_position=$s[0] OR pl_position1=$s[0])";
$s[1] = $this->db->getOne($sql);
$s[2] = (int)$value["Pts"];
$s[3] = (int)$value["Rebs"];
$s[4] = (int)$value["Ast"];
$s[5] = (int)$value["Blk"];
$s[6] = (int)$value["Stl"];
$s[7] = (int)$value["TO"];
$s[8] = (int)$value["Fouls"];
$s[9] = (int)$value["Mins"];
$s[10] = (int)$value["FG/Att"];
$s[11] = (int)substr($value["FG/Att"], strpos($value["FG/Att"], "/")+1);
$s[12] = (int)str_replace(".", "", $value["FG%"]);
$s[13] = (int)$value["3P/Att"];
$s[14] = (int)substr($value["3P/Att"], strpos($value["3P/Att"], "/")+1);
$s[15] = (int)str_replace(".", "", $value["3P%"]);
$s[16] = (int)$value["FT/Att"];
$s[17] = (int)substr($value["FT/Att"], strpos($value["FT/Att"], "/")+1);
$s[18] = (int)str_replace(".", "", $value["FT%"]);
$s[19] = (int)$value["O. Reb"];
$s[20] = (int)$value["D. Reb"];
$sql = "INSERT INTO ".TABLE_GAMESTATS." (st_ga_id,st_te_id,st_pl_id,st_pts,st_rebs,st_ast,st_blk,st_stl,st_to,st_fouls,st_mins,st_fgm,st_fga,st_fgp,st_3pm,st_3pa,st_3pp,st_ftm,st_fta,st_ftp,st_oreb,st_dreb)VALUES ($game_id,$away[te_id],$s[1],$s[2],$s[3],$s[4],$s[5],$s[6],$s[7],$s[8],$s[9],$s[10],$s[11],$s[12],$s[13],$s[14],$s[15],$s[16],$s[17],$s[18],$s[19],$s[20])";
if($s[1]) {
$this->db->query($sql);
}
}
return $game_id;
}
public function removeGame($id) {
$sql = "SELECT ga_date FROM ".TABLE_GAMES." WHERE ga_id=$id";
$gameDate = $this->db->getOne($sql);
$gameDir = realpath(DIR_GAMESDATA."/".$gameDate);
$homeFile = "$gameDir/home.txt";
$awayFile = "$gameDir/away.txt";
unlink($homeFile); unlink($awayFile); rmdir($gameDir);
$sql = "DELETE FROM ".TABLE_GAMES." WHERE ga_id=$id";
$this->db->query($sql);
$sql = "DELETE FROM ".TABLE_GAMESTATS." WHERE st_ga_id=$id";
$this->db->query($sql);
}
private function fetchStats($file) {
$txt = file($file);
$team = trim($txt[1]);
$stats["team"]= $team;
$params = $txt[3];
$format = array(12,12,18,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12);
$p = 0;
for ($i=0; $i<=count($format); $i++) {
$h = trim(substr($params, $p, $format[$i]));
if (strlen($h) > 0) $head[$i] = $h;
$p += $format[$i];
}
$txt = array_slice($txt, 5);
foreach ($txt as $line) {
$p = 0;
if (strlen(trim($line)) > 2) {
for ($i=0; $i<=count($format); $i++) {
$h = trim(substr($line, $p, $format[$i]));
if (strlen($h) > 0) $player[$head[$i]] = $h;
$p += $format[$i];
}
$stats["Pts"] += (int)$player["Pts"];
$stats["players"][$player["Name"].$player["Pos."]] = $player;
}
}
return $stats;
}
}
?>
Čia toks NBA turnyrams rezultatų įrašymo funkcijų failas. Jo dėka per .html failą galima įdėti rezultatą ir atsinaujina visa informacija duom. bazėje, + į ftp įsideda prisegti .txt failai. Aš noriu, kad visą to rezultato įdėjimą būtų galima įdėti
php-fusion webe. Jei reikia, štai ir tas.html failas:
{include file="include/header.html"}
<b>Prašome įkelti statistikos failus.</b><br/><br/>
<form action="" method="post" enctype="multipart/form-data">
<input type="hidden" name="step" value="1" />
<input type="hidden" name="command" value="addgame" />
Namų komandos statistika: <br/>
<input type="file" name="home" />
<br/>
Svečių komandos statistika:<br/>
<input type="file" name="away" />
<br/><br/>
Slaptažodis:<br/>
<input type="password" name="password" />
<br/><br/>
<input type="submit" value="Atsiųsti" />
</form>
{include file="include/footer.html"}
Redagavo Narysx· 2009 Vas. 23 16:02:48