<?
include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/user.php';

if (!isset($user)) {
header("Location: /index.php?".SID);
exit;
	}

$set[title]='Новая запись микроблога';
if (isset($_GET[ok])) {

$name=esc(stripcslashes(htmlspecialchars($_POST['name'])));
if (isset($_POST['translit1']) && $_POST['translit1']==1)$name=translit($name);
if (strlen2($name)<3)$err='Короткое название для темы';
if (strlen2($name)>256)$err='Название темы не должно быть длиннее 32-х символов';
$name=mysql_real_escape_string($name);

if (!isset($err)) {

mysql_query("UPDATE `user` SET `balls` = '".($user['balls']+1)."' WHERE `id` = '$user[id]' LIMIT 1");

mysql_query("INSERT INTO `microblog` (`id_user`, `name`, `msg`, `read`, `write`, `time`) values('$user[id]', '$name', '$msg', '$_POST[read]', '$_POST[write]', '$time')");
$dnev[id]=mysql_insert_id();

if ($_POST[read]!=2) {
$q = mysql_query("SELECT * FROM `fanat` WHERE `user` = '$user[id]' AND `i` = '1'");
while ($f = mysql_fetch_array($q))
{
$a = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '$f[frend]' LIMIT 1"));

$msg_lenta="Установил новый микроблог [url=/microblog/blog.php?id=$dnev[id]] $name [/url]";

mysql_query("INSERT INTO `lenta` (`id_user`, `id_kont`, `msg`, `time`) values('$user[id]', '$a[id]', '$msg_lenta', '$time')"); 
	}
	}
//mysql_query("UPDATE `user` SET `kol_blog` = '".($user['kol_blog']+1)."' WHERE `id` = '$user[id]' LIMIT 1");
header("Location: /microblog/blog.php?id=$dnev[id]".SID);
exit;

	}
	}

include_once '../sys/inc/thead.php';
title();
err();


echo "<div class='textmes'>";
echo "<form method='post' enctype='multipart/form-data'  action='?ok'>";
echo "Текст микроблога(3-256 символа):<br />\n";
echo "<input name='name' type='text' maxlength='256' value='$_POST[name]' /><br />\n";
if ($user['set_translit']==1)echo "<label><input type='checkbox' name='translit1' value='1' /> Транслит</label><br />\n";

echo "Пишут комментарии:<br />\n<select name='write'>\n";
echo "<option value='0'>Все</option>\n";
echo "<option value='1'>Друзья</option>\n";
echo "<option value='2'>Только я</option>\n";
echo "</select><br />\n";

echo "<input value='Создать' type='submit' /><br />\n";
echo "</form>\n";

echo "</div>\n";
include_once '../sys/inc/tfoot.php';
?>