<?
///////////////////////
if($_GET['activate'])
	{
	mysql_query("UPDATE board SET activ = '0', data=NOW(), data1=NOW()+INTERVAL ".$rru['srok']." DAY 
	WHERE activ=1 AND id='".intval($_GET['activate'])."' AND pass='".anti($_GET['pass'])."'");
	}
	
if($_GET['activ_vip'])
	{
	if($_GET['activ_vip']==1) $activ_vip=1; else $activ_vip=0;
	mysql_query("UPDATE board SET activ = '".$activ_vip."' 
	WHERE id='".intval($_GET['id'])."' AND pass='".anti($_GET['pass'])."'");
	}
	
		if($_GET['prolong'])
			{
			$prolong=intval($_GET['prolong']);
			$vip=intval($_GET['vip']);
			$pro=intval($_GET['pro']);
			include_once($base_path.'blok/vibor_payment_arr.php');
			
			$cena=$koshel[$vip]; 
			$sum = intval($sum);
			
			if($cena>$sum)
				{
				echo '<table width=300 bordercolor=red border=3 cellSpacing=0 cellPadding=5><tr><td bgcolor=ffffff>
				<p>Для продления услуги '.$a_name[$vip].' необходима сумма '.$cena.' '.$rru['cena_valuta'].'.
				<br>
				А в Вашем кошельке только '.$sum.' '.$rru['cena_valuta'].'
				</p>';
				?>
				<form action="b_user.php" method="post" name="form_ok" >
  				<input class="submit" type="submit" name="OK" value="OK">
				</form>
				<?
				echo '</td></tr></table><br>';
				}
			else
				{
				echo '<table width=300 bordercolor=red border=3 cellSpacing=0 cellPadding=5><tr><td bgcolor=ffffff>
				<p>Вы действительно хотите продлить '.$a_name[$vip].' под номером: <b>'.$prolong.'</b> ?
				<br>
				Это обойдется Вам в '.$cena.' '.$rru['cena_valuta'];
				if($pro==1)
					{
					$dat=date("d-m-Y H:i", time()+7*24*60*60 );
					echo '<br>Услуга будет продлена до '.$dat;
					}
				
				elseif($pro==2)
					{
					$m=mysql_query("SELECT * FROM board WHERE id='".$prolong."'");
					$mm=mysql_fetch_array($m);
					$dat=date("d-m-Y H:i", strtotime($mm['vip_data'])+7*24*60*60 );
					echo '<br>Услуга будет продлена до '.$dat;
					}
				
				echo '</p>';
				?>
				<form action="b_user.php" method="post" name="form_prolong" >
  				<input name="prolong" type="hidden" value="<?=$prolong?>">
  				<input name="vip" type="hidden" value="<?=$vip?>">
  				<input name="pro" type="hidden" value="<?=$pro?>">
  				<input class="submit" type="submit" name="pro_yes" value="Да">
  				<input class="submit" type="submit" name="pro_no" value="Нет">
				</form>
				<?
				echo '</td></tr></table><br>';
				}
			}
	
	
		if($_POST['pro_yes'] && $_POST['prolong'])
			{
			$prolong=intval($_POST['prolong']);
			$vip=intval($_POST['vip']);
			$pro=intval($_POST['pro']);
			
			include_once($base_path.'blok/vibor_payment_arr.php');
			
			$cena=$koshel[$vip]; 
			$sum = intval($sum);
			
			if($cena>$sum)
				{
				echo '<table width=300 bordercolor=red border=3 cellSpacing=0 cellPadding=5><tr><td bgcolor=ffffff>
				<p>Для продления услуги '.$a_name[$vip].' необходима сумма '.$cena.' '.$rru['cena_valuta'].'.
				<br>
				А в Вашем кошельке только '.$sum.' '.$rru['cena_valuta'].'
				</p>';
				?>
				<form action="b_user.php" method="post" name="form_ok" >
  				<input class="submit" type="submit" name="OK" value="OK">
				</form>
				<?
				echo '</td></tr></table><br>';
				}
			else
				{
				if($pro==1)
				mysql_query("UPDATE board SET vip_data=NOW() + INTERVAL 7 DAY WHERE id='".$prolong."'");
				elseif($pro==2)
				mysql_query("UPDATE board SET vip_data=vip_data + INTERVAL 7 DAY WHERE id='".$prolong."'");
				
				
				$o = mysql_query("SELECT * FROM board WHERE data1 < vip_data AND id='".$prolong."'");
				$oo = mysql_num_rows($o);
				if($oo)
					{
					mysql_query("UPDATE board SET data1 = vip_data WHERE id='".$prolong."'");
					}
				
							
				mysql_query("INSERT INTO plateg (summa, id_akk, typ, data, opis)  
							VALUES ('".$cena."', '".$_SESSION['ID_P'][1]."', 2, NOW(), 
							'Продление услуги ".$name[$vip]." под номером ".$prolong." ')");
				$id_user=$_SESSION['ID_P'][1];
				include_once('balans.php');
				
				
				echo "<HTML><HEAD><meta http-equiv='Refresh' charset='utf-8' content='0; URL=refresh.php?i=b_user.php'></HEAD></HTML>";
				exit();

				}
			}
	
	
	
	
		if($_POST['ch'])
			{
			$ind=implode(',', $_POST['ch']);
			echo '<table width=400 bordercolor=red border=3 cellSpacing=0 cellPadding=5><tr><td bgcolor=ffffff>
			<p>Вы действительно хотите удалить объявления под номерами: <b>'.$ind.'</b> ?</p>';
			?>
			<form action="" method="post" name="form_del" >
  			<input name="del_pdt" type="hidden" value="<? echo $ind; ?>">
  			<input class="submit" type="submit" name="del_yes" value="Да">
  			<input class="submit" type="submit" name="del_no" value="Нет">
			</form>
			<?
			echo '</td></tr></table><br>';
			}

		if($_POST['del_pdt'] && $_POST['del_yes'])
			{
			$r=mysql_query("SELECT * FROM board WHERE id IN (".$_POST['del_pdt'].") AND id_akk !='".$_SESSION['ID_P'][1]."'");
			$nr=mysql_num_rows($r);
			if(!$nr)
				{
				$r=mysql_query("SELECT * FROM foto WHERE id IN (".$_POST['del_pdt'].")");
				while($rr=mysql_fetch_array($r))
					{
					$small = '../foto/'.$rr['papka'].'/'.$rr['id_foto'].'s.jpg';
					$big   = '../foto/'.$rr['papka'].'/'.$rr['id_foto'].'b.jpg';
					if(file_exists($small) && is_file($small)) unlink($small);
					if(file_exists($big) && is_file($big)) unlink($big);
					}
			
				$del_ttmp=explode(',',$_POST['del_pdt']);
				foreach($del_ttmp as $d_t)
					{
					$mid = '../foto_vip/'.$d_t.'m.jpg';
					if (file_exists($mid) && is_file($mid)) unlink($mid);
					}

				mysql_query("DELETE FROM foto WHERE id IN (".$_POST['del_pdt'].")");
				mysql_query("DELETE FROM board WHERE id IN (".$_POST['del_pdt'].") AND id_akk='".$_SESSION['ID_P'][1]."'");
			
				echo '<table width=400 bordercolor=green border=3 cellSpacing=0 cellPadding=5><tr><td bgcolor=ffffff>
				<p>Объявления под номерами: <b>'.$_POST['del_pdt'].'</b> успешно удалены</p>';
				?>
				<form action="" method="post" name="form_null" >
  				<input class="submit" type="submit" name="ok" value="OK">
				</form>
				<?
				echo '</td></tr></table><br>';
				}
			}
///////////////////////

$maxRows_Recordset1=$rru['ob_na_str'];
$pn = 0;
if (isset($_GET['pn'])) 
	{
	$pn = intval($_GET['pn']);
	}
 
$uri=$_SERVER['REQUEST_URI'];
$uri=str_replace("&pn=".$pn, "", $uri);
$uri=str_replace("?pn=".$pn, "", $uri);
$uri=str_replace("%5B", "[", $uri);
$uri=str_replace("%5D", "]", $uri);

$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);

	
	$all_Recordset1 = mysql_query($query_count);
	$arr_query_count = mysql_fetch_array($all_Recordset1);
	$totalRows_Recordset1 = $arr_query_count[0];

$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

if($pn && $pn>$totalPages_Recordset1)
	{
	$zam = str_replace("pn=".$pn, "pn=".$totalPages_Recordset1, $_SERVER['QUERY_STRING']);
	echo "<HTML><HEAD><meta http-equiv='Refresh' charset='utf-8' content='0; URL=?".$zam."'></HEAD></HTML>";
	exit;
	}

echo '&nbsp;Найдено записей: '.intval($totalRows_Recordset1);

if($totalRows_Recordset1) 
	{
	echo '<form action="" method=post>';
	echo '<br><TABLE width="100%"  cellpadding="0" cellspacing="1" border="0">';

	do 
		{ 
	  	if (isset ($row_Recordset1['id'])) 
			{
			$color="";
			
			if($row_Recordset1['vip']) $vip_fon='bgcolor="#FFFFCA"'; else $vip_fon=''; /////////////////// VIP FON
			if($row_Recordset1['moder']) $vip_fon='bgcolor="#EDD6DB"'; else $vip_fon=''; /////////////////// VIP FON

			echo '<tr><td '.$vip_fon.'><table width="100%" cellpadding="5" cellspacing="5" >';
			
			echo '<tr valign=top height="100" >';
			echo '<td width="20" valign=top>';
			if(strtotime($row_Recordset1['vip_data'])<time() && !$row_Recordset1['moder'])
				{
				echo '<a title="Выделить объявление" href="../pages/payment.php?id='.$row_Recordset1['id'].'&type_payment=2&step=1"><img src="../icon/info.png" width=20 border=0></a>';
				echo '<a title="Сделать VIP-объявлением" href="../pages/payment.php?id='.$row_Recordset1['id'].'&type_payment=3&step=1"><img src="../icon/message.png" width=20 border=0></a>';
				echo '<a title="Спецразмещение" href="../pages/payment.php?id='.$row_Recordset1['id'].'&type_payment=4&step=1"><img src="../icon/favorites.png" width=20 border=0></a>';
				
				}
			
			echo '<td width="120">';
			
			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 ' &nbsp; <span style="color:#858585">'.date("H:i", strtotime($row_Recordset1['data'])).'</span>';
			
			$ost = floor((strtotime($row_Recordset1['data1'])-time())/(24*60*60));
			if($ost>0)
			echo '<br><font color=green>Осталось '.$ost.' дн.</font>';
			elseif($ost==0)
			echo '<br>Последний день';
			elseif($ost<0)
				{
				if (!$row_Recordset1['activ'])
				echo '<br><font color=red>Просрочено</font>';
				else
					{
					echo '<br><font color=orange>В архиве</font>';
					echo '<br><a href="?activate='.$row_Recordset1['id'].'&pass='.$row_Recordset1['pass'].'"><font color=grau>Разместить заново</font></a>';
					}
				}
			
			if(!$row_Recordset1['moder'])
			echo '<br><a target=_blank href="../blok/edit.php?id='.$row_Recordset1['id'].'&pass='.$row_Recordset1['pass'].'">редактировать</a>';
			else
			echo '<br><font color=orange>Ожидает модерации</font>';
			
			if($row_Recordset1['vip'])
				{
				if(!$row_Recordset1['activ'])
				echo '<br><a href="?activ_vip=1&id='.$row_Recordset1['id'].'&pass='.$row_Recordset1['pass'].'"><font color=red>Не показывать</font></a>';
				else
				echo '<br><a href="?activ_vip=2&id='.$row_Recordset1['id'].'&pass='.$row_Recordset1['pass'].'"><font color=green>Активировать</font></a>';
				}

			
			
			if(!$row_Recordset1['vip'])
			echo '<br><br><input type="checkbox" name="ch[]" value="'.$row_Recordset1['id'].'">';

			echo '<td align=center valign=top 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>';
			echo '<a style="font-size:14px" href="'.$bp.'items/'.$row_Recordset1['zag_url'].'_'.$row_Recordset1['id'].'" >'.$row_Recordset1['zag'].'</a>';
			if($row_Recordset1['f_cena_'])
				{
				echo '<br>'._font($row_Recordset1['f_cena_'],1).' '.$rru['cena_valuta'];
				if($row_Recordset1['suff'])
				echo $row_Recordset1['suff'];
				}
			
			if($row_Recordset1['razdel'] && !$con_razdel)
			echo '<br><span style="color:#858585">'.$row_Recordset1['razdel'].'</span>';
			if($row_Recordset1['pols']==2) 
			echo '<br><span style="color:#858585">Компания</span>';

			if($row_Recordset1['id_gorod']==$id_region)
				{
				if($row_Recordset1['rayon'])
				echo '<br><span style="color:#858585">'.$row_Recordset1['rayon'].'</span>';
				}
			elseif (!($arr_rayon && in_array($id_region, $arr_rayon)) && $row_Recordset1['gorod'])
			echo '<br><span style="color:#858585">'.$row_Recordset1['gorod'].'</span>';

			echo '<td>';
			echo '<td width="100">';
			if($row_Recordset1['vip'])
				{
				if($row_Recordset1['vip']==2) $vip='<font color=red>Выделенное</font>';
				elseif($row_Recordset1['vip']==3) $vip='<font color=red>VIP</font>';
				elseif($row_Recordset1['vip']==4) $vip='<font color=red>Спецразмещение</font>';
				
				echo $vip;
				
				$ost = floor((strtotime($row_Recordset1['vip_data'])-time())/(24*60*60));
				if($ost<0) $pro=1; else $pro=2;
				
				if($ost>0)
				echo '<br><font color=green>Осталось '.$ost.' дн.</font>';
				elseif($ost==0)
				echo '<br>Последний день';
				elseif($ost<0)
				echo '<br><font color=red>Просрочено</font>';
				echo '<br><a class=green href="?prolong='.$row_Recordset1['id'].'&pro='.$pro.'&vip='.$row_Recordset1['vip'].'">Продлить</a>';

				}

			echo '</table>';
			}
		} while ($row_Recordset1 = mysql_fetch_array($Recordset1));
		echo '</table>';
		echo '<br><br><input type="submit" class="submit" name="submit" value="Выделенные удалить">';
		echo '</form>';
	}

mysql_free_result($Recordset1);





$uris=explode("?",$uri);

if($uris[1]) //есть параметы кроме pn
	{
	$dop2="&pn=";
	}
else
	{
	$dop2="?pn=";
	}

pages(15, $totalPages_Recordset1, $pn, $uri, $dop2);

?>
