2 error_reporting(E_ALL);
7 include_once("config.php");
8 include_once("output.php"); /* html output only */
9 include_once("db.php"); /* database only */
10 include_once("functions.php"); /* the rest */
12 /* check if some variables are set in the config file, else set defaults */
13 if(!isset($EmailName))
17 /* in case work has to be done on the database or other section we can
18 * shut down the server and tell people to come back later
23 echo "Working on the database...please check back in a few mintues";
31 echo "Database error, can't connect...";
38 /* check if we want to start a new game */
41 $names = DB_get_all_names();
42 output_form_for_new_game($names);
44 /*check if everything is ready to set up a new game */
45 else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen" ))
47 $PlayerA = $_REQUEST["PlayerA"];
48 $PlayerB = $_REQUEST["PlayerB"];
49 $PlayerC = $_REQUEST["PlayerC"];
50 $PlayerD = $_REQUEST["PlayerD"];
52 $dullen = $_REQUEST["dullen"];
53 $schweinchen = $_REQUEST["schweinchen"];
55 $EmailA = DB_get_email_by_name($PlayerA);
56 $EmailB = DB_get_email_by_name($PlayerB);
57 $EmailC = DB_get_email_by_name($PlayerC);
58 $EmailD = DB_get_email_by_name($PlayerD);
60 if($EmailA=="" || $EmailB=="" || $EmailC=="" || $EmailD=="")
62 echo "couldn't find one of the names, please start a new game";
67 $useridA = DB_get_userid_by_name($PlayerA);
68 $useridB = DB_get_userid_by_name($PlayerB);
69 $useridC = DB_get_userid_by_name($PlayerC);
70 $useridD = DB_get_userid_by_name($PlayerD);
72 /* create random numbers */
73 $randomNR = create_array_of_random_numbers();
74 $randomNRstring = join(":",$randomNR);
76 /* get ruleset information or create new one */
77 $ruleset = DB_get_ruleset($dullen,$schweinchen);
80 echo "Error defining ruleset: $ruleset";
87 if(myisset("followup") )
89 $followup= $_REQUEST["followup"];
90 $session = DB_get_session_by_gameid($followup);
91 $ruleset = DB_get_ruleset_by_gameid($followup); /* just copy ruleset from old game,
92 this way no manipulation is possible */
94 mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1','pre',".
95 "'$ruleset','$session' ,NULL)");
99 $max = DB_get_max_session();
101 mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1','pre',".
102 "'$ruleset','$max' ,NULL)");
103 mysql_query("UPDATE Game SET session='".$max."' WHERE id=".DB_quote_smart($followup));
107 mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1','pre', ".
108 "'$ruleset',NULL ,NULL)");
109 $game_id = mysql_insert_id();
112 $TIME = (string) time(); /* to avoid collisions */
113 $hashA = md5("AGameOfDoko".$game_id.$PlayerA.$EmailA.$TIME);
114 $hashB = md5("AGameOfDoko".$game_id.$PlayerB.$EmailB.$TIME);
115 $hashC = md5("AGameOfDoko".$game_id.$PlayerC.$EmailC.$TIME);
116 $hashD = md5("AGameOfDoko".$game_id.$PlayerD.$EmailD.$TIME);
119 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridA).
120 ", ".DB_quote_smart($hashA).", 'start','1',NULL,NULL,NULL,NULL)");
121 $hand_idA = mysql_insert_id();
122 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridB).
123 ", ".DB_quote_smart($hashB).", 'start','2',NULL,NULL,NULL,NULL)");
124 $hand_idB = mysql_insert_id();
125 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridC).
126 ", ".DB_quote_smart($hashC).", 'start','3',NULL,NULL,NULL,NULL)");
127 $hand_idC = mysql_insert_id();
128 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridD).
129 ", ".DB_quote_smart($hashD).", 'start','4',NULL,NULL,NULL,NULL)");
130 $hand_idD = mysql_insert_id();
134 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idA', '".$randomNR[$i]."', 'false')");
135 for($i=12;$i<24;$i++)
136 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idB', '".$randomNR[$i]."', 'false')");
137 for($i=24;$i<36;$i++)
138 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idC', '".$randomNR[$i]."', 'false')");
139 for($i=36;$i<48;$i++)
140 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idD', '".$randomNR[$i]."', 'false')");
142 /* send out email, TODO: check for error with email */
144 "you are invited to play a game of DoKo (that is to debug the program ;).\n".
145 "Place comments and bug reports here:\n".
146 "http://wiki.nubati.net/index.php?title=EmailDoko\n\n".
147 "The whole round would consist of the following players:\n".
152 "If you want to join this game, please follow this link:\n\n".
155 mymail($EmailA,"You are invited to a game of DoKo","Hello $PlayerA,\n".$message.$hashA);
156 mymail($EmailB,"You are invited to a game of DoKo","Hello $PlayerB,\n".$message.$hashB);
157 mymail($EmailC,"You are invited to a game of DoKo","Hello $PlayerC,\n".$message.$hashC);
158 mymail($EmailD,"You are invited to a game of DoKo","Hello $PlayerD,\n".$message.$hashD);
160 echo "You started a new game. The emails have been sent out!";
161 } /* end set up a new game */
162 /* cancle a game, if nothing has happend in the last N minutes */
163 else if(myisset("cancle","me"))
165 $me = $_REQUEST["me"];
167 /* test for valid ID */
168 $myid = DB_get_userid_by_hash($me);
171 echo "Can't find you in the database, please check the url.<br />\n";
172 echo "perhaps the game has been cancled, check by login in <a href=\"$host\">here</a>.";
177 DB_update_user_timestamp($myid);
179 /* get some information from the DB */
180 $gameid = DB_get_gameid_by_hash($me);
181 $myname = DB_get_name_by_hash($me);
183 /* check if game really is old enough */
184 $result = mysql_query("SELECT mod_date from Game WHERE id='$gameid' " );
185 $r = mysql_fetch_array($result,MYSQL_NUM);
186 if(time()-strtotime($r[0]) > 60*60*24*30) /* = 1 month */
188 $message = "Hello, \n\n".
189 "Game $gameid has been cancled since nothing happend for a while and $myname requested it.\n";
191 $userids = DB_get_all_userid_by_gameid($gameid);
192 foreach($userids as $user)
194 $To = DB_get_email_by_userid($user);
195 mymail($To,$EmailName."game $gameid cancled (timed out)",$message);
198 /* delete everything from the dB */
201 echo "<p style=\"background-color:red\";>Game $gameid has been cancled.<br /><br /></p>";
204 echo "<p>You need to wait longer before you can cancle a game...</p>\n";
206 /* handle request from one specific player for one game,
207 * (the hash is set on a per game base) */
208 else if(myisset("me"))
210 $me = $_REQUEST["me"];
212 /* test for valid ID */
213 $myid = DB_get_userid_by_hash($me);
216 echo "Can't find you in the database, please check the url.<br />\n";
217 echo "perhaps the game has been cancled, check by login in <a href=\"$host\">here</a>.";
222 /* the user had done something, update the timestamp */
223 DB_update_user_timestamp($myid);
225 /* get some information from the DB */
226 $gameid = DB_get_gameid_by_hash($me);
227 $myname = DB_get_name_by_hash($me);
228 $mystatus = DB_get_status_by_hash($me);
229 $mypos = DB_get_pos_by_hash($me);
230 $myhand = DB_get_handid_by_hash($me);
232 /* get prefs and save them */
237 /* get rule set for this game */
238 $result = mysql_query("SELECT * FROM Rulesets".
239 " LEFT JOIN Game ON Game.ruleset=Rulesets.id ".
240 " WHERE Game.id='$gameid'" );
241 $r = mysql_fetch_array($result,MYSQL_NUM);
243 $RULES["dullen"] = $r[2];
244 $RULES["schweinchen"] = $r[3];
246 /* get some infos about the game */
247 $gametype = DB_get_gametype_by_gameid($gameid);
248 $gamestatus = DB_get_game_status_by_gameid($gameid);
250 if($gametype=="solo")
252 $gametype = DB_get_solo_by_gameid($gameid);
253 $GT = $gametype." ".$GT;
256 /* display rule set for this game */
257 echo "<div class=\"ruleset\">\n";
259 if($gamestatus != 'pre')
260 echo " Gametype: $GT <br />\n";
262 echo "Rules: <br />\n";
263 echo "10ofhearts : ".$r[2]."<br />\n";
264 echo "schweinchen: ".$r[3]."<br />\n";
267 /* does anyone have both foxes */
268 $GAME["schweinchen"]=0;
271 $hash = DB_get_hash_from_game_and_pos($gameid,$i);
272 $cards = DB_get_all_hand($hash);
273 if( in_array("19",$cards) && in_array("20",$cards) )
275 $GAME["schweinchen"]=1;
276 $GAME["schweinchen-who"]=$hash;
280 /* mystatus gets the player through the different stages of a game.
282 * init: check values from start,
284 * check: check for return values from init
285 * poverty: handle poverty, wait here until all player have reached this state
286 * display sickness and move on to game
287 * play: game in progress
288 * gameover: are we revisiting a game
293 check_want_to_play($me);
294 /* move on to the next stage*/
295 DB_set_hand_status_by_hash($me,'init');
298 /* first check if everything went ok in the last step
299 * if not, send user back, if yes, check what he did
303 echo "<p> you need to answer the <a href=\"$host?me=$me\">question</a>.</p>";
304 DB_set_hand_status_by_hash($me,'start');
308 if($_REQUEST["in"] == "no")
310 /* cancle the game */
311 $message = "Hello, \n\n".
312 "the game has been canceled due to the request of one of the players.\n";
314 $userids = DB_get_all_userid_by_gameid($gameid);
315 foreach($userids as $user)
317 $To = DB_get_email_by_userid($user);
318 mymail($To,$EmailName."game $gameid canceled",$message);
321 /* delete everything from the dB */
326 echo "thanks for joining the game...";
328 $mycards = DB_get_hand($me);
330 echo "<p class=\"mycards\" style=\"margin-top:8em;\">your cards are: <br />\n";
331 foreach($mycards as $card)
332 display_card($card,$PREF["cardset"]);
335 check_for_sickness($me,$mycards);
337 /* move on to the next stage*/
338 DB_set_hand_status_by_hash($me,'check');
344 /* ok, user is in the game, saw his cards and selected his vorbehalt
345 * so first we check what he selected
347 echo "Processing what you selected in the last step...<br />";
349 if(!myisset("solo","wedding","poverty","nines") )
351 /* all these variables have a pre-selected default,
352 * so we should never get here,
353 * unless a user tries to cheat ;) */
354 echo "something went wrong...please contact the admin.";
358 /* check if this sickness needs to be handled first */
359 $gametype = DB_get_gametype_by_gameid($gameid);
360 $startplayer = DB_get_startplayer_by_gameid($gameid);
362 if( $_REQUEST["solo"]!="No")
364 /* user wants to play a solo */
366 /* store the info in the user's hand info */
367 DB_set_solo_by_hash($me,$_REQUEST["solo"]);
368 DB_set_sickness_by_hash($me,"solo");
370 echo "<br />Seems like you want to play a ".$_REQUEST["solo"]." solo. Got it.<br />\n";
372 if($gametype == "solo" && $startplayer<$mypos)
373 {}/* do nothing, since someone else already is playing solo */
376 /* this solo comes first
377 * store info in game table
379 DB_set_gametype_by_gameid($gameid,"solo");
380 DB_set_startplayer_by_gameid($gameid,$mypos);
381 DB_set_solo_by_gameid($gameid,$_REQUEST["solo"]);
384 else if($_REQUEST["wedding"] == "yes")
386 /* TODO: add silent solo somewhere*/
387 echo "Ok, you don't want to play a silent solo...wedding was chosen.<br />\n";
388 DB_set_sickness_by_hash($me,"wedding");
390 else if($_REQUEST["poverty"] == "yes")
392 echo "Don't think you can win with just a few trump...? ok, poverty chosen <br />\n";
393 DB_set_sickness_by_hash($me,"poverty");
395 else if($_REQUEST["nines"] == "yes")
397 echo "What? You just don't want to play a game because you have a few nines? Well, if no one".
398 " is playing solo, this game will be canceled.<br />\n";
399 DB_set_sickness_by_hash($me,"nines");
403 echo " Ok, done with checking, please go to the <a href=\"$host?me=$me\">next step of the setup</a>.<br />";
405 /* move on to the next stage*/
406 DB_set_hand_status_by_hash($me,'poverty');
408 /* check if everyone has reached this stage, send out email */
409 $userids = DB_get_all_userid_by_gameid($gameid);
411 foreach($userids as $user)
413 $userstat = DB_get_hand_status_by_userid_and_gameid($user,$gameid);
414 if($userstat!='poverty' && $userstat!='play')
418 foreach($userids as $user)
420 $To = DB_get_email_by_userid($user);
421 $userhash =DB_get_hash_from_gameid_and_userid($gameid,$user);
424 $message = "Everyone finish the questionary in game $gameid, please visit this link now to continue: \n".
425 " ".$host."?me=".$userhash."\n\n" ;
426 mymail($To,$EmailName." finished setup",$message);
433 /* here we need to check if there is a solo or some other form of sickness.
434 * If so, which one is the most important one
435 * set that one in the Game table
436 * tell people about it.
438 echo "<br /> Checking if someone else selected solo, nines or wedding or poverty.<br />";
440 /* check if everyone has reached this stage */
441 $userids = DB_get_all_userid_by_gameid($gameid);
443 foreach($userids as $user)
445 $userstat = DB_get_hand_status_by_userid_and_gameid($user,$gameid);
446 if($userstat!='poverty' && $userstat!='play')
452 echo "This step can only be handled after everyone finished the last step. ".
453 "Seems like this is not the case, so you need to wait a bit... you will get an email once that is the case, please use the link in that email to continue the game.<br />";
457 echo "Everyone has finished checking their cards, let's see what they said...<br />";
459 /* check what kind of game we are playing, in case there are any solos this already
460 *will have the correct information in it */
461 $gametype = DB_get_gametype_by_gameid($gameid);
462 $startplayer = DB_get_startplayer_by_gameid($gameid);
464 /* check for different sickness and just output a general info */
471 foreach($userids as $user)
473 $name = DB_get_name_by_userid($user);
474 $usersick = DB_get_sickness_by_userid_and_gameid($user,$gameid);
475 if($usersick == 'nines')
478 echo "$name has a Vorbehalt. <br />";
481 else if($usersick == 'poverty')
484 echo "$name has a Vorbehalt. <br />";
486 else if($usersick == 'wedding')
489 echo "$name has a Vorbehalt. <br />" ;
491 else if($usersick == 'solo')
494 echo "$name has a Vorbehalt. <br />" ;
498 /* now check which sickness comes first and set the gametype to it */
500 /* gamestatus == normal, => cancel game */
501 if($gametype == "solo")
508 /* TODO: should we keep statistics of this? */
509 $message = "Hello, \n\n".
510 "the game has been canceled because ".DB_get_name_by_userid($nines).
511 " has five or more nines and nobody is playing solo.\n";
513 /* TODO: add info about redeal in case this is a game of a series */
515 $userids = DB_get_all_userid_by_gameid($gameid);
516 foreach($userids as $user)
518 $To = DB_get_email_by_userid($user);
519 mymail($To,$EmailName."game $gameid canceled",$message);
522 /* delete everything from the dB */
525 echo "The game has been canceled because ".DB_get_name_by_userid($nines).
526 " has five or more nines and nobody is playing solo.\n";
532 DB_set_gametype_by_gameid($gameid,"poverty");
533 $gametype = "poverty";
534 $who=DB_get_sickness_by_gameid($gameid);
537 $firstsick = DB_get_sickness_by_pos_and_gameid(1,$gameid);
538 if($firstsick == "poverty")
539 DB_set_sickness_by_gameid($gameid,2); /* who needs to be asked first */
541 DB_set_sickness_by_gameid($gameid,1); /* who needs to be asked first */
546 DB_set_gametype_by_gameid($gameid,"dpoverty");
547 $gametype = "dpoverty";
548 $who=DB_get_sickness_by_gameid($gameid);
551 $firstsick = DB_get_sickness_by_pos_and_gameid(1,$gameid);
552 if($firstsick == "poverty")
554 $seconsick = DB_get_sickness_by_pos_and_gameid(1,$gameid);
555 if($secondsick == "poverty")
556 DB_set_sickness_by_gameid($gameid,30); /* who needs to be asked first */
558 DB_set_sickness_by_gameid($gameid,20); /* who needs to be asked first */
561 DB_set_sickness_by_gameid($gameid,10); /* who needs to be asked first */
566 DB_set_gametype_by_gameid($gameid,"wedding");
567 DB_set_sickness_by_gameid($gameid,'-1'); /* wedding not resolved yet */
568 $gametype = "wedding";
573 /* now the gametype is set correctly (shouldn't matter that this is calculated for every user)
574 * output what kind of game we have */
577 foreach($userids as $user)
579 /* userids are sorted by position...
580 * so output whatever the firstone has, then whatever the next one has
581 * stop when the sickness is the same as the gametype
584 $name = DB_get_name_by_userid($user);
585 $usersick = DB_get_sickness_by_userid_and_gameid($user,$gameid);
588 echo "$name has $usersick. <br />"; /*TODO: perhaps save this in a string and store in Game? */
590 if($usersick=="poverty")
592 if($usersick == "wedding" && $gametype =="wedding")
594 if($usersick == "poverty" && $gametype =="poverty")
596 if($usersick == "poverty" && $gametype =="dpoverty" && $poverty==2)
598 if($usersick == "solo" && $gametype =="solo")
602 /* output Schweinchen in case the rules need it */
603 if( $gametype != "solo")
604 if($GAME["schweinchen"] && $RULES["schweinchen"]=="both" )
605 echo DB_get_name_by_hash($GAME["schweinchen-who"])." has Schweinchen. <br />";
609 /* finished the setup, set re/contra parties if possible, go to next stage unless there is a case of poverty*/
613 /* are we the solo player? set us to re, else set us to contra */
614 $pos = DB_get_pos_by_hash($me);
615 if($pos == $startplayer)
616 DB_set_party_by_hash($me,"re");
618 DB_set_party_by_hash($me,"contra");
619 DB_set_hand_status_by_hash($me,'play');
623 /* set person with the wedding to re, do the rest during the game */
624 $usersick = DB_get_sickness_by_userid_and_gameid($myid,$gameid);
625 if($usersick == "wedding")
626 DB_set_party_by_hash($me,"re");
628 DB_set_party_by_hash($me,"contra");
630 echo "Whoever will make the first trick will be on the re team. <br />\n";
631 echo " Ok, the game can start now, please finish <a href=\"$host?me=$me\">the setup</a>.<br />";
632 DB_set_hand_status_by_hash($me,'play');
636 $hand = DB_get_all_hand($me);
638 if(in_array('3',$hand)||in_array('4',$hand))
639 DB_set_party_by_hash($me,"re");
641 DB_set_party_by_hash($me,"contra");
642 DB_set_hand_status_by_hash($me,'play');
646 /* check if poverty resolved (e.g. DB.Game who set to NULL)
647 * yes? =>trump was taken, start game; break;
649 $who = DB_get_sickness_by_gameid($gameid);
651 { /* trump has been taken */
652 DB_set_hand_status_by_hash($me,'play');
656 if($who>9) /*= two people still have trump on the table*/
661 /* check if we are being asked now
662 * no? display wait message, e.g. player X is asked at the moment
664 $usersick = DB_get_sickness_by_userid_and_gameid($myid,$gameid);
665 if(myisset("trump") && $_REQUEST["trump"]=="no" && ($who==$mypos || $who==$mypos*10))
667 /* user doesn't want to take trump */
668 /* set next player who needs to be asked */
669 $firstsick = (string) DB_get_sickness_by_pos_and_gameid($mypos+1,$gameid);
670 $secondsick = (string) DB_get_sickness_by_pos_and_gameid($mypos+2,$gameid);
672 if($firstsick=="poverty")
674 if($secondsick=="poverty")
675 DB_set_sickness_by_gameid($gameid,$who+$add*3);
677 DB_set_sickness_by_gameid($gameid,$who+$add*2);
680 DB_set_sickness_by_gameid($gameid,$who+$add);
682 /* email next player */
683 $who = DB_get_sickness_by_gameid($gameid);
684 if($who>9) $who = $who/10;
688 $To = DB_get_email_by_pos_and_gameid($who,$gameid);
689 $userhash = DB_get_hash_from_game_and_pos($gameid,$who);
691 $message = "Someone has poverty, it's your turn to decide, if you want to take the trump. Please visit:".
692 " ".$host."?me=".$userhash."\n\n" ;
693 mymail($To,$EmailName." poverty",$message);
696 /* this user is done */
697 DB_set_hand_status_by_hash($me,'play');
700 else if(myisset("trump") && !myisset("exchange") && $_REQUEST["trump"]>0 && ($who==$mypos || $who==$mypos*10))
702 /* user wants to take trump */
703 $trump = $_REQUEST["trump"];
705 /* get hand id for user $trump */
706 $userhand = DB_get_handid_by_gameid_and_userid($gameid,$trump);
707 /* copy trump from player A to B */
708 $result = mysql_query("UPDATE Hand_Card SET hand_id='$myhand' WHERE hand_id='$userhand' AND card_id<'27'" );
710 /* add hidden button with trump in it to get to the next point */
711 echo "<form action=\"index.php\" method=\"post\">\n";
712 echo " <input type=\"hidden\" name=\"exchange\" value=\"-1\" />\n";
713 echo " <input type=\"hidden\" name=\"trump\" value=\"".$trump."\" />\n";
714 echo " <input type=\"hidden\" name=\"me\" value=\"".$me."\" />\n";
715 echo " <input type=\"submit\" class=\"submitbutton\" value=\"select cards to give back\" />\n";
718 else if(myisset("trump","exchange") && $_REQUEST["trump"]>0 && ($who==$mypos || $who==$mypos*10))
720 $trump = $_REQUEST["trump"];
721 $exchange = $_REQUEST["exchange"];
722 $userhand = DB_get_handid_by_gameid_and_userid($gameid,$trump);
724 /* if exchange is set to a value>0, exchange that card back to user $trump */
727 $result = mysql_query("UPDATE Hand_Card SET hand_id='$userhand'".
728 " WHERE hand_id='$myhand' AND card_id='$exchange'" );
731 /* if number of cards == 12, set status to play for both users */
732 $result = mysql_query("SELECT COUNT(*) FROM Hand_Card WHERE hand_id='$myhand'" );
733 $r = mysql_fetch_array($result,MYSQL_NUM);
736 die("error in poverty");
740 if($gametype=="poverty" || $who<9)
742 DB_set_sickness_by_gameid($gameid,-1); /* done with poverty */
744 else /* reduce poverty count by one, that is go to single digits $who */
749 /* whom to ask next */
750 $firstsick = DB_get_sickness_by_pos_and_gameid($mypos+1,$gameid);
751 $secondsick = DB_get_sickness_by_pos_and_gameid($mypos+2,$gameid);
753 if($firstsick!="poverty")
754 DB_set_sickness_by_gameid($gameid,$who+$add);
757 if($secondsick!="poverty")
758 DB_set_sickness_by_gameid($gameid,$who+$add*2);
760 DB_set_sickness_by_gameid($gameid,$who+$add*3);
763 /* email next player */
764 $who = DB_get_sickness_by_gameid($gameid);
767 $To = DB_get_email_by_pos_and_gameid($who,$gameid);
768 $userhash = DB_get_hash_from_game_and_pos($gameid,$who);
770 $message = "Someone has poverty, it's your turn to decide, if you want to take the trump. Please visit:".
771 " ".$host."?me=".$userhash."\n\n" ;
772 mymail($To,$EmailName." poverty",$message);
777 /* this user is done */
778 DB_set_hand_status_by_hash($me,'play');
779 /* and so is his partner */
780 $hash = DB_get_hash_from_gameid_and_userid($gameid,$trump);
781 DB_set_hand_status_by_hash($hash,'play');
783 /* set party to re, unless we had dpoverty, in that case check if we need to set re/contra*/
785 foreach($userids as $user)
787 $userhash =DB_get_hash_from_gameid_and_userid($gameid,$user);
788 $party=DB_get_party_by_hash($userhash);
794 DB_set_party_by_hash($me,"contra");
795 DB_set_party_by_hash($hash,"contra");
799 foreach($userids as $user)
801 $userhash =DB_get_hash_from_gameid_and_userid($gameid,$user);
802 if($userhash==$hash||$userhash==$me)
803 DB_set_party_by_hash($userhash,"re");
805 DB_set_party_by_hash($userhash,"contra");
814 /* else show all trump, have lowest card pre-selected, have hidden setting for */
815 echo "you need to get rid of a few cards<br />\n";
817 set_gametype($gametype); /* this sets the $CARDS variable */
818 $mycards = DB_get_hand($me);
819 $mycards = mysort($mycards,$gametype);
821 echo "<form class=\"exchange\" action=\"index.php\" method=\"post\">\n";
823 foreach($mycards as $card)
824 display_link_card($card,$PREF["cardset"],$type);
825 echo " <input type=\"hidden\" name=\"trump\" value=\"".$trump."\" />\n";
826 echo " <input type=\"hidden\" name=\"me\" value=\"".$me."\" />\n";
827 echo " <input type=\"submit\" class=\"submitbutton\" value=\"select one card to give back\" />\n";
831 else if($who == $mypos || $who == $mypos*10)
833 foreach($userids as $user)
835 $name = DB_get_name_by_userid($user);
836 $usersick = DB_get_sickness_by_userid_and_gameid($user,$gameid);
838 if($usersick=="poverty")
840 $hash =DB_get_hash_from_gameid_and_userid($gameid,$user);
841 $cards=DB_get_hand($hash);
842 $nrtrump=count_trump($cards);
845 echo "Player $name has $nrtrump trump. Do you want to take them?".
846 "<a href=\"index.php?me=$me&trump=$user\">yes</a> <br />";
849 echo "I don't want to take any trump: ".
850 "<a href=\"index.php?me=$me&trump=no\">yes</a> <br />";
852 echo "Your cards are: <br />\n";
853 $mycards = DB_get_hand($me);
855 echo "<p class=\"mycards\" style=\"margin-top:8em;\">your cards are: <br />\n";
856 foreach($mycards as $card)
857 display_card($card,$PREF["cardset"]);
862 $mysick = DB_get_sickness_by_userid_and_gameid($myid,$gameid);
863 if($mysick=="poverty")
864 echo "The others are asked if they want to take your trump, you have to wait (you'll get an email).";
866 echo "it's not your turn yet to decide if you want to take the trump or not.";
869 * yes, display number of trump and user's hand, ask if he wants to take it
870 * no, set whom-to-ask to next player, email next player, cancle game if no next player
871 * yes -> link to new page:display all cards, ask for N return cards
877 /* check if no one wanted to take trump, in that case the gamesickness would be set to 5 or 50 */
878 $who = DB_get_sickness_by_gameid($gameid);
879 if($who==5 || $who==50)
881 $message = "Hello, \n\n".
882 "Game $gameid has been cancled since nobody wanted to take the trump.\n";
884 $userids = DB_get_all_userid_by_gameid($gameid);
885 foreach($userids as $user)
887 $To = DB_get_email_by_userid($user);
888 mymail($To,$EmailName."game $gameid cancled (poverty not resolved)",$message);
891 /* delete everything from the dB */
894 echo "<p style=\"background-color:red\";>Game $gameid has been cancled.<br /><br /></p>";
899 /* check if all players are ready to play */
901 foreach($userids as $user)
902 if(DB_get_hand_status_by_userid_and_gameid($user,$gameid)!='play')
907 /* only set this after all poverty, etc. are handled*/
908 DB_set_game_status_by_gameid($gameid,'play');
910 /* email startplayer */
911 $startplayer = DB_get_startplayer_by_gameid($gameid);
912 $email = DB_get_email_by_pos_and_gameid($startplayer,$gameid);
913 $hash = DB_get_hash_from_game_and_pos($gameid,$startplayer);
917 /* email startplayer) */
918 $message = "It's your turn now in game $gameid.\n".
919 "Use this link to play a card: ".$host."?me=".$hash."\n\n" ;
920 mymail($email,$EmailName."ready, set, go... ",$message);
923 echo " Please, <a href=\"$host?me=$me\">start</a> the game.<br />";
931 /* both entries here, so that the tricks are visible for both.
932 * in case of 'play' there is a break later that skips the last part
935 /* figure out what kind of game we are playing,
936 * set the global variables $CARDS["trump"],$CARDS["diamonds"],$CARDS["hearts"],
937 * $CARDS["clubs"],$CARDS["spades"],$CARDS["foxes"]
941 $gametype = DB_get_gametype_by_gameid($gameid);
943 if($gametype=="solo")
945 $gametype = DB_get_solo_by_gameid($gameid);
946 $GT = $gametype." ".$GT;
951 set_gametype($gametype); /* this sets the $CARDS variable */
953 /* get some infos about the game */
954 $gamestatus = DB_get_game_status_by_gameid($gameid);
956 /* display useful things in divs */
958 /* display links to the users status page */
959 $result = mysql_query("SELECT email,password from User WHERE id='$myid'" );
960 $r = mysql_fetch_array($result,MYSQL_NUM);
962 display_links($r[0],$r[1]);
964 /* end display useful things*/
966 /* has the game started? No, then just wait here...*/
967 if($gamestatus == 'pre')
969 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... <br />";
970 break; /* not sure this works... the idea is that you can
971 * only play a card after everyone is ready to play */
974 /* display the table and the names */
975 $result = mysql_query("SELECT User.fullname as name,".
976 " Hand.position as position, ".
978 " Hand.party as party, ".
979 " Hand.sickness as sickness, ".
982 "LEFT JOIN User ON User.id=Hand.user_id ".
983 "WHERE Hand.game_id='".$gameid."' ".
984 "ORDER BY position ASC");
986 echo "<div class=\"table\">\n".
987 " <img src=\"pics/table.png\" alt=\"table\" />\n";
988 while($r = mysql_fetch_array($result,MYSQL_NUM))
997 $offset = DB_get_user_timezone($user);
998 $zone = return_timezone($offset);
999 date_default_timezone_set($zone);
1001 echo " <span class=\"table".($pos-1)."\">\n";
1003 /* add hints for poverty, wedding, solo, etc */
1004 if($GT=="poverty" && $party=="re")
1005 if($sickness=="poverty")
1012 if($sickness=="poverty")
1013 echo "(poverty A <)";
1015 echo "(poverty A >)";
1017 if($sickness=="poverty")
1018 echo "(poverty B <)";
1020 echo "(poverty B >)";
1022 if($GT=="wedding" && $party=="re")
1023 if($sickness=="wedding")
1027 /* add point calls */
1029 echo " $party $call ";
1032 echo " local time: ".date("Y-m-d H:i:s")."\n";
1038 /* get everything relevant to display the tricks */
1039 $result = mysql_query("SELECT Hand_Card.card_id as card,".
1040 " Hand.position as position,".
1041 " Play.sequence as sequence, ".
1043 " Comment.comment ".
1045 "LEFT JOIN Play ON Trick.id=Play.trick_id ".
1046 "LEFT JOIN Hand_Card ON Play.hand_card_id=Hand_Card.id ".
1047 "LEFT JOIN Hand ON Hand_Card.hand_id=Hand.id ".
1048 "LEFT JOIN Comment ON Play.id=Comment.play_id ".
1049 "WHERE Trick.game_id='".$gameid."' ".
1050 "ORDER BY Trick.id,sequence ASC");
1053 $lasttrick = DB_get_max_trickid($gameid);
1055 $play = array(); /* needed to calculate winner later */
1057 $pos = DB_get_startplayer_by_gameid($gameid)-1;
1058 $firstcard = ""; /* first card in a trick */
1060 echo "\n<ul class=\"tricks\">\n";
1061 echo " <li class=\"nohighlight\"> Game $gameid: </li>\n";
1063 while($r = mysql_fetch_array($result,MYSQL_NUM))
1070 /* check if first schweinchen has been played */
1071 if($r[0] == 19 || $r[0] == 20 )
1072 $GAME["schweinchen"]++;
1074 /* save card to be able to find the winner of the trick later */
1075 $play[$seq] = array("card"=>$r[0],"pos"=>$pos);
1079 /* first card in a trick, output some html */
1080 if($trick!=$lasttrick)
1082 /* start of an old trick? */
1083 echo " <li onclick=\"hl('$trickNR');\" class=\"old\"><a href=\"#\">Trick $trickNR</a>\n".
1084 " <div class=\"trick\" id=\"trick".$trickNR."\">\n".
1085 " <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";
1087 else if($trick==$lasttrick)
1089 /* start of a last trick? */
1090 echo " <li onclick=\"hl('$trickNR');\" class=\"current\"><a href=\"#\">Trick $trickNR</a>\n".
1091 " <div class=\"trick\" id=\"trick".$trickNR."\">\n".
1092 " <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";
1095 /* remember first card, so that we are able to check, what cards can be played */
1100 echo " <div class=\"card".($pos-1)."\">\n";
1102 /* display comments */
1104 echo " <span class=\"comment\">".$comment."</span>\n";
1107 display_card($r[0],$PREF["cardset"]);
1109 echo " </div>\n"; /* end div card */
1115 echo " </div>\n </li>\n"; /* end div table, end li table */
1119 if($seq!=4 && $trickNR>1)
1120 echo " </div>\n </li>\n"; /* end div table, end li table */
1124 /* whos turn is it? */
1127 $winner = get_winner($play,$gametype); /* returns the position */
1129 $firstcard = ""; /* new trick, no first card */
1134 if($next==5) $next=1;
1137 /* my turn?, display cards as links, ask for comments*/
1138 if(DB_get_pos_by_hash($me) == $next)
1143 /* do we want to play a card? */
1144 if(myisset("card") && $myturn)
1146 $card = $_REQUEST["card"];
1147 $handid = DB_get_handid_by_hash($me);
1149 /* check if we have card and that we haven't played it yet*/
1150 /* set played in hand_card to true where hand_id and card_id*/
1151 $result = mysql_query("SELECT id FROM Hand_Card WHERE played='false' and ".
1152 "hand_id='$handid' AND card_id=".DB_quote_smart($card));
1153 $r = mysql_fetch_array($result,MYSQL_NUM);
1154 $handcardid = $r[0];
1156 if($handcardid) /* everything ok, play card */
1160 /* mark card as played */
1161 mysql_query("UPDATE Hand_Card SET played='true' WHERE hand_id='$handid' AND card_id=".
1162 DB_quote_smart($card));
1164 /* update Game timestamp */
1165 DB_update_game_timestamp($gameid);
1167 /* check if a call was made */
1168 if(myisset("call120") && $_REQUEST["call120"] == "yes")
1169 $result = mysql_query("UPDATE Hand SET point_call='120' WHERE hash='$me' ");
1170 if(myisset("call90") && $_REQUEST["call90"] == "yes")
1171 $result = mysql_query("UPDATE Hand SET point_call='90' WHERE hash='$me' ");
1172 if(myisset("call60") && $_REQUEST["call60"] == "yes")
1173 $result = mysql_query("UPDATE Hand SET point_call='60' WHERE hash='$me' ");
1174 if(myisset("call30") && $_REQUEST["call30"] == "yes")
1175 $result = mysql_query("UPDATE Hand SET point_call='30' WHERE hash='$me' ");
1176 if(myisset("call0") && $_REQUEST["call0"] == "yes")
1177 $result = mysql_query("UPDATE Hand SET point_call='0' WHERE hash='$me' ");
1180 /* check for schweinchen */
1181 //echo "schweinchen = ".$GAME["schweinchen"]." --$card-<br />";
1182 if($card == 19 || $card == 20 )
1184 $GAME["schweinchen"]++;
1185 if($GAME["schweinchen"]==3 && $RULES["schweinchen"]=="second" )
1186 $comment="Schweinchen! ";
1187 if($RULES["schweinchen"]=="both" )
1188 $comment="Schweinchen! ";
1189 if ($debug) echo "schweinchen = ".$GAME["schweinchen"]." ---<br />";
1192 /* get trick id or start new trick */
1193 $a = DB_get_current_trickid($gameid);
1198 $playid = DB_play_card($trickid,$handcardid,$sequence);
1200 /* if sequence == 4 check who one in case of wedding */
1201 if($sequence == 4 && $GT == "wedding")
1203 /* is wedding resolve */
1204 $resolved = DB_get_sickness_by_gameid($gameid);
1207 /* who has wedding */
1208 $userids = DB_get_all_userid_by_gameid($gameid);
1209 foreach($userids as $user)
1211 $usersick = DB_get_sickness_by_userid_and_gameid($user,$gameid);
1212 if($usersick == "wedding")
1215 /* who won the trick */
1216 $play = DB_get_cards_by_trick($trickid);
1217 $winner = get_winner($play,$gametype); /* returns the position */
1218 $winnerid = DB_get_userid_by_gameid_and_position($gameid,$winner);
1219 /* is tricknr <=3 */
1220 if($tricknr <=3 && $winnerid!=$whosick)
1222 /* set resolved at tricknr*/
1223 $resolved = DB_set_sickness_by_gameid($gameid,$tricknr);
1225 $whash = DB_get_hash_from_gameid_and_userid($gameid,$winnerid);
1226 DB_set_party_by_hash($whash,"re");
1228 if($tricknr == 3 && $winnerid==$whosick)
1230 /* set resolved at tricknr*/
1231 $resolved = DB_set_sickness_by_gameid($gameid,'3');
1236 /* check for coment */
1237 if(myisset("comment"))
1239 $comment.=$_REQUEST["comment"];
1242 DB_insert_comment($comment,$playid,$myid);
1244 /* display played card */
1245 echo "<div class=\"card\">";
1246 echo " you played <br />";
1247 display_card($card,$PREF["cardset"]);
1250 /*check if we still have cards left, else set status to gameover */
1251 if(sizeof(DB_get_hand($me))==0)
1253 DB_set_hand_status_by_hash($me,'gameover');
1254 $mystatus='gameover';
1257 /* if all players are done, set game status to game over,
1258 * get the points of the last trick and send out an email
1261 $userids = DB_get_all_userid_by_gameid($gameid);
1264 foreach($userids as $user)
1265 if(DB_get_hand_status_by_userid_and_gameid($user,$gameid)!='gameover')
1270 DB_set_game_status_by_gameid($gameid,"gameover");
1271 /* get score for last trick
1272 * all other tricks are handled a few lines further down*/
1273 $play = DB_get_cards_by_trick($trickid);
1274 $winner = get_winner($play,$gametype); /* returns the position */
1275 /* get points of last trick and save it */
1277 foreach($play as $card)
1278 $points = $points + card_value($card["card"]);
1279 $winnerid = DB_get_handid_by_gameid_and_position($gameid,$winner);
1281 mysql_query("INSERT INTO Score VALUES (NULL, '$gameid', '$winnerid', '$points')");
1283 echo "ERROR during scoring";
1285 /* email all players */
1286 /* individual score */
1287 $result = mysql_query("SELECT fullname, SUM(score), Hand.party FROM Score".
1288 " LEFT JOIN Hand ON Hand.id=hand_id".
1289 " LEFT JOIN User ON Hand.user_id=User.id".
1290 " WHERE Hand.game_id=$gameid".
1291 " GROUP BY fullname" );
1292 $message = "The game is over. Thanks for playing :)\n";
1293 while( $r = mysql_fetch_array($result,MYSQL_NUM))
1294 $message .= " FINAL SCORE: ".$r[0]."(".$r[2].") ".$r[1]."\n";
1295 $message .= "\nIf your not in the list above your score is zero...\n\n";
1297 $result = mysql_query("SELECT Hand.party, SUM(score) FROM Score".
1298 " LEFT JOIN Hand ON Hand.id=hand_id".
1299 " LEFT JOIN User ON Hand.user_id=User.id".
1300 " WHERE Hand.game_id=$gameid".
1301 " GROUP BY Hand.party" );
1303 while( $r = mysql_fetch_array($result,MYSQL_NUM))
1304 $message .= " FINAL SCORE: ".$r[0]." ".$r[1]."\n";
1306 /* check who wants to be CC'ed on the email */
1309 foreach($userids as $user)
1311 $result = mysql_query("SELECT value from User_Prefs".
1312 " WHERE user_id='$user' AND pref_key='ccemail'" );
1313 $r = mysql_fetch_array($result,MYSQL_NUM);
1314 if($r && $r[0]=="yes")
1315 $h[] = DB_get_email_by_userid($user);
1318 $header = "CC: ".join(",",$h)."\r\n";
1320 foreach($userids as $user)
1322 $To = DB_get_email_by_userid($user);
1323 $hash = DB_get_hash_from_gameid_and_userid($gameid,$user)
1324 $mymessage = $message."Use this link to have a look at the game: ".$host."?me=".$hash."\n\n" ;
1325 mymail($To,$EmailName."game over (game $gameid)",$mymessage,$header);
1330 /* email next player */
1331 if(DB_get_game_status_by_gameid($gameid)=='play')
1335 $play = DB_get_cards_by_trick($trickid);
1336 $winner = get_winner($play,$gametype); /* returns the position */
1338 /* get points of last trick and save it, last trick is handled
1339 * a few lines further up */
1341 foreach($play as $card)
1342 $points = $points + card_value($card["card"]);
1344 $winnerid = DB_get_handid_by_gameid_and_position($gameid,$winner);
1346 mysql_query("INSERT INTO Score VALUES (NULL, '$gameid', '$winnerid', '$points')");
1348 echo "ERROR during scoring";
1351 echo "DEBUG: $winner got $points <br />";
1353 /* who is the next player? */
1358 $next = DB_get_pos_by_hash($me)+1;
1360 if($next==5) $next=1;
1362 /* email next player */
1363 $next_hash = DB_get_hash_from_game_and_pos($gameid,$next);
1364 $email = DB_get_email_by_hash($next_hash);
1366 $message = "A card has been played in game $gameid.\n\n".
1367 "It's your turn now.\n".
1368 "Use this link to play a card: ".$host."?me=".$next_hash."\n\n" ;
1369 mymail($email,$EmailName."a card has been played",$message);
1374 echo "can't find that card?! <br />\n";
1377 else if(myisset("card") && !$myturn )
1379 echo "please wait until it's your turn! <br />\n";
1382 $mycards = DB_get_hand($me);
1383 $mycards = mysort($mycards,$gametype);
1384 echo "<div class=\"mycards\">\n";
1386 if($myturn && !myisset("card"))
1388 echo "Hello ".$myname.", it's your turn! <br />\n";
1389 echo "Your cards are: <br />\n";
1390 echo "<form action=\"index.php?me=$me\" method=\"post\">\n";
1392 /* do we have to follow suite? */
1394 if(have_suit($mycards,$firstcard))
1397 foreach($mycards as $card)
1399 if($followsuit && !same_type($card,$firstcard))
1400 display_card($card,$PREF["cardset"]);
1402 display_link_card($card,$PREF["cardset"]);
1405 if( can_call(120,$me) )
1406 echo " re/contra (120):".
1407 " <input type=\"radio\" name=\"call120\" value=\"yes\" /> ";
1408 if( can_call(90,$me) )
1410 " <input type=\"radio\" name=\"call90\" value=\"yes\" /> ";
1411 if( can_call(60,$me) )
1413 " <input type=\"radio\" name=\"call60\" value=\"yes\" /> ";
1414 if( can_call(30,$me) )
1416 " <input type=\"radio\" name=\"call30\" value=\"yes\" /> ";
1417 if( can_call(0,$me) )
1419 " <input type=\"radio\" name=\"call0\" value=\"yes\" /> ";
1421 echo "<br />\nA short comments:<input name=\"comment\" type=\"text\" size=\"30\" maxlength=\"50\" />\n";
1422 echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
1423 echo "<input type=\"submit\" value=\"move\" />\n";
1426 else if($mystatus=='play')
1428 echo "Your cards are: <br />\n";
1429 foreach($mycards as $card)
1430 display_card($card,$PREF["cardset"]);
1432 else if($mystatus=='gameover')
1434 $oldcards = DB_get_all_hand($me);
1435 $oldcards = mysort($oldcards,$gametype);
1436 echo "Your cards were: <br />\n";
1437 foreach($oldcards as $card)
1438 display_card($card,$PREF["cardset"]);
1442 /* check if we need to set status to 'gameover' is done during playing of the card */
1443 if($mystatus=='play')
1445 /* the following happens only when the gamestatus is 'gameover' */
1446 /* check if game is over, display results */
1447 if(DB_get_game_status_by_gameid($gameid)=='play')
1449 echo "the game is over for you.. other people still need to play though";
1453 echo "the game is over now...<br />\n";
1455 $result = mysql_query("SELECT fullname, SUM(score), Hand.party FROM Score".
1456 " LEFT JOIN Hand ON Hand.id=hand_id".
1457 " LEFT JOIN User ON Hand.user_id=User.id".
1458 " WHERE Hand.game_id=$gameid".
1459 " GROUP BY fullname" );
1460 while( $r = mysql_fetch_array($result,MYSQL_NUM))
1461 echo " FINAL SCORE: ".$r[0]."(".$r[2].") ".$r[1]."<br />";
1463 $result = mysql_query("SELECT Hand.party, SUM(score) FROM Score".
1464 " LEFT JOIN Hand ON Hand.id=hand_id".
1465 " LEFT JOIN User ON Hand.user_id=User.id".
1466 " WHERE Hand.game_id=$gameid".
1467 " GROUP BY Hand.party" );
1468 while( $r = mysql_fetch_array($result,MYSQL_NUM))
1469 echo " FINAL SCORE: ".$r[0]." ".$r[1]."<br />\n";
1472 $session = DB_get_session_by_gameid($gameid);
1473 $result = mysql_query("SELECT id,create_date FROM Game".
1474 " WHERE session=$session".
1475 " ORDER BY create_date DESC".
1479 $r = mysql_fetch_array($result,MYSQL_NUM);
1481 if(!$session || $gameid==$r[0])
1483 /* suggest a new game with the same people in it, just rotated once */
1484 $names = DB_get_all_names_by_gameid($gameid);
1485 output_ask_for_new_game($names[1],$names[2],$names[3],$names[0],$gameid);
1490 echo "error in testing the status";
1495 /* user status page */
1496 else if(myisset("email","password"))
1498 /* test id and password, should really be done in one step */
1499 $email = $_REQUEST["email"];
1500 $password = $_REQUEST["password"];
1503 if(myisset("forgot"))
1507 $uid = DB_get_userid_by_email($email);
1513 echo "Hmm, you forgot your passwort...nothing I can do at the moment:( ";
1514 echo " you need to email Arun for now... in the future it will be all automated and an ";
1515 echo "email with a new password will go to $email.";
1520 echo "you need to give me an email address!";
1522 echo "couldn't find a player with this email, please contact Arun, if you think this is a mistake";
1527 /* verify password and email */
1528 if(strlen($password)!=32)
1529 $password = md5($password);
1532 $uid = DB_get_userid_by_email_and_password($email,$password);
1540 if(myisset("setpref"))
1542 $setpref=$_REQUEST["setpref"];
1546 case "englishcards":
1547 $result = mysql_query("SELECT * from User_Prefs".
1548 " WHERE user_id='$uid' AND pref_key='cardset'" );
1549 if( mysql_fetch_array($result,MYSQL_NUM))
1550 $result = mysql_query("UPDATE User_Prefs SET value=".DB_quote_smart($setpref).
1551 " WHERE user_id='$uid' AND pref_key='cardset'" );
1553 $result = mysql_query("INSERT INTO User_Prefs VALUES(NULL,'$uid','cardset',".DB_quote_smart($setpref).")");
1554 echo "Ok, changed you preferences for the cards.\n";
1557 $result = mysql_query("SELECT * from User_Prefs".
1558 " WHERE user_id='$uid' AND pref_key='ccemail'" );
1559 if( mysql_fetch_array($result,MYSQL_NUM))
1560 if($PREF["ccemail"]=="yes")
1561 $result = mysql_query("UPDATE User_Prefs SET value=".DB_quote_smart("no").
1562 " WHERE user_id='$uid' AND pref_key='ccemail'" );
1564 $result = mysql_query("UPDATE User_Prefs SET value=".DB_quote_smart("yes").
1565 " WHERE user_id='$uid' AND pref_key='ccemail'" );
1567 $result = mysql_query("INSERT INTO User_Prefs VALUES(NULL,'$uid','ccemail',".DB_quote_smart("yes").")");
1568 echo "Ok, changed you preferences for being CC'ed on emails.\n";
1573 else /* output default user page */
1575 $time = DB_get_user_timestamp($uid);
1576 $unixtime =strtotime($time);
1578 $offset = DB_get_user_timezone($uid);
1579 $zone = return_timezone($offset);
1580 date_default_timezone_set($zone);
1582 /* display links to settings */
1583 output_user_settings($email,$password);
1585 echo "last login: ".date("r",$unixtime)."<br />";
1587 DB_update_user_timestamp($uid);
1589 echo "<p>these are your games that haven't started yet:<br />\n";
1590 $result = mysql_query("SELECT Hand.hash,Hand.game_id,Game.mod_date from Hand".
1591 " LEFT JOIN Game On Hand.game_id=Game.id".
1592 " WHERE Hand.user_id='$uid' AND Game.status='pre'" );
1593 while( $r = mysql_fetch_array($result,MYSQL_NUM))
1595 echo "<a href=\"".$host."?me=".$r[0]."\">game #".$r[1]." </a>";
1596 if(time()-strtotime($r[2]) > 60*60*24*30)
1597 echo " The game has been running for over a month.".
1598 " Do you want to cancel it? <a href=\"$host?cancle=1&me=".$r[0]."\">yes</a>".
1599 " (clicking here is final and can't be restored)";
1604 echo "<p>these are the games you are playing in:<br />\n";
1605 $result = mysql_query("SELECT Hand.hash,Hand.game_id,Game.mod_date from Hand".
1606 " LEFT JOIN Game On Hand.game_id=Game.id".
1607 " WHERE Hand.user_id='$uid' AND Game.status='play'" );
1608 while( $r = mysql_fetch_array($result,MYSQL_NUM))
1610 echo "<a href=\"".$host."?me=".$r[0]."\">game #".$r[1]." </a>";
1611 if(time()-strtotime($r[2]) > 60*60*24*30)
1612 echo " The game has been running for over a month.".
1613 " Do you want to cancel it? <a href=\"$host?cancle=1&me=".$r[0]."\">yes</a>".
1614 " (clicking here is final and can't be restored)";
1620 echo "<p>and these are your games that are already done:<br />Game: \n";
1621 $result = mysql_query("SELECT hash,game_id from Hand WHERE user_id='$uid' AND status='gameover'" );
1622 while( $r = mysql_fetch_array($result,MYSQL_NUM))
1623 echo "<a href=\"".$host."?me=".$r[0]."\">#".$r[1]." </a>, ";
1626 $names = DB_get_all_names();
1627 echo "<p>registered players:<br />\n";
1628 foreach ($names as $name)
1632 echo "<p>Want to start a new game? Visit <a href=\"".$host."?new\">this page.</a></p>";
1637 echo "sorry email and password don't match <br />";
1643 /* page for registration */
1644 else if(myisset("register") )
1648 /* new user wants to register */
1649 else if(myisset("Rfullname","Remail","Rpassword","Rtimezone") )
1652 if(DB_get_userid_by_name($_REQUEST["Rfullname"]))
1654 echo "please chose another name<br />";
1657 if(DB_get_userid_by_email($_REQUEST["Remail"]))
1659 echo "this email address is already used ?!<br />";
1664 $r=mysql_query("INSERT INTO User VALUES(NULL,".DB_quote_smart($_REQUEST["Rfullname"]).
1665 ",".DB_quote_smart($_REQUEST["Remail"]).
1666 ",".DB_quote_smart(md5($_REQUEST["Rpassword"])).
1667 ",".DB_quote_smart($_REQUEST["Rtimezone"]).",NULL)");
1670 echo " added you to the database";
1672 echo " something went wrong";
1675 /* default login page */
1678 $pre=0;$game=0;$done=0;
1679 $r=mysql_query("SELECT COUNT(id) FROM Game GROUP BY status");
1681 $pre = mysql_fetch_array($r,MYSQL_NUM);
1682 $game = mysql_fetch_array($r,MYSQL_NUM);
1683 $done = mysql_fetch_array($r,MYSQL_NUM);
1685 output_home_page($pre[0],$game[0],$done[0]);