From d3841fcbcb98f5e2bbdeb7b89733b8757e848f20 Mon Sep 17 00:00:00 2001 From: Arun Persaud Date: Thu, 2 May 2013 21:19:21 -0700 Subject: CLEANUP: GT,gametype,mygametype variable, make it translatable, some code cleanup --- include/functions.php | 173 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 114 insertions(+), 59 deletions(-) (limited to 'include/functions.php') diff --git a/include/functions.php b/include/functions.php index 3142b02..b48c9df 100644 --- a/include/functions.php +++ b/include/functions.php @@ -985,23 +985,22 @@ function can_call($what,$hash) function display_table_begin () { - global $gameid, $GT, $debug,$INDEX,$defaulttimezone,$session; - global $RULES,$GAME,$gametype; - - $result = DB_query("SELECT User.fullname as name,". - " Hand.position as position, ". - " User.id, ". - " Hand.party as party, ". - " Hand.sickness as sickness, ". - " Hand.point_call, ". - " User.last_login, ". - " Hand.hash, ". - " User.timezone, ". - " User.email ". - " FROM Hand". - " LEFT JOIN User ON User.id=Hand.user_id". - " WHERE Hand.game_id=".DB_quote_smart($gameid). - " ORDER BY position ASC"); + global $gameid; + + $result = DB_query('SELECT User.fullname as name,'. + ' Hand.position as position,'. + ' User.id,'. + ' Hand.party as party,'. + ' Hand.sickness as sickness,'. + ' Hand.point_call,'. + ' User.last_login,'. + ' Hand.hash,'. + ' User.timezone,'. + ' User.email'. + ' FROM Hand'. + ' LEFT JOIN User ON User.id=Hand.user_id'. + ' WHERE Hand.game_id='.DB_quote_smart($gameid). + ' ORDER BY position ASC'); $row0 = DB_fetch_array($result); $row1 = DB_fetch_array($result); @@ -1017,25 +1016,26 @@ function display_table_begin () return; } + + function display_table_end () { - global $gameid, $GT, $debug,$INDEX,$defaulttimezone,$session; - global $RULES,$GAME,$gametype; - - $result = DB_query("SELECT User.fullname as name,". - " Hand.position as position, ". - " User.id, ". - " Hand.party as party, ". - " Hand.sickness as sickness, ". - " Hand.point_call, ". - " User.last_login, ". - " Hand.hash, ". - " User.timezone, ". - " User.email ". - " FROM Hand". - " LEFT JOIN User ON User.id=Hand.user_id". - " WHERE Hand.game_id=".DB_quote_smart($gameid). - " ORDER BY position ASC"); + global $gameid; + + $result = DB_query('SELECT User.fullname as name,'. + ' Hand.position as position,'. + ' User.id,'. + ' Hand.party as party,'. + ' Hand.sickness as sickness,'. + ' Hand.point_call,'. + ' User.last_login,'. + ' Hand.hash,'. + ' User.timezone,'. + ' User.email'. + ' FROM Hand'. + ' LEFT JOIN User ON User.id=Hand.user_id'. + ' WHERE Hand.game_id='.DB_quote_smart($gameid). + ' ORDER BY position ASC'); $row0 = DB_fetch_array($result); $row1 = DB_fetch_array($result); @@ -1053,8 +1053,8 @@ function display_single_user($r,$start=0) { /* start=1, mark starting player, default=0, so the player on the left is not marked */ - global $gameid, $GT, $debug,$INDEX,$defaulttimezone,$session; - global $RULES,$GAME,$gametype; + global $gameid, $debug,$INDEX,$defaulttimezone; + global $RULES,$GAME, $gametype_raw; $name = $r[0]; $pos = $r[1]; @@ -1096,11 +1096,11 @@ function display_single_user($r,$start=0) echo" \n"; /* add hints for poverty, wedding, solo, etc */ - if( $gametype != "solo") + if( $gametype_raw != "solo") if( $RULES["schweinchen"]=="both" && $GAME["schweinchen-who"]==$hash ) echo " Schweinchen.
"; - if($GT=="poverty" && $party=="re") + if($gametype_raw=="poverty" && $party=="re") if($sickness=="poverty" || ($RULES['lowtrump']=='poverty' && $sickness=='lowtrump')) { $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user); @@ -1117,7 +1117,7 @@ function display_single_user($r,$start=0) echo " \n"; - if($GT=="dpoverty") + if($gametype_raw=="dpoverty") if($party=="re") if($sickness=="poverty" || ($RULES['lowtrump']=='poverty' && $sickness=='lowtrump')) { @@ -1151,28 +1151,31 @@ function display_single_user($r,$start=0) echo " \" title=\"poverty2 partner\" />\n"; - if($GT=="wedding" && $party=="re") + if($gametype_raw=="wedding" && $party=="re") if($sickness=="wedding") echo " \"wedding\"\n"; else echo " \n"; - if( (strpos($GT,"solo")!==false) && $party=="re") + if( $gametype_raw=='solo' && $party=="re") { - if(strpos($GT,"queen")!==false) + $solotype = DB_get_solo_by_gameid($gameid); + $GT = get_display_gametype($gameid); + + if($solotype=='queen') echo " \"$GT\"\n"; - else if(strpos($GT,"jack")!==false) + else if($solotype=='jack') echo " \"$GT\"\n"; - else if(strpos($GT,"club")!==false) + else if($solotype=='club') echo " \"$GT\"\n"; - else if(strpos($GT,"spade")!==false) + else if($solotype=='spade') echo " \"$GT\"\n"; - else if(strpos($GT,"heart")!==false) + else if($solotype=='heart') echo " \"$GT\"\n"; - else if(strpos($GT,"trumpless")!==false) + else if($solotype=='trumpless') echo " \"$GT\"\n"; - else if(strpos($GT,"trump")!==false) + else if($solotype=='trump') echo " \"$GT\"\n"; } @@ -1237,12 +1240,12 @@ function display_user_menu($id, $skiphash=NULL) " AND ( Game.status='pre' OR Game.status='play' )". " ORDER BY Game.session" ); else - $result = DB_query("SELECT Hand.hash,Hand.game_id,Game.player from Hand". - " LEFT JOIN Game On Hand.game_id=Game.id". - " WHERE Hand.user_id=".DB_quote_smart($id). - " AND ( Game.player=".DB_quote_smart($id)." OR ISNULL(Game.player) )". + $result = DB_query('SELECT Hand.hash,Hand.game_id,Game.player from Hand'. + ' LEFT JOIN Game On Hand.game_id=Game.id'. + ' WHERE Hand.user_id='.DB_quote_smart($id). + ' AND ( Game.player='.DB_quote_smart($id).' OR ISNULL(Game.player) )'. " AND ( Game.status='pre' OR Game.status='play' )". - " ORDER BY Game.session" ); + ' ORDER BY Game.session' ); $i=0; while( $r = DB_fetch_array($result)) @@ -1293,8 +1296,8 @@ function generate_score_table($session) $player_party = array(); /* get player id from the first game */ - $result = DB_query("SELECT user_id from Hand". - " WHERE Hand.game_id=".DB_quote_smart($gameids[0][0])); + $result = DB_query('SELECT user_id from Hand'. + ' WHERE Hand.game_id='.DB_quote_smart($gameids[0][0])); while( $r = DB_fetch_array($result)) $player[$r[0]] = 0; @@ -1310,18 +1313,18 @@ function generate_score_table($session) foreach($player as $id=>$points) { $party = $player_party[$id][$i][0]; - if($party == "re") - if($gametype=="solo") + if($party == 're') + if($gametype=='solo') $player[$id] += 3*$re_score; else $player[$id] += $re_score; - else if ($party == "contra") + else if ($party == 'contra') $player[$id] -= $re_score; } $score[$i]['gameid'] = $gameid[0] ; $score[$i]['players'] = $player; $score[$i]['points'] = abs($re_score); - $score[$i]['solo'] = ($gametype=="solo"); + $score[$i]['solo'] = ($gametype=='solo'); $i++; } @@ -1743,4 +1746,56 @@ function set_language($l,$type='lang') return; } +function get_display_gametype($gameid) +{ + /* return a readable string that can be displayed to show the game type + * this means hiding silent solo from the user + */ + + $gametype = DB_get_gametype_by_gameid($gameid); + + if ($gametype == 'normal') + $GT = _('normal'); + else if($gametype=='solo') + { + $solotype = DB_get_solo_by_gameid($gameid); + + switch($solotype) + { + case 'trumpless': + $GT = _('trumpless solo'); + break; + case 'jack': + $GT = _('jack solo'); + break; + case 'queen': + $GT = _('queen solo'); + break; + case 'trump': + $GT = _('trump solo'); + break; + case 'club': + $GT = _('club solo'); + break; + case 'spade': + $GT = _('spade solo'); + break; + case 'heart': + $GT = _('heart solo'); + break; + case 'silent': + $GT = _('normal'); /* this is change compared to $gametype */ + break; + } + } + else if ($gametype == 'wedding') + $GT = _('wedding'); + else if ($gametype == 'poverty') + $GT = _('poverty'); + else if ($gametype == 'dpoverty') + $GT = _('double poverty'); + + return $GT; +} + ?> -- cgit v1.2.3-18-g5258