Файл: gazeta/article.php
Строк: 120
<?
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';
include_once '../sys/inc/thead.php';
$art=mysql_fetch_array(mysql_query("SELECT * FROM `gazeta` WHERE `id` = '".intval($_GET['id'])."' LIMIT 1"));
$set['title']=''.htmlspecialchars($art['name']).'';
title();
$d = $_GET['d'];
aut();
$id=intval($_GET['id']);
if (!isset($_GET['d'])) {
header("Location: article.php?id=$id&d".SID); }
switch ($d) {
case 'del':
if ($user['level'] > 4 or $user['id'] == $art['id_user']) {
echo '<div class="err">Вы уверены?!<br /><a href="article.php?id='.$id.'&d=del_ok">Да</a> | <a href="article.php?id='.$id.'">Нет</a></div>';}
else {echo 'Вы не имеете право удалить это';}
break;
/////////////////////////
case 'del_ok':
if ($user['level'] > 4 or $user['id'] == $art['id_user']) {
mysql_query("DELETE FROM `gazeta` WHERE `id` = '" .$id. "'");
echo '<div class="foot">Статья успешно удалена <br /><a href="index.php">К категориям</a></div>'; }
break;
////////////////////////
case 'img':
$q=mysql_query("SELECT * FROM `gazeta` WHERE `id` = '".$id."'");
while ($res = mysql_fetch_assoc($q)) {
if ($user['level'] > 4 or $user['id'] == $art['id_user'])
{
if($_GET['d'] == "img")
{
if(isset($_GET['save']) && isset($_POST['ok']))
{
if (isset($_FILES['file']))
{
$type = $_FILES['file']['type'];
if ($type!=='image/jpeg' && $type!=='image/jpg' && $type!=='image/gif' && $type!=='image/png')$err='Это не картинка.';
}
if (!isset($err))
{
$tmp = $_FILES['file']['tmp_name'];
unlink(H.'gazeta/images/'.$res['id'].'.png');
move_uploaded_file($tmp,
H.'gazeta/images/'.$res['id'].'.png');
chmod(H.'gazeta/'.$res['id'].'.png', 0777);
header("location: ?id=$res[id]");
}
}
echo "<form method='post' action='?id=$res[id]&d=img&save' enctype='multipart/form-data'>";
echo "<b>Изображение:</b><br/>";
echo "<input type='file' name='file'/><br/>";
echo "<input value='Добавить' type='submit' name='ok' /><br />n";
echo "</form>";
}
}
}
break;
case 'rating':
$pokaz = mysql_result(mysql_query("SELECT * FROM `gazeta_rating` WHERE `id_user` = '$user[id]' AND `id_gazeta` = '".$id."' "),0);
if ($pokaz == 0){
mysql_query("INSERT INTO `gazeta_rating` (`id_gazeta`, `id_user`) values ('".$id."', '$user[id]')");
}
if ($pokaz != 0){
mysql_query("DELETE FROM `gazeta_rating` WHERE `id_user` = '$user[id]' AND `id_gazeta` = '".$id."'");
}
{header("Location: article.php?id=".$id."".SID);exit;}
break;
case 'zakl':
$zakl3=mysql_fetch_assoc(mysql_query("SELECT * FROM `gazeta` order by `time` desc limit 1 "));
$zakl2 = mysql_result(mysql_query("SELECT * FROM `gazeta_zakl` WHERE `id_user` = '$user[id]' AND `id_gazeta` = '".$id."' "),0);
if ($zakl2 == 0 and $id <= $zakl3['id']){
mysql_query("INSERT INTO `gazeta_zakl` (`id_gazeta`, `id_user`) values ('".$id."', '$user[id]')");
}
{header("Location: article.php?id=".$id."".SID);exit;}
break;
case 'zakl_del':
$zakl2 = mysql_result(mysql_query("SELECT * FROM `gazeta_zakl` WHERE `id_user` = '$user[id]' AND `id_gazeta` = '".$id."' "),0);
if ($zakl2 != 0){
mysql_query("DELETE FROM `gazeta_zakl` WHERE `id_user` = '$user[id]' AND `id_gazeta` = '".$id."'");
}
{header("Location: article.php?id=".$id."".SID);exit;}
break;
case 'edit':
if ($user['level'] > 4 or $user['id'] == $art['id_user']) {
echo '<div class="p_t"><form action="article.php?id='.$id.'&d=add" method="post">Название статьи:<br/>
<input type="text" name="name" value ="'.$art['name'].'"/><br/>Статья:<br/>
<textarea name="article">'.$art['article'].'</textarea><br/>
<input type="submit" value="Изменить"/></form></div>';
}
break;
//////////////////////////
case 'add':
if ($user['level'] > 4 or $user['id'] == $art['id_user']) {
$article=mysql_real_escape_string($_POST['article']);
$name=mysql_real_escape_string($_POST['name']);
if($name != NULL and $article != NULL){
mysql_query("UPDATE `gazeta` SET `name` = '".$name."' WHERE `id` = '$id' ");
mysql_query("UPDATE `gazeta` SET `article` = '".$article."' WHERE `id` = '$id' ");
header("Location: article.php?id=$id".SID);
}
else
{
echo '<div class="err">ОШИБКА!<br />Одно из полей заполнено неправильно!<br /><a href="cat.php?id='.$id.'&d=art">Назад</a></div>';
}
}
break;
default:
/// Вывод разделов
$q=mysql_query("SELECT * FROM `gazeta` WHERE `id` = '".$id."' ");
while ($res = mysql_fetch_assoc($q)) {
$cat=mysql_fetch_array(mysql_query("SELECT * FROM `gazeta_cat` WHERE `id` = '".$res['id_cat']."' LIMIT 1"));
echo '<div class="rekl"><a href="/gazeta">Все категории</a> <font color="black">| '.$cat['name'].'</font></div>';
if ($user['level'] > 4 or $user['id'] == $art['id_user']) {echo '<a href="article.php?id='.$res['id'].'&d=img"> <font color="red">Доб. фото</font></a>
|<a href="article.php?id='.$res['id'].'&d=del"> <font color="red"> Удалить</font></a>
|<a href="article.php?id='.$res['id'].'&d=edit"> <font color="red"> Изменить</font></a>
';
}
echo ' <div class="nav1"><img src ="img/art.png">'.output_text($res['name']).'</div>';
if(is_file(H.'gazeta/images/'.$res['id'].'.png')) echo '<div class ="rekl"><img src="/gazeta/images/'.$res['id'].'.png" alt="*" style="max-width:100%; border-bottom-left-radius: 20px;
border-bottom-right-radius: 20px; border-top-right-radius: 20px; border-top-left-radius: 20px;"/></div>';
echo ' <div class="mess">'.output_text($res['article']).'';
echo ' </div>';
$ank=get_user($res['id_user']);
if(isset($user['id'])){
$zakl = mysql_result(mysql_query("SELECT COUNT(*) FROM `gazeta_zakl` where `id_user` = '$user[id]' and `id_gazeta` = '$res[id]' "), 0);
if($zakl == 0){
echo'<div class="nav1"><img src="/style/icons/rekl.png" alt=""/> <a href="article.php?id='.$res['id'].'&d=zakl">В закладки</a> </div>';
}else{
echo'<div class="nav1"><img src="/style/icons/rekl.png" alt=""/> <a href="article.php?id='.$res['id'].'&d=zakl_del">Удалить из закладки</a> </div>';
}
}
echo'<div class="nav1"><img src="img/date.png" alt=""/> Добавлено: <b>'.vremja($res['time']).'</b> </div>';
echo'<div class="nav1"><img src="img/user.png" alt=""/> Добавил: <a href="/info.php?id='.$ank['id'].'"><b> '.$ank['nick'].'</b></a> </div>';
$pokz = mysql_result(mysql_query("SELECT COUNT(*) FROM `gazeta_views` WHERE `id_gazeta` = '".$id."' LIMIT 1"),0);
echo '<div class="nav1"><img src="img/read.png" alt=""/> Читали: <a href="views.php?id='.$id.'"><b>'.$pokz.'</b></a></div>';
$pokaz = mysql_result(mysql_query("SELECT * FROM `gazeta_views` WHERE `id_user` = '$user[id]' AND `id_gazeta` = '".$id."' "),0);
if ($pokaz == 0){
mysql_query("INSERT INTO `gazeta_views` (`id_gazeta`, `id_user`) values ('".$id."', '$user[id]')");
}
$like = mysql_result(mysql_query("SELECT COUNT(*) FROM `gazeta_rating` WHERE `id_gazeta` = '".$id."' LIMIT 1"),0);
echo "<div class='nav1'><img src='img/good.png' alt''/> <a href='article.php?id=".$id."&d=rating'>Голосовать: </a>
<b><a href='rating.php?id=".$id."'>".$like."</b></a></div> ";
}
$comm = mysql_result(mysql_query("SELECT COUNT(*) FROM `gazeta_komm` WHERE `id_gazeta` = '".$id."' LIMIT 1"),0);
echo "<div class='nav1'> <a href='komm.php?id=".$id."'><img src='img/komm.gif' alt=''/> Комментарии</a> <b>(".$comm.")</b></div> ";
}
err();
include_once '../sys/inc/tfoot.php';
?>