Location: PHPKode > projects > Slashster > slashster/html/join.php
<?

# Slashster: Open Source Friend of a Friend Software
# Copyright 2004 Mark El-Wakil
# Contact: hide@address.com
# http://seventhcycle.net
#
# This file is part of Slashster.
#
# Slashster is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Slashster is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Slashster; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    import_request_variables("gPc");

    require_once("PageClass.php");
    $mpage = new PageClass("authonly");


    if (($_SERVER[SERVER_PORT] != 443) && $mpage->sys[securenbl])
    {
        $url = $mpage->sys[secureurl];
        $url .= $_SERVER[SCRIPT_NAME];
        $url .= "?" . $_SERVER[QUERY_STRING] . "&" . sid;

        header("Location: $url");
        exit;
    }




    $repeat = 1;
    $errmsg = "";

    if ($ym)
    { 
        $email1 = $ym;
        $email2 = $ym;
    }

    if ($i)
    {
         $sql = "select Email from UserTable where Id = \"$i\" limit 1"; 
         $bmm = $mpage->DoQuery($sql,1);

         if (sizeof($bmm)) $buddyemail = $bmm[0][Email];
    }


    foreach ($_POST as $k=>$v) $_POST[$k] = trim($v);
    extract($_POST);

    if ($submit)
    {
         $repeat = 0;

         $email1 = strtolower($email1);
         $email2 = strtolower($email2);


         $vml = (!preg_match ("/^[\w\.\-]+\@[\w\.\-]+\.[a-z]{2,4}$/i", $email1));


         if (!$repeat && $vml)
         {
              $repeat = 1;
              $errmsg = "Please enter a valid email address";
         }

         if (!$repeat && ($email1 != $email2))
         {
              $repeat = 1;
              $errmsg = "Please make sure both email addresses match";
         }

         if (!$repeat)
         {
              $sql = "select * from UserTable where Email = \"$email1\" ";
              $r = $mpage->DoQuery($sql);
          
              if (sizeof($r))
              {
                  $repeat = 1;                
                  $errmsg = "User already exists!  You've already signed up!";
              }
         }

         if (!$repeat && !strlen($fname) )
         {
              $repeat = 1;
              $errmsg = "Please enter a first name.";
         }

         if (!$repeat && !strlen($lname) )
         {
              $repeat = 1;
              $errmsg = "Please enter a last name.";                 
         }

         if (!$repeat && (strlen($pass1) < 6))
         {
              $repeat = 1;
              $errmsg = "Please enter a password of at least 6 characters";
         }

         if (!$repeat && ($pass1 != $pass2))
         {
              $repeat = 1;
              $errmsg = "Please make sure both passwords entered match.";
         }

         if (!$repeat && !in_array($gender, array(1,2)))
         {
              $repeat = 1;
              $errmsg = "Please tell us if you're male or female.";
         }

         if (!$dating && !$relatn)
         {
             $drgender=0;
         }

         if (!$repeat && !in_array($drgender, array(1,2,3)) && ($dating || $relatn)  )
         {
              $repeat = 1;
              $errmsg = "Please enter your dating / relationship gender interest";
         }

         if (!$friends && !$netbud)
         {
             $fngender=0;
         }

         if (!$repeat && !in_array($fngender, array(1,2,3)) && ($friends || $netbud))
         {
              $repeat = 1;
              $errmsg = "Please enter your friend / netbuddy gender interest";
         }

         if (!$repeat && !in_array($month, array(1,2,3,4,5,6,7,8,9,10,11,12)))
         {
              $repeat = 1;
              $errmsg = "What month were you born?";    
         }

         $day = floor($day);

         if (!$repeat && ( ($day < 1) || ($day > 31) ) )   
         {
              $repeat = 1;
              $errmsg = "What day were you born?";                          
         }

         if (!$repeat && ( ($year < date("Y")-100) || ($day > date("Y")-12) ) )
         {
              $repeat = 1;
              $errmsg = "What year were you born (Ages 13-100 allowed)?";
         }

         if (!$repeat)
         {
              $mkt = mktime(1,1,1, $month, 1, $year);
              $dim = date("t",$mkt);
              
              if ($day > $dim)
              {
                 $repeat = 1;
                 $errmsg = "There were only $dim days in the month of $month / $year";
              }
         }

         if (!$repeat && !in_array($meetme, array(1,2,3,4)))
         {
              $repeat = 1;
              $errmsg = "Please enter your plans on meeting / calling / chatting people on this site";
         }

         if (!$repeat)
         {
              if ($buddyemail)
              {
                 $sql = "select * from UserTable where Email = \"$buddyemail\" ";
                 $inlst = $mpage->DoQuery($sql,1);

                 if (!sizeof($inlst))
                 {
                     $errmsg = "No such email in the ".$mpage->sys[sitename]." system";
                     $repeat = 1;
                 }
                 else 
                 {
                     $budid  = $inlst[0][Id];

                     $sql = "select InviteEmail.*, UserTable.Email, UserTable.Id as uid from InviteEmail 
                             left join UserTable on InviteEmail.UserId = UserTable.Id
                             where InviteEmail.Email = \"$email1\" AND UserTable.Email
                             = \"$buddyemail\" ";

                     $budinv = $mpage->DoQuery($sql,1);

                     $addfr = (sizeof($budinv)) ? 1 : 0;
                 }
              }
              else
              {
                 $budid = 0;
              }

         }

         if (!$repeat && ($validch != $_SESSION['rndchr']))
         {                
             $repeat = 1;
             $errmsg = "Characters in box do not match.";
         }
    }

    if (!$repeat)
    {
        $month = sprintf("%02d", $month);
        $day   = sprintf("%02d", $day);

        $dating  = ($dating)  ? 1 : 0;
        $relatn  = ($relatn)  ? 1 : 0;
        $friends = ($friends) ? 1 : 0;
        $netbud  = ($netbud)  ? 1 : 0;


        $salt = $mpage->RandomChars(10);

        $pass = md5($pass1 . $salt);

        $sql = "insert into UserTable set
                         Fname = \"$fname\",
                         Lname = \"$lname\",
                         Email = \"$email1\",
                         Pass  = \"$pass\", 
                         Salt  = \"$salt\",
                         DateJoined = NOW(),
                         LastSeen   = NOW(),
                         Gender = \"$gender\",
                         Birthday = \"$year-$month-$day\",
                         Dating  = \"$dating\",  
                         Relatn  = \"$relatn\",
                         Friends = \"$friends\",
                         Netbud  = \"$netbud\",
                         DrGender = \"$drgender\",
                         FnGender = \"$fngender\",
                         MeetMe   = \"$meetme\",
                         Referer  = \"$budid\",
                         CSS      = \"$_SESSION[CSS]\"
               ";

        $mpage->DoQuery($sql);
        $mid = mysql_insert_id();

        $mpage->MakeCert($mid, $pass1);

        $sql = "update UserTable set Age = (YEAR(CURDATE())-YEAR(Birthday)) - (RIGHT(CURDATE(),5)<RIGHT(BirthDay,5))
                where Id = $mid";
        $mpage->DoQuery($sql);

        if ($mid == 1)
        {
            $sql = "update UserTable set Admin=1 where Id = \"$mid\" ";
            $mpage->DoQuery($sql);
        }

        if ($budid)
        {
            if ($addfr)
            {
                $sql = "delete from InviteEmail where Email = \"$email1\" AND
                        UserId=\"$budid\"";

                $mpage->DoQuery($sql);

                $sql = "insert into FriendTable (Start, End) values ($budid, $mid), 
                        ($mid, $budid)";

                $mpage->DoQuery($sql);
            }
            else
            {
                $mpage->FriendRequest($mid, $budid);
            }
        }

        $sql = "select * from InviteEmail where Email=\"$email1\" ";
        $ase = $mpage->DoQuery($sql,1);

        foreach ($ase as $asee)
        {
           $mpage->FriendRequest($asee[UserId],$mid);
        }

        $sql = "delete from InviteEmail where Email=\"$email1\" ";
        $mpage->DoQuery($sql);


        $sql = "insert into PrivateFolders set Owner=\"$mid\", Name=\"Inbox\", Special=1";
        $mpage->DoQuery($sql);
        $bb1 = mysql_insert_id();

        $sql = "insert into PrivateFolders set Owner=\"$mid\", Name=\"Trash Can\", Special=1";
        $mpage->DoQuery($sql);
        $bb2 = mysql_insert_id();

        $sql = "insert into PrivateFolders set Owner=\"$mid\", Name=\"Outgoing\", Special=1";
        $mpage->DoQuery($sql);
        $bb3 = mysql_insert_id(); 
            
        $sql = "update UserTable set    
                     DefMailInbox = \"$bb1\",
                     DefMailTrash = \"$bb2\",
                     DefMailOutg  = \"$bb3\" where Id = \"$mid\" ";
        $mpage->DoQuery($sql);   


        $_SESSION[userid] = $mid;

        EmailConfirmation($fname, $email1, $pass1, $mid, $salt);

        $fll = $mpage->sys[siteroot] . "friendlist/$mid.txt";

        touch($fll);
        chmod($fll, 0777); 

        header("Location: ". $mpage->stdurl ."usersetup.php?" . sid);
        exit;
    }


    $mpage->Initialize("authremainder");

    $_SESSION['rndchr'] = $mpage->RandomChars(3);

