<?

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");

$us=$row["user"];  

if(!isset($go)){
if ($ver=="wml"){
echo $xml;
echo $dtd;
echo "<wml>\n";
echo "<head><meta http-equiv=\"Cache-Control\" content=\"no-cache\" forua=\"true\"/></head>\n";
echo "<card id=\"change\" title=\"Настройки\">\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=\"Content-Type\" content=\"text/html; charset=utf-8\"/></head><body>";
echo "<div align=\"left\">";
echo "<form method=\"POST\" action=\"change.php?$ses&amp;go=rew&amp;ref=$ref\" name=\"auth\">\n";
}
echo $fsize1;
echo "Время автообновления(сек):<br/>\n";
echo $fsize2;
echo "<select name=\"avr\">\n";
if($row["avr"] === "100")
{
echo "<option value=\"100\">10</option>\n";
}
elseif($row["avr"] === "150")
{
echo "<option value=\"150\">15</option>\n";
}
elseif($row["avr"] === "200")
{
echo "<option value=\"200\">20</option>\n";
}
elseif($row["avr"] === "250")
{
echo "<option value=\"250\">25</option>\n";
}
elseif($row["avr"] === "300")
{
echo "<option value=\"300\">30</option>\n";
}
elseif($row["avr"] === 0) echo "<option value=\"0\">Отключить</option>\n";
echo "<option value=\"0\">Отключить</option>\n";
echo "<option value=\"100\">10</option>\n";
echo "<option value=\"150\">15</option>\n";
echo "<option value=\"200\">20</option>\n";
echo "<option value=\"250\">25</option>\n";
echo "<option value=\"300\">30</option>\n";
echo "</select><br/>\n";
echo $fsize1;
echo "Кол-во сообшений:<br/>\n";
echo $fsize2;
echo "<select name=\"max\">\n";
if($row["max"] === "5")
{
echo "<option value=\"5\">5</option>\n";
}
elseif($row["max"] === "8")
{
echo "<option value=\"8\">8</option>\n";
}
elseif($row["max"] === "10")
{
echo "<option value=\"10\">10</option>\n";
}
elseif($row["max"] === "12")
{
echo "<option value=\"12\">12</option>\n";
}
elseif($row["max"] === "15")
{
echo "<option value=\"15\">15</option>\n";
}
elseif($row["max"] === "20")
{
echo "<option value=\"20\">20</option>\n";
}
elseif($row["max"] === "25")
{
echo "<option value=\"25\">25</option>\n";
}
elseif($row["max"] === "30")
{
echo "<option value=\"30\">30</option>\n";
}
echo "<option value=\"5\">5</option>\n";
echo "<option value=\"8\">8</option>\n";
echo "<option value=\"10\">10</option>\n";
echo "<option value=\"12\">12</option>\n";
echo "<option value=\"15\">15</option>\n";
echo "<option value=\"20\">20</option>\n";
echo "<option value=\"25\">25</option>\n";
echo "<option value=\"30\">30</option>\n";
echo "</select><br/>\n";
if($row["posts"] >= "10000") {
echo $fsize1;
echo "<u>Статус:</u><br/>\n"; 
echo $fsize2;
echo "<input name=\"status\" value=\"$row[status]\" title=\"status\"/><br/>\n";
}
if($row["posts"] >= "25000") {
echo $fsize1;
echo "<u>Невидимость:</u><br/>\n"; 
echo $fsize2;
echo "<select name=\"invis\">\n";
if ($row["inv"] == 0)echo "<option value=\"0\">Отключена</option>\n";
elseif ($row["inv"] == 1)echo "<option value=\"1\">Включена</option>\n";
if ($row["inv"]!=0) echo "<option value=\"0\">Отключена</option>\n";
if ($row["inv"]!=1) echo "<option value=\"1\">Включена</option>\n";
echo "</select><br/>\n";
}
echo $fsize1;
echo "По умолчанию сказать:<br/>\n";
echo $fsize2;
echo "<select name=\"say\">\n";
if ($row["say"]==1){
echo "<option value=\"1\">Приватно</option>\n";
echo "<option value=\"0\">Всем</option>\n";
} else {
echo "<option value=\"0\">Всем</option>\n";
echo "<option value=\"1\">Приватно</option>\n";
}
echo "</select><br/>\n"; 
echo $fsize1;
echo "Транслит:<br/>\n";
echo $fsize2;
echo "<select name=\"trun\">\n";
if($row["translit"] == 0){
echo "<option value=\"0\">Отключен</option>\n";
echo "<option value=\"1\">Включен</option>\n";
} else {
echo "<option value=\"1\">Включен</option>\n";
echo "<option value=\"0\">Отключен</option>\n";
}
echo "</select><br/>\n";
echo $fsize1;
echo "Смайлы:<br/>\n";
echo $fsize2;
echo "<select name=\"smls\">\n";
if ($row["smiles"]==0){
echo "<option value=\"0\">Отключены</option>\n";
echo "<option value=\"1\">Статичные</option>\n";  
echo "<option value=\"2\">Все смайлы</option>\n";
}else if ($row["smiles"]==1){     
echo "<option value=\"1\">Статичные</option>\n";
echo "<option value=\"0\">Отключены</option>\n";  
echo "<option value=\"2\">Все смайлы</option>\n";
}else{                  
echo "<option value=\"2\">Все смайлы</option>\n";
echo "<option value=\"0\">Отключены</option>\n"; 
echo "<option value=\"1\">Статичные</option>\n"; 
}
echo "</select><br/>\n"; 
echo $fsize1;
echo "Уведомление о безопасности:<br/>\n";
echo $fsize2;
echo "<select name=\"safe\">\n";    
if ($row["safe"]==1){    
echo "<option value=\"1\">Включено</option>\n";
echo "<option value=\"0\">Отключено</option>\n";  
}else{    
echo "<option value=\"0\">Отключено</option>\n";
echo "<option value=\"1\">Включено</option>\n";
}
echo "</select><br/>\n";
echo $fsize1;
echo "Размер шрифта:<br/>\n";
echo $fsize2;
echo "<select name=\"fsize\">\n";
if ($row["fsize"]=="verysmall"){
echo "<option value=\"verysmall\">Очень мелкий</option>\n";
echo "<option value=\"small\">Мелкий</option>\n";
echo "<option value=\"medium\">Нормальный</option>\n";  
echo "<option value=\"big\">Большой</option>\n";
}else if ($row["fsize"]=="small"){
echo "<option value=\"small\">Мелкий</option>\n";
echo "<option value=\"medium\">Нормальный</option>\n";  
echo "<option value=\"big\">Большой</option>\n";
echo "<option value=\"verysmall\">Очень мелкий</option>\n";
}else if ($row["fsize"]=="medium"){     
echo "<option value=\"medium\">Нормальный</option>\n";  
echo "<option value=\"big\">Большой</option>\n";
echo "<option value=\"small\">Мелкий</option>\n";
echo "<option value=\"verysmall\">Очень мелкий</option>\n";
}else if ($row["fsize"]=="big"){                  
echo "<option value=\"big\">Большой</option>\n";
echo "<option value=\"medium\">Нормальный</option>\n";
echo "<option value=\"small\">Мелкий</option>\n"; 
echo "<option value=\"verysmall\">Очень мелкий</option>\n";
}
echo "</select><br/>\n";
echo $fsize1;
echo "Сокращённая анкета:<br/>\n";
echo $fsize2;
echo "<select name=\"anketa\">\n";
if($row["anketa"] === "1"){
echo "<option value=\"1\">Включена</option>\n";
echo "<option value=\"0\">Отключена</option>\n";
} else {
echo "<option value=\"0\">Отключена</option>\n";
echo "<option value=\"1\">Включена</option>\n";
}
echo "</select><br/>\n";
if ($ver=="wml"){
echo $fsize1;
echo "<anchor title=\"go\">Обновить<go href=\"change.php?$ses&amp;go=rew&amp;ref=$ref\" method=\"post\">\n";
echo "<postfield name=\"avr\" value=\"$(avr)\"/>\n";
echo "<postfield name=\"max\" value=\"$(max)\"/>\n";
echo "<postfield name=\"say\" value=\"$(say)\"/>\n";
echo "<postfield name=\"trun\" value=\"$(trun)\"/>\n"; 
echo "<postfield name=\"smls\" value=\"$(smls)\"/>\n";  
echo "<postfield name=\"safe\" value=\"$(safe)\"/>\n";
echo "<postfield name=\"fsize\" value=\"$(fsize)\"/>\n";
echo "<postfield name=\"anketa\" value=\"$(anketa)\"/>\n";
if($row["posts"] >= "10000") {
echo "<postfield name=\"status\" value=\"$(status)\"/>\n";
}
if($row["posts"] >= "25000") {
echo "<postfield name=\"invis\" value=\"$(invis)\"/>\n";
}
echo "</go></anchor>\n";
echo $fsize2;
}else{
echo "<input type=\"submit\" value=\"Обновить\" name=\"enter\"><br/>\n";
}
echo $fsize1;
echo "<br/>\n";
echo $divide;
echo "<a href=\"enter.php?id=$id&amp;ps=$ps&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;
}

