CLEANUP: make emails more uniform
authorArun Persaud <arun@nubati.net>
Sat, 14 Feb 2009 07:40:26 +0000 (23:40 -0800)
committerArun Persaud <arun@nubati.net>
Tue, 24 Feb 2009 05:32:21 +0000 (21:32 -0800)
provide a standard header and footer. Also prepare for emails to be send to the database for later delivery.

include/cancelgame.php
include/functions.php
include/game.php
include/newgame.php
include/reminder.php
include/user.php

index 357d226d9becc6a3b0a86915c5fd075d6094d33a..224020356f6bf95efc5965905b53255f9d3f639d 100644 (file)
@@ -44,8 +44,8 @@ if(time()-strtotime($r[0]) > 60*60*24*30) /* = 1 month */
     $userids = DB_get_all_userid_by_gameid($gameid);
     foreach($userids as $user)
       {
     $userids = DB_get_all_userid_by_gameid($gameid);
     foreach($userids as $user)
       {
-       $To = DB_get_email('userid',$user);
-       mymail($To,$EmailName."game ".DB_format_gameid($gameid)." canceled (timed out)",$message);
+       $subject = "Game ".DB_format_gameid($gameid)." canceled (timed out)";
+       mymail($user,$subject,$message);
       }
 
     /* delete everything from the dB */
       }
 
     /* delete everything from the dB */
index f982029a4947035c7e0346007ef791cbf7b90592..7141ec75c86236389a668a33539d870ed0a6fdc8 100644 (file)
@@ -54,10 +54,49 @@ function config_check()
   return;
 }
 
   return;
 }
 
-function mymail($To,$Subject,$message,$header="")
+function mymail($uid,$subject,$message)
 {
 {
+  global $EmailName;
+
+  /* check if user wants email right away or if we should save it in
+   * the database for later delivery
+   */
+  if(0)
+    {
+      /* send to database (not yet implemented)*/
+    }
+  else
+    {
+      /* send email right away */
+
+      /* add standard header and footer */
+      $subject = "$EmailName".$subject;
+
+      /* standard greeting */
+      $header  = "Hello ...\n\n";
+
+      /* and standard goodbye */
+      $footer  = "\n\nHave a nice day\n".
+       "   your E-Doko service department\n\n".
+       "-- \n".
+       "You can change your mail delivery mode in the preference menu.\n".
+       'web: http://doko.nubati.net   '.
+       'help: http://wiki.nubati.net/EmailDoko   '.
+       'bugs: http://wiki.nubati.net/EmailDokoIssues';
+
+      $To = DB_get_email('userid',$uid);
+
+      sendmail($To,$subject,$header.$message.$footer);
+    }
+}
+
+function sendmail($To,$Subject,$message)
+{
+  /* this function sends the mail or outputs to the screen in case of debugging */
   global $debug,$EMAIL_REPLY;
 
   global $debug,$EMAIL_REPLY;
 
+  $header = "";
+
   if(isset($EMAIL_REPLY))
     $header .= "From: e-DoKo daemon <$EMAIL_REPLY>\r\n";
 
   if(isset($EMAIL_REPLY))
     $header .= "From: e-DoKo daemon <$EMAIL_REPLY>\r\n";
 
@@ -104,7 +143,7 @@ function myisset()
 function myerror($message)
 {
   echo "<span class=\"error\">".htmlspecialchars($message)."</span>\n";
 function myerror($message)
 {
   echo "<span class=\"error\">".htmlspecialchars($message)."</span>\n";
-  mymail($ADMIN_EMAIL,$EmailName." Error in Code",$message);
+  sendmail($ADMIN_EMAIL,$EmailName." Error in Code",$message);
   return;
 }
 
   return;
 }
 
index 845a5629b6cea269fab793e38ef4bff6b3b1af8d..b3f852d3ab83d25d8c79337011606f339d4ab469 100644 (file)
@@ -307,8 +307,8 @@ switch($mystatus)
            $userids = DB_get_all_userid_by_gameid($gameid);
            foreach($userids as $user)
              {
            $userids = DB_get_all_userid_by_gameid($gameid);
            foreach($userids as $user)
              {
-               $To = DB_get_email('userid',$user);
-               mymail($To,"$EmailName game ".DB_format_gameid($gameid)." canceled",$message);
+               $subject = 'Game '.DB_format_gameid($gameid).' canceled';
+               mymail($user,$subject,$message);
              }
 
            /* delete everything from the dB */
              }
 
            /* delete everything from the dB */
@@ -351,14 +351,13 @@ switch($mystatus)
                  {
                    /* email startplayer */
                    /*
                  {
                    /* email startplayer */
                    /*
-                    $email       = DB_get_email('position-gameid',$startplayer,$gameid);
                     $hash        = DB_get_hash_from_game_and_pos($gameid,$startplayer);
                     $hash        = DB_get_hash_from_game_and_pos($gameid,$startplayer);
-                    $who         = DB_get_userid('email',$email);
+                    $who         = DB_get_userid('hash',$hash);
                     DB_set_player_by_gameid($gameid,$who);
 
                     $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
                     "Use this link to go the game: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
                     DB_set_player_by_gameid($gameid,$who);
 
                     $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
                     "Use this link to go the game: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
-                    mymail($email,$EmailName."ready, set, go... (game ".DB_format_gameid($gameid).") ",$message);
+                    mymail($who,"Ready, set, go... (game ".DB_format_gameid($gameid).") ",$message);
                    */
                  }
              }
                    */
                  }
              }
