Merge branch 'master' of /home/arun/nubati.net/git/e-DoKo
authorArun Persaud <arun@nubati.net>
Sun, 14 Mar 2010 21:36:47 +0000 (14:36 -0700)
committerArun Persaud <arun@nubati.net>
Sun, 14 Mar 2010 21:36:47 +0000 (14:36 -0700)
16 files changed:
INSTALL
TRANSLATION [new file with mode: 0644]
cards/altenburg/License
create_database.sql
include/db.php
include/functions.php
include/game.php
include/newgame.php
include/output.php
include/preferences.php
include/stats.php
index.php
locale/de/LC_MESSAGES/edoko.mo [new file with mode: 0644]
po/de.po [new file with mode: 0644]
po/messages.pot [new file with mode: 0644]
update_db.php

diff --git a/INSTALL b/INSTALL
index 0fada71b774e4d81101c8b8e24a2163d05b1758f..1929213241253db014ba7c4b55d6ac0419a74152 100644 (file)
--- 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 (file)
index 0000000..38bbaaa
--- /dev/null
@@ -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
index 02f0f204d7cea468532c659a1db3862d3ad839e8..303db83f41d4f8156ada0736681af08a6cca4c66 100644 (file)
@@ -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.
+
index fd7b22a8ba348901d86c897ae51724fbe7ce5eb6..71a6dfc2650c39a64232a26c781cd90f4d648393 100644 (file)
@@ -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 */;
 
index b79da87def6d231ccbc39507619e21a049cc8e09..ad6c6f0cfbae967f536e99073f436ef6b9b8d781 100644 (file)
@@ -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;
 }
index 998ca028756b82489361877d49ed1436c5c05f99..a06f3d425ed4c1acf4ae189b446f162b052ef650 100644 (file)
@@ -146,8 +146,8 @@ function sendmail($To,$Subject,$message)
        * change txt -> html
        */
       $message = str_replace("\n","<br />\n",$message);
-      $message = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",
-                     "<a href=\"\\0\">\\0</a>", $message);
+      $message = preg_replace("#(\w+://[^<>\s]+[\w/]*)#",
+                             "<a href=\"$1\">$1</a>", $message);
 
       echo "<br />To: $To<br />";
       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. <br />";
 
       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 "   <img src=\"pics/button/poverty_partner_button.png\" class=\"button\" alt=\"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 "   <img src=\"pics/button/wedding_partner_button.png\" class=\"button\" alt=\"wedding partner\" title=\"wedding partner\" />";
 
-      if(ereg("solo",$GT) && $party=="re")
+      if( (strpos($GT,"solo")!==false) && $party=="re")
        {
-         if(ereg("queen",$GT))
+         if(strpos($GT,"queen")!==false)
            echo "   <img src=\"pics/button/queensolo_button.png\" class=\"button\" alt=\"$GT\" title=\"Queen solo\" />";
-         else if(ereg("jack",$GT))
+         else if(strpos($GT,"jack")!==false)
            echo "   <img src=\"pics/button/jacksolo_button.png\" class=\"button\" alt=\"$GT\" title=\"Jack solo\" />";
-         else if(ereg("club",$GT))
+         else if(strpos($GT,"club")!==false)
            echo "   <img src=\"pics/button/clubsolo_button.png\" class=\"button\" alt=\"$GT\" title=\"Club solo\" />";
-         else if(ereg("spade",$GT))
+         else if(strpos($GT,"spade")!==false)
            echo "   <img src=\"pics/button/spadesolo_button.png\" class=\"button\" alt=\"$GT\" title=\"Spade solo\" />";
-         else if(ereg("heart",$GT))
+         else if(strpos($GT,"heart")!==false)
            echo "   <img src=\"pics/button/heartsolo_button.png\" class=\"button\" alt=\"$GT\" title=\"Heart solo\" />";
-         else if(ereg("trumpless",$GT))
+         else if(strpos($GT,"trumpless")!==false)
            echo "   <img src=\"pics/button/notrumpsolo_button.png\" class=\"button\" alt=\"$GT\" title=\"Trumpless solo\" />";
-         else if(ereg("trump",$GT))
+         else if(strpos($GT,"trump")!==false)
            echo "   <img src=\"pics/button/trumpsolo_button.png\" class=\"button\" alt=\"$GT\" title=\"Trump solo\" />";
        }
 
