Размер файла: 7.61Kb
<?php
// by mides, 1da.su
$title = 'Блоги';
require_once 'system/sys.php';
require_once 'system/header.php';
$type = 'blogs';
switch ($act) {
default:
tp('Блоги');
$cats_r = mysql_query("SELECT * FROM `blogs_cats` ORDER BY `name`");
$mysql_num_rows = mysql_num_rows($cats_r);
if ($mysql_num_rows) {
while ($cat = mysql_fetch_assoc($cats_r)) {
$blogs = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `blogs` WHERE `id_cat` = '$cat[id]'"), 0);
echo '<a href="?act=cat&id='.$cat['id'].'">'.$cat['name'].'</a> ('.$blogs.')<br />';
}
} else {
echo 'Разделы не созданы.';
}
if ($u['id'] and $mysql_num_rows) echo '<br /><a href="?act=article_add">Написать</a>';
nav_main();
break;
case 'cat':
$cat = mysql_fetch_assoc(mysql_query("SELECT * FROM `blogs_cats` WHERE `id` = '$id'"));
if ($cat['id']) {
echo '<div class="title"><a href="?">Блоги</a> > '.$cat['name'].'</div><div class="list">';
$total = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `blogs` WHERE `id_cat` = '$id'"), 0);
if ($total > 0) {
$pages = ceil($total / $config['onpage']);
if ($page > $pages or $page == 0) {
$page = 1;
}
$begin = ($page - 1) * $config['onpage'];
$blogs_r = mysql_query("SELECT * FROM `blogs` WHERE `id_cat` = '$id' ORDER BY `time` DESC LIMIT $begin, $config[onpage]");
while ($blog = mysql_fetch_assoc($blogs_r)) {
if (!isset($num) ) $num = 1;
$num++;
$row_class = (!($num % 2)) ? 'row1' : 'row2';
//$comm = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `blogs_comm` WHERE `id_load` = '$load[id]'"), 0);
echo '<div class="'.$row_class.'">
<a href="?act=view&id='.$blog['id'].'">'.$blog['name'].'</a> ('.date('d.m.y, H:i', $blog['time']).')';
if ($u['access'] > 1) echo ' <a href="?act=article_edit&id='.$blog['id'].'">ред</a>';
if ($u['access'] == 3) echo '/<a href="?act=article_del&id='.$blog['id'].'">уд</a>';
//echo '<br />Комментарий: '.$comm.'<br />';
echo '</div>';
}
navig($page, '?act=cat&id='.$id.'&', $pages);
} else {
echo 'Пусто.';
}
nav('?');
} else {
error('Выбранный раздел не существует.');
nav_main();
}
break;
case 'article_add':
if ($u['id']) {
$cats_r = mysql_query("SELECT * FROM `blogs_cats` ORDER BY `name`");
if (mysql_num_rows($cats_r)) {
if (isset($_GET['ok'])) {
if ($_POST['name'] and $_POST['text']) {
$cat = intval($_REQUEST['cat']);
$name = check($_POST['name']);
$text = check($_POST['text']);
mysql_query("INSERT INTO `blogs` SET `id_cat` = '$cat', `id_user` = '$u[id]', `name` = '$name', `text` = '$text', `time` = '".time()."'");
$last_id = mysql_insert_id();
header('location: ?act=view&id='.$last_id);
} else {
error('Вы не заполнили поля.');
nav('?act=article_add');
}
} else {
tp('Написать статью');
echo '<form action="?act=article_add&ok=1" method="post">
Выбрать раздел:<br /><select name="cat">';
$cat_r = mysql_query("SELECT * FROM `blogs_cats` ORDER BY `name`");
while ($cat = mysql_fetch_assoc($cat_r)) {
echo '<option value="'.$cat['id'].'">'.$cat['name'].'</option>';
}
echo '</select><br />
Название(max50):<br /><input name="name" type="text" maxlength="50" /><br />
Описание:<br /><textarea name="text" cols="" rows="4"></textarea><br />
<input name="submit" type="submit" value="Ok" />
</form>';
nav('?');
}
} else {
header('location: ?');
exit;
}
} else {
header('location: ?');
exit;
}
break;
case 'view':
$blog = mysql_fetch_assoc(mysql_query("SELECT * FROM `blogs` WHERE `id` = '$id'"));
if ($blog['id']) {
tp($blog['name']);
echo bb($blog['text']).'<br />';
echo '<br />';
echo 'Добавлено: <a href="profile.php?id='.$blog['id_user'].'">'.login($blog['id_user']).'</a> ('.date('d.m.y, H:i', $blog['time']).')<br />';
$comm = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `blogs_comm` WHERE `id_blogs` = '$blog[id]'"), 0);
echo '<a href="?act=comm&id='.$blog['id'].'">Комментарии</a> ('.$comm.')<br />';
if ($u['id']) echo '<br />Скопировать адрес:<br /><input name="file" type="text" value="http://'.$config['copy'].'/blogs.php?act=view&id='.$blog['id'].'" /><br />';
echo 'BB-код для форума:<br /><input name="bb_code" type="text" value="[url=http://'.$config['copy'].'/blogs.php?act=view&id='.$blog['id'].']'.$blog['name'].'[/url]" /><br />';
if ($u['access'] > 1) echo '<br />- <a href="?act=article_edit&id='.$blog['id'].'">Редактировать</a><br />';
if ($u['access'] == 3) echo '- <a href="?act=article_del&id='.$blog['id'].'">Удалить</a><br />';
$cat = mysql_fetch_assoc(mysql_query("SELECT `name` FROM `blogs_cats` WHERE `id` = '$blog[id_cat]'"));
nav2('?act=cat&id='.$blog['id_cat'], $cat['name']);
} else {
error('Выбранная статья не существует.');
nav('?');
}
break;
case 'article_edit':
if ($u['access'] > 1) {
$blog = mysql_fetch_assoc(mysql_query("SELECT * FROM `blogs` WHERE `id` = '$id'"));
if ($blog['id']) {
if ($ok) {
if ($_POST['name'] and $_POST['text']) {
$name = check($_POST['name']);
$text = check($_POST['text']);
mysql_query("UPDATE `blogs` SET `name` = '$name', `text` = '$text' WHERE `id` = '$id'");
header('location: ?act=view&id='.$id);
} else {
header('location: ?act=artiсle_edit&id='.$id);
}
} else {
tp('Редактирование статью');
echo '<form action="?act=article_edit&id='.$id.'&ok=1" method="post">
Название(max50):<br /><input name="name" type="text" maxlength="50" value="'.$blog['name'].'" /><br />
Текст:<br /><textarea name="text" cols="" rows="5">'.$blog['text'].'</textarea><br />
<input name="submit" type="submit" value="Ok" />
</form>';
nav('?act=view&id='.$id);
}
} else {
error('Статья не существует.');
nav('?');
}
} else {
header('location: ?');
exit;
}
break;
case 'article_del':
if ($u['access'] == 3) {
$blog = mysql_fetch_assoc(mysql_query("SELECT * FROM `blogs` WHERE `id` = '$id'"));
if ($blog['id']) {
if (isset($_GET['ok'])) {
mysql_query("DELETE FROM `blogs` WHERE `id` = '$blog[id]'");
header('location: ?act=cat&id='.$blog['id_cat']);
exit;
} else {
tp('Подтверждение');
echo 'Вы действительно хотите удалить файл "'.$blog['name'].'"?<br />
<form action="?act=article_del&id='.$id.'&ok=1" method="post">
<input name="submit" type="submit" value="Yeah" />
</form>';
nav2('?act=view&id='.$blog['id'], 'К статье');
}
} else {
error('Статья не существует.');
nav('?');
}
} else {
header('location: ?');
exit;
}
break;
case 'comm':
require_once 'system/comm.php';
break;
case 'comm_add':
require_once 'system/comm_add.php';
break;
case 'comm_reply':
require_once 'system/comm_reply.php';
break;
case 'comm_edit':
require_once 'system/comm_edit.php';
break;
case 'comm_del':
require_once 'system/comm_del.php';
break;
}
require_once 'system/tail.php';
?>