?>
<span class="title1"><?= $mpage->sys[sitename] ?> Beta</span>
<BR><span class="title2"><?= $mpage->sys[slogan] ?></span>


<P>Meet people.  Chat.  Play.

<? if ($errmsg) { ?>


<P>
<table border=4 bordercolor=red cellspacing=0 cellpadding=5px>
<tr><td style="font: bold 16px arial; color:red;">
Error: <?= $errmsg ?>
</td></tr>
</table>
<P>

<? } ?>



<table border=0 width=100%>
<tr><td width=300 valign=top>



<form method=post>
<table cellpadding=0 cellspacing=0 width=300>
<tr>
<td class="stdtable" width=150><B>Your Email</b></td>
<td class="stdfilling" width=150><input name="email1" 
    class="input" value="<?= htmlentities($email1) ?>"></td>
</tr>

<tr>
<td class="stdtable" width=150><B>Your Email (Confirm)</b></td>       
<td class="stdfilling" width=150><input name=email2
    class="input" value="<?= htmlentities($email2) ?>"></td>     
</tr>

<tr>
<td class="stdtable" width=150><B>First Name</b></td>
<td class="stdfilling" width=150><input name=fname 
    class="input" value="<?= htmlentities($fname) ?>"></td>
</tr>

<tr>
<td class="stdtable" width=150><B>Last Name</b></td>
<td class="stdfilling" width=150><input name=lname
    class="input" value="<?= htmlentities($lname) ?>"></td>
