<?
require'../config.php';
$align='left';
$title='Админ Новости';
head();
aut();

levels(9);
who_add(0,'enter');
$mid = (int)$_GET['mid'];
echo '<br/>';


switch($mod){
default:

if (empty($user['max'])) $user['max']=10;
$max = $user['max'];
$k_post=$db->sql_fetchfield($db->sql_query("select count(*) as num from admin_news"),0);
$k_page=k_page($k_post,$max);
$page=page($k_page);
$start=$max*$page-$max;

$r = $db->sql_query ("Select * from admin_news order by time desc LIMIT $start, $max");
if ($k_post == 0)echo 'Новостей нет<br />';
$post_k=$start+1;
while($a = @$db->sql_fetchrow($r)){
echo links.''.nik($a[user_id]).' ('.times($a['time']).')'.div;
echo text($a[msg]);
echo '<br/>- - -<br/>';
echo '<a href="admin_news?mod=komm&amp;new='.$a[id].'">Комментарии</a> ('.$db->sql_fetchfield($db->sql_query("select count(*) as num from admin_newskom where new = '".$a[id]."'"),0).')<br/>';
echo '<dl></dl>';

}

if ($k_page>1){
str('admin_news?',$k_page,$page);
}



break;

case 'komm':
$new = check(intval($_GET['new']));
$r = $db->sql_query("Select * from admin_news WHERE `id` = '".$new."'");
if (mysql_affected_rows()==0){echo 'Новость не найдена!<br />';
}else{

if (isset($_GET['delk'])){
if($user[level]>=5){
$db->sql_query("DELETE FROM `admin_newskom` WHERE `id` = '".intval($_GET['delk'])."'");
}
header ('Location: admin_news?mod='.$mod.'&new='.$new.'&'.SID);
}

if (isset($_POST['msg'])){
if (strlen2($_POST['msg'])>3){
if ($user['translit']==1)$_POST['msg'] = translit($_POST['msg']);
if ($db->sql_query ("INSERT INTO admin_newskom (new,user_id,time,msg) VALUES ('$new','$user[id]','$time','".check($_POST['msg'])."')")){header ('Location: admin_news?mod='.$mod.'&new='.$new.'&'.SID); exit;
}else echo 'Ошибка!<br />';


}

}


if (empty($user['max'])) $user['max']=10;
$max = $user['max'];
$k_post=$db->sql_fetchfield($db->sql_query("select count(*) as num from admin_newskom where new = '".check(intval($_GET['new']))."'"),0);
$k_page=k_page($k_post,$max);
$page=page($k_page);
$start=$max*$page-$max;

$r = $db->sql_query ("Select * from admin_newskom where new = '".check(intval($_GET['new']))."' order by time desc LIMIT $start, $max");
if ($k_post == 0)echo 'Комментариев нет<br />';
$post_k=$start+1;
while($a = @$db->sql_fetchrow($r)){
echo links.''.nik($a[user_id]).'';
if($user[level]>=5)echo '<small><a href="admin_news?mod='.$mod.'&amp;&amp;new='.$new.'&amp;delk='.$a['id'].'">[X]</a></small>';
echo '('.times($a['time']).')'.div;

echo text($a[msg]);
echo '<dl></dl>';

}

if ($k_page>1){
str('admin_news?mod='.$mod.'&amp;&amp;new='.$new.'&amp;',$k_page,$page); 
}

if ($ver!='wml')echo '<form action="admin_news?mod='.$mod.'&amp;new='.$new.'&amp;'.SID.'" method="post">';
if ($ver=='wml')echo '<br />Ваш комментарий:<br /><input name="msg'.$ref.'" maxlength="15" title="Text"/><br/>';
else echo '<br/>Ваш комментарий:<br/><textarea cols="'.$user['pole2'].'" rows="'.$user['pole1'].'" name="msg"></textarea><br/><br/>';
if ($ver=='wml'){
echo '<anchor title="go">Добавить<go href="admin_news?mod='.$mod.'&amp;new='.$new.'&amp;'.SID.'" method="post">';
echo '<postfield name="msg" value="$msg'.$ref.'"/>
</go></anchor><br/><br/>';
;
}else{
echo '<input type="submit" class="ibutton" value="Добавить"/></form><br/><br/>';
}
}
break;

}
echo '<br/>';
if ($mod)echo gb.'<a href="admin_news">Новости</a>'.div;
echo gb.'<a href="'.H.'enter">Прихожая</a>'.div;
info_compress();
echo 'Время:'.$debag->endTimer().' сек<br />'.div;
foot();

?>