@@ -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));
index a1c02a0b4f90f4929f6c856254bf3b13ca6a7b30..db27bde601dd75d743c62d99c0674f4ea07df303 100644 (file)
@@ -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']}      <br />\n";
     echo "       schweinchen: {$RULES['schweinchen']} <br />\n";
     echo "       call:        {$RULES['call']}        <br />\n";
+    echo "       lowtrump:    {$RULES['lowtrump']}    <br />\n";
     echo "  </div>\n  </div>\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<ul class=\"tricks\">\n";
@@ -438,9 +440,10 @@ switch($mystatus)
        /* check if someone selected more than one sickness */
        $Nsickness = 0;
        if($_REQUEST['solo']!='No')       $Nsickness++;
-       if($_REQUEST['wedding'] == 'yes') $Nsickness++;
-       if($_REQUEST['poverty'] == 'yes') $Nsickness++;
-       if($_REQUEST['nines'] == 'yes')   $Nsickness++;
+       if($_REQUEST['wedding']  == 'yes') $Nsickness++;
+       if($_REQUEST['poverty']  == 'yes') $Nsickness++;
+       if($_REQUEST['nines']    == 'yes') $Nsickness++;
+       if($_REQUEST['lowtrump'] == 'yes') $Nsickness++;
 
        if($Nsickness>1)
          {
@@ -502,6 +505,16 @@ switch($mystatus)
                  " is playing solo, this game will be canceled.<br />\n";
                DB_set_sickness_by_hash($me,'nines');
              }
+           else if($_REQUEST['lowtrump'] == 'yes')
+             {
+               if($RULES['lowtrump']=='cancel')
+                 echo "What? You just don't want to play a game because you have low trump? Well, if no one".
+                 " is playing solo, this game will be canceled.<br />\n";
+               else
+                 echo "Don't think you can win with low trumps...? ok, poverty chosen <br />.<br />\n";
+
+               DB_set_sickness_by_hash($me,'lowtrump');
+             }
 
            echo "</p>\n";
 
@@ -591,7 +604,7 @@ switch($mystatus)
        $startplayer = DB_get_startplayer_by_gameid($gameid);
 
        /* check for sickness */
-       $nines   = 0;
+       $cancel  = 0;
        $poverty = 0;
        $wedding = 0;
        $solo    = 0;
@@ -599,12 +612,13 @@ switch($mystatus)
          {
            $name     = DB_get_name('userid',$user);
            $usersick = DB_get_sickness_by_userid_and_gameid($user,$gameid);
-           if($usersick == 'nines')
+           if($usersick == 'nines' || ($RULES['lowtrump']=='cancel' && $usersick=='lowtrump') )
              {
-               $nines = $user;
+               $cancel     = $user;
+               $cancelsick = $usersick;
                break; /* no need to check for other poverties, since only solo can win and that is already set */
              }
-           else if($usersick == 'poverty')
+           else if($usersick == 'poverty' || ($RULES['lowtrump']=='poverty' && $usersick=='lowtrump'))
              $poverty++;
            else if($usersick == 'wedding')
              $wedding=$user;
@@ -617,13 +631,35 @@ switch($mystatus)
          {
            /* do nothing */
          }
-       else if($nines)
+       else if($cancel)
          {
            /* cancel game */
-           $message = "The game has been canceled because ".DB_get_name('userid',$nines).
-             " has five or more nines and nobody is playing solo.\n\n".
-             "To redeal either start a new game or, in case the game was part of a tournament,\n".
-             "go to the last game and use the link at the bottom of the page to redeal.\n\n";
+           if($cancelsick == 'nines')
+             {
+               $message = "The game has been canceled because ".DB_get_name('userid',$cancel).
+                 " has five or more nines and nobody is playing solo.\n\n".
+                 "To redeal either start a new game or, in case the game was part of a tournament,\n".
+                 "go to the last game and use the link at the bottom of the page to redeal.\n\n";
+
+               /* update game status */
+               cancel_game('nines',$gameid);
+
+               echo "<p>The game has been canceled because ".DB_get_name('userid',$cancel).
+                 " has five or more nines and nobody is playing solo.</p>\n";
+             }
+           else if ($cancelsick == 'lowtrump')
+             {
+               $message = "The game has been canceled because ".DB_get_name('userid',$cancel).
+                 " has low trump and nobody is playing solo.\n\n".
+                 "To redeal either start a new game or, in case the game was part of a tournament,\n".
+                 "go to the last game and use the link at the bottom of the page to redeal.\n\n";
+
+               /* update game status */
+               cancel_game('lowtrump',$gameid);
+
+               echo "<p>The game has been canceled because ".DB_get_name('userid',$cancel).
+                 " has low trump and nobody is playing solo.</p>\n";
+             };
 
            $userids = DB_get_all_userid_by_gameid($gameid);
            foreach($userids as $user)
@@ -632,12 +668,7 @@ switch($mystatus)
                mymail($user,$subject,$message);
              }
 
-           /* update game status */
-           cancel_game('nines',$gameid);
-
-           echo "<p>The game has been canceled because ".DB_get_name('userid',$nines).
-             " has five or more nines and nobody is playing solo.</p>\n";
-           echo "</div>\n";
+           echo "</div>\n"; /* end div message */
            break;
          }
        else if($poverty==1) /* one person has poverty */