@@ -600,8 +599,8 @@ switch($mystatus)
            $userids = DB_get_all_userid_by_gameid($gameid);
            foreach($userids as $user)
              {
            $userids = DB_get_all_userid_by_gameid($gameid);
            foreach($userids as $user)
              {
-               $To = DB_get_email('userid',$user);
-               mymail($To,"$EmailName game ".DB_format_gameid($gameid)." canceled",$message);
+               $subject = 'Game '.DB_format_gameid($gameid).' canceled';
+               mymail($user,$subject,$message);
              }
 
            /* delete everything from the dB */
              }
 
            /* delete everything from the dB */
@@ -731,9 +730,8 @@ switch($mystatus)
        if($gametype!='poverty' && $gametype!='dpoverty')
          {
            $startplayer = DB_get_startplayer_by_gameid($gameid);
        if($gametype!='poverty' && $gametype!='dpoverty')
          {
            $startplayer = DB_get_startplayer_by_gameid($gameid);
-           $email       = DB_get_email('position-gameid',$startplayer,$gameid);
            $hash        = DB_get_hash_from_game_and_pos($gameid,$startplayer);
            $hash        = DB_get_hash_from_game_and_pos($gameid,$startplayer);
-           $who         = DB_get_userid('email',$email);
+           $who         = DB_get_userid('hash',$hash);
            DB_set_player_by_gameid($gameid,$who);
 
            if($hash!=$me)
            DB_set_player_by_gameid($gameid,$who);
 
            if($hash!=$me)
@@ -743,7 +741,8 @@ switch($mystatus)
                    /* email startplayer */
                    $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
                      "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
                    /* email startplayer */
                    $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
                      "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
-                   mymail($email,$EmailName."ready, set, go... (game ".DB_format_gameid($gameid).") ",$message);
+                   $subject = 'Ready, set, go... (game '.DB_format_gameid($gameid).')';
+                   mymail($who,$subject,$message);
                  }
              }
            else
                  }
              }
            else
@@ -760,7 +759,6 @@ switch($mystatus)
              echo " Please, <a href=\"$INDEX?action=game&amp;me=$me\">start</a> the game.<br />\n";
            else
              {
              echo " Please, <a href=\"$INDEX?action=game&amp;me=$me\">start</a> the game.<br />\n";
            else
              {
-               $email   = DB_get_email('position-gameid',$who,$gameid);
                $whohash = DB_get_hash_from_game_and_pos($gameid,$who);
                DB_set_player_by_gameid($gameid,$whoid);
 
                $whohash = DB_get_hash_from_game_and_pos($gameid,$who);
                DB_set_player_by_gameid($gameid,$whoid);
 
@@ -769,7 +767,8 @@ switch($mystatus)
                    /* email player for poverty */
                    $message = "Poverty: It's your turn now in game ".DB_format_gameid($gameid).".\n".
                      "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$whohash."\n\n" ;
                    /* email player for poverty */
                    $message = "Poverty: It's your turn now in game ".DB_format_gameid($gameid).".\n".
                      "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$whohash."\n\n" ;
-                   mymail($email,$EmailName."Poverty (game ".DB_format_gameid($gameid).") ",$message);
+                   $subject = 'Poverty (game '.DB_format_gameid($gameid).') ';
+                   mymail($whoid,$subject,$message);
                  }
              }
          }
                  }
              }
          }
