NEW FEATURE: added admin name and email address to be configurable
authorArun Persaud <arun@nubati.net>
Sat, 23 Jun 2007 17:14:58 +0000 (19:14 +0200)
committerArun Persaud <arun@nubati.net>
Sun, 24 Jun 2007 16:42:04 +0000 (18:42 +0200)
email and name can be defined in config.php. Errors are send to that email address.

functions.php
index.php

index be8897453ab574d2b0f2f4c4e9f8f52745bddf53..7ee180e946b9d2f8c248b9062e428b1d866ac61d 100644 (file)
@@ -28,7 +28,7 @@ function myisset()
   /* returns 1 if all names passed as args are defined by a GET or POST statement,
    * else return 0
    */
-
+  
   $ok   = 1;
   $args = func_get_args();
   
@@ -41,10 +41,17 @@ function myisset()
   return $ok;
 }
 
+function myerror($message)
+{
+  echo "<span class=\"error\">".htmlspecialchars($message)."</span>\n";
+  mymail($ADMIN_EMAIL,$EmailName." Error in Code",$message);
+  return;
+}
+
 function pos_array($c,$arr)
 {
   $ret = 0;
-
+  
   $i   = 0;
   foreach($arr as $a)
     {
@@ -335,7 +342,8 @@ function card_value($card)
     case 48:                  
       return 0;
     default:
-      echo "something went wrong, please contact the admin. ErrorCode: 2 - $card<br>";
+      myerror("something went wrong, please contact $ADMIN_NAME at $ADMIN_EMAIL. ErrorCode: 2 - $card<br>");
+      echo "something went wrong, please contact $ADMIN_NAME at $ADMIN_EMAIL. ErrorCode: 2 - $card<br>";
       return 0;
     }
 }
index 980db24fcdd2f7909acd2ab148fa2316cb051f0b..44a5d5fc233f3d8220538ecc3a1e103be6ffabfa 100644 (file)
--- a/index.php
+++ b/index.php
@@ -13,6 +13,23 @@ 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 send to this address.";
+    output_footer(); 
+    exit(); 
+  }
 
 /* in case work has to be done on the database or other section we can
  * shut down the server and tell people to come back later 
@@ -28,7 +45,8 @@ if(0)
 if(DB_open()<0)
   {
     output_header();
-    echo "Database error, can't connect...";
+    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.";
     output_footer(); 
     exit(); 
   }
@@ -79,7 +97,7 @@ if(myisset("new"))
     $ruleset = DB_get_ruleset($dullen,$schweinchen);
     if($ruleset <0) 
       {
-       echo "Error defining ruleset: $ruleset";
+       myerror("Error defining ruleset: $ruleset");
        output_footer();
        DB_close();
        exit();
@@ -379,7 +397,7 @@ else if(myisset("me"))
          /* all these variables have a pre-selected default,
           * so we should never get here,
           * unless a user tries to cheat ;) */
-         echo "something went wrong...please contact the admin.";
+         echo "something went wrong during the setup...please contact the $ADMIN_NAME at $ADMIN_EMAIL.";
        }
       else
        {
@@ -771,7 +789,8 @@ else if(myisset("me"))
                  $r      = mysql_fetch_array($result,MYSQL_NUM);
                  if(!$r)
                    {
-                     die("error in poverty");
+                     myerror("error in poverty");
+                     die();
                    };
                  if($r[0]==12)
                    {
@@ -1396,8 +1415,9 @@ else if(myisset("me"))
                  if($winnerid>0)
                    mysql_query("INSERT INTO Score VALUES (NULL, '$gameid', '$winnerid', '$points')");
                  else
-                   echo "ERROR during scoring";
-                 
+                   {
+                     myerror("ERROR during scoring");
+                   }             
                  /* email all players */
                  /* individual score */
                  $result = mysql_query("SELECT fullname, IFNULL(SUM(score),0), Hand.party FROM Hand".
@@ -1458,8 +1478,9 @@ else if(myisset("me"))
                      if($winnerid>0)
                        mysql_query("INSERT INTO Score VALUES (NULL, '$gameid', '$winnerid', '$points')");
                      else
-                       echo "ERROR during scoring";
-                     
+                       {
+                         myerror("ERROR during scoring");
+                       };
                      if($debug)
                        echo "DEBUG: $winner got $points <br />";
                      
@@ -1627,7 +1648,7 @@ else if(myisset("me"))
        }
       break;
     default:
-      echo "error in testing the status";
+      myerror("error in testing the status");
     }
     output_footer();
     DB_close();