<?php
require"../system/config.php";
require"../system/func.php";
if($_GET['act']=="read" && !empty($_GET['id'])){
$q=mysql_fetch_assoc(mysql_query("SELECT `name` FROM `library` WHERE `id`='".$_GET['id']."' LIMIT 1")); $title=$q['name'];}
if($_GET['act']=="view" && !empty($_GET['id'])){
$q=mysql_fetch_assoc(mysql_query("SELECT `name` FROM `library_kategory` WHERE `id`='".$_GET['id']."' LIMIT 1")); $title=$q['name'];}
if(empty($_GET['act']) && empty($_GET['id'])){
$title='Вап мастер Библиотека';
}
require"../system/head.php";
require"../system/error.php";
$act=prov($_GET['act']);
switch($act){
default:
echo'<div class="p">';
if($vhod==1){echo'<img src="/design/default/act.gif" alt="-"> <a href="index.php?act=add"><b>Добавить статью</b></a><br>';}
echo'<img src="/design/default/act.gif" alt="-"> <a href="index.php?act=new">Новые статьи</a><br><img src="/design/default/act.gif" alt="-"> <a href="index.php?act=top">Топ30 статей</a><br><img src="/design/default/act.gif" alt="-"> <a href="index.php?act=top_v">
Топ вылаживающих</a><br><img src="/design/default/act.gif" alt="-"> <a href="index.php?act=search">Поиск статей</a></div>';
$total=mysql_result(mysql_query("SELECT COUNT(*) FROM `library_kategory` WHERE `gde`='0'"),0);
$totel=mysql_result(mysql_query("SELECT COUNT(*) FROM `library` WHERE `stat`='0'"),0);
if($total!=0){ $page = abs((int)$_GET['page']);
if($page < 0 || $page > $total) $page = 0;
if ($total < $page + 10) $end = $total;
else $end = $page + 10;
$query=mysql_query("SELECT * FROM `library_kategory` WHERE `gde`='0' ORDER BY `id` LIMIT $page,10");
while($data=mysql_fetch_array($query)){echo'<div class="p"><img src="../design/default/act.gif" alt="-"> <a href="/library/view/'.$data['id'].'/">'.$data['name'].'</a> ['.podlib_stat($data['id']).']</div>';
}
strpage($page, 10, $total, 'index.php');
echo'<div class="p">Всего статей: '.$totel.'</div>';}else{echo'Еще не создано не одной категории';}
break;
case'view': $id=(int)$_GET['id']; $er=mysql_result(mysql_query("SELECT COUNT(*) FROM `library_kategory` WHERE `id`='$id'"),0);
if($er==0){ echo'Нет такой категории'; include'../system/foot.php'; exit;}
$quera=mysql_query("SELECT * FROM `library_kategory` WHERE `gde`='$id' ORDER BY `id` DESC");
while($deta=mysql_fetch_array($quera)){echo'<div class="p"><img src="/design/default/act.gif" alt="-"><a href="/library/view/'.$deta['id'].'/">'.$deta['name'].'</a> ('.podlib_stat($deta['id']).')</div>';
}
//Статьи
$totel=mysql_result(mysql_query("SELECT COUNT(*) FROM `library` WHERE `id_kat`='$id' AND `stat`='0'"),0);
if($totel!=0){
$page = abs((int)$_GET['page']);
if($page < 0 || $page > $totel) $page = 0;
if ($totel < $page + 10) $end = $totel;
else $end = $page + 10;
$mt=mysql_query("SELECT * FROM `library` WHERE `id_kat`='$id' AND `stat`=0 ORDER BY `id` DESC LIMIT $page,10");
while($data=mysql_fetch_array($mt)){ echo'<div class="p"><a href="/library/read/'.$data['id'].'/">'.$data['name'].'</a><br>Выложил: '.nik_two($data['id_user']).'<br>Прочитали: '.$data['prosm'].' раз(a)<br>('.date_fixed($data['time']).')</div>
';
}
strmpage($page, 10, $totel, '/library/view/'.$id.'/');
echo'<div class="p">Всего статей: '.$totel.'</div>';}
if(mysql_num_rows($quera)==0 and $totel==0){echo'Пусто';}
break;
case'read': $id=(int)$_GET['id']; $er=mysql_num_rows(mysql_query("SELECT * FROM `library` WHERE `id`='$id' AND `stat`='0' LIMIT 1"));
if($er!=0){ $data=mysql_fetch_assoc(mysql_query("SELECT * FROM `library` WHERE `id`='$id' AND `stat`='0' LIMIT 1")); $nkat=mysql_fetch_assoc(mysql_query("SELECT `name` FROM `library_kategory` WHERE `id`='".$data['id_kat']."' LIMIT 1"));
echo'<div class="p">Название: '.$data['name'].'<br>Добавлена: '.date_fixed($data['time']).'<br>Добавил: '.nik_two($data['id_user']).'<br>Категория: '.$nkat['name'].'<br>Просмотров: '.$data['prosm'].' раз(a)</div>
<div class="p">'.$data['text'].'</div>'; $koments=mysql_result(mysql_query("SELECT COUNT(*) FROM `koments` WHERE `type`='library' AND `id_kogo`='".$data['id']."'"),0);
echo'<div class="p"><a href="/pages/koments.php?id_wm='.$data['id'].'&type=library&">Комментарии</a> ['.$koments.']<br>
</div>'; }else{echo'Нет такой статьи';} break;
case add_kat:
if($vhod==1){ if($adm_pr==2 or $adm_pr==3 or $adm_pr==4){
echo'<div class="i">Добавление разделов</div>';
$qeq=mysql_query("SELECT `id`,`name` FROM `library_kategory` ORDER BY `id` DESC"); echo'<form action="index.php?act=adds_kat" method="post">';
echo'Название:<br><input type="text" class="form" size="18" name="name"/>';
echo'<br><select name="kat" class="form"><option value="0">Главная</option>'; while($dat=mysql_fetch_array($qeq)){echo'<option value="'.$dat['id'].'">'.$dat['name'].' ('.podlib_stat($dat['id']).')</option>';} echo'</select>
<br><input type="submit" class="but" value="Добавить"/></form>';
}else{header("Location:index.php");}}else{header("Location:index.php");} break;
case 'adds_kat':
if($vhod==1){if($adm_pr==2 or $adm_pr==3 or $adm_pr==4){
$name=prov($_POST['name']);
$kat=prov($_POST['kat']);
if(empty($name)){echo'Не введено название'; require"../system/foot.php"; exit;}
if($kat==0){$kat='';} mysql_query("INSERT INTO `library_kategory` SET `name`='$name', `gde`='$kat'");
echo'Раздел успешно создан<div class="p"><img src="'.$dirsite.'/design/default/act.gif" alt=""> <a href="index.php?act=add_kat">Назад</a></div>';
}else{header("Location:index.php");}}else{header("Location:index.php");} break;
case 'add':
if($vhod==1){ echo'<div class="i">Добавление статьи</div>';
$qeetp=mysql_num_rows(mysql_query("SELECT * FROM `library_kategory`"));
if($qeetp==0){echo'Категории еще не созданы'; require"../system/foot.php"; exit;}
$qqq=mysql_query("SELECT * FROM `library_kategory` ORDER BY `id` DESC");
$_SESSION['kod']=mt_rand(1111,9999); echo'<form action="index.php?act=adds" method="post">Категория:<br><select name="sa1">';
while($data=mysql_fetch_array($qqq)){
echo'<option value="'.$data['id'].'">'.$data['name'].'</option>';} echo'</select><br>Название:<br><input type="text" class="form" size="18" name="sa2"/><br>Текст:<br><textarea class="form" cols="18" rows="3" name="sa3"/></textarea><br>Введите
код: <img src="/system/kapa.php?id='.$_SESSION['kod'].'" alt="-"><br><input type="text" class="form" size="18" name="pkod"/><br><input type="submit" class="but" value="Добавить"/></form>';
}else{header("Location:index.php");}
break;
case 'adds':
if($vhod==1){
$sa=(int)$_POST['sa1'];
$saa=prov($_POST['sa2']);
$saaa=prov($_POST['sa3']);
$pkod=(int)$_POST['pkod'];
if($_SESSION['kod']!=$pkod){echo'Не верно введен код с картинки'; require"../system/foot.php"; exit;}
if(empty($sa) or empty($saa) or empty($saaa)){echo'Какоето поле,пришло пустое'; require"../system/foot.php"; exit;}
$kk=mysql_num_rows(mysql_query("SELECT * FROM `library_kategory` WHERE `id`='$sa'"));
if($kk==0){echo'Нет такой категории'; require"../system/foot.php"; exit;}
if($adm_pr==2 or $adm_pr==3 or $adm_pr==4){$stat=0;}else{$stat=1;}
mysql_query("INSERT INTO `library` SET `id_kat`='$sa', `name`='$saa', `text`='$saaa', `id_user`='$id_user', `stat`='$stat', `time`='".time()."'"); if($adm_pr==2 or $adm_pr==3 or $adm_pr==4){
echo'Успешно добавлено';}else{echo'Статья отправлена на модэрацию';}
echo'<div class="p"><img src="'.$dirsite.'/design/default/act.gif" alt=""> <a href="index.php?act=add">Назад</a></div>';
}else{header("Location:index.php");} break;
case admk:
if($vhod==1){if($adm_pr==2 or $adm_pr==3 or $adm_pr==4){
echo'<div class="p">Категории:</div>';
$allgod=mysql_result(mysql_query("SELECT COUNT(*) FROM `library_kategory`"),0);
if($allgod==0){echo'Не создано не одной категории'; }
$allrum=mysql_query("SELECT * FROM `library_kategory`");
while($data=mysql_fetch_array($allrum)){
$kolss=mysql_result(mysql_query("SELECT COUNT(*) FROM `library` WHERE `id_kat`='".$data['id']."'"),0);
echo'<div class="p"><img src="'.$dirsite.'/design/default/act.gif" alt=""> <a href="/library/view/'.$data['id'].'/">'.$data['name'].'</a> ['.$kolss.'] [<a href="/library/index.php?act=admkedit&k='.$data['id'].'"><font color="blue">E</font></a>] [<a href="/library/index.php?act=admkdel&
k='.$data['id'].'"><font color="red">D</font></a>]<br>В:<br>'; if($data['gde']==""){echo'Главная';}else{ $nkat=mysql_fetch_assoc(mysql_query("SELECT `name` FROM `library_kategory` WHERE `id`='".$data['gde']."' LIMIT 1"));
echo $nkat['name'];} echo'</div>';}
echo'<div class="p"><img src="'.$dirsite.'/design/default/act.gif" alt=""> <a href="/library/index.php?act=add_kat">Добавить раздел</a></div><div class="p"><img src="'.$dirsite.'/design/default/act.gif" alt=""> <a href="/library/index.php?act=add">
Добавить статью</a></div>'; }else{header("Location:index.php");}}else{header("Location:index.php");}
break;
case admkdel: if($vhod==1){if($adm_pr==2 or $adm_pr==3 or $adm_pr==4){
$k=(int)$_GET['k']; $qres=mysql_query("SELECT * FROM `library_kategory` WHERE `id`='$k'");
if(mysql_num_rows($qres)==0){echo'Нет такой категории'; require"../system/foot.php"; exit;}else{ if(empty($_GET['y'])){echo'Вы действительно хотите удалить эту категорию,вместе со всеми ее
статьями?<br><a href="/library/index.php?act=admkdel&k='.$k.'&y=y"><input type="submit" value="Да" class="form"></a> <a href=p"/library/index.php?act=admk">Нет</a>';}else{
mysql_query("DELETE FROM `library_kategory` WHERE `id`='$k'");
mysql_query("DELETE FROM `library` WHERE `id_kat`='$k'");
echo'Успешно удалено!';}}
}else{header("Location:index.php"); exit;}}else{header("Location:index.php"); exit;} break;
case admkedit: if($vhod==1){if($adm_pr==2 or $adm_pr==3 or $adm_pr==4){
$k=(int)$_GET['k'];
$qres=mysql_query("SELECT * FROM `library_kategory` WHERE `id`='$k'"); if(mysql_num_rows($qres)==0){echo'Нет такой категории'; require"../system/foot.php"; exit;}else{ $qqq=mysql_fetch_assoc(mysql_query("SELECT * FROM `library_kategory` WHERE
`id`='$k'"));
echo'<form action="index.php?act=admkedit2&k='.$k.'" method="post">Название:<br><input type="text" value="'.$qqq['name'].'" size="18" name="t1" class="form"/><br>
<input type="submit" class="but" value="Редактировать"/></form>'; }
}else{header("Location:index.php"); exit;}}else{header("Location:index.php"); exit;} break;
case admkedit2: if($vhod==1){if($adm_pr==2 or $adm_pr==3 or $adm_pr==4){
$k=(int)$_GET['k'];
$qres=mysql_query("SELECT * FROM `library_kategory` WHERE `id`='$k'"); if(mysql_num_rows($qres)==0){echo'Нет такой категории'; require"../system/foot.php"; exit;}else{
$t1=prov($_POST['t1']); if(empty($t1)){echo'Ниче не написано'; require"../system/foot.php"; exit;}
mysql_query("UPDATE `library_kategory` SET `name`='$t1' WHERE `id`='$k'"); echo' Успешно отредактировано<br/> <a href="index.php?act=admk">Назад</a>';
}}else{header("Location:index.php"); exit;}}else{header("Location:index.php"); exit;} break;
case'moder': if($adm_pr==2 or $adm_pr==3 or $adm_pr==4){ $er=mysql_result(mysql_query("SELECT COUNT(*) FROM `library` WHERE `stat`='1'"),0);
if($total!=0){ $page = abs((int)$_GET['page']);
if($page < 0 || $page > $total) $page = 0;
if ($total < $page + 2) $end = $total;
else $end = $page + 2;
$query=mysql_query("SELECT * FROM `library` WHERE `stat`='1' ORDER BY `id` LIMIT $page,2");
while($data=mysql_fetch_array($query)){
$nkat=mysql_fetch_assoc(mysql_query("SELECT `name` FROM `library_kategory` WHERE `id`='".$data['id_kat']."' LIMIT 1"));
echo'<div class="p">Название: '.$data['name'].'<br>Добавлена: '.date_fixed($data['time']).'<br>Добавил: '.nik_two($data['id_user']).'<br>Категория: '.$nkat['name'].'</div><div class="p">'.$data['text'].'</div>
<div class="p"><img src="/design/default/act.gif" alt="-"> <a href="/library/index.php?act=moder_go&id='.$data['id'].'"><font color="blue">Промодэрировать</font></a> <br><img src="/design/default/act.gif" alt="-"> <a href="/library/index.php?act=moder_del&
id='.$data['id'].'"><font color="red">Удалить</font></a></div>'; } strpage($page, 2, $total, 'index.php','act=moder&'); }else{echo'Нет статей для модэрации';} }else{header("Location:index.php");}
break;
case'moder_del': if($adm_pr==2 or $adm_pr==3 or $adm_pr==4){ $id=(int)$_GET['id']; $er=mysql_result(mysql_query("SELECT COUNT(*) FROM `library` WHERE `stat`='1' AND `id`='$id'"),0); if($total==0){echo'Нет такой статьи';}else{ mysql_query("DELETE
FROM `library` WHERE `stat`='1' AND `id`='$id'"); echo'Статья удалена';} }else{header("Location:index.php");}
break;
case'moder_go': if($adm_pr==2 or $adm_pr==3 or $adm_pr==4){ $id=(int)$_GET['id']; $er=mysql_result(mysql_query("SELECT COUNT(*) FROM `library` WHERE `stat`='1' AND `id`='$id'"),0); if($total==0){echo'Нет такой статьи';}else{ mysql_query("UPDATE
`library` SET `stat`='0' WHERE `stat`='1' AND `id`='$id'"); echo'Статья промодэрирована';} }else{header("Location:index.php");}
break;
case'user': $id=(int)$_GET['id']; $er=mysql_num_rows(mysql_query("SELECT * FROM `user` WHERE `id_user`='$id' LIMIT 1")); if($er==0){echo'Нет такого пользователя'; require"../system/foot.php"; exit;} $total=mysql_result(mysql_query("SELECT
COUNT(*) FROM `library` WHERE `stat`='0' AND `id_user`='$id'"),0);
if($total!=0){ $page = abs((int)$_GET['page']);
if($page < 0 || $page > $total) $page = 0;
if ($total < $page + 10) $end = $total;
else $end = $page + 10; $query=mysql_query("SELECT * FROM `library` WHERE `stat`='1' AND `id_user`='$id' LIMIT $page,10");
while($data=mysql_fetch_array($query)){
$nkat=mysql_fetch_assoc(mysql_query("SELECT `name` FROM `library_kategory` WHERE `id`='".$data['id_kat']."' LIMIT 1"));
echo'<div class="p">Название: <a href="/library/read/'.$data['id'].'">'.$data['name'].'</a><br>Добавлена: '.date_fixed($data['time']).'<br>Категория: '.$nkat['name'].'</div> '; }
strmpage($page, 10, $total, '/library/user/'.$id);
}else{echo'Этот пользователь,еще не выложил не одной статьи';}
break;
case'new': $total=mysql_result(mysql_query("SELECT COUNT(*) FROM `library` WHERE `stat`='0' AND `time`>'".(time()-86400*3)."'"),0);
if($total!=0){ $page = abs((int)$_GET['page']);
if($page < 0 || $page > $total) $page = 0;
if ($total < $page + 10) $end = $total;
else $end = $page + 10; $query=mysql_query("SELECT * FROM `library` WHERE `stat`='0' AND `time`>'".(time()-86400*3)."' LIMIT $page,10");
while($data=mysql_fetch_array($query)){
$nkat=mysql_fetch_assoc(mysql_query("SELECT `name` FROM `library_kategory` WHERE `id`='".$data['id_kat']."' LIMIT 1"));
echo'<div class="p">Название: <a href="/library/read/'.$data['id'].'">'.$data['name'].'</a><br>Добавлена: '.date_fixed($data['time']).'<br>Добавил: '.nik_two($data['id_user']).'<br>Категория: '.$nkat['name'].'<br>Просмотров:
'.$data['prosm'].' раз(а)</div>'; } strmpage($page, 10, $total, 'index.php','act=new&'); }else{echo'За 3дня новых небыло';}
break;
case'top':
$er=mysql_num_rows(mysql_query("SELECT * FROM `library` WHERE `stat`='0' LIMIT 1")); if($er!=0){
$page = abs((int)$_GET['page']);
if($page < 0 || $page > $total) $page = 0;
if ($total < $page + 10) $end = $total;
else $end = $page + 10; $query=mysql_query("SELECT * FROM `library` WHERE `stat`='0' ORDER BY `prosm` DESC LIMIT 30");
while($data=mysql_fetch_array($query)){
$nkat=mysql_fetch_assoc(mysql_query("SELECT `name` FROM `library_kategory` WHERE `id`='".$data['id_kat']."' LIMIT 1"));
echo'<div class="p">Название: <a href="/library/read/'.$data['id'].'">'.$data['name'].'</a><br>Добавлена: '.date_fixed($data['time']).'<br>Добавил: '.nik_two($data['id_user']).'<br>Категория: '.$nkat['name'].'<br>Просмотров:
'.$data['prosm'].' раз(а)</div> '; } strmpage($page, 10, $total, 'index.php','act=top&'); }else{echo'Нет статей!';}
break;
case'top_v':
$tot=mysql_result(mysql_query("SELECT COUNT(*) FROM `library` WHERE `stat`='0'"),0);
if($tot==0){echo'Нет статей'; include'../system/foot.php'; exit;}
$total=mysql_result(mysql_query("SELECT COUNT(*) `cn`, `id_user` FROM `library` WHERE `stat`='0' GROUP BY `id_user` ORDER BY `cn`"),0);
$page = abs((int)$_GET['page']);
if($page < 0 || $page > $total) $page = 0;
if ($total < $page + 10) $end = $total;
else $end = $page + 10;
$sdata=mysql_query("SELECT COUNT(*) `cn`, `id_user` FROM `library` WHERE `stat`='0' GROUP BY `id_user` ORDER BY `cn` DESC LIMIT $page,10"); if($total==0){
echo'<div class="p">
пусто<br>
</div>';
}else{
while($ofile=mysql_fetch_array($sdata)){
echo'<div class="p">'.nik_one($ofile['avtor']).' <a href="/library/user/'.$ofile['avtor'].'/">['.$ofile['cn'].']</a></div>';
}}
strpage($page, 10, $total, 'index.php','act=top_v&');
break;
case'search': if($_GET['go']=="yes"){ if($_SESSION['pkod']!=$_POST['kod']){echo'Не верно введен код с картинки!'; require"../system/foot.php"; exit;} $gde=(int)$_POST['gde']; $text=prov($_POST['text']); $er=mysql_num_rows(mysql_query("SELECT
* FROM `library` WHERE `stat`='0' LIMIT 1")); if($er==0){echo'Нет статей в библиотеке'; require"../system/foot.php"; exit;} if(empty($text) or empty($gde)){echo'Не заполнено поле поиска,или не выбрано где
искать'; require"../system/foot.php"; exit;} if($gde==1){ $total=mysql_result(mysql_query("SELECT COUNT(*) FROM `library` WHERE `stat`='0' AND `name` LIKE '$text'"),0);
$query=mysql_query("SELECT * FROM `library` WHERE `stat`='0' AND `name` LIKE '$text'");}
if($gde==2){ $total=mysql_result(mysql_query("SELECT COUNT(*) FROM `library` WHERE `stat`='0' AND `text` LIKE '$text'"),0);
$query=mysql_query("SELECT * FROM `library` WHERE `stat`='0' AND `text` LIKE '$text'");}
if($total!=0){ echo'<div class="p">Результатов: '.$total.'</div>'; while($data=mysql_fetch_array($query)){
$nkat=mysql_fetch_assoc(mysql_query("SELECT `name` FROM `library_kategory` WHERE `id`='".$data['id_kat']."' LIMIT 1"));
echo'<div class="p">Название: <a href="/library/read/'.$data['id'].'">'.$data['name'].'</a><br>Добавил: '.nik_tri($data['id_user']).'<br>Добавлена: '.date_fixed($data['time']).'<br>Категория: '.$nkat['name'].'<br>Просмотров:
'.$data['prosm'].'</div>'; }
}else{echo'Ничего не найдено :(';} }else{ $_SESSION['pkod']=mt_rand(1111,9999); echo'Введите, что исчите<br><form action="/library/index.php?act=search&go=yes" method="post">Запрос:<br><textarea cols="18" rows="2" class="form"
name="text"></textarea><br>Где искать:<br><select name="gde" class="form"><option value="1">В название</option><option value="2">В тексте</option>
</select><br>Введите код <img src="/system/kapa.php?id='.$_SESSION['pkod'].'" alt=""><br><input type="text" class="form" name="kod" size="3"><br><input type="submit" value="Искать" class="but"/></form>';}
break;
case'loc': $id=(int)$_POST['id']; $er=mysql_num_rows(mysql_query("SELECT * FROM `library_kategory` WHERE `id`='$id' LIMIT 1"));
if($er!=0){ header('Location: /library/view/'.$id.'/'); }else{header("Location: /library/index.php");} break; }
$couk=mysql_result(mysql_query("SELECT COUNT(*) FROM `library_kategory`"),0);
if($couk!=0){
$qeq=mysql_query("SELECT `id`,`name` FROM `library_kategory` ORDER BY `id` DESC");
echo'<div class="p" align="center">К категории:<br><form action="/library/index.php?act=loc" method="post"><select name="id" class="form"><option value="">Главная</option>'; while($dat=mysql_fetch_array($qeq)){echo'<option value="'.$dat['id'].'">
'.$dat['name'].' ('.podlib_stat($dat['id']).')</option>';} echo'</select><br><input type="submit" value="Перейти" class="but"/></form></div>'; }
if($adm_pr==2 or $adm_pr==3 or $adm_pr==4){ $coumod=mysql_result(mysql_query("SELECT COUNT(*) FROM `library` WHERE `stat`='1'"),0);
echo'<div class="p"><img src="/design/default/act.gif" alt="-"> <a href="/library/index.php?act=admk">Управление</a><br><img src="/design/default/act.gif" alt="-"> <a href="/library/index.php?act=moder">Статьи на модэрации</a>['.$coumod.']</div>
';}
require"../system/foot.php";
?>