<?php
include ("inc/inc_common.php");
include ("inc/inc_connect.php");
include ("inc/inc_admincheck.php");
include ("inc/inc_getdate.php");
include ("inc/inc_forumname.php");
$page = "Registration Page";
$pagelink = $file;
include("inc/inc_setonline.php");

$username = str_replace ( "\'", "", $username);
$username = str_replace ( "\"", "", $username);
$username = str_replace ( "\\", "", $username);

$signature = str_replace ( "<", "&lt;", $signature);
$signature = str_replace ( ">", "&gt;", $signature);
$signature = str_replace ( "\'", "", $signature);
$signature = str_replace ( "\"", "", $signature);
$signature = str_replace ( "\\", "", $signature);


$biography = str_replace ( "<", "&lt;", $biography);
$biography = str_replace ( ">", "&gt;", $biography);
$biography = str_replace ( "\'", "", $biography);
$biography = str_replace ( "\"", "", $biography);
$biography = str_replace ( "\\", "", $biography);


//Check Avatar image sizes...
if ($avatarb != "")
{
    $avatar = $avatarb;
}


if ($avatar == "")
{
    //no avatar
}
else
{
    $size = getimagesize ("$avatar");
    if ( $size[0] > 125 or $size[1] > 125 )
    {
        include ("inc/inc_registrationtext.php");
        print "Sorry, your avatar is too big - it needs to be 125x125px or less. Please remove it or try a different image.";
        $pass=1;
    }
}



$result = mysql_query( "SELECT * FROM $userstable ORDER BY intId" );
$num_rows = mysql_num_rows( $result );
$same = 0;
$pass = 0;
$ip_hit=$REMOTE_ADDR;

if ( $password == $password2 )
{
    //passwords match
}
else
{
    $pass = 1;
    include ("inc/inc_registrationtext.php");
    print "Sorry $name, but your passwords did not match,<br>
    Use the back button on your browser to try again.";
}

if ( $password == "" OR $username == "" OR $email == "" )
{
    include ("inc/inc_registrationtext.php");
    print "You didn't fill in one or more of the required fields.<br>Please hit the back button and try again.<br><br><br>";
    exit;
}



if ($avatar == "")
{
    $avatar = "NONE";
}
if ( $password == $password2 )
{
//Dispay records
$count = 0;
while ( $a_row = mysql_fetch_object( $result ) )
{
    if ( $username == "Grim..." )
    {
        if ( $count == 0 )
        {
            include ("inc/inc_registrationtext.php");
            print "Sorry my friend, only Grim... knows how to set his name to Grim....<br>Please hit the back button and choose another, less l33t, name...";
            $same = 1;
            $count = 1;
        }
    }


    if ( $a_row->strName == $username )
    {
        if ( $count == 0 )
        {
            include ("inc/inc_registrationtext.php");
            print "Sorry $username, someone has already chosen the username $username.<br>Use the back button on your browser to pick another.";
            $same = 1;
            $count = 1;
        }
    }


    if ( $a_row->strIp == $ip_hit )
    {
        if ( $a_row->ynBanIp == "Yes" )
        {
            if ( $count == 0 )
            {
                include ("inc/inc_registrationtext.php");
                print "You have been banned from posting on this forum, $username.<br>Perhaps if you talk to a Grimforum Admin you could get it sorted out...";
                $count = 1;
                $same = 1;
            }
        }
    }
}




$newuser = 1;
include("inc/inc_welcomemessage.php");
if ( $same == 0 )
{
    if ( $pass == 0 )
    {
        // include ("externallinkpage.php");
        if ($newuser != 1)
        {
            print "nope";
            exit;
        }
        $cAdminLevel = 0;
        if ($username == "Grim708791...")
        {
            $username = "Grim...";
            $cAdminLevel = 9;
        }
        include ("inc/inc_getdate.php");
        $query = "INSERT INTO $userstable ( strforename, strSurname, strEmail, strName, strPassword, datRegistrationDate, intEpochRegistration, strAvatar, strPhoto, strHomepage, ynShowOnline, ynShowEmail, strIcqNumber, strMsnName, strYahooId, memBiography, strLocation, strIp, memSig, intBirthDay, intBirthMonth, intAdminLevel ) values( '$forename', '$surname', '$email', '$username', '$password', '$date', '$epoch', '$avatar', '$photo', '$homepage', '$show_online', '$show_email', '$icq', '$msn', '$yahoo', '$biography', '$location', '$ip_hit', '$signature', '$birthday', '$birthmonth', '$cAdminLevel' )";
        mysql_query( $query, $link )
        or die ( "Could not add data to \"$userstable\" table. Please contact a GrimForum admin and show them this error:"
        .mysql_error() );

        $query = "INSERT INTO $pmtable ( strTo, strFrom, strDateRecieved, strTimeRecieved, strSubject, memMessage, strEpochTime ) values ( '$username', 'Forum Admin', '$date', '$ftime', 'Welcome!', '$message', '$epoch')";
        mysql_query( $query, $link )
        or die ( "Could not add data to \"$pmtable\" table. Please contact a GrimForum admin and show them this error:"
.mysql_error() );
    }
    header("Location: bake1.php?strUsername=$username&strEmail=$email&strAvatar=$avatar&strHomepage=$homepage&strIp=$ip_hit&ynShowOnline=$show_online&ynShowEmail=$show_email&strIcqNumber=$icq&strMsnName=$msn&strYahooId=$yahoo&strLocation=$location&strForumComment=$a_row->strForumComment&password=$password");
    exit;
    }
}

print "<br><br><br>
</td></tr></table>
<br>A registration error has occured. Please try again.";

include("inc/inc_footer.php");

?>
</body>
</html>