<?

header("Cache-Control: no-cache");
if ($ver=="wml")header ("Content-type:text/vnd.wap.wml; charset=utf-8");
else header("Content-Type:text/html; charset=UTF-8");

require("inc.php"); 
$link = connect_db();
list($row, $id, $ps, $fsize1, $fsize2) = check_login($link);
require("version.php");

if(!isset($err)) $err="";

if(!isset($go)){
if ($ver=="wml"){
echo $xml;
echo $dtd;
echo "<wml>";
echo "<card id=\"profile\" title=\"Анкета\">\n";
echo "<p align=\"left\">";
}else{
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">";
echo "<head><link rel=\"stylesheet\" type=\"text/css\" href=\"css/css.css\"/>";
echo "<title>Анкета</title>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/></head><body>";
echo "<div align=\"left\">";
echo "<form method=\"POST\" action=\"profile.php?$ses&amp;go=rew&amp;ref=$ref\" name=\"auth\">\n";
}
echo $fsize1;
echo "<b>$row[user]</b><br/>\n";
echo $divide;
echo "*Ваш пароль:<br/>\n";     
echo $fsize2;
echo "<input type=\"password\" name=\"pass\" maxlength=\"20\" value=\"$row[pass]\" title=\"pass\" emptyok=\"false\"/><br/>\n";
echo $fsize1;
echo "*Ваше имя:<br/>\n";     
echo $fsize2;
echo "<input name=\"name\" maxlength=\"15\" value=\"$row[name]\" title=\"name\" emptyok=\"false\"/><br/>\n";
if($row["sex"] === "М"){
echo $fsize1;
echo "Пол:<br/>\n";
echo $fsize2;
echo "<select name=\"sex\">\n";
echo "<option value=\"М\">М</option>\n";
echo "<option value=\"Ж\">Ж</option>\n";
echo "</select><br/>\n";
} else {
echo $fsize1;
echo "Пол:<br/>\n";
echo $fsize2;
echo "<select name=\"sex\">\n";
echo "<option value=\"Ж\">Ж</option>\n";
echo "<option value=\"М\">М</option>\n";
echo "</select><br/>\n"; 
}
@list( $day, $month, $year ) = split( '-', $row["birth"] );
echo $fsize1;
echo "*Дата рождения:<br/>\n";     
echo $fsize2;
echo "<input size=\"2\" name=\"day\" value=\"$day\" maxlength=\"2\" emptyok=\"false\"/>-"; 
echo "<input size=\"2\" name=\"month\" value=\"$month\" maxlength=\"2\" emptyok=\"false\"/>-"; 
echo "<input size=\"4\" name=\"year\" value=\"$year\" maxlength=\"4\" emptyok=\"false\"/><br/>\n"; 
echo $fsize1;
echo "*Город:<br/>\n";     
echo $fsize2;
echo "<input name=\"city\" maxlength=\"40\" value=\"$row[city]\" title=\"city\" emptyok=\"false\"/><br/>\n";
echo $fsize1;
echo "Сотовый оператор:<br/>\n";     
echo $fsize2;
echo "<input name=\"op\" maxlength=\"20\" value=\"$row[op]\" title=\"op\" emptyok=\"true\"/><br/>\n";
echo $fsize1;
echo "Модель телефона:<br/>\n";     
echo $fsize2;
echo "<input name=\"mob\" maxlength=\"40\" value=\"$row[mob]\" title=\"mob\" emptyok=\"true\"/><br/>\n";
echo $fsize1;
echo "Номер телефона:<br/>\n";     
echo "+\n"; 
echo $fsize2;
echo "<input name=\"number\" maxlength=\"12\" value=\"$row[number]\" format=\"*N\" title=\"number\" emptyok=\"true\"/><br/>\n";  
echo $fsize1;   
echo "E-mail:<br/>\n";     
echo $fsize2;
echo "<input name=\"mail\" maxlength=\"70\" value=\"$row[mail]\" title=\"mail\" emptyok=\"true\"/><br/>\n";
echo $fsize1;
echo "ICQ:<br/>\n";     
echo $fsize2;
echo "<input name=\"icq\" maxlength=\"11\" value=\"$row[icq]\" title=\"icq\" emptyok=\"true\"/><br/>\n";
echo $fsize1;
echo "*О себе:<br/>\n";     
echo $fsize2;
echo "<input name=\"infa\" maxlength=\"220\" value=\"$row[infa]\" title=\"infa\" emptyok=\"false\"/><br/>\n";  
echo $fsize1;
echo "Текст автоответчика(записки):<br/>\n";     
echo $fsize2;
echo "<input name=\"avtootvet\" maxlength=\"100\" value=\"$row[avtootvet]\" title=\"avtootvet\" emptyok=\"true\"/><br/>\n";  
echo $fsize1;
echo $divide;
echo $fsize2;
if ($ver=="wml"){
echo $fsize1;
echo "<anchor title=\"go\">Изменить<go href=\"profile.php?$ses&amp;go=rew&amp;ref=$ref\" method=\"post\">\n";
echo "<postfield name=\"pass\" value=\"$(pass)\"/>\n";
echo "<postfield name=\"name\" value=\"$(name)\"/>\n";
echo "<postfield name=\"sex\" value=\"$(sex)\"/>\n";
echo "<postfield name=\"day\" value=\"$(day)\"/>\n";
echo "<postfield name=\"month\" value=\"$(month)\"/>\n";
echo "<postfield name=\"year\" value=\"$(year)\"/>\n";
echo "<postfield name=\"op\" value=\"$(op)\"/>\n";
echo "<postfield name=\"mob\" value=\"$(mob)\"/>\n";
echo "<postfield name=\"number\" value=\"$(number)\"/>\n";
echo "<postfield name=\"mail\" value=\"$(mail)\"/>\n";
echo "<postfield name=\"city\" value=\"$(city)\"/>\n";
echo "<postfield name=\"icq\" value=\"$(icq)\"/>\n";
echo "<postfield name=\"infa\" value=\"$(infa)\"/>\n";
echo "<postfield name=\"avtootvet\" value=\"$(avtootvet)\"/>\n";
echo "</go></anchor>\n";
echo $fsize2;
echo "<br/>\n";
}else{
echo "<input type=\"submit\" value=\"Изменить\" name=\"enter\"><br/>\n";
}
echo $fsize1;
echo $divide;
echo "<a href=\"enter.php?$ses&amp;ref=$ref\">Прихожая</a>\n";
echo $fsize2;
if ($ver=="wml")echo "</p></card></wml>\n";
else echo "</div></body></html>\n";
mysql_close ($link);
exit;
}

