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