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