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

Размер файла: 4.56Kb
<?php
  include 'guestbook/mylib.php';
  include 'config.php';
  if (!checkagent($_SERVER['HTTP_USER_AGENT'])) { noemul(); exit; }
  session_start();
  $agent=$_SERVER['HTTP_USER_AGENT'];
  $uid=0;
  $lang=$_GET['lang'];
  $r=$_GET['r'];
  if (!$r) $r=$_POST['r'];
  $t=htmlspecialchars(trim($_GET['t']),ENT_QUOTES);
  $pid=htmlspecialchars(trim($_GET['pid']),ENT_QUOTES);
  $close=htmlspecialchars(trim($_GET['close']),ENT_QUOTES);
  if ((!$pid)&&(!$t)) exit;
  if (($close)&&(!$t)) exit;
  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($_POST['login']),ENT_QUOTES);
	$pass=htmlspecialchars(trim($_POST['pass']),ENT_QUOTES);
	$nocookie=1;
  }
  if (!($conn=pg_connect("host=$dbhost port=$dbport dbname=$dbname user=$dbuser password=$dbpass"))) exit;
	if ((isset($_SESSION['id']))&&(isset($_SESSION['access']))) {
		$uid=$_SESSION['id'];
		$access=$_SESSION['access'];
	} else {
	$res=pg_query($conn,"select id,access from users where login='$login' and passwd='$pass' and moder=0;");
	$rows=pg_numrows($res);

	if (!$rows) {
		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="Login" title="Login">
<p align="center">
Login: 
<input type="text" name="login" title="Login" maxlength="10"/><br/>
Password:
<input type="password" name="pass" title="Password" maxlength="15"/><br/>
<anchor title="Del">DELETE<go href="forum_del.php" method="post">
<postfield name="login" value="$(login)"/>
<postfield name="pass" value="$(pass)"/>
<?php print "<postfield name=\"lang\" value=\"".$_GET['lang']."\"/>\n";
print "<postfield name=\"pid\" value=\"".$pid."\"/>\n";
print "<postfield name=\"t\" value=\"".$t."\"/>\n";
print "<postfield name=\"close\" value=\"".$close."\"/>\n";
print "<postfield name=\"r\" value=\"".$r."\"/>\n"; ?>
</go></anchor>
</p>
</card>
</wml>
<?php
		pg_close($conn);
		exit;
	}
	$uid=pg_result($res,0,0);
	$access=pg_result($res,0,1);
	$_SESSION['id']=$uid;
	$_SESSION['access']=$access;
}
	if ($pid) {
		$res=pg_query($conn,"select uid,theme from threads where id='$pid';");
		$fr_u=pg_result($res,0,0);
		$t=pg_result($res,0,1);
		$res=pg_query($conn,"select forum from themes where id='$t';");
		$f=pg_result($res,0,0);
	} else {
		$res=pg_query($conn,"select rplnum,forum from themes where id='$t';");
		$rplnum=pg_result($res,0,0);
		$f=pg_result($res,0,1);
	}
	$res=pg_query($conn,"select id from forum_moder where forum='$f' and uid='$uid';");
	if (pg_numrows($res)==1) $fmoder=1; else $fmoder=0;

	if (($access < 3)&&(!$fmoder)) {
		pg_close($conn);
		header("Location: /");
	}
	
	$res=pg_query($conn,"select id from user_agent where uid='$uid' and agent='$agent';");
#	if (pg_numrows($res)!=1) {
	if (1==2) {
		pg_close($conn);
		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="NoOK" title="Error">
<p align="center">
DELETE failed.
</p>
</card>
</wml>
<?php
		exit;
	}
	pg_query($conn,"begin;");
	if ($pid) {
		pg_query($conn,"update users set fposts=fposts-1 where id='$fr_u';");
		pg_query($conn,"update themes set rplnum=rplnum-1 where id='$t';");
		pg_query($conn,"update forums set nrepl=nrepl-1 where id='$f';");
		pg_query($conn,"delete from threads where id='$pid';");
	} else {
		$res=pg_query($conn,"select uid from threads where theme='$t';");
		$rows=pg_numrows($res);
		for ($i=0; $i<$rows; $i++) {
			$fr_u=pg_result($res,0,0);
			pg_query($conn,"update users set fposts=fposts-1 where id='$fr_u';");
		}
		pg_query($conn,"update forums set nrepl=nrepl-'$rplnum',nthemes=nthemes-1 where id='$f';");
		pg_query($conn,"delete from threads where theme='$t';");
		pg_query($conn,"delete from seen_by where theme='$t';");
		pg_query($conn,"delete from themes where id='$t';");
	}       
	pg_query($conn,"end;");
	
	pg_close($conn);
	if (!$res) exit;
	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
	if ($pid) {
		print "<card id=\"DelOk\" title=\"REMOVED\" ontimer=\"forum.php?t=".$t."&amp;".SID."\">\n";
	} else {
		print "<card id=\"DelOk\" title=\"REMOVED\" ontimer=\"forum.php?f=".$f."&amp;".SID."\">\n";
	}
 ?>
<timer value="10"/>
<p align="center">
<?php print "Removed\n"; ?>
</p>
</card>
</wml>