<?
$base_path="../";
$bp="../../../";

require_once($base_path.'connect/connect.php');
include_once($base_path.'lib/lib.php');

$id_magazin=intval($_GET['id_magazin']);
$pn = 0;
if (isset($_GET['pn'])) 
	{
	if(intval($_GET['pn'])==-1)
	$pn=0;
	else
	$pn = intval($_GET['pn']);
	}

$count=intval($_GET['count']);

$order=intval($_GET['order']);
if($order==1) {$orders=2; $ord=' ASC '; $fww='&#8595;';}
elseif($order==2) {$orders=1; $ord=' DESC '; $fww='&#8593;';}

$sort=anti($_GET['srt']);
$sorts=$sort.$ord;
if($_GET['srt2'])
	{
	$sort2 = anti($_GET['srt2']);
	$sorts .= ", ".$sort2.$ord;
	}


if($_GET)
	{
	$err = '';

	for($i=0; $i<4; $i++)
		{
		if($_GET['razdel_'.$i])
			{
			$rzd = " AND razdel_".$i."='".intval($_GET['razdel_'.$i])."' ";
			$id_catalog=intval($_GET['razdel_'.$i]);
			}
		}

	$err .= $rzd;

	for($i=0; $i<4; $i++)
		{
		if($_GET['region_'.$i])
		$rgn = " AND region_".$i."='".intval($_GET['region_'.$i])."' ";
		}

	if($rgn)
	$err .= $rgn;

	if($id_magazin)
	$err .= " AND id_akk ='".$id_magazin."' ";

	if($id_catalog)
		{
		include_once($base_path.'cashe_catalog/_svod_catalog_'.$id_catalog.'.php');
		include_once($base_path.'plugin/board/func_search_user.php'); 
		include_once($base_path.'plugin/board/func_view.php');

		if($arr_sp)
			{
			foreach($arr_sp as $ars)
				{
				if(file_exists($base_path.'cashe_n/_svod_element_'.$ars[0].'.php'))
				include_once($base_path.'cashe_n/_svod_element_'.$ars[0].'.php');
		
				if(file_exists($base_path.'cashe_n/_svod_element_two_'.$ars[1].'.php'))
				include_once($base_path.'cashe_n/_svod_element_two_'.$ars[1].'.php');
				}
			}
		}

	if($arr_field)  
		{
		foreach($arr_field as $ar_fi) 
			{
			if($ar_fi['spec']=='st' || $ar_fi['spec']=='sp')
				{
				eval ("\$data['".$ar_fi['field_field']."']=field_func_search_".$ar_fi['field_typ']." ('prov', \$ar_fi, \$_GET[\$ar_fi['field_field']] );");
				if($data[$ar_fi['field_field']][0])
				$err .= " ".$data[$ar_fi['field_field']][0]." ";
				}
			}
		}

	if($_GET['fy'])
	$err .= " AND small !='' ";

	if($_GET['pols'])
	$err .= " AND pols ='".intval($_GET['pols'])."' ";

	if($_GET['text_search'])
		{
		$_GET['text_search']=urldecode($_GET['text_search']);
		function _pred ($a)
			{
			$a=strip_tags($a);
			$a=str_replace("`","",$a);
			$a=str_replace("'","",$a);
			$a=str_replace('"',"",$a);
			$a=str_replace("&","",$a);
			$a=str_replace("=","",$a);
			$a=str_replace('javascript',"",$a);
			$a=trim($a);
			return $a;
			}
		$_GET['text_search']=_pred ($_GET['text_search']);

		if($_POST['sz'])
		$err .= " AND ".search2($_GET['text_search'], 'zag')." ";
		else
		$err .= " AND ".search2($_GET['text_search'], 'opis')." ";
		}

	if($err)
	$err=" WHERE ".mb_substr($err, 4, mb_strlen($err)-4)." AND activ !=1 "; 
	else
	$err=" WHERE activ !=1 "; 
	
	$query = "SELECT * FROM board ".$err." ORDER BY ".$sorts;	
		
	
	//echo $query.'<br>'; 

	$maxRows_Recordset1=$rru['ob_na_str'];
	$startRow_Recordset1 = $pn * $maxRows_Recordset1;
	$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query, $startRow_Recordset1, $maxRows_Recordset1);
	$Recordset1 = mysql_query($query_limit_Recordset1, $connect) or die(mysql_error());
	$row_Recordset1 = mysql_fetch_array($Recordset1);

	$totalRows_Recordset1 = $count;
	$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
	
	if($totalRows_Recordset1) 
		{
		echo '<br><TABLE width="100%"  cellpadding="2" cellspacing="0" border="0">';

		echo '<tr  bgcolor=#EEE8DF height="50" align=center valign=middle >';
		
		echo '<td>';
		if($sort=='data') 
			{
			echo '<a onclick="sort_tab('.$totalRows_Recordset1.', \'data\', \'\', \'-1\', '.$orders.')"><span class=line><em>Дата</em>';
			echo "<font color=red> ".$fww."</font>";
			}
		else
		echo '<a onclick="sort_tab('.$totalRows_Recordset1.', \'data\', \'\', \'-1\', 1)"><span class=line><em>Дата</em>';
		echo '</span></a>';
		
		
		echo '<td>';
		if($sort=='small') 
			{
			echo '<a onclick="sort_tab('.$totalRows_Recordset1.', \'small\', \'\', \'-1\', '.$orders.')"><span class=line><em>Фото</em>';
			echo "<font color=red> ".$fww."</font>";
			}
		else
		echo '<a onclick="sort_tab('.$totalRows_Recordset1.', \'small\', \'\', \'-1\', 1)"><span class=line><em>Фото</em>';
		echo '</span></a>';
		
		
		echo '<td>';
		if($sort=='gorod') 
			{
			echo '<a onclick="sort_tab('.$totalRows_Recordset1.', \'gorod\', \'\', \'-1\', '.$orders.')"><span class=line><em>Город</em>';
			echo "<font color=red> ".$fww."</font>";
			}
		else
		echo '<a onclick="sort_tab('.$totalRows_Recordset1.', \'gorod\', \'\', \'-1\', 1)"><span class=line><em>Город</em>';
		echo '</span></a>';
		
		if($arr_field)
			{
			foreach ($arr_field as $ar_fi)
				{
				if($ar_fi['field_tab'])
					{
					echo '<td>';
					if($sort==$ar_fi['field_field']) 
						{
						if($ar_fi['field_field']=='f_cena_')
						echo '<a onclick="sort_tab('.$totalRows_Recordset1.', \''.$ar_fi['field_field'].'\', \''.$ar_fi['field_field_two'].'\', \'-1\', '.$orders.')"><span class=line><em>'.$ar_fi['field_tab'].', '.$rru['cena_valuta'].'</em>';
						else
						echo '<a onclick="sort_tab('.$totalRows_Recordset1.', \''.$ar_fi['field_field'].'\', \''.$ar_fi['field_field_two'].'\', \'-1\', '.$orders.')"><span class=line><em>'.$ar_fi['field_tab'].'</em>';
						echo "<font color=red> ".$fww."</font>";
						}
					else
						{
						if($ar_fi['field_field']=='f_cena_')
						echo '<a onclick="sort_tab('.$totalRows_Recordset1.', \''.$ar_fi['field_field'].'\', \''.$ar_fi['field_field_two'].'\', \'-1\', 1)"><span class=line><em>'.$ar_fi['field_tab'].', '.$rru['cena_valuta'].'</em>';
						else
						echo '<a onclick="sort_tab('.$totalRows_Recordset1.', \''.$ar_fi['field_field'].'\', \''.$ar_fi['field_field_two'].'\', \'-1\', 1)"><span class=line><em>'.$ar_fi['field_tab'].'</em>';
						}
					echo '</span></a>';
					}
				}
			}

		do 
			{ 
	  		if (isset ($row_Recordset1['id'])) 
				{
				if($row_Recordset1['vip']) $vip_fon='bgcolor="#FFFFCA"'; else $vip_fon=''; /////////////////// VIP FON
			
				echo '<tr data-href="'.$bp.'items/'.$row_Recordset1['zag_url'].'_'.$row_Recordset1['id'].'" valign=middle height="110" '.$vip_fon.'>';
			
				echo '<td width="60">';
				if(date($date_format_site, strtotime($row_Recordset1['data'])) == date($date_format_site))
				echo 'Сегодня';
				elseif(date($date_format_site, (strtotime($row_Recordset1['data']) + 24*60*60)) == date($date_format_site))
				echo 'Вчера';
				else
				echo dat_rus($row_Recordset1['data'], 1);
				//echo date("d-m", strtotime($row_Recordset1['data']));
				echo '<br><span style="color:#858585">'.date("H:i", strtotime($row_Recordset1['data'])).'</span>';

				$titt=explode("<hr>", $row_Recordset1['opis']);
				if($titt[1])
				$tit='title="'.obrez(str_replace("\n"," ", $titt[1]), 200).'"'; else $tit='';
				
				echo '<br><a style="font-size:14px; TEXT-DECORATION: none" '.$tit.' href="'.$bp.'items/'.$row_Recordset1['zag_url'].'_'.$row_Recordset1['id'].'" >&nbsp;&nbsp;&#8594;</a>';
			
				echo '<td align=center valign=middle width="100">';
				if($row_Recordset1['small'])
				echo '<img class="imground" src="'.$bp.$row_Recordset1['small'].'" border=0>';
				elseif ($row_Recordset1['video_host'] == 'youtu.be' || $row_Recordset1['video_host']=='youtube.com')
				echo '<img class="imground" width=100 src="http://i.ytimg.com/vi/'.$row_Recordset1['video_item'].'/1.jpg" border=0>';

				echo '<td width="100" align=center>';
				echo $row_Recordset1['gorod'];
				if($row_Recordset1['rayon'])
				echo '<br><span style="color:#858585">'.$row_Recordset1['rayon'].'</span>';

			
				if($arr_field)
					{
					foreach ($arr_field as $ar_fi)
						{
						if($ar_fi['field_tab'])
							{
							echo '<td align=center>';
							if($ar_fi['field_field_two'])
							eval("field_func_view_".$ar_fi['field_typ']." ('view_tab', \$ar_fi, \$row_Recordset1[\$ar_fi['field_field']], \$row_Recordset1[\$ar_fi['field_field_two']]);");
							else
							eval("field_func_view_".$ar_fi['field_typ']." ('view_tab', \$ar_fi, \$row_Recordset1[\$ar_fi['field_field']]);");
							
							if($ar_fi['field_field']=='f_cena_' && $row_Recordset1['suff'])
							echo '<br>'.$row_Recordset1['suff'];
							
							echo '</td>';
							}
						}
					}
				}
			} while ($row_Recordset1 = mysql_fetch_array($Recordset1));
			echo '</table>';
		}

	mysql_free_result($Recordset1);
	
	pages4(15, $totalPages_Recordset1, $pn, $totalRows_Recordset1, $sort, $sort2, $order);
	}

if($rru['round'])
	{
	$browser_array=array('ie6','ie7','ie8');

	if ( stristr($_SERVER['HTTP_USER_AGENT'], 'MSIE 6.0') ) $browser = 'ie6';
	elseif ( stristr($_SERVER['HTTP_USER_AGENT'], 'MSIE 7.0') ) $browser = 'ie7';
	elseif ( stristr($_SERVER['HTTP_USER_AGENT'], 'MSIE 8.0') ) $browser = 'ie8';
	else $browser = '';

	if(!in_array($browser, $browser_array))
		{
		?>
		<p>
		<script type="text/javascript">
		$(document).ready(function(){
		$(".imground").corner("round");
		});
		</script>
		<?
	}
}
?>
<script type="text/javascript">
		jQuery( function($) {
			$('tbody tr[data-href]').addClass('clickable').click( function() {
			window.location = $(this).attr('data-href');
			});
		});
</script>