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

Размер файла: 1.61Kb
<?php
  include '../wap/config.php';
	include 'acl.php';
    if (!($conn=pg_connect("host=$dbhost port=$dbport dbname=$dbname user=$dbuser password=$dbpass"))) {
      echo ("пЫЙВЛБ РПДЛМАЮЕОЙС Л вд!\n");
    };
	list ($uid, $pl) = priv_level();
	$addr=$_SERVER['REMOTE_ADDR'];
	$agent=$_SERVER['HTTP_USER_AGENT'];
	$message=htmlspecialchars(trim($_POST['message']),ENT_QUOTES);
	$to=htmlspecialchars(trim($_POST['to']),ENT_QUOTES);
	pg_query($conn,"SET CLIENT_ENCODING TO 'KOI8';");
	$mtime=time();
	pg_query($conn,"begin;");
	$to_uid=0;
	$pflag=0;
	if ($to!='') {
		$res=pg_query($conn,"select id from users where login='$to';");
		if (pg_numrows($res)) $to_uid=pg_result($res,0,0);
	}
	if (($message[0]=='/')&&(!$to)) {
		$bp=strpos($message, ' ');
		if ($bp) $tag=substr($message,1,$bp-1);
			else $tag=substr($message,1);
		$res=pg_query($conn,"select txt from chat_tags where tag='$tag' order by id;");
		$rows=pg_numrows($res);
		if ($rows) {
			if ($rows > 1) { $tn=rand(0,$rows-1); }
				else { $tn=0; }
			$message=pg_result($res,$tn,0);
			$pflag=1;
		}
	}
	if ($r!=18) {
    	pg_query($conn,"insert into chat (room,fr_u,to_u,time,message,agent,host,flag) values ('$r','$uid','$to_uid','$mtime','$message','$agent','$addr','$pflag');");
	} else {
		if ($to_uid==0) $to_uid=$uid;
    	pg_query($conn,"insert into chat_tet (fr_u,to_u,time,message,agent,host) values ('$uid','$to_uid','$mtime','$message','$agent','$addr');");
	}
	pg_query($conn,"update users set posts=posts+1,lastact='$mtime' where id='$uid';");
	pg_query($conn,"end;");
    pg_close($conn);
	$link=sprintf("Location: chat.php?action=add&r=%s", $r);
	header($link);
?>