Location: PHPKode > projects > Skrupel User Game Administration > include/charts.inc.php
<?php
/**
 * @TODO needs optimization -> return array instead of requiring x calls causing x queries
 */
function get_gamecharts($action,$num)
{
        global $skrupel_spiele,$skrupel_schiffe,$skrupel_planeten,$skrupel_user;
        global $DB;

        if ($action == "aktiv"){
  	        $sql = "SELECT * FROM skrupel_user ORDER BY stat_teilnahme desc, stat_monate desc limit 1";
  	        $abf = $DB->query($sql);
                if ($DB->num_rows() < 1)
                {
                        $chart = "k.a.";
                }
                else{
                        while ($DB->next())
                        {
                                if ($num == 1){
                                        $chart = $DB->value("nick");
                                }
                                else if ($num == 2){
                                        $chart = $DB->value("stat_teilnahme");
                                }
                                else if ($num == 3){
                                        $chart = $DB->value("stat_monate");
                                }      
                                else{
                                        $chart = "k.a.";
                                }
                        }
                }
        }
        else if ($action == "teilnahme"){
          	$sql = "SELECT * FROM $skrupel_user ORDER BY stat_teilnahme desc limit 1";
          	$DB->query($sql);
                if ($DB->num_rows() < 1){
                        $chart = "k.a.";
                }
                else{
                        while ($DB->next()){
                                if ($num == 1){
                                        $chart = $DB->value("nick");
                                }
                                else if ($num == 2){
                                        $chart = $DB->value("stat_teilnahme");
                                }
                                else{
                                        $chart = "k.a.";
                                }
                        }
                }
        }
        else if ($action == "siege"){
          	 $sql = "SELECT * FROM $skrupel_user ORDER BY stat_sieg desc limit 1";
          	 $DB->query($sql);
                 if ($DB->num_rows < 1){
                        $chart = "k.a.";
                }
                else{
                        while ($DB->next()){
                                if ($num == 1){
                                        $chart = $DB->value("nick");
                                }
                                else if ($num == 2){
                                        $chart = $DB->value("stat_sieg");
                                }
                                else{
                                        $chart = "k.a.";
                                }
                        }
              }
        }
        else if ($action == "schlachten"){
  	                $sql = "SELECT * FROM $skrupel_user ORDER BY stat_schlacht desc limit 1";
  	                $DB->query($sql);
                if ($DB->num_rows < 1){
                        $chart = "k.a.";
                }
                else{
                        while ($DB->next()){
                                if ($num == 1){
                                        $chart = $DB->value("nick");
                                }
                                else if ($num == 2){
                                        $chart = $DB->value("stat_schlacht");
                                }
                                else{
                                        $chart = "k.a.";
                                }
                        }
                }
        }
        else if ($action == "schlachten_siege"){
                $sql = "SELECT * FROM $skrupel_user ORDER BY stat_schlacht_sieg desc limit 1";
                $DB->query($sql);
                if ($DB->num_rows() < 1){
                        $chart = "k.a.";
                }
                else{
                        while ($DB->next()){
                                if ($num == 1){
                                        $chart = $DB->value("nick");
                                }
                                else if ($num == 2){
                                        $chart = $DB->value("stat_schlacht_sieg");
                                }
                                else{
                                        $chart = "k.a.";
                                }
                        }
                }
        }
        else if ($action == "kolonien"){
  	        $sql = "SELECT * FROM $skrupel_user ORDER BY stat_kol_erobert desc limit 1";
  	        $DB->query($sql);
                if ($DB->num_rows() < 1){
                        $chart = "k.a.";
                }
                else{
                        while ($DB->next()){
                                if ($num == 1){
                                        $chart = $DB->value("nick");
                                }
                                else if ($num == 2){
                                        $chart = $DB->value("stat_kol_erobert");
                                }
                                else{
                                        $chart = "k.a.";
                                }
                        }
                }
        }
        else if ($action == "lichtjahre"){
  	        $sql = "SELECT * FROM $skrupel_user ORDER BY stat_lichtjahre desc limit 1";
  	        $DB->query($sql);
                if ($DB->num_rows() < 1){
                        $chart = "k.a.";
                }
                else{
                        while ($DB->next()){
                                if ($num == 1){
                                        $chart = $DB->value("nick");
                                }
                                else if ($num == 2){
                                        $chart = $DB->value("stat_lichtjahre");
                                }
                                else{
                                        $chart = "k.a.";
                                }
                        }
                }
        }
        else if ($action == "monate"){
  	        $sql = "SELECT * FROM $skrupel_user ORDER BY stat_monate desc limit 1";
  	        $DB->query($sql);
                if ($DB->num_rows() < 1){
                        $chart = "k.a.";
                }
                else{
                        while ($DB->next()){
                                if ($num == 1){
                                        $chart = $DB->value("nick");
                                }
                                else if ($num == 2){
                                        $chart = $DB->value("stat_monate");
                                }
                                else{
                                        $chart = "k.a.";
                                }
                        }
                }
        }
        else if ($action == "offen"){
  	        $sql_stat_monate = "SELECT version FROM $skrupel_info LIMIT 1";
  	        $abf_stat_monate = mysql_query($sql_monate);
        }
        return $chart;
}

function get_game_auto_tick($lasttick_p,$tick_time_p){
        $nexttick=$lasttick_p+(60*60*$tick_time_p);
        $datum_auto=date('d.m.y G:i',$nexttick);
        if (time()>=$nexttick){
                return 0;
        }
        else{
                return $datum_auto;
        }
}

function get_is_auto_tick($lasttick_p,$tick_time_p){
        if(!$tick_time_p){
                return 0;
        }
        $nexttick=$lasttick_p+(60*60*$tick_time_p);
        if (time()>=$nexttick){
                return 1;
        }
        return 0;
}

function get_players_dates($disp_singles,$template_hook='statistic_games'){
        global $skrupel_spiele,$skrupel_user,$spielerfarbe;
        global $DB,$template;
        
        $DB2 = new db_sql;
        
        $sql = "SELECT * FROM $skrupel_spiele ORDER BY name";
        $DB->query($sql);
 
        while($DB->next()){
                
                $id=$DB->value("id");
                
                if(!$disp_singles && ($DB->value("spieleranzahl")==1) ){
                        continue;
                }
                $autotick = "";
                if(get_is_auto_tick($DB->value("lasttick"),$DB->value("autozug"))){
                        $autotick = "AUTO";
                }
                $autotick_when = "";
                if(get_game_auto_tick($DB->value("lasttick"),$DB->value("autozug"))){
                        $autotick_when = $datum_auto;
                }
                
                $template->assign_block_vars('games_row',array('name' => $DB->value("name"),
                                                               'round' => $DB->value("runde"),
                                                               'autotick' => $autotick,
                                                               'autotick_when' => $autotick_when,
                                                               ));
  
                
                           
  
                for($i=1;$i<=10;$i++){
                        $player_num=$DB->value('spieler_'.$i);
                        $player_done=$DB->value('spieler_'.$i.'_zug');
                        $player_gone=$DB->value('spieler_'.$i.'_raus');
                        if($player_num && !$player_done && !$player_gone ){
                                $sql2 = "SELECT nick FROM $skrupel_user WHERE id=$player_num;";
                                $DB2->query($sql2);
                                while($DB2->next()){
                                        $template->assign_block_vars('games_row.player',array('nick'=> $DB2->value("nick"),
                                                                                              'color' =>$spielerfarbe[$i] ));
                                }
                        }
                }
        }     
        $template->assign_var_from_handle($template_hook,'statisticgames');
}
?>
Return current item: Skrupel User Game Administration