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

$base_path="../";
$id_rec=intval($_REQUEST['id_rec']);
$action2='all_rec_user.php';
$action='rec_user.php';


if (isset($_POST["MM_insert"]) && $_POST["MM_insert"] == "rec" ) 
	{
	if($_POST['brr'])
		{
		foreach($_POST['brr'] as $key=>$bb)
			{
			if($bb) 
				{
				$new_arrs[$key][$bb]=$id_rec;
				}
			}
			
		if($new_arrs && count($new_arrs)>0)
		$new=serialize($new_arrs);
		else
		$new='';

		mysql_query("UPDATE rec SET 
		str='".$new."'
		WHERE id_rec='".$id_rec."'");

		include('_svod_rec.php');

		echo "<HTML><HEAD><meta http-equiv='Refresh' charset='utf-8' content='0; URL=refresh.php?i=".$action2."'></HEAD></HTML>";
		exit();
		}

	}



$r = mysql_query ("SELECT * FROM rec WHERE id_rec='".$id_rec."' ") or die(mysql_error());
$nr=mysql_num_rows($r);

$rr = mysql_fetch_array($r);
$content=$rr['rec_cont'];
$opl=$rr['opl'];

if($rr['str']) $new_arr=unserialize($rr['str']); 

$titl="Рекламный блок: ".$id_rec;
require ('top.php'); 

if($err) echo '<p><font color=red>'.$err.'</font></p>';

echo '<form method=post name=recl action="">';
echo '<TABLE width="100%" style="BORDER-COLLAPSE: collapse" cellpadding="1" cellspacing="1" border="1" bordercolor="#E2E2E2">';
echo '<tr align=center >';
echo '<td>';
echo 'Страница';
echo '<td><font color=red>Отключено</font>';

for($i=1; $i<3; $i++)
{
echo '<td>место '.$i;
}


	echo '<tr align=center>';
	echo '<td align=left width="40%">';
	echo '<img src="../icon/file.gif" border=0> <a target=_blank href="../">Главная</a> '; 

	echo  '<td><input type=radio name=brr[0] value="0" >';
	
	for($i=1; $i<3; $i++)
		{
			if($new_arr[0][$i]) {$ch="checked"; $fn='bgcolor="#B6D3BE"';}
			else {$ch=''; $fn='';}
			$out .=  '<td '.$fn.'><input type=radio name=brr[0] value="'.$i.'" '.$ch.' >';
		}


function get_tree($parent_id, $prefix) {
global $out;
global $arr_typ_catalog;
global $new_arr;

$query = "SELECT * FROM catalog WHERE parent_id = '".$parent_id."' ORDER BY num";
$result = mysql_query($query);	
$nr = mysql_num_rows($result);  
	  
while ($rr = mysql_fetch_array($result)) 
	{
	$out .= '<tr align=center>';
	$out .= '<td align=left width="40%">';
	$out .= $prefix.'<img src="../icon/file.gif" border=0> <a target=_blank href="../catalog/'.$rr['url'].'_'.$rr['id_catalog'].'/all_0/">'.$rr['catalog'].'</a> '; 

	$out .=  '<td><input type=radio name=brr['.$rr['id_catalog'].'] value="0" >';
	
	for($i=1; $i<3; $i++)
		{
			if($new_arr[$rr['id_catalog']][$i]) {$ch="checked"; $fn='bgcolor="#B6D3BE"';}
			else {$ch=''; $fn='';}
			$out .=  '<td '.$fn.'><input type=radio name=brr['.$rr['id_catalog'].'] value="'.$i.'" '.$ch.' >';
		}

	if(!$rr['typ']) 
	get_tree($rr['id_catalog'], $prefix."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
	}
return $out;
} // end function

echo get_tree(0, "");

echo '</table>';
echo '<br><input type="submit"  class="submit" name="Submit" value="Изменить">';
echo '<input type="hidden" name="MM_insert" value="rec">';
echo '<input type="hidden" name="id_rec" value="'.$id_rec.'">';
echo '</form>';
require('bottom.php');
?>