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