<?
if (isset($_GET['sort']) && $_GET['sort'] == 'month') {
  $orderTIME = mktime(0, 0, 0, date("m"), 1, date("Y"));
  $type = 'month';
} else {
  $orderTIME = mktime(0, 0, 0);
  $type = 'today';
}
if (isset($_GET['sort']) && $_GET['sort'] == 'montha') {
$orderTIME = mktime(0, 0, 0, date("m")-1, 1, date("Y"));
$type = 'montha';
}

$system['title'] = 'Новые комментарии';
require SYS . 'header.php';

?>
<ul class="nav nav-pills">
  <li <?= ($type == 'today' ? 'class="disabled"' : '')?>><a href="?func=<?= $func?>">Сегодня</a></li>
  <li <?= ($type == 'month' ? 'class="disabled"' : '')?>><a href="?func=<?= $func?>&amp;sort=month">За <?= str_m($time)?></a></li>
  <li <?= ($type == 'montha' ? 'class="disabled"' : '')?>><a href="?func=<?= $func?>&amp;sort=montha">За <?= str_m($time-2678400)?></a></li>
</ul>
<?
$k_post = count($sql -> selectCol("SELECT shop_comments.id_goods, count( shop_comments.id ) AS count, shop_comments.time, shop_goods.name, shop_goods.id_user, shop_goods.id
FROM shop_comments
LEFT JOIN shop_goods ON shop_comments.id_goods = shop_goods.id
WHERE shop_comments.`time` > '" . $orderTIME . "'
GROUP BY id_goods"));
  
if ($k_post == 0) {
  ?>
  <div class="alert" style="margin: 2px;">Нет новых комментариев</div>
  <?
} else {
  $k_page = k_page($k_post, $system['page_str']);
  $page = page($k_page);
  $start =  $system['page_str'] * $page -  $system['page_str'];
  $array = $sql -> select("SELECT shop_comments.id_goods, count( shop_comments.id ) AS count, shop_comments.time, shop_goods.name, shop_goods.id_user, shop_goods.id
FROM shop_comments
LEFT JOIN shop_goods ON shop_comments.id_goods = shop_goods.id
WHERE shop_comments.`time` > '" . $orderTIME . "'
GROUP BY id_goods
ORDER BY `time` DESC 
LIMIT  $start, $system[page_str]");
    
    
    foreach ($array AS $goods) {
?>
      <div class="media <?= ($num % 2 ? "nav1" : "nav2")?>">
        <div class="media-body">
        <a href="/goods/<?= $goods['id']?>" class="media-heading"><b><?= text($goods['name'])?></b></a>
        <span class="time"><?= vremja($goods['time'])?></span><br />
        <a href="/?func=shop.comments&amp;id=<?= $goods['id']?>"><i class="icon-comment"></i> Комментариев</a> (<?= $goods['count']?>)<br />
        </div>
      </div>
<?
    }

  if ($k_page > 1) { 
    str('/?func=' . $func . '&sort='.$type.'&amp;', $k_page, $page);
  }  
}
?>