</tr>

<tr>
<td class="stdtable" width=150><b>Password</b></td>           
<td class="stdfilling" width=150><input name=pass1 type=password 
    class="input" value="<?= htmlentities($pass1) ?>"></td> 
</tr>

<tr>
<td class="stdtable" width=150><b>Password (Again)</b></td>
<td class="stdfilling" width=150><input name=pass2 type=password 
    class="input" value="<?= htmlentities($pass2) ?>"></td>
</tr>

<tr>
<td class="stdtable" width=150><b>Gender</b></td>
<td class="stdtable" width=150>

<input name=gender type=radio value=1 <?= ($gender == "1") ? "checked" : "" ?>>Male
<input name=gender type=radio value=2 <?= ($gender == "2") ? "checked" : "" ?>>Female

</td>
</tr>

<tr><td class="stdtable" colspan =2>

<B>I want to meet people for:</b>

<table width=100%>
<tr><td class="stdtable">
    <input name="dating" type="checkbox" value="1" <?= ($dating == "1") ? "checked" : "" ?>>Dating
<BR><input name="relatn" type="checkbox" value="1" <?= ($relatn == "1") ? "checked" : "" ?>>Relationship

</td><td class="stdtable">
<input name="drgender" type="radio" value="1" <?= ($drgender == "1") ? "checked" : "" ?>>Men
<input name="drgender" type="radio" value="2" <?= ($drgender == "2") ? "checked" : "" ?>>Women
<BR>
<input name="drgender" type="radio" value="3" <?= ($drgender == "3") ? "checked" : "" ?>>Men & Women

</td>
</tr>
<tr><td colspan=2>
<hr>
</td></tr>

<tr><td class="stdtable">
    <input name="friends" type="checkbox" value="1" <?= ($friends == "1") ? "checked" : "" ?>>Friends
