Просмотр файла modules/forum/add_post.php

Размер файла: 4.51Kb
<?php
/**********************************
*	@package: PerfCMS			  *
*	@year: 2012					  *
*	@author: Artas				  *
*	@link: http://perfcms.ru	  *
**********************************/
$locate = 'in_forum';
$topic_id = abs(intval($_GET['topic_id']));
if(!isset($user) || !isset($topic_id)) { header('Location:/'); }
if($db->query("SELECT * FROM `forum_t` WHERE `id` = '". $topic_id ."'")->rowCount() == 0) {
header('Location:/forum/');
}
if(isset($_POST['create']) && $_GET['act'] == 'create') {

if(!empty($_POST['text'])) { $text = substr(input($_POST['text']), 0, 10000);} else { $err = 'Message is empty'; }
if(!empty($_POST['text'])) {
$db->query("INSERT INTO `forum_pt` SET `text` = '".$text."', `time` = '". time() ."', `user_id` = '".$user['id']."', `topic_id` = '".$topic_id."', `file` = '', `file_size` = '0', `edit_time` = '0', `edit_user_id` = '0', `count_edit` = '0', `cat_id` = '0', `name` = ''");
// print_r($db->errorInfo());
$lastPostId = $db->lastInsertId();
if($db->query("SELECT * FROM `notify` WHERE `user_id` = '". $user['id'] ."' AND `type` = 'notify_topic_reply' AND `request_id` = '$topic_id'")->rowCount() == 0)
	{
		$db->query("INSERT INTO `notify` SET `user_id` = '". $user['id'] ."', `from_id` ='". $user['id'] ."', `request_id` = '$topic_id', `type` = 'notify_topic_reply', `read` = '0', `time` = '". time() ."'");
		// print_r($db->errorInfo());
		$db->query("UPDATE `notify` SET `read` = '0', `time` = '". time() ."' WHERE `user_id` = '". $user['id'] ."' AND `from_id` = '". $user['id'] ."' AND `type` = 'notify_topic_reply' AND `request_id` = '$topic_id'");
		// print_r($db->errorInfo());
	}
else
	{
		$db->query("UPDATE `notify` SET `from_id` = '". $user['id'] ."', `read` = '0', `time` = '". time() ."' WHERE `type` = 'notify_topic_reply' AND `request_id` = '$topic_id' AND `user_id` != '$user[id]'");
		// print_r($db->errorInfo());
	}
$db->query("UPDATE `forum_t` SET `time_last_post` = '". time() ."', `user_last_post` = '". $user['id'] ."' WHERE `id` = '".$topic_id."'");
$file_dir = ROOT .'/files/forum/';
		if (isset($_FILES['file']) && $_FILES['file']['tmp_name']) {
			$patch = pathinfo($_FILES['file']['name']);
			if (!in_array($patch['extension'], explode(';', $system['files_types']))) { $err = 'File extention not allowed.<br />'; }
			$name_start = cyrlat($patch['filename']);
			$name_short = trim($name_start).'_'.time();
			$name_end = mb_convert_encoding($name_short, "UTF-8");
			$name = $name_end.'.'. $patch['extension'];
			if (file_exists($file_dir . $name)) { $err = 'This file exists<br />'; }
			
			if(!isset($err)) {
        	move_uploaded_file($_FILES['file']['tmp_name'], $file_dir . $name);
        	$db->query("UPDATE `forum_pt` SET `file` = '". input($name) ."', `file_size` = '". $_FILES['file']['size'] ."' WHERE `id` = '".$lastPostId."'");
			// print_r($db->errorInfo());
			} else { echo $err; }
 		}
// print_r($db->errorInfo());
header('Location:/forum/topic'. abs(intval($topic_id)).'/?page=end');
exit;
// print_r($db->errorInfo());
 } else { header('Location:/forum/topic'. abs(intval($topic_id)).'/?page=end'); exit;}
}
$title = $lang->word('add_message');
require_once(SYS.'/view/header.php');
$tpl->div('title', $lang->word('add_message'));
$tpl->div('menu', '<form action="/forum/add_post/'. $topic_id .'/?act=create" method="post" enctype="multipart/form-data">
			<b>'. $lang->word('message') .'</b>:<br/>
			<textarea name="text" rows="5" cols="26">'.(isset($_GET['reply_to']) ? '[b]'.input($_GET['reply_to']).'[/b], ' : NULL) . (isset($_GET['quote']) ? "[quote][i][b]".tnick($db->query("SELECT user_id FROM `forum_pt` WHERE `topic_id` = '". $topic_id ."' AND `id` = '". abs(intval($_GET['quote'])) ."'")->fetchColumn())."[/b] ".date('d.m.Y, H:i', $db->query("SELECT time FROM `forum_pt` WHERE `topic_id` = '". $topic_id ."' AND `id` = '". abs(intval($_GET['quote'])) ."'")->fetchColumn())."[/i]:\n".preg_replace("/\[quote\]|\[\/quote\]/i", '', $db->query("SELECT text FROM `forum_pt` WHERE `topic_id` = '". $topic_id ."' AND `id` = '". abs(intval($_GET['quote'])) ."'")->fetchColumn())."\n[/quote] " : NULL)  .'</textarea><br/>
			<b>'.$lang->word('add_file').'</b><br/>
			<input type="file" name="file"><br/>
			<input name="create" type="submit" value="'. $lang->word('create') .'" /><br/>
		</form>');
		
$tpl->div('block',  NAV .'<a href="/forum/topic'.$topic_id.'?page=end">'. $lang->word('back') .'</a><br/>' . NAV .'<a href="/forum/">'. $lang->word('forum') .'</a><br/>' . HICO .'<a href="/">'. $lang->word('home').'</a>');
require_once(SYS.'/view/footer.php');
?>