<?php

require '../system/start.php';
require '../system/functions.php';
reg();
$query = mysql_fetch_assoc(mysql_query("select * from `forum_forums` where `id` = ".int($_GET['id']).""));
$str['mesto'] = 'Добавить тему';
$str['block'] = $set['site'].' / <a href="index.php">Форум</a> / '.$query['title'].'';
include '../style/'.$style.'/head.php';
if(empty($query['title']))
{
    echo '<div class="forum1">Форум не найден!</div>';
    include '../style/'.$style.'/foot.php';
    exit;
}
if(isset($_POST['title']) && !empty($_POST['title']) && !empty($_POST['text']))
{
    mysql_query ("INSERT INTO `forum_topics` (id_forum,title,status,position,time) VALUES (".int($_GET['id']).",'".protect($_POST['title'])."',1,2,".time().")");
    $ins_id = mysql_insert_id();
    mysql_query ("INSERT INTO `forum_posts` (id_forum,id_topic,login,text,time) VALUES (".int($_GET['id']).",".$ins_id.",'".$user['login']."','".protect($_POST['text'])."',".time().")");
    mysql_query("update `users` set `balls`=`balls`+1 where `id` = ".$user['id']."");    
    echo '<div class="forum1">Тема успешно создана!<br />
    <a href="topic.php?id='.$ins_id.'">Перейти &raquo;</a></div>';
    include '../style/'.$style.'/foot.php';
    exit;
}
echo '<div class="mess">
<form action="addtopic.php?id='.int($_GET['id']).'" method="post">
<div>
Название темы:<br/>
<input name="title" type="text" value=""/><br/>
Сообщение:<br/>
<textarea name="text"></textarea><br />
<input type="submit" value="Создать"/></div></form></div>
<div class="on2">
<img class="ico" src="../style/'.$style.'/ico/newpost.png" alt="" /> <a href="../pages/info.php?act=bbcode">BBcode</a><br/>
<img class="ico" src="../style/'.$style.'/ico/newpost.png" alt="" /> <a href="../pages/info.php?act=smiles">Смайлы</a>
</div>
';
include '../style/'.$style.'/foot.php';
?>