Файл: public_html/modules/forum/add_topic.php
Строк: 92
<?php
/**********************************
* @package: PerfCMS *
* @year: 2012 *
* @author: Artas *
* @link: http://perfcms.net *
* ------------------------------- *
* @package: PerfCMS Ultra *
* @year: 2013 *
* @author: wanya26ua & Tesla *
* @link: http://perfclub.ru *
**********************************/
$locate = 'in_forum';
$cat_id = abs(intval($_GET['cat_id']));
if(!isset($user) || !isset($cat_id)) { header('Location:/'); }
if($db->query("SELECT * FROM `forum_c` WHERE `id` = '". $cat_id ."'")->rowCount() == 0) {
header('Location:/forum/');
}
if(isset($_POST['create']) && $_GET['act'] == 'create') {
if(!empty($_POST['name'])) { $name = substr(input($_POST['name']), 0, 100); } else { $err = 'Name is empty'; }
if(!empty($_POST['text'])) { $text = substr(input($_POST['text']), 0, 6000); } else { $err = 'Message is empty'; }
if(!isset($err)) {
$db->query("INSERT INTO `forum_t`(`name`, `cat_id`, `time_last_post`, `user_last_post`, `attach`, `closed`) VALUES('".$name."','". abs(intval($cat_id)) ."', '". time() ."', '". $user['id'] ."', '0', '0')");
// print_r($db->errorInfo());
$last_id = $db->lastInsertId();
$db->query("UPDATE `users` SET `balans` = '".($user['balans']+$system[balans_forum])."' WHERE `id` = '".$user['id'] . "'");
$db->query("INSERT INTO `forum_pt`(`name`, `text`, `time`, `user_id`, `cat_id`, `topic_id`, `file`, `file_size`, `edit_time`, `edit_user_id`, `count_edit`) VALUES('".$name."', '". $text ."', '". time() ."', '". $user['id'] ."', '". abs(intval($cat_id))."', '". $last_id ."', '', 0, 0, 0, 0)");
// print_r($db->errorInfo());
$lastPostId = $db->lastInsertId();
$db->query("INSERT INTO `notify` SET `user_id` = '". $user['id'] ."', `from_id` ='". $user['id'] ."', `request_id` = '$last_id', `type` = 'notify_topic_reply', `read` = '1', `time` = '". time() ."'");
$file_dir = ROOT .'/files/forum/';
if ($_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; }
}
header('Location:/forum/topic'. $last_id);
exit;
// print_r($db->errorInfo());
} else { header('Location:/forum/add_topic/'. $cat_id .'/'); }
}
$title = $lang->word('create_topic');
require_once(SYS.'/view/header.php');
$tpl->div('title', $lang->word('create_topic'));
echo '<form action="/forum/add_topic/'. $cat_id .'/?act=create" method="post" enctype="multipart/form-data">
<div class="menu">
<b>'. $lang->word('name') .'</b>:<br/>';
require_once(SYS.'/inc/bb.php');
echo '<input name="name" type="text" /><br/>
<b>'. $lang->word('message') .'</b>:<br/>
<textarea name="text" id="view_bar"></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/>
</div>
</form>';
$tpl->div('block', NAV .'<a href="/forum/">'. $lang->word('forum') .'</a><br/>' . HICO .'<a href="/">'. $lang->word('home').'</a>');
require_once(SYS.'/view/footer.php');
?>