<?php 
user_access('adm_mysql', null, 'index.php?'.SID);


if (isset($_GET['sort']) && $_GET['sort'] == 'today') {
  $count = mysql_fetch_assoc(mysql_query("SELECT SUM(wmr) AS wmr,
  (SELECT COUNT(*) FROM `payment` WHERE `time_paid` > '" . mktime(0, 0, 0) . "' AND `paid` = '1') AS 'paid',
  (SELECT COUNT(*) FROM `payment` WHERE `time_paid` > '" . mktime(0, 0, 0) . "' AND `paid` = '0') AS 'unpaid'
  FROM `payment` WHERE `time_paid` > '" . mktime(0, 0, 0) . "' AND `paid` = '1'"));
  $type = 'today';
} elseif (isset($_GET['sort']) && $_GET['sort'] == 'month') {
  $count = mysql_fetch_assoc(mysql_query("SELECT SUM(wmr) AS wmr,
  (SELECT COUNT(*) FROM `payment` WHERE `time_paid` > '" . mktime(0, 0, 0, date("m"), 1, date("Y")) . "' AND `paid` = '1') AS 'paid',
  (SELECT COUNT(*) FROM `payment` WHERE `time_paid` > '" . mktime(0, 0, 0, date("m"), 1, date("Y")) . "' AND `paid` = '0') AS 'unpaid'
  FROM `payment` WHERE `time_paid` > '" . mktime(0, 0, 0, date("m"), 1, date("Y")) . "' AND `paid` = '1'"));
  $type = 'month';
} elseif (isset($_GET['sort']) && $_GET['sort'] == 'year') {
  $count = mysql_fetch_assoc(mysql_query("SELECT SUM(wmr) AS wmr,
  (SELECT COUNT(*) FROM `payment` WHERE `time_paid` > '" . mktime(0, 0, 0, 1, 1, date("Y")) . "' AND `paid` = '1') AS 'paid',
  (SELECT COUNT(*) FROM `payment` WHERE `time_paid` > '" . mktime(0, 0, 0, 1, 1, date("Y")) . "' AND `paid` = '0') AS 'unpaid'
  FROM `payment` WHERE `time_paid` > '" . mktime(0, 0, 0, 1, 1, date("Y")) . "' AND `paid` = '1'"));
  $type = 'year';
} else {
  $count = mysql_fetch_assoc(mysql_query("SELECT SUM(wmr) AS wmr,
  (SELECT COUNT(*) FROM `payment` WHERE `paid` = '1') AS 'paid',
  (SELECT COUNT(*) FROM `payment` WHERE `paid` = '0') AS 'unpaid'
  FROM `payment` WHERE `paid` = '1'"));
  $type = 'age';
}

$set['title'] = __('Статистика'); 
include_once H.'sys/inc/thead.php';
title();
aut();
err();

?>
<div class="panel panel-info margin">
  <div class="panel-heading"><?= __('Статистика')?></div>

    <table class="table table-bordered" style="margin: 2px;">
      <tr>
        <td style="text-align: center; font-weight: bold; font-size: 14px; color: #289300;">
          <?= __('Дата')?>
        </td>
        <td style="text-align: center; font-weight: bold; font-size: 14px; color: #289300;">
          <?= __('Оплат')?>
        </td>
        <td style="text-align: center; font-weight: bold; font-size: 14px; color: #289300;">
          <?= __('Доход')?>
        </td>
      </tr>
      
      <tr>
        <td style="text-align: center; font-size: 12px;">
          <?= (int) $count['paid']?>
        </td>
        
        <td style="text-align: center; font-size: 12px;">
          <?= (int) $count['paid']?>
        </td>
        
        <td style="text-align: center; font-size: 12px;">
          <?= round($count['wmr'], 2)?> wmr
        </td>
      </tr>
    </table>
</div>
