summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorArun Persaud <arun@nubati.net>2013-05-02 21:19:21 -0700
committerArun Persaud <arun@nubati.net>2013-05-02 21:20:10 -0700
commitd3841fcbcb98f5e2bbdeb7b89733b8757e848f20 (patch)
treeb18cb623298e64f910f7f3041cea3393cbc96a44 /include
parente6a828bc2f742e617842ff2ca3a9dbb812dab16a (diff)
downloade-DoKo-d3841fcbcb98f5e2bbdeb7b89733b8757e848f20.tar.gz
e-DoKo-d3841fcbcb98f5e2bbdeb7b89733b8757e848f20.tar.bz2
e-DoKo-d3841fcbcb98f5e2bbdeb7b89733b8757e848f20.zip
CLEANUP: GT,gametype,mygametype variable, make it translatable, some code cleanup
Diffstat (limited to 'include')
-rw-r--r--include/functions.php173
-rw-r--r--include/game.php117
-rw-r--r--include/output.php8
3 files changed, 169 insertions, 129 deletions
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" </a>\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. <br />";
- 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 " <img src=\"pics/button/poverty_partner_button.png\" class=\"button\" ".
"alt=\"poverty partner\" title=\"poverty partner\" />\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 " <img src=\"pics/button/poverty2_partner_button.png\" class=\"button\" ".
"alt=\"poverty2 >\" title=\"poverty2 partner\" />\n";
- if($GT=="wedding" && $party=="re")
+ if($gametype_raw=="wedding" && $party=="re")
if($sickness=="wedding")
echo " <img src=\"pics/button/wedding_button.png\" class=\"button\" alt=\"wedding\" title=\"wedding\" />\n";
else
echo " <img src=\"pics/button/wedding_partner_button.png\" class=\"button\" ".
"alt=\"wedding partner\" title=\"wedding partner\" />\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 " <img src=\"pics/button/queensolo_button.png\" class=\"button\" alt=\"$GT\" title=\"Queen solo\" />\n";
- else if(strpos($GT,"jack")!==false)
+ else if($solotype=='jack')
echo " <img src=\"pics/button/jacksolo_button.png\" class=\"button\" alt=\"$GT\" title=\"Jack solo\" />\n";
- else if(strpos($GT,"club")!==false)
+ else if($solotype=='club')
echo " <img src=\"pics/button/clubsolo_button.png\" class=\"button\" alt=\"$GT\" title=\"Club solo\" />\n";
- else if(strpos($GT,"spade")!==false)
+ else if($solotype=='spade')
echo " <img src=\"pics/button/spadesolo_button.png\" class=\"button\" alt=\"$GT\" title=\"Spade solo\" />\n";
- else if(strpos($GT,"heart")!==false)
+ else if($solotype=='heart')
echo " <img src=\"pics/button/heartsolo_button.png\" class=\"button\" alt=\"$GT\" title=\"Heart solo\" />\n";
- else if(strpos($GT,"trumpless")!==false)
+ else if($solotype=='trumpless')
echo " <img src=\"pics/button/notrumpsolo_button.png\" class=\"button\" alt=\"$GT\" title=\"Trumpless solo\" />\n";
- else if(strpos($GT,"trump")!==false)
+ else if($solotype=='trump')
echo " <img src=\"pics/button/trumpsolo_button.png\" class=\"button\" alt=\"$GT\" title=\"Trump solo\" />\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;
+}
+
?>
diff --git a/include/game.php b/include/game.php
index 38cf7e3..541c70a 100644
--- a/include/game.php
+++ b/include/game.php
@@ -65,17 +65,20 @@ set_language($PREF['language']);
$RULES = DB_get_RULES($gameid);
/* get some infos about the game */
-$gametype = DB_get_gametype_by_gameid($gameid);
-$gamestatus = DB_get_game_status_by_gameid($gameid);
-$GT = $gametype;
-if($gametype=='solo')
- {
- $gametype = DB_get_solo_by_gameid($gameid);
- if($gametype=='silent')
- $GT = 'normal';
- else
- $GT = $gametype.' '.$GT;
- }
+$gametype_raw = DB_get_gametype_by_gameid($gameid);
+$gametype_solo = DB_get_solo_by_gameid($gameid);
+
+/* replace solo with the type of solo */
+$gametype = $gametype_raw;
+if($gametype_raw=='solo')
+ $gametype = $gametype_solo;
+
+/* gametype for displaying it (hides hidden solo)*/
+$GT = get_display_gametype($gameid);
+
+$gamestatus = DB_get_game_status_by_gameid($gameid);
+
+
/* do we need to worry about Schweinchen?
* check gametype and rules
@@ -279,7 +282,7 @@ if($session)
$score = generate_score_table($session);
/* get the last entry to show on the main page */
- $tmpscore= $score;
+ $tmpscore = $score;
$finalscore = array_pop($tmpscore);
$finalscore = $finalscore['players'];
@@ -306,7 +309,7 @@ if($session)
* previous and next game if possible
*/
$hashes = DB_get_hashes_by_session($session,$myid);
- $next = NULL;
+ $next = NULL;
$i = 1;
foreach($hashes as $hash)
{
@@ -328,8 +331,11 @@ if($session)
/* check for solo, add game type to session number */
echo ' '._('Game')." $session.$j";
- if($gamestatus != 'pre' && $GT !='normal' )
- echo " ($GT)";
+ if($gamestatus != 'pre')
+ if($gametype_raw != 'normal') /* only show when needed */
+ if(!($gametype_raw == 'solo' && $gametyep_solo == 'silent') )
+ echo " ($GT)";
+
if(isset($_SESSION['id']) && $_SESSION['id']==$myid)
{
if($previous)
@@ -377,9 +383,6 @@ switch($mystatus)
if($myparty=='re' || $myparty=='contra')
{
echo "\n<ul class=\"tricks\">\n";
-
- $mygametype = DB_get_gametype_by_gameid($gameid);
-
echo " <li onclick=\"hl(0);\" class=\"active\"><a href=\"#\">Pre</a>\n";
echo " </li>\n</ul>\n\n"; /* end div trick, end li trick , end ul tricks */
}
@@ -391,15 +394,13 @@ switch($mystatus)
echo "\n<ul class=\"tricks\">\n";
/* output vorbehalte */
- $mygametype = DB_get_gametype_by_gameid($gameid);
- $mygamesolo = DB_get_solo_by_gameid($gameid);
- if($mygametype != 'normal') /* only show when needed */
- if(!( $mygametype == 'solo' && $mygamesolo == 'silent') )
+ if($gametype_raw != 'normal') /* only show when needed */
+ if(!($gametype_raw == 'solo' && $gametyep_solo == 'silent') )
echo " <li onclick=\"hl(0);\" class=\"old\"><a href=\"#\">Pre</a></li>\n";
$result = DB_query('SELECT Trick.id'.
' FROM Trick'.
- " WHERE Trick.game_id=".DB_quote_smart($gameid).
+ ' WHERE Trick.game_id='.DB_quote_smart($gameid).
' GROUP BY Trick.id'.
' ORDER BY Trick.id ASC');
$trickNR = 1;
@@ -565,7 +566,6 @@ switch($mystatus)
$messages[] = _('Processing what you selected in the last step...');
/* check if this sickness needs to be handled first */
- $gametype = DB_get_gametype_by_gameid($gameid);
$startplayer = DB_get_startplayer_by_gameid($gameid); /* need this to check which solo goes first */
if( $_REQUEST['solo']!='No' )
@@ -580,7 +580,7 @@ switch($mystatus)
sprintf(_('Seems like you want to play a %s solo. Got it.'),$_REQUEST['solo']).
"<br />\n";
- if($gametype == 'solo' && $startplayer<$mypos)
+ if($gametype_raw == 'solo' && $startplayer<$mypos)
{}/* do nothing, since someone else already is playing solo */
else
{
@@ -588,8 +588,11 @@ switch($mystatus)
* store info in game table
*/
DB_set_gametype_by_gameid($gameid,'solo');
+ $gametype_raw = 'solo';
DB_set_startplayer_by_gameid($gameid,$mypos);
DB_set_solo_by_gameid($gameid,$_REQUEST['solo']);
+ $gametype_solo = $_REQUEST['solo'];
+ $gametype = $gametype_solo;
};
}
else if($_REQUEST['wedding'] == 'yes')
@@ -662,7 +665,9 @@ switch($mystatus)
$messages[] = _('Ok, everyone is done... figuring out what kind of game we are playing.');
- $gametype = DB_get_gametype_by_gameid($gameid);
+ /* gametype for displaying it (hides hidden solo)*/
+ $GT = get_display_gametype($gameid);
+
$startplayer = DB_get_startplayer_by_gameid($gameid);
/* check for sickness */
@@ -689,7 +694,7 @@ switch($mystatus)
}
/* now check which sickness comes first and set the gametype to it */
- if($gametype == 'solo')
+ if($gametype_raw == 'solo')
{
/* do nothing */
}
@@ -745,7 +750,8 @@ switch($mystatus)
else if($poverty==1) /* one person has poverty */
{
DB_set_gametype_by_gameid($gameid,'poverty');
- $gametype = 'poverty';
+ $gametype_raw = 'poverty';
+ $gametype = 'poverty';
$who = DB_get_sickness_by_gameid($gameid);
if(!$who)
{
@@ -759,7 +765,8 @@ switch($mystatus)
else if($poverty==2) /* two people have poverty */
{
DB_set_gametype_by_gameid($gameid,'dpoverty');
- $gametype = 'dpoverty';
+ $gametype_raw = 'dpoverty';
+ $gametype = 'dpoverty';
$who = DB_get_sickness_by_gameid($gameid);
if(!$who)
{
@@ -780,7 +787,8 @@ switch($mystatus)
{
DB_set_gametype_by_gameid($gameid,'wedding');
DB_set_sickness_by_gameid($gameid,'-1'); /* wedding not resolved yet */
- $gametype = 'wedding';
+ $gametype_raw = 'wedding';
+ $gametype = 'wedding';
};
/* now the gametype is set correctly in the database */
$messages[] = _('Got it').' :)';
@@ -791,7 +799,7 @@ switch($mystatus)
{
$userhash = DB_get_hash_from_gameid_and_userid($gameid,$userid);
- switch($gametype)
+ switch($gametype_raw)
{
case 'solo':
/* are we the solo player? set us to re, else set us to contra */
@@ -839,13 +847,12 @@ switch($mystatus)
}
}
/* check for silent solo, set game type to solo in this case */
- $gametype = DB_get_gametype_by_gameid($gameid);
$userids = DB_get_all_userid_by_gameid($gameid);
foreach($userids as $userid)
{
$userhash = DB_get_hash_from_gameid_and_userid($gameid,$userid);
- if($gametype=='normal')
+ if($gametype_raw=='normal')
{
$userhand = DB_get_all_hand($userhash);
if(check_wedding($userhand))
@@ -854,6 +861,9 @@ switch($mystatus)
/* keep startplayer, just set gametype to silent solo */
DB_set_gametype_by_gameid($gameid,'solo');
DB_set_solo_by_gameid($gameid,'silent');
+ $gametype_raw = 'solo';
+ $gametype_solo = 'silent';
+ $gametype = 'normal';
}
}
}
@@ -1260,19 +1270,6 @@ switch($mystatus)
* accordingly
*/
- $gametype = DB_get_gametype_by_gameid($gameid);
- $GT = $gametype;
- if($gametype=='solo')
- {
- $gametype = DB_get_solo_by_gameid($gameid);
- if($gametype=='silent')
- $GT = 'normal';
- else
- $GT = $gametype.' '.$GT;
- }
- else
- $gametype = 'normal';
-
set_gametype($gametype); /* this sets the $CARDS variable */
/* get some infos about the game, need to reset this, since it might have changed */
@@ -1317,16 +1314,14 @@ switch($mystatus)
echo "\n<div class=\"tricks\">\n";
/* output vorbehalte */
- $mygametype = DB_get_gametype_by_gameid($gameid);
- $mygamesolo = DB_get_solo_by_gameid($gameid);
$show_pre_game_comments=1;
- if($mygametype != 'normal') /* only show when needed */
- if(!( $mygametype == 'solo' && $mygamesolo == 'silent') )
+ if($gametype_raw != 'normal') /* only show when needed */
+ if(!($gametype_raw == 'solo' && $gametype_solo == 'silent') )
{
echo " <div class=\"trick\" id=\"trick0\">\n";
/* get information so show the cards that have been handed over in a poverty game */
- output_exchanged_cards();
+ output_exchanged_cards($gametype);
$show_pre_game_comments=0;
echo " </div>\n"; /* end div trick, end li trick */
@@ -1543,7 +1538,7 @@ switch($mystatus)
* since it doesn't make sense in some games
*/
$ok = 0; /* fox shouldn't be counted */
- if(DB_get_gametype_by_gameid($gameid)=='solo')
+ if($gametype_raw=='solo')
{
$solo = DB_get_solo_by_gameid($gameid);
if($solo == 'trump' || $solo == 'silent')
@@ -1580,13 +1575,8 @@ switch($mystatus)
if($tricknr == 12 ) /* Karlchen works only in the last trick */
{
- /* check for solo */
- $solo = 'none';
- if(DB_get_gametype_by_gameid($gameid)=='solo' )
- $solo = DB_get_solo_by_gameid($gameid);
-
/* no Karlchen in these solos */
- if($solo != 'trumpless' && $solo != 'jack' && $solo != 'queen' )
+ if($gametype_solo != 'trumpless' && $gametype_solo != 'jack' && $gametype_solo != 'queen' )
{
foreach($play as $played)
if ( $played['card']==11 || $played['card']==12 )
@@ -2131,12 +2121,10 @@ switch($mystatus)
{
echo "\n<div class=\"tricks\">\n";
- $mygametype = DB_get_gametype_by_gameid($gameid);
-
echo " <div class=\"trick\" id=\"trick0\">\n";
/* get information so show the cards that have been handed over in a poverty game */
- output_exchanged_cards();
+ output_exchanged_cards($gametype);
echo " </div>\n </div>\n\n"; /* end div trick, end li trick , end ul tricks */
}
@@ -2392,13 +2380,10 @@ if($mystatus=='gameover' &&
{
/* suggest a new game with the same people in it, just rotated once (unless last game was solo) */
$names = DB_get_all_names_by_gameid($gameid);
- $type = DB_get_gametype_by_gameid($gameid);
- if($type=='solo')
+ if($gametype_raw=='solo')
{
- $solo = DB_get_solo_by_gameid($gameid);
-
- if($solo!='silent') /* repeat game with same first player */
+ if($gametype_solo!='silent') /* repeat game with same first player */
output_ask_for_new_game($names[0],$names[1],$names[2],$names[3],$gameid);
else /* rotate normally */
output_ask_for_new_game($names[1],$names[2],$names[3],$names[0],$gameid);
diff --git a/include/output.php b/include/output.php
index 0be920e..67c1870 100644
--- a/include/output.php
+++ b/include/output.php
@@ -640,7 +640,7 @@ function output_robotproof($i)
}
}
-function output_exchanged_cards()
+function output_exchanged_cards($gametype)
{
/* in a poverty game this function will output the exchanged cards
* players in the team will see the cards, the other team will see
@@ -648,7 +648,7 @@ function output_exchanged_cards()
*/
/* need some information about the game */
- global $gameid,$mygametype, $PREF,$me,$mystatus, $RULES;
+ global $gameid,$PREF,$me,$mystatus, $RULES;
/* some variables to track where the people with poverty are sitting */
$partnerpos1 = 0;
@@ -659,7 +659,7 @@ function output_exchanged_cards()
/* only need to do it in a poverty game, this might not be needed, but
* just to make sure everything is ok
*/
- if($mygametype == 'poverty' || $mygametype=='dpoverty')
+ if($gametype == 'poverty' || $gametype=='dpoverty')
{
/* find out who has poverty */
for($mypos=1;$mypos<5;$mypos++)
@@ -795,7 +795,7 @@ function output_exchanged_cards()
}
echo " </div>\n";
}
- if($mygametype == $usersick)
+ if($gametype == $usersick)
$show = 0;
}
}