<?
session_start();
require_once('../connect/connect.php'); 
include_once('../lib/lib.php');
require('pdk.php');

$id_blok=$_REQUEST['id_blok'];
$id_catalog=$_REQUEST['id_catalog'];

if($_POST['id_blok'] && $_POST['rss_insert']) 
{
$rss = trim($_POST['rss']);
$kol_rss = $_POST['kol_rss'];
if(!$kol_rss) $kol_rss=10;
if(!$rss) $err="Укажите RSS-канал";

$r1=mysql_query("SELECT num FROM subblok WHERE id_blok='".$id_blok."' AND id_catalog='".$id_catalog."' ORDER BY num DESC LIMIT 1");
$rr1=mysql_fetch_array($r1);
if($rr1['num']) $new_num=$rr1['num']+1; else $new_num=1;

if(!$err)
	{
	mysql_query("INSERT INTO subblok (id_blok, id_catalog, rss, kol_rss, num) 
	VALUES ('".$id_blok."', '".$id_catalog."', '".$rss."', '".$kol_rss."', '".$new_num."')");
	
				echo "<HTML><HEAD><meta http-equiv='Refresh' charset='utf-8' content='0; URL=catalog.php?id_catalog=".$id_catalog."'></HEAD></HTML>";
				exit();

	}

}

$titl="Импорт RSS-канала";
require ('top.php'); 

if($err) echo '<p><font color=red>'.$err.'</font></p>';
?>
	
	<form name="form1" method="POST" action="add_blok_rss.php">
	<table width="738" border="0" cellspacing="0" cellpadding="0" >
        <tr>
    		<td width="188">
		Вы можете загрузить сразу несколько RSS-каналов, разделяя их пробелами
		<td width="550">
		<input name="rss" type="text" size="50" value="<?  echo $rss; ?>">
	<tr>
		<td>
		Кол-во новостей в канале
		<td>
		<input type="text" name="kol_rss" size="3" value="<?  echo $kol_rss; ?>">
	<tr>
		<td>
      			<input type="hidden" name="rss_insert" value="form1">
      			<input type="hidden" name="id_blok" value="<? echo $id_blok; ?>">
      			<input type="hidden" name="id_catalog" value="<? echo $id_catalog; ?>">
      			<input class="submit" type="submit" name="submit" value="Добавить">
		<td>

	</table>
    </form>
<?
require('bottom.php');
?>