CLEANUP: moved registration to seperate php file
[e-DoKo.git] / functions.php
index 66cc57f548fced0ada347dba319c02d9f280b4fb..6fe813734755166a63c1ac3a33918d751d50d794 100644 (file)
@@ -1,5 +1,54 @@
 <?php
 
+function config_check()
+{
+  global $EmailName,$EMAIL_REPLY,$ADMIN_NAME,$ADMIN_EMAIL,$DB_work;
+
+  /* check if some variables are set in the config file, else set defaults */
+  if(!isset($EmailName))
+    $EmailName="[DoKo] ";
+  if(isset($EMAIL_REPLY))
+    {
+      ini_set("sendmail_from",$EMAIL_REPLY);
+    }
+  if(!isset($ADMIN_NAME))
+    {
+      output_header();
+      echo "<h1>Setup not completed</h1>";
+      echo "You need to set \$ADMIN_NAME in config.php.";
+      output_footer(); 
+      exit(); 
+    }    
+  if(!isset($ADMIN_EMAIL))
+    {
+      output_header();
+      echo "<h1>Setup not completed</h1>";
+      echo "You need to set \$ADMIN_EMAIL in config.php. ".
+       "If something goes wrong an email will be send to this address.";
+      output_footer(); 
+      exit(); 
+    }
+  if(!isset($DB_work))
+    {
+      output_header();
+      echo "<h1>Setup not completed</h1>";
+      echo "You need to set \$DB_work in config.php. ".
+       "If this is set to 1, the game will be suspended and one can work safely on the database.".
+       "The default should be 0 for the game to work.";
+      output_footer(); 
+      exit(); 
+    }
+  if($DB_work) 
+    {
+      output_header();
+      echo "Working on the database...please check back later."; 
+      output_footer(); 
+      exit(); 
+    }
+  
+  return;
+}
+
 function mymail($To,$Subject,$message,$header="")
 {  
   global $debug;
@@ -526,10 +575,16 @@ function can_call($what,$hash)
 {
   global $RULES;
 
-  /*TODO: check if this already has been call by teammate */
-  
   $gameid   = DB_get_gameid_by_hash($hash);
   $gametype = DB_get_gametype_by_gameid($gameid);
+  $oldcall  = DB_get_call_by_hash($hash);
+  $pcall    = DB_get_partner_call_by_hash($hash);
+
+  if( ($pcall!=NULL && $what >= $pcall) || 
+      ($oldcall!=NULL && $what >=$oldcall) )
+    {
+      return 0;
+    }
 
   $NRcards  = count(DB_get_hand($hash));
   
@@ -560,8 +615,40 @@ function can_call($what,$hash)
        return 1;
       break;
     case "9-cards":
-      if( ($what/10) <= $NRcards + $offset)
-       return 1;
+      
+      if($oldcall!=NULL && $pcall!=NULL)
+       $mincall = ($oldcall>$pcall) ? $pcall : $oldcall;
+      else if($oldcall!=NULL)
+       $mincall = $oldcall;
+      else if ($pcall!=NULL)
+       $mincall = $pcall;
+      else
+       $mincall = -1;
+
+      if( 12 <= ($NRcards + $offset))
+       {
+         return 1;
+       }
+      else if ( 9 <= ($NRcards + $offset))
+       {
+         if( ($mincall>=0 && $mincall==120) )
+           return 1;
+       }
+      else if ( 6 <= ($NRcards + $offset))
+       {
+         if( ($mincall>=0 && $mincall<=90 && $what<=60 ) )
+           return 1;
+       }
+      else if ( 3 <= ($NRcards + $offset))
+       {
+         if( ($mincall>=0 && $mincall<=60 && $what<=30 ) )
+           return 1;
+       }
+      else if ( 0 <= ($NRcards + $offset))
+       {
+         if( ($mincall>=0 && $mincall<=30 && $what==0 ) )
+           return 1;
+       };
       break;
     }