@@ -648,7 +679,7 @@ switch($mystatus)
            if(!$who)
              {
                $firstsick = DB_get_sickness_by_pos_and_gameid(1,$gameid);
-               if($firstsick == 'poverty')
+               if($firstsick == 'poverty' || ($RULES['lowtrump']=='poverty' && $firstsick=='lowtrump'))
                  DB_set_sickness_by_gameid($gameid,2); /* who needs to be asked first */
                else
                  DB_set_sickness_by_gameid($gameid,1); /* who needs to be asked first */
@@ -662,10 +693,10 @@ switch($mystatus)
            if(!$who)
              {
                $firstsick = DB_get_sickness_by_pos_and_gameid(1,$gameid);
-               if($firstsick == 'poverty')
+               if($firstsick == 'poverty' || ($RULES['lowtrump']=='poverty' && $firstsick=='lowtrump'))
                  {
-                   $seconsick = DB_get_sickness_by_pos_and_gameid(1,$gameid);
-                   if($secondsick == 'poverty')
+                   $secondsick = DB_get_sickness_by_pos_and_gameid(1,$gameid);
+                   if($secondsick == 'poverty'  || ($RULES['lowtrump']=='poverty' && $secondsick=='lowtrump'))
                      DB_set_sickness_by_gameid($gameid,30); /* who needs to be asked first */
                    else
                      DB_set_sickness_by_gameid($gameid,20); /* who needs to be asked first */
@@ -725,7 +756,7 @@ switch($mystatus)
              case 'dpoverty':
                /* set person with poverty to play status */
                $usersick = DB_get_sickness_by_userid_and_gameid($userid,$gameid);
-               if($usersick == 'poverty')
+               if($usersick == 'poverty'  || ($RULES['lowtrump']=='poverty' && $usersick=='lowtrump'))
                  DB_set_hand_status_by_hash($userhash,'play');
 
                /* set status of first player to be asked to poverty */
@@ -776,7 +807,7 @@ switch($mystatus)
                  }
              }
            else
-             echo "<div class=\"message\">Please, <a href=\"$INDEX?action=game&amp;me=$me\">start</a> the game.</div>\n";
+             echo "Please, <a href=\"$INDEX?action=game&amp;me=$me\">start</a> the game.<br />\n";
          }
        else
          {
@@ -786,7 +817,7 @@ switch($mystatus)
 
            $whoid = DB_get_userid('gameid-position',$gameid,$who);
            if($whoid==$myid)
-             echo "<div class=\"message\">Please, <a href=\"$INDEX?action=game&amp;me=$me\">start</a> the game.</div>\n";
+             echo "Please, <a href=\"$INDEX?action=game&amp;me=$me\">start</a> the game.<br /\n";
            else
              {
                $whohash = DB_get_hash_from_game_and_pos($gameid,$who);
@@ -805,6 +836,7 @@ switch($mystatus)
        echo "</div>\n";
        break;
       }
+
   case 'poverty':
     /* user only gets here in a poverty game, several things have to be handled here:
      * A) ask, if user wants to take trump
@@ -862,7 +894,7 @@ switch($mystatus)
        /* get information so show the cards that have been handed over in a poverty game */
        output_exchanged_cards();
 
-       echo "    </div>\n  </li>\n";  /* end div trick, end li trick */
+       echo "    </div>\n  </li>\n</ul>\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?".
                      "<a href=\"index.php?action=game&amp;me=$me&amp;trump=$user\">Yes</a> <br />\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 "<div class=\"message\">Please, <a href=\"$INDEX?action=game&amp;me=$me\">continue</a> here.</div>\n";
          }
       }
