X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=index.php;h=a2cf35b0cd2f38a1085e1088c5d6fa258ab5e530;hp=64068373728db048265eaecee9d2ec4ee4cb5a40;hb=e68d4598c0d0a5e1f138b9c891f5c1c9ae0e8541;hpb=d5233803bcd19376ea074e27205a77a0148880ac diff --git a/index.php b/index.php index 6406837..a2cf35b 100644 --- a/index.php +++ b/index.php @@ -1,415 +1,148 @@ - - -
-
",$message);
- echo " Game $gameid has been cancled. You need to wait longer before you can cancle a game... no game in progress, please input 4 names and email addresses, please make sure that the addresses are correct! aehm... at the moment please just answer everything with no, still need to implement this your cards are: Game $gameid has been cancled. these are your games that haven't started yet: these are the games you are playing in: and these are your games that are already done: registered players: Want to start a new game? Visit this page.
To: $To
Subject: $Subject
$message
";
- }
- else
- mail($To,$Subject,$message);
- return;
-}
-
-function parse_status()
-{
- global $game,$history,$player,$hash,$lines;
-
- $game["init"] = 0;
- $game["solo-who"] = -1;
- $game["solo-what"] = "todo";
- $game["wedding"] = -1;
- $game["poverty"] = -1;
- $game["nines"] = -1;
- $game["startplayer"] = 0;
-
- for($i=0;$i<4;$i++)
- {
- $tmp = explode( ":",$lines[$i]);
- $hash[$i] = $tmp[0];
- $player[$tmp[0]]["number"] = $i;
- $player[$tmp[0]]["hash"] = $tmp[0];
- $player[$tmp[0]]["name"] = $tmp[1];
- $player[$tmp[0]]["email"] = $tmp[2];
- $player[$tmp[0]]["option"] = $tmp[3];
- $player[$tmp[0]]["points"] = $tmp[4];
- $player[$tmp[0]]["cards"] = $tmp[5];
- if(ereg("s",$tmp[3])) $game["init"]++;
- if(ereg("P",$tmp[3])) $game["poverty"] = $i;
- if(ereg("N",$tmp[3])) $game["nines"] = $i;
- if(ereg("W",$tmp[3])) $game["wedding"] = $i;
- if(ereg("[OSQJCAH]",$tmp[3]) && ($game["solo-who"]<0) )
- {
- $game["solo-who"] = $i;
- $game["startplayer"] = $i;
- }
-
- }
- /* save the game history */
- for($i=4;$i
\n";
+ echo "perhaps the game has been cancled, check by login in here.";
+ output_footer();
+ DB_close();
+ exit();
+ }
+
+ DB_update_user_timestamp($myid);
+
+ /* get some information from the DB */
+ $gameid = DB_get_gameid_by_hash($me);
+ $myname = DB_get_name_by_hash($me);
+
+ /* check if game really is old enough */
+ $result = mysql_query("SELECT mod_date from Game WHERE id='$gameid' " );
+ $r = mysql_fetch_array($result,MYSQL_NUM);
+ if(time()-strtotime($r[0]) > 60*60*24*30) /* = 1 month */
+ {
+ $message = "Hello, \n\n".
+ "Game $gameid has been cancled since nothing happend for a while and $myname requested it.\n";
- fwrite($output, "$hashC:$PlayerC:$EmailC:::" );
- for(;$i<35;$i++)
- fwrite($output,"$randomNR[$i];" );
- fwrite($output,"$randomNR[35]:" ); $i++;
- fwrite($output,"\n");
+ $userids = DB_get_all_userid_by_gameid($gameid);
+ foreach($userids as $user)
+ {
+ $To = DB_get_email_by_userid($user);
+ mymail($To,$EmailName."game $gameid cancled (timed out)",$message);
+ }
- fwrite($output, "$hashD:$PlayerD:$EmailD:::");
- for(;$i<47;$i++)
- fwrite($output,"$randomNR[$i];" );
- fwrite($output,"$randomNR[47]:" );
- fwrite($output,"\n");
+ /* delete everything from the dB */
+ DB_cancel_game($me);
- fclose($output);
+ echo "
";
- }
- else
- { /* show the hand */
- if($_REQUEST["in"]=="no")
- {
- for($i=0;$i<4;$i++)
- {
- $message = "Hello ".$player[$hash[$i]]["name"].",\n\n".
- "the game has been canceled due to the request of one of the players.\n";
- mymail($player[$hash[$i]]["email"],"[DoKo-Debug] the game has been canceled",$message);
- }
- $output = fopen("status.txt","w");
- if($output)
- fclose($output);
- else
- echo "problem opening file";
- }
- else
- {
- if($_REQUEST["update"]=="card") $player[$b]["option"].="c";
- if($_REQUEST["update"]=="turn") $player[$b]["option"].="t";
-
- $player[$b]["option"].="i";
-
- save_status();
-
- $allcards = $player[$b]["cards"];
- $mycards = explode(";",$allcards);
-
- sort($mycards);
- echo "your cards are
";
- foreach($mycards as $card)
- {
- display_card($card);
- }
- echo "
\n";
- ?>
-
\n";
+
+ set_gametype($gametype); /* this sets the $CARDS variable */
+ $mycards = DB_get_hand($me);
+ $mycards = mysort($mycards,$gametype);
+
+ echo "\n";
+ }
+ }
+ else if($who == $mypos || $who == $mypos*10)
+ {
+ foreach($userids as $user)
+ {
+ $name = DB_get_name_by_userid($user);
+ $usersick = DB_get_sickness_by_userid_and_gameid($user,$gameid);
+
+ if($usersick=="poverty")
+ {
+ $hash =DB_get_hash_from_gameid_and_userid($gameid,$user);
+ $cards=DB_get_hand($hash);
+ $nrtrump=count_trump($cards);
+ /* count trump */
+ if($nrtrump<4)
+ echo "Player $name has $nrtrump trump. Do you want to take them?".
+ "yes
";
+ }
+ }
+ echo "I don't want to take any trump: ".
+ "yes
";
+
+ echo "Your cards are:
\n";
+ $mycards = DB_get_hand($me);
+ sort($mycards);
+ echo "
\n";
+ foreach($mycards as $card)
+ display_card($card,$PREF["cardset"]);
+ echo "
";
+ }
+ else
+ echo "\n
";
+
+ break;
+ case 'play':
+ case 'gameover':
+ /* both entries here, so that the tricks are visible for both.
+ * in case of 'play' there is a break later that skips the last part
+ */
+
+ /* figure out what kind of game we are playing,
+ * set the global variables $CARDS["trump"],$CARDS["diamonds"],$CARDS["hearts"],
+ * $CARDS["clubs"],$CARDS["spades"],$CARDS["foxes"]
+ * accordingly
+ */
+
+ $gametype = DB_get_gametype_by_gameid($gameid);
+ $GT = $gametype;
+ if($gametype=="solo")
+ {
+ $gametype = DB_get_solo_by_gameid($gameid);
+ $GT = $gametype." ".$GT;
+ }
+ else
+ $gametype="normal";
+
+ set_gametype($gametype); /* this sets the $CARDS variable */
+
+ /* get some infos about the game */
+ $gamestatus = DB_get_game_status_by_gameid($gameid);
+
+ /* display useful things in divs */
+
+ /* display links to the users status page */
+ $result = mysql_query("SELECT email,password from User WHERE id='$myid'" );
+ $r = mysql_fetch_array($result,MYSQL_NUM);
+
+ display_links($r[0],$r[1]);
+
+ /* end display useful things*/
+
+ /* has the game started? No, then just wait here...*/
+ if($gamestatus == 'pre')
+ {
+ echo "You finished the setup, but not everyone else finished it... ".
+ "so you need to wait for the others. Just wait for the an email...
";
+ break; /* not sure this works... the idea is that you can
+ * only play a card after everyone is ready to play */
+ }
+
+ /* display the table and the names */
+ $result = mysql_query("SELECT User.fullname as name,".
+ " Hand.position as position, ".
+ " User.id, ".
+ " Hand.party as party, ".
+ " Hand.sickness as sickness, ".
+ " Hand.point_call, ".
+ " User.last_login, ".
+ " Hand.hash ".
+ "FROM Hand ".
+ "LEFT JOIN User ON User.id=Hand.user_id ".
+ "WHERE Hand.game_id='".$gameid."' ".
+ "ORDER BY position ASC");
+
+ echo "
\n";
+ echo " local time: ".date("Y-m-d H:i:s")."
\n";
+ echo " last login: ".date("Y-m-d H:i:s",$lastlogin)."
\n";
+ echo " \n";
+
+ }
+ echo "\n";
+ echo "
\n";
+
+ /* whos turn is it? */
+ if($seq==4)
+ {
+ $winner = get_winner($play,$gametype); /* returns the position */
+ $next = $winner;
+ $firstcard = ""; /* new trick, no first card */
+ }
+ else
+ {
+ $next = $pos+1;
+ if($next==5) $next=1;
+ }
+
+ /* my turn?, display cards as links, ask for comments*/
+ if(DB_get_pos_by_hash($me) == $next)
+ $myturn = 1;
+ else
+ $myturn = 0;
+
+ /* do we want to play a card? */
+ if(myisset("card") && $myturn)
+ {
+ $card = $_REQUEST["card"];
+ $handid = DB_get_handid_by_hash($me);
+
+ /* check if we have card and that we haven't played it yet*/
+ /* set played in hand_card to true where hand_id and card_id*/
+ $result = mysql_query("SELECT id FROM Hand_Card WHERE played='false' and ".
+ "hand_id='$handid' AND card_id=".DB_quote_smart($card));
+ $r = mysql_fetch_array($result,MYSQL_NUM);
+ $handcardid = $r[0];
+
+ if($handcardid) /* everything ok, play card */
+ {
+ $comment = "";
+
+ /* update Game timestamp */
+ DB_update_game_timestamp($gameid);
+
+ /* check if a call was made, must do this before we set the card status to played */
+ if(myisset("call120") && $_REQUEST["call120"] == "yes" && can_call(120,$me))
+ $result = mysql_query("UPDATE Hand SET point_call='120' WHERE hash='$me' ");
+ if(myisset("call90") && $_REQUEST["call90"] == "yes" && can_call(90,$me))
+ $result = mysql_query("UPDATE Hand SET point_call='90' WHERE hash='$me' ");
+ if(myisset("call60") && $_REQUEST["call60"] == "yes" && can_call(60,$me))
+ $result = mysql_query("UPDATE Hand SET point_call='60' WHERE hash='$me' ");
+ if(myisset("call30") && $_REQUEST["call30"] == "yes" && can_call(30,$me))
+ $result = mysql_query("UPDATE Hand SET point_call='30' WHERE hash='$me' ");
+ if(myisset("call0") && $_REQUEST["call0"] == "yes" && can_call(0,$me))
+ $result = mysql_query("UPDATE Hand SET point_call='0' WHERE hash='$me' ");
+
+ /* mark card as played */
+ mysql_query("UPDATE Hand_Card SET played='true' WHERE hand_id='$handid' AND card_id=".
+ DB_quote_smart($card));
+
+ /* check for schweinchen */
+ //echo "schweinchen = ".$GAME["schweinchen"]." --$card-
";
+ if($card == 19 || $card == 20 )
+ {
+ $GAME["schweinchen"]++;
+ if($GAME["schweinchen"]==3 && $RULES["schweinchen"]=="second" )
+ $comment="Schweinchen! ";
+ if($RULES["schweinchen"]=="both" )
+ $comment="Schweinchen! ";
+ if ($debug) echo "schweinchen = ".$GAME["schweinchen"]." ---
";
+ }
+
+ /* get trick id or start new trick */
+ $a = DB_get_current_trickid($gameid);
+ $trickid = $a[0];
+ $sequence = $a[1];
+ $tricknr = $a[2];
+
+ $playid = DB_play_card($trickid,$handcardid,$sequence);
+
+ /* if sequence == 4 check who one in case of wedding */
+ if($sequence == 4 && $GT == "wedding")
+ {
+ /* is wedding resolve */
+ $resolved = DB_get_sickness_by_gameid($gameid);
+ if($resolved<0)
+ {
+ /* who has wedding */
+ $userids = DB_get_all_userid_by_gameid($gameid);
+ foreach($userids as $user)
+ {
+ $usersick = DB_get_sickness_by_userid_and_gameid($user,$gameid);
+ if($usersick == "wedding")
+ $whosick = $user;
+ }
+ /* who won the trick */
+ $play = DB_get_cards_by_trick($trickid);
+ $winner = get_winner($play,$gametype); /* returns the position */
+ $winnerid = DB_get_userid_by_gameid_and_position($gameid,$winner);
+ /* is tricknr <=3 */
+ if($tricknr <=3 && $winnerid!=$whosick)
+ {
+ /* set resolved at tricknr*/
+ $resolved = DB_set_sickness_by_gameid($gameid,$tricknr);
+ /* set partner */
+ $whash = DB_get_hash_from_gameid_and_userid($gameid,$winnerid);
+ DB_set_party_by_hash($whash,"re");
+ }
+ if($tricknr == 3 && $winnerid==$whosick)
+ {
+ /* set resolved at tricknr*/
+ $resolved = DB_set_sickness_by_gameid($gameid,'3');
+ }
+ }
+ }
+
+ /* check for coment */
+ if(myisset("comment"))
+ {
+ $comment.=$_REQUEST["comment"];
+ };
+ if($comment != "")
+ DB_insert_comment($comment,$playid,$myid);
+
+ /* display played card */
+ echo "
";
+ display_card($card,$PREF["cardset"]);
+ echo "
";
+
+ /* who is the next player? */
+ $next = $winner;
+ }
+ else
+ {
+ $next = DB_get_pos_by_hash($me)+1;
+ }
+ if($next==5) $next=1;
+
+ /* email next player */
+ $next_hash = DB_get_hash_from_game_and_pos($gameid,$next);
+ $email = DB_get_email_by_hash($next_hash);
+ $who = DB_get_userid_by_email($email);
+ DB_set_player_by_gameid($gameid,$who);
+
+ $message = "A card has been played in game $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 $gameid",$message);
+ }
+ }
+ else
+ {
+ echo "can't find that card?!
\n";
+ }
+ }
+ else if(myisset("card") && !$myturn )
+ {
+ echo "please wait until it's your turn!
\n";
+ }
+
+ $mycards = DB_get_hand($me);
+ $mycards = mysort($mycards,$gametype);
+ echo "
\n";
+ echo "Your cards are:
\n";
+ echo "\n";
+ }
+ else if($mystatus=='play')
+ {
+ echo "Your cards are:
\n";
+ foreach($mycards as $card)
+ display_card($card,$PREF["cardset"]);
+ }
+ else if($mystatus=='gameover')
+ {
+ $oldcards = DB_get_all_hand($me);
+ $oldcards = mysort($oldcards,$gametype);
+ echo "Your cards were:
\n";
+ foreach($oldcards as $card)
+ display_card($card,$PREF["cardset"]);
+ }
+ echo "
\n";
+
+ $result = mysql_query("SELECT fullname, IFNULL(SUM(score),0), Hand.party FROM Hand".
+ " LEFT JOIN Score ON Hand.id=Score.hand_id".
+ " LEFT JOIN User ON Hand.user_id=User.id".
+ " WHERE Hand.game_id=$gameid".
+ " GROUP BY fullname" );
+ echo "Final Score:
\n".
+ " \n";;
+ while( $r = mysql_fetch_array($result,MYSQL_NUM))
+ echo "
\n";
+
+ $result = mysql_query("SELECT Hand.party, IFNULL(SUM(score),0) FROM Hand".
+ " LEFT JOIN Score ON Hand.id=Score.hand_id".
+ " LEFT JOIN User ON Hand.user_id=User.id".
+ " WHERE Hand.game_id=$gameid".
+ " GROUP BY Hand.party" );
+ echo "Totals: ";
+ echo " ".$r[0]." (".$r[2].") ".$r[1]."
\n".
+ " \n";
+ while( $r = mysql_fetch_array($result,MYSQL_NUM))
+ echo "
\n";
+
+ $session = DB_get_session_by_gameid($gameid);
+ $result = mysql_query("SELECT id,create_date FROM Game".
+ " WHERE session=$session".
+ " ORDER BY create_date DESC".
+ " LIMIT 1");
+ $r=-1;
+ if($result)
+ $r = mysql_fetch_array($result,MYSQL_NUM);
+
+ if(!$session || $gameid==$r[0])
+ {
+ /* suggest a new game with the same people in it, just rotated once */
+ $names = DB_get_all_names_by_gameid($gameid);
+ output_ask_for_new_game($names[1],$names[2],$names[3],$names[0],$gameid);
+ }
+ }
+ break;
+ default:
+ echo "error in testing the status";
+ }
+ output_footer();
+ DB_close();
+ exit();
+ }
+/* user status page */
+ else if(myisset("email","password"))
+ {
+ /* test id and password, should really be done in one step */
+ $email = $_REQUEST["email"];
+ $password = $_REQUEST["password"];
- echo "wedding?";
- if(check_wedding($player[$b]["cards"]))
- {
- echo " yes";
- echo " no \n";
+ echo "".$r[0]." ".$r[1]."
";
- }
- else
- {
- echo " no
";
- };
-
- echo "do you have poverty?";
- if(count_trump($player[$b]["cards"])<4)
- {
- echo " yes";
- echo " no
";
- }
- else
- {
- echo " no
";
- };
-
- echo "do you have too many nines?";
- if(count_nines($player[$b]["cards"])>4)
- {
- echo " yes";
- echo " no
";
- }
- else
- {
- echo " no
";
- };
-
- echo "\n";
- echo "\n";
-
- echo "\n";
- }
- }
- }
- if(isset($_REQUEST["c"]))
+
+ if(myisset("forgot"))
{
- $c=$_REQUEST["c"];
+ $ok=1;
+
+ $uid = DB_get_userid_by_email($email);
+ if(!$uid)
+ $ok=0;
- if(!isset($_REQUEST["solo"])|| !isset($_REQUEST["wedding"])|| !isset($_REQUEST["poverty"]) || !isset($_REQUEST["nines"]) )
+ if($ok)
{
- echo "go back to ";
- echo " here and fill out the form
";
+ echo "Hmm, you forgot your passwort...nothing I can do at the moment:( ";
+ echo " you need to email Arun for now... in the future it will be all automated and an ";
+ echo "email with a new password will go to $email.";
}
- else if( ereg("s",$player[$c]["option"]) && $game["init"]<4 )
+ else
{
- echo "just wait for the game to start";
- }
- else if($game["init"]<4)
- {
- if( $_REQUEST["solo"]!="No")
- {
- switch($_REQUEST["solo"])
- {
- case "No trump":
- $player[$c]["option"].="O";
- break;
- case "Normal solo":
- $player[$c]["option"].="S";
- break;
- case "Queen solo":
- $player[$c]["option"].="Q";
- break;
- case "Jack solo":
- $player[$c]["option"].="J";
- break;
- case "Club solo":
- $player[$c]["option"].="C";
- break;
- case "Spade solo":
- $player[$c]["option"].="A";
- break;
- case "Hear solo":
- $player[$c]["option"].="H";
- break;
- }
- }
- else if($_REQUEST["wedding"] == "yes")
- {
- echo "wedding was chosen
";
- $player[$c]["option"].="W";
- }
- else if($_REQUEST["poverty"] == "yes")
- {
- echo "poverty was chosen
";
- $player[$c]["option"].="P";
- }
- else if($_REQUEST["nines"] == "yes")
- {
- echo "nines was chosen
";
- $player[$c]["option"].="N";
- }
-
- $message = "you're in. once everyone has filled out the form,".
- "the game will start and you'll get an eamil on your turn\n";
- mymail($player[$c]["email"],"[DoKo-debug] the game will start soon",$message);
-
- $player[$c]["option"].="s";
- save_status();
- if(file_exists("status.txt"))
- $lines = file("status.txt");
+ if($email=="")
+ echo "you need to give me an email address!";
else
- die("no file");
- parse_status();
-
- if($game["init"]==4)
- {
- $message = "The game can start now, it's your turn, please use this link to play a card:\n".
- $host."?me=".$hash[$game["startplayer"]]."\n";
- mymail($player[$hash[$game["startplayer"]]]["email"],"[DoKo-debug] let's go",$message);
- }
-
- }
+ echo "couldn't find a player with this email, please contact Arun, if you think this is a mistake";
+ }
}
- if($game["init"]==4)
- {
- /* check for sickness*/
- /***** someone has 5 nines and no one is playing solo=> cance5Al game */
- if($game["nines"]>=0 && $game["solo-who"]<0)
- {
- $message = $player[$hash[$game["poverty"]]]["nines"]." has more than 4 nines. Game aborted!\n";
- for($i=0;$i<4;$i++)
- {
- mymail($player[$hash[$i]]["email"],"[DoKo-debug] the game has been canceled",$message);
- }
- $output = fopen("status.txt","w");
- if($output)
- fclose($output);
- else
- echo "problem opening file";
- }
+ else
+ {
+ /* verify password and email */
+ if(strlen($password)!=32)
+ $password = md5($password);
+
+ $ok=1;
+ $uid = DB_get_userid_by_email_and_password($email,$password);
+ if(!$uid)
+ $ok=0;
+
+ if($ok)
+ {
+ DB_get_PREF($uid);
- /* who is requesting this*/
- if(!isset($_REQUEST["me"]))
- {
- if(!isset($_REQUEST["recovery"]))
- {
- echo "a game is in progress, but you are not playing.
";
- echo "In case you are playing, but lost your email or can't access the game anymore, please input your email here:
";
-?>
-
-=0)
+ if(myisset("setpref"))
{
- $message = "Please try this link: ".$host."?me=".$hash[$ok]."\n".
- "\n if this doesn't work, contact the admin.\n";
- mymail($recovery,"[DoKo-Debug] recovery ",$message);
- echo "email has been sent.";
- }
- else
- {
- echo "can't find this email address, sorry.";
- };
- }
- }
- else
- {
- $me = $_REQUEST["me"];
-
- echo "game in progress and you are in it
";
- if($game["solo-who"]>=0)
- echo $player[$hash[$game["solo-who"]]]["name"]." is playing a ".$game["solo-what"]." solo!
";
- else if($game["wedding"]>=0)
- echo $player[$hash[$game["wedding"]]]["name"]." is playing a wedding!
";
-
- foreach($history as $play)
- {
- echo "
";
-
- $trick = explode(":",$play);
-
- $last=-2;
- /* found old trick, display it */
- for($i=0;$i
";
- }
- }
- }
+ $setpref=$_REQUEST["setpref"];
+ switch($setpref)
+ {
+ case "germancards":
+ case "englishcards":
+ $result = mysql_query("SELECT * from User_Prefs".
+ " WHERE user_id='$uid' AND pref_key='cardset'" );
+ if( mysql_fetch_array($result,MYSQL_NUM))
+ $result = mysql_query("UPDATE User_Prefs SET value=".DB_quote_smart($setpref).
+ " WHERE user_id='$uid' AND pref_key='cardset'" );
+ else
+ $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
- echo "seems like you don't have that card
";
-
- }
-
- }
- else if(isset($_REQUEST["win"]) && strlen($history[sizeof($history)-1])>3)
- {
- $win=$_REQUEST["win"];
- $history[]=$win.":\n";
- /* count points of the last trick */
- $points=0;
-
- $tmp = explode(":",$history[sizeof($history)-2]);
- for($i=0;$i<4;$i++)
- {
- $tmp2 = explode("->",$tmp[$i]);
- $c = $tmp2[1];
- $points += card_value($c);
- }
- $player[$hash[$win]]["points"]+=$points;
- echo "
".$player[$hash[$win]]["name"]." won: $points Points
";
-
- save_status();
- }
- echo "
";
-
- $tmp = explode(":",$history[sizeof($history)-1]);
-
- if(sizeof($tmp)==5)
- {
- ?>
-
-the next player
";
-
- if(strlen(trim($player[$me]["cards"]))==0)
- {
- echo "
game over, count points
";
- for($i=0;$i<4;$i++)
- {
- echo $player[$hash[$i]]["name"]." got ".$player[$hash[$i]]["points"]."
";
- }
- }
- }
- if($hash[$next]==$me && strlen(trim($player[$me]["cards"]))>0 )
- {
-
- echo "ITS YOUR TURN
";
- $allcards = trim($player[$me]["cards"]);
- $mycards = explode(";",$allcards);
-
- sort($mycards);
- echo "your cards are
";
- foreach($mycards as $card)
- {
- display_link_card($card,$me);
- }
- echo "
\n";
- }
- echo "
";
-
- }
- }
+ }
+ }
+ else /* output default user page */
+ {
+ $time = DB_get_user_timestamp($uid);
+ $unixtime =strtotime($time);
+
+ $offset = DB_get_user_timezone($uid);
+ $zone = return_timezone($offset);
+ date_default_timezone_set($zone);
+
+ /* display links to settings */
+ output_user_settings($email,$password);
+
+ echo "last login: ".date("r",$unixtime)."
";
+
+ DB_update_user_timestamp($uid);
+
+ echo "
\n";
+ $result = mysql_query("SELECT Hand.hash,Hand.game_id,Game.mod_date,Game.player 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($r[3])
+ {
+ if($r[3]==$uid)
+ echo "(it's your turn)\n";
+ else
+ {
+ $name = DB_get_name_by_userid($r[3]);
+ echo "(it's $name's turn)\n";
+ };
+ }
+ 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";
+ $result = mysql_query("SELECT Hand.hash,Hand.game_id,Game.mod_date,Game.player from Hand".
+ " LEFT JOIN Game On Hand.game_id=Game.id".
+ " WHERE Hand.user_id='$uid' AND Game.status='play'" );
+ while( $r = mysql_fetch_array($result,MYSQL_NUM))
+ {
+ echo "game #".$r[1]." ";
+ if($r[3])
+ {
+ if($r[3]==$uid)
+ echo "(it's your turn)\n";
+ else
+ {
+ $name = DB_get_name_by_userid($r[3]);
+ echo "(it's $name's turn)\n";
+ };
+ }
+ 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 "
Game: \n";
+ $output=array();
+ $result = mysql_query("SELECT hash,game_id from Hand WHERE user_id='$uid' AND status='gameover'" );
+ while( $r = mysql_fetch_array($result,MYSQL_NUM))
+ $output[]= "#".$r[1]." ";
+ echo implode(", ",$output)."
\n";
+ echo implode(", ",$names)."\n";
+ echo "
";
+ }
+ };
+ output_footer();
+ DB_close();
+ exit();
+ }
+/* page for registration */
+ else if(myisset("register") )
+ {
+ output_register();
+ }
+/* new user wants to register */
+ else if(myisset("Rfullname","Remail","Rpassword","Rtimezone") )
+ {
+ $ok=1;
+ if(DB_get_userid_by_name($_REQUEST["Rfullname"]))
+ {
+ echo "please chose another name
";
+ $ok=0;
+ }
+ if(DB_get_userid_by_email($_REQUEST["Remail"]))
+ {
+ echo "this email address is already used ?!
";
+ $ok=0;
}
+ if($ok)
+ {
+ $r=mysql_query("INSERT INTO User VALUES(NULL,".DB_quote_smart($_REQUEST["Rfullname"]).
+ ",".DB_quote_smart($_REQUEST["Remail"]).
+ ",".DB_quote_smart(md5($_REQUEST["Rpassword"])).
+ ",".DB_quote_smart($_REQUEST["Rtimezone"]).",NULL)");
+
+ if($r)
+ echo " added you to the database";
+ else
+ echo " something went wrong";
+ }
+ }
+/* default login page */
+ else
+ {
+ $pre[0]=0;$game[0]=0;$done[0]=0;
+ $r=mysql_query("SELECT COUNT(id) FROM Game GROUP BY status");
+ if($r) {
+ $pre = mysql_fetch_array($r,MYSQL_NUM);
+ $game = mysql_fetch_array($r,MYSQL_NUM);
+ $done = mysql_fetch_array($r,MYSQL_NUM);
+ }
- }
+ $r=mysql_query("SELECT AVG(datediff(mod_date,create_date)) FROM Game where status='gameover' ");
+ if($r)
+ $avgage= mysql_fetch_array($r,MYSQL_NUM);
+ else
+ $avgage[0]=0;
+ output_home_page($pre[0],$game[0],$done[0],$avgage[0]);
+ }
+
+output_footer();
+
+DB_close();
+
+/*
+ *Local Variables:
+ *mode: php
+ *mode: hs-minor
+ *End:
+ */
?>
-