<?
/*
=============================================
Движок:  SHCMS Engine
=============================================
Название файла: Форум
=============================================
Official website: http://shcms.ru
=============================================
*/
define('SHCMS', true);
if($_GET['id']){$id = $_GET['id'];}
include_once'../system/inc/basic_settings.php';
$themes = mysql_fetch_array(mysql_query("SELECT * FROM `forum_razd` WHERE id=$id"));
$shcmsengine['title'] = 'Создать новую тему в разделе '.$themes['name'].'';
include_once'../template/head.php';
registrat();


if($_POST['prosmotr'])
{$prosmotr = $_POST['prosmotr'];}

if(isset($prosmotr))
{

if($_POST['text'])
{$text = $_POST['text'];}

if(empty($text))
{
errors('Вы не ввели текст');
	include_once'../template/foot.php';
exit;
}

echo '<div class="maintitle">';
echo ''.users_profile($user_id).'</div>';

echo '<div class="maintext">'.$_POST['text'].'</div>';

	include_once'../template/foot.php';
exit;
}




$q = mysql_query("SELECT * FROM `forum_razd` WHERE `id` = '$id'");
if (!mysql_num_rows($q)) {
    header('Refresh: 1; url=./');
    echo 'В данном разделе нельзя создавать темы';
    include_once'../template/foot.php';
    exit();
	}

if($_POST['submit']) {
    $submit = $_POST['submit'];
	}

if(isset($submit)) {

if($_POST['name']) {
    $name = $_POST['name'];
	}
if($_POST['text']) {
    $text = $_POST['text'];
	}

	
if(isset($name) && isset($text)) {

$themesdb = mysql_query("INSERT INTO `forum_them` (`id_razd`,`id_cat`,`name`,`time`,`user_id`) VALUES ('$id',$themes[id_cat],'$name','$time_date','$user_id')");
$unid = mysql_fetch_array(mysql_query("SELECT * FROM `forum_them` WHERE `id_razd` = '$id' ORDER BY `id` DESC"));
mysql_query("INSERT INTO `forum_mess` (`id_cat`,`id_razd`,`id_them`,`id_user`,`message`,`time`) VALUE ('$themes[id_cat]','$id','$unid[id]','$user_id','$text','".time()."')");


if($themesdb == true) {
    echo'<div class="actshcms">Тема успешно создана</div>';
    header('Refresh: 1; url=message.php?id='.$unid['id'].'&' . $conservation . '&' );
    include_once'../template/foot.php';
    exit();
    } else {
    echo'<div class="errors">Ошибка создании нового раздела</div>';
    header('Refresh: 1; url=them.php?id='.$id.'&' . $conservation . '&' );
	include_once'../template/foot.php';
    exit; }}

    }

echo '<form action="?id='.$id.'" method="post">';
echo 'Название темы:<br/><input type="text" name="name"><br/>';
echo 'Сообщение:<br/><textarea name="text"></textarea><br/>';
echo '<br/><input type="submit" name="submit" value="Создать тему">
<input type="submit" name="prosmotr" value="Предпросмотр"></form>';


echo '<div class="posts"><a href="them.php?id='.$id.'">Назад</a></div>';
	include_once'../template/foot.php';
?>