From: Arun Persaud Date: Sun, 14 Mar 2010 21:36:47 +0000 (-0700) Subject: Merge branch 'master' of /home/arun/nubati.net/git/e-DoKo X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=commitdiff_plain;h=c581cd05476d07f0fd17dab41cbb211a443fd57f;hp=f47ddae6b4d00d950c3a29d6b7536ce1ae9ac813 Merge branch 'master' of /home/arun/nubati.net/git/e-DoKo --- diff --git a/INSTALL b/INSTALL index 0fada71..1929213 100644 --- a/INSTALL +++ b/INSTALL @@ -3,7 +3,7 @@ Installation ------------ -1) What you need - all you need is PHP and MYSQL + all you need is PHP and MYSQL. PHP has to include gettext support. 0) Get files diff --git a/TRANSLATION b/TRANSLATION new file mode 100644 index 0000000..38bbaaa --- /dev/null +++ b/TRANSLATION @@ -0,0 +1,23 @@ +Translation: + +to update the pot file run: + +xgettext -L PHP -n --package-name=edoko --msgid-bugs-address=arun@nubati.net *php */*php +mv messages.po po/messages.pot + + +To start a new translation use something like (here shown to create de.po): + +cd po +msginit -i messages.pot -o de.po + +To update a po file run: + +cd po +msgmerge de.po messages.pot + +Start editing and then after updating a po run: + +msgconv -t ISO-8859-1 de.po > de.po.new && mv de.po.new de.po +msgfmt -cv -o de.mo de.po +mv de.mo ../locale/de/LC_MESSAGES/edoko.mo \ No newline at end of file diff --git a/cards/altenburg/License b/cards/altenburg/License index 02f0f20..303db83 100644 --- a/cards/altenburg/License +++ b/cards/altenburg/License @@ -1,8 +1,12 @@ -Verwendung der ASS Altenburger Spielkartenbilder mit Genehmigung der +You need to a license from + Spielkartenfabrik Altenburg GmbH, ASS Altenburger -Leipziger Strasse 7, 04600 Altenburg bis zum 31.12.2009 +Leipziger Strasse 7, 04600 Altenburg Email: info@spielkarten.com -internet: www.spielkarten.com \ No newline at end of file +internet: www.spielkarten.com + +for these images. This involves some paperwork, but was free for non-commercial purposes. + diff --git a/create_database.sql b/create_database.sql index fd7b22a..71a6dfc 100644 --- a/create_database.sql +++ b/create_database.sql @@ -48,7 +48,7 @@ CREATE TABLE `Version` ( /*!40000 ALTER TABLE `Card` DISABLE KEYS */; LOCK TABLES `Version` WRITE; -INSERT INTO `Version` VALUES (1); +INSERT INTO `Version` VALUES (2); UNLOCK TABLES; /*!40000 ALTER TABLE `Version` ENABLE KEYS */; @@ -141,7 +141,7 @@ CREATE TABLE `Game` ( `sickness` int(11) default NULL, `startplayer` tinyint(4) default '1', `player` int(11) default NULL, - `status` enum('pre','play','gameover','cancel-timedout','cancel-nines','cancel-trump','cancel-noplay') default NULL, + `status` enum('pre','play','gameover','cancel-timedout','cancel-nines','cancel-trump','cancel-noplay','cancel-lowtrump') default NULL, `ruleset` int(11) default NULL, `session` int(11) default NULL, `id` int(11) NOT NULL auto_increment, @@ -171,6 +171,7 @@ CREATE TABLE `Rulesets` ( `dullen` enum('none','firstwins','secondwins') default 'secondwins', `schweinchen` enum ('none','both','second','secondaftercall') default 'second', `call` enum ('1st-own-card','5th-card','9-cards') default '1st-own-card', + `lowtrump` enum('poverty','cancel','none') default 'poverty', `id` int(11) NOT NULL auto_increment, UNIQUE KEY `id` (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; @@ -200,7 +201,7 @@ CREATE TABLE `Hand` ( `status` enum('start','init','check','poverty','play','gameover') default 'start', `position` tinyint(4) NOT NULL default '0', `party` enum('re','contra') default NULL, - `sickness` enum('wedding','nines','poverty','solo') default NULL, + `sickness` enum('wedding','nines','poverty','solo','lowtrump') default NULL, `solo` enum('trumpless','jack','queen','trump','club','spade','heart','silent') default NULL, `point_call` enum('120','90','60','30','0') default NULL, UNIQUE KEY `id` (`id`), @@ -263,7 +264,7 @@ CREATE TABLE `Card_Exchange` ( /*!40000 ALTER TABLE `Hand_Card` DISABLE KEYS */; -LOCK TABLES `Hand_Card` WRITE; +LOCK TABLES `Card_Exchange` WRITE; UNLOCK TABLES; /*!40000 ALTER TABLE `Hand_Card` ENABLE KEYS */; diff --git a/include/db.php b/include/db.php index b79da87..ad6c6f0 100644 --- a/include/db.php +++ b/include/db.php @@ -30,17 +30,24 @@ if(!isset($HOST)) function DB_open() { + $version_needed = 2; + global $DB,$DB_user,$DB_host,$DB_database,$DB_password; $DB = @mysql_connect($DB_host,$DB_user, $DB_password); if ( $DB ) { - mysql_select_db($DB_database) or die('Could not select database'); + mysql_select_db($DB_database) or die('Error: Could not select database'); } else { echo mysql_errno() . ": " . mysql_error(). "\n"; return -1; - } + }; + + $version = DB_get_version(); + if ($version != $version_needed) + return -2; + return 0; } @@ -696,14 +703,15 @@ function DB_get_hashes_by_session($session,$user) return $r; } -function DB_get_ruleset($dullen,$schweinchen,$call) +function DB_get_ruleset($dullen,$schweinchen,$call,$lowtrump) { $r = array(); $result = DB_query("SELECT id FROM Rulesets WHERE". " dullen=".DB_quote_smart($dullen)." AND ". " Rulesets.call=".DB_quote_smart($call)." AND ". - " schweinchen=".DB_quote_smart($schweinchen)); + " schweinchen=".DB_quote_smart($schweinchen)." AND ". + " lowtrump=".DB_quote_smart($lowtrump)); if($result) $r = DB_fetch_array($result); @@ -715,6 +723,7 @@ function DB_get_ruleset($dullen,$schweinchen,$call) $result = DB_query("INSERT INTO Rulesets VALUES (NULL, NULL, ". DB_quote_smart($dullen).",". DB_quote_smart($schweinchen).",". + DB_quote_smart($lowtrump).",". DB_quote_smart($call). ", NULL)"); if($result) @@ -763,6 +772,7 @@ function DB_get_PREF($myid) $PREF['vacation_start'] = NULL; $PREF['vacation_stop'] = NULL; $PREF['vacation_comment'] = ''; + $PREF['language'] = 'en'; /* get all preferences */ $r = DB_query('SELECT pref_key, value FROM User_Prefs'. @@ -816,8 +826,14 @@ function DB_get_PREF($myid) if($pref[1]) $PREF['vacation_comment'] = $pref[1]; break; + + case 'language': + if($pref[1]) + $PREF['language'] = $pref[1]; + break; } } + $_SESSION['language'] = $PREF['language']; return $PREF; } @@ -827,9 +843,10 @@ function DB_get_RULES($gameid) " LEFT JOIN Game ON Game.ruleset=Rulesets.id ". " WHERE Game.id='$gameid'" ); - $RULES["dullen"] = $r[2]; - $RULES["schweinchen"] = $r[3]; - $RULES["call"] = $r[4]; + $RULES['dullen'] = $r[2]; + $RULES['schweinchen'] = $r[3]; + $RULES['lowtrump'] = $r[4]; + $RULES['call'] = $r[5]; return $RULES; } diff --git a/include/functions.php b/include/functions.php index 998ca02..a06f3d4 100644 --- a/include/functions.php +++ b/include/functions.php @@ -146,8 +146,8 @@ function sendmail($To,$Subject,$message) * change txt -> html */ $message = str_replace("\n","
\n",$message); - $message = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", - "\\0", $message); + $message = preg_replace("#(\w+://[^<>\s]+[\w/]*)#", + "$1", $message); echo "
To: $To
"; if($header != "") @@ -455,6 +455,39 @@ function count_trump($cards,$status='pregame') return $trump; } +function check_low_trump($cards) +{ + global $RULES; + + if($RULES['lowtrump']=='none') + return 0; + + /* check if we have low trump */ + + $lowtrump=1; + foreach($cards as $card) + { + /* card a trump, but not a diamond? */ + if( $card<19 ) + $lowtrump=0; + } + + /* handle case where player has schweinchen */ + if( in_array("19",$cards) && in_array("20",$cards) ) + switch($RULES["schweinchen"]) + { + case "both": + case "second": + case "secondaftercall": + $lowtrump=0; + break; + case "none": + break; + } + + return $lowtrump; +} + function create_array_of_random_numbers($useridA,$useridB,$useridC,$useridD) { global $debug; @@ -467,12 +500,12 @@ function create_array_of_random_numbers($useridA,$useridB,$useridC,$useridD) $r[ 1]=2; $r[13]=23; $r[25]=14; $r[37]=38; $r[ 2]=3; $r[14]=27; $r[26]=15; $r[38]=39; $r[ 3]=4; $r[15]=16; $r[27]=28; $r[39]=40; - $r[ 4]=5; $r[16]=17; $r[28]=29; $r[40]=41; + $r[ 4]=5; $r[16]=17; $r[28]=29; $r[40]=21; $r[ 5]=18; $r[17]=6; $r[29]=30; $r[41]=42; - $r[ 6]=21; $r[18]=7; $r[30]=31; $r[42]=43; - $r[ 7]=22; $r[19]=8; $r[31]=32; $r[43]=44; - $r[ 8]=45; $r[20]=9; $r[32]=19; $r[44]=33; - $r[ 9]=46; $r[21]=10; $r[33]=20; $r[45]=24; + $r[ 6]=41; $r[18]=7; $r[30]=31; $r[42]=43; + $r[ 7]=22; $r[19]=8; $r[31]=32; $r[43]=20; + $r[ 8]=45; $r[20]=9; $r[32]=33; $r[44]=19; + $r[ 9]=46; $r[21]=10; $r[33]=44; $r[45]=24; $r[10]=35; $r[22]=11; $r[34]=48; $r[46]=25; $r[11]=36; $r[23]=12; $r[35]=34; $r[47]=26; } @@ -933,7 +966,7 @@ function display_table () echo " Schweinchen.
"; if($GT=="poverty" && $party=="re") - if($sickness=="poverty") + if($sickness=="poverty" || ($RULES['lowtrump']=='poverty' && $sickness=='lowtrump')) { $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user); $cards = DB_get_all_hand($userhash); @@ -948,7 +981,7 @@ function display_table () if($GT=="dpoverty") if($party=="re") - if($sickness=="poverty") + if($sickness=="poverty" || ($RULES['lowtrump']=='poverty' && $sickness=='lowtrump')) { $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user); $cards = DB_get_all_hand($userhash); @@ -961,7 +994,7 @@ function display_table () else echo " \"poverty\" title=\"poverty partner\" />"; else - if($sickness=="poverty") + if($sickness=="poverty" || ($RULES['lowtrump']=='poverty' && $sickness=='lowtrump')) { $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user); $cards = DB_get_all_hand($userhash); @@ -980,21 +1013,21 @@ function display_table () else echo " \"wedding"; - if(ereg("solo",$GT) && $party=="re") + if( (strpos($GT,"solo")!==false) && $party=="re") { - if(ereg("queen",$GT)) + if(strpos($GT,"queen")!==false) echo " \"$GT\""; - else if(ereg("jack",$GT)) + else if(strpos($GT,"jack")!==false) echo " \"$GT\""; - else if(ereg("club",$GT)) + else if(strpos($GT,"club")!==false) echo " \"$GT\""; - else if(ereg("spade",$GT)) + else if(strpos($GT,"spade")!==false) echo " \"$GT\""; - else if(ereg("heart",$GT)) + else if(strpos($GT,"heart")!==false) echo " \"$GT\""; - else if(ereg("trumpless",$GT)) + else if(strpos($GT,"trumpless")!==false) echo " \"$GT\""; - else if(ereg("trump",$GT)) + else if(strpos($GT,"trump")!==false) echo " \"$GT\""; } @@ -1156,7 +1189,8 @@ function generate_global_score_table() /* save information in an array */ while( $r = DB_fetch_array($result)) - $player[$r[0]] = array('name'=> $r[1], 'points' => 0 ,'nr' => 0); + $player[$r[0]] = array('name'=> $r[1], 'points' => 0 , 'nr' => 0, 'active' => 0, + 'response' => 0 , 'solo' => 0, 'soloavg' => 0); /* get points and generate table */ foreach($gameids as $gameid) @@ -1182,9 +1216,53 @@ function generate_global_score_table() } } + /* add number of active games */ + $result = DB_query_array_all("SELECT user_id, COUNT(*) as c " . + " FROM Hand". + " LEFT JOIN Game ON Game.id=game_id". + " WHERE Game.status IN ('pre','play')". + " GROUP BY user_id"); + + foreach($result as $res) + { + $player[$res[0]]['active'] = $res[1]; + } + + /* response time of users*/ + $result = DB_query_array_all("SELECT user_id,". + "IFNULL(AVG(if(P1.sequence in (2,3,4),". + "-timestampdiff(MINUTE,mod_date,(select mod_date from Play P2 where P1.trick_id=P2.trick_id and P2.sequence=P1.sequence-1)),NULL )),1e9) as a ". + "FROM Play P1 ". + "LEFT JOIN Hand_Card ON P1.hand_card_id=Hand_Card.id ". + "LEFT JOIN Hand ON Hand.id=Hand_Card.hand_id ". + "GROUP BY user_id "); + + foreach($result as $res) + { + $player[$res[0]]['response'] = $res[1]; + } + + /* most solos */ + $result = DB_query_array_all("SELECT user_id as uid,". + " COUNT(*), ". + " COUNT(*)/(SELECT COUNT(*) FROM Hand LEFT JOIN User ON User.id=Hand.user_id WHERE User.id=uid) as c ". + " FROM Game ". + " LEFT JOIN Hand ON Hand.position=startplayer AND Game.id=Hand.game_id ". + " WHERE type='solo' AND Game.status='gameover' ". + " GROUP BY user_id "); + + foreach($result as $res) + { + $player[$res[0]]['solo'] = $res[1]; + $player[$res[0]]['soloavg'] = $res[2]; + } + + + /* sort everything nicely */ + function cmp($a,$b) { - if($a['nr']==0 ) return 1; + if($a['nr']==0) return 1; if($b['nr']==0) return 1; $a=$a['points']/$a['nr']; @@ -1196,11 +1274,13 @@ function generate_global_score_table() } usort($player,'cmp'); + foreach($player as $pl) { /* limit to players with at least 10 games */ if($pl['nr']>10) - $return[] = array( $pl['name'], round($pl['points']/$pl['nr'],3), $pl['points'],$pl['nr']); + $return[] = array( $pl['name'], round($pl['points']/$pl['nr'],3), $pl['points'],$pl['nr'],$pl['active'], + $pl['response'],$pl['solo'],$pl['soloavg']); } return $return; @@ -1391,6 +1471,9 @@ function cancel_game($why,$gameid) case 'noplay': DB_query("UPDATE Game SET status='cancel-noplay' WHERE id=$gameid"); break; + case 'lowtrump': + DB_query("UPDATE Game SET status='cancel-lowtrump' WHERE id=$gameid"); + break; } /* set each player to gameover */ $result = DB_query("SELECT id FROM Hand WHERE game_id=".DB_quote_smart($gameid)); diff --git a/include/game.php b/include/game.php index a1c02a0..db27bde 100644 --- a/include/game.php +++ b/include/game.php @@ -47,6 +47,7 @@ global $GAME,$RULES,$CARDS; $gameid = DB_get_gameid_by_hash($me); $myname = DB_get_name('hash',$me); $mystatus = DB_get_status_by_hash($me); +$origmystatus = DB_get_status_by_hash($me); /* to show "it's your turn" menu when game has just finished */ $mypos = DB_get_pos_by_hash($me); $myhand = DB_get_handid('hash',$me); $myparty = DB_get_party_by_hash($me); @@ -222,6 +223,7 @@ if($session) echo " 10ofhearts : {$RULES['dullen']}
\n"; echo " schweinchen: {$RULES['schweinchen']}
\n"; echo " call: {$RULES['call']}
\n"; + echo " lowtrump: {$RULES['lowtrump']}
\n"; echo " \n \n"; /* show score */ @@ -399,7 +401,7 @@ switch($mystatus) $mycards = DB_get_hand($me); $mycards = mysort($mycards,$gametype); - if(!myisset('solo','wedding','poverty','nines') ) + if(!myisset('solo','wedding','poverty','nines','lowtrump') ) { /* output sickness of other playes, in case the already selected and are sitting in front of the current player */ echo "\n\n\n"; /* end div trick, end li trick , end ul tricks */ } /* end output pre-game trick */ @@ -918,7 +950,7 @@ switch($mystatus) $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user); $userparty = DB_get_party_by_hash($userhash); - if($usersick=='poverty' && !$userparty) + if(($usersick=='poverty'|| ($RULES['lowtrump']=='poverty' && $usersick=='lowtrump')) && !$userparty) { $hash = DB_get_hash_from_gameid_and_userid($gameid,$user); $cards = DB_get_hand($hash); @@ -926,7 +958,10 @@ switch($mystatus) $nrtrump = 0; foreach($cards as $card) if($card<27) $nrtrump++; - echo "Player $name has $nrtrump trump. Do you want to take them?". + $low=''; + if($usersick=='lowtrump') + $low='low'; + echo "Player $name has $nrtrump $low trump. Do you want to take them?". "Yes
\n"; } } @@ -955,9 +990,9 @@ switch($mystatus) /* don't ask people who have poverty */ $next=1; - if($firstsick=='poverty') + if($firstsick=='poverty' || ($RULES['lowtrump']=='poverty' && $firstsick=='lowtrump')) { - if($secondsick=='poverty') + if($secondsick=='poverty'|| ($RULES['lowtrump']=='poverty' && $secondsick=='lowtrump')) $next=3; else $next=2; @@ -1072,8 +1107,8 @@ switch($mystatus) $secondsick = (string) DB_get_sickness_by_pos_and_gameid($mypos+2,$gameid); $next=1; - if($firstsick=='poverty') - if($secondsick=='poverty') + if($firstsick=='poverty'|| ($RULES['lowtrump']=='poverty' && $firstsick=='lowtrump')) + if($secondsick=='poverty'|| ($RULES['lowtrump']=='poverty' && $secondsick=='lowtrump')) $next=3; else $next=2; @@ -1096,7 +1131,7 @@ switch($mystatus) echo "
Please, continue here.
\n"; } } - echo ""; + echo "\n"; break; case 'play': @@ -1115,9 +1150,11 @@ switch($mystatus) echo "

