<?

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=\"emo\" 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 action=\"emo.php?$ses&amp;go=rew&amp;ref=$ref\" method=\"post\" title=\"Сказать\">\n";
}
echo $fsize1;
echo "<b>Дополнительные настройки:</b><br/>";
echo $divide;
echo "<b>Автоответчик для писем:</b><br/>";
echo $fsize2;
echo "<input name=\"avtootvet\" maxlength=\"100\" value=\"".$row["avtootvet"]."\"/><br/>";
echo $fsize1;
echo $divide;
echo "<b>Эмоции:</b><br/>";
echo $fsize2;
echo "<select name=\"selemoc\">";
if($row["selemoc"]=="1") {
echo"<option value=\"1\">Включены</option>"; 
echo"<option value=\"0\">Выключены</option>"; 
}else{ 
echo"<option value=\"0\">Выключены</option>"; 
echo"<option value=\"1\">Включены</option>"; 
}
echo "</select><br/>";
echo $fsize1;
echo "<b>Личные эмоции:</b><br/>";
echo $divide;
echo $fsize2;
echo "<select name=\"emocmenu\">";
if($row["emocmenu"]=="1") {
echo"<option value=\"1\">Да</option>"; 
echo"<option value=\"0\">Нет</option>"; 
}else{ 
echo"<option value=\"0\">Нет</option>"; 
echo"<option value=\"1\">Да</option>"; 
}
echo "</select><br/>";
echo $fsize1;
echo "Личные эмоции:<br/>";
echo $fsize2;
for($i = 1; $i <= 10; $i++) {
$emoc = "emoc".$i;
$emocname = $row["emoc".$i];
echo $fsize1;
echo $i.")\n";
echo $fsize2;
echo "<input name=\"$emoc\" maxlength=\"12\" value=\"$emocname\"/><br/>";
}
echo $fsize1;
echo $divide;
echo $fsize2;
if ($ver=="wml"){
echo $fsize1;
echo "<anchor title=\"go\">Сохранить<go href=\"emo.php?$ses&amp;go=rew&amp;ref=$ref\" method=\"post\">\n";
echo "<postfield name=\"avtootvet\" value=\"$(avtootvet)\"/>\n";
echo "<postfield name=\"selemoc\" value=\"$(selemoc)\"/>\n";
echo "<postfield name=\"emocmenu\" value=\"$(emocmenu)\"/>\n";
echo "<postfield name=\"emoc1\" value=\"$(emoc1)\"/>\n";
echo "<postfield name=\"emoc2\" value=\"$(emoc2)\"/>\n";
echo "<postfield name=\"emoc3\" value=\"$(emoc3)\"/>\n";
echo "<postfield name=\"emoc4\" value=\"$(emoc4)\"/>\n";
echo "<postfield name=\"emoc5\" value=\"$(emoc5)\"/>\n";
echo "<postfield name=\"emoc6\" value=\"$(emoc6)\"/>\n";
echo "<postfield name=\"emoc7\" value=\"$(emoc7)\"/>\n";
echo "<postfield name=\"emoc8\" value=\"$(emoc8)\"/>\n";
echo "<postfield name=\"emoc9\" value=\"$(emoc9)\"/>\n";
echo "<postfield name=\"emoc10\" value=\"$(emoc10)\"/>\n";
echo "</go></anchor>\n";
echo $fsize2;
echo "<br/>\n";
}else{
echo "<input type=submit value=\"Сохранить\"/></form>\n";
}
echo $fsize1;
echo $divide;
echo "<a href=\"cabinet.php?$ses&amp;ref=$ref\">&#8592; Личный кабинет</a><br/>\n";
echo "<a href=\"enter.php?$ses&amp;ref=$ref\">&#8592; Прихожая</a>\n";
echo $fsize2;
if ($ver=="wml")echo "</p></card></wml>\n";
else echo "</div></body></html>\n";
mysql_close ($link);
exit;
}

         if ($row["translit"]==1){ 
         $emoc1 = trun_to_rus($emoc1);     
         $emoc2 = trun_to_rus($emoc2);     
         $emoc3 = trun_to_rus($emoc3);     
         $emoc4 = trun_to_rus($emoc4);     
         $emoc5 = trun_to_rus($emoc5);     
         $emoc6 = trun_to_rus($emoc6);
		 $emoc7 = trun_to_rus($emoc7);     
         $emoc8 = trun_to_rus($emoc8);               
         $emoc9 = trun_to_rus($emoc9);     
         $emoc10 = trun_to_rus($emoc10);
         }
         
		 
		 $avtootvet = check($avtootvet);
		 $avtootvet = substr($avtootvet,0,100);
		 $emoc1 = check($emoc1);     
         $emoc2 = check($emoc2);     
         $emoc3 = check($emoc3);     
         $emoc4 = check($emoc4);     
         $emoc5 = check($emoc5);     
         $emoc6 = check($emoc6);
		 $emoc7 = check($emoc7);     
         $emoc8 = check($emoc8);               
         $emoc9 = check($emoc9);     
         $emoc10 = check($emoc10);     

$emp="Неправильный формат данных!";
if(!preg_match("!^[0-9]+$!i",$emocmenu)){$error = $emp;}
elseif(!preg_match("!^[0-9]+$!i",$selemoc)){$error = $emp;}

if (!isset($error)) {
if (mysql_query ("Update users set avtootvet = '".$avtootvet."', selemoc = '".$selemoc."', emocmenu = '".$emocmenu."', emoc1 = '".$emoc1."', emoc2 = '".$emoc2."', emoc3 = '".$emoc3."', emoc4 = '".$emoc4."', emoc5 = '".$emoc5."', emoc6 = '".$emoc6."', emoc7 = '".$emoc7."', emoc8 = '".$emoc8."', emoc9 = '".$emoc9."', emoc10 = '".$emoc10."' where id ='".$id."'")){
$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=\"error\" ontimer=\"emo.php?$ses&amp;ref=$ref\"><timer value=\"10\"/>\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=emo.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=\"cabinet.php?$ses&amp;ref=$ref\"><timer value=\"10\"/>\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=cabinet.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 "$msg\n";
echo $fsize2;
if ($ver=="wml")echo "</p></card></wml>\n";
else echo "</div></body></html>\n";
?>