started on adding support for different solo games (modified get_winner a tiny bit...
[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         /* here we need to check if there is a solo or some other form o sickness.
229          * If so, which one counts
230          * set that one in the Game table, delete other ones form Hand table 
231          * tell people about it.
232          */
233         echo "<br />poverty not handeled at the moment... you need to play a normal game<br />";
234         
235         /* only set this after all poverty, etc. are handeled*/
236         DB_set_hand_status_by_hash($me,'play');
237
238         /* check if the game can start  */
239         $userids = DB_get_all_userid_by_gameid($gameid);
240         $done=1;
241         foreach($userids as $user)
242           if(DB_get_hand_status_by_userid($user)!='play')
243             $done=0;
244
245         if($done)
246           DB_set_game_status_by_gameid($gameid,'play');
247
248         break;
249       case 'play':
250       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*/
251         /* display local time */
252         echo "<div class=\"time\">\n Local times:<table>";
253         $users = array();
254         $users = DB_get_all_userid_by_gameid($gameid);
255         foreach($users as $user)
256           {
257             $offset = DB_get_user_timezone($user);
258             $zone = return_timezone($offset);
259             date_default_timezone_set($zone);
260             $name = DB_get_name_by_userid($user);
261             
262             echo "<tr> <td>$name</td> <td>".date("Y-m-d H:i:s")."</td></tr>\n";
263           };
264         echo "</table>\n</div>\n";
265         display_status();
266
267         /* display links to other games */
268         echo "<div class=\"over\">\n";
269         $result = mysql_query("SELECT email,password from User WHERE id='$myid'" );
270         $r = mysql_fetch_array($result,MYSQL_NUM);
271         echo "<form action=\"index.php\" method=\"post\">\n";
272         echo "  <input type=\"hidden\" name=\"email\" value=\"".$r[0]."\" />\n";
273         echo "  <input type=\"hidden\" name=\"password\" value=\"".$r[1]."\" />\n";
274         echo "  <input type=\"submit\" value=\"go to my user page\" />\n";
275         echo "</form>\n";
276         echo "</div>\n";
277
278         display_news();
279
280         $gamestatus = DB_get_game_status_by_gameid($gameid);
281         if($gamestatus == 'pre')
282           {
283             echo "you need to wait for the others... <br />";
284             break;
285           }
286         /* get everythin relevant to display the tricks */
287         $result = mysql_query("SELECT Hand_Card.card_id as card,".
288                               "       User.fullname as name,".
289                               "       Hand.position as position,".
290                               "       Play.sequence as sequence, ".
291                               "       Hand.hash     as hash,     ".
292                               "       Trick.id, ".
293                               "       Comment.comment ".
294                               "FROM Trick ".
295                               "LEFT JOIN Play ON Trick.id=Play.trick_id ".
296                               "LEFT JOIN Hand_Card ON Play.hand_card_id=Hand_Card.id ".
297                               "LEFT JOIN Hand ON Hand_Card.hand_id=Hand.id ".
298                               "LEFT JOIN User ON User.id=Hand.user_id ".
299                               "LEFT JOIN Comment ON Play.id=Comment.play_id ".
300                               "WHERE Trick.game_id='".$gameid."' ".
301                               "ORDER BY Trick.id,sequence ASC");
302         
303         
304         $trickNR = 1;
305         
306         $lasttrick = DB_get_max_trickid($gameid);
307         
308         $play = array(); /* needed to calculate winner later  */
309         $seq  = 1;          
310         $pos  = 0;
311         
312         echo "\n<ul class=\"oldtrick\">\n";
313         echo "  <li> Hello $myname!   History: </li>\n";
314         
315         while($r = mysql_fetch_array($result,MYSQL_NUM))
316           {
317             $seq     = $r[3];
318             $pos     = $r[2];
319             $trick   = $r[5];
320             $comment = $r[6];
321             
322             if($trick!=$lasttrick && $seq==1)
323               {
324                 /* start of an old trick? */
325                 echo "  <li onclick=\"hl('$trickNR');\"><a href=\"#\">Trick $trickNR</a>\n".
326                   "    <div class=\"table\" id=\"trick".$trickNR."\">\n".
327                   "      <img class=\"table\" src=\"pics/table".($pos-1).".png\" alt=\"table\" />\n";
328               }
329             else if($trick==$lasttrick && $seq==1)
330               {
331                 /* start of a last trick? */
332                 echo "  <li onclick=\"hl('$trickNR');\"><a href=\"#\">Current Trick</a>\n".
333                   "    <div class=\"table\" id=\"trick".$trickNR."\">\n".
334                   "      <img class=\"table\" src=\"pics/table".($pos-1).".png\" alt=\"table\" />\n";
335               }
336             
337             /* display card */
338             echo "      <div class=\"card".($pos-1)."\">\n";
339             
340             $play[$pos]=$r[0];
341             
342             if($comment!="")
343               echo "        <span class=\"comment\">";
344             else
345               echo "        <span>";
346             
347             /* print name */
348             echo $r[1];
349             
350             /* check for comment */
351             if($comment!="")
352               echo "<span>".$comment."</span>";
353             echo "</span>\n        ";
354             
355             display_card($r[0]);
356             
357             echo "      </div>\n"; /* end div card */
358             
359             /* end of trick? */
360             if($seq==4)
361               {
362                 $trickNR++;
363                 echo "    </div>\n  </li>\n";  /* end div table, end li table */
364               }
365           }
366
367         if($seq!=4 && $trickNR>1) 
368           echo "    </div>\n  </li>\n";  /* end div table, end li table */
369         
370         echo "</ul>\n";
371         
372         /* whos turn is it? */
373         if($seq==4)
374           {
375              $winner = get_winner($play,"normal"); /* returns the position */
376              $next = $winner;
377           }
378         else
379           {
380             $next = $pos+1;
381           }
382         if($next==5) $next=1;
383         
384         /* my turn?, display cards as links, ask for comments*/
385         if(DB_get_pos_by_hash($me) == $next)
386           $myturn = 1;
387         else
388           $myturn = 0;
389
390         /* do we want to play a card? */
391         if(isset($_REQUEST["card"]) && $myturn)
392           {
393             $card   = $_REQUEST["card"];
394             $handid = DB_get_handid_by_hash($me); 
395             
396             /* check if we have card and that we haven't played it yet*/
397             /* set played in hand_card to true where hand_id and card_id*/
398             $result = mysql_query("SELECT id FROM Hand_Card WHERE played='false' and ".
399                                   "hand_id='$handid' AND card_id=".DB_quote_smart($card));
400             $r = mysql_fetch_array($result,MYSQL_NUM);
401             $handcardid = $r[0];
402             
403             if($handcardid)
404               {
405                 mysql_query("UPDATE Hand_Card SET played='true' WHERE hand_id='$handid' AND card_id=".DB_quote_smart($card));
406                 
407                 /* get trick id or start new trick */
408                 $a = DB_get_current_trickid($gameid);
409                 $trickid  = $a[0];
410                 $sequence = $a[1];
411                 
412                 $playid = DB_play_card($trickid,$handcardid,$sequence);
413
414                 /*check for coment */
415                 if(isset($_REQUEST["comment"]))
416                   {
417                     DB_insert_comment($_REQUEST["comment"],$playid,$myid);
418                   };  
419
420                 echo "<div class=\"card\">";
421                 echo " you played  <br />";
422                 display_card($card);
423                 echo "</div>\n";
424                 
425
426                 /*check if we still have cards left, else set status to gameover */
427                 if(sizeof(DB_get_hand($me))==0)
428                   {
429                     DB_set_hand_status_by_hash($me,'gameover');
430                     $mystatus='gameover';
431                   }
432                 
433                 /* if all players are done, set game status also to game over */
434                 $userids = DB_get_all_userid_by_gameid($gameid);
435                 $done=1;
436                 foreach($userids as $user)
437                   if(DB_get_hand_status_by_userid($user)!='gameover')
438                     $done=0;
439
440                 if($done)
441                   DB_set_game_status_by_gameid($gameid,"gameover");
442                 
443                 /* email next player */
444                 if(DB_get_game_status_by_gameid($gameid)=='play')
445                   {
446                     if($sequence==4)
447                       {
448                         $play   = DB_get_cards_by_trick($trickid);
449                         $winner = get_winner($play,"normal"); /* returns the position */
450                         $next = $winner;
451                       }
452                     else
453                       {
454                         $next = DB_get_pos_by_hash($me)+1;
455                       }
456                     if($next==5) $next=1;
457
458                     /* email next player */
459                     $next_hash = DB_get_hash_from_game_and_pos($gameid,$next);
460                     $email     = DB_get_email_by_hash($next_hash);
461
462                     $message = "It's your turn  now.\n".
463                       "Use this link to play a card: ".$host."?me=".$next_hash."\n\n" ;
464                     mymail($email,"[DoKo-debug] a card has been played",$message);
465                     
466                     if($debug)
467                       echo "DEBUG:<a href=\"index.php?me=".DB_get_hash_from_game_and_pos($gameid,$next).
468                         "\"> next player </a> <br />\n";
469
470                   }
471               }
472             else
473               {
474                 echo "couldn't find card <br />\n";
475               }
476           }
477         else if(isset($_REQUEST["card"]) && !$myturn )
478           {
479             echo "please wait until it is your turn! <br />\n";
480           }
481         
482         $mycards = DB_get_hand($me);
483         sort($mycards);
484         echo "<div class=\"mycards\">\n";
485         
486         if($myturn && !isset($_REQUEST["card"]))
487           {
488             echo "Hello ".$myname.", it's your turn!  <br />\n";
489             echo "Your cards are: <br />\n";
490             echo "<form action=\"index.php?me=$me\" method=\"post\">\n";
491             foreach($mycards as $card) 
492               display_link_card($card);
493 ?>
494     <br />A short comments:<input name="comment" type="text" size="30" maxlength="50" /> 
495     <input type="hidden" name="me" value="<?php echo $me; ?>" />
496     <input type="submit" value="move" />
497  </form>
498  <?php
499          }
500         else if($mystatus=='play')
501           {
502             echo "Your cards are: <br />\n";
503             foreach($mycards as $card) 
504               display_card($card);
505           }
506         echo "</div>\n";
507
508         /* check if we need to set status to 'gameover' is done during playing of the card */
509         if($mystatus=='play')
510           break;
511    /* the following happens only when the gamestatus is 'gameover' */
512         /* check if game is over, display results */
513         if(DB_get_game_status_by_gameid($gameid)=='play')
514           {
515             echo "the game is over for you.. other people still need to play though";
516           }
517         else
518           {
519             echo "the game is over now... guess the final score should be displayed here...<br />\n";
520             
521             /* suggest a new game with the same people in it, just rotated once */
522             $names = DB_get_all_names_by_gameid($gameid);
523             
524             echo "Do you want to continue playing?(This will start a new game, with the next person as dealer.)\n";
525             echo "<form action=\"index.php\" method=\"post\">\n";
526             echo "  <input type=\"hidden\" name=\"PlayerA\" value=\"".($names[1])."\" />\n";
527             echo "  <input type=\"hidden\" name=\"PlayerB\" value=\"".($names[2])."\" />\n";
528             echo "  <input type=\"hidden\" name=\"PlayerC\" value=\"".($names[3])."\" />\n";
529             echo "  <input type=\"hidden\" name=\"PlayerD\" value=\"".($names[0])."\" />\n";
530             echo "  <input type=\"hidden\" name=\"followup\" value=\"".($gameid)."\" />\n";
531             echo "  <input type=\"submit\" value=\"keep playing\" />\n";
532             echo "</form>\n";
533           }
534         break;
535       default:
536         echo "error in testing the status";
537       }
538     exit();
539   } 
540 /* user status page */ 
541  else if(isset($_REQUEST["email"]) && isset($_REQUEST["password"]))
542   {
543     /* test id and password, should really be done in one step */
544     $email     = $_REQUEST["email"];
545     $password  = $_REQUEST["password"];
546
547     if(strlen($password)!=32)
548       $password = md5($password);
549
550     $ok=1;
551     $uid = DB_get_userid_by_email_and_password($email,$password);
552     if(!$uid)
553       $ok=0;
554
555     if($ok)
556       {
557         $time = DB_get_user_timestamp($uid);
558         $unixtime =strtotime($time);
559         
560         $offset = DB_get_user_timezone($uid);
561         $zone = return_timezone($offset);
562         date_default_timezone_set($zone);
563
564         echo "last login: ".date("r",$unixtime)."<br />";
565
566         DB_update_user_timestamp($uid);
567
568         echo "<p>these are the games you are playing in:<br />\n";
569         $result = mysql_query("SELECT hash,game_id from Hand WHERE user_id='$uid' AND status<>'gameover'" );
570         while( $r = mysql_fetch_array($result,MYSQL_NUM))
571           echo "<a href=\"".$host."?me=".$r[0]."\">game #".$r[1]." </a><br />";
572         echo "</p>\n";
573
574         $names = DB_get_all_names();
575         echo "<p>registered players:<br />\n";
576         foreach ($names as $name)
577           echo "$name <br />\n";
578         echo "</p>\n";
579         echo "<p>Want to start a new game? remember 4 names from the list above and visit ".
580           "<a href=\"".$host."?new\">this page.</a></p>";
581       }
582     else
583       {
584         echo "sorry email and password don't match <br />";
585       }
586     exit();
587   }
588 /* page for registration */
589 else if(isset($_REQUEST["register"]) )
590   {
591     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 />";
592     echo "TODO: convert timezone into a menu<br />\n";
593     echo "TODO: figure out a way to handle passwrods <br />\n";
594 ?>
595         <form action="index.php" method="post">
596           <fieldset>
597             <legend>Register</legend>
598              <table>
599               <tr>
600                <td><label for="Rfullname">Full name:</label></td>
601                <td><input type="text" id="Rfullname" name="Rfullname" size="20" maxsize="30" /> </td>
602               </tr><tr>
603                <td><label for="Remail">Email:</label></td>
604                <td><input type="text" id="Remail" name="Remail" size="20" maxsize="30" /></td>
605               </tr><tr>
606                <td><label for="Rpassword">Password(will be displayed in cleartext on the next page):</label></td>
607                <td><input type="password" id="Rpassword" name="Rpassword" size="20" maxsize="30" /></td>
608               </tr><tr>
609                <td><label for="Rtimezone">Timezone:</label></td>
610                <td>
611                   <input type="text" id="Rtimezone" name="Rtimezone" size="4" maxsize="4" value="+1" />
612                </td>
613               </tr><tr>
614                <td colspan="2"> <input type="submit" value="register" /></td>
615              </table>
616           </fieldset>
617         </form>
618 <?php
619   }
620 /* new user wants to register */
621 else if(isset($_REQUEST["Rfullname"]) && 
622         isset($_REQUEST["Remail"]   ) && 
623         isset($_REQUEST["Rpassword"]) && 
624         isset($_REQUEST["Rtimezone"]) )
625   {
626         $ok=1;
627         if(DB_get_userid_by_name($_REQUEST["Rfullname"]))
628           {
629             echo "please chose another name<br />";
630             $ok=0;
631           }
632         if(DB_get_userid_by_email($_REQUEST["Remail"]))
633           {
634             echo "this email address is already used ?!<br />";
635             $ok=0;
636           }
637         if($ok)
638           {
639             $r=mysql_query("INSERT INTO User VALUES(NULL,".DB_quote_smart($_REQUEST["Rfullname"]).
640                       ",".DB_quote_smart($_REQUEST["Remail"]).
641                       ",".DB_quote_smart(md5($_REQUEST["Rpassword"])).
642                       ",".DB_quote_smart($_REQUEST["Rtimezone"]).",NULL)"); 
643             
644             if($r)
645               echo "  added you to the database";
646             else
647               echo " something went wrong";
648           }
649   }
650 /* default login page */
651 else
652   { /* no new game, not in a game */
653     home_page();
654   }
655
656 output_footer();
657
658 DB_close();
659
660 /*
661  *Local Variables: 
662  *mode: php
663  *mode: hs-minor
664  *End:
665  */
666 ?>
667
668