moved more stuff from index.php to output.php
[e-DoKo.git] / index.php
1 <?php
2 error_reporting(E_ALL);
3
4 include_once("config.php");     
5 include_once("output.php");      /* html output only */
6 include_once("db.php");          /* database only */
7 include_once("functions.php");   /* the rest */
8
9 DB_open();
10
11 /*****************  M A I N **************************/
12 output_header();
13
14
15 /* check if we want to start a new game */
16 if(isset($_REQUEST["new"]))
17      output_form_for_new_game();
18
19 /*check if everything is ready to set up a new game */
20 else if( isset($_REQUEST["PlayerA"]) && 
21     isset($_REQUEST["PlayerB"]) && 
22     isset($_REQUEST["PlayerC"]) && 
23     isset($_REQUEST["PlayerD"]) )
24   {
25     $PlayerA = $_REQUEST["PlayerA"];
26     $PlayerB = $_REQUEST["PlayerB"];
27     $PlayerC = $_REQUEST["PlayerC"];
28     $PlayerD = $_REQUEST["PlayerD"];
29     
30     $EmailA  = DB_get_email_by_name($PlayerA);
31     $EmailB  = DB_get_email_by_name($PlayerB);
32     $EmailC  = DB_get_email_by_name($PlayerC);
33     $EmailD  = DB_get_email_by_name($PlayerD);
34     
35     if($EmailA=="" || $EmailB=="" || $EmailC=="" || $EmailD=="")
36       {
37         echo "couldn't find one of the names, please start a new game";
38         exit();
39       }
40     
41     $useridA  = DB_get_userid_by_name($PlayerA);
42     $useridB  = DB_get_userid_by_name($PlayerB);
43     $useridC  = DB_get_userid_by_name($PlayerC);
44     $useridD  = DB_get_userid_by_name($PlayerD);
45     
46     /* create random numbers */
47     $randomNR       = create_array_of_random_numbers();
48     $randomNRstring = join(":",$randomNR);
49     
50     /* create game */
51     $followup = NULL;
52     if(isset($_REQUEST["followup"])) 
53       {
54         $followup= $_REQUEST["followup"];
55         mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', NULL, NULL,'pre','$followup' ,NULL)");
56       }
57     else
58       mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', NULL, NULL,'pre', NULL ,NULL)");
59     $game_id = mysql_insert_id();
60     
61     /* create hash */
62     $hashA = md5("AGameOfDoko".$game_id.$PlayerA.$EmailA);
63     $hashB = md5("AGameOfDoko".$game_id.$PlayerB.$EmailB);
64     $hashC = md5("AGameOfDoko".$game_id.$PlayerC.$EmailC);
65     $hashD = md5("AGameOfDoko".$game_id.$PlayerD.$EmailD);
66     
67     /* create hands */
68     mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridA).
69                 ", ".DB_quote_smart($hashA).", 'start','1',NULL,NULL,NULL,'false','false',NULL)");
70     $hand_idA = mysql_insert_id();                                                             
71     mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridB).
72                 ", ".DB_quote_smart($hashB).", 'start','2',NULL,NULL,NULL,'false','false',NULL)");
73     $hand_idB = mysql_insert_id();                                                             
74     mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridC).
75                 ", ".DB_quote_smart($hashC).", 'start','3',NULL,NULL,NULL,'false','false',NULL)");
76     $hand_idC = mysql_insert_id();                                                             
77     mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridD).
78                 ", ".DB_quote_smart($hashD).", 'start','4',NULL,NULL,NULL,'false','false',NULL)");
79     $hand_idD = mysql_insert_id();
80     
81     /* save cards */
82     for($i=0;$i<12;$i++)
83       mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idA', '".$randomNR[$i]."', 'false')");
84     for($i=12;$i<24;$i++)
85       mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idB', '".$randomNR[$i]."', 'false')");
86     for($i=24;$i<36;$i++)
87       mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idC', '".$randomNR[$i]."', 'false')");
88     for($i=36;$i<48;$i++)
89       mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idD', '".$randomNR[$i]."', 'false')");
90
91     /* send out email, TODO: check for error with email */
92     $message = "\n".
93       "you are invited to play a game of DoKo (that is to debug the program ;).\n".
94       "Place comments and bug reports here:\n".
95       "http://wiki.nubati.net/index.php?title=EmailDoko\n\n".
96       "The whole round would consist of the following players:\n".
97       "$PlayerA\n".
98       "$PlayerB\n".
99       "$PlayerC\n".
100       "$PlayerD\n\n".
101       "If you want to join this game, please follow this link:\n\n".
102       " ".$host."?me=";
103     
104     mymail($EmailA,"You are invited to a game of DoKo","Hello $PlayerA,\n".$message.$hashA);
105     mymail($EmailB,"You are invited to a game of DoKo","Hello $PlayerB,\n".$message.$hashB);
106     mymail($EmailC,"You are invited to a game of DoKo","Hello $PlayerC,\n".$message.$hashC);
107     mymail($EmailD,"You are invited to a game of DoKo","Hello $PlayerD,\n".$message.$hashD);
108         
109   }    
110 /* end set up a new game */
111
112 else if(isset($_REQUEST["me"]))
113   {
114      /* handle request from one specifig player,
115       * the hash is set on a per game base, so first just handle this game
116       * perhaps also show links to other games in a sidebar
117       */
118     
119     $me = $_REQUEST["me"];
120
121     /* test for valid ID */
122     $myid = DB_get_userid_by_hash($me);
123     if(!$myid)
124       {
125         echo "Can't find you in the database, please check the url.<br />\n";
126         echo "perhaps the game has been cancled.";
127         exit();
128       }
129     
130     DB_update_user_timestamp($myid);
131
132     /* get some information from the DB */
133     $gameid   = DB_get_gameid_by_hash($me);
134     $myname   = DB_get_name_by_hash($me);
135     $mystatus = DB_get_status_by_hash($me);
136     
137     switch($mystatus)
138       {
139       case 'start':
140         check_want_to_play($me);
141         DB_set_hand_status_by_hash($me,'init');
142         break;
143       case 'init':
144         if( !isset($_REQUEST["in"]) || !isset($_REQUEST["update"]))
145           {
146             DB_set_hand_status_by_hash($me,'start');
147             echo "you need to answer both question";
148           }
149         else
150           {
151             if($_REQUEST["in"] == "no")
152               {
153                 echo "TODO: email everyone that the game has been canceled.<br />";
154                  /*something like need to modify for DB backend
155                  for($i=0;$i<4;$i++)
156                    {
157                      $message = "Hello ".$player[$hash[$i]]["name"].",\n\n".
158                        "the game has been canceled due to the request of one of the players.\n";
159                      mymail($player[$hash[$i]]["email"],"[DoKo-Debug] the game has been canceled",$message); 
160                    }
161                  */
162                 /* delete everything from the dB */
163                 DB_cancel_game($me);
164               }
165             else
166               {
167                 echo "thanks for joining the game... please scroll down";
168                 echo "TODO: make this page nicer<br />";
169                 echo "TODO: set card pref<br />";
170                 
171                 $mycards = DB_get_hand($me);
172                 sort($mycards);
173                 echo "<p class=\"mycards\">your cards are: <br />\n";
174                 foreach($mycards as $card) 
175                   display_card($card);
176                 echo "</p>\n";   
177                 
178                 check_for_sickness($me,$mycards);
179                 
180                 DB_set_hand_status_by_hash($me,'check');
181               }
182            }
183         break;
184         
185       case 'check':
186         echo "no checking at the moment... you need to play a normal game. At the moment you need to reload this page to finish the setup.";
187         if(!isset($_REQUEST["solo"])    || 
188            !isset($_REQUEST["wedding"]) ||
189            !isset($_REQUEST["poverty"]) ||
190            !isset($_REQUEST["nines"]) )
191           {
192             DB_set_hand_status_by_hash($me,'init');
193             /* problem: by setting it back to init, variables "in" and "update" are 
194              * not set, so the player will be send back to the start, after seeing his hand
195              */
196             echo "you need to fill out the form";
197           }
198         else
199           {
200             if( $_REQUEST["solo"]!="No")
201               {
202                 DB_set_solo_by_hash($me,$_REQUEST["solo"]);
203                 DB_set_sickness_by_hash($me,"solo");
204               }
205             else if($_REQUEST["wedding"] == "yes")
206               {
207                 echo "wedding was chosen<br />\n";
208                 DB_set_sickness_by_hash($me,"wedding");
209               }
210             else if($_REQUEST["poverty"] == "yes")
211               {
212                 echo "poverty was chosen<br />\n";
213                 DB_set_sickness_by_hash($me,"poverty");
214               }
215             else if($_REQUEST["nines"] == "yes")
216               {
217                 echo "nines was chosen<br />\n";
218                  DB_set_sickness_by_hash($me,"nines");
219               }
220           }
221         DB_set_hand_status_by_hash($me,'poverty');
222         
223         /* check all players and set game to final result, e.g. solo, wedding, povert, redeal */
224         
225         /* reset solo, etc from players who did say something, but it didn't matter? */
226         break;
227       case 'poverty':
228         echo "<br />poverty not handeled at the moment... you need to play a normal game<br />";
229         
230         /* only set this after all poverty, etc. are handeled*/
231         DB_set_hand_status_by_hash($me,'play');
232
233         /* check if the game can start  */
234         $userids = DB_get_all_userid_by_gameid($gameid);
235         $done=1;
236         foreach($userids as $user)
237           if(DB_get_hand_status_by_userid($user)!='play')
238             $done=0;
239
240         if($done)
241           DB_set_game_status_by_gameid($gameid,'play');
242
243         break;
244       case 'play':
245       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*/
246         /* display local time */
247         echo "<div class=\"time\">\n Local times:<table>";
248         $users = array();
249         $users = DB_get_all_userid_by_gameid($gameid);
250         foreach($users as $user)
251           {
252             $offset = DB_get_user_timezone($user);
253             $zone = return_timezone($offset);
254             date_default_timezone_set($zone);
255             $name = DB_get_name_by_userid($user);
256             
257             echo "<tr> <td>$name</td> <td>".date("Y-m-d H:i:s")."</td></tr>\n";
258           };
259         echo "</table>\n</div>\n";
260         display_status();
261
262         /* display links to other games */
263         echo "<div class=\"over\">\n";
264         $result = mysql_query("SELECT email,password from User WHERE id='$myid'" );
265         $r = mysql_fetch_array($result,MYSQL_NUM);
266         echo "<form action=\"index.php\" method=\"post\">\n";
267         echo "  <input type=\"hidden\" name=\"email\" value=\"".$r[0]."\" />\n";
268         echo "  <input type=\"hidden\" name=\"password\" value=\"".$r[1]."\" />\n";
269         echo "  <input type=\"submit\" value=\"go to my user page\" />\n";
270         echo "</form>\n";
271         echo "</div>\n";
272
273         display_news();
274
275         $gamestatus = DB_get_game_status_by_gameid($gameid);
276         if($gamestatus == 'pre')
277           {
278             echo "you need to wait for the others... <br />";
279             break;
280           }
281         /* get everythin relevant to display the tricks */
282         $result = mysql_query("SELECT Hand_Card.card_id as card,".
283                               "       User.fullname as name,".
284                               "       Hand.position as position,".
285                               "       Play.sequence as sequence, ".
286                               "       Hand.hash     as hash,     ".
287                               "       Trick.id, ".
288                               "       Comment.comment ".
289                               "FROM Trick ".
290                               "LEFT JOIN Play ON Trick.id=Play.trick_id ".
291                               "LEFT JOIN Hand_Card ON Play.hand_card_id=Hand_Card.id ".
292                               "LEFT JOIN Hand ON Hand_Card.hand_id=Hand.id ".
293                               "LEFT JOIN User ON User.id=Hand.user_id ".
294                               "LEFT JOIN Comment ON Play.id=Comment.play_id ".
295                               "WHERE Trick.game_id='".$gameid."' ".
296                               "ORDER BY Trick.id,sequence ASC");
297         
298         
299         $trickNR = 1;
300         
301         $lasttrick = DB_get_max_trickid($gameid);
302         
303         $play = array(); /* needed to calculate winner later  */
304         $seq  = 1;          
305         $pos  = 0;
306         
307         echo "\n<ul class=\"oldtrick\">\n";
308         echo "  <li> Hello $myname!   History: </li>\n";
309         
310         while($r = mysql_fetch_array($result,MYSQL_NUM))
311           {
312             $seq     = $r[3];
313             $pos     = $r[2];
314             $trick   = $r[5];
315             $comment = $r[6];
316             
317             if($trick!=$lasttrick && $seq==1)
318               {
319                 /* start of an old trick? */
320                 echo "  <li onclick=\"hl('$trickNR');\"><a href=\"#\">Trick $trickNR</a>\n".
321                   "    <div class=\"table\" id=\"trick".$trickNR."\">\n".
322                   "      <img class=\"table\" src=\"pics/table".($pos-1).".png\" alt=\"table\" />\n";
323               }
324             else if($trick==$lasttrick && $seq==1)
325               {
326                 /* start of a last trick? */
327                 echo "  <li onclick=\"hl('$trickNR');\"><a href=\"#\">Current Trick</a>\n".
328                   "    <div class=\"table\" id=\"trick".$trickNR."\">\n".
329                   "      <img class=\"table\" src=\"pics/table".($pos-1).".png\" alt=\"table\" />\n";
330               }
331             
332             /* display card */
333             echo "      <div class=\"card".($pos-1)."\">\n";
334             
335             $play[$pos]=$r[0];
336             
337             if($comment!="")
338               echo "        <span class=\"comment\">";
339             else
340               echo "        <span>";
341             
342             /* print name */
343             echo $r[1];
344             
345             /* check for comment */
346             if($comment!="")
347               echo "<span>".$comment."</span>";
348             echo "</span>\n        ";
349             
350             display_card($r[0]);
351             
352             echo "      </div>\n"; /* end div card */
353             
354             /* end of trick? */
355             if($seq==4)
356               {
357                 $trickNR++;
358                 echo "    </div>\n  </li>\n";  /* end div table, end li table */
359               }
360           }
361
362         if($seq!=4 && $trickNR>1) 
363           echo "    </div>\n  </li>\n";  /* end div table, end li table */
364         
365         echo "</ul>\n";
366         
367         /* whos turn is it? */
368         if($seq==4)
369           {
370              $winner = get_winner($play); /* returns the position */
371              $next = $winner;
372           }
373         else
374           {
375             $next = $pos+1;
376           }
377         if($next==5) $next=1;
378         
379         /* my turn?, display cards as links, ask for comments*/
380         if(DB_get_pos_by_hash($me) == $next)
381           $myturn = 1;
382         else
383           $myturn = 0;
384
385         /* do we want to play a card? */
386         if(isset($_REQUEST["card"]) && $myturn)
387           {
388             $card   = $_REQUEST["card"];
389             $handid = DB_get_handid_by_hash($me); 
390             
391             /* check if we have card and that we haven't played it yet*/
392             /* set played in hand_card to true where hand_id and card_id*/
393             $result = mysql_query("SELECT id FROM Hand_Card WHERE played='false' and ".
394                                   "hand_id='$handid' AND card_id=".DB_quote_smart($card));
395             $r = mysql_fetch_array($result,MYSQL_NUM);
396             $handcardid = $r[0];
397             
398             if($handcardid)
399               {
400                 mysql_query("UPDATE Hand_Card SET played='true' WHERE hand_id='$handid' AND card_id=".DB_quote_smart($card));
401                 
402                 /* get trick id or start new trick */
403                 $a = DB_get_current_trickid($gameid);
404                 $trickid  = $a[0];
405                 $sequence = $a[1];
406                 
407                 $playid = DB_play_card($trickid,$handcardid,$sequence);
408
409                 /*check for coment */
410                 if(isset($_REQUEST["comment"]))
411                   {
412                     DB_insert_comment($_REQUEST["comment"],$playid,$myid);
413                   };  
414
415                 echo "<div class=\"card\">";
416                 echo " you played  <br />";
417                 display_card($card);
418                 echo "</div>\n";
419                 
420
421                 /*check if we still have cards left, else set status to gameover */
422                 if(sizeof(DB_get_hand($me))==0)
423                   {
424                     DB_set_hand_status_by_hash($me,'gameover');
425                     $mystatus='gameover';
426                   }
427                 
428                 /* if all players are done, set game status also to game over */
429                 $userids = DB_get_all_userid_by_gameid($gameid);
430                 $done=1;
431                 foreach($userids as $user)
432                   if(DB_get_hand_status_by_userid($user)!='gameover')
433                     $done=0;
434
435                 if($done)
436                   DB_set_game_status_by_gameid($gameid,"gameover");
437                 
438                 /* email next player */
439                 if(DB_get_game_status_by_gameid($gameid)=='play')
440                   {
441                     if($sequence==4)
442                       {
443                         $play   = DB_get_cards_by_trick($trickid);
444                         $winner = get_winner($play); /* returns the position */
445                         $next = $winner;
446                       }
447                     else
448                       {
449                         $next = DB_get_pos_by_hash($me)+1;
450                       }
451                     if($next==5) $next=1;
452
453                     /* email next player */
454                     $next_hash = DB_get_hash_from_game_and_pos($gameid,$next);
455                     $email     = DB_get_email_by_hash($next_hash);
456
457                     $message = "It's your turn  now.\n".
458                       "Use this link to play a card: ".$host."?me=".$next_hash."\n\n" ;
459                     mymail($email,"[DoKo-debug] a card has been played",$message);
460                     
461                     if($debug)
462                       echo "DEBUG:<a href=\"index.php?me=".DB_get_hash_from_game_and_pos($gameid,$next).
463                         "\"> next player </a> <br />\n";
464
465                   }
466               }
467             else
468               {
469                 echo "couldn't find card <br />\n";
470               }
471           }
472         else if(isset($_REQUEST["card"]) && !$myturn )
473           {
474             echo "please wait until it is your turn! <br />\n";
475           }
476         
477         $mycards = DB_get_hand($me);
478         sort($mycards);
479         echo "<div class=\"mycards\">\n";
480         
481         if($myturn && !isset($_REQUEST["card"]))
482           {
483             echo "Hello ".$myname.", it's your turn!  <br />\n";
484             echo "Your cards are: <br />\n";
485             echo "<form action=\"index.php?me=$me\" method=\"post\">\n";
486             foreach($mycards as $card) 
487               display_link_card($card);
488 ?>
489     <br />A short comments:<input name="comment" type="text" size="30" maxlength="50" /> 
490     <input type="hidden" name="me" value="<?php echo $me; ?>" />
491     <input type="submit" value="move" />
492  </form>
493  <?php
494          }
495         else if($mystatus=='play')
496           {
497             echo "Your cards are: <br />\n";
498             foreach($mycards as $card) 
499               display_card($card);
500           }
501         echo "</div>\n";
502
503         /* check if we need to set status to 'gameover' is done during playing of the card */
504         if($mystatus=='play')
505           break;
506    /* the following happens only when the gamestatus is 'gameover' */
507         /* check if game is over, display results */
508         if(DB_get_game_status_by_gameid($gameid)=='play')
509           {
510             echo "the game is over for you.. other people still need to play though";
511           }
512         else
513           {
514             echo "the game is over now... guess the final score should be displayed here...<br />\n";
515             
516             /* suggest a new game with the same people in it, just rotated once */
517             $names = DB_get_all_names_by_gameid($gameid);
518             
519             echo "Do you want to continue playing?(This will start a new game, with the next person as dealer.)\n";
520             echo "<form action=\"index.php\" method=\"post\">\n";
521             echo "  <input type=\"hidden\" name=\"PlayerA\" value=\"".($names[1])."\" />\n";
522             echo "  <input type=\"hidden\" name=\"PlayerB\" value=\"".($names[2])."\" />\n";
523             echo "  <input type=\"hidden\" name=\"PlayerC\" value=\"".($names[3])."\" />\n";
524             echo "  <input type=\"hidden\" name=\"PlayerD\" value=\"".($names[0])."\" />\n";
525             echo "  <input type=\"hidden\" name=\"followup\" value=\"".($gameid)."\" />\n";
526             echo "  <input type=\"submit\" value=\"keep playing\" />\n";
527             echo "</form>\n";
528           }
529         break;
530       default:
531         echo "error in testing the status";
532       }
533     exit();
534   } 
535 /* user status page */ 
536  else if(isset($_REQUEST["email"]) && isset($_REQUEST["password"]))
537   {
538     /* test id and password, should really be done in one step */
539     $email     = $_REQUEST["email"];
540     $password  = $_REQUEST["password"];
541
542     if(strlen($password)!=32)
543       $password = md5($password);
544
545     $ok=1;
546     $uid = DB_get_userid_by_email_and_password($email,$password);
547     if(!$uid)
548       $ok=0;
549
550     if($ok)
551       {
552         $time = DB_get_user_timestamp($uid);
553         $unixtime =strtotime($time);
554         
555         $offset = DB_get_user_timezone($uid);
556         $zone = return_timezone($offset);
557         date_default_timezone_set($zone);
558
559         echo "last login: ".date("r",$unixtime)."<br />";
560
561         DB_update_user_timestamp($uid);
562
563         echo "<p>these are the games you are playing in:<br />\n";
564         $result = mysql_query("SELECT hash,game_id from Hand WHERE user_id='$uid' AND status<>'gameover'" );
565         while( $r = mysql_fetch_array($result,MYSQL_NUM))
566           echo "<a href=\"".$host."?me=".$r[0]."\">game #".$r[1]." </a><br />";
567         echo "</p>\n";
568
569         $names = DB_get_all_names();
570         echo "<p>registered players:<br />\n";
571         foreach ($names as $name)
572           echo "$name <br />\n";
573         echo "</p>\n";
574         echo "<p>Want to start a new game? remember 4 names from the list above and visit ".
575           "<a href=\"".$host."?new\">this page.</a></p>";
576       }
577     else
578       {
579         echo "sorry email and password don't match <br />";
580       }
581     exit();
582   }
583 /* page for registration */
584 else if(isset($_REQUEST["register"]) )
585   {
586     echo "IMPORTANT: passwords are going over the net as clear text, so pick an easy password. No need to pick anything complicated here ;)<br /><br />";
587     echo "TODO: convert timezone into a menu<br />\n";
588     echo "TODO: figure out a way to handle passwrods <br />\n";
589 ?>
590         <form action="index.php" method="post">
591           <fieldset>
592             <legend>Register</legend>
593              <table>
594               <tr>
595                <td><label for="Rfullname">Full name:</label></td>
596                <td><input type="text" id="Rfullname" name="Rfullname" size="20" maxsize="30" /> </td>
597               </tr><tr>
598                <td><label for="Remail">Email:</label></td>
599                <td><input type="text" id="Remail" name="Remail" size="20" maxsize="30" /></td>
600               </tr><tr>
601                <td><label for="Rpassword">Password(will be displayed in cleartext on the next page):</label></td>
602                <td><input type="password" id="Rpassword" name="Rpassword" size="20" maxsize="30" /></td>
603               </tr><tr>
604                <td><label for="Rtimezone">Timezone:</label></td>
605                <td>
606                   <input type="text" id="Rtimezone" name="Rtimezone" size="4" maxsize="4" value="+1" />
607                </td>
608               </tr><tr>
609                <td colspan="2"> <input type="submit" value="register" /></td>
610              </table>
611           </fieldset>
612         </form>
613 <?php
614   }
615 /* new user wants to register */
616 else if(isset($_REQUEST["Rfullname"]) && 
617         isset($_REQUEST["Remail"]   ) && 
618         isset($_REQUEST["Rpassword"]) && 
619         isset($_REQUEST["Rtimezone"]) )
620   {
621         $ok=1;
622         if(DB_get_userid_by_name($_REQUEST["Rfullname"]))
623           {
624             echo "please chose another name<br />";
625             $ok=0;
626           }
627         if(DB_get_userid_by_email($_REQUEST["Remail"]))
628           {
629             echo "this email address is already used ?!<br />";
630             $ok=0;
631           }
632         if($ok)
633           {
634             $r=mysql_query("INSERT INTO User VALUES(NULL,".DB_quote_smart($_REQUEST["Rfullname"]).
635                       ",".DB_quote_smart($_REQUEST["Remail"]).
636                       ",".DB_quote_smart(md5($_REQUEST["Rpassword"])).
637                       ",".DB_quote_smart($_REQUEST["Rtimezone"]).",NULL)"); 
638             
639             if($r)
640               echo "  added you to the database";
641             else
642               echo " something went wrong";
643           }
644   }
645 /* default login page */
646 else
647   { /* no new game, not in a game */
648     home_page();
649   }
650
651 output_footer();
652
653 DB_close();
654
655 /*
656  *Local Variables: 
657  *mode: php
658  *mode: hs-minor
659  *End:
660  */
661 ?>
662
663