NEW FEATURE: implement Lance's Schweinchen rule
[e-DoKo.git] / include / functions.php
index f8a0da4e58d7e4faf1121a6eb44f707a9bb66899..d09408cd43094b0c0e4ca00b5b460b2442297fbb 100644 (file)
@@ -177,14 +177,27 @@ function compare_cards($a,$b,$game)
            return 1;
          if($b == 19 || $b == 20 )
            return 0;
-       };
-      if($RULES['schweinchen']=='second' && $GAME['schweinchen-second'])
+       }
+      else if($RULES['schweinchen']=='second' && $GAME['schweinchen-second'])
        {
          if($a == 19 || $a == 20 )
            return 1;
          if($b == 19 || $b == 20 )
            return 0;
-       };
+       }
+      else if($RULES['schweinchen']=='secondaftercall' && $GAME['schweinchen-who'] && $GAME['schweinchen-second'] )
+       {
+         /* check if a call was made either by the player or his partner. If so activate Schweinchen rule. */
+         if(DB_get_call_by_hash($GAME['schweinchen-who']) || DB_get_partner_call_by_hash($GAME['schweinchen-who']) )
+           {
+             if($a == 19 || $a == 20 )
+               return 1;
+             if($b == 19 || $b == 20 )
+               return 0;
+           }
+         /* if not, do nothing and the foxes are just handeled as normal trump */
+       }
+       ;
     case "heart":
     case "spade":
     case "club":
@@ -846,12 +859,18 @@ function display_table ()
 
 function display_user_menu()
 {
-  global $WIKI,$myid,$INDEX;
+  global $WIKI,$INDEX;
+
+  /* get the id we are looking for */
+  if(isset($_SESSION['id']))
+     $myid = $_SESSION['id'];
+  else
+    return;
 
   $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='$myid'".
-                    " AND Game.player='$myid'".
+                    " AND ( Game.player='$myid' OR ISNULL(Game.player) )".
                     " AND Game.status<>'gameover'".
                     " ORDER BY Game.session" );
 
@@ -1055,7 +1074,12 @@ function format_score_table_html($score,$userid)
       $i++;
       $output.=" <tr>";
       $userhash = DB_get_hash_from_gameid_and_userid($game['gameid'],$userid);
-      $output.="  <td> <a href=\"".$INDEX."?action=game&amp;me=".$userhash."\">$i</a></td>";
+      /* create link to old games only if you are logged in and its your game*/
+      if(isset($_SESSION['id']) && $_SESSION['id']==$userid)
+       $output.="  <td> <a href=\"".$INDEX."?action=game&amp;me=".$userhash."\">$i</a></td>";
+      else
+       $output.="  <td>$i</td>";
+
       foreach($game['players'] as $id=>$points)
        $output.="<td>".$points."</td>";
       $output.="<td>".$game['points'];
@@ -1071,6 +1095,30 @@ function format_score_table_html($score,$userid)
   return $output;
 }
 
+function createCache($content, $cacheFile)
+{
+  $fp = fopen($cacheFile,"w");
+  if($fp)
+    {
+      fwrite($fp,$content);
+      fclose($fp);
+    }
+  else
+    echo "WARNING: couldn't create cache file";
+
+  return;
+}
+
+function getCache($cacheFile, $expireTime)
+{
+  if( file_exists($cacheFile) &&
+      filemtime($cacheFile )>( time() - $expireTime ) )
+    {
+      return file_get_contents($cacheFile);
+    }
+
+  return false;
+}
 
 
 ?>