The game has been canceled because one player wasn't responding.

If this was a mistake all 4 players need to send an Email to $ADMIN_NAME at $ADMIN_EMAIL requesting that the game should be restarted.

"; break; case 'cancel-nines': - case 'cancel-timedout': echo "

The game has been canceled because one player had too many nines.

"; break; + case 'cancel-lowtrump': + echo "

The game has been canceled because one player had low trump.

"; + break; case 'cancel-trump': echo "

The game has been canceled because nobody wanted to take the trump.

"; break; @@ -1487,28 +1524,31 @@ switch($mystatus) /* same as for foxes, karlchen doesn't always make sense * check what kind of game it is and set karlchen accordingly */ - $ok = 1; /* default: karlchen should be accounted for */ - if($tricknr != 12 ) - $ok = 0; /* Karlchen works only in the last trick */ - if($ok && DB_get_gametype_by_gameid($gameid)=='solo' ) + + if($tricknr == 12 ) /* Karlchen works only in the last trick */ { - $solo = DB_get_solo_by_gameid($gameid); - if($solo == 'trumpless' || $solo == 'jack' || $solo == 'queen' ) - $ok = 0; /* no Karlchen in these solos */ - } + /* check for solo */ + $solo = 'none'; + if(DB_get_gametype_by_gameid($gameid)=='solo' ) + $solo = DB_get_solo_by_gameid($gameid); - if($ok) - foreach($play as $played) - if ( $played['card']==11 || $played['card']==12 ) - if ($played['pos'] == $winner ) - { - /* possible caught a fox, check party */ - $uid1 = DB_get_userid('gameid-position',$gameid,$winner); - $party1 = DB_get_party_by_gameid_and_userid($gameid,$uid1); + /* no Karlchen in these solos */ + if($solo != 'trumpless' && $solo != 'jack' && $solo != 'queen' ) + { + foreach($play as $played) + if ( $played['card']==11 || $played['card']==12 ) + if ($played['pos'] == $winner ) + { + /* save Karlchen */ + $uid1 = DB_get_userid('gameid-position',$gameid,$winner); + $party1 = DB_get_party_by_gameid_and_userid($gameid,$uid1); + + DB_query("INSERT INTO Score". + " VALUES( NULL,NULL,$gameid,'$party1',$uid1,NULL,'karlchen')"); + }; + }; + }; /* end scoring Karlchen */ - DB_query("INSERT INTO Score". - " VALUES( NULL,NULL,$gameid,'$party1',$uid1,NULL,'karlchen')"); - } /* * check for doppelopf (>40 points) ***********************************/ @@ -2031,11 +2071,20 @@ switch($mystatus) /* output other games where it is the users turn * make sure that the people looking at old games don't see the wrong games here */ -if( $mystatus != 'gameover' ) - display_user_menu($myid); +if( $gamestatus != 'gameover' ) + { + /* game isn't over, only valid user can get here, so show menu */ + display_user_menu($myid); + } +else if( $origmystatus != 'gameover' ) + { + /* user just played the very last card, game is now over, it's still ok to show the menu though */ + display_user_menu($myid); + } else if( $mystatus == 'gameover' && - isset($_SESSION['id']) ) + isset($_SESSION['id']) ) { + /* user is looking at someone else's game, show the menu for the correct user */ display_user_menu($_SESSION['id']); } else diff --git a/include/newgame.php b/include/newgame.php index d7a2d7f..f06bebe 100644 --- a/include/newgame.php +++ b/include/newgame.php @@ -40,7 +40,7 @@ else DB_update_user_timestamp($myid); - if( !myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen","callrule" )) + if( !myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen","callrule","lowtrump" )) { /* only get players that want to be in new games */ $names = DB_get_all_user_names_open_for_games(); @@ -80,6 +80,7 @@ else $dullen = $_REQUEST["dullen"]; $schweinchen = $_REQUEST["schweinchen"]; $call = $_REQUEST["callrule"]; + $lowtrump = $_REQUEST["lowtrump"]; /* get the emails addresses of the players */ $EmailA = DB_get_email('name',$PlayerA); @@ -142,7 +143,7 @@ else else /* no follow up, start a new session */ { /* get ruleset information or create new one */ - $ruleset = DB_get_ruleset($dullen,$schweinchen,$call); + $ruleset = DB_get_ruleset($dullen,$schweinchen,$call,$lowtrump); if($ruleset <0) { myerror("Error defining ruleset: $ruleset"); diff --git a/include/output.php b/include/output.php index 06eb8de..79e42c2 100644 --- a/include/output.php +++ b/include/output.php @@ -31,7 +31,7 @@ function output_ask_for_new_game($playerA,$playerB,$playerC,$playerD,$oldgameid) global $RULES; echo "
\n
\n"; - echo "Do you want to continue playing?(This will start a new game, with $playerD as dealer.)\n"; + echo "Do you want to continue playing?(This will start a new game, with $playerA starting the game.)\n"; echo " \n"; echo " \n"; echo " \n"; @@ -123,10 +123,19 @@ function output_form_for_new_game($names)

+

Low trump

+

+ Player can't trump a fox, that is none of his trump is higher than a fox. + +

Scoring-related

(not yet implemented)

@@ -205,10 +214,11 @@ function display_link_card($card,$dir="english",$type="card") function output_check_for_sickness($me,$mycards) { + global $RULES; ?>
Thanks for joining the game...
- do you want to play solo? + Do you want to play solo?
\n"; }; - echo "Do you have too many nines?"; + echo "Do you have too many nines?"; if(count_nines($mycards)>4) { echo " yes"; @@ -256,6 +266,26 @@ function output_check_for_sickness($me,$mycards) echo " no
\n"; }; + if($RULES['lowtrump']=='cancel' || $RULES['lowtrump']=='poverty') + { + if($RULES['lowtrump']=='cancel') + echo "Do you have low trump (cancel game)?"; + else + echo "Do you have low trump (poverty)?"; + + if(check_low_trump($mycards)) + { + echo " yes"; + echo " no
\n"; + } + else + { + echo " no
\n"; + }; + } + else + echo ""; + echo "\n"; echo "\n"; @@ -364,7 +394,9 @@ function output_header()
-

Welcome to E-Doko

+ '._('Welcome to E-Doko').' '; +?>
\n\n"; echo "
\n"; - echo "

copyright 2006-2009 Arun Persaud, Lance Thornton(graphics), Jeff Zerger(database support)
\n". + echo "

copyright 2006,2007,2008,2009,2010 Arun Persaud, Lance Thornton(graphics), Jeff Zerger(database support)
\n". " Verwendung der [deutschen] Kartenbilder mit Genehmigung
der Spielkartenfabrik Altenburg GmbH,(c) ASS Altenburger
\n". " - ASS Altenburger Spielkarten - Spielkartenfabrik Altenburg GmbH
\n". " a Carta Mundi Company Email: info@spielkarten.com Internet: www.spielkarten.com

\n"; @@ -486,6 +518,26 @@ function output_select_timezone($name,$timezone="") return; } +function output_select_language($name,$language="") +{ + $LOCALE = array ("English" => "en", + "Deutsch" => "de" ); + + echo " \n"; + + return; +} + + function output_password_recovery($email,$password) { ?> @@ -556,7 +608,7 @@ function output_exchanged_cards() */ /* need some information about the game */ - global $gameid,$mygametype, $PREF,$me,$mystatus; + global $gameid,$mygametype, $PREF,$me,$mystatus, $RULES; /* some variables to track where the people with poverty are sitting */ $partnerpos1 = 0; @@ -573,7 +625,7 @@ function output_exchanged_cards() for($mypos=1;$mypos<5;$mypos++) { $usersick = DB_get_sickness_by_pos_and_gameid($mypos,$gameid); - if($usersick == 'poverty') + if($usersick == 'poverty' || ($RULES['lowtrump']=='poverty' && $usersick=='lowtrump')) if($povertypos1) $povertypos2 = $mypos; else diff --git a/include/preferences.php b/include/preferences.php index 6648b99..3904899 100644 --- a/include/preferences.php +++ b/include/preferences.php @@ -43,6 +43,7 @@ $changed_openforgames = 0; $changed_vacation = 0; $changed_openid = 0; $changed_digest = 0; +$changed_language = 0; display_user_menu($myid); @@ -297,6 +298,25 @@ if(myisset("openid_url") && $_REQUEST['openid_url']!='') DB_AttachOpenID($openid_url, $myid); } +if(myisset("language")) + { + $language = $_REQUEST['language']; + if($language != $PREF['language']) + { + /* check if we already have an entry for the user, if so change it, if not create new one */ + $result = DB_query("SELECT * from User_Prefs". + " WHERE user_id='$myid' AND pref_key='language'" ); + if( DB_fetch_array($result)) + $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($language). + " WHERE user_id='$myid' AND pref_key='language'" ); + else + $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','language',". + DB_quote_smart($language).")"); + $changed_language = 1; + } + } + + /* get infos again in case they have changed */ $PREF = DB_get_PREF($myid); $timezone = DB_get_user_timezone($myid); @@ -461,7 +481,9 @@ echo " Timezone: \n"; output_select_timezone("timezone",$timezone); if($changed_timezone) echo "changed"; echo "\n"; - +echo " Language: \n"; +output_select_language("language",$PREF['language']); +echo "\n"; echo " Password(old): ", ""; switch($changed_password) diff --git a/include/stats.php b/include/stats.php index fb56df8..61e7d88 100644 --- a/include/stats.php +++ b/include/stats.php @@ -24,6 +24,9 @@ if(!isset($HOST)) exit; +/* turn warnings off (problem with two warnings in function.php */ +error_reporting(!E_ALL & ~E_NOTICE); + $name = $_SESSION["name"]; $email = DB_get_email('name',$name); @@ -190,46 +193,6 @@ if( !$content = getCache("cache/stats.html",60*60*24) ) array_unshift($result,array("Position","Number of tricks")); echo output_table($result,"Tricks at the table","stats"); - /* most solos */ - $result = DB_query_array_all("SELECT fullname as fname,". - " COUNT(*), ". - " COUNT(*)/(SELECT COUNT(*) FROM Hand LEFT JOIN User ON User.id=Hand.user_id WHERE fullname=fname) as c ". - " FROM Game ". - " LEFT JOIN Hand ON Hand.position=startplayer AND Game.id=Hand.game_id ". - " LEFT JOIN User ON User.id=Hand.user_id ". - " WHERE type='solo' AND Game.status='gameover' ". - " GROUP BY user_id ". - " ORDER BY c DESC;"); - array_unshift($result,array("Name","Number of solos","Solos/game")); - echo output_table($result,"Most solos","stats"); - - - /* most active games */ - $result = DB_query_array_all("SELECT fullname, COUNT(*) as c " . - " FROM Hand". - " LEFT JOIN User ON User.id=user_id". - " LEFT JOIN Game ON Game.id=game_id". - " WHERE Game.status IN ('pre','play')". - " GROUP BY user_id". - " ORDER BY c DESC LIMIT 7" ); - array_unshift($result,array("Name","Number of active games")); - echo output_table($result,"Active games","stats"); - - /* response time of users*/ - $result = DB_query_array_all("SELECT User.fullname,". - "IFNULL(AVG(if(P1.sequence in (2,3,4),". - "-timestampdiff(MINUTE,mod_date,(select mod_date from Play P2 where P1.trick_id=P2.trick_id and P2.sequence=P1.sequence-1)),NULL )),1e9) as a, ". - " COUNT(*) as na ". - "FROM Play P1 ". - "LEFT JOIN Hand_Card ON P1.hand_card_id=Hand_Card.id ". - "LEFT JOIN Hand ON Hand.id=Hand_Card.hand_id ". - "LEFT JOIN User ON Hand.user_id=User.id ". - "GROUP BY user_id ". - "HAVING na>8 ". - "ORDER BY a " ); - array_unshift($result,array("Name","Average minutes before response","trick count")); - echo output_table($result,"Response","stats"); - /* does the party win more often if they start @@ -244,8 +207,9 @@ if( !$content = getCache("cache/stats.html",60*60*24) ) echo " games

\n"; */ $result = generate_global_score_table(); - array_unshift($result,array("Name","Average score per game","Total Points","Number of games")); - echo output_table($result,"Points per game (need more than 10 games)","stats","ScoreTable"); + array_unshift($result,array('Name','Average score per game','Total Points','Number of games', 'Active games', + 'Response Time [min]','Number of solos','Solos/game')); + echo output_table($result,'Players (need more than 10 games)','stats','ScoreTable'); /* * how often is the last trick a non-trump trick diff --git a/index.php b/index.php index 83618f3..61b0e3f 100644 --- a/index.php +++ b/index.php @@ -36,16 +36,51 @@ include_once("./include/functions.php"); /* the rest */ config_check(); /* open the database */ -if(DB_open()<0) +$DBopen = DB_open(); +if($DBopen<0) { output_header(); - echo "Database error, can't connect... Please wait a while and try again. ". - "If the problem doesn't go away feel free to contact $ADMIN_NAME at $ADMIN_EMAIL."; + + if($DBopen == -1) + echo "Database error, can't connect... Please wait a while and try again. ". + "If the problem doesn't go away feel free to contact $ADMIN_NAME at $ADMIN_EMAIL."; + else if ($DBopen == -2) + echo "Wrong database version, please update your database using the update.php script."; + output_footer(); exit(); } -/* done major error checking, output5B header of HTML page */ +/* localization */ +/* needs to be in front of output_header, but we don't know the users preferences at this time, + * so we go by the session variable or if language is set + */ +if(myisset('language') || isset($_SESSION['language'])) + { + $language = 'en'; + if(isset($_SESSION['language'])) + $language = $_SESSION['language']; + if(myisset('language')) + { + $language = $_REQUEST['language']; + $_SESSION['language'] = $language; /* overrule preferences */ + } + switch($language) + { + case 'de': + putenv("LC_ALL=de_DE"); + setlocale(LC_ALL, "de_DE"); + // Specify location of translation tables + bindtextdomain("edoko", "./locale"); + // Choose domain + textdomain("edoko"); + break; + default: + /* do nothing */ + } + } + +/* done major error checking, output header of HTML page */ output_header(); /* The rest of the file consists of handling user input. @@ -114,5 +149,3 @@ DB_close(); *End: */ ?> - - diff --git a/locale/de/LC_MESSAGES/edoko.mo b/locale/de/LC_MESSAGES/edoko.mo new file mode 100644 index 0000000..e72f5ab Binary files /dev/null and b/locale/de/LC_MESSAGES/edoko.mo differ diff --git a/po/de.po b/po/de.po new file mode 100644 index 0000000..9d27938 --- /dev/null +++ b/po/de.po @@ -0,0 +1,21 @@ +# English translations for PACKAGE package. +# Copyright (C) 2010 THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# Arun Persaud , 2010. +# +msgid "" +msgstr "" +"Project-Id-Version: edoko\n" +"Report-Msgid-Bugs-To: arun@nubati.net\n" +"POT-Creation-Date: 2010-03-14 11:35-0700\n" +"PO-Revision-Date: 2010-03-14 12:01-0700\n" +"Last-Translator: Arun Persaud \n" +"Language-Team: English\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=ISO-8859-1\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: include/output.php:398 +msgid "Welcome to E-Doko" +msgstr "Willkommen bei E-Doko" diff --git a/po/messages.pot b/po/messages.pot new file mode 100644 index 0000000..08d1463 --- /dev/null +++ b/po/messages.pot @@ -0,0 +1,21 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: edoko\n" +"Report-Msgid-Bugs-To: arun@nubati.net\n" +"POT-Creation-Date: 2010-03-14 11:35-0700\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: include/output.php:398 +msgid "Welcome to E-Doko" +msgstr "" diff --git a/update_db.php b/update_db.php index deae974..498b24e 100644 --- a/update_db.php +++ b/update_db.php @@ -28,7 +28,8 @@ include_once("./include/functions.php"); /* the rest */ config_check(); /* open the database */ -if(DB_open()<0) +$return = DB_open(); +if($return<0 && $return != -2) /* -2 = wrong DB version is ok */ exit(); /* only callable via cron or CLI */ @@ -36,7 +37,7 @@ if(isset($_SERVER['REMOTE_ADDR'])) exit(); $old_version = DB_get_version(); -$current_version = 1; +$current_version = 2; if($old_version < $current_version) echo "Will upgrade your database now:\n"; @@ -56,6 +57,17 @@ switch($old_version) " index (email))"); DB_query("UPDATE Version set version=1"); echo "Upgraded to version 1.\n"; + case 1: + /* add new rules */ + DB_query("ALTER TABLE Rulesets". + " ADD COLUMN `lowtrump` enum('poverty','cancel','none') default 'poverty' AFTER schweinchen"); + DB_query("ALTER TABLE Hand". + " MODIFY COLUMN `sickness` enum('wedding','nines','poverty','solo','lowtrump') default NULL"); + DB_query("ALTER TABLE Game". + " MODIFY COLUMN `status` enum('pre','play','gameover','cancel-timedout','cancel-nines','cancel-trump','cancel-noplay','cancel-lowtrump') default NULL"); + + DB_query("UPDATE Version set version=2"); + echo "Upgraded to version 2.\n"; } ?> \ No newline at end of file