From: Arun Persaud Date: Thu, 8 Nov 2007 19:58:20 +0000 (+0100) Subject: NEW FEATURE: addicted people can turn of a lot of the email spam and just check... X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=commitdiff_plain;h=9732aef914603924915bde24684f322843ead085 NEW FEATURE: addicted people can turn of a lot of the email spam and just check online all emails saying: it's your turn can be turned off now by a user preference --- diff --git a/db.php b/db.php index db1910f..f5f6673 100644 --- a/db.php +++ b/db.php @@ -792,20 +792,68 @@ 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"; + /* Cardset */ + $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"; - return; + /* Email */ + $result = mysql_query("SELECT value FROM User_Prefs". + " WHERE user_id='$myid' AND pref_key='email'" ); + $r = mysql_fetch_array($result,MYSQL_NUM); + if($r) + { + if($r[0]=="emailaddict") + $PREF["email"]="emailaddict"; + else + $PREF["email"]="emailnonaddict"; + } + else + $PREF["email"]="emailnonaddict"; + + return; +} + +function DB_get_email_pref_by_hash($hash) +{ + $result = mysql_query("SELECT value FROM Hand". + " LEFT JOIN User_Prefs ON Hand.user_id=User_Prefs.user_id". + " WHERE hash='$hash' AND pref_key='email'" ); + $r = mysql_fetch_array($result,MYSQL_NUM); + if($r) + { + if($r[0]=="emailaddict") + return "emailaddict"; + else + return "emailnonaddict"; + } + else + return "emailnonaddict"; +} + +function DB_get_email_pref_by_uid($uid) +{ + $result = mysql_query("SELECT value FROM User_Prefs ". + " WHERE user_id='$uid' AND pref_key='email'" ); + $r = mysql_fetch_array($result,MYSQL_NUM); + if($r) + { + if($r[0]=="emailaddict") + return "emailaddict"; + else + return "emailnonaddict"; + } + else + return "emailnonaddict"; } function DB_get_unused_randomnumbers($userstr) diff --git a/index.php b/index.php index cf14fbd..bf96982 100644 --- a/index.php +++ b/index.php @@ -1048,7 +1048,7 @@ else if(myisset("me")) $who = DB_get_userid_by_email($email); DB_set_player_by_gameid($gameid,$who); - if($hash!=$me) + if($hash!=$me && DB_get_email_pref_by_hash($hash)!="emailaddict") { /* email startplayer) */ $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n". @@ -1441,7 +1441,8 @@ else if(myisset("me")) $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."?me=".$next_hash."\n\n" ; - mymail($email,$EmailName."a card has been played in game ".DB_format_gameid($gameid),$message); + if( DB_get_email_pref_by_uid($who)!="emailaddict" ) + mymail($email,$EmailName."a card has been played in game ".DB_format_gameid($gameid),$message); } else /* send out final email */ { @@ -1603,7 +1604,8 @@ else if(myisset("me")) $hash = DB_get_hash_from_gameid_and_userid($gameid,$user); $link = "Use this link to have a look at game ".DB_format_gameid($gameid).": ".$host."?me=".$hash."\n\n" ; - mymail($To,$EmailName."game over (game ".DB_format_gameid($gameid).") part 2(2)",$link); + if( DB_get_email_pref_by_uid($user) != "emailaddict" ) + mymail($To,$EmailName."game over (game ".DB_format_gameid($gameid).") part 2(2)",$link); } } } @@ -1910,6 +1912,18 @@ else if( myisset("email","password") || isset($_SESSION["name"]) ) DB_quote_smart($setpref).")"); echo "Ok, changed you preferences for the cards.\n"; break; + case "emailaddict": + case "emailnonaddict": + $result = mysql_query("SELECT * from User_Prefs". + " WHERE user_id='$myid' AND pref_key='email'" ); + if( mysql_fetch_array($result,MYSQL_NUM)) + $result = mysql_query("UPDATE User_Prefs SET value=".DB_quote_smart($setpref). + " WHERE user_id='$myid' AND pref_key='email'" ); + else + $result = mysql_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','email',". + DB_quote_smart($setpref).")"); + echo "Ok, changed you preferences for sending out emails.\n"; + break; } } else if(myisset("passwd")) diff --git a/output.php b/output.php index a8d6bf1..39f67b0 100644 --- a/output.php +++ b/output.php @@ -10,11 +10,18 @@ function output_user_settings() echo "

Settings

\n"; echo "change password
"; + echo "
Card set
\n"; if( $PREF["cardset"] == "english" ) echo "use german cards
"; else echo "use english cards
"; + echo "
Email
\n"; + if( $PREF["email"] == "emailaddict" ) + echo "I'm not addicted (emails for each move)
"; + else + echo "Addicted (minimal amount of emails)
"; + echo "\n"; return;