-    echo "</div>";
+    echo "</div>\n";
     break;
 
   case 'play':
@@ -1115,9 +1150,11 @@ switch($mystatus)
        echo "<div class=\"message\"><p>The game has been canceled because one player wasn't responding.</p><p>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.</p></div>";
        break;
       case 'cancel-nines':
-      case 'cancel-timedout':
        echo "<div class=\"message\"><p>The game has been canceled because one player had too many nines.</p></div>";
        break;
+      case 'cancel-lowtrump':
+       echo "<div class=\"message\"><p>The game has been canceled because one player had low trump.</p></div>";
+       break;
       case 'cancel-trump':
        echo "<div class=\"message\"><p>The game has been canceled because nobody wanted to take the trump.</p></div>";
        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
index d7a2d7f35378bd3fdccf2f9cf477251967f69c23..f06bebe65d5e82b1028764fb03136080f7bab056 100644 (file)
@@ -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");
index 06eb8de66dd02945609b8dc6c92fe5a91fd1f6d2..79e42c276f130c879ee10f06deb9af6392b40b09 100644 (file)
@@ -31,7 +31,7 @@ function output_ask_for_new_game($playerA,$playerB,$playerC,$playerD,$oldgameid)
   global $RULES;
 
   echo "<div class=\"message\">\n<form action=\"index.php?action=new\" method=\"post\">\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 "  <input type=\"hidden\" name=\"PlayerA\" value=\"$playerA\" />\n";
   echo "  <input type=\"hidden\" name=\"PlayerB\" value=\"$playerB\" />\n";
   echo "  <input type=\"hidden\" name=\"PlayerC\" value=\"$playerC\" />\n";
@@ -123,10 +123,19 @@ function output_form_for_new_game($names)
      <p>
        <select name="callrule">
         <option value="1st-own-card" selected="selected">  Can call re/contra on the first <strong>own</strong> card played, 90 on the second, etc.</option>
-        <option value="5th-card">  Can call re/contra until 5th card is played, 90 until 9th card is played, etc.</option>
+        <option value="5th-card"> Can call re/contra until 5th card is played, 90 until 9th card is played, etc.</option>
         <option value="9-cards" > Can call re/contra until 5th card is played, 90 if player still has 9 cards, etc.</option>
        </select>
      </p>
+     <h4>Low trump</h4>
+     <p>
+       Player can't trump a fox, that is none of his trump is higher than a fox.
+       <select name="lowtrump">
+        <option value="poverty">The trump will be treated as poverty and offered to another player.</option>
+        <option value="cancel">  The game will be canceled unless there is a solo.</option>
+        <option value="none">   Bad luck, the player needs to play a normal game.</option>
+       </select>
+     </p>
      <h3>Scoring-related</h3>
      <h4>(not yet implemented)</h4>
      <p><input type="submit" value="start game"></p>
@@ -205,10 +214,11 @@ function display_link_card($card,$dir="english",$type="card")
 
 function output_check_for_sickness($me,$mycards)
 {
+  global $RULES;
  ?>
   <div class="sickness"> Thanks for joining the game...<br />
 
-    do you want to play solo?
+    Do you want to play solo?
     <select name="solo" size="1">
       <option selected="selected">No</option>
       <option>trumpless</option>
@@ -245,7 +255,7 @@ function output_check_for_sickness($me,$mycards)
       echo " no <input type=\"hidden\" name=\"poverty\" value=\"no\" /> <br />\n";
     };
 
