From 924f395a39eeccbcd54d540613e440cbedd6ba3d Mon Sep 17 00:00:00 2001 From: Arun Persaud Date: Sat, 26 Apr 2008 13:01:41 -0700 Subject: CLEANUP: cleaned up index.php a bit more by introducing an 'action' variable no more if, but one nice switch statement in index.php Signed-off-by: Arun Persaud --- include/cancelgame.php | 8 ++ include/functions.php | 6 +- include/game.php | 40 ++++++---- include/login.php | 33 +++++++++ include/logout.php | 2 - include/newgame.php | 186 ++++++++++++++++++++++++++++++++++++++++++++--- include/newgameready.php | 175 -------------------------------------------- include/output.php | 6 +- include/reminder.php | 10 ++- include/user.php | 10 +-- index.php | 66 +++++++---------- 11 files changed, 288 insertions(+), 254 deletions(-) create mode 100644 include/login.php delete mode 100644 include/newgameready.php diff --git a/include/cancelgame.php b/include/cancelgame.php index 9f86142..fba950e 100644 --- a/include/cancelgame.php +++ b/include/cancelgame.php @@ -7,6 +7,14 @@ if(!isset($HOST)) output_status(); +if(!myisset("me")) + { + echo "Hmm, you really shouldn't mess with the urls.
\n"; + output_footer(); + DB_close(); + exit(); + } + $me = $_REQUEST["me"]; /* test for valid ID */ diff --git a/include/functions.php b/include/functions.php index 991d53d..28e5937 100644 --- a/include/functions.php +++ b/include/functions.php @@ -700,7 +700,7 @@ function display_table () if(!$debug) echo " $name \n"; else - echo " $name\n"; + echo " $name\n"; /* add hints for poverty, wedding, solo, etc */ if($GT=="poverty" && $party=="re") @@ -823,10 +823,10 @@ function display_user_menu() while( $r = mysql_fetch_array($result,MYSQL_NUM)) { - echo "game ".DB_format_gameid($r[1])."
\n"; + echo "game ".DB_format_gameid($r[1])."
\n"; } - echo "
Start a new game\n"; + echo "
Start a new game\n"; echo "
Statistics\n"; diff --git a/include/game.php b/include/game.php index 0e16292..51d4320 100644 --- a/include/game.php +++ b/include/game.php @@ -5,6 +5,14 @@ if(!isset($HOST)) exit; +if(!myisset("me")) + { + echo "Hmm, you really shouldn't mess with the urls.
\n"; + output_footer(); + DB_close(); + exit(); + } + $me = $_REQUEST["me"]; /* test for valid ID */ @@ -70,7 +78,7 @@ for($i=1;$i<5;$i++) }; /* put everyting in a form */ -echo "
\n"; +echo "\n"; /* output game */ @@ -86,7 +94,7 @@ if($session) if($hash == $me) echo "$i \n"; else - echo "$i \n"; + echo "$i \n"; $i++; } echo "\n"; @@ -174,7 +182,7 @@ switch($mystatus) 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."?me=".$hash."\n\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); */ } @@ -208,7 +216,7 @@ switch($mystatus) * unless a user tries to cheat ;) * can also happen if user reloads the page! */ - echo "

You need to answer the questions.

"; + echo "

You need to answer the questions.

"; DB_set_hand_status_by_hash($me,'init'); } else @@ -223,7 +231,7 @@ switch($mystatus) if($Nvorbehalt>1) { echo "

You selected more than one vorbehalt, please go back ". - "and answer the question again.

"; + "and answer the question again.

"; DB_set_hand_status_by_hash($me,'init'); } else @@ -274,7 +282,7 @@ switch($mystatus) DB_set_sickness_by_hash($me,"nines"); } - echo " Ok, done with checking, please go to the next step of the setup.

"; + echo " Ok, done with checking, please go to the next step of the setup.

