<?php
class Timer {
var $startTime;
var $endTime;
function start() {
$this->startTime = gettimeofday();
}
function stop() {
$this->endTime = gettimeofday();
}
function elapsed() {
return (($this->endTime["sec"] - $this->startTime["sec"]) * 1000000 + ($this->endTime["usec"] - $this->startTime["usec"])) / 1000000;
}
}
$timer = new Timer();
$timer->start();
session_start();
include("settings-data.php");
include("lib.php");
include("users-data.php");
session_register("error");
session_register("style");
session_register("userLogin");
session_register("userId");
session_register("userMail");
session_register("userPassword");
session_register("confirmUserPassword");
session_register("url");
session_register("icq");
session_register("country");
session_register("city");
session_register("day");
session_register("month");
session_register("year");
$error = "";
$style = "";
if (!isset($user))
$user = array();
if (!isset($userLogin))
$userLogin = "";
if (!isset($userMail))
$userMail = "";
if (!isset($userPassword))
$userPassword = "";
if (!isset($confirmUserPassword))
$confirmUserPassword = "";
if (!isset($url))
$year = "";
if (!isset($icq))
$icq = "";
if (!isset($city))
$city = "";
if (!isset($year))
$year = "";
$userLogin = translateHtml($userLogin, false);
$userMail = translateHtml($userMail, false);
$city = translateHtml($city, false);
$url = translateHtml($url, false);
$userLogin = convertName($userLogin);
if ($userLogin == "")
{
$error .= "User name is empty<br/>";
$style .= "\n.userLogin {\n\tcolor : ".$constant['error-color']."\n}\n";
}
else if (strlen($userLogin) > 30)
{
$error .= "User name is long.<br/>";
$style .= "\n.userLogin {\n\tcolor : ".$constant['error-color']."\n}\n";
}
else
{
foreach($user as $v1)
{
foreach ($v1 as $v2)
{
if (toLower($userLogin) == toLower($v2))
{
$error .= "User name already registered.<br/>";
$style .= "\n.userLogin {\n\tcolor : ".$constant['error-color']."\n}\n";
break 2;
}
}
}
}
if ($userMail == "")
{
$error .= "User mail is empty<br/>";
$style .= "\n.usermail {\n\tcolor : ".$constant['error-color']."\n}\n";
}
else if (strlen($userMail) > 128)
{
$error .= "User mail is long.<br/>";
$style .= "\n.usermail {\n\tcolor : ".$constant['error-color']."\n}\n";
}
else if (!validEmail($userMail))
{
$error .= "Wrong e-mail<br/>";
$style .= "\n.usermail {\n\tcolor : ".$constant['error-color']."\n}\n";
}
if ($url != "" && $url != "http://")
{
$url_status = @check_url($url);
if (!$url_status)
{
$error .= "Wrong or inaccessible url<br/>";
$style .= "\n.url {\n\tcolor : ".$constant['error-color']."\n}\n";
}
else if ($url_status == "DNS")
{
$error .= "Inaccessible url<br/>";
$style .= "\n.url {\n\tcolor : ".$constant['error-color']."\n}\n";
}
}
$passwordLength = strlen($userPassword);
if ($passwordLength < 4)
{
$error .= "'New user password' is short<br>";
$style .= "\n.userpassword {\n\tcolor : ".$constant['error-color']."\n}\n";
}
if ($userPassword != $confirmUserPassword)
{
$error .= "'New user password' and 'confirm password' different<br>";
$style .= "\n.userpassword {\n\tcolor : ".$constant['error-color']."\n}\n";
}
if ($passwordLength > 3 && $userPassword == $confirmUserPassword)
{
$newUserPassword = md5($userPassword);
}
if ($day != "")
{
if(!isInteger($day))
{
$error .= "'Day' must have only number<br>";
$style .= "\n.birthday {\n\tcolor : ".$constant['error-color']."\n}\n";
}
}
if ($year != "")
{
if(!isInteger($year))
{
$error .= "'Year' must have only number<br>";
$style .= "\n.birthday {\n\tcolor : ".$constant['error-color']."\n}\n";
}
}
if ($icq != "")
{
if(!isInteger($icq))
{
$error .= "'Icq' must contain only number<br>";
$style .= "\n.icq {\n\tcolor : ".$constant['error-color']."\n}\n";
}
if(strlen($icq) < 5)
{
$error .= "'Icq' is too short. Minimum length is 5 digit";
$style .= "\n.icq {\n\tcolor : ".$constant['error-color']."\n}\n";
}
}
if ($error != "")
{
Header("Location: user-registration.php?user");exit;
}
setUserCookie(stripslashes($userLogin), "cookie[name]");
setUserCookie(stripslashes($userMail), "cookie[mail]");
setUserCookie(stripslashes($url), "cookie[url]");
setUserCookie(stripslashes($icq), "cookie[icq]");
$newUserList = "<?php\n";
$contentCnt = sizeof($user);
for($i = 0; $i < $contentCnt; $i++)
{
while(list($key, $value) = each($user[$i]))
{
$newUserList .= "\t\$user[".$i."]['".$key."'] = \"".$value."\";\n";
}
if ($i != $contentCnt)
$newUserList .= "\n";
}
$currIdx = $contentCnt;
$newUserList .= "\t\$user[".$currIdx."]['name'] = \"".$userLogin."\";\n";
$newUserList .= "\t\$user[".$currIdx."]['mail'] = \"".$userMail."\";\n";
$newUserList .= "\t\$user[".$currIdx."]['password'] = \"".$newUserPassword."\";\n";
$newUserList .= "\t\$user[".$currIdx."]['url'] = \"".$url."\";\n";
$newUserList .= "\t\$user[".$currIdx."]['icq'] = \"".$icq."\";\n";
$newUserList .= "\t\$user[".$currIdx."]['country'] = \"".$country."\";\n";
$newUserList .= "\t\$user[".$currIdx."]['city'] = \"".$city."\";\n";
$newUserList .= "\t\$user[".$currIdx."]['day'] = \"".$day."\";\n";
$newUserList .= "\t\$user[".$currIdx."]['month'] = \"".$month."\";\n";
$newUserList .= "\t\$user[".$currIdx."]['year'] = \"".$year."\";\n";
$newUserList .= "\t\$user[".$currIdx."]['time'] = \"".time()."\";\n";
$newUserList .= "\t\$user[".$currIdx."]['status'] = \"1\";\n";
$newUserList .= "?>";
reWriteDataInFile ($newUserList,"users-data.php");
$userPassword = $newUserPassword;
$userId = 0;
session_unregister("error");
session_unregister("style");
session_unregister("userMail");
session_unregister("url");
session_unregister("icq");
session_unregister("country");
session_unregister("city");
session_unregister("day");
session_unregister("month");
session_unregister("year");
$timer->stop();
Header("Location: user-registration.php?registered=true&".$timer->elapsed());exit;
?>