@@ -856,9 +855,8 @@ switch($mystatus)
 
        /* email start player */
        $startplayer = DB_get_startplayer_by_gameid($gameid);
 
        /* email start player */
        $startplayer = DB_get_startplayer_by_gameid($gameid);
-       $email       = DB_get_email('position-gameid',$startplayer,$gameid);
        $hash        = DB_get_hash_from_game_and_pos($gameid,$startplayer);
        $hash        = DB_get_hash_from_game_and_pos($gameid,$startplayer);
-       $who         = DB_get_userid('email',$email);
+       $who         = DB_get_userid('hash',$hash);
        DB_set_player_by_gameid($gameid,$who);
 
        if($hash!=$me)
        DB_set_player_by_gameid($gameid,$who);
 
        if($hash!=$me)
@@ -868,7 +866,8 @@ switch($mystatus)
                /* email startplayer */
                $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
                  "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
                /* email startplayer */
                $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
                  "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
-               mymail($email,$EmailName."ready, set, go... (game ".DB_format_gameid($gameid).") ",$message);
+               $subject = 'Ready, set, go... (game '.DB_format_gameid($gameid).') ';
+               mymail($who,$subject,$message);
              }
          }
        else
              }
          }
        else
@@ -947,8 +946,8 @@ switch($mystatus)
                $userids = DB_get_all_userid_by_gameid($gameid);
                foreach($userids as $user)
                  {
                $userids = DB_get_all_userid_by_gameid($gameid);
                foreach($userids as $user)
                  {
-                   $To = DB_get_email('userid',$user);
-                   mymail($To,$EmailName."game ".DB_format_gameid($gameid)." canceled (poverty not resolved)",$message);
+                   $subject = 'Game '.DB_format_gameid($gameid).' canceled (poverty not resolved)';
+                   mymail($user,$subject,$message);
                  }
 
                /* delete everything from the dB */
                  }
 
                /* delete everything from the dB */
@@ -960,16 +959,16 @@ switch($mystatus)
            else
              {
                /* email next player, set his status to poverty */
            else
              {
                /* email next player, set his status to poverty */
-               $To       = DB_get_email('position-gameid',$mypos+$next,$gameid);
                $userhash = DB_get_hash_from_game_and_pos($gameid,$mypos+$next);
                $userhash = DB_get_hash_from_game_and_pos($gameid,$mypos+$next);
-               $userid   = DB_get_userid('email',$To);
+               $userid   = DB_get_userid('hash',$userhash);
 
                DB_set_player_by_gameid($gameid,$userid);
                DB_set_hand_status_by_hash($userhash,'poverty');
 
                $message = "Someone has poverty, it's your turn to decide, if you want to take the trump. Please visit:".
                  " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ;
 
                DB_set_player_by_gameid($gameid,$userid);
                DB_set_hand_status_by_hash($userhash,'poverty');
 
                $message = "Someone has poverty, it's your turn to decide, if you want to take the trump. Please visit:".
                  " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ;
-               mymail($To,$EmailName." poverty (game ".DB_format_gameid($gameid).")",$message);
+               $subject = 'Poverty (game '.DB_format_gameid($gameid).')';
+               mymail($userid,$subject,$message);
              }
          }
        else
              }
          }
        else
@@ -1052,18 +1051,16 @@ switch($mystatus)
                    if($mypos+$next>4)
                      echo "<div class=\"message\">Error in poverty, please contact the Admin</div>\n";
 
                    if($mypos+$next>4)
                      echo "<div class=\"message\">Error in poverty, please contact the Admin</div>\n";
 
-                   $To       = DB_get_email('position-gameid',$mypos+$next,$gameid);
                    $userhash = DB_get_hash_from_game_and_pos($gameid,$mypos+$next);
                    $userhash = DB_get_hash_from_game_and_pos($gameid,$mypos+$next);
-                   $userid   = DB_get_userid('email',$To);
+                   $userid   = DB_get_userid('hash',$userhash);
 
                    DB_set_player_by_gameid($gameid,$userid);
                    DB_set_hand_status_by_hash($userhash,'poverty');
 
                    $message = "Two people have poverty, it's your turn to decide, if you want to take the trump. Please visit:".
                      " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ;
 
                    DB_set_player_by_gameid($gameid,$userid);
                    DB_set_hand_status_by_hash($userhash,'poverty');
 
                    $message = "Two people have poverty, it's your turn to decide, if you want to take the trump. Please visit:".
                      " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ;
