From 0703a75b3d53fd28f21f3dbabf2c1630da46bd2c Mon Sep 17 00:00:00 2001 From: arun Date: Tue, 22 May 2007 09:49:07 +0000 Subject: [PATCH] feature: added link to game in final email, CC'ed people in final email --- db.php | 27 ++++++++++++++++++++ functions.php | 12 ++++++--- index.php | 69 ++++++++++++++++++++++++++++++++++++++++----------- output.php | 11 ++++++++ 4 files changed, 101 insertions(+), 18 deletions(-) diff --git a/db.php b/db.php index 98e7724..64a80b9 100644 --- a/db.php +++ b/db.php @@ -704,5 +704,32 @@ function DB_set_party_by_hash($hash,$party) return; } +function DB_get_PREF($myid) +{ + global $PREF; + + $result = mysql_query("SELECT value from User_Prefs". + " WHERE user_id='$myid' AND pref_key='cardset'" ); + $r = mysql_fetch_array($result,MYSQL_NUM); + if($r) + { + if($r[0]=="germancards" && (time()-strtotime( "2009-12-31 23:59:59")<0) ) /* licence only valid until then */ + $PREF["cardset"]="altenburg"; + else + $PREF["cardset"]="english"; + } + else + $PREF["cardset"]="english"; + + $result = mysql_query("SELECT value from User_Prefs". + " WHERE user_id='$myid' AND pref_key='ccemail'" ); + $r = mysql_fetch_array($result,MYSQL_NUM); + if($r) + $PREF["ccemail"]=$r[0]; + else + $PREF["ccemail"]="no"; + + return; +} ?> \ No newline at end of file diff --git a/functions.php b/functions.php index 75f1fed..f33dd1c 100644 --- a/functions.php +++ b/functions.php @@ -1,6 +1,6 @@ \\0", $message); //$message = ereg_replace("(http.*)[ <>]","\\1 ",$message); - echo "
To: $To
Subject: $Subject
$message
\n"; + echo "
To: $To
"; + if($header != "") + echo $header."
"; + echo "Subject: $Subject
$message
\n"; } else - mail($To,$Subject,$message); + if($header != "") + mail($To,$Subject,$message,$header); + else + mail($To,$Subject,$message); return; } diff --git a/index.php b/index.php index 0620502..e8fffb7 100644 --- a/index.php +++ b/index.php @@ -230,18 +230,8 @@ else if(myisset("me")) $myhand = DB_get_handid_by_hash($me); /* get prefs and save them */ - $result = mysql_query("SELECT value from User_Prefs". - " WHERE user_id='$myid' AND pref_key='cardset'" ); - $r = mysql_fetch_array($result,MYSQL_NUM); - if($r) - { - if($r[0]=="germancards" && (time()-strtotime( "2009-12-31 23:59:59")<0) ) /* licence only valid until then */ - $PREF["cardset"]="altenburg"; - else - $PREF["cardset"]="english"; - } - else - $PREF["cardset"]="english"; + DB_get_PREF($myid); + /* end set pref */ /* get rule set for this game */ @@ -1312,11 +1302,27 @@ else if(myisset("me")) $message .= "\n"; while( $r = mysql_fetch_array($result,MYSQL_NUM)) $message .= " FINAL SCORE: ".$r[0]." ".$r[1]."\n"; + + /* check who wants to be CC'ed on the email */ + $h = array(); + $header = ""; + foreach($userids as $user) + { + $result = mysql_query("SELECT value from User_Prefs". + " WHERE user_id='$user' AND pref_key='ccemail'" ); + $r = mysql_fetch_array($result,MYSQL_NUM); + if($r && $r[0]=="yes") + $h[] = DB_get_email_by_userid($user); + } + if(sizeof($h)) + $header = "CC: ".join(",",$h)."\r\n"; foreach($userids as $user) { - $To = DB_get_email_by_userid($user); - mymail($To,$EmailName."game over (game $gameid)",$message); + $To = DB_get_email_by_userid($user); + $hash = DB_get_hash_from_gameid_and_userid($gameid,$user) + $mymessage = $message."Use this link to have a look at the game: ".$host."?me=".$hash."\n\n" ; + mymail($To,$EmailName."game over (game $gameid)",$mymessage,$header); } } @@ -1492,6 +1498,7 @@ else if(myisset("me")) /* test id and password, should really be done in one step */ $email = $_REQUEST["email"]; $password = $_REQUEST["password"]; + if(myisset("forgot")) { @@ -1528,6 +1535,8 @@ else if(myisset("me")) if($ok) { + DB_get_PREF($uid); + if(myisset("setpref")) { $setpref=$_REQUEST["setpref"]; @@ -1544,6 +1553,21 @@ else if(myisset("me")) $result = mysql_query("INSERT INTO User_Prefs VALUES(NULL,'$uid','cardset',".DB_quote_smart($setpref).")"); echo "Ok, changed you preferences for the cards.\n"; break; + case "ccemail": + $result = mysql_query("SELECT * from User_Prefs". + " WHERE user_id='$uid' AND pref_key='ccemail'" ); + if( mysql_fetch_array($result,MYSQL_NUM)) + if($PREF["ccemail"]=="yes") + $result = mysql_query("UPDATE User_Prefs SET value=".DB_quote_smart("no"). + " WHERE user_id='$uid' AND pref_key='ccemail'" ); + else + $result = mysql_query("UPDATE User_Prefs SET value=".DB_quote_smart("yes"). + " WHERE user_id='$uid' AND pref_key='ccemail'" ); + else + $result = mysql_query("INSERT INTO User_Prefs VALUES(NULL,'$uid','ccemail',".DB_quote_smart("yes").")"); + echo "Ok, changed you preferences for being CC'ed on emails.\n"; + break; + } } else /* output default user page */ @@ -1562,10 +1586,25 @@ else if(myisset("me")) DB_update_user_timestamp($uid); + echo "

