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