"; /* move on to the next stage*/ DB_set_hand_status_by_hash($me,'poverty'); @@ -304,7 +312,7 @@ switch($mystatus) { $message = "Everyone finish the questionary in game ".DB_format_gameid($gameid).", ". "please visit this link now to continue: \n". - " ".$HOST.$INDEX."?me=".$userhash."\n\n" ; + " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ; mymail($To,$EmailName." finished setup in game ".DB_format_gameid($gameid),$message); } }; @@ -513,7 +521,7 @@ switch($mystatus) DB_set_party_by_hash($me,"contra"); echo "Whoever will make the first trick will be on the re team.
\n"; - echo " Ok, the game can start now, please finish the setup.
"; + echo " Ok, the game can start now, please finish the setup.
"; DB_set_hand_status_by_hash($me,'play'); break; @@ -576,7 +584,7 @@ switch($mystatus) DB_set_player_by_gameid($gameid,$userid); $message = "Someone has poverty, it's your turn to decide, if you want to take the trump. Please visit:". - " ".$HOST.$INDEX."?me=".$userhash."\n\n" ; + " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ; mymail($To,$EmailName." poverty (game ".DB_format_gameid($gameid).")",$message); } @@ -658,7 +666,7 @@ switch($mystatus) $message = "Someone has poverty, it's your turn to decide, ". "if you want to take the trump. Please visit:". - " ".$HOST.$INDEX."?me=".$userhash."\n\n" ; + " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ; mymail($To,$EmailName." poverty (game ".DB_format_gameid($gameid).")",$message); } } @@ -732,10 +740,10 @@ switch($mystatus) /* count trump */ if($nrtrump<4) echo "Player $name has $nrtrump trump. Do you want to take them?". - "yes
\n"; + "yes
\n"; } } - echo "No,way I take those trump...
\n"; + echo "No,way I take those trump...
\n"; echo "
\n"; echo "Your cards are:
\n"; @@ -803,11 +811,11 @@ 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."?me=".$hash."\n\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); } else - echo " Please, start the game.
"; + echo " Please, start the game.
"; } else echo "\n
"; @@ -1260,7 +1268,7 @@ switch($mystatus) $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."?me=".$next_hash."\n\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); } @@ -1526,7 +1534,7 @@ switch($mystatus) $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.$INDEX."?me=".$hash."\n\n" ; + $HOST.$INDEX."?action=game&me=".$hash."\n\n" ; if( DB_get_email_pref_by_uid($user) != "emailaddict" ) mymail($To,$EmailName."game over (game ".DB_format_gameid($gameid).") part 2(2)",$link); } diff --git a/include/login.php b/include/login.php new file mode 100644 index 0000000..346c71e --- /dev/null +++ b/include/login.php @@ -0,0 +1,33 @@ + \ No newline at end of file diff --git a/include/logout.php b/include/logout.php index d74f091..f2ebbaf 100644 --- a/include/logout.php +++ b/include/logout.php @@ -10,6 +10,4 @@ session_unset(); session_destroy(); $_SESSION = array(); -echo "
You are now logged out!
\n". -"(This will take you back to the home-page)
"; ?> \ No newline at end of file diff --git a/include/newgame.php b/include/newgame.php index 5764568..5db0f28 100644 --- a/include/newgame.php +++ b/include/newgame.php @@ -7,16 +7,180 @@ if(!isset($HOST)) output_status(); /* user needs to be logged in to do this */ -if( isset($_SESSION["name"]) ) +if(! isset($_SESSION["name"]) ) { - $names = DB_get_all_names(); - echo "
\n"; - output_form_for_new_game($names); - echo "
\n"; - display_user_menu(); + echo "
Please log in.
"; } - else - { - echo "
Please log in.
"; - } -?> \ No newline at end of file +else + { + if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen","callrule" )) + { + /* get my name */ + $name = $_SESSION["name"]; + + /* the names of the four players */ + $PlayerA = $_REQUEST["PlayerA"]; + $PlayerB = $_REQUEST["PlayerB"]; + $PlayerC = $_REQUEST["PlayerC"]; + $PlayerD = $_REQUEST["PlayerD"]; + + /* the person who sets up the game has to be one of the players */ + if(!in_array($name,array($PlayerA,$PlayerB,$PlayerC,$PlayerD))) + { + echo "
You need to be one of the players to start a new game.
"; + output_footer(); + DB_close(); + exit(); + } + + /* what rules were selected */ + $dullen = $_REQUEST["dullen"]; + $schweinchen = $_REQUEST["schweinchen"]; + $call = $_REQUEST["callrule"]; + + /* get the emails addresses of the players */ + $EmailA = DB_get_email('name',$PlayerA); + $EmailB = DB_get_email('name',$PlayerB); + $EmailC = DB_get_email('name',$PlayerC); + $EmailD = DB_get_email('name',$PlayerD); + + /* this is used to check if the player names are all ok */ + if($EmailA=="" || $EmailB=="" || $EmailC=="" || $EmailD=="") + { + echo "couldn't find one of the names, please start a new game"; + output_footer(); + DB_close(); + exit(); + } + + /* get user ids */ + $useridA = DB_get_userid('name',$PlayerA); + $useridB = DB_get_userid('name',$PlayerB); + $useridC = DB_get_userid('name',$PlayerC); + $useridD = DB_get_userid('name',$PlayerD); + + /* create random numbers */ + $randomNR = create_array_of_random_numbers($useridA,$useridB,$useridC,$useridD); + $randomNRstring = join(":",$randomNR); + + /* create game */ + $followup = NULL; + /* is this game a follow up in an already started session? */ + if(myisset("followup") ) + { + $followup= $_REQUEST["followup"]; + $session = DB_get_session_by_gameid($followup); + $ruleset = DB_get_ruleset_by_gameid($followup); /* just copy ruleset from old game, + this way no manipulation is possible */ + + /* check if there is a game in pre or play mode, in that case do nothing */ + if( DB_is_session_active($session) > 0 ) + { + echo "

There is already a game going on in session $session, you can't start a new one

"; + output_footer(); + DB_close(); + exit(); + } + else if ( DB_is_session_active($session) < 0 ) + { + echo "

ERROR: status of session $session couldn't be determined.

"; + output_footer(); + DB_close(); + exit(); + } + + if($session) + mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre',". + "'$ruleset','$session' ,NULL)"); + else + { + /* get max session and start a new one */ + $max = DB_get_max_session(); + $max++; + mysql_query("UPDATE Game SET session='".$max."' WHERE id=".DB_quote_smart($followup)); + mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre',". + "'$ruleset','$max' ,NULL)"); + } + } + else /* no follow up, start a new session */ + { + /* get ruleset information or create new one */ + $ruleset = DB_get_ruleset($dullen,$schweinchen,$call); + if($ruleset <0) + { + myerror("Error defining ruleset: $ruleset"); + output_footer(); + DB_close(); + exit(); + }; + /* get max session */ + $max = DB_get_max_session(); + $max++; + + mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre', ". + "'$ruleset','$max' ,NULL)"); + } + $game_id = mysql_insert_id(); + + /* create hash */ + $TIME = (string) time(); /* to avoid collisions */ + $hashA = md5("AGameOfDoko".$game_id.$PlayerA.$EmailA.$TIME); + $hashB = md5("AGameOfDoko".$game_id.$PlayerB.$EmailB.$TIME); + $hashC = md5("AGameOfDoko".$game_id.$PlayerC.$EmailC.$TIME); + $hashD = md5("AGameOfDoko".$game_id.$PlayerD.$EmailD.$TIME); + + /* create hands */ + mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridA). + ", ".DB_quote_smart($hashA).", 'start','1',NULL,NULL,NULL,NULL)"); + $hand_idA = mysql_insert_id(); + mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridB). + ", ".DB_quote_smart($hashB).", 'start','2',NULL,NULL,NULL,NULL)"); + $hand_idB = mysql_insert_id(); + mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridC). + ", ".DB_quote_smart($hashC).", 'start','3',NULL,NULL,NULL,NULL)"); + $hand_idC = mysql_insert_id(); + mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridD). + ", ".DB_quote_smart($hashD).", 'start','4',NULL,NULL,NULL,NULL)"); + $hand_idD = mysql_insert_id(); + + /* save cards */ + for($i=0;$i<12;$i++) + mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idA', '".$randomNR[$i]."', 'false')"); + for($i=12;$i<24;$i++) + mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idB', '".$randomNR[$i]."', 'false')"); + for($i=24;$i<36;$i++) + mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idC', '".$randomNR[$i]."', 'false')"); + for($i=36;$i<48;$i++) + mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idD', '".$randomNR[$i]."', 'false')"); + + /* send out email, TODO: check for error with email */ + $message = "\n". + "you are invited to play a game of DoKo (that is to debug the program ;).\n". + "Place comments and bug reports here:\n". + "http://wiki.nubati.net/index.php?title=EmailDoko\n\n". + "The whole round would consist of the following players:\n". + "$PlayerA\n". + "$PlayerB\n". + "$PlayerC\n". + "$PlayerD\n\n". + "If you want to join this game, please follow this link:\n\n". + "".$HOST.$INDEX."?action=game&me="; + + mymail($EmailA,"You are invited to a game of DoKo","Hello $PlayerA,\n".$message.$hashA); + mymail($EmailB,"You are invited to a game of DoKo","Hello $PlayerB,\n".$message.$hashB); + mymail($EmailC,"You are invited to a game of DoKo","Hello $PlayerC,\n".$message.$hashC); + mymail($EmailD,"You are invited to a game of DoKo","Hello $PlayerD,\n".$message.$hashD); + + echo "
You started a new game. The emails have been sent out!
\n"; + } + else + { + $names = DB_get_all_names(); + echo "
\n"; + output_form_for_new_game($names); + echo "
\n"; + display_user_menu(); + } + } + +?> diff --git a/include/newgameready.php b/include/newgameready.php deleted file mode 100644 index 6d74af0..0000000 --- a/include/newgameready.php +++ /dev/null @@ -1,175 +0,0 @@ -Please log in.
"; - } - else - { - /* get my name */ - $name = $_SESSION["name"]; - - /* the names of the four players */ - $PlayerA = $_REQUEST["PlayerA"]; - $PlayerB = $_REQUEST["PlayerB"]; - $PlayerC = $_REQUEST["PlayerC"]; - $PlayerD = $_REQUEST["PlayerD"]; - - /* the person who sets up the game has to be one of the players */ - if(!in_array($name,array($PlayerA,$PlayerB,$PlayerC,$PlayerD))) - { - echo "
You need to be one of the players to start a new game.
"; - output_footer(); - DB_close(); - exit(); - } - - /* what rules were selected */ - $dullen = $_REQUEST["dullen"]; - $schweinchen = $_REQUEST["schweinchen"]; - $call = $_REQUEST["callrule"]; - - /* get the emails addresses of the players */ - $EmailA = DB_get_email('name',$PlayerA); - $EmailB = DB_get_email('name',$PlayerB); - $EmailC = DB_get_email('name',$PlayerC); - $EmailD = DB_get_email('name',$PlayerD); - - /* this is used to check if the player names are all ok */ - if($EmailA=="" || $EmailB=="" || $EmailC=="" || $EmailD=="") - { - echo "couldn't find one of the names, please start a new game"; - output_footer(); - DB_close(); - exit(); - } - - /* get user ids */ - $useridA = DB_get_userid('name',$PlayerA); - $useridB = DB_get_userid('name',$PlayerB); - $useridC = DB_get_userid('name',$PlayerC); - $useridD = DB_get_userid('name',$PlayerD); - - /* create random numbers */ - $randomNR = create_array_of_random_numbers($useridA,$useridB,$useridC,$useridD); - $randomNRstring = join(":",$randomNR); - - /* create game */ - $followup = NULL; - /* is this game a follow up in an already started session? */ - if(myisset("followup") ) - { - $followup= $_REQUEST["followup"]; - $session = DB_get_session_by_gameid($followup); - $ruleset = DB_get_ruleset_by_gameid($followup); /* just copy ruleset from old game, - this way no manipulation is possible */ - - /* check if there is a game in pre or play mode, in that case do nothing */ - if( DB_is_session_active($session) > 0 ) - { - echo "

