Просмотр файла katrinka.ru/midi.php

Размер файла: 12.27Kb
  1. <?php
  2. include 'config.php';
  3. include 'guestbook/mylib.php';
  4. $ppp=20;
  5. session_start();
  6.  
  7. $lang=$_GET['lang'];
  8. $p=htmlspecialchars(trim($_GET['p']),ENT_QUOTES);
  9. $cat=htmlspecialchars(trim($_GET['cat']),ENT_QUOTES);
  10. $action=htmlspecialchars(trim($_GET['action']),ENT_QUOTES);
  11. # if ($_POST['id']!=0) $id=$_POST['id'];
  12. # else $id=$_GET['id'];
  13. $id=htmlspecialchars(trim($_GET['id']),ENT_QUOTES);
  14. $agent=$_SERVER['HTTP_USER_AGENT'];
  15. $addr=$_SERVER['REMOTE_ADDR'];
  16. list ($opname, $chatok) = check_op($_SERVER['REMOTE_ADDR']);
  17. $dayx=date("Y-m-d", mktime(0,0,0,date("m"), date("d")-3, date("Y")));
  18.  
  19. # if (midi_access($agent)) $access=1;
  20. # else $access=0;
  21. $access=1;
  22. $getpath='/sorry.wml';
  23. ?>
  24. <?php
  25. if (!($conn=pg_connect("host=$dbhost port=$dbport dbname=$dbname user=$dbuser password=$dbpass")))
  26. {
  27. header("Content-type: text/vnd.wap.wml");
  28. ?>
  29. <?xml version="1.0" encoding="utf-8"?>
  30. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
  31. <wml>
  32. <card id="CatalogErr" title="&#x041E;&#x0448;&#x0438;&#x0431;&#x043A;&#x0430;">
  33. <p align="center">
  34. &#x041E;&#x0448;&#x0438;&#x0431;&#x043A;&#x0430; &#x043F;&#x043E;&#x0434;&#x043A;&#x043B;&#x044E;&#x0447;&#x0435;&#x043D;&#x0438;&#x044F; &#x043A; &#x0411;&#x0414<br/>
  35. <a href="/">&#x041D;&#x0430; &#x0433;&#x043B;&#x0430;&#x0432;&#x043D;&#x0443;&#x044E;</a>
  36. </p>
  37. </card>
  38. </wml>
  39. <?php
  40. exit;
  41. }
  42. if (($cat==0)&&($action=='')&&($id==0)) {
  43. header("Content-type: text/vnd.wap.wml"); ?>
  44. <?xml version="1.0" encoding="utf-8"?>
  45. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
  46. <wml> <?php
  47. print "<card id=\"Catalog\" title=\"Polyphony\">\n";
  48. print "<p align=\"center\">**********<br/>\n";
  49. $res=pg_query($conn,"select count(*) from midi,cat where midi.adate > '$dayx' and midi.enabled=1 and midi.category=cat.id and cat.content=1;");
  50. if ($lang=='eng') {
  51. print "<a href=\"midi.php?lang=eng&amp;action=news\">What's New (".pg_result($res,0,0).")</a><br/>\n";
  52. print "<a href=\"midi.php?lang=eng&amp;action=top\">Top 10</a><br/><br/>\n";
  53. } else {
  54. print "<a href=\"midi.php?action=news\">&#x0427;&#x0442;&#x043E; &#x041D;&#x043E;&#x0432;&#x0435;&#x043D;&#x044C;&#x043A;&#x043E;&#x0433;&#x043E; (".pg_result($res,0,0).")</a><br/>\n";
  55. print "<a href=\"midi.php?action=top\">Top 10</a><br/><br/>\n";
  56. }
  57. $res=pg_query($conn,"select id,name_eng,name_rus from cat where enabled=1 and content=1 order by id;");
  58. $rows=pg_numrows($res);
  59.  
  60. for ($i=0;$i<$rows;$i++) {
  61. $cid=pg_result($res,$i,0);
  62. $res_cnt=pg_query($conn,"select count(*) from midi where category='$cid' and enabled=1;");
  63. if ($lang=='eng') {
  64. $catname=pg_result($res,$i,1);
  65. print "<a href=\"midi.php?lang=eng&amp;cat=".pg_result($res,$i,0)."\">".$catname." (".pg_result($res_cnt,0,0).")</a><br/>\n";
  66. } else {
  67. $catname=uconv(pg_result($res,$i,2));
  68. if ($catname=='') $catname=pg_result($res,$i,1);
  69. print "<a href=\"midi.php?cat=".pg_result($res,$i,0)."\">".$catname." (".pg_result($res_cnt,0,0).")</a><br/>\n";
  70. }
  71. }
  72.  
  73. pg_close($conn);
  74. print "*******<br/>\n";
  75. if ($lang=='eng') print "<a href=\"/index.php?lang=eng\">Main page</a><br/>\n";
  76. else print "<a href=\"/\">&#x041D;&#x0430; &#x0433;&#x043B;&#x0430;&#x0432;&#x043D;&#x0443;&#x044E;</a><br/>\n";
  77. }
  78. if (($cat>0)&&($action=='')&&($id==0)) {
  79. if ($access) setcookie("Sweetty", "21895", time()+864000, "/");
  80. header("Content-type: text/vnd.wap.wml"); ?>
  81. <?xml version="1.0" encoding="utf-8"?>
  82. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
  83. <wml> <?php
  84. $res=pg_query($conn,"select name_eng,name_rus from cat where id=$cat;");
  85. if ($lang=='eng') $catname=pg_result($res,0,0);
  86. else {
  87. $catname=uconv(pg_result($res,0,1));
  88. if ($catname=='') $catname=pg_result($res,0,0);
  89. }
  90. print "<card id=\"Links\" title=\"".$catname."\">\n";
  91. print "<p align=\"center\">**************<br/>\n";
  92. $offset=$p*$ppp;
  93. $res=pg_query($conn,"select count(id) from midi where enabled=1 and category='$cat';");
  94. $numrec=pg_result($res,0,0);
  95. $res=pg_query($conn,"select id,name_eng,name_rus from midi where enabled=1 and category=$cat order by name_eng limit $ppp offset $offset;");
  96. $rows=pg_numrows($res);
  97. $np=$p+1; $pp=$p-1; $mp=floor(($numrec-1)/$ppp);
  98.  
  99. for ($i=0;$i<$rows;$i++) {
  100. if ($lang=='eng') $midiname=uconv(pg_result($res,$i,1));
  101. else {
  102. $midiname=uconv(pg_result($res,$i,2));
  103. if ($midiname=='') $midiname=uconv(pg_result($res,$i,1));
  104. }
  105. if ($access) $getpath=sprintf("midi.php?id=%d", pg_result($res,$i,0));
  106. else $getpath='/sorry.wml';
  107. print "<a href=\"".$getpath."\">".$midiname."</a><br/>\n";
  108. }
  109. $res=pg_query($conn, "select rdate from cat where id=$cat and enabled=1;");
  110. ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", pg_result($res,0,0), $regs);
  111. pg_close($conn);
  112.  
  113. print "*******<br/><br/>\n";
  114. if ($lang=='eng') {
  115. if ($numrec > $ppp) {
  116. if ($p<$mp) print("<a href=\"midi.php?lang=eng&amp;p=".$np."&amp;cat=".$cat."\">Next ".$ppp."</a><br/>\n");
  117. if ($p>0) print("<a href=\"midi.php?lang=eng&amp;p=".$pp."&amp;cat=".$cat."\">Prev ".$ppp."</a><br/>\n");
  118. }
  119. print "<a href=\"midi.php?lang=eng\">Back</a><br/>\n";
  120. print "<b>Last update: ".$regs[1]."-".$regs[2]."-".$regs[3]."</b>";
  121. } else {
  122. if ($numrec > $ppp) {
  123. if ($p<$mp) print("<a href=\"midi.php?p=".$np."&amp;cat=".$cat."\">&#x0421;&#x043B;&#x0435;&#x0434;&#x0443;&#x044E;&#x0449;&#x0438;&#x0435; ".$ppp."</a><br/>\n");
  124. if ($p>0) print("<a href=\"midi.php?p=".$pp."&amp;cat=".$cat."\">&#x041F;&#x0440;&#x0435;&#x0434;&#x044B;&#x0434;&#x0443;&#x0449;&#x0438;&#x0435; ".$ppp."</a><br/>\n");
  125. }
  126. print "<a href=\"midi.php\">&#x041D;&#x0430;&#x0437;&#x0430;&#x0434;</a><br/>\n";
  127. print "<b>&#x041F;&#x043E;&#x0441;&#x043B;&#x0435;&#x0434;&#x043D;&#x0435;&#x0435; &#x043E;&#x0431;&#x043D;&#x043E;&#x0432;&#x043B;&#x0435;&#x043D;&#x0438;&#x0435;: ".$regs[3].".".$regs[2].".".$regs[1]."</b>";
  128. }
  129. }
  130.  
  131. if (($action=='top')&&($cat==0)&&($id==0)) {
  132. if ($access) setcookie("Sweetty", "21895", time()+864000, "/");
  133. header("Content-type: text/vnd.wap.wml"); ?>
  134. <?xml version="1.0" encoding="utf-8"?>
  135. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
  136. <wml>
  137. <card id="Top10" title="Top10">
  138. <p align="center">
  139. ***********<br/>
  140. <?php
  141. $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 > 0and midi.category=cat.id and cat.content=1 order by midi.dlcount desc limit 10;");
  142. $rows=pg_numrows($res);
  143. for ($i=0; $i<$rows; $i++) {
  144. $fname=uconv(pg_result($res,$i,2));
  145. $pos=$i+1;
  146. if (($lang=='eng')||($fname=='')) $fname=uconv(pg_result($res,$i,1));
  147. if ($access) $getpath=sprintf("midi.php?id=%d", pg_result($res,$i,0));
  148. print $pos.".<a href=\"".$getpath."\">".$fname."</a><br/>\n";
  149. }
  150. print "<br/>\n";
  151. if ($lang=='eng')
  152. print "<a href=\"midi.php?lang=eng\">Back</a><br/>\n";
  153. else
  154. print "<a href=\"midi.php\">&#x041D;&#x0430;&#x0437;&#x0430;&#x0434;</a><br/>\n";
  155. print "*******\n";
  156. pg_close($conn);
  157. }
  158.  
  159. if (($action=='news')&&($id==0)) {
  160. if ($cat=='') $cat=1;
  161. if ($access) setcookie("Sweetty", "21895", time()+864000, "/");
  162. header("Content-type: text/vnd.wap.wml"); ?>
  163. <?xml version="1.0" encoding="utf-8"?>
  164. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
  165. <wml> <?php
  166. $fl=0;
  167. $res=pg_query($conn,"select max(rdate) from cat where enabled=1;");
  168. ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", pg_result($res,0,0), $regs);
  169. if ($lang=='eng') {
  170. print "<card id=\"News\" title=\"What's New\">\n";
  171. print "<p align=\"center\">\n";
  172. print "***********<br/>\n";
  173. print "<b>Last update: ".$regs[1]."-".$regs[2]."-".$regs[3]."</b><br/><br/>";
  174. } else {
  175. print "<card id=\"News\" title=\"&#x0427;&#x0442;&#x043E; &#x043D;&#x043E;&#x0432;&#x0435;&#x043D;&#x044C;&#x043A;&#x043E;&#x0433;&#x043E;\">\n";
  176. print "<p align=\"center\">\n";
  177. print "***********<br/>\n";
  178. print "<b>&#x041F;&#x043E;&#x0441;&#x043B;&#x0435;&#x0434;&#x043D;&#x0435;&#x0435; &#x043E;&#x0431;&#x043D;&#x043E;&#x0432;&#x043B;&#x0435;&#x043D;&#x0438;&#x0435;: ".$regs[3].".".$regs[2].".".$regs[1]."</b><br/><br/>";
  179. }
  180. $res=pg_query($conn, "select id,name_eng,name_rus from cat where enabled=1 and content=1 order by id;");
  181. $rows=pg_numrows($res);
  182. for ($i=0; $i<$rows; $i++)
  183. {
  184. $cid=pg_result($res,$i,0);
  185. $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;");
  186. $frows=pg_numrows($fres);
  187. if ($frows > 0) {
  188. $fl++;
  189. if ($lang=='eng') {
  190. $catname=pg_result($res,$i,1);
  191. print "<a href=\"midi.php?cat=".pg_result($res,$i,0)."&amp;lang=eng&amp;action=news\">".
  192. $catname." (".$frows."):</a><br/>----------------<br/>\n";
  193. if (pg_result($res,$i,0)==$cat) {
  194. for ($f=0; $f<$frows; $f++) {
  195. $fname=uconv(pg_result($fres,$f,1));
  196. if ($access) $getpath=sprintf("midi.php?id=%d", pg_result($fres,$f,0));
  197. print "<a href=\"".$getpath."\">".$fname."</a><br/>\n";
  198. }
  199. print "<br/>\n";
  200. }
  201. } else {
  202. $catname=uconv(pg_result($res,$i,2));
  203. if ($catname=='') $catname=pg_result($res,$i,1);
  204. print "<a href=\"midi.php?cat=".pg_result($res,$i,0)."&amp;action=news\">".
  205. $catname." (".$frows."):</a><br/>----------------<br/>\n";
  206. if (pg_result($res,$i,0)==$cat) {
  207. for ($f=0; $f<$frows; $f++) {
  208. $fname=uconv(pg_result($fres,$f,2));
  209. if ($fname=='') $fname=uconv(pg_result($fres,$f,1));
  210. if ($access) $getpath=sprintf("midi.php?id=%d", pg_result($fres,$f,0));
  211. print "<a href=\"".$getpath."\">".$fname."</a><br/>\n";
  212. }
  213. print "<br/>\n";
  214. }
  215. }
  216. }
  217. }
  218.  
  219. if ($lang=='eng') {
  220. if (!$fl) print "Sorry, nothing new at this moment.<br/>\n";
  221. print "<a href=\"midi.php?lang=eng\">Back</a><br/>\n";
  222. } else {
  223. if (!$fl) print "&#x0418;&#x0437;&#x0432;&#x0438;&#x043D;&#x0438;&#x0442;&#x0435;, &#x043D;&#x0438;&#x0447;&#x0435;&#x0433;&#x043E; &#x043D;&#x043E;&#x0432;&#x0435;&#x043D;&#x044C;&#x043A;&#x043E;&#x0433;&#x043E; &#x043D;&#x0435;&#x0442;.<br/>\n";
  224. print "<a href=\"midi.php\">&#x041D;&#x0430;&#x0437;&#x0430;&#x0434;</a><br/>\n";
  225. }
  226. print "*******\n";
  227. pg_close($conn);
  228. }
  229.  
  230. if (($id>0)&&($cat==0)&&($action=='')) {
  231. $uid=0;
  232. if (isset($_SESSION['id'])) {
  233. $uid=$_SESSION['id'];
  234. } else {
  235. if ((trim($_COOKIE['Login'])!='')&&(trim($_COOKIE['Password'])!='')) {
  236. $login=htmlspecialchars(trim($_COOKIE['Login']),ENT_QUOTES);
  237. $pass=htmlspecialchars(trim($_COOKIE['Password']),ENT_QUOTES);
  238. } else {
  239. $login=htmlspecialchars(trim($_GET['login']),ENT_QUOTES);
  240. $pass=htmlspecialchars(trim($_GET['pass']),ENT_QUOTES);
  241. }
  242. $res=pg_query($conn, "select id from users where login='$login' and passwd='$pass' and moder=0;");
  243. if (pg_numrows($res)==1) $uid=pg_result($res,0,0);
  244. $_SESSION['id']=$uid;
  245. }
  246. if ($uid) {
  247. pg_query($conn, "begin;");
  248. pg_query($conn, "update midi set dlcount=dlcount+1,dltotal=dltotal+1 where id='$id';");
  249. $dltime=time();
  250. pg_query($conn, "update users set lastact='$dltime' where id='$uid';");
  251. # pg_query($conn, "insert into downloads (uid,midi,ip,agent,time) values ('$uid','$id','$addr','$agent','$dltime');");
  252. $res=pg_query($conn,"select path from midi where id='$id';");
  253. pg_query($conn, "end;");
  254. # if (($_COOKIE['Sweetty']!='21895')&&(!$chatok)) $access=0;
  255. if ($access) $getfile = sprintf("Location: http://katrinka.ru%s", pg_result($res,0,0));
  256. else $getfile = sprintf("Location: /sorry.wml");
  257. header($getfile);
  258. } else {
  259. header("Cache-Control: no-cache");
  260. header("Content-type: text/vnd.wap.wml");
  261. ?>
  262. <?xml version="1.0" encoding="utf-8"?>
  263. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
  264. <wml>
  265. <head><meta http-equiv="Cache-Control" content="no-cache" forua="true"/></head>
  266. <card id="Login" title="Login">
  267. <p align="center">
  268. Login:
  269. <input type="text" name="login" title="Login" maxlength="15"/><br/>
  270. Password:
  271. <input type="password" name="pass" title="Password" maxlength="15"/><br/>
  272. <anchor title="Download">Download<go href="midi.php" method="get">
  273. <postfield name="login" value="$(login)"/>
  274. <postfield name="pass" value="$(pass)"/>
  275. <postfield name="nc" value="1"/>
  276. <?php print "<postfield name=\"lang\" value=\"".$_GET['lang']."\"/>\n";
  277. print "<postfield name=\"id\" value=\"".$id."\"/>\n";
  278. print "<postfield name=\"PHPSESSID\" value=\"".session_id()."\"/>\n"; ?>
  279. </go></anchor>
  280. </p>
  281. </card>
  282. </wml>
  283. <?php }
  284. pg_close($conn);
  285. } else {
  286. print "</p>\n";
  287. counters();
  288. print "</card>\n";
  289. print "</wml>\n";
  290. }
  291. ?>