Example #1
0
function updateStats($event_id, $time, $serialize = TRUE)
{
    global $sql;
    global $pref;
    $rater = new rater();
    $file = e_PLUGIN . 'ebattles/cache/sql_cache_event_' . $event_id . '.txt';
    $id = array();
    $uid = array();
    $team = array();
    $name = array();
    $avatar = array();
    $games_played = array();
    $ELO = array();
    $Skill = array();
    $G2 = array();
    $win = array();
    $loss = array();
    $draw = array();
    $windrawloss = array();
    $streaks = array();
    $victory_ratio = array();
    $victory_percent = array();
    $unique_opponents = array();
    $opponentsELO = array();
    $score = array();
    $oppscore = array();
    $scorediff = array();
    $points = array();
    $forfeits = array();
    $forfeits_percent = array();
    $banned = array();
    $rating = array();
    $games_played_score = array();
    $ELO_score = array();
    $Skill_score = array();
    $G2_score = array();
    $win_score = array();
    $loss_score = array();
    $draw_score = array();
    $windrawloss_score = array();
    $victory_ratio_score = array();
    $victory_percent_score = array();
    $unique_opponents_score = array();
    $opponentsELO_score = array();
    $streak_score = array();
    $score_score = array();
    $oppscore_score = array();
    $scorediff_score = array();
    $points_score = array();
    $forfeits_score = array();
    $forfeits_percent_score = array();
    /* Event Info */
    $event = new Event($event_id);
    $type = $event->getField('Type');
    $competition_type = $event->getCompetitionType();
    $hide_ratings_column = $event->getField('hide_ratings_column');
    if ($event->getField('RankingType') == "Classic") {
        $hide_ratings_column = TRUE;
    }
    // Update Players stats
    $q_Players = "SELECT " . TBL_PLAYERS . ".*, " . TBL_USERS . ".*" . " FROM " . TBL_PLAYERS . ", " . TBL_GAMERS . ", " . TBL_USERS . " WHERE (" . TBL_PLAYERS . ".Event = '{$event_id}')" . " AND (" . TBL_PLAYERS . ".Gamer = " . TBL_GAMERS . ".GamerID)" . " AND (" . TBL_USERS . ".user_id = " . TBL_GAMERS . ".User)";
    $result_Players = $sql->db_Query($q_Players);
    $numPlayers = mysql_numrows($result_Players);
    $players_rated = 0;
    for ($player = 0; $player < $numPlayers; $player++) {
        // For each player
        $pid = mysql_result($result_Players, $player, TBL_PLAYERS . ".PlayerID");
        $puid = mysql_result($result_Players, $player, TBL_USERS . ".user_id");
        $gamer_id = mysql_result($result_Players, $player, TBL_PLAYERS . ".Gamer");
        $gamer = new Gamer($gamer_id);
        $pname = $gamer->getField('Name');
        $pavatar = mysql_result($result_Players, $player, TBL_USERS . ".user_image");
        $pteam = mysql_result($result_Players, $player, TBL_PLAYERS . ".Team");
        $pgames_played = mysql_result($result_Players, $player, TBL_PLAYERS . ".GamesPlayed");
        $pELO = mysql_result($result_Players, $player, TBL_PLAYERS . ".ELORanking");
        $pTS_mu = mysql_result($result_Players, $player, TBL_PLAYERS . ".TS_mu");
        $pTS_sigma = mysql_result($result_Players, $player, TBL_PLAYERS . ".TS_sigma");
        $pSkill = $pTS_mu - 3 * $pTS_sigma;
        $pG2_r = mysql_result($result_Players, $player, TBL_PLAYERS . ".G2_r");
        $pG2_RD = mysql_result($result_Players, $player, TBL_PLAYERS . ".G2_RD");
        $pG2 = $pG2_r - 2 * $pG2_RD;
        $pwin = mysql_result($result_Players, $player, TBL_PLAYERS . ".Win");
        $pdraw = mysql_result($result_Players, $player, TBL_PLAYERS . ".Draw");
        $ploss = mysql_result($result_Players, $player, TBL_PLAYERS . ".Loss");
        $pstreak = mysql_result($result_Players, $player, TBL_PLAYERS . ".Streak");
        $pstreak_worst = mysql_result($result_Players, $player, TBL_PLAYERS . ".Streak_Worst");
        $pstreak_best = mysql_result($result_Players, $player, TBL_PLAYERS . ".Streak_Best");
        $pwindrawloss = $pwin . "/" . $pdraw . "/" . $ploss;
        $pwinloss = $pwin . "/" . $ploss;
        $pvictory_ratio = $ploss > 0 ? $pwin / $ploss : $pwin;
        //fm- draw here???
        $pvictory_percent = $pwin + $pdraw + $ploss > 0 ? 100 * $pwin / ($pwin + $pdraw + $ploss) : 0;
        $pscore = mysql_result($result_Players, $player, TBL_PLAYERS . ".Score");
        $poppscore = mysql_result($result_Players, $player, TBL_PLAYERS . ".ScoreAgainst");
        $ppoints = mysql_result($result_Players, $player, TBL_PLAYERS . ".Points");
        $pforfeits = mysql_result($result_Players, $player, TBL_PLAYERS . ".Forfeits");
        $pforfeits_percent = $pgames_played > 0 ? 100 * $pforfeits / $pgames_played : 0;
        $pbanned = mysql_result($result_Players, $player, TBL_PLAYERS . ".Banned");
        $popponentsELO = 0;
        $popponents = 0;
        $prating = 0;
        $prating_votes = 0;
        // Unique Opponents
        // Find all matches played by current player
        $q_Matches = "SELECT " . TBL_MATCHS . ".*, " . TBL_SCORES . ".*, " . TBL_PLAYERS . ".*" . " FROM " . TBL_MATCHS . ", " . TBL_SCORES . ", " . TBL_PLAYERS . " WHERE (" . TBL_SCORES . ".MatchID = " . TBL_MATCHS . ".MatchID)" . " AND (" . TBL_MATCHS . ".Status = 'active')" . " AND (" . TBL_PLAYERS . ".PlayerID = " . TBL_SCORES . ".Player)" . " AND (" . TBL_PLAYERS . ".PlayerID = '{$pid}')";
        $result_Matches = $sql->db_Query($q_Matches);
        $numMatches = mysql_numrows($result_Matches);
        $players = array();
        if ($numMatches > 0) {
            for ($match = 0; $match < $numMatches; $match++) {
                // For each match played by current player
                $mID = mysql_result($result_Matches, $match, TBL_MATCHS . ".MatchID");
                $mplayermatchteam = mysql_result($result_Matches, $match, TBL_SCORES . ".Player_MatchTeam");
                // Find all scores/players(+users) for that match
                $q_Scores = "SELECT " . TBL_MATCHS . ".*, " . TBL_SCORES . ".*, " . TBL_PLAYERS . ".*, " . TBL_USERS . ".*" . " FROM " . TBL_MATCHS . ", " . TBL_SCORES . ", " . TBL_PLAYERS . ", " . TBL_GAMERS . ", " . TBL_USERS . " WHERE (" . TBL_MATCHS . ".MatchID = '{$mID}')" . " AND (" . TBL_SCORES . ".MatchID = " . TBL_MATCHS . ".MatchID)" . " AND (" . TBL_PLAYERS . ".PlayerID = " . TBL_SCORES . ".Player)" . " AND (" . TBL_PLAYERS . ".Gamer = " . TBL_GAMERS . ".GamerID)" . " AND (" . TBL_USERS . ".user_id = " . TBL_GAMERS . ".User)";
                $result_Scores = $sql->db_Query($q_Scores);
                $numScores = mysql_numrows($result_Scores);
                for ($scoreIndex = 0; $scoreIndex < $numScores; $scoreIndex++) {
                    $osid = mysql_result($result_Scores, $scoreIndex, TBL_SCORES . ".ScoreID");
                    $ouid = mysql_result($result_Scores, $scoreIndex, TBL_USERS . ".user_id");
                    $oplayermatchteam = mysql_result($result_Scores, $scoreIndex, TBL_SCORES . ".Player_MatchTeam");
                    $oELO = mysql_result($result_Scores, $scoreIndex, TBL_PLAYERS . ".ELORanking");
                    if ($oplayermatchteam != $mplayermatchteam) {
                        $players[] = "{$ouid}";
                        $popponentsELO += $oELO;
                        $popponents += 1;
                    }
                    if ($ouid == $puid) {
                        // Get user rating.
                        $rate = $rater->GetRating("ebscores", $osid);
                        $prating += $rate[0] * ($rate[1] + $rate[2] / 10);
                        $prating_votes += $rate[0];
                    }
                }
            }
        }
        $punique_opponents = count(array_unique($players));
        if ($popponents != 0) {
            $popponentsELO /= $popponents;
        }
        if ($prating_votes != 0) {
            $prating /= $prating_votes;
        }
        // For display
        $id[] = $pid;
        $uid[] = $puid;
        $name[] = $pname;
        $avatar[] = $pavatar;
        $team[] = $pteam;
        $games_played[] = $pgames_played;
        $ELO[] = $pELO;
        $Skill[] = max(0, number_format($pSkill, 0));
        $G2[] = number_format($pG2_r, 0) . " +/- " . number_format($pG2_RD, 0);
        $win[] = $pwin;
        $loss[] = $ploss;
        $draw[] = $pdraw;
        $streaks[] = $pstreak . "|" . $pstreak_best . "|" . $pstreak_worst;
        $windrawloss[] = $pwindrawloss;
        $victory_ratio[] = $pwinloss;
        $victory_percent[] = number_format($pvictory_percent, 2) . "%";
        $unique_opponents[] = $punique_opponents;
        $opponentsELO[] = floor($popponentsELO);
        $score[] = $pgames_played > 0 ? number_format($pscore / $pgames_played, 2) : 0;
        $oppscore[] = $pgames_played > 0 ? number_format($poppscore / $pgames_played, 2) : 0;
        $scorediff[] = $pgames_played > 0 ? number_format(($pscore - $poppscore) / $pgames_played, 2) : 0;
        $points[] = $ppoints;
        $forfeits[] = $pforfeits;
        $forfeits_percent[] = number_format($pforfeits_percent, 2) . "%";
        $banned[] = $pbanned;
        $rating[] = displayRating($prating, $prating_votes);
        // Actual score (not for display)
        $games_played_score[] = $pgames_played;
        $ELO_score[] = $pELO;
        $Skill_score[] = $pSkill;
        $G2_score[] = $pG2;
        $win_score[] = $pwin;
        $loss_score[] = $ploss;
        $draw_score[] = $pdraw;
        $windrawloss_score[] = $pwin - $ploss;
        //fm - ???
        $victory_ratio_score[] = $pvictory_ratio;
        $victory_percent_score[] = $pvictory_percent;
        $unique_opponents_score[] = $punique_opponents;
        $opponentsELO_score[] = $popponentsELO;
        $streaks_score[] = $pstreak_best;
        //max(0,$pstreak_best + $pstreak_worst); //fmarc- TBD
        $score_score[] = $pgames_played > 0 ? $pscore / $pgames_played : 0;
        $oppscore_score[] = $pgames_played > 0 ? -$poppscore / $pgames_played : 0;
        $scorediff_score[] = $pgames_played > 0 ? ($pscore - $poppscore) / $pgames_played : 0;
        $points_score[] = $ppoints;
        $forfeits_score[] = -$pforfeits;
        $forfeits_percent_score[] = -$pforfeits_percent;
        if ($pgames_played >= $event->getField('nbr_games_to_rank') && $pbanned == 0) {
            $players_rated++;
        }
    }
    $rating_max = 0;
    $q_Categories = "SELECT " . TBL_STATSCATEGORIES . ".*" . " FROM " . TBL_STATSCATEGORIES . " WHERE (" . TBL_STATSCATEGORIES . ".Event = '{$event_id}')" . " ORDER BY " . TBL_STATSCATEGORIES . ".CategoryMaxValue DESC";
    $result_Categories = $sql->db_Query($q_Categories);
    $numCategories = mysql_numrows($result_Categories);
    $stat_cat_header = array();
    $stat_min = array();
    $stat_max = array();
    $stat_a = array();
    $stat_b = array();
    $stat_score = array();
    $stat_display = array();
    $cat_index = 0;
    $categories = array();
    for ($category = 0; $category < $numCategories; $category++) {
        $cat_name = mysql_result($result_Categories, $category, TBL_STATSCATEGORIES . ".CategoryName");
        $cat_minpoints = mysql_result($result_Categories, $category, TBL_STATSCATEGORIES . ".CategoryMinValue");
        $cat_maxpoints = mysql_result($result_Categories, $category, TBL_STATSCATEGORIES . ".CategoryMaxValue");
        $cat_InfoOnly = mysql_result($result_Categories, $category, TBL_STATSCATEGORIES . ".InfoOnly");
        if ($cat_maxpoints > 0) {
            //dbg- echo "$cat_name<br>";
            $display_cat = 1;
            switch ($cat_name) {
                case "ELO":
                    $cat_header_title = EB_STATS_L1;
                    $cat_header_text = EB_STATS_L2;
                    $min = min($ELO_score);
                    $max = max($ELO_score);
                    $stat_score[$cat_index] = $ELO_score;
                    $stat_display[$cat_index] = $ELO;
                    break;
                case "Skill":
                    $cat_header_title = EB_STATS_L3;
                    $cat_header_text = EB_STATS_L4;
                    $min = min($Skill_score);
                    $max = max($Skill_score);
                    $stat_score[$cat_index] = $Skill_score;
                    $stat_display[$cat_index] = $Skill;
                    break;
                case "Glicko2":
                    $cat_header_title = EB_STATS_L41;
                    $cat_header_text = EB_STATS_L42;
                    $min = min($G2_score);
                    $max = max($G2_score);
                    $stat_score[$cat_index] = $G2_score;
                    $stat_display[$cat_index] = $G2;
                    break;
                case "GamesPlayed":
                    $cat_header_title = EB_STATS_L5;
                    $cat_header_text = EB_STATS_L6;
                    $min = 0;
                    //min($games_played_score);
                    $max = max($games_played);
                    $stat_score[$cat_index] = $games_played_score;
                    $stat_display[$cat_index] = $games_played;
                    break;
                case "VictoryRatio":
                    $cat_header_title = EB_STATS_L7;
                    $cat_header_text = EB_STATS_L8;
                    $min = 0;
                    //min($victory_ratio_score);
                    $max = max($victory_ratio_score);
                    $stat_score[$cat_index] = $victory_ratio_score;
                    $stat_display[$cat_index] = $victory_ratio;
                    break;
                case "VictoryPercent":
                    $cat_header_title = EB_STATS_L9;
                    $cat_header_text = EB_STATS_L10;
                    $min = 0;
                    //min($victory_percent_score);
                    $max = max($victory_percent_score);
                    $stat_score[$cat_index] = $victory_percent_score;
                    $stat_display[$cat_index] = $victory_percent;
                    break;
                case "WinDrawLoss":
                    $cat_header_title = EB_STATS_L11;
                    $cat_header_text = EB_STATS_L12;
                    $min = min($windrawloss_score);
                    $max = max($windrawloss_score);
                    $stat_score[$cat_index] = $windrawloss_score;
                    $stat_display[$cat_index] = $windrawloss;
                    break;
                case "UniqueOpponents":
                    $cat_header_title = EB_STATS_L13;
                    $cat_header_text = EB_STATS_L14;
                    $min = 0;
                    //min($unique_opponents_score);
                    $max = max($unique_opponents_score);
                    $stat_score[$cat_index] = $unique_opponents_score;
                    $stat_display[$cat_index] = $unique_opponents;
                    break;
                case "OpponentsELO":
                    $cat_header_title = EB_STATS_L15;
                    $cat_header_text = EB_STATS_L16;
                    $min = min($opponentsELO_score);
                    $max = max($opponentsELO_score);
                    $stat_score[$cat_index] = $opponentsELO_score;
                    $stat_display[$cat_index] = $opponentsELO;
                    break;
                case "Streaks":
                    $cat_header_title = EB_STATS_L17;
                    $cat_header_text = EB_STATS_L18;
                    $min = min($streaks_score);
                    $max = max($streaks_score);
                    $stat_score[$cat_index] = $streaks_score;
                    $stat_display[$cat_index] = $streaks;
                    break;
                case "Score":
                    $cat_header_title = EB_STATS_L19;
                    $cat_header_text = EB_STATS_L20;
                    $min = min($score_score);
                    $max = max($score_score);
                    $stat_score[$cat_index] = $score_score;
                    $stat_display[$cat_index] = $score;
                    break;
                case "ScoreAgainst":
                    $cat_header_title = EB_STATS_L21;
                    $cat_header_text = EB_STATS_L22;
                    $min = min($oppscore_score);
                    $max = max($oppscore_score);
                    $stat_score[$cat_index] = $oppscore_score;
                    $stat_display[$cat_index] = $oppscore;
                    break;
                case "ScoreDiff":
                    $cat_header_title = EB_STATS_L23;
                    $cat_header_text = EB_STATS_L24;
                    $min = min($scorediff_score);
                    $max = max($scorediff_score);
                    $stat_score[$cat_index] = $scorediff_score;
                    $stat_display[$cat_index] = $scorediff;
                    break;
                case "Points":
                    $cat_header_title = EB_STATS_L25;
                    $cat_header_text = EB_STATS_L26;
                    $min = min($points_score);
                    $max = max($points_score);
                    $stat_score[$cat_index] = $points_score;
                    $stat_display[$cat_index] = $points;
                    break;
                case "Forfeits":
                    $cat_header_title = EB_STATS_L43;
                    $cat_header_text = EB_STATS_L44;
                    $min = min($forfeits_score);
                    $max = max($forfeits_score);
                    $stat_score[$cat_index] = $forfeits_score;
                    $stat_display[$cat_index] = $forfeits;
                    break;
                case "ForfeitsPercent":
                    $cat_header_title = EB_STATS_L45;
                    $cat_header_text = EB_STATS_L46;
                    $min = min($forfeits_percent_score);
                    $max = max($forfeits_percent_score);
                    $stat_score[$cat_index] = $forfeits_percent_score;
                    $stat_display[$cat_index] = $forfeits_percent;
                    break;
                default:
                    $display_cat = 0;
            }
            if ($display_cat == 1) {
                $stat_InfoOnly[$cat_index] = $cat_InfoOnly;
                switch ($event->getField('RankingType')) {
                    case "CombinedStats":
                        if ($cat_InfoOnly == TRUE) {
                            $cat_header = '<b title="' . $cat_header_title . '">' . $cat_header_text . '</b>';
                        } else {
                            $categories[] = $cat_index;
                            $cat_header = '<b title="' . $cat_header_title . ' [' . number_format($cat_maxpoints, 2) . ' ' . EB_STATS_L27 . ']">' . $cat_header_text . '</b>';
                            /*
                            $cat_header = '
                            <b title="'.$cat_header_title.'">'.$cat_header_text.'</b>
                            <br /><div class="smalltext">['.number_format ($cat_maxpoints,2).'&nbsp;'.EB_STATS_L27.']</div>
                            ';
                            */
                            // a = (ymax-ymin)/(xmax-xmin)
                            // b = ymin - a.xmin
                            if ($max == $min) {
                                $a = 0;
                                $b = $cat_maxpoints;
                            } else {
                                $a = ($cat_maxpoints - $cat_minpoints) / ($max - $min);
                                $b = $cat_minpoints - $a * $min;
                            }
                            $stat_min[$cat_index] = $min;
                            $stat_max[$cat_index] = $max;
                            $stat_a[$cat_index] = $a;
                            $stat_b[$cat_index] = $b;
                            $rating_max += $cat_maxpoints;
                        }
                        break;
                    case "Classic":
                        if ($cat_InfoOnly == TRUE) {
                            $cat_header = '<span title="' . $cat_header_title . '">' . $cat_header_text . '</span>';
                        } else {
                            $cat_header = '<b title="' . $cat_header_title . '">' . $cat_header_text . '</b>';
                            $categories[] = $cat_index;
                        }
                        break;
                    default:
                }
                $stat_cat_header[$cat_index] = $cat_header;
                $cat_index++;
            }
        }
    }
    $numDisplayedCategories = $cat_index;
    $ranks = getRanking($stat_score, $categories);
    $stats = array("0" => array('header', '<b>' . EB_STATS_L28 . '</b>', '<b>' . EB_STATS_L29 . '</b>'));
    // user rating not shown
    // $stats[0][] = '<b>'.EB_STATS_L30.'</b>';
    if ($hide_ratings_column == FALSE) {
        $stats[0][] = '<b title="' . EB_STATS_L31 . ' [' . number_format($rating_max, 2) . ' ' . EB_STATS_L27 . ']">' . EB_STATS_L32 . '</b>';
    }
    //$stats[0][] = '<b title="'.EB_STATS_L31.'">'.EB_STATS_L32.'</b><br /><div class="smalltext">['.number_format ($rating_max,2).'&nbsp;'.EB_STATS_L27.']</div>';
    for ($category = 0; $category < $numDisplayedCategories; $category++) {
        $stats[0][] = $stat_cat_header[$category];
    }
    // Challenge column
    $stats[0][] = "<b>" . EB_CHALLENGE_L1 . "<b>";
    switch ($event->getField('RankingType')) {
        case "CombinedStats":
            $OverallScoreThreshold = 0;
            $final_score = array();
            for ($player = 0; $player < $numPlayers; $player++) {
                $OverallScore[$player] = 0;
                if ($games_played[$player] >= $event->getField('nbr_games_to_rank') && $banned[$player] == 0) {
                    for ($category = 0; $category < $numDisplayedCategories; $category++) {
                        if ($stat_InfoOnly[$category] == FALSE) {
                            $final_score[$category][$player] = $stat_a[$category] * $stat_score[$category][$player] + $stat_b[$category];
                            $OverallScore[$player] += $final_score[$category][$player];
                        }
                    }
                } else {
                    for ($category = 0; $category < $numDisplayedCategories; $category++) {
                        $final_score[$category][$player] = 0;
                    }
                }
                $q_update = "UPDATE " . TBL_PLAYERS . " SET OverallScore = '" . floatToSQL($OverallScore[$player]) . "' WHERE (PlayerID = '{$id[$player]}') AND (Event = '{$event_id}')";
                $result_update = $sql->db_Query($q_update);
            }
            break;
        case "Classic":
            $OverallScoreThreshold = $numPlayers;
            for ($player = 0; $player < $numPlayers; $player++) {
                if ($games_played[$player] >= $event->getField('nbr_games_to_rank') && $banned[$player] == 0) {
                    $OverallScore[$player] = array_search($player, $ranks, false) + $numPlayers + 1;
                } else {
                    $OverallScore[$player] = array_search($player, $ranks, false);
                }
                //dbg: echo "<br>Player $player ($name[$player]), os: $OverallScore[$player]";
                $q_update = "UPDATE " . TBL_PLAYERS . " SET OverallScore = '" . floatToSQL($OverallScore[$player]) . "' WHERE (PlayerID = '{$id[$player]}') AND (Event = '{$event_id}')";
                $result_update = $sql->db_Query($q_update);
            }
            break;
        default:
    }
    // Build results table
    //--------------------
    $q_Players = "SELECT *" . " FROM " . TBL_PLAYERS . " WHERE (Event = '{$event_id}')" . " ORDER BY " . TBL_PLAYERS . ".OverallScore DESC, " . TBL_PLAYERS . ".GamesPlayed DESC, " . TBL_PLAYERS . ".ELORanking DESC, " . TBL_PLAYERS . ".Banned ASC";
    $result_Players = $sql->db_Query($q_Players);
    $ranknumber = 1;
    for ($player = 0; $player < $numPlayers; $player++) {
        $pid = mysql_result($result_Players, $player, TBL_PLAYERS . ".PlayerID");
        $puid = mysql_result($result_Players, $player, TBL_PLAYERS . ".User");
        $prank = mysql_result($result_Players, $player, TBL_PLAYERS . ".Rank");
        $prankdelta = mysql_result($result_Players, $player, TBL_PLAYERS . ".RankDelta");
        $pstreak = mysql_result($result_Players, $player, TBL_PLAYERS . ".Streak");
        // Find index of player
        $index = array_search($pid, $id);
        $prank_side_image = "";
        if ($banned[$index] == 1) {
            $rank = '<span title="' . EB_STATS_L33 . '"><img class="eb_image" src="' . e_PLUGIN . 'ebattles/images/user_delete.ico" alt="' . EB_STATS_L34 . '" title="' . EB_STATS_L34 . '"/></span>';
            $prankdelta_string = "";
            $q_update = "UPDATE " . TBL_PLAYERS . " SET Rank = 0 WHERE (PlayerID = '{$pid}') AND (Event = '{$event_id}')";
            $result_update = $sql->db_Query($q_update);
        } elseif ($OverallScore[$index] <= $OverallScoreThreshold) {
            $rank = '<span title="' . EB_STATS_L35 . '">' . EB_STATS_L36 . '</span>';
            $prankdelta_string = "";
            $q_update = "UPDATE " . TBL_PLAYERS . " SET Rank = 0 WHERE (PlayerID = '{$pid}') AND (Event = '{$event_id}')";
            $result_update = $sql->db_Query($q_update);
        } else {
            $rank = $ranknumber;
            $ranknumber++;
            // increases $ranknumber by 1
            $q_update = "UPDATE " . TBL_PLAYERS . " SET Rank = {$rank} WHERE (PlayerID = '{$pid}') AND (Event = '{$event_id}')";
            $result_update = $sql->db_Query($q_update);
            $new_rankdelta = $prank - $rank;
            if ($new_rankdelta != 0) {
                $prankdelta += $new_rankdelta;
                $q_update = "UPDATE " . TBL_PLAYERS . " SET RankDelta = {$prankdelta} WHERE (PlayerID = '{$pid}') AND (Event = '{$event_id}')";
                $result_update = $sql->db_Query($q_update);
            }
            if ($new_rankdelta != 0 && $rank == 1 && $competition_type == 'Ladder') {
                // Award: player took 1st place
                $q_Awards = "INSERT INTO " . TBL_AWARDS . "(Player,Type,timestamp)\r\n\t\t\t\tVALUES ({$pid},'PlayerTookFirstPlace',{$time})";
                $result_Awards = $sql->db_Query($q_Awards);
            }
            if ($new_rankdelta != 0 && ($prank > 10 || $prank == 0) && $rank <= 10 && $competition_type == 'Ladder') {
                // Award: player enters top 10
                $q_Awards = "INSERT INTO " . TBL_AWARDS . "(Player,Type,timestamp)\r\n\t\t\t\tVALUES ({$pid},'PlayerInTopTen',{$time})";
                $result_Awards = $sql->db_Query($q_Awards);
            }
            $q_Awards = "SELECT " . TBL_AWARDS . ".*, " . TBL_PLAYERS . ".*" . " FROM " . TBL_AWARDS . ", " . TBL_PLAYERS . " WHERE (" . TBL_AWARDS . ".Player = " . TBL_PLAYERS . ".PlayerID)" . " AND (" . TBL_PLAYERS . ".PlayerID = '{$pid}')" . " ORDER BY " . TBL_AWARDS . ".timestamp DESC";
            $result_Awards = $sql->db_Query($q_Awards);
            $numAwards = mysql_numrows($result_Awards);
            if ($numAwards > 0) {
                $paward = mysql_result($result_Awards, 0, TBL_AWARDS . ".AwardID");
                $pawardType = mysql_result($result_Awards, 0, TBL_AWARDS . ".Type");
            }
            if ($rank == 1) {
                $prank_side_image = '<img class="eb_image" src="' . e_PLUGIN . 'ebattles/images/awards/award_star_gold_3.png" alt="' . EB_AWARD_L3 . '" title="' . EB_AWARD_L3 . '"/>';
            } else {
                if ($rank <= 10 && ($rank + $prankdelta > min(10, $numPlayers) || $rank + $prankdelta == 0)) {
                    $prank_side_image = '<img class="eb_image" src="' . e_PLUGIN . 'ebattles/images/awards/award_star_bronze_3.png" alt="' . EB_AWARD_L5 . '" title="' . EB_AWARD_L5 . '"/>';
                } else {
                    if ($numAwards > 0 && $pawardType != 'PlayerTookFirstPlace' && $pawardType != 'PlayerInTopTen' && $pstreak >= 5) {
                        switch ($pawardType) {
                            case 'PlayerStreak5':
                                if ($pstreak >= 5) {
                                    $award = EB_AWARD_L6;
                                    $prank_side_image = '<img class="eb_image" src="' . e_PLUGIN . 'ebattles/images/awards/medal_bronze_3.png" alt="' . EB_AWARD_L7 . '" title="' . EB_AWARD_L7 . '"/>';
                                }
                                break;
                            case 'PlayerStreak10':
                                if ($pstreak >= 10) {
                                    $award = EB_AWARD_L8;
                                    $prank_side_image = '<img class="eb_image" src="' . e_PLUGIN . 'ebattles/images/awards/medal_silver_3.png" alt="' . EB_AWARD_L9 . '" title="' . EB_AWARD_L9 . '"/>';
                                }
                                break;
                            case 'PlayerStreak25':
                                if ($pstreak >= 25) {
                                    $award = EB_AWARD_L10;
                                    $prank_side_image = '<img class="eb_image" src="' . e_PLUGIN . 'ebattles/images/awards/medal_gold_3.png" alt="' . EB_AWARD_L11 . '" title="' . EB_AWARD_L11 . '"/>';
                                }
                                break;
                        }
                    } else {
                        if ($prankdelta > 0) {
                            $prank_side_image = '<img class="eb_image" src="' . e_PLUGIN . 'ebattles/images/arrow_up.gif" alt="+' . $prankdelta . '" title="+' . $prankdelta . '"/>';
                        } else {
                            if ($prankdelta < 0 && $rank + $prankdelta != 0) {
                                $prank_side_image = '<img class="eb_image" src="' . e_PLUGIN . 'ebattles/images/arrow_down.gif" alt="' . $prankdelta . '" title="' . $prankdelta . '"/>';
                            } else {
                                if ($rank + $prankdelta == 0) {
                                    $prank_side_image = '<img class="eb_image" src="' . e_PLUGIN . 'ebattles/images/arrow_up.gif" alt="Up" title="' . EB_STATS_L37 . '"/>';
                                }
                            }
                        }
                    }
                }
            }
        }
        list($pclan, $pclantag, $pclanid) = getClanInfo($team[$index]);
        if (strcmp(USERID, $puid) == 0) {
            $stats_row = array("row_highlight");
        } else {
            $stats_row = array("row");
        }
        $stats_row[] = "<b>{$rank}</b> {$prank_side_image}";
        $image = "";
        if ($pref['eb_avatar_enable_playersstandings'] == 1) {
            if ($avatar[$index]) {
                $image = '<img ' . getAvatarResize(avatar($avatar[$index])) . '/>';
            } else {
                if ($pref['eb_avatar_default_image'] != '') {
                    $image = '<img ' . getAvatarResize(getImagePath($pref['eb_avatar_default_image'], 'avatars')) . '/>';
                }
            }
        }
        $stats_row[] = $image . '&nbsp;<a href="' . e_PLUGIN . 'ebattles/userinfo.php?user='******'"><b>' . $pclantag . $name[$index] . '</b></a>';
        // user rating not shown
        //$stats_row[] = $rating[$index];
        if ($hide_ratings_column == FALSE) {
            $stats_row[] = number_format($OverallScore[$index], 2);
        }
        for ($category = 0; $category < $numDisplayedCategories; $category++) {
            if ($stat_InfoOnly[$category] == TRUE || $event->getField('RankingType') == "Classic") {
                $stats_row[] = $stat_display[$category][$index];
            } else {
                $stats_row[] = $stat_display[$category][$index] . '<br /><div class="smalltext">[' . number_format($final_score[$category][$index], 2) . ']</div>';
            }
        }
        // Add challenge button here
        $challenge_text = ' <a href="javascript:challenge_player_js(\'' . $pid . '\');" title="' . EB_CHALLENGE_L1 . ' ' . $pclantag . $name[$index] . '"><img class="eb_image" src="' . e_PLUGIN . 'ebattles/images/challenge.png" alt="' . EB_CHALLENGE_L1 . ' ' . $pclantag . $name[$index] . '"/></a>';
        $stats_row[] = $challenge_text;
        $stats[] = $stats_row;
    }
    /*
    // debug print array
    print_r($stats);
    print_r($stat_score);
    echo "<br>";
    print_r($ranks);
    */
    if ($serialize) {
        // Serialize results array
        $OUTPUT = serialize($stats);
        $fp = fopen($file, "w");
        // open file with Write permission
        if ($fp == FALSE) {
            // handle error
            $error .= EB_STATS_L38;
            echo $error;
            exit;
        }
        fputs($fp, $OUTPUT);
        fclose($fp);
        /*
        $stats = unserialize(implode('',file($file)));
        foreach ($stats as $id=>$row)
        {
        print $row['category_name']."<br />";
        }
        */
    }
}
Example #2
0
function section_teaminfo()
{
    require_once 'lib/common.php';
    $s_teamid = $_SESSION['teamid'];
    $s_logedin = isAuthenticated();
    $s_level = $_SESSION['level'];
    $s_playerid = $_SESSION['playerid'];
    $id = addslashes($_GET['id']);
    $res = mysql_query("SELECT name, comment, leader, logo, status, score, \n                     unix_timestamp(status_changed) as status_changed, unix_timestamp(created) as ucreated\n    FROM l_team WHERE id='{$id}'");
    $team = mysql_fetch_object($res);
    if (!$team) {
        echo '<BR><CENTER>Specified team does not exist<BR>';
        return;
    }
    echo '<TABLE align=center><TR><TD>' . htmlURLbutton('Opponent summary', 'oppsumm', "id={$id}") . '</td>';
    // Join this team if opened, and if we are logged and not belonging to any team
    if ($s_logedin && !$s_teamid && $members < 20 && $team->status == "opened") {
        echo '<TD>' . htmlURLbutton('Join Team', 'jointhisteam', "id={$id}") . '</td>';
    }
    // Send a message to all the team members
    if ($s_logedin && $team->status != 'deleted') {
        echo '<TD>' . htmlURLbutton('Send BZmessage', 'sendmessage', "tid={$id}") . '</td>';
    }
    echo '</tr></table>';
    if ($team->status == 'deleted') {
        echo '<div class=feedback>';
        if ($team->status_changed) {
            echo "<br><center>This team was deleted on " . gmdate('Y-m-d', $team->status_changed) . "</center>";
        } else {
            echo "<br><center>This team is deleted.</center>";
        }
        echo '</div>';
    }
    echo '<BR><table align=center border=0 cellspacing=0 cellpadding=1>
    <tr><td class=teamName align=center>' . $team->name . '<BR></td></tr>';
    // Logo if any
    if ($team->logo != "") {
        echo '<tr><td align=center>
    <table><TR><TD bgcolor=white><img src="' . $team->logo . '"></td></tr></table>
    <hr></td></tr>';
    }
    // Ratings
    $act45 = teamActivity($id, 45);
    $act90 = teamActivity($id, 90);
    echo '<tr><td> <TABLE align=center>
    <TR><TD width=50% align=right>Created:</td><td width=10></td><td width=50%>' . gmdate('Y-m-d', $team->ucreated) . '</td></tr>
    <TR><TD align=right>Rating:</td><td></td><td>' . displayRating($id) . '</td></tr>
    <TR><TD align=right>Activity:</td><TD></td><td>' . sprintf('%1.2f / %1.2f', $act45, $act90) . '</td></tr>
     <TR><TD colspan=3 align=center>  Average number of games played per day<BR>
     <NOBR>(exponential moving average over last 45 / 90 days)</nobr></td></tr>';
    echo '</td></td></table></td></tr>';
    // Matches statistics
    $sta1 = mysql_fetch_object(mysql_query("select ifnull(sum(if(score1>score2,1,0)),0) win,\n    ifnull(sum(if(score1=score2,1,0)),0) draw,\n    ifnull(sum(if(score1<score2,1,0)),0) loss\n    from " . TBL_MATCH . " where team1={$id}"));
    $sta2 = mysql_fetch_object(mysql_query("select ifnull(sum(if(score2>score1,1,0)),0) win,\n    ifnull(sum(if(score2=score1,1,0)),0) draw,\n    ifnull(sum(if(score2<score1,1,0)),0) loss\n    from " . TBL_MATCH . " where team2={$id}"));
    $win = $sta1->win + $sta2->win;
    $draw = $sta1->draw + $sta2->draw;
    $loss = $sta1->loss + $sta2->loss;
    echo "<tr><td align=center><hr>\n  <table border=0 cellspacing=0 cellpadding=0 align=center><tr>\n  <td align=center>Wins</td><td align=center>&nbsp;&nbsp;Draws&nbsp;&nbsp;</td><td align=center>Losses</td></tr><tr>\n  <td align=center>{$win}</td><td align=center>{$draw}</td><td align=center>{$loss}</td>\n  </tr></table>\n  <hr></td></tr>";
    // Comment if any
    if ($team->comment != "") {
        echo '<tr><td><ul>' . nl2br($team->comment) . '</ul><hr></td></tr>';
    }
    // Players list
    $i = 0;
    if (SHOW_PLAYER_ACTIVE > 0) {
        $activeDays = SHOW_PLAYER_ACTIVE;
    } else {
        $activeDays = 0;
    }
    $res = mysql_query("select id, callsign, comment, status, C.flagname, \n    last_login > subdate(now(), INTERVAL {$activeDays} DAY) as active\n    from l_player\n    left join bzl_countries C on country = C.numcode\n    where team=" . $id . "\n    order by active desc,callsign");
    $members = 0;
    echo '<TR><TD><table border=0 cellspacing=0 cellpadding=0 align=center>';
    while ($obj = mysql_fetch_object($res)) {
        $members++;
        if (++$i & 1) {
            $cl = "rowEven";
        } else {
            $cl = "rowOdd";
        }
        echo "<tr class='{$cl}' valign=middle>";
        echo "<TD align=right><a href='index.php?link=playerinfo&id={$obj->id}'>{$obj->callsign}</a></td><TD>";
        if ($obj->id == $team->leader) {
            echo '&nbsp;<img TITLE="Team Leader" src="' . THEME_DIR . 'leader.gif">';
        }
        echo '</td><TD>';
        if ($obj->active) {
            echo '&nbsp;<img TITLE="Active player (has logged into this site recently)" src="' . THEME_DIR . 'active.gif">';
        }
        echo '</td><TD width=10></td>';
        echo '<TD>' . smallflag($obj->flagname) . '</td>';
        if ($s_logedin && (isFuncAllowed('teamadmin::edit_any_team') || $s_playerid == $team->leader)) {
            if ($obj->id != $team->leader) {
                // Link to ban a player from a team
                echo '<td align=center>' . htmlURLbutSmall('BAN', 'banplayer', "playerid={$obj->id}&teamid={$id}&f_ok_x=2", ADMBUT) . '</form></td></tr>';
            } else {
                echo '<td>&nbsp;</td></tr>';
            }
        } else {
            echo '<td>&nbsp;</td></tr>';
        }
        echo "\n";
    }
    echo '</td></tr></table>';
    // Show last fights
    $sql = "SELECT  t1.id, t1.name, f.score1, t2.id, t2.name, f.score2, f.tsactual, unix_timestamp(f.tsactual) tstamp_ts \n" . "FROM " . TBL_MATCH . " f, l_team t1, l_team t2 " . "WHERE (f.team1 = '{$id}' OR f.team2 = '{$id}') " . " AND f.team1 = t1.id " . " AND f.team2 = t2.id " . "ORDER BY f.tsactual DESC " . "LIMIT 11 ";
    $res = sqlQuery($sql);
    $tmp = '';
    $count = 0;
    while ($row = mysql_fetch_array($res)) {
        $count++;
        if ($count < 11) {
            if (isset($_SESSION['last_login']) && $_SESSION['last_login'] < $row[7]) {
                $new1 = "<font color=\"red\">";
                $new2 = "</font>";
            } else {
                $new1 = '';
                $new2 = '';
            }
            if ($count % 2) {
                $cl = "rowEven";
            } else {
                $cl = "rowOdd";
            }
            $tmp .= "<tr class=\"{$cl}\">";
            $tmp .= '<td align="right">' . $new1 . $row[6] . $new2 . '</td>';
            if ($row[0] != $id) {
                $oppid = $row[0];
                $oppname = stripslashes($row[1]);
                $oppscore = $row[2];
                $teamscore = $row[5];
            } else {
                $oppid = $row[3];
                $oppname = stripslashes($row[4]);
                $oppscore = $row[5];
                $teamscore = $row[2];
            }
            $tmp .= "<td>{$new1}";
            $oppname = '<a href="index.php?link=teaminfo&id=' . $oppid . '&' . SID . '">' . $new1 . $oppname . $new2 . '</a>';
            if ($oppscore < $teamscore) {
                $tmp .= "<b>Won</b> against {$oppname}";
            } elseif ($oppscore > $teamscore) {
                $tmp .= "<b>Lost</b> against {$oppname}";
            } else {
                $tmp .= "<b>Tie</b> against {$oppname}";
            }
            $tmp .= " ({$row[2]} - {$row[5]})";
            $tmp .= "{$new2}</td>";
            $tmp .= "</tr>\n";
        }
    }
    echo '<tr>';
    echo '<td align=center>&nbsp;<br><b>';
    if ($count == 1) {
        echo 'Last match';
    } else {
        if ($count == 11) {
            echo 'Last 10 matches, view them all <a href="index.php?link=fights&id=' . $id . '&' . SID . '">here</a>';
        } elseif ($count == 0) {
            echo "No matches played";
        } else {
            echo "Last {$count} matches";
        }
    }
    echo '</b><BR><BR></td></tr><TR><TD>';
    echo "<table align=center border=0>{$tmp}</table>";
    // Or... edit your team if you are a leader or ad admin, or with a password if you are a member
    // Team members can't change the password, though...
    // Unless ofcause the team is deleted
    if ($team->status == 'deleted') {
        if ($team->status_changed) {
            echo "<br><center>This team is deleted as of " . gmdate('Y-m-d', $team->status_changed) . "</center>";
        } else {
            echo "<br><center>This team is deleted.</center>";
        }
    } else {
        if ($s_logedin && (isFuncAllowed('teamadmin::edit_any_team') || $s_teamid == $id)) {
            if (!isFuncAllowed('teamadmin::edit_any_team') && $s_playerid != $team->leader) {
                // Team member, need password
                echo '<form method=post>
          <input type=hidden name=link value=teamadmin>
          <input type=hidden name=id value=' . $id . '>
          <br><center>Enter team password <input type=password size=8 maxlength=8 name=f_password> and 
          ' . htmlFormButton('Edit Team', 'f_edit_x') . '
          </center></form>';
            } else {
                $invites = sqlQuery("SELECT *, l_player.callsign FROM bzl_invites,  l_player\n            WHERE teamid={$id} AND expires > NOW() AND bzl_invites.playerid = l_player.id");
                if (mysql_num_rows($invites) > 0) {
                    echo '<BR><HR>Invitations currently active:<BR><TABLE>';
                    while ($row = mysql_fetch_object($invites)) {
                        echo '<TR><TD width=25></td><TD>' . playerLink($row->playerid, $row->callsign) . "</td><TD width=10></td><TD>(expires: {$row->expires})</td></tr>";
                    }
                    echo '</table><HR>';
                }
                // Team leader or admin, let's go
                echo '<center><BR>
        ' . htmlURLbutton('Edit Team', 'teamadmin', "id={$id}", ADMBUT) . '
        <BR>
        ' . htmlURLbutton('Dismiss Team', 'dismissteam', "id={$id}", ADMBUT);
            }
        }
    }
}
Example #3
0
 $q_Scores = "SELECT " . TBL_SCORES . ".*, " . TBL_PLAYERS . ".*" . " FROM " . TBL_SCORES . ", " . TBL_PLAYERS . " WHERE (" . TBL_PLAYERS . ".PlayerID = " . TBL_SCORES . ".Player)" . " AND (" . TBL_PLAYERS . ".PlayerID = '{$player_id}')";
 $result_Scores = $sql->db_Query($q_Scores);
 $numScores = mysql_numrows($result_Scores);
 $prating = 0;
 $prating_votes = 0;
 for ($scoreIndex = 0; $scoreIndex < $numScores; $scoreIndex++) {
     $sid = mysql_result($result_Scores, $scoreIndex, TBL_SCORES . ".ScoreID");
     // Get user rating.
     $rate = $rater->GetRating("ebscores", $sid);
     $prating += $rate[0] * ($rate[1] + $rate[2] / 10);
     $prating_votes += $rate[0];
 }
 if ($prating_votes != 0) {
     $prating /= $prating_votes;
 }
 $rating = displayRating($prating, $prating_votes);
 $text .= '<tr>';
 $text .= '<td class="eb_td">';
 $text .= '<a href="' . e_PLUGIN . 'ebattles/eventinfo.php?eventid=' . $event_id . '">' . $event->getField('Name') . '</a>';
 $text .= '</td>';
 //$text .= '<td class="eb_td">';
 //$text .= '<img '.getGameIconResize($gIcon).'/> '.$gName;
 //$text .= '</td>';
 $text .= '<td class="eb_td">';
 $text .= $pRank;
 $text .= '</td>';
 $text .= '<td class="eb_td">';
 $text .= $pWinLoss;
 $text .= '</td>';
 $text .= '<td class="eb_td">';
 $text .= $rating;
