<?

header('Cache-Control: no-store, no-cache, must-revalidate');
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");

$user=$row["user"];
$level=$row["level"];

if ($ver=="wml"){
echo $xml;
echo $dtd;
echo "<wml>\n";
echo "<card title=\"Фотогалерея!\">\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>";
}

switch($mod) {

default:
if ($ver=="wml")echo "<p align=\"center\">\n";
else echo "<div align=\"center\">\n";
echo $fsize1;
echo "Фото Юзеров чата!<br/>";
echo $divide;
echo "В галерее оцениваются только ЛИЧНЫЕ фото.<br/>";
echo "Все иные картинки и аватары на усмотрение Администрации будут удалены.<br/>";
echo $divide;

$galery = mysql_query ("select count(id) as num from users where img!=''");
$foto = mysql_fetch_array($galery);
$kolfoto = $foto["num"];
echo "Всего фоток Юзеров: <b>".$kolfoto."</b><br/>";
echo $divide; 

$galerym = mysql_query ("select count(id) as num from users where img!='' and sex ='М'");
$fotomr = mysql_fetch_array($galerym);
$fotom = $fotomr["num"];
echo "Парни: <b><a href=\"galery.php?mod=m&amp;$ses&amp;ref=$ref\">".$fotom."</a></b><br/>";

echo $divide; 
$galeryz = mysql_query ("select count(id) as num from users where img!='' and sex ='Ж'");
$fotozr = mysql_fetch_array($galeryz);
$fotoz = $fotozr["num"];
echo "Девушки: <b><a href=\"galery.php?mod=zh&amp;$ses&amp;ref=$ref\">".$fotoz."</a></b><br/>";

echo $fsize2;
break;

case 'm':
if ($ver=="wml")echo "<p align=\"left\">\n";
else echo "<div align=\"left\">\n";
echo $fsize1;
echo "<b>Фото Парней чата!</b><br/>";
echo $divide; 
echo $fsize2;
$galery = mysql_query ("select count(id) as num from users where img!='' and sex ='М';");
$foto = mysql_fetch_array($galery);
$num = $foto["num"]; 
if ($num == 0){
echo $fsize1;
echo "Нет фото парней в галерее.<br/>";
echo $fsize2;
mysql_close($link);
}else{
if(!isset($s))$s=0;
$mx=round(($num/10)+0.45);
if($s>$mx)$s=$mx;
if($s==0)$s=1;
$ot=(($s-1)*10)+1;
$do=$s*10;
if($do>$num)$do=$num;
$o=$ot-1;
$n=$ot;
if($do==0)$n=$o;
echo $fsize1;
echo "Показывает $n-$do из $num<br/>\n";
echo $divide;
echo $fsize2;
$r = mysql_query ("select id,user,img,votefoto from `users` where img!='' and sex ='М' order by votefoto desc limit $o,$do");
for ($i=$ot;$i<=$do;$i++){
$arr = mysql_fetch_array($r);
echo $fsize1;
$login=$arr['user'];
$usid=$arr['id'];
$img=$arr['img'];
if ($id==$usid){
echo ($i).") <a href=\"userfoto.php?usid=$usid&amp;$ses&amp;ref=$ref\"><img src=\"scr.php?photos/$img\" alt=\"Фото\"/></a><b><a href=\"info.php?$ses&amp;nk=$usid&amp;ref=$ref\">".$login."</a></b>| Голосов: ".$arr['votefoto']."<br/>"; 
}else{
echo ($i).") <a href=\"userfoto.php?usid=$usid&amp;$ses&amp;ref=$ref\"><img src=\"scr.php?photos/$img\" alt=\"Фото\"/></a><a href=\"info.php?$ses&amp;nk=$usid&amp;ref=$ref\">".$login."</a>| Голосов: ".$arr['votefoto']."<br/>"; 
}
echo $fsize2;
if ($id!=$usid){
echo $fsize1;
echo "<a href=\"galery.php?mod=votes&amp;$ses&amp;nk=$usid&amp;ref=$ref\">Голосовать!</a>";
echo $fsize2; 
echo "<br/>"; 
if($level>6){
echo $fsize1;
echo "<b><a href=\"galery.php?mod=delfoto&amp;$ses&amp;nk=$usid&amp;ref=$ref\">Удалить фото</a></b><br/>";
echo $fsize2;
echo "<br/>";
}
}else{
echo $fsize1;
echo "<a href=\"cabinet.php?go=golos&amp;$ses&amp;ref=$ref\">Кто голосовал за Вас?</a><br/>";
echo $fsize2; 
}
echo $fsize1;
echo $divide; 
echo $fsize2;
}                                               
mysql_close($link);
$next=$s+1;
$prev=$s-1;
if ($num>$do) {
$ot=(($next-1)*10)+1;
$do=$next*10;
if($do>$num)$do=$num;
echo $fsize1;
echo "<a href=\"galery.php?mod=m&amp;$ses&amp;s=$next&amp;ref=$ref\">&gt;&gt;$ot-$do&gt;&gt;</a><br/>\n";
echo $fsize2;
}
if($s>1) {
$ot=(($prev-1)*10)+1;
$do=$prev*10;
echo $fsize1;
echo "<a href=\"galery.php?mod=m&amp;$ses&amp;s=$prev&amp;ref=$ref\">&lt;&lt;$ot-$do&lt;&lt;</a><br/>\n";
echo $fsize2;
}
}
break;

case 'zh':
if ($ver=="wml")echo "<p align=\"left\">\n";
else echo "<div align=\"left\">\n";
echo $fsize1;
echo "<b>Фото Девушек чата!</b><br/>";
echo $divide; 
echo $fsize2;
$galery = mysql_query ("select count(id) as num from users where img!='' and sex ='Ж';");
$foto = mysql_fetch_array($galery);
$num = $foto["num"]; 
if ($num == 0){
echo $fsize1;
echo "Нет фото девушек в галерее.<br/>";
echo $fsize2;
mysql_close($link);
}else{
if(!isset($s))$s=0;
$mx=round(($num/10)+0.45);
if($s>$mx)$s=$mx;
if($s==0)$s=1;
$ot=(($s-1)*10)+1;
$do=$s*10;
if($do>$num)$do=$num;
$o=$ot-1;
$n=$ot;
if($do==0)$n=$o;
echo $fsize1;
echo "Показывает $n-$do из $num<br/>\n";
echo $divide;
echo $fsize2;
$r = mysql_query ("select id,user,img,votefoto from `users` where img!='' and sex ='Ж' order by votefoto desc limit $o,$do");
for ($i=$ot;$i<=$do;$i++){
$arr = mysql_fetch_array($r);
echo $fsize1;
$login=$arr['user'];
$usid=$arr['id'];
$img=$arr['img'];
if ($id==$usid){
echo ($i).") <a href=\"userfoto.php?usid=$usid&amp;$ses&amp;ref=$ref\"><img src=\"scr.php?photos/$img\" alt=\"Фото\"/></a><b><a href=\"info.php?$ses&amp;nk=$usid&amp;ref=$ref\">".$login."</a></b>| Голосов: ".$arr['votefoto']."<br/>"; 
}else{
echo ($i).") <a href=\"userfoto.php?usid=$usid&amp;$ses&amp;ref=$ref\"><img src=\"scr.php?photos/$img\" alt=\"Фото\"/></a><a href=\"info.php?$ses&amp;nk=$usid&amp;ref=$ref\">".$login."</a>| Голосов: ".$arr['votefoto']."<br/>"; 
}
echo $fsize2;
if ($id!=$usid){
echo $fsize1;
echo "<a href=\"galery.php?mod=votes&amp;$ses&amp;nk=$usid&amp;ref=$ref\">Голосовать!</a>";
echo $fsize2; 
echo "<br/>"; 
if($level>6){
echo $fsize1;
echo "<b><a href=\"galery.php?mod=delfoto&amp;$ses&amp;nk=$usid&amp;ref=$ref\">Удалить фото</a></b><br/>";
echo $fsize2;
echo "<br/>";
}
}else{
echo $fsize1;
echo "<a href=\"cabinet.php?go=golos&amp;$ses&amp;ref=$ref\">Кто голосовал за Вас?</a><br/>";
echo $fsize2; 
}
echo $fsize1;
echo $divide; 
echo $fsize2;
}                                               
mysql_close($link);
$next=$s+1;
$prev=$s-1;
if ($num>$do) {
$ot=(($next-1)*10)+1;
$do=$next*10;
if($do>$num)$do=$num;
echo $fsize1;
echo "<a href=\"galery.php?mod=zh&amp;$ses&amp;s=$next&amp;ref=$ref\">&gt;&gt;$ot-$do&gt;&gt;</a><br/>\n";
echo $fsize2;
}
if($s>1) {
$ot=(($prev-1)*10)+1;
$do=$prev*10;
echo $fsize1;
echo "<a href=\"galery.php?mod=zh&amp;$ses&amp;s=$prev&amp;ref=$ref\">&lt;&lt;$ot-$do&lt;&lt;</a><br/>\n";
echo $fsize2;
}
}
break;

case 'votes':
if ($id==$nk){
if ($ver=="wml")echo "<p align=\"center\">\n";
else echo "<div align=\"center\">\n";
echo $fsize1; 
echo "За себя Вы не можете голосовать!<br/>";
print $fsize2;
}else{
mysql_query ("Select * from golos where user='".$nk."' and who='".$id."'");
if (mysql_affected_rows()!=0){
if ($ver=="wml")echo "<p align=\"center\">\n";
else echo "<div align=\"center\">\n";
echo $fsize1;
echo "Вы уже голосовали за это фото. Голос не принят.<br/>";
echo $fsize2;
} else {
$q = mysql_query("select user,votefoto from users where id='".$nk."';");
$data = mysql_fetch_array($q);
$counter = $data['votefoto'];
$login = $data['user'];
$counter2 = $counter+1;
mysql_query ("update users set votefoto='".$counter2."' where id='".$nk."';");
mysql_query ("INSERT INTO golos SET user = '".$nk."', who = '".$id."'"); 
if ($ver=="wml")echo "<p align=\"center\">\n";
else echo "<div align=\"center\">\n";
echo $fsize1;
echo "Ваш голос принят!<br/>";
echo $fsize2;
mysql_close ($link);
}
}
break;

case 'delfoto':
if ($ver=="wml")echo "<p align=\"center\">\n";
else echo "<div align=\"center\">\n";
if($level>6){
echo $fsize1; 
$s = @mysql_query ("Select img from users where id='".$nk."' LIMIT 1;");
$rr = @mysql_fetch_array ($s);
$myfotos = $rr["img"];
$ras=explode(".", $myfotos);
$types=$ras[1];
if (!file_exists("photos/".$nk.".".$types."")){
echo "У Вас не установлено фото!<br/>\n";
}else{
if (!ctype_digit($nk)) { header("Location: index.php"); die; }
if(@mysql_query ("Update users set img ='' where id ='".$nk."';")){
unlink ("photos/".$nk.".".$types."");
echo "Фото успешно удалено.<br/>";
} else {
print "Ошибка удаления фото.<br/>";
}
}
echo $fsize2;
}else{
echo $fsize1; 
echo "У Вас недостаточно прав доступа.<br/>";
echo $fsize2;
}
mysql_close ($link);
break;
}
echo $fsize1;
echo $divide;
if($mod) echo "<a href=\"galery.php?$ses&amp;ref=$ref\">&#8592; В Галерею</a><br/>\n";
if (isset ($rm))echo "<a href=\"chat.php?$ses&amp;rm=$rm\">&#8592; В чат</a><br/>\n"; 
echo "<a href=\"enter.php?$ses&amp;ref=$ref\">&#8592; Прихожая</a><br/>\n";
echo $fsize2;
if ($ver=="wml")echo "</p></card></wml>";
else echo "</div></body></html>";
?>