<?php
include '../config.php';
include '../guestbook/mylib.php';
$ppp=20;
session_start();
$lang=$_GET['lang'];
$p=htmlspecialchars(trim($_GET['p']),ENT_QUOTES);
$cat=htmlspecialchars(trim($_GET['cat']),ENT_QUOTES);
$action=htmlspecialchars(trim($_GET['action']),ENT_QUOTES);
# if ($_POST['id']!=0) $id=$_POST['id'];
# else $id=$_GET['id'];
$id=htmlspecialchars(trim($_GET['id']),ENT_QUOTES);
$agent=$_SERVER['HTTP_USER_AGENT'];
$addr=$_SERVER['REMOTE_ADDR'];
list ($opname, $chatok) = check_op($_SERVER['REMOTE_ADDR']);
$dayx=date("Y-m-d", mktime(0,0,0,date("m"), date("d")-3, date("Y")));
$access=1;
$getpath='/sorry.wml';
?>
<?php
if (!($conn=pg_connect("host=$dbhost port=$dbport dbname=$dbname user=$dbuser password=$dbpass")))
{
header("Content-type: text/vnd.wap.wml");
?>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
<wml>
<card id="CatalogErr" title="Ошибка">
<p align="center">
Ошибка подключения к БД<br/>
<a href="/">На главную</a>
</p>
</card>
</wml>
<?php
exit;
}
if (($action=='')&&($id==0)) {
header("Content-type: text/vnd.wap.wml"); ?>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
<wml> <?php
print "<card id=\"Photos\" title=\"Photos\">\n";
print "<p align=\"center\">**************<br/>\n";
$offset=$p*$ppp;
$res=pg_query($conn,"select count(*) from photos,users where users.id=photos.uid and users.moder=0;");
$numrec=pg_result($res,0,0);
$res=pg_query($conn,"select photos.id,users.login from photos,users where users.id=photos.uid and users.moder=0 order by users.access desc,photos.dlcount desc limit $ppp offset $offset;");
$rows=pg_numrows($res);
$np=$p+1; $pp=$p-1; $mp=floor(($numrec-1)/$ppp);
for ($i=0;$i<$rows;$i++) {
$login=uconv(pg_result($res,$i,1));
$getpath=sprintf("photos.php?id=%d", pg_result($res,$i,0));
print "<a href=\"".$getpath."\">".$login."</a><br/>\n";
}
pg_close($conn);
print "*******<br/><br/>\n";
if ($lang=='eng') {
if ($numrec > $ppp) {
if ($p<$mp) print("<a href=\"photos.php?lang=eng&p=".$np."&cat=".$cat."\">Next ".$ppp."</a><br/>\n");
if ($p>0) print("<a href=\"photos.php?lang=eng&p=".$pp."&cat=".$cat."\">Prev ".$ppp."</a><br/>\n");
}
print "<a href=\"index.php\">Back</a><br/>\n";
} else {
if ($numrec > $ppp) {
if ($p<$mp) print("<a href=\"photos.php?p=".$np."&cat=".$cat."\">Следующие ".$ppp."</a><br/>\n");
if ($p>0) print("<a href=\"photos.php?p=".$pp."&cat=".$cat."\">Предыдущие ".$ppp."</a><br/>\n");
}
print "<a href=\"index.php\">Назад</a><br/>\n";
}
}
if (($action=='top')&&($cat==0)&&($id==0)) {
if ($access) setcookie("Sweetty", "21895", time()+864000, "/");
header("Content-type: text/vnd.wap.wml"); ?>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
<wml>
<card id="Top10" title="Top10">
<p align="center">
***********<br/>
<?php
$res=pg_query($conn,"select midi.id,midi.name_eng,midi.name_rus,midi.dlcount from midi,cat where midi.enabled=1 and midi.dlcount > 0 and midi.cat=cat.id and cat.content=2 order by midi.dlcount desc limit 10;");
$rows=pg_numrows($res);
for ($i=0; $i<$rows; $i++) {
$fname=uconv(pg_result($res,$i,2));
$pos=$i+1;
if (($lang=='eng')||($fname=='')) $fname=uconv(pg_result($res,$i,1));
if ($access) $getpath=sprintf("photos.php?id=%d", pg_result($res,$i,0));
print $pos.".<a href=\"".$getpath."\">".$fname."</a><br/>\n";
}
print "<br/>\n";
if ($lang=='eng')
print "<a href=\"photos.php?lang=eng\">Back</a><br/>\n";
else
print "<a href=\"photos.php\">Назад</a><br/>\n";
print "*******\n";
pg_close($conn);
}
if (($action=='news')&&($id==0)) {
if ($cat=='') $cat=1;
if ($access) setcookie("Sweetty", "21895", time()+864000, "/");
header("Content-type: text/vnd.wap.wml"); ?>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
<wml> <?php
$fl=0;
$res=pg_query($conn,"select max(rdate) from cat where enabled=1;");
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", pg_result($res,0,0), $regs);
if ($lang=='eng') {
print "<card id=\"News\" title=\"What's New\">\n";
print "<p align=\"center\">\n";
print "***********<br/>\n";
print "<b>Last update: ".$regs[1]."-".$regs[2]."-".$regs[3]."</b><br/><br/>";
} else {
print "<card id=\"News\" title=\"Что новенького\">\n";
print "<p align=\"center\">\n";
print "***********<br/>\n";
print "<b>Последнее обновление: ".$regs[3].".".$regs[2].".".$regs[1]."</b><br/><br/>";
}
$res=pg_query($conn, "select id,name_eng,name_rus from cat where enabled=1 and content=2 order by id;");
$rows=pg_numrows($res);
for ($i=0; $i<$rows; $i++)
{
$cid=pg_result($res,$i,0);
$fres=pg_query($conn, "select id,name_eng,name_rus from midi where enabled=1 and category ='$cid' and adate > '$dayx' order by name_eng;");
$frows=pg_numrows($fres);
if ($frows > 0) {
$fl++;
if ($lang=='eng') {
$catname=pg_result($res,$i,1);
print "<a href=\"photos.php?cat=".pg_result($res,$i,0)."&lang=eng&action=news\">".
$catname." (".$frows."):</a><br/>----------------<br/>\n";
if (pg_result($res,$i,0)==$cat) {
for ($f=0; $f<$frows; $f++) {
$fname=uconv(pg_result($fres,$f,1));
if ($access) $getpath=sprintf("photos.php?id=%d", pg_result($fres,$f,0));
print "<a href=\"".$getpath."\">".$fname."</a><br/>\n";
}
print "<br/>\n";
}
} else {
$catname=uconv(pg_result($res,$i,2));
if ($catname=='') $catname=pg_result($res,$i,1);
print "<a href=\"photos.php?cat=".pg_result($res,$i,0)."&action=news\">".
$catname." (".$frows."):</a><br/>----------------<br/>\n";
if (pg_result($res,$i,0)==$cat) {
for ($f=0; $f<$frows; $f++) {
$fname=uconv(pg_result($fres,$f,2));
if ($fname=='') $fname=uconv(pg_result($fres,$f,1));
if ($access) $getpath=sprintf("photos.php?id=%d", pg_result($fres,$f,0));
print "<a href=\"".$getpath."\">".$fname."</a><br/>\n";
}
print "<br/>\n";
}
}
}
}
if ($lang=='eng') {
if (!$fl) print "Sorry, nothing new at this moment.<br/>\n";
print "<a href=\"photos.php?lang=eng\">Back</a><br/>\n";
} else {
if (!$fl) print "Извините, ничего новенького нет.<br/>\n";
print "<a href=\"photos.php\">Назад</a><br/>\n";
}
print "*******\n";
pg_close($conn);
}
if (($id>0)&&($action=='')) {
$uid=0;
if (isset($_SESSION['id'])) {
$uid=$_SESSION['id'];
} else {
if ((trim($_COOKIE['Login'])!='')&&(trim($_COOKIE['Password'])!='')) {
$login=htmlspecialchars(trim($_COOKIE['Login']),ENT_QUOTES);
$pass=htmlspecialchars(trim($_COOKIE['Password']),ENT_QUOTES);
} else {
$login=htmlspecialchars(trim($_GET['login']),ENT_QUOTES);
$pass=htmlspecialchars(trim($_GET['pass']),ENT_QUOTES);
}
$res=pg_query($conn, "select id from users where login='$login' and passwd='$pass' and moder=0;");
if (pg_numrows($res)==1) $uid=pg_result($res,0,0);
$_SESSION['id']=$uid;
}
if ($uid) {
pg_query($conn, "begin;");
pg_query($conn, "update photos set dlcount=dlcount+1 where id='$id';");
$dltime=time();
pg_query($conn, "update users set lastact='$dltime' where id='$uid';");
# pg_query($conn, "insert into downloads (uid,midi,ip,agent,time) values ('$uid','$id','$addr','$agent','$dltime');");
$res=pg_query($conn,"select path from photos where id='$id';");
pg_query($conn, "end;");
# if (($_COOKIE['Sweetty']!='21895')&&(!$chatok)) $access=0;
if ($access) {
$getfile = sprintf("/home/katrinka/WWW/%s", pg_result($res,0,0));
$im=@imagecreatefromjpeg($getfile);
header("Content-type: image/jpeg");
imagejpeg($im);
} else {
$getfile = sprintf("Location: /sorry.wml");
header($getfile);
}
} else {
header("Content-type: text/vnd.wap.wml");
header("Cache-Control: no-cache");
?>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
<wml>
<head><meta http-equiv="Cache-Control" content="no-cache" forua="true"/></head>
<card id="Login" title="Login">
<p align="center">
Login:
<input type="text" name="login" title="Login" maxlength="15"/><br/>
Password:
<input type="password" name="pass" title="Password" maxlength="15"/><br/>
<anchor title="Download">Download<go href="photos.php" method="get">
<postfield name="login" value="$(login)"/>
<postfield name="pass" value="$(pass)"/>
<postfield name="nc" value="1"/>
<?php print "<postfield name=\"lang\" value=\"".$_GET['lang']."\"/>\n";
print "<postfield name=\"id\" value=\"".$id."\"/>\n";
print "<postfield name=\"PHPSESSID\" value=\"".session_id()."\"/>\n"; ?>
</go></anchor>
</p>
</card>
</wml>
<?php }
pg_close($conn);
} else {
print "</p>\n";
counters();
print "</card>\n";
print "</wml>\n";
}
?>