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

Размер файла: 1.83Kb
<?php
  include '../wap/config.php';
  include '../wap/guestbook/mylib.php';
  include 'acl.php';
  list ($uid, $pl) = priv_level();
  $agent=$_SERVER['HTTP_USER_AGENT'];
  $addr=$_SERVER['REMOTE_ADDR'];
  $pid=htmlspecialchars(trim($_GET['pid']),ENT_QUOTES);
  $t=htmlspecialchars(trim($_GET['t']),ENT_QUOTES);
  if ((!$pid)&&(!$t)) exit;
  if (!($conn=pg_connect("host=$dbhost port=$dbport dbname=$dbname user=$dbuser password=$dbpass"))) exit;
  pg_query($conn,"SET CLIENT_ENCODING TO 'KOI8';");
	pg_query($conn,"begin;");
	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);
		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 rplnum,forum from themes where id='$t';");
		$rplnum=pg_result($res,0,0);
		$f=pg_result($res,0,1);
		$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 ($pid)
			$link=sprintf("Location: forum.php?t=%s", $t);
		else	
			$link=sprintf("Location: forum.php?f=%s", $f);
		header($link);
?>