-   echo "Do you have too many nines?";
+  echo "Do you have too many nines?";
   if(count_nines($mycards)>4)
      {
        echo " yes<input type=\"radio\" name=\"nines\" value=\"yes\" checked=\"checked\" />";
@@ -256,6 +266,26 @@ function output_check_for_sickness($me,$mycards)
        echo " no <input type=\"hidden\" name=\"nines\" value=\"no\" /> <br />\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<input type=\"radio\" name=\"lowtrump\" value=\"yes\" checked=\"checked\" />";
+         echo " no <input type=\"radio\" name=\"lowtrump\" value=\"no\" /> <br />\n";
+       }
+      else
+       {
+         echo " no <input type=\"hidden\" name=\"lowtrump\" value=\"no\" /> <br />\n";
+       };
+    }
+  else
+    echo "<input type=\"hidden\" name=\"lowtrump\" value=\"no\" />";
+
    echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
    echo "<input type=\"submit\" value=\"count me in\" />\n";
 
@@ -364,7 +394,9 @@ function output_header()
   </head>
 <body onload="high_last();">
 <div class="header">
-<h1> Welcome to E-Doko </h1>
+<?php
+  echo '<h1> '._('Welcome to E-Doko').' </h1>';
+?>
 </div>
 <?php
 
@@ -378,7 +410,7 @@ function output_footer()
 
   echo "</div>\n\n";
   echo "<div class=\"footer\">\n";
-  echo "  <p class=\"left\"> copyright 2006-2009 Arun Persaud, Lance Thornton(graphics), Jeff Zerger(database support) <br />\n".
+  echo "  <p class=\"left\"> copyright 2006,2007,2008,2009,2010 Arun Persaud, Lance Thornton(graphics),  Jeff Zerger(database support) <br />\n".
     "  Verwendung der [deutschen] Kartenbilder mit Genehmigung <br />der Spielkartenfabrik Altenburg GmbH,(c) ASS Altenburger <br />\n".
     "  - ASS Altenburger Spielkarten - Spielkartenfabrik Altenburg GmbH <br />\n".
     "  a Carta Mundi Company Email: info@spielkarten.com Internet: www.spielkarten.com</p>\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 "  <select id=\"$name\" name=\"$name\" size=\"1\">\n";
+
+  foreach($LOCALE as $place=>$locale)
+    {
+      if($language==$locale)
+       echo "   <option value=\"$locale\" selected=\"selected\">$place</option>\n";
+      else
+       echo "   <option value=\"$locale\">$place</option>\n";
+    }
+  echo "  </select>\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
index 6648b993458ace924d212f9715e5d452d4a267d4..3904899191ed778840f7a7fde514e76cfcae8601 100644 (file)
@@ -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 "        <tr><td>Timezone:              </td><td>\n";
 output_select_timezone("timezone",$timezone);
 if($changed_timezone) echo "changed";
 echo "</td></tr>\n";
-
+echo "        <tr><td>Language:              </td><td>\n";
+output_select_language("language",$PREF['language']);
+echo "</td></tr>\n";
 echo "        <tr><td>Password(old):         </td><td>",
   "<input type=\"password\" id=\"password0\" name=\"password0\" size=\"20\" maxlength=\"30\" />";
 switch($changed_password)
index fb56df8243413c0f4768789c0e133d03301a6328..61e7d880af99d216d2d176b21aea668eb9d3f3b8 100644 (file)
@@ -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</p>\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
index 83618f32d856d089b33b1b5bfb306297c8951647..61b0e3f284aadb42d304c350734cf0ad2c092e24 100644 (file)
--- 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 (file)
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 (file)
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 <arun@nubati.net>, 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 <arun@nubati.net>\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 (file)
index 0000000..08d1463
--- /dev/null
@@ -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 <EMAIL@ADDRESS>, 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 <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\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 ""
index deae974c9f9343309bd0cd7d2145da8b48e3353a..498b24e663317d22c7044fca8d36b94637c7df99 100644 (file)
@@ -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