<?php 

if (isset($_GET['act']) && $ID != 0) {
  $ads = mysql_fetch_assoc(mysql_query("SELECT * FROM `ads` WHERE `id` = '$ID' LIMIT 1"));
  
  if ($_GET['act'] == 'delete') {
    if (user_access('adm_mysql')) {
      mysql_query("DELETE FROM `ads` WHERE id = '$ID' LIMIT 1");
      mysql_query("DELETE FROM `payment` WHERE `service_id` = '$ID' AND `service` = 'ads' AND `paid` = '0' LIMIT 1");
      $_SESSION['message'] = __('Реклама успешно удалена');
    }
    
    header('Location: ?func=' . $func);
    exit;
  }
  
}

$set['title'] = __('Управление рекламой'); 
include_once H.'sys/inc/thead.php';
title();
aut();
err();

$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `ads`"), 0);
$k_page = k_page($k_post,$set['p_str']);
$page = page($k_page);
$start = $set['p_str'] * $page - $set['p_str'];

if ($k_post == 0)
{
?><div class="mess"><?= __('Список пуст')?></div><?
} else {
  
  $q = mysql_query("SELECT * FROM ads
  ORDER BY id DESC LIMIT $start, $set[p_str]");
  $num = 0;
  
  while ($post = mysql_fetch_assoc($q))
  {
    $num++;
    ?>
    <div class="nav<?= ($num % 2 ? 1 : 2)?>">
      &raquo; <a href="<?= text($post['url'])?>" target="_blank"><?= text($post['name'])?></a>
      <span class="pull-right"><a href="?func=<?= $func?>&amp;id=<?= $post['id']?>&amp;act=delete"><img src="/style/icons/delete.gif" /></a></span>
    </div>
    <?
  }

  if ($k_page > 1) {
    str('?', $k_page, $page);
  }
}
?>
<ol class="breadcrumb">
  <li><img src="/<?= $config['patch_icons']?>/arrow-180.png" /> <a href="?func=menu"><?= __('Биллинг')?></a></li>
  <li><a href="?func=admin"><?= __('Управление')?></a></li>
  <li class="active"><?= __('Реклама')?></li>
</ol>