Размер файла: 10.47Kb
<?php
// by Mike O. (mides), coolcms.mobi
$title = $lang['blogs'];
require_once 'system/sys.php';
require_once 'system/header.php';
$type = 'blogs';
switch ($act) {
default:
tp($lang['blogs']);
$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=note_add">'.$lang['compose'].'</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="?">'.$lang['blogs'].'</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';
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=note_edit&id='.$blog['id'].'">'.$lang['edit'].'</a>';
if ($u['access'] == 3) echo '/<a href="?act=note_del&id='.$blog['id'].'">Del</a>';
$comm = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `blogs_comm` WHERE `id_blogs` = '$blog[id]'"), 0);
echo '<br />'.$lang['comments'].': '.$comm.'<br />';
echo '</div>';
}
navig($page, '?act=cat&id='.$id.'&', $pages);
} else {
echo $lang['there_is_nothing_yet'];
}
nav('?');
} else {
redirect('?');
}
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 $lang['composed_by'].': <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'].'">'.$lang['comments'].'</a> ('.$comm.')<br />';
if ($u['id']) echo '<br />'.$lang['copy_link'].':<br /><input name="copy_link" type="text" value="'.HTTPHOME.'/blogs.php?act=view&id='.$blog['id'].'" /><br />';
echo $lang['bb_code_forum'].':<br /><input name="bb_code" type="text" value="[url='.HTTPHOME.'/blogs.php?act=view&id='.$blog['id'].']'.$blog['name'].'[/url]" /><br />';
if ($u['access'] > 1) echo '<br />- <a href="?act=note_edit&id='.$blog['id'].'">'.$lang['edit'].'</a><br />';
if ($u['access'] == 3) echo '- <a href="?act=note_del&id='.$blog['id'].'">'.$lang['delete'].'</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 {
redirect('?');
}
break;
case 'note_add':
if ($u['id']) {
$cats_r = mysql_query("SELECT * FROM `blogs_cats` ORDER BY `name`");
if (mysql_num_rows($cats_r)) {
if ($ok) {
if (!empty($_POST['name']) and !empty($_POST['text']) and !empty($_POST['code']) ) {
$code = abs(intval($_POST['code']));
if ($_SESSION['code'] == $code) {
$cat = abs(intval($_POST['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();
redirect('?act=view&id='.$last_id);
} else {
error('Неверный код.');
nav('?act=note_add');
}
} else {
redirect('?act=note_add');
}
} else {
tp($lang['compose']);
echo '<form name="form" action="?act=note_add&ok=1" method="post">
'.$lang['choose_a_category'].':<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 />
'.$lang['name'].'(max50):<br /><input name="name" type="text" maxlength="50" /><br />
'.bbpanel('form', 'text').'<textarea name="text" cols="" rows="5"></textarea><br />
Провер. код:<br />
<img src="inc/code.php" alt="" /><br />
<input name="code" maxlength="5" /><br />
<input name="submit" type="submit" value="Ok" />
</form>';
nav('?');
}
} else {
redirect('?');
}
} else {
redirect('?');
}
break;
case 'note_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'");
redirect('?act=view&id='.$id);
} else {
redirect('?act=note_edit&id='.$id);
}
} else {
tp($lang['edit']);
echo '<form name="form" action="?act=note_edit&id='.$id.'&ok=1" method="post">
'.$lang['name'].'(max50):<br /><input name="name" type="text" maxlength="50" value="'.$blog['name'].'" /><br />
'.bbpanel('form', 'text').'<textarea name="text" cols="" rows="5">'.$blog['text'].'</textarea><br />
<input name="submit" type="submit" value="Ok" />
</form>';
nav('?act=view&id='.$id);
}
} else {
redirect('?');
}
} else {
redirect('?');
}
break;
case 'note_del':
if ($u['access'] == 3) {
$blog = mysql_fetch_assoc(mysql_query("SELECT * FROM `blogs` WHERE `id` = '$id'"));
if ($blog['id']) {
if ($ok) {
mysql_query("DELETE FROM `blogs` WHERE `id` = '$blog[id]'");
redirect('?act=cat&id='.$blog['id_cat']);
} else {
tp($lang['confirmation']);
echo $lang['are_you_sure_del'].' "'.$blog['name'].'"?<br />
<form name="form" action="?act=note_del&id='.$id.'&ok=1" method="post">
<input name="submit" type="submit" value="Yeah" />
</form>';
nav2('?act=view&id='.$blog['id'], $lang['to_the_note']);
}
} else {
redirect('?');
}
} else {
redirect('?');
}
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';
?>