if($row["posts"] < "10000") $status=$row["status"];
if($row["posts"] < "25000") $invis=$row["inv"];
if($invis >= "2") $invis="0";

$emp="Неправильный формат данных!";
if(!preg_match("!^[0-9]+$!i",$avr)){$error = $emp;}
elseif(!preg_match("!^[0-9]+$!i",$max)){$error = $emp;}
elseif(!preg_match("!^[0-9]+$!i",$say)){$error = $emp;}
elseif(!preg_match("!^[0-9]+$!i",$trun)){$error = $emp;}
elseif(!preg_match("!^[0-9]+$!i",$smls)){$error = $emp;}
elseif(!preg_match("!^[0-9]+$!i",$safe)){$error = $emp;}
elseif(!preg_match("!^[0-9]+$!i",$anketa)){$error = $emp;}
elseif(!preg_match("!^[0-9]+$!i",$invis)){$error = $emp;}
$status = check($status);
$fsize = check($fsize);

if (!isset($error)) {
$result = mysql_query ("Select * users where id = '".$id."'");
if (mysql_affected_rows() == 0){
$error = "database error...";
}else{
$ins_str = "Update users set avr='".$avr."', max='".$max."', say='".$say."', inv='".$invis."', status='".$status."', translit='".$trun."', smiles='".$smls."', safe='".$safe."', fsize='".$fsize."', anketa='".$anketa."' where id ='".$id."'";
}
if (mysql_query ($ins_str)) {
$msg = "Ваши настройки изменены";
}else{
$error = " ".mysql_error()." ";
}
}
mysql_close($link);

if (isset($error)) {
if ($ver=="wml"){
echo $xml;
echo $dtd;
echo "<wml>\n";
echo "<card id=\"error\" title=\"Ошибка\" ontimer=\"change.php?$ses&amp;ref=$ref\"><timer value=\"10\"/>\n";
echo "<do type=\"prev\" label=\"Back\"><prev/></do>\n";
echo "<p align=\"center\">";
}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=change.php?$ses&amp;ref=$ref\">";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/></head><body>";
echo "<div align=\"center\">";
}
echo $fsize1;
echo "<b>$error</b>\n";
echo $fsize2;
if ($ver=="wml")echo "</p></card></wml>\n";
else echo "</div></body></html>\n";
exit;
} 
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=\"10\"/>\n";
echo "<p align=\"center\">";
}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=\"center\">";
}
echo $fsize1;
echo "<b>$msg</b><br/>\n";
echo $fsize2;
if ($ver=="wml")echo "</p></card></wml>\n";
else echo "</div></body></html>\n";
?>