-                   mymail($To,$EmailName." double poverty (game ".DB_format_gameid($gameid).")",$message);
-
-
+                   $subject = 'Double poverty (game '.DB_format_gameid($gameid).')';
+                   mymail($userid,$subject,$message);
                  }
              }
            echo "<div class=\"message\"> Please, <a href=\"$INDEX?action=game&amp;me=$me\">continue</a> here.</div>\n";
                  }
              }
            echo "<div class=\"message\"> Please, <a href=\"$INDEX?action=game&amp;me=$me\">continue</a> here.</div>\n";
@@ -1104,9 +1101,8 @@ switch($mystatus)
 
            /* email startplayer */
            $startplayer = DB_get_startplayer_by_gameid($gameid);
 
            /* email startplayer */
            $startplayer = DB_get_startplayer_by_gameid($gameid);
-           $email       = DB_get_email('position-gameid',$startplayer,$gameid);
            $hash        = DB_get_hash_from_game_and_pos($gameid,$startplayer);
            $hash        = DB_get_hash_from_game_and_pos($gameid,$startplayer);
-           $who         = DB_get_userid('email',$email);
+           $who         = DB_get_userid('hash',$hash);
            DB_set_player_by_gameid($gameid,$who);
 
            if($hash!=$me && DB_get_email_pref_by_hash($hash)!='emailaddict')
            DB_set_player_by_gameid($gameid,$who);
 
            if($hash!=$me && DB_get_email_pref_by_hash($hash)!='emailaddict')
@@ -1114,7 +1110,8 @@ switch($mystatus)
                /* email startplayer) */
                $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
                  "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
                /* email startplayer) */
                $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
                  "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
-               mymail($email,$EmailName."ready, set, go... (game ".DB_format_gameid($gameid).") ",$message);
+               $subject = 'Ready, set, go... (game '.DB_format_gameid($gameid).')';
+               mymail($who,$subject,$message);
              }
          }
       }
              }
          }
       }
@@ -1540,15 +1537,17 @@ switch($mystatus)
            if(DB_get_game_status_by_gameid($gameid)=='play')
              {
                $next_hash = DB_get_hash_from_game_and_pos($gameid,$next);
            if(DB_get_game_status_by_gameid($gameid)=='play')
              {
                $next_hash = DB_get_hash_from_game_and_pos($gameid,$next);
-               $email     = DB_get_email('hash',$next_hash);
-               $who       = DB_get_userid('email',$email);
+               $who       = DB_get_userid('hash',$next_hash);
                DB_set_player_by_gameid($gameid,$who);
 
                $message = "A card has been played in game ".DB_format_gameid($gameid).".\n\n".
                  "It's your turn  now.\n".
                  "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$next_hash."\n\n" ;
                if( DB_get_email_pref_by_uid($who)!='emailaddict' )
                DB_set_player_by_gameid($gameid,$who);
 
                $message = "A card has been played in game ".DB_format_gameid($gameid).".\n\n".
                  "It's your turn  now.\n".
                  "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$next_hash."\n\n" ;
                if( DB_get_email_pref_by_uid($who)!='emailaddict' )
-                 mymail($email,$EmailName."a card has been played in game ".DB_format_gameid($gameid),$message);
+                 {
+                   $subject = 'A card has been played in game '.DB_format_gameid($gameid);
+                   mymail($who,$subject,$message);
+                 }
              }
            else /* send out final email */
              {
              }
            else /* send out final email */
              {
@@ -1795,7 +1794,8 @@ switch($mystatus)
                  $To = implode(",",$all);
 
                  $message .= "\n\n (you can use reply all on this email to reach all the players.)\n";
                  $To = implode(",",$all);
 
                  $message .= "\n\n (you can use reply all on this email to reach all the players.)\n";
-                 mymail($To,$EmailName."Game over (game ".DB_format_gameid($gameid).") ",$message);
+                 $subject = $EmailName.' Game over (game '.DB_format_gameid($gameid).') ';
+                 sendmail($To,$subject,$message);
              }
          }
        else
              }
          }
        else
index 40ab74de6f47e88e959e451c976a6044b213ed3f..4ce13cb771e07e80c9663ed300a6bd40487b289b 100644 (file)
@@ -182,14 +182,11 @@ else
          "If you want to join this game, please follow this link:\n\n".
          "".$HOST.$INDEX."?action=game&me=";
 
          "If you want to join this game, please follow this link:\n\n".
          "".$HOST.$INDEX."?action=game&me=";
 