There is already a game going on in session $session, you can't start a new one

"; - output_footer(); - DB_close(); - exit(); - } - else if ( DB_is_session_active($session) < 0 ) - { - echo "

ERROR: status of session $session couldn't be determined.

"; - output_footer(); - DB_close(); - exit(); - } - - if($session) - mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre',". - "'$ruleset','$session' ,NULL)"); - else - { - /* get max session and start a new one */ - $max = DB_get_max_session(); - $max++; - mysql_query("UPDATE Game SET session='".$max."' WHERE id=".DB_quote_smart($followup)); - mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre',". - "'$ruleset','$max' ,NULL)"); - } - } - else /* no follow up, start a new session */ - { - /* get ruleset information or create new one */ - $ruleset = DB_get_ruleset($dullen,$schweinchen,$call); - if($ruleset <0) - { - myerror("Error defining ruleset: $ruleset"); - output_footer(); - DB_close(); - exit(); - }; - /* get max session */ - $max = DB_get_max_session(); - $max++; - - mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre', ". - "'$ruleset','$max' ,NULL)"); - } - $game_id = mysql_insert_id(); - - /* create hash */ - $TIME = (string) time(); /* to avoid collisions */ - $hashA = md5("AGameOfDoko".$game_id.$PlayerA.$EmailA.$TIME); - $hashB = md5("AGameOfDoko".$game_id.$PlayerB.$EmailB.$TIME); - $hashC = md5("AGameOfDoko".$game_id.$PlayerC.$EmailC.$TIME); - $hashD = md5("AGameOfDoko".$game_id.$PlayerD.$EmailD.$TIME); - - /* create hands */ - mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridA). - ", ".DB_quote_smart($hashA).", 'start','1',NULL,NULL,NULL,NULL)"); - $hand_idA = mysql_insert_id(); - mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridB). - ", ".DB_quote_smart($hashB).", 'start','2',NULL,NULL,NULL,NULL)"); - $hand_idB = mysql_insert_id(); - mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridC). - ", ".DB_quote_smart($hashC).", 'start','3',NULL,NULL,NULL,NULL)"); - $hand_idC = mysql_insert_id(); - mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridD). - ", ".DB_quote_smart($hashD).", 'start','4',NULL,NULL,NULL,NULL)"); - $hand_idD = mysql_insert_id(); - - /* save cards */ - for($i=0;$i<12;$i++) - mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idA', '".$randomNR[$i]."', 'false')"); - for($i=12;$i<24;$i++) - mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idB', '".$randomNR[$i]."', 'false')"); - for($i=24;$i<36;$i++) - mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idC', '".$randomNR[$i]."', 'false')"); - for($i=36;$i<48;$i++) - mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idD', '".$randomNR[$i]."', 'false')"); - - /* send out email, TODO: check for error with email */ - $message = "\n". - "you are invited to play a game of DoKo (that is to debug the program ;).\n". - "Place comments and bug reports here:\n". - "http://wiki.nubati.net/index.php?title=EmailDoko\n\n". - "The whole round would consist of the following players:\n". - "$PlayerA\n". - "$PlayerB\n". - "$PlayerC\n". - "$PlayerD\n\n". - "If you want to join this game, please follow this link:\n\n". - "".$HOST.$INDEX."?me="; - - mymail($EmailA,"You are invited to a game of DoKo","Hello $PlayerA,\n".$message.$hashA); - mymail($EmailB,"You are invited to a game of DoKo","Hello $PlayerB,\n".$message.$hashB); - mymail($EmailC,"You are invited to a game of DoKo","Hello $PlayerC,\n".$message.$hashC); - mymail($EmailD,"You are invited to a game of DoKo","Hello $PlayerD,\n".$message.$hashD); - - echo "
You started a new game. The emails have been sent out!
\n"; - } -/* end set up a new game */ -?> \ No newline at end of file diff --git a/include/output.php b/include/output.php index 1637603..b22b6ef 100644 --- a/include/output.php +++ b/include/output.php @@ -56,7 +56,7 @@ function output_form_for_new_game($names)

