<?php

require '../system/start.php';
require '../system/functions.php';
reg();
$str['mesto'] = 'Дневники';
$str['block'] = $set['site'].' / Дневники / Пользователь '.$user['login'].' / Добавить запись';
include '../style/'.$style.'/head.php';
$myblog = mysql_result(mysql_query("select count(*) from `blogs` where `id_user` = ".$user['id'].""),0);
$blog = mysql_fetch_assoc(mysql_query("select `id` from `blogs` where `id_user` = ".$user['id'].""));
if($myblog == 0)
{
	echo '<div class="mess">У вас еще нет дневника!</div>';
}
if(isset($_POST['title']) and !empty($_POST['title']) and !empty($_POST['text']))
{
              mysql_query("update `users` set `balls`=`balls`+1 where `id` = ".$user['id']."");
	echo '<div class="mess">Запись успешно добавлена!<br />';
	mysql_query("INSERT INTO `blogs_records` (id_user,id_blog,title,text,time) VALUES (".$user['id'].",".$blog['id'].",'".protect($_POST['title'])."','".protect($_POST['text'])."',".time().")");
	echo '<a href="user.php?id='.$user['id'].'">Перейти &raquo;</a></div>';
	include '../style/'.$style.'/foot.php';
	exit;
}
echo '<div class="mess">
<form method="post" action="add_record.php"><div>
<b>Название записи</b>:<br/>
<input name="title" type="text" value=""/><br/>
<b>Текст записи</b>:<br/>
<textarea cols="22" rows="2" name="text" id="text"></textarea><br/>
<input value="Отправить" type="submit"/></div></form></div>';
echo '<div class="on2">
<img class="ico" src="../style/'.$style.'/ico/newpost.png" alt="" />
<a href="index.php">Дневники</a><br/>
</div>';
include '../style/'.$style.'/foot.php';
?>