Файл: modules/forum/add_post.php
Строк: 101
<?php
$locate = 'in_forum';
$topic_id = abs(intval($_GET['topic_id']));
$topic_ps = $db->query("SELECT * FROM `forum_t` WHERE `id` = '". $topic_id ."'")->fetch();
if(!isset($user) || !isset($topic_id) || $topic_ps['closed'] == 1) { 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'; }
$s = $db->query("SELECT * FROM `forum_pt` WHERE `user_id` = '". $user['id'] ."' AND `time` > '". (time()-$system['spam_forum']) ."'")->rowCount();
if ($s>0) {
header('Location:/forum/topic'. abs(intval($topic_id)).'/?page=end&act=spam');
} else {
if(!empty($_POST['text'])) {
$db->query("UPDATE `users` SET `rub` = '".($user['rub']+0.05)."' WHERE `id` = '". $user['id'] ."'");
$db->query("UPDATE `users` SET `balans` = '".($user['balans']+$system[balans_forum])."' WHERE `id` = '".$user['id'] . "'");
$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 (isset($_GET['reply_to'])) {
$reply_to = $db->query("SELECT * FROM `users` WHERE `nick` = '". input($_GET['reply_to']) ."'")->fetch();
$db->query("INSERT INTO `notify` SET `user_id` = '". $reply_to['id'] ."', `from_id` ='". $user['id'] ."', `request_id` = '$topic_id', `type` = 'notify_topic_reply', `read` = '0', `time` = '". time() ."'");
}
elseif (isset($_GET['quote'])) {
$quote = $db->query("SELECT * FROM `forum_pt` WHERE `id` = '". abs(intval($_GET['quote'])) ."'")->fetch();
$db->query("INSERT INTO `notify` SET `user_id` = '". $quote['user_id'] ."', `from_id` ='". $user['id'] ."', `request_id` = '$topic_id', `type` = 'notify_topic_reply', `read` = '0', `time` = '". time() ."'");
}
else {
$topic_pod = $db->query("SELECT * FROM `forum_pod` WHERE `topic_id` = '". $topic_id ."' ORDER BY time");
while($user_pod = $topic_pod->fetch()) {
$db->query("INSERT INTO `notify` SET `user_id` = '". $user_pod['user'] ."', `from_id` ='". $user['id'] ."', `request_id` = '$topic_id', `type` = 'notify_topic_reply', `read` = '0', `time` = '". time() ."'");
}
}
$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'));
echo '<div class="menu"><form action="/forum/add_post/'. $topic_id .'/?act=create" method="post" enctype="multipart/form-data">
<b>'. $lang->word('message') .'</b>:<br/>';
require_once(SYS.'/inc/bb.php');
echo '<textarea name="text" id="view_bar">'.(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>
* Максимальный размер загружаемого файла: 20Mb.</div>';
$tpl->div('block', NAV .'<a href="/forum/topic'.$topic_id.'?page=end">'. $lang->word('back') .'</a><br/>' . img('forum.png') .'<a href="/forum/">'. $lang->word('forum') .'</a><br/>' . HICO .'<a href="/">'. $lang->word('home').'</a>');
require_once(SYS.'/view/footer.php');
?>