<?
$sum_num=1;
if(intval($_GET['gazeta'])!=NULL && mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_gazeta` WHERE `id` = '".intval($_GET['gazeta'])."'"),0)!=0)$gazeta=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_gazeta` WHERE `id` = '".intval($_GET['gazeta'])."'"));
if(isset($gazeta) && $gazeta['type']=='tema')
{
$fk=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_gazeta` WHERE `type` = 'komm' AND `mother` = '$gazeta[id]' ORDER BY `time` ASC LIMIT 1"));
$mother=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_gazeta` WHERE `id` = '$gazeta[mother]'"));
if($mother['locked']==1 && $ku['status']<=0)header("Location:?gazeta");
if(isset($_GET['edit']) && $ku['status']>0)
{
echo '<div class="event"><h1>Редактирование статьи</h1></div>';
if($_GET['edit']=='ok')
{
$name=$_POST['name'];
$msg=$_POST['msg'];
if($name==NULL)
{
echo err_game("Слишком короткое название");
$err=1;
}
if($msg==NULL)
{
echo err_game("Слишком короткое сообщение");
$err=1;
}
if(!isset($err))
{
mysql_querll("UPDATE `kolhoz_gazeta` SET `name` = '".my_esc($name)."', `msg` = '".my_esc($msg)."', `visit` = ',".$ku['id']."' WHERE `id` = '$gazeta[id]'");
mysql_querll("UPDATE `kolhoz_gazeta` SET `msg` = '".my_esc($msg)."' WHERE `id` = '$fk[id]'");
mysql_querll("UPDATE `kolhoz_gazeta` SET `visit` = ',".$ku['id']."' WHERE `id` = '".$gazeta['mother']."'");
header("Location:?gazeta=$gazeta[id]");
exit;
}
}
echo '<div class="content"><div class="block">';
echo "<form action='?gazeta=$gazeta[id]&edit=ok' method='post'><ul><li><label><div>Заголовок:</div><div><input type='text' class='wide' value='".hsc($gazeta['name'])."' name='name'></div></label></li><li><label><div>Содержимое: <a href='?teg'>Теги</a> | <a href='?smiles'>Смайлы</a></div><div><textarea class='wide' rows='5' name='msg'>".hsc($gazeta['msg'])."</textarea></div></label></li><li><input type='submit' value='Сохранить'></li></ul></form></div>";
include_once 'inc/foot.php';
}
elseif(isset($_GET['lock']) && $ku['status']>0)
{
mysql_querll("UPDATE `kolhoz_gazeta` SET `locked` = '".($gazeta['locked']==1?"0":"1")."' WHERE `id` = '$gazeta[id]'");
header("Location:?gazeta=$gazeta[id]");
}
elseif(isset($_GET['pin']) && $ku['status']>0)
{
mysql_querll("UPDATE `kolhoz_gazeta` SET `pined` = '".($gazeta['pined']==1?"0":"1")."' WHERE `id` = '$gazeta[id]'");
header("Location:?gazeta=$gazeta[id]");
}
elseif(isset($_GET['del']) && $ku['status']>0)
{
if($_GET['del']=='ok')
{
mysql_querll("delete from `kolhoz_gazeta` where `mother` = '$gazeta[id]' and `type` = 'komm'");
mysql_querll("delete from `kolhoz_gazeta` where `id` = '$gazeta[id]' and `type` = 'tema'");
header("Location:?gazeta=$mother[id]");
}
else echo '<div class="event"><h1>Подтверждение</h1></div><div class="content"><div class="block"><ul class="block"><li><span class="title">Вы уверены?</span></li><li class="pt"><img alt="" width="16" height="16" src="img/icons/tick.png"> <a href="?gazeta='.$gazeta['id'].'&del=ok"><span>
Да, подтверждаю</span></a></li><li><img alt="" width="16" height="16" src="img/icons/cross.png"> <a href="?gazeta='.$gazeta['id'].'"><span>
Нет, отказываюсь</span></a></li></ul></div>';
include_once 'inc/foot.php';
}
elseif(isset($_GET['del_komm']) && intval($_GET['del_komm'])!=NULL && mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_gazeta` WHERE `id` = '".intval($_GET['del_komm'])."' AND `type` = 'komm' AND `id` != '$fk[id]'"),0)!=0 && $ku['status']>0)
{
mysql_querll("delete from `kolhoz_gazeta` where `mother` = '$gazeta[id]' and `type` = 'komm' and `id` = '".intval($_GET['del_komm'])."'");
header("Location:?gazeta=$gazeta[id]");
}
else
{
echo "<div class='event'><h1>« <a href='?gazeta'>Газета</a> | <a href='?gazeta=$mother[id]'>".hsc($mother['name'])."</a> | <b>".hsc($gazeta['name'])."</b></h1></div>";
echo "<div class='content'><div class='block'>";
if($ku['status']>0)echo " <a href='?gazeta=$gazeta[id]&lock'><span>".($gazeta['locked']==0?"За":"От")."крыть</span></a> | ";
if($ku['status']>0)echo " <a href='?gazeta=$gazeta[id]&pin'><span>".($gazeta['pined']==0?"За":"От")."крепить</span></a> | ";
if($ku['status']>0)echo " <a href='?gazeta=$gazeta[id]&moderate".(!isset($_GET['replace'])?"&replace":null)."'>Перенести</a> | ";
if($ku['status']>0)echo " <a href='?gazeta=$gazeta[id]&edit'>Изменить</a> | ";
if($ku['status']>0)echo " <a href='?gazeta=$gazeta[id]&del'>Удалить</a>";


echo "</div></div>";
{
$otv=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_user` WHERE `id` = '".intval($_GET['otv'])."'"));
$otvu=$otv;
}
if(isset($_GET['add']) && $_GET['add']=='ok' && $gazeta['locked']==0 && !isset($molchi))
{
$msg=$_POST['msg'];
if($msg==NULL)
{
echo err_game("Слишком короткое сообщение");
$err=1;
}
if($ku['level']<=15)
{
$err=1;
err_game("Писать в газете можно после того как достигните 15-го уровня!");
}
if($ku['time']<=3600*1)
{
$err=1;
err_game("Писать в газете можно после того как проведете в игре <b>1 часа</b>");
}


if($ku['almaz']<=1)
{
$err=1;
err_game("У вас не хватает баксов");
}

if(!isset($err))
{
mysql_query("UPDATE `kolhoz_user` SET `almaz` = '".($ku['almaz']+1)."' WHERE `id` = '$ku[id]' LIMIT 1");
mysql_querll("INSERT INTO `kolhoz_gazeta` SET `msg` = '".my_esc($msg)."', `id_user` = '$ku[id]', `type` = 'komm', `mother` = '$gazeta[id]', `time` = '$time'".(isset($otv)?", `otvet` = '$otv[id]'":null)."");
mysql_querll("UPDATE `kolhoz_gazeta` SET `time_obnov` = '$time', `visit` = ',".$ku['id']."' WHERE `id` = '$gazeta[id]'");
$for_raz=mysql_fetch_array(mysql_querll("SELECT * FROM kolhoz_gazeta WHERE id='".$gazeta['id']."'"));
mysql_querll("UPDATE `kolhoz_gazeta` SET `visit` = ',".$ku['id']."' WHERE `id` = '".$for_raz['mother']."'");
mysql_querll("UPDATE `kolhoz_user` SET `money` = '".($ku['money']+10)."' WHERE `id` = '$ku[id]' LIMIT 1");
mysql_querll("UPDATE `kolhoz_user` SET `gazetapost` = '".($ku['gazetapost']+1)."' WHERE `id` = '$ku[id]' LIMIT 1");
header("Location:?gazeta=".$gazeta['id']."&page=end");
exit;
}
}
//======================================//
$visit=mysql_fetch_array(mysql_querll("SELECT * FROM kolhoz_gazeta WHERE id='".$gazeta['id']."'"));
$visit_array=explode(',',$visit['visit']);
$visit_num=count($visit_array)+$sum_num;
if(!in_array($ku['id'],$visit_array)){
$visit_array[$visit_num]=$ku['id'];
mysql_querll("UPDATE kolhoz_gazeta SET visit='".implode(',',$visit_array)."' WHERE id='".$gazeta['id']."'");
}
//======================================//
if($_GET['dav']==1){echo '1';}
echo "<div class='content'><div class='block'>";
$k_post = mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_gazeta` WHERE `type` = 'komm' AND `mother` = '$gazeta[id]'"),0);
if ($k_post==0)
{
echo "Список пуст...";
}

$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];

$q=mysql_querll("SELECT * FROM `kolhoz_gazeta` WHERE `type` = 'komm' AND `mother` = '$gazeta[id]' ORDER BY `time` ASC LIMIT $start, $set[p_str]");
while($post=mysql_fetch_array($q))
{
/*$ank=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_user` WHERE `id` = '$post[id_user]'"));
$anku=$ank;
//===
*/
//=====
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '$post[id_user]'"));






//echo "<span class='small'><span>";
echo "<div class='block'>";

echo on_k($ank['id']);
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '$post[id_user]'"));

if($post['otvet']!=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_user` WHERE `id` = '$post[otvet]'"),0)!=0)
{
$ot=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '$post[otvet]'"));
}

if($ank['id']==$ank[id])
if($mcu['status']<=3)echo "";

echo "<a class='' href='?user=$ank[id]'>".nc($ank['id'])."</a></span>";
echo " ".med($ank['id'])."";
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_user` WHERE `id` = '$ank[id]' AND `date_last` > '".(time()-600)."' LIMIT 1"),0)==1)
echo " <img src='img/icons/online.gif' alt='' class='*'/>";echo " ";
//===

$ban = mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_ban` WHERE `id_user` = '$ank[id]' AND (`time` > '$time' OR `izg` = '1') ORDER BY `id` DESC LIMIT 1"));
$us_ban = mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_user` WHERE `id` = '$ban[id_who]'"));

if($ban['id']){
echo "".($ban['izg']==1?'<br/><font color="tomato">Сообщение заблокировано</font>':"<br/><font color='tomato'>Сообщение заблокировано до:</font> <b>".vremja($ban['time']))."</b><br/>";
}
else
if($ank['id']){

//echo " <span class='minor'><span>".vremja($post['time'])."</span></span></span><p>".(isset($otvet)?"".($ku['id']==$otvet['id']?"<span class='rare'>":null)."$otvetu[nick]".($ku['id']==$otvet['id']?"</span>":null).", ":null)."".output_text($post['msg'], $ank['id'])."</p><span class='small'>".($fk['id']!=$post['id']?"".($gazeta['locked']==0?"".($ank['id']!=$ku['id']?"<a href='?gazeta=$gazeta[id]&otv=$ank[id]'>[ответить]</a>":null)."":null)."":null)."";
echo "<br/><span class='minor small'> ".vremja($post['time'])."</span><br/>".(!empty($post['otvet'])?"".($ku['id']==$ot['id']?"<span class='rare'>":null)."$ot[nick]".($ku['id']==$ot['id']?"</span>":null).", ":null)."".output_text($post['msg'], $ank['id'])."</br>".($ank['id']!=$ku['id']?"<a class='small minor' href='?gazeta=$gazeta[id]&otv=$ank[id]'>[ответить]</a>":null)."";

}

//=====
if($ku['status']>0 && $post['id']!=$fk['id'])echo " <a class='small minor' href='?gazeta=$gazeta[id]&del_komm=$post[id]'>[удалить]</a></div>";
if($post['id']==$gazeta['id']+1){echo "<hr color='#114411' size='1'>";}else{echo "";}
}
/*
if($ban['id'])
{
echo "<li class='major'><span>".($ban['izg']==1?'':"Обет Молчания до ".vremja($ban['time']))."</span>, выдал".($us_ban['pol']==0?'a':null)." <span>";
echo on_k($us_ban['id']);
echo "<a href='?user=$us_ban[id]'>".nc($us_ban['id'])."</a></span><span>, (".output_text($ban['msg']).")</span></li></div></ul>";
}
else
*/
{
if($ku['level']>=15)
{
$for_net=1;
if ($k_page>1){str("?gazeta=$gazeta[id]&",$k_page,$page); echo"<br/>";} // Вывод страниц


if($gazeta['locked']==0)echo "<form action='?gazeta=$gazeta[id]&add=ok".(isset($otv)?"&otv=$otv[id]":null)."' method='post'><ul><li><label><div>Комментарий".(isset($otv)?" для $otvu[nick]":null)."</br>Вставить: <a href='?teg'>Теги</a> | <a href='?smiles'>Смайлы</a></div><div><textarea class='wide' rows='5' name='msg'></textarea></div></label></li><li><input type='submit' value='Написать'></li></ul></form>";

//if($gazeta['locked']==0)echo "<form action='?gazeta=$gazeta[id]&add=ok".(isset($otv)?"&otv=$otv[id]":null)."' method='post'><ul><li><label><div>Комментарий".(isset($otv)?" для $otvu[nick]":null)."</div><div><textarea class='wide' rows='5' name='msg'></textarea></div></label></li><input type='submit' value='Написать'> <font color='#33FFCC'>+1<img src='img/icons/baks.png' alt='*'/></font></form>";
else echo "<div class='pt minor'>Комментирование статьи запрещенно.</div>";
}
else
{
$for_net=1;
if ($k_page>1){str("?gazeta=$gazeta[id]&",$k_page,$page);} // Вывод страниц
echo "<br><font color='yellow'>Писать в газете можно только с 15 уровня.</font>";
}
}
if($for_net!=1){
if ($k_page>1)str("?gazeta=$gazeta[id]&",$k_page,$page); // Вывод страниц
}
echo "</div>";
{
echo "<div class='block'>";
//if($ku['status']>0)echo "<li><img alt='o' width='16' height='16' src='img/icons/gazeta_close.png'> <a href='?gazeta=$gazeta[id]&lock'><span>".($gazeta['locked']==0?"За":"От")."крыть</span></a></li>";
//if($ku['status']>0)echo "<li><img alt='o' width='16' height='16' src='img/icons/gazeta_pin.png'> <a href='?gazeta=$gazeta[id]&pin'><span>".($gazeta['pined']==0?"При":"От")."крепить</span></a></li>";
//if($ku['status']>0)echo "<li><img alt='o' width='16' height='16' src='img/icons/gazeta_move.png'> <a href='?gazeta=$gazeta[id]&moderate".(!isset($_GET['replace'])?"&replace":null)."'>Перенести</a><br></li>";
if(isset($_GET['replace']))
{
if($_GET['replace']=='ok' && mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_gazeta` WHERE `id` = '".intval($_POST['gazeta'])."' AND `type` = 'razdel'"),0)!=0)
{
mysql_querll("UPDATE `kolhoz_gazeta` SET `mother` = '".intval($_POST['gazeta'])."' WHERE `id` = '$gazeta[id]'");
header("Location:?gazeta=$gazeta[id]");
}
echo "<li>";
echo "<form method='post' action='?gazeta=$gazeta[id]&moderate&replace=ok'><div>Перенос топика \"<span>".hsc($gazeta['name'])."</span>\"</div><label>Новый раздел<br>";
echo "<select name='gazeta'>";
$q=mysql_querll("SELECT * FROM `kolhoz_gazeta` WHERE `id` != '$mother[id]' AND `type` = 'razdel'");
while($post=mysql_fetch_array($q))
{
echo "<option value='$post[id]'>".hsc($post['name'])."</option>";
}
echo "</label><br><input type='submit' value='Перенести'></form></li>";
}
}
//if($ku['status']>0)echo "<li><img alt='o' width='16' height='16' src='img/icons/delete.png'> <a href='?gazeta=$gazeta[id]&del'>Удалить</a></li>";
//if($ku['status']>0)echo "<li><img alt='o' width='16' height='16' src='img/icons/gazeta_edit.png'> <a href='?gazeta=$gazeta[id]&edit'>Изменить</a></li>";

echo "</ul></div>";
include_once 'inc/foot.php';
}
}
elseif(isset($gazeta) && $gazeta['type']=='razdel' && ($gazeta['locked']==1 && $ku['status']>0 || $gazeta['locked']==0))
{
if(isset($_GET['add']) && !isset($molchi) && $ku['level']>=10 && ($gazeta['admod']==1 && $ku['status']>0 || $gazeta['admod']==0))
{
echo '<div class="event"><h1>Создание статьи</h1></div>';
if($_GET['add']=='ok')
{
$name=$_POST['name'];
$msg=$_POST['msg'];
if($name==NULL)
{
echo err_game("Слишком короткое название");
$err=1;
}
if($msg==NULL)
{
echo err_game("Слишком короткое сообщение");
$err=1;
}
if(!isset($err))
{
mysql_querll("INSERT INTO `kolhoz_gazeta` SET `name` = '".my_esc($name)."', `msg` = '".my_esc($msg)."', `id_user` = '$ku[id]', `type` = 'tema', `mother` = '$gazeta[id]', `time` = '$time', `time_obnov` = '$time'");
$id=mysql_insert_id();
mysql_querll("INSERT INTO `kolhoz_gazeta` SET `msg` = '".my_esc($msg)."', `id_user` = '$ku[id]', `type` = 'komm', `mother` = '$id', `time` = '$time'");
mysql_querll("UPDATE `kolhoz_gazeta` SET `visit` = ',".$ku['id']."' WHERE `id` = '".$gazeta['id']."'");
header("Location:?gazeta=$id");
exit;
}
}
echo '<div class="content"><div class="block">';
echo "<form action='?gazeta=$gazeta[id]&add=ok' method='post'><ul><li><label><div>Заголовок:</div><div><input type='text' class='wide' value='' name='name'></div></label></li><li><label><div>Содержимое: <a href='?teg'>Теги</a> | <a href='?smiles'>Смайлы</a></div><div><textarea class='wide' rows='5' name='msg'></textarea></div></label></li><li><input type='submit' value='Создать статью'></li></ul></form></div>";
include_once 'inc/foot.php';
}
elseif(isset($_GET['edit']) && $ku['status']>0)
{
echo '<div class="event"><h1>Редактирование категории</h1></div>';
if($_GET['edit']=='ok')
{
$name=$_POST['name'];
if($name==NULL)
{
echo err_game("Слишком короткое название");
$err=1;
}
if(!isset($err))
{
if($_POST['admod']==1)$admod=1;else $admod=0;
if($_POST['locked']==1)$locked=1;else $locked=0;
mysql_querll("UPDATE `kolhoz_gazeta` SET `name` = '".my_esc($name)."', `admod` = '$admod', `locked` = '$locked' WHERE `id` = '$gazeta[id]'");
header("Location:?gazeta=$gazeta[id]");
exit;
}
}
echo '<div class="content"><div class="block">';
echo "<form action='?gazeta=$gazeta[id]&edit=ok' method='post'><ul><li><label><div>Название:</div><div><input type='text' class='wide' value='".hsc($gazeta['name'])."' name='name'></div></label></li>";
echo "<input type='checkbox' name='admod' value='1'".($gazeta['admod']==1?" checked='checked'":null)."> <span>Писать статьи могут только админы (НЕ ставьте галочку если хотите сделать пользовательскую газету) тойсть раздел газеты написанный простыми игроками</span><br/>";
echo "<input type='checkbox' name='locked' value='1'".($gazeta['locked']==1?" checked='checked'":null)."> <span>Только для администрации</span><br/>";
echo "<li><input type='submit' value='Сохранить'></li></ul></form></div>";
include_once 'inc/foot.php';
}
elseif(isset($_GET['del']) && $ku['status']>0)
{
if($_GET['del']=='ok')
{
$q=mysql_querll("SELECT * FROM `kolhoz_gazeta` WHERE `mother` = '$gazeta[id]' AND `type` = 'tema'");
while($post=mysql_fetch_array($q))
{
mysql_querll("delete from `kolhoz_gazeta` where `mother` = '$post[id]' and `type` = 'komm'");
mysql_querll("delete from `kolhoz_gazeta` where `id` = '$post[id]'");
}
$links = mysql_querll("SELECT * FROM `kolhoz_gazeta` WHERE `type` = 'razdel' AND `pos` > '$gazeta[pos]' ORDER BY `pos` ASC");
while ($p = mysql_fetch_array($links))
{
mysql_querll("UPDATE `kolhoz_gazeta` SET `pos` = '".($p['pos']-1)."' WHERE `id` = '$p[id]' LIMIT 1");
}
mysql_querll("delete from `kolhoz_gazeta` where `id` = '$gazeta[id]' and `type` = 'razdel'");
header("Location:?gazeta");
}
else echo '<div class="event"><h1>Подтверждение</h1></div><div class="content"><div class="block"><li><span class="title">Вы уверены?</span></li><li class="pt"><img alt="" width="16" height="16" src="img/icons/tick.png"> <a href="?gazeta='.$gazeta['id'].'&del=ok"><span>
Да, подтверждаю</span></a></li><li><img alt="" width="16" height="16" src="img/icons/cross.png"> <a href="?gazeta='.$gazeta['id'].'"><span>
Нет, отказываюсь</span></a></li></div></div>';
include_once 'inc/foot.php';
}
else
{
echo "<div class='event'><h1>« <a href='?gazeta'>Газета</a> | <b>".hsc($gazeta['name'])."</b></h1></div>";//топики
echo '<div class="content"><div class="block"><ul>';
if($ku['status']>0)echo "<div class='block'><a href='?gazeta=$gazeta[id]&edit'>Изменить</a> | ";
if($ku['status']>0)echo "<a href='?gazeta=$gazeta[id]&del'>Удалить</a></div>";
if($ku['level']>=10 && ($gazeta['admod']==1 && $ku['status']>0 || $gazeta['admod']==0))echo "<img src='img/gazeta/add.gif' alt='*' title='*'> <a href='?gazeta=$gazeta[id]&add'>Создать статью</a> | ";
echo "<a href='?gazeta=".$gazeta['id']."&proshit'>Отметить как прочитанное</a>";

$k_post = mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_gazeta` WHERE `type` = 'tema' AND `mother` = '$gazeta[id]'"),0);
if ($k_post==0)
{
echo "</br>В газете пусто...";
}
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
$q=mysql_querll("SELECT * FROM `kolhoz_gazeta` WHERE `type` = 'tema' AND `mother` = '$gazeta[id]' ORDER BY `pined` DESC, `time_obnov` DESC LIMIT $start, $set[p_str]");

//======================================//
$visit=mysql_fetch_array(mysql_querll("SELECT * FROM kolhoz_gazeta WHERE id='".$gazeta['id']."'"));
$visit_array=explode(',',$visit['visit']);
$visit_num=count($visit_array)+$sum_num;
if(!in_array($ku['id'],$visit_array)){
$visit_array[$visit_num]=$ku['id'];
mysql_querll("UPDATE kolhoz_gazeta SET visit='".implode(',',$visit_array)."' WHERE id='".$gazeta['id']."'");
}
//======================================//

if(isset($_GET['proshit'])){
while($post=mysql_fetch_array($q))
{
$visit_array=explode(',',$post['visit']);
$visit_num=count($visit_array)+$sum_num;
if(!in_array($ku['id'],$visit_array)){
$visit_array[$visit_num]=$ku['id'];
mysql_querll("UPDATE kolhoz_gazeta SET visit='".implode(',',$visit_array)."' WHERE id='".$post['id']."'");
}
}
header("Location:?gazeta=".$gazeta['id'].""); exit;
}

/////===========================================================================================//
/*
while($post=mysql_fetch_array($q))
{
echo "<div class='block'>"; 
$visit_array=explode(',',$post['visit']);
$visit_num=count($visit_array)+$sum_num;
if(!in_array($ku['id'],$visit_array)){echo"<img width='16' height='16' src='img/gazeta/on.png' alt='x' title='x'>";
} else {
if($post['locked']==1){echo"<img width='16' height='16' src='img/gazeta/zak.png' alt='x' title='x'>";
} else {
echo"<img width='16' height='16' src='img/gazeta/of.png' alt='*' title='*'>";
}
}
echo" <a href='?gazeta=$post[id]'><span style='font-weight:bold'>".hsc($post['name'])."</span></a>";
echo'</div>';
}
*/




while($post=mysql_fetch_array($q))
{
echo "<div class='block'>"; 
$visit_array=explode(',',$post['visit']);
$visit_num=count($visit_array)+$sum_num;
if(!in_array($ku['id'],$visit_array)){echo"<img width='16' height='16' src='img/gazeta/on.png' alt='x' title='x'>";
} else {
if($post['locked']==1){echo"<img width='16' height='16' src='img/gazeta/del.png' alt='x' title='x'>";
} else {
if($post['pined']==1){echo"<img width='16' height='16' src='img/gazeta/zak.png' alt='x' title='x'>";
} else {
echo"<img width='16' height='16' src='img/gazeta/of.png' alt='*' title='*'>";
}
}
}
echo" <a href='?gazeta=$post[id]'><span style='font-weight:bold'>".hsc($post['name'])."</span></a>";
echo'</div>';
}





if ($k_page>1)str("?gazeta=$gazeta[id]&",$k_page,$page); // Вывод страниц
echo "</ul>";
//echo "<ul class='pt'>";
echo "<li></li>";
if($ban['id'])
{
echo "<div>
<li class='major'><span>".($ban['izg']==1?'Изгнание':"Обет Молчания до ".vremja($ban['time']))."</span>, выдал".($us_ban['pol']==0?'a':null)." <span>";
echo on_k($us_ban['id']);
echo "<a href='?user=$us_ban[id]'>".nc($us_ban['id'])."</a></span><span>, (".output_text($ban['msg']).")</span></li></div></ul>";
}
//elseif($ku['level']>=10 && ($gazeta['admod']==1 && $ku['status']>0 || $gazeta['admod']==0))echo "<li><img width='16' height='16' src='img/icons/gazeta_topic.png' alt='*' title='*'> <a href='?gazeta=$gazeta[id]&add'>Создать топик</a></li>";
//echo "<li><img width='16' height='16' src='img/icons/tick.png' alt='*' title='*'> <a href='?gazeta=".$gazeta['id']."&proshit'>Отметить все как прочитанное</a></li>";
//if($ku['status']>0)echo "<li><img alt='o' width='16' height='16' src='img/icons/delete.png'> <a href='?gazeta=$gazeta[id]&del'>Удалить</a></li>";
//if($ku['status']>0)echo "<li><img alt='o' width='16' height='16' src='img/icons/gazeta_edit.png'> <a href='?gazeta=$gazeta[id]&edit'>Изменить название</a></li>";
echo "</div>";
include_once 'inc/foot.php';
}
}
else
{
if(isset($_GET['add']) && $ku['status']>0)
{
echo '<div class="event"><h1>Создание категории</h1></div>';
if($_GET['add']=='ok')
{
$name=$_POST['name'];
if($name==NULL)
{
echo err_game("Слишком короткое название");
$err=1;
}
if(!isset($err))
{
if($_POST['admod']==1)$admod=1;else $admod=0;
$pos=mysql_result(mysql_querll("SELECT MAX(`pos`) FROM `kolhoz_gazeta` WHERE `type` = 'razdel'"), 0)+1;
mysql_querll("INSERT INTO `kolhoz_gazeta` SET `name` = '".my_esc($name)."', `id_user` = '$ku[id]', `type` = 'razdel', `mother` = '0', `time` = '$time', `admod` = '$admod', `pos` = '$pos', `locked` = '".($_POST['locked']==1?"1":"0")."'");
header("Location:?gazeta");
exit;
}
}
echo '<div class="content"><div class="block">';
echo "<form action='?gazeta&add=ok' method='post'><ul><li><label><div>Название:</div><div><input type='text' class='wide' value='' name='name'></div></label></li>";
echo "<input type='checkbox' name='admod' value='1'> <span>Писать статьи могут только админы (НЕ ставьте галочку если хотите сделать пользовательскую газету) тойсть раздел газеты написанный простыми игроками</span><br/>";
echo "<input type='checkbox' name='locked' value='1'> <span>Только для администрации</span><br/>";
echo "<li><input type='submit' value='Создать'></li></ul></form></div></div>";
include_once 'inc/foot.php';
}
else
{
if (isset($_GET['up']) && $ku['status']>0)
{
$up=mysql_fetch_assoc(mysql_querll("SELECT * FROM `kolhoz_gazeta` WHERE `id` = '".intval($_GET['up'])."' AND `type` = 'razdel' LIMIT 1"));
if(mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_gazeta` WHERE `pos` < '$up[pos]' AND `type` = 'razdel' LIMIT 1"),0)!=0)
{
mysql_querll("UPDATE `kolhoz_gazeta` SET `pos` = '".($up['pos'])."' WHERE `pos` = '".($up['pos']-1)."' AND `type` = 'razdel' LIMIT 1");
mysql_querll("UPDATE `kolhoz_gazeta` SET `pos` = '".($up['pos']-1)."' WHERE `id` = '".intval($_GET['up'])."' AND `type` = 'razdel' LIMIT 1");
}
}
elseif (isset($_GET['down']) && $ku['status']>0)
{
$down=mysql_fetch_assoc(mysql_querll("SELECT * FROM `kolhoz_gazeta` WHERE `id` = '".intval($_GET['down'])."' AND `type` = 'razdel' LIMIT 1"));
if(mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_gazeta` WHERE `pos` > '$down[pos]' AND `type` = 'razdel' LIMIT 1"),0)!=0)
{
mysql_querll("UPDATE `kolhoz_gazeta` SET `pos` = '".($down['pos'])."' WHERE `pos` = '".($down['pos']+1)."' AND `type` = 'razdel' LIMIT 1");
mysql_querll("UPDATE `kolhoz_gazeta` SET `pos` = '".($down['pos']+1)."' WHERE `id` = '".intval($_GET['down'])."' AND `type` = 'razdel' LIMIT 1");
}
}

echo "<div class='event'><h1>Наша газета</h1></div>";
echo '<div class="content"><div class="block"><ul>';
if($ku['status']>0)echo "<img src='img/gazeta/ok.gif' alt='*' title='*'> <a href='?gazeta&add'>Создать категорию</a>";

$q=mysql_querll("SELECT * FROM `kolhoz_gazeta` WHERE `type` = 'razdel' ORDER BY `pos` ASC");
while($post=mysql_fetch_array($q))
{
echo "<div class='block'>";
$visit_array=explode(',',$post['visit']);
$visit_num=count($visit_array)+$sum_num;
if(!in_array($ku['id'],$visit_array)){echo"<img width='16' height='16' src='img/gazeta/kat_on.png' alt='*' title='*'>";} else {echo"<img width='16' height='16' src='img/gazeta/kat.png' alt='*' title='*'>";}

echo " <a href='?gazeta=$post[id]'><span>".hsc($post['name'])."</span></a>";
echo ' <font color="violet">('.mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_gazeta` WHERE `id` >= $post[id] AND `mother` = $post[id]"),0).')</font> ';
if($ku['status']>0)echo "<a href='?gazeta&moderate&up=$post[id]'><img width='16' height='16' src='img/icons/up.png' alt='o'></a> <a href='?gazeta&moderate&down=$post[id]'><img width='16' height='16' src='img/icons/down.png' alt='o'></a>";
if($ku['status']>0)echo " <a href='?gazeta=$post[id]&edit'><img src='img/gazeta/red.gif'></a> ";
if($ku['status']>0)echo " <a href='?gazeta=$post[id]&del'><img src='img/gazeta/del.gif'></a> ";
echo "</div>";
}

include_once 'inc/foot.php';
}
}
?>