<?php
include("settings-data.php");
include("lib.php");
session_start();
include("users-data.php");
$error = "";
$style = "";
if (!isset($id))
$id = "";
if (!isset($user[$id]))
{
session_destroy();
Header("Location: user-login.php");exit;
}
checkUserPermissions($userLogin, $userPassword);
if (!isset($icq))
$icq = "";
if (!isset($city))
$city = "";
if (!isset($year))
$year = "";
session_register("error");
session_register("style");
session_register("name");
session_register("email");
session_register("newPassword");
session_register("confirmPassword");
session_register("url");
session_register("icq");
session_register("country");
session_register("city");
session_register("day");
session_register("month");
session_register("year");
$name = strtolower(translateHtml($name, false));
$name = convertName($name);
$email = strtolower(translateHtml($email, false));
if ($name == "")
{
$error .= "Name is empty<br>";
$style .= "\n.name {\n\tcolor : ".$constant['error-color']."\n}\n";
}
else if (strlen($name) > 30)
{
$error .= "Name is long<br>";
$style .= "\n.name {\n\tcolor : ".$constant['error-color']."\n}\n";
}
else
{
foreach($user as $v1)
{
foreach ($v1 as $v2)
{
if ($name == $v2 && $v2 != $user[$id]['name'])
{
$error .= "User name already registered.<br/>";
$style .= "\n.name {\n\tcolor : ".$constant['error-color']."\n}\n";
break 2;
}
}
}
}
if ($email == "")
{
$error .= "e-mail is empty<br>";
$style .= "\n.email {\n\tcolor : ".$constant['error-color']."\n}\n";
}
else if (strlen($email) > 30)
{
$error .= "email is long<br>";
$style .= "\n.email {\n\tcolor : ".$constant['error-color']."\n}\n";
}
if (!validEmail($email))
{
$error .= "Wrong e-mail<br>";
$style .= "\n.email {\n\tcolor : ".$constant['error-color']."\n}\n";
}
if ($newPassword != "")
{
$newPassLen = strlen($newPassword);
if ($newPassLen < 4)
{
$error .= "'New password' is short<br>";
$style .= "\n.adminpassword {\n\tcolor : ".$constant['error-color']."\n}\n";
}
if ($newPassword != $confirmPassword)
{
$error .= "'New password' and 'Confirm password' different<br>";
$style .= "\n.adminpassword {\n\tcolor : ".$constant['error-color']."\n}\n";
}
if ($newPassLen > 3 && $newPassword == $confirmPassword)
{
session_register("userPassword");
$userPassword = md5($newPassword);
}
}
if ($day != "")
{
if(!isInteger($day))
{
$error .= "'Day' must contain only number<br>";
$style .= "\n.birthday {\n\tcolor : ".$constant['error-color']."\n}\n";
}
}
if ($month != "")
{
if(!isInteger($month))
{
$error .= "'Month' must contain only number<br>";
$style .= "\n.birthday {\n\tcolor : ".$constant['error-color']."\n}\n";
}
}
if ($year != "")
{
if(!isInteger($year))
{
$error .= "'Year' must contain 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";
}
else if(strlen($icq) > 9)
{
$error .= "'Icq' is too long. Maximum length is 9 digit";
$style .= "\n.icq {\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";
}
}
if ($error != "")
{
Header("Location: user-edit.php?id=".$id."&page=".$page);exit;
}
setUserCookie(stripslashes($name), "cookie[name]");
setUserCookie(stripslashes($email), "cookie[mail]");
setUserCookie(stripslashes($url), "cookie[url]");
setUserCookie(stripslashes($icq), "cookie[icq]");
$contentCnt = sizeof($user);
$user[$id]['name'] = $name;
$user[$id]['mail'] = $email;
$user[$id]['url'] = $url;
$user[$id]['icq'] = $icq;
$user[$id]['country'] = $country;
$user[$id]['city'] = $city;
$user[$id]['day'] = $day;
$user[$id]['month'] = $month;
$user[$id]['year'] = $year;
if ($newPassword != "")
{
$user[$id]['password'] = md5($newPassword);
$userPassword = $user[$id]['password'];
}
$userLogin = $user[$id]['name'];
$updateContent = "<?php\n";
for($i = 0; $i < $contentCnt; $i++)
{
while(list($key, $value) = each($user[$i]))
{
$updateContent .= "\t\$user[".$i."]['".$key."'] = \"".$value."\";\n";
}
if ($i != $contentCnt-1)
$updateContent .= "\n";
}
$updateContent .= "?>";
reWriteDataInFile ($updateContent, "users-data.php");
session_unregister("error");
session_unregister("style");
session_unregister("name");
session_unregister("email");
session_unregister("url");
session_unregister("icq");
session_unregister("country");
session_unregister("city");
session_unregister("day");
session_unregister("month");
session_unregister("year");
session_unregister("newPassword");
session_unregister("confirmPassword");
Header("Location: index.php?page=".$page);exit;
?>