Example #4
0
function section_teams()
{
    require_once "lib/common.php";
    $s_logedin = isAuthenticated();
    $s_teamid = $_SESSION['teamid'];
    $tacts = teamActivity(null, 45);
    echo '<BR>';
    $res = sqlQuery("\n    SELECT  l_team.id, l_team.name, l_team.logo, l_team.score, \n        player2.callsign leader, player2.id leaderid, \n        l_team.status, count(distinct l_player.callsign) numplayers,\n        l_team.active = 'yes' activeteam, l_team.matches, l_team.matches > 0 sorter\n    FROM  l_team, l_player player2, l_player\n    WHERE player2.id = l_team.leader \n     AND l_team.status != 'deleted' \n     AND l_player.team = l_team.id\n    GROUP BY l_team.name, l_team.leader, l_team.status, l_team.score\n    ORDER BY  sorter desc, activeteam desc, l_team.score desc,  l_team.name");
    echo "<table align=center border=0 cellspacing=0 cellpadding=2>\n      <tr class=tabhead align=center>\n      <td>Name</td><td>Leader</td><td colspan=2>Members</td>\n      <td colspan=2>Rating</td><td>Join</td><TD>Activity</td></tr>";
    $separated = 0;
    $rownum = 0;
    while ($obj = mysql_fetch_object($res)) {
        ++$rownum;
        if ($obj->activeteam == 0 && $separated == 0) {
            $separated = 1;
            echo '<tr><td align=center colspan=10><hr><b>Inactive Teams</b></td></tr>';
            $rownum = 1;
        }
        if ($obj->sorter == 0 && $separated == 1) {
            $separated = 2;
            echo '<tr><td align=center colspan=10><hr><b>Did not play any match</b></td></tr>';
            $rownum = 1;
        }
        if ($obj->logo != '') {
            $logo = '<img src="' . THEME_DIR . 'islogo.gif">';
        } else {
            $logo = ' ';
        }
        if ($s_teamid == $obj->id) {
            $c = 'myteam';
        } elseif ($obj->status == 'deleted') {
            $c = 'deletedteam';
        } else {
            if ($rownum % 2) {
                $c = 'rowOdd';
            } else {
                $c = 'rowEven';
            }
        }
        echo "<TR class='{$c}' valign=middle>";
        $teamname = substr($obj->name, 0, 35);
        $act = $tacts[$obj->id];
        echo '<td><a href="index.php?link=teaminfo&id=' . $obj->id . '">' . $teamname . '</a></td>
    <td><a href="index.php?link=playerinfo&id=' . $obj->leaderid . '&' . SID . '">' . $obj->leader . '</a></td>
    <td align=center>' . $obj->numplayers . '</td><td>' . $logo . '</td>
    <td align=left>' . displayRating($obj->id) . '</td>';
        if ($separated) {
            echo '<td>&nbsp;</td>';
        } else {
            echo '<td align=center>(' . $obj->matches . ')</td>';
        }
        // Print join or joinnot, not forgetting we may already belong to a team
        echo '<TD align=left>';
        if ($s_logedin) {
            if (!$s_teamid) {
                switch ($obj->status) {
                    case 'opened':
                        if ($obj->numplayers < 20) {
                            echo htmlURLbutSmall('JOIN', 'jointeam', "id={$obj->id}") . '</td>';
                        } else {
                            echo '&nbsp;[Closed]</td>';
                        }
                        break;
                    case 'closed':
                        echo '&nbsp;[Closed]</td>';
                        break;
                    default:
                        echo 'Deleted.</td>';
                        break;
                }
            } else {
                if ($s_teamid == $obj->id) {
                    //          if( $_SESSION['playerid'] != 2074 ) // Dont allow Admir to leave (SC request)
                    echo htmlURLbutSmall('Abandon', 'leaveteam', "id={$obj->id}&leader={$obj->leaderid}") . '</td>';
                } elseif ($obj->status == 'closed') {
                    echo '&nbsp;[Closed]</td>';
                } elseif ($obj->status == 'deleted') {
                    echo 'deleted.</td>';
                } else {
                    echo '</td>';
                }
            }
        } elseif ($obj->status == 'closed') {
            echo '&nbsp;[Closed]</td>';
        } else {
            echo '</td>';
        }
        $act = sprintf('%1.2f', $tacts[$obj->id]);
        echo "<TD align=center>{$act}</td>";
        echo "</tr>";
    }
    echo "</table>";
    // Create a new team, if logged in and not a team member
    if ($s_logedin && !$s_teamid) {
        echo '<br><center>
    ' . htmlURLbutton('Create New Team', 'createteam', null) . '</center>';
    }
}
Example #5
0
    function pageTop($title = false, $endBreak = "true", $ratingItem = "")
    {
        global $this_page, $img_home, $quick_list_truncate, $img_random_play, $cms_mode, $random_play_amounts, $directory_level, $img_up_arrow, $header_drops, $genre_drop, $artist_drop, $album_drop, $quick_drop, $root_dir, $web_root, $song_drop, $audio_types, $video_types, $media_dir, $img_more, $img_random_play_dis, $url_seperator, $help_access, $jukebox, $jukebox_num, $disable_random, $jz_lang_file, $show_slimzora, $img_slim_pop, $allow_resample, $resampleRates, $default_random_type, $default_random_count, $display_previous, $echocloud, $display_recommended, $enable_requests, $enable_ratings, $enable_search, $enable_meta_search, $user_tracking_display, $user_tracking_admin_only, $site_title, $node, $jzUSER, $allow_filesystem_modify, $jukebox_display, $jbArr, $include_path;
        // Let's see if they wanted to pass a title
        if (!$title) {
            $title = $site_title;
        }
        // Let's setup our objects
        $root =& new jzMediaNode();
        $display =& new jzDisplay();
        $blocks = new jzBlocks();
        ?>
			<table class="jz_header_table" width="100%" cellpadding="0" cellspacing="0" border="0">
				<tr class="jz_header_table_tr">
					<td width="80" align="left" valign="top" class="jz_header_table_outer" >
						<table class="" width="80" cellpadding="0" style="padding:5px;" cellspacing="0" border="0">
							<tr class="jz_header_table_tr">
								<td width="80" align="left" valign="top" class="" >
									<nobr>
									<?php 
        // Now let's make sure they can see this
        if ($jzUSER->getSetting("view") === true) {
            // Let's display the home icon
            $display->homeButton();
            // Let's setup the link for the help docs IF they have access to it
            if ($help_access == $_SESSION['jz_access_level'] or $help_access == "all") {
                $item_url = $root_dir . '/docs/' . $jz_lang_file . '/index.html';
                ?>
											<a href="<?php 
                echo $item_url;
                ?>
" onClick="openPopup(this, 500, 500, false, 'Help'); return false;" target="_blank"><?php 
                echo $img_more;
                ?>
</a>
											<?php 
            }
            // Now let's show them the Slimzora popup
            if ($show_slimzora && $jzUSER->getSetting('view') !== false) {
                $display->popupLink("slimzora");
            }
        } else {
            echo "&nbsp;";
        }
        if (checkPermission($jzUSER, "play")) {
            echo '&nbsp';
            $display->popupLink('plmanager');
        }
        // Now let's see if they get the tools menu
        if ($_SESSION['jz_access_level'] == "admin") {
            global $skin, $jz_MenuItemLeft, $jz_MenuSplit, $jz_MenuItemHover, $jz_MainItemHover, $main_img_dir, $jz_MenuItem;
            //include_once($web_root. $root_dir. '/lib/menu/tools-menu.php');
        }
        ?>
								</nobr>
								</td>
							</tr>
						</table>
					</td>
					<td width="100%" valign="top" class="jz_header_table_outer">
						<table width="100%" class="jz_header_table" border="0" cellpadding="0" cellspacing="0" style="padding:5px;">
							<tr class="jz_header_table_tr">
								<td width="50%" valign="top" class="jz_header_table_td">
									<?php 
        // Now let's set the header text
        if ($_SESSION['jz_access_level'] != "noaccess") {
            echo '<span class="jz_headerTitle">' . jzstripslashes($title) . '</span>';
        }
        // Now let's show the rating
        if ($enable_ratings == "true" and $ratingItem != "") {
            echo "&nbsp;" . displayRating($ratingItem, false);
        }
        // Now let's make sure they deleted the "install" directory
        if (is_dir($include_path . "install") and !is_dir($include_path . "CVS")) {
            echo "<br><br><strong>";
            echo word("You're Jinzora installation is NOT secure!!!  You need to delete the 'install' directory to secure your installation!!! - Once you delete the 'install' directory this message will go away");
            echo "</strong><br>";
        }
        // Let's see if there is a file that we want to put in the header here
        //echo returnHeaderText();
        ?>
								</td>
								<td width="50%" valign="top" class="jz_header_table_td" align="right">
									<div align="right">
									
									<?php 
        $display->loginLink();
        echo " | ";
        // Let's see if the user has logged in, and if not let's show that link
        if ($jzUSER->getSetting('admin') and $allow_filesystem_modify == "true") {
            $url_array = array();
            $url_array['jz_path'] = $node->getPath("String");
            $url_array['action'] = "popup";
            $url_array['ptype'] = "uploadmedia";
            echo '<a class="jz_header_table_href" onClick="openPopup(' . "'" . urlize($url_array) . "'" . ',450,400); return false;" href="javascript:;">' . word("Add Media") . '</a> | ';
        }
        if (false !== $display->popupLink("preferences", word("Preferences"))) {
            echo ' | ';
        }
        // Now let's show them the search box
        if ($_SESSION['jz_access_level'] != "noaccess" and $_SESSION['jz_access_level'] != "viewonly" and $_SESSION['jz_access_level'] != "lofi" and $enable_search != "false") {
            $url = array();
            $url['action'] = 'powersearch';
            echo "<a href=\"" . urlize($url) . "\" class=\"jz_header_table_href\">" . word("Search") . "</a>";
            // Now let's see if there is a value for the box
            $value = "";
            if (isset($_POST['search_query'])) {
                $value = $_POST['search_query'];
            }
            if (isset($_GET['song_title'])) {
                $value = $_GET['song_title'];
            }
            ?>
										<?php 
            $onSubmit = "";
            if ($jukebox == "true" && !defined('NO_AJAX_JUKEBOX')) {
                $onSubmit = 'onSubmit="return searchKeywords(this,\'' . htmlentities($this_page) . '\');"';
            }
            if ($cms_mode == "true") {
                $method = "GET";
            } else {
                $method = "POST";
            }
            ?>
										  
											<form action="<?php 
            echo $this_page;
            ?>
" method="<?php 
            echo $method;
            ?>
" name="searchForm" <?php 
            echo $onSubmit;
            ?>
>
											<?php 
            foreach (getURLVars($this_page) as $key => $val) {
                echo '<input type="hidden" name="' . htmlentities($key) . '" value="' . htmlentities($value) . '">';
            }
            ?>
											<input class="jz_input" type="text" name="search_query" size="15" value="<?php 
            echo $value;
            ?>
">
											<select class="jz_select" name="search_type">
												<option value="ALL">All Media</option>
												
												<?php 
            if (distanceTo("artist") !== false) {
                echo '<option value="artists">' . word("Artists") . '</option>' . "\n";
            }
            if (distanceTo("album") !== false) {
                echo '<option value="albums">' . word("Albums") . '</option>' . "\n";
            }
            ?>
												<option value="tracks"><?php 
            echo word("Tracks");
            ?>
</option>
 											    <option value="lyrics"><?php 
            echo word("Lyrics");
            ?>
</option>
											</select>
											<input type="hidden" name="doSearch" value="true">
											<input class="jz_submit" type="submit" name="doSearch" value="<?php 
            echo word("Go");
            ?>
">
											</form>
											</nobr>
										<?php 
        }
        // Let's show them the up arrow, unless they are viewing the first page
        ?>
										<table width="100%" cellpadding="0"><tr><td width="100%" align="right"><div align="right"><nobr>
										   <?php 
        $bcrumbs = $blocks->breadCrumbs();
        // Now let's display the header for the block
        $title = "Browse";
        if ($node->getName() != "") {
            $parent = $node->getParent();
            if ($parent->getName() != "") {
                $title .= " :: " . $parent->getName();
            }
            $title .= " :: " . $node->getName();
        }
        echo $bcrumbs;
        ?>
										</nobr></div></td></tr></table>
										<?php 
        ?>
								</div>
								</td>
							</tr>
						</table>
						<?php 
        // Now, do they want to display where the other users are?
        if ($user_tracking_display == "true") {
            // Now do they only want admins to see this?
            if ($user_tracking_admin_only == "true") {
                if ($_SESSION['jz_access_level'] == "admin") {
                    displayUserTracking();
                }
            } else {
                displayUserTracking();
            }
        }
        ?>
						</td>
					</tr>
				<?php 
        // Now let's see if they are in Jukebox mode, but are NOT an admin they can only stream
        if (checkPermission($jzUSER, "jukebox_queue") && $jukebox_display != "small" && $jukebox_display != "off") {
            jzTableClose();
            echo '<div id="jukebox">' . "\n";
            $blocks->jukeboxBlock();
            echo '</div>', "\n";
            jzTableOpen("100", "0", "jz_header_table");
        }
        // Let's see if they wanted to turn the drop down boxes off
        if ($header_drops == "true") {
            ?>
					<tr class="jz_header_table_tr">
						<td width="100%" align="right" valign="top" class="jz_header_table_outer" colspan="2" style="padding:5px;">
							<table width="100%" cellpadding="0" cellspacing="0" border="0">
								<tr class="jz_header_table_tr">
								<?php 
            if (checkPermission($jzUSER, "jukebox_queue") && ($jukebox_display == "small" or $jukebox_display == "minimal")) {
                ?>
					     <td width="15%" valign="top" class="jz_header_table_td"><div id="smallJukebox">
					     <?php 
                $blocks->smallJukebox(false, 'top');
                ?>
					     
					     </div></td>
					     <?php 
            }
            // Let's make sure they wanted to see the Genre drop down
            if ($genre_drop != "false" && distanceTo("genre") !== false) {
                ?>
											<td width="15%" valign="top" class="jz_header_table_td">
												<?php 
                $display->popupLink("genre");
                ?>
										<br>
										<?php 
                if ($genre_drop == "true") {
                    ?>
										  <form action="<?php 
                    echo $this_page;
                    ?>
" method="GET">
										     <?php 
                    $display->hiddenPageVars();
                    $display->dropdown("genre");
                    ?>
												</form>
												    <?php 
                }
                ?>
											</td>
										<?php 
            }
            // Let's see if they are looking at 2 levels or 3 and show them the artists select box
            if ($artist_drop != "false" && distanceTo("artist") !== false) {
                ?>
											<td width="15%" valign="top" class="jz_header_table_td">
												<?php 
                $display->popupLink("artist");
                ?>
											   <br><?php 
                if ($artist_drop == "true") {
                    ?>
												<form action="<?php 
                    echo $this_page;
                    ?>
" method="GET">
												<?php 
                    $display->hiddenPageVars();
                    $display->dropdown("artist");
                    ?>
												</form> <?php 
                }
                ?>
											</td>
										<?php 
            }
            // Let's see if they are looking at 2 levels or 3 and show them the artists select box
            if ($album_drop != "false" && distanceTo("album") !== false) {
                ?>
											<td width="15%" valign="top" class="jz_header_table_td">
												<?php 
                $display->popupLink("album");
                ?>
											   <br><?php 
                if ($album_drop == "true") {
                    ?>
												<form action="<?php 
                    echo $this_page;
                    ?>
" method="GET">
												<?php 
                    $display->hiddenPageVars();
                    $display->dropdown("album");
                    ?>
												</form><?php 
                }
                ?>
											</td>
										<?php 
            }
            if ($song_drop != "false") {
                ?>
											<td width="15%" valign="top" class="jz_header_table_td">
												<?php 
                $display->popupLink("track");
                ?>
											   <br><?php 
                if ($song_drop == "true") {
                    ?>
												<form action="<?php 
                    echo $this_page;
                    ?>
" method="GET">
												<?php 
                    $display->hiddenPageVars();
                    $display->dropdown("track");
                    ?>
												</form><?php 
                }
                ?>
											</td>
										<?php 
            }
            // Now let's display the random playlist generator
            if ($quick_drop == "true" and $_SESSION['jz_access_level'] != "viewonly" and $_SESSION['jz_access_level'] != "lofi") {
                jzTDOpen("15", "left", "top", "jz_header_table_td", "0");
                echo '<nobr>';
                $blocks->randomGenerateSelector($node);
                echo '</nobr>';
                jzTDClose();
            }
            // Now let's display the resampler
            if ($display->wantResampleDropdown($node)) {
                jzTDOpen("10", "left", "top", "jz_header_table_td", "0");
                $display->displayResampleDropdown($node);
                jzTDClose();
            }
            jzTRClose();
            // Now let's close out
            jzTableClose();
            jzTDClose();
            jzTRClose();
        }
        // This closes our big table above
        jzTableClose();
    }