Players

Please select four players (or use the randomly pre-selected names)

Remember: you need to be one of the players ;)

- +
table @@ -278,7 +278,7 @@ function output_home_page($pre,$game,$done,$avgtime)

Please register, in case you have not done that yet
or login with you email-address or name and password here:

- +
Login @@ -383,7 +383,7 @@ function output_status() /* logout info */ echo "\n
"; echo $name; - echo " logout"; + echo " logout"; echo "
\n"; /* last logon time */ diff --git a/include/reminder.php b/include/reminder.php index 1e3135c..a269478 100644 --- a/include/reminder.php +++ b/include/reminder.php @@ -7,6 +7,14 @@ if(!isset($HOST)) output_status(); +if(!myisset("me")) + { + echo "Hmm, you really shouldn't mess with the urls.
\n"; + output_footer(); + DB_close(); + exit(); + } + $me = $_REQUEST["me"]; /* test for valid ID */ @@ -39,7 +47,7 @@ if( (time()-strtotime($r[0]) > 60*60*24*7) && ($r[2]!='gameover') ) /* = 1 week "It's your turn in game ".DB_format_gameid($gameid)." \n". "Actually everyone else is waiting for you for more than a week now ;)\n\n". "Please visit this link now to continue: \n". - " ".$HOST.$INDEX."?me=".$userhash."\n\n" ; + " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ; /* make sure we don't send too many reminders to one person */ if(DB_get_reminder($r[1],$gameid)>0) diff --git a/include/user.php b/include/user.php index 0f67a68..8feac01 100644 --- a/include/user.php +++ b/include/user.php @@ -212,14 +212,14 @@ if(myisset("forgot")) } if($r[4]=='pre') { - echo "\n p "; + echo "\n p "; } else if ($r[4]=='gameover') - echo "\n F "; + echo "\n F "; else { - echo "\n P "; + echo "\n P "; } if($r[4] != 'gameover') { @@ -233,12 +233,12 @@ if(myisset("forgot")) if(DB_get_reminder($r[3],$gameid)==0) if(time()-strtotime($r[2]) > 60*60*24*7) echo "". - "Send a reminder."; + "Send a reminder."; echo "(it's $name's turn)\n"; }; if(time()-strtotime($r[2]) > 60*60*24*30) echo "". - "Cancel?". + "Cancel?". " (clicking here is final and can't be restored)"; } diff --git a/index.php b/index.php index 54e2cb7..31c497a 100644 --- a/index.php +++ b/index.php @@ -31,51 +31,41 @@ output_header(); /* The rest of the file consists of handling user input. * The user sends information via html GET and POST variables, - * the script checks if these are set via "myisset" - * which can check a list of variables. + * and the action variable tells the prog what the user wants to do */ +if(myisset("action")) + $action=$_REQUEST['action']; +else + $action=""; /* so that we can use a default option below */ -/* does the user want to log out? */ -if(myisset("logout")) - { - require './include/logout.php'; - } -/* check if we want to start a new game */ -else if(myisset("new")) +switch($action) { + case 'new': require './include/newgame.php'; - } -/*check if everything is ready to set up a new game */ -else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen","callrule" )) - { - require './include/newgameready.php'; - } -/* cancel a game, if nothing has happend in the last N minutes */ -else if(myisset("cancel","me")) - { + break; + case 'cancel': require './include/cancelgame.php'; - } -/* send out a reminder */ -else if(myisset("remind","me")) - { + break; + case 'reminder': require './include/reminder.php'; - } -/* handle request from one specific player for one game, - * (the hash is set on a per game base) */ -else if(myisset("me")) - { + break; + case 'logout': + require './include/logout.php'; + require './include/welcome.php'; + break; + case 'login': + require './include/login.php'; + require './include/user.php'; + break; + case 'game': require './include/game.php'; - } -/* user status page */ -else if( myisset("email","password") || isset($_SESSION["name"]) ) - { - require './include/user.php'; - } -/* default login page */ - else - { - require './include/welcome.php'; - } + break; + default: + if(isset($_SESSION["name"])) + require './include/user.php'; + else + require './include/welcome.php'; + } output_footer(); -- cgit v1.2.3-18-g5258