$error = true;
if ($row["translit"]==1){ 
$name = trun_to_rus($name);
$city = trun_to_rus($city);
$infa = trun_to_rus($infa);
$avtootvet = trun_to_rus($avtootvet);
}

$emp2 = "Неправильный формат данных!";    
$emp = "Не заполнены обязательные поля!";              
$wrongdate = "Не верно указана дата рождения! 0на должна иметь формат дд-мм-гггг, и быть реальной =)";               
$god=date("Y")-10;

if ($pass == "") {$msg = "".$emp."";} 
elseif(!preg_match("!^[a-z0-9]+$!i",$pass)) {$msg = "Недопустимые символы в пароле!";} 
elseif ($name == "") {$msg = "".$emp."";} 
elseif ($day == "") {$msg = "".$emp."";} 
elseif ($month == "") {$msg = "".$emp."";} 
elseif (strlen($pass) < 4) {$msg = "Пароль не должен быть короче четырёх символов!";} 
elseif ((strlen($day) !== 2)||($day>31)){$msg = "".$wrongdate."";} 
elseif ((strlen($month) !== 2)||($month>12)){$msg = "".$wrongdate."";} 
elseif ((strlen($year) !== 4)||($year>=$god)||($year<1950)){$msg = "".$wrongdate."";} 
elseif ($year == "") {$msg = "".$emp."";} 
elseif ($city == "") {$msg = "".$emp."";} 
elseif ($infa == "") {$msg = "".$emp."";} 
else {
$pass = check($pass);     
$name = check($name);     
$day = check($day);     
$month = check($month);     
$year = check($year);     
$city = check($city);     
$mail = check($mail);                
$infa = check($infa);
$avtootvet = check($avtootvet); 
$icq = check($icq); 
$sex = check($sex);
$op = check($op);     
$mob = check($mob);  
$number=check($number);            
$infa=substr($infa,0,400);  
$avtootvet=substr($avtootvet,0,100); 
if(!eregi("^[a-z0-9\._-]+@[a-z0-9\._-]+\.[a-z]{2,4}\$", $mail))$mail="";            
if(!eregi("^((http://))((([a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z;]{2,3}))|(([0-9]{1,3}\.){3}([0-9]{1,3})))((/|\?)[a-z0-9~#%&'_\+=:;\?\.-]*)*)\$", $site))$site="";
if(!preg_match("!^[0-9]+$!i",$day)){$error = $emp2;} 
elseif(!preg_match("!^[0-9]+$!i",$month)){$error = $emp2;} 
elseif(!preg_match("!^[0-9]+$!i",$year)){$error = $emp2;}
if (mysql_query ("Update users set pass='".$pass."', name='".$name."', sex='".$sex."', birth='".$day."-".$month."-".$year."', city='".$city."', mail='".$mail."', icq='".$icq."', infa='".$infa."', op='".$op."', mob='".$mob."', number='".$number."', avtootvet='".$avtootvet."' where id ='".$id."'")) {
$msg = "Ваш профиль изменён";
$error = False;
} else {
$msg = "database error...";
}
mysql_close($link);
}
if ($error) {
if ($ver=="wml"){
echo $xml;
echo $dtd;
echo "<wml>\n";
echo "<card id=\"error\" title=\"Ошибка\" ontimer=\"profile.php?$ses&amp;ref=$ref\"><timer value=\"20\"/>\n";
echo "<do type=\"prev\" label=\"Back\"><prev/></do>\n";
echo "<p>\n";
}else{
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">";
echo "<head><link rel=\"stylesheet\" type=\"text/css\" href=\"css/css.css\"/>";
echo "<title>Ошибка</title>";
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2; URL=profile.php?$ses&amp;ref=$ref\">";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/></head><body>";
echo "<div align=\"left\">";
}
echo $fsize1;
echo "<b>$msg</b>\n";
echo $fsize2;
if ($ver=="wml")echo "</p></card></wml>\n";
else echo "</div></body></html>\n";
} else {
if ($ver=="wml"){
echo $xml;
echo $dtd;
echo "<wml>\n";
echo "<card id=\"ok\" title=\"OK\" ontimer=\"enter.php?$ses&amp;ref=$ref\"><timer value=\"20\"/>\n";
echo "<p>\n";
}else{
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">";
echo "<head><link rel=\"stylesheet\" type=\"text/css\" href=\"css/css.css\"/>";
echo "<title>Ок</title>";
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2; URL=enter.php?$ses&amp;ref=$ref\">";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/></head><body>";
echo "<div align=\"left\">";
}
echo $fsize1;
echo "<b>$msg</b><br/>\n";
echo $fsize2;
if ($ver=="wml")echo "</p></card></wml>\n";
else echo "</div></body></html>\n";
}
?>