From: Arun Persaud Date: Mon, 16 Jun 2008 06:43:19 +0000 (-0700) Subject: NEW FEATURE: login button X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=commitdiff_plain;h=27cbc14d28d072c37474ac1e96d677b88dde27ba NEW FEATURE: login button added a login button to the top right, in case you were not logged in. output_status can now be called in only one place, ie index.php and all pages will get the menu... Signed-off-by: Arun Persaud --- diff --git a/include/cancelgame.php b/include/cancelgame.php index 5b85534..43d3274 100644 --- a/include/cancelgame.php +++ b/include/cancelgame.php @@ -10,9 +10,7 @@ output_status(); if(!myisset("me")) { echo "Hmm, you really shouldn't mess with the urls.
\n"; - output_footer(); - DB_close(); - exit(); + return; } $me = $_REQUEST["me"]; @@ -23,9 +21,7 @@ if(!$myid) { echo "Can't find you in the database, please check the url.
\n"; echo "perhaps the game has been canceled, check by login in here."; - output_footer(); - DB_close(); - exit(); + return; } DB_update_user_timestamp($myid); diff --git a/include/game.php b/include/game.php index 0350d9e..25e2b2f 100644 --- a/include/game.php +++ b/include/game.php @@ -9,9 +9,7 @@ if(!isset($HOST)) if(!myisset("me")) { echo "Hmm, you really shouldn't mess with the urls.
\n"; - output_footer(); - DB_close(); - exit(); + return; } $me = $_REQUEST["me"]; @@ -21,17 +19,11 @@ if(!$myid) { echo "Can't find you in the database, please check the url.
\n"; echo "perhaps the game has been canceled, check by login in here."; - output_footer(); - DB_close(); - exit(); + return; } global $GAME,$RULES,$CARDS; -/* user might get here by clicking on the link in an email, so session might not be set */ -if(isset($_SESSION["name"])) - output_status($_SESSION["name"]); - /* the user has done something, update the timestamp */ DB_update_user_timestamp($myid); @@ -501,9 +493,7 @@ switch($mystatus) echo "The game has been canceled because ".DB_get_name('userid',$nines). " has five or more nines and nobody is playing solo.\n"; - output_footer(); - DB_close(); - exit(); + return; } else if($poverty==1) /* one person has poverty */ { @@ -832,9 +822,7 @@ switch($mystatus) DB_cancel_game($me); echo "

Game ".DB_format_gameid($gameid)." has been canceled.

"; - output_footer(); - DB_close(); - exit(); + return; } else { @@ -1894,8 +1882,4 @@ switch($mystatus) output_ask_for_new_game($names[1],$names[2],$names[3],$names[0],$gameid); } } - - output_footer(); - DB_close(); - exit(); ?> \ No newline at end of file diff --git a/include/newgame.php b/include/newgame.php index feb5216..db6b62d 100644 --- a/include/newgame.php +++ b/include/newgame.php @@ -20,7 +20,6 @@ else return; DB_update_user_timestamp($myid); - output_status(); if( !myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen","callrule" )) { @@ -45,9 +44,7 @@ else 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(); + return; } /* what rules were selected */ @@ -65,9 +62,7 @@ else if($EmailA=="" || $EmailB=="" || $EmailC=="" || $EmailD=="") { echo "couldn't find one of the names, please start a new game"; - output_footer(); - DB_close(); - exit(); + return; } /* get user ids */ @@ -94,16 +89,12 @@ else 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(); + return; } else if ( DB_is_session_active($session) < 0 ) { echo "

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

"; - output_footer(); - DB_close(); - exit(); + return; } if($session) @@ -126,9 +117,7 @@ else if($ruleset <0) { myerror("Error defining ruleset: $ruleset"); - output_footer(); - DB_close(); - exit(); + return; }; /* get max session */ $max = DB_get_max_session(); diff --git a/include/output.php b/include/output.php index 2f846be..81f01c5 100644 --- a/include/output.php +++ b/include/output.php @@ -372,7 +372,13 @@ function output_status() date_default_timezone_set($zone); echo "
last login: ".date("r",$unixtime)."
\n"; - }; + } + else + { + echo "\n
\n"; + echo "login\n"; + echo "
\n"; + } return; } diff --git a/include/preferences.php b/include/preferences.php index 8a6050d..0382193 100644 --- a/include/preferences.php +++ b/include/preferences.php @@ -18,7 +18,6 @@ $changed_cards = 0; $changed_timezone = 0; $changed_autosetup = 0; -output_status(); display_user_menu(); /* get old infos */ @@ -206,8 +205,5 @@ echo " \n"; echo " \n"; echo "\n"; -output_footer(); -DB_close(); -exit(); - +return; ?> \ No newline at end of file diff --git a/include/reminder.php b/include/reminder.php index 8844e48..9c297cd 100644 --- a/include/reminder.php +++ b/include/reminder.php @@ -5,14 +5,10 @@ if(!isset($HOST)) exit; -output_status(); - if(!myisset("me")) { echo "Hmm, you really shouldn't mess with the urls.
\n"; - output_footer(); - DB_close(); - exit(); + return; } $me = $_REQUEST["me"]; @@ -23,9 +19,7 @@ if(!$myid) { echo "Can't find you in the database, please check the url.
\n"; echo "perhaps the game has been canceled, check by login in here."; - output_footer(); - DB_close(); - exit(); + return; } DB_update_user_timestamp($myid); diff --git a/include/stats.php b/include/stats.php index cff6a84..97e1979 100644 --- a/include/stats.php +++ b/include/stats.php @@ -12,8 +12,6 @@ $myid = DB_get_userid('email',$email); if(!$myid) return; -output_status(); - $PREF = DB_get_PREF($myid); DB_update_user_timestamp($myid); diff --git a/include/user.php b/include/user.php index 7b4880d..19eb27b 100644 --- a/include/user.php +++ b/include/user.php @@ -6,17 +6,17 @@ if(!isset($HOST)) exit; /* test id and password, should really be done in one step */ -if(!isset($_SESSION["name"])) +if(!isset($_SESSION["name"])) { $email = $_REQUEST["email"]; $password = $_REQUEST["password"]; } - else - { - $name = $_SESSION["name"]; - $email = DB_get_email('name',$name); - $password = DB_get_passwd_by_name($name); - }; +else + { + $name = $_SESSION["name"]; + $email = DB_get_email('name',$name); + $password = DB_get_passwd_by_name($name); + }; /* user has forgotten his password */ if(myisset("forgot")) @@ -81,111 +81,103 @@ if(myisset("forgot")) "or else try again."; } } - else - { /* normal user page */ - - /* verify password and email */ - if(strlen($password)!=32) - $password = md5($password); - - $ok = 1; - $myid = DB_get_userid('email-password',$email,$password); - if(!$myid) - $ok = 0; - - if($ok) - { - /* user information is ok */ - $myname = DB_get_name('email',$email); - $_SESSION["name"] = $myname; - output_status(); +else + { /* normal user page */ - $PREF = DB_get_PREF($myid); + /* verify password and email */ + if(strlen($password)!=32) + $password = md5($password); - DB_update_user_timestamp($myid); - - display_user_menu(); - - /* display all games the user has played */ - echo "
"; - echo "

These are all your games:

\n"; - echo "

Session:
\n"; - echo " p = pre-game phase "; - echo "P = game in progess "; - echo "F = game finished
"; - echo "

\n"; - - $output = array(); - $result = DB_query("SELECT Hand.hash,Hand.game_id,Game.mod_date,Game.player,Game.status from Hand". - " LEFT JOIN Game ON Game.id=Hand.game_id". - " WHERE user_id='$myid'". - " ORDER BY Game.session,Game.create_date" ); - $gamenrold = -1; - echo "\n \n \n"; - else - echo "$gamenr:\n"; - $gamenrold = $gamenr; - echo "\n\n
\n"; - while( $r = DB_fetch_array($result)) - { - $game = DB_format_gameid($r[1]); - $gamenr = (int) $game; - if($gamenrold < $gamenr) - { - if($gamenrold!=-1) - echo "
$gamenr:\n"; - } - if($r[4]=='pre') - echo "\n p "; - else if ($r[4]=='gameover') - echo "\n F "; - else - echo "\n P "; - if($r[4] != 'gameover') - { - echo "\n "; - if($r[3]==$myid || !$r[3]) - echo "(it's your turn)\n"; - else - { - $name = DB_get_name('userid',$r[3]); - $gameid = $r[1]; - if(DB_get_reminder($r[3],$gameid)==0) - if(time()-strtotime($r[2]) > 60*60*24*7) - echo "". - "Send a reminder."; - echo "(it's $name's turn)\n"; - }; - if(time()-strtotime($r[2]) > 60*60*24*30) - echo "". - "Cancel?". - " (clicking here is final and can't be restored)"; - - } - } - echo "
\n"; - - /* display last 5 users that have signed up to e-DoKo */ - $names = DB_get_names_of_new_logins(5); - echo "

New Players:

\n

\n"; - echo implode(", ",$names).",...\n"; - echo "

\n"; - - /* display last 5 users that logged on */ - $names = DB_get_names_of_last_logins(5); - echo "

Players last logged in:

\n

\n"; - echo implode(", ",$names).",...\n"; - echo "

\n"; - - echo "
\n"; - } - else - { - echo "
Sorry email and password don't match. Please try again.
"; - } - }; -output_footer(); -DB_close(); -exit(); - + $ok = 1; + $myid = DB_get_userid('email-password',$email,$password); + if(!$myid) + $ok = 0; + + if($ok) + { + /* user information is ok */ + $myname = DB_get_name('email',$email); + $_SESSION["name"] = $myname; + + $PREF = DB_get_PREF($myid); + + DB_update_user_timestamp($myid); + + display_user_menu(); + + /* display all games the user has played */ + echo "
"; + echo "

These are all your games:

\n"; + echo "

Session:
\n"; + echo " p = pre-game phase "; + echo "P = game in progess "; + echo "F = game finished
"; + echo "

\n"; + + $output = array(); + $result = DB_query("SELECT Hand.hash,Hand.game_id,Game.mod_date,Game.player,Game.status from Hand". + " LEFT JOIN Game ON Game.id=Hand.game_id". + " WHERE user_id='$myid'". + " ORDER BY Game.session,Game.create_date" ); + $gamenrold = -1; + echo "\n \n \n"; + else + echo "$gamenr:\n"; + $gamenrold = $gamenr; + echo "\n\n
\n"; + while( $r = DB_fetch_array($result)) + { + $game = DB_format_gameid($r[1]); + $gamenr = (int) $game; + if($gamenrold < $gamenr) + { + if($gamenrold!=-1) + echo "
$gamenr:\n"; + } + if($r[4]=='pre') + echo " p \n"; + else if ($r[4]=='gameover') + echo " F \n"; + else + echo " P \n"; + if($r[4] != 'gameover') + { + echo "\n "; + if($r[3]==$myid || !$r[3]) + echo "(it's your turn)\n"; + else + { + $name = DB_get_name('userid',$r[3]); + $gameid = $r[1]; + if(DB_get_reminder($r[3],$gameid)==0) + if(time()-strtotime($r[2]) > 60*60*24*7) + echo "Send a reminder."; + echo "(it's $name's turn)\n"; + }; + if(time()-strtotime($r[2]) > 60*60*24*30) + echo "Cancel?". + " (clicking here is final and can't be restored)"; + } + } + echo "
\n"; + + /* display last 5 users that have signed up to e-DoKo */ + $names = DB_get_names_of_new_logins(5); + echo "

New Players:

\n

\n"; + echo implode(", ",$names).",...\n"; + echo "

\n"; + + /* display last 5 users that logged on */ + $names = DB_get_names_of_last_logins(5); + echo "

Players last logged in:

\n

\n"; + echo implode(", ",$names).",...\n"; + echo "

\n"; + + echo "
\n"; + } + else + { + echo "
Sorry email and password don't match. Please try again.
"; + } + }; ?> \ No newline at end of file diff --git a/index.php b/index.php index 76bbc29..9702800 100644 --- a/index.php +++ b/index.php @@ -8,13 +8,11 @@ error_reporting(E_ALL); */ session_start(); - include_once("config.php"); /* needs to be first in list, since other includes use this */ include_once("./include/output.php"); /* html output only */ include_once("./include/db.php"); /* database only */ include_once("./include/functions.php"); /* the rest */ - /* make sure that user has set all variables in config.php */ config_check(); @@ -28,7 +26,7 @@ if(DB_open()<0) exit(); } -/* done major error checking, output header of HTML page */ +/* done major error checking, output5B header of HTML page */ output_header(); /* The rest of the file consists of handling user input. @@ -81,6 +79,11 @@ switch($action) require './include/welcome.php'; } +/* ask for login or display login info, needs to go at the end, so that we have the + * session-variable already set. + */ +output_status(); + output_footer(); DB_close();