summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/cancelgame.php4
-rw-r--r--include/functions.php43
-rw-r--r--include/game.php64
-rw-r--r--include/newgame.php13
-rw-r--r--include/reminder.php6
-rw-r--r--include/user.php5
6 files changed, 86 insertions, 49 deletions
diff --git a/include/cancelgame.php b/include/cancelgame.php
index 357d226..2240203 100644
--- a/include/cancelgame.php
+++ b/include/cancelgame.php
@@ -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)
{
- $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 */
diff --git a/include/functions.php b/include/functions.php
index f982029..7141ec7 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -54,10 +54,49 @@ function config_check()
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;
+ $header = "";
+
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";
- mymail($ADMIN_EMAIL,$EmailName." Error in Code",$message);
+ sendmail($ADMIN_EMAIL,$EmailName." Error in Code",$message);
return;
}
diff --git a/include/game.php b/include/game.php
index 845a562..b3f852d 100644
--- a/include/game.php
+++ b/include/game.php
@@ -307,8 +307,8 @@ switch($mystatus)
$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 */
@@ -351,14 +351,13 @@ switch($mystatus)
{
/* email startplayer */
/*
- $email = DB_get_email('position-gameid',$startplayer,$gameid);
$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" ;
- 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)
{
- $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 */
@@ -731,9 +730,8 @@ switch($mystatus)
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);
- $who = DB_get_userid('email',$email);
+ $who = DB_get_userid('hash',$hash);
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" ;
- 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
@@ -760,7 +759,6 @@ switch($mystatus)
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);
@@ -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" ;
- 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 = DB_get_email('position-gameid',$startplayer,$gameid);
$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)
@@ -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" ;
- 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
@@ -947,8 +946,8 @@ switch($mystatus)
$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 */
@@ -960,16 +959,16 @@ switch($mystatus)
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);
- $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" ;
- mymail($To,$EmailName." poverty (game ".DB_format_gameid($gameid).")",$message);
+ $subject = 'Poverty (game '.DB_format_gameid($gameid).')';
+ mymail($userid,$subject,$message);
}
}
else
@@ -1052,18 +1051,16 @@ switch($mystatus)
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);
- $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" ;
- 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";
@@ -1104,9 +1101,8 @@ switch($mystatus)
/* 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);
- $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')
@@ -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" ;
- 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);
- $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' )
- 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 */
{
@@ -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";
- 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
diff --git a/include/newgame.php b/include/newgame.php
index 40ab74d..4ce13cb 100644
--- a/include/newgame.php
+++ b/include/newgame.php
@@ -182,14 +182,11 @@ else
"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);
diff --git a/include/reminder.php b/include/reminder.php
index 9c297cd..61bd37b 100644
--- a/include/reminder.php
+++ b/include/reminder.php
@@ -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]);
- $To = DB_get_email('userid',$r[1]);
$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);
- 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>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
diff --git a/include/user.php b/include/user.php
index 6cc9637..8855fc0 100644
--- a/include/user.php
+++ b/include/user.php
@@ -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".
- " 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));