<?
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($_GET['add']) && isset($user) && $user['level']>2)
{
$set['title']="Справка - Добавить запись";
include_once '../sys/inc/thead.php';:доб
title();
aut();
if(isset($_POST['ok']) && isset($_GET['ok']))
{
$title=$_POST['title'];
$msg=$_POST['msg'];
if(strlen2($title)<1)$err[]='<img src="/style/icons/err.png"/> Заголовок слишком короткий';
if(strlen2($title)>100)$err[]='<img src="/style/icons/err.png"/> Заголовок слишком длинный';
if(strlen2($msg)<1)$err[]='<img src="/style/icons/err.png"/> Сообщение слишком короткое';
if(!isset($err))
{
if (isset($_POST['translit']) && $_POST['translit']==1)$msg=translit($msg);
$pos=mysql_result(mysql_query("SELECT MAX(`pos`) FROM `ihelp`"), 0)+1;
mysql_query("INSERT INTO `ihelp` SET `title` = '$title', `msg` = '$msg', `pos` = '$pos'");
header("Location:?");
}
}
err();
echo "<form method='post' action='?add&ok'>";
echo "<img src='/style/icons/field.png'/> Заголовок:<br/>";
echo "<input type='text' name='title' value=''><br/>";
echo "<img src='/style/icons/field.png'/> Сообщение:<br/>";
echo "<textarea name='msg'></textarea><br/>";
if ($user['set_translit']==1)echo "<label><input type='checkbox' name='translit' value='1' /> Транслит</label><br />\n";
echo "<input type='submit' name='ok' value='Добавить'><br/>";
echo "</form>";
echo "<div class='foot'><img src='/style/icons/back.png'/> <a href='?'>Назад</a></div>";
include_once '../sys/inc/tfoot.php';
exit;
}
elseif(isset($_GET['edit']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `ihelp` WHERE `id` = '".intval($_GET['edit'])."'"),0)!=0 && isset($user) && $user['level']>2)
{
$edit=mysql_fetch_array(mysql_query("SELECT * FROM `ihelp` WHERE `id` = '".intval($_GET['edit'])."'"));
$set['title']="Справка - ".htmlspecialchars($edit['title'])." - Редактировать";
include_once '../sys/inc/thead.php';
title();
aut();
if(isset($_POST['ok']) && isset($_GET['ok']))
{
$title=$_POST['title'];
$msg=$_POST['msg'];
if(strlen2($title)<1)$err[]='<img src="/style/icons/err.png"/> Заголовок слишком короткий';
if(strlen2($title)>100)$err[]='<img src="/style/icons/err.png"/> Заголовок слишком длинный';
if(strlen2($msg)<1)$err[]='<img src="/style/icons/err.png"/> Сообщение слишком короткое';
if(!isset($err))
{
if (isset($_POST['translit']) && $_POST['translit']==1)$msg=translit($msg);
mysql_query("UPDATE `ihelp` SET `title` = '$title', `msg` = '$msg' WHERE `id` = '$edit[id]'");
header("Location:?id=$edit[id]");
}
}
err();
echo "<form method='post' action='?edit=$edit[id]&ok'>";
echo "<img src='/style/icons/field.png'/> Заголовок:<br/>";
echo "<input type='text' name='title' value='".htmlspecialchars($edit['title'])."'><br/>";
echo "<img src='/style/icons/field.png'/> Сообщение:<br/>";
echo "<textarea name='msg'>$edit[msg]</textarea><br/>";
if ($user['set_translit']==1)echo "<label><input type='checkbox' name='translit' value='1' /> Транслит</label><br />\n";
echo "<input type='submit' name='ok' value='Сохранить'><br/>";
echo "</form>";
echo "<div class='foot'><img src='/style/icons/back.png'/> <a href='?'>Назад</a></div>";
include_once '../sys/inc/tfoot.php';
exit;
}
elseif(isset($_GET['delete']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `ihelp` WHERE `id` = '".intval($_GET['delete'])."'"),0)!=0 && isset($user) && $user['level']>2)
{
$delete=mysql_fetch_array(mysql_query("SELECT * FROM `ihelp` WHERE `id` = '".intval($_GET['delete'])."'"));
$set['title']="Справка - ".htmlspecialchars($delete['title'])." - Удаление";
include_once '../sys/inc/thead.php';
title();
aut();
if(isset($_POST['ok']) && isset($_GET['ok']))
{
mysql_query("DELETE FROM `ihelp` WHERE `id` = '$delete[id]'");
mysql_query("DELETE FROM `ihelp_rating` WHERE `id_help` = '$delete[id]'");
header("Location:?");
}
elseif(isset($_POST['cancel']) && isset($_GET['ok']))header("Location:?id=$delete[id]");
echo '<img src="/style/icons/err.png"/> Подтвердите удаление<br/>';
echo "<form method='post' action='?delete=$delete[id]&ok'>";
echo "<input type='submit' name='ok' value='Удалить' style='width:30%'>";
echo "<input type='submit' name='cancel' value='Отменить' style='width:30%'>";
echo "</form>";
include_once '../sys/inc/tfoot.php';
exit;
}
elseif(isset($_GET['id']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `ihelp` WHERE `id` = '".intval($_GET['id'])."'"),0)!=0)
{
$help=mysql_fetch_array(mysql_query("SELECT * FROM `ihelp` WHERE `id` = '".intval($_GET['id'])."'"));
$set['title']="Справка - ".htmlspecialchars($help['title'])."";
include_once '../sys/inc/thead.php';
title();
aut();
if(isset($_GET['rating']) && isset($user))
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `ihelp_rating` WHERE `id_help` = '$help[id]' AND `id_user` = '$user[id]'"),0)==0)
{
if($_GET['rating']=='plus')
{
mysql_query("INSERT INTO `ihelp_rating` SET `id_help` = '$help[id]', `id_user` = '$user[id]', `rating` = '1'");
mysql_query("UPDATE `ihelp` SET `rating` = '".($help['rating']+1)."' WHERE `id` = '$help[id]'");
$help['rating']=$help['rating']+1;
msg("Ваш отзыв принят");
}
elseif($_GET['rating']=='minus')
{
mysql_query("INSERT INTO `ihelp_rating` SET `id_help` = '$help[id]', `id_user` = '$user[id]', `rating` = '-1'");
mysql_query("UPDATE `ihelp` SET `rating` = '".($help['rating']-1)."' WHERE `id` = '$help[id]'");
$help['rating']=$help['rating']-1;
msg("Ваш отзыв принят");
}
else $err[]='Неверная оценка';
}
else $err[]='Вы уже отдали свой голос';
}
echo "<div class='foot'><img src='/style/icons/help.png'/> <b>".htmlspecialchars($help['title'])."</b> ".(isset($user) && $user['level']>2?"<span style='float: right; font-size: small; color: grey'><a href='?edit=$help[id]'><img src='/style/icons/edit.png'/></a> <a href='?delete=$help[id]'><img src='/style/icons/delete.png'/></a></span>":null)."</div>";
echo "<div style='border-radius: 5px;margin: 1px;padding: 3px;border: 1px solid #e5e5e5;background:#f7f7f7'>".output_text($help['msg'])."</div>";
echo "<div style='padding:2px;background-color:#fff9d7;border-top:1px solid #e2c822;border-bottom:1px solid #e2c822'>\n";
$rating=$help['rating'];
echo "<img src='/style/icons/field.png'/> ".(mysql_result(mysql_query("SELECT COUNT(*) FROM `ihelp_rating` WHERE `id_help` = '$help[id]' AND `id_user` = '$user[id]'"),0)!=0?"Общая оценка: $rating":"Полезное сообщение? <a href='?id=$help[id]&rating=plus'>Да</a> <a href='?id=$help[id]&rating=minus'>Нет</a>")."</div>\n";
echo "<div class='foot'><img src='/style/icons/back.png'/> <a href='?'>Назад</a></div>";
include_once '../sys/inc/tfoot.php';
exit;
}
$set['title']="Справка";
include_once '../sys/inc/thead.php';
title();
aut();
if (isset($_GET['up']) && isset($user) && $user['level']>2)
{
$up=mysql_fetch_assoc(mysql_query("SELECT * FROM `ihelp` WHERE `id` = '".intval($_GET['up'])."' LIMIT 1"));
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `ihelp` WHERE `pos` < '$up[pos]' LIMIT 1"),0)!=0)
{
mysql_query("UPDATE `ihelp` SET `pos` = '".($up['pos'])."' WHERE `pos` = '".($up['pos']-1)."' LIMIT 1");
mysql_query("UPDATE `ihelp` SET `pos` = '".($up['pos']-1)."' WHERE `id` = '".intval($_GET['up'])."' LIMIT 1");
}
}
elseif (isset($_GET['down']) && isset($user) && $user['level']>2)
{
$down=mysql_fetch_assoc(mysql_query("SELECT * FROM `ihelp` WHERE `id` = '".intval($_GET['down'])."' LIMIT 1"));
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `ihelp` WHERE `pos` > '$down[pos]' LIMIT 1"),0)!=0)
{
mysql_query("UPDATE `ihelp` SET `pos` = '".($down['pos'])."' WHERE `pos` = '".($down['pos']+1)."' LIMIT 1");
mysql_query("UPDATE `ihelp` SET `pos` = '".($down['pos']+1)."' WHERE `id` = '".intval($_GET['down'])."' LIMIT 1");
}
}
$q=mysql_query("SELECT * FROM `ihelp` ORDER BY `pos` ASC");
if(mysql_num_rows($q)==0)echo "Список пуст";
$i=1;
while($post=mysql_fetch_array($q))
{
if(isset($num) && $num==1){
echo "<div class='p_t'>";
$num=0;
}else{
echo "<div style='border-radius: 1px;margin: 1px;padding: 1px;border: 1px solid #e5e5e5;background:#f7f7f7'>";
$num=1;}
echo "".$i.". <a href='?id=$post[id]'>".htmlspecialchars($post['title'])."</a>";
if(isset($_GET['moderate']) && isset($user) && $user['level']>2)echo "<a href='?moderate&up=$post[id]'><img src='/style/icons/up.png' alt='o'></a> <a href='?moderate&down=$post[id]'><img src='/style/icons/down.png' alt='o'></a>";
echo "</div>";
$i++;
}
if(isset($user) && $user['level']>2)echo "<div class='p_t'><a href='?add'>Добавить запись</a><br/><img src='/style/icons/settings.png'/> <a href='?".(!isset($_GET['moderate'])?"moderate":null)."'>Управление</a></div>";
include_once '../sys/inc/tfoot.php';
?>