-       mymail($EmailA,"$EmailName You are invited to a game of DoKo (game ".DB_format_gameid($gameid).")",
-              "Hello $PlayerA,\n".$message.$hashA);
-       mymail($EmailB,"$EmailName You are invited to a game of DoKo (game ".DB_format_gameid($gameid).")",
-              "Hello $PlayerB,\n".$message.$hashB);
-       mymail($EmailC,"$EmailName You are invited to a game of DoKo (game ".DB_format_gameid($gameid).")",
-              "Hello $PlayerC,\n".$message.$hashC);
-       mymail($EmailD,"$EmailName You are invited to a game of DoKo (game ".DB_format_gameid($gameid).")",
-              "Hello $PlayerD,\n".$message.$hashD);
+       $subject = 'You are invited to a game of DoKo (game '.DB_format_gameid($gameid).')';
+       sendmail($EmailA,$subject, "Hello $PlayerA,\n".$message.$hashA);
+       sendmail($EmailB,$subject, "Hello $PlayerB,\n".$message.$hashB);
+       sendmail($EmailC,$subject, "Hello $PlayerC,\n".$message.$hashC);
+       sendmail($EmailD,$subject, "Hello $PlayerD,\n".$message.$hashD);
 
        echo "<div class=\"message\">You started a new game. The emails have been sent out!</div>\n";
         display_user_menu($myid);
 
        echo "<div class=\"message\">You started a new game. The emails have been sent out!</div>\n";
         display_user_menu($myid);
index 9c297cd4d7793ef58474618bce8e9e3ee0e85c89..61bd37ba1322d9104213353ae23c0080a79e59e8 100644 (file)
@@ -33,7 +33,6 @@ $r = DB_query_array("SELECT mod_date,player,status from Game WHERE id='$gameid'
 if( (time()-strtotime($r[0]) > 60*60*24*7)  && ($r[2]!='gameover') ) /* = 1 week */
   {
     $name = DB_get_name('userid',$r[1]);
 if( (time()-strtotime($r[0]) > 60*60*24*7)  && ($r[2]!='gameover') ) /* = 1 week */
   {
     $name = DB_get_name('userid',$r[1]);
-    $To   = DB_get_email('userid',$r[1]);
     $userhash = DB_get_hash_from_gameid_and_userid($gameid,$r[1]);
 
     $message = "Hello $name, \n\n".
     $userhash = DB_get_hash_from_gameid_and_userid($gameid,$r[1]);
 
     $message = "Hello $name, \n\n".
@@ -50,12 +49,13 @@ if( (time()-strtotime($r[0]) > 60*60*24*7)  && ($r[2]!='gameover') ) /* = 1 week
     else
       {
        DB_set_reminder($r[1],$gameid);
     else
       {
        DB_set_reminder($r[1],$gameid);
-       mymail($To,$EmailName."Reminder: game ".DB_format_gameid($gameid)." it's your turn",$message);
+       $subject ='Reminder: game '.DB_format_gameid($gameid)." it's your turn";
+       mymail($r[1],$subject,$message);
 
        echo "<p style=\"background-color:red\";>Game ".DB_format_gameid($gameid).
          ": an email has been sent out.<br /><br /></p>";
       }
   }
  else
 
        echo "<p style=\"background-color:red\";>Game ".DB_format_gameid($gameid).
          ": an email has been sent out.<br /><br /></p>";
       }
   }
  else
-   echo "<p>You need to wait longer before you can send out a reminder...</p>\n";
+   echo '<p>You need to wait longer before you can send out a reminder...</p>\n';
 ?>
\ No newline at end of file
 ?>
\ No newline at end of file
index 6cc96370bac78718f1e1a8510cecd5be7213e339..8855fc070502bade79e253dd5d6b054502415ee7 100644 (file)
@@ -53,8 +53,9 @@ if(myisset("forgot"))
              "   $newpw    \n".
              "to log into the server. The new password is valid for 24h, so make\n".
              "sure you reset your password to something new. Your old password will\n".
              "   $newpw    \n".
              "to log into the server. The new password is valid for 24h, so make\n".
              "sure you reset your password to something new. Your old password will\n".
-             " also still be valid until you set a new one\n";
-           mymail($email,$EmailName."recovery ",$message);
+             "also still be valid until you set a new one.\n";
+           $subject = $EmailName.' Recovery';
+           sendmail($email,$subject,$message);
 
            /* we save these in the database */
            DB_set_recovery_password($myid,md5($newpw));
 
            /* we save these in the database */
            DB_set_recovery_password($myid,md5($newpw));