<?php
require_once "../conf.php";
require_once 'auth.php';
include 'menu.php';
if(!$_REQUEST[os]>0){
$_REQUEST[os]=0;
}
if(!mysql_connect($_conf[mysql_host],$_conf[mysql_user],$_conf[mysql_passwd])){
die('Не удалось установить соединение с MySQL!');
}
if(!mysql_select_db($_conf[mysql_dbname])){
die('База данных не найдена!');
}
switch($_REQUEST['act']){
case 's_add':
show_form('add');
echo '<a href="sites.php?category_id='.$_REQUEST[category_id].'">Назад</a>';
break;
case 'add':
mysql_query('insert into '.$_conf[table_prefix].'sites (category_id, url, title, description, banner_url, allowed, date) values (\''.$_REQUEST[category_id].'\',\''.$_REQUEST[url].'\',\''.$_REQUEST[title].'\',\''.$_REQUEST[description].'\',\''.$_REQUEST[banner_url].'\',\''.$_REQUEST[allowed].'\', '.time().')');
show();
break;
case 'edit':
mysql_query('update '.$_conf[table_prefix].'sites set
category_id=\''.$_REQUEST[category_id].'\',
url=\''.$_REQUEST[url].'\',
title=\''.$_REQUEST[title].'\',
description=\''.$_REQUEST[description].'\',
banner_url=\''.$_REQUEST[banner_url].'\',
allowed=\''.$_REQUEST[allowed].'\' where id=\''.$_REQUEST[id].'\'');
show();
break;
case 's_edit':
show_form('edit',$_REQUEST[id]);
echo '<a href="sites.php?category_id='.$_REQUEST[category_id].'">Назад</a>';
break;
case 'del':
mysql_query('delete from '.$_conf[table_prefix].'sites where id=\''.$_REQUEST[id].'\'');
show();
break;
default:
show();
}
function show(){
GLOBAL $_conf;
$cat=mysql_fetch_array(mysql_query('select * from '.$_conf[table_prefix].'categories where id='.$_REQUEST[category_id]));
$name = ''.$cat[name].': сайты';
$rown=mysql_fetch_array(mysql_query('select count(*) n from '.$_conf[table_prefix].'sites where category_id='.$_REQUEST[category_id]));
$res=mysql_query('select * from '.$_conf[table_prefix].'sites where category_id='.$_REQUEST[category_id].' order by allowed, id desc limit '.$_REQUEST[os].', '.$_conf[on_page]);
?>
<table bgcolor="#d1d1d1" cellpadding="0" cellspacing="0" width="100%">
<tr>
<th style="padding: 5px;">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td><b><?=$name?>:</b> <a href="sites.php?act=s_add&category_id=<?=$_REQUEST[category_id]?>">добавить</a></td>
<td align="right" valign="bottom"><strong>Сайтов: <?=$rown[n]?></strong></td>
</tr>
</table>
</th>
</tr>
<tr>
<td>
<table cellspacing="1" cellpadding="2" width="100%">
<tr>
<td bgColor="#f5f5f5" width="120">URL</th>
<td bgColor="#f5f5f5" align="left"> Название</th>
<td bgColor="#f5f5f5" align="left"> Описание</th>
<td bgColor="#f5f5f5" align="left"> Разрешен</th>
<td bgColor="#f5f5f5" width="190"> </th>
</tr>
<?
while ($row=mysql_fetch_array($res)) {
?>
<tr>
<td bgColor="#f5f5f5" align="left"> <?=$row[url]?></td>
<td bgColor="#f5f5f5" align="left"> <?=$row[title]?></td>
<td bgColor="#f5f5f5" align="left"> <?=$row[description]?></td>
<td bgColor="#f5f5f5" align="left"> <?=$row[allowed]==1?'да':'<b style="color: red;">нет</b>'?></td>
<td bgColor="#f5f5f5" align="right">[<a href="sites.php?act=s_edit&id=<?=$row[id]?>&category_id=<?=$_REQUEST[category_id]?>">Изменить</a>][<a href="sites.php?act=del&id=<?=$row[id]?>&category_id=<?=$_REQUEST[category_id]?>">Удалить</a>]</td>
</tr>
<?
}
?>
</table>
</td>
</tr>
<?
if($rown[n]>$_conf[on_page]){
echo '<tr><td style="padding: 5px;">Страницы: '.listpages ('<a href="sites.php?category_id='.$_REQUEST[category_id].'&os=%os%">%link%</a>', $rown[n], $_REQUEST[os], $_conf[on_page], 6).'</td></tr>';
}
?>
</table>
<br>
<a href="categories.php">К разделам</a>
<?
}
function listpages ($href, $total, $os, $rpp, $limit=15) {
/*
отображение постраничного разбиения
*/
$page = floor($os/$rpp)+1;
$pages = ceil($total/$rpp);
$_start = max(0,$page-max(ceil($limit/2),$page-$pages+$limit))+1;
$_finish = min($pages,$_start + $limit-1);
if ($qs) if ($qs{0}!='?') $qs='?'.$qs;
if ($total > $rpp) {
for($i=$_start;$i<=$_finish;$i++) {
if($i!=$_start) $ret.=' | ';
if ($i != $page) {
$ret .= str_replace(array('%os%','%link%'),array(($i-1)*$rpp,$i),$href);
} else {
$ret .= "<strong>$i</strong>";
}
}
}
return $ret;
}
function show_form($act,$id=null){
GLOBAL $_conf;
if($act=='edit'){
$row=mysql_fetch_array(mysql_query('select * from '.$_conf[table_prefix].'sites where id='.$id));
$form_header_text = 'Сайт [ID:' . $row[id] . ']';
$submit='Сохранить';
}else{
$form_header_text = 'Добавить сайт';
$submit='Добавить';
}
?>
<script Language="JavaScript">
function checkform(theForm)
{
return (true);
}
</script>
<b>Редактирование сайта</b>
<table bgcolor="#d1d1d1" cellpadding="1" cellspacing="0" border="0" width="100%">
<tr>
<td style="padding: 5px;">
<strong><?=$form_header_text?></strong>
</td>
</tr>
<tr>
<td>
<form enctype="multipart/form-data" action="sites.php" method="post" onsubmit="return checkform(this);">
<input type="hidden" name="act" value="<?=$act?>">
<input type="hidden" name="id" value="<?=$id?>">
<input type="hidden" name="category_id" value="<?=$_REQUEST[category_id]?>">
<table cellpadding="2" bgcolor="#f5f5f5" width="100%" border="0">
<tr>
<td valign="top">URL </td>
<td bgColor=#ffffff width="100%">
<input style="width:100%" type="text" name="url" value="<?=$row[url]?>">
</td>
</tr>
<tr>
<td valign="top">Название </td>
<td bgColor=#ffffff width="100%">
<input style="width:100%" type="text" name="title" value="<?=$row[title]?>">
</td>
</tr>
<tr>
<td valign="top">Раздел </td>
<td bgColor=#ffffff width="100%">
<?
echo '<select name=category_id>';
$res1=mysql_query('select * from '.$_conf[table_prefix].'categories where parent_id=0 order by name');
while($row1=mysql_fetch_array($res1)){
if($row1[id]==$row[category_id]){
echo '<option selected value="'.$row1[id].'">'.$row1[name];
}else{
echo '<option value="'.$row1[id].'">'.$row1[name];
}
$res2=mysql_query('select * from '.$_conf[table_prefix].'categories where parent_id='.$row1[id].' order by name');
while($row2=mysql_fetch_array($res2)){
if($row2[id]==$row[category_id]){
echo '<option selected value="'.$row2[id].'">'.$row1[name].' >> '.$row2[name];
}else{
echo '<option value="'.$row2[id].'">'.$row1[name].' >> '.$row2[name];
}
}
}
$content.= '</select>';
?>
</td>
</tr>
<tr>
<td valign="top">Описание </td>
<td bgColor=#ffffff width="100%">
<textarea style="width:100%;height:50px;" name="description"><?=$row[description]?></textarea>
</td>
</tr>
<tr>
<td valign="top">URL кнопки </td>
<td bgColor=#ffffff width="100%">
<input style="width:100%" type="text" name="banner_url" value="<?=$row[banner_url]?>">
</td>
</tr>
<tr>
<td valign="top">Разрешен </td>
<td bgColor=#ffffff width="100%">
<select name="allowed">
<option value=0>Нет
<option value=1 <?if($row[allowed]==1){echo 'selected';}?>>Да
</select>
</td>
</tr>
<tr>
<td valign="top"> </td>
<td><input bgColor=#f5f5f5 type="submit" value="<?=$submit?>" style="width:100;"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</from>
<?
}