these are your games that haven't started yet:
\n"; + $result = mysql_query("SELECT Hand.hash,Hand.game_id,Game.mod_date from Hand". + " LEFT JOIN Game On Hand.game_id=Game.id". + " WHERE Hand.user_id='$uid' AND Game.status='pre'" ); + while( $r = mysql_fetch_array($result,MYSQL_NUM)) + { + echo "game #".$r[1]." "; + if(time()-strtotime($r[2]) > 60*60*24*30) + echo " The game has been running for over a month.". + " Do you want to cancel it? yes". + " (clicking here is final and can't be restored)"; + echo "
"; + } + echo "

\n"; + echo "

these are the games you are playing in:
\n"; $result = mysql_query("SELECT Hand.hash,Hand.game_id,Game.mod_date from Hand". " LEFT JOIN Game On Hand.game_id=Game.id". - " WHERE Hand.user_id='$uid' AND Game.status<>'gameover'" ); + " WHERE Hand.user_id='$uid' AND Game.status='play'" ); while( $r = mysql_fetch_array($result,MYSQL_NUM)) { echo "game #".$r[1]." "; diff --git a/output.php b/output.php index a224d6f..8288ee2 100644 --- a/output.php +++ b/output.php @@ -27,6 +27,8 @@ function output_link_to_user_page($email,$password) function output_user_settings($email,$password) { + global $PREF; + echo "

\n"; echo "

Settings

\n"; echo "
\n"; @@ -46,6 +48,15 @@ function output_user_settings($email,$password) echo " \n"; echo "
\n"; echo "
\n"; + echo "
\n"; + echo " \n"; + echo " \n"; + echo " \n"; + if($PREF["ccemail"]=="no") + echo "
\n"; + else + echo "
\n"; + echo "
\n"; echo "
\n"; return; } -- 2.25.1