<BR><input name="netbud"  type="checkbox" value="1" <?= ($netbud  == "1") ? "checked" : "" ?>>Net Buddy

</td><td class="stdtable">
<input name="fngender" type="radio" value="1" <?= ($fngender == "1") ? "checked" : "" ?>>Men
<input name="fngender" type="radio" value="2" <?= ($fngender == "2") ? "checked" : "" ?>>Women
<BR>
<input name="fngender" type="radio" value="3" <?= ($fngender == "3") ? "checked" : "" ?>>Men & Women

</td>
</tr>

<tr><td colspan=2>
<hr> 
</td></tr>




<tr><td colspan=2 class="stdtable">

<B>My Birthday:</b><BR>

<select name="month">
  <option value="">-----------
  <?
      for ($x = 1; $x <= 12; $x++) { 
         $dt = mktime(1,1,1, $x, 1, 2000);
         ?>
             <option value="<?= $x ?>" <?= ($month == $x) ? "selected" : "" ?>> 
               (<?= sprintf("%02d", $x) ?>) <?= date("M", $dt) ?> 
         <?
      }
  ?>
</select>
<select name="day">
  <option value="">--
  <? for ($x = 1; $x <= 31; $x++) { ?>
     <option value="<?= sprintf("%02d", $x) ?>" <?= ($day == $x) ? "selected" : "" ?> > <?= sprintf("%02d", $x) ?>        
  <? } ?>
</select>
<select name="year">
  <option value="">----
  <? for ($x = date("Y") - 12; $x >= date("Y") - 100; $x--) { ?>
     <option value="<?= $x ?>" <?= ($year == $x) ? "selected" : "" ?>> <?= $x ?>
  <? } ?>  
</select>

</td></tr>



<tr><td colspan=2>
<hr>
</td></tr>



</table>

<B>The people I talk to on here I may: </b>

<BR>&nbsp;&nbsp;<select name="meetme">
  <option value="">--Choose one--
  <option value="1" <?= ($meetme == 1) ? "selected" : "" ?>>Chat online only
  <option value="2" <?= ($meetme == 2) ? "selected" : "" ?>>Call on the phone
  <option value="3" <?= ($meetme == 3) ? "selected" : "" ?>>Meet if they're in the area.
  <option value="4" <?= ($meetme == 4) ? "selected" : "" ?>>Might travel and meet up.

</select>

</td></tr>

<tr><td colspan=2 class="stdtable">
<P><B>Please enter in the text in the box below
</td></tr>

<tr><td class="stdtable" align=center>
<img src="validpic.php?PHPSESSID=<?= $mpage->SessionId ?>">
</td><td class="stdtable">
<input name="validch">

</td></tr>

</table>

<P><B>Did someone refer you here?</b>

<BR>Buddy's Email:
<input name="buddyemail" value="<?= htmlentities($buddyemail) ?>"><BR>
<small>(This'll hook you up to your friend and his/her friends)</small>


<P>
<div style="width:300" align=center>
<input name="submit" type="submit" class="submit" value="Continue">
</div>

</form>




</td><td valign=top align=center>

<BR><BR>
<img src="images/logo2-<?= $mpage->CSS ?>.gif">

</td></tr>
</table>

<? $mpage->ClosePage() ?>

<?

function EmailConfirmation($fname, $email, $pass, $id, $salt)
{
   global $mpage;

   $verify = md5($id . "-" . $salt);

   $txt .= "Dear $fname\n\n";

   $txt .= "Welcome to ".$mpage->sys[sitename].".  Here is a copy of your login\n";
   $txt .= "and password for safekeeping.\n\n";

   $txt .= "Login: $email\n";  
   $txt .= "Pass:  $pass\n\n";

   $txt .= "You will also need to verify your email.  You can do\n";
   $txt .= "so by clicking or copying the link below into a browser.\n\n";

   $txt .= $mpage->stdurl . "verify.php?id=$id&verify=";
   $txt .= $verify;
   $txt .= "\n\n";

   $txt .= "Thanks for signing up!";

   $mpage->MailSchedule($id,
                                  $id,
                                  $mpage->sys[sitename] . " Signup", $txt, 1, 1, 0);   


}
Return current item: Slashster