1
0

authday.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
  4. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  5. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/idfilter.php");
  6. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/datetimefilter.php");
  7. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/oufilter.php");
  8. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/gatefilter.php");
  9. $auth=get_record_sql($db_link,'SELECT * FROM user_auth WHERE id=?', [$id]);
  10. $user=get_record_sql($db_link,'SELECT * FROM user_list WHERE id=?', [ $auth['user_id']]);
  11. $gateway_list = get_gateways($db_link);
  12. ?>
  13. <div id="cont">
  14. <b>
  15. <?php
  16. print WEB_report_user_traffic."&nbsp<a href=../users/edituser.php?id=".$auth['user_id'].">" . $user['login'] . "</a>&nbsp";
  17. print WEB_report_traffic_for_ip."&nbsp<a href=../users/editauth.php?id=$id>".$auth['ip']."</a>";
  18. ?>
  19. </b>
  20. <br>
  21. <form action="<?php print $_SERVER['PHP_SELF']; ?>" method="post">
  22. <input type="hidden" name="id" value=<?php echo $id; ?>>
  23. <?php print_date_fields($date1,$date2,$date_shift); ?>
  24. <?php echo WEB_cell_gateway; ?>:&nbsp <?php print_gateway_select($db_link, 'gateway', $rgateway); ?>
  25. <input type="submit" value="<?php echo WEB_btn_show; ?>">
  26. </form>
  27. <br>
  28. <table class="data" width=700>
  29. <tr align="center">
  30. <td class="data"><b><?php echo WEB_cell_gateway; ?></b></td>
  31. <td class="data"><b><?php print WEB_title_date; ?></b></td>
  32. <td class="data"><b><?php print WEB_title_input; ?></b></td>
  33. <td class="data"><b><?php print WEB_title_output; ?></b></td>
  34. <td class="data"><b><?php print WEB_title_maxpktin; ?></b></td>
  35. <td class="data"><b><?php print WEB_title_maxpktout; ?></b></td>
  36. </tr>
  37. <?php
  38. // === 1. Определяем тип СУБД ===
  39. $db_type = $db_link->getAttribute(PDO::ATTR_DRIVER_NAME);
  40. // === 2. Выбираем формат даты для каждой СУБД ===
  41. if ($days_shift <= 1) {
  42. $mysql_format = '%Y-%m-%d %H';
  43. $pg_format = 'YYYY-MM-DD HH24';
  44. } elseif ($days_shift <= 30) {
  45. $mysql_format = '%Y-%m-%d';
  46. $pg_format = 'YYYY-MM-DD';
  47. } elseif ($days_shift <= 730) {
  48. $mysql_format = '%Y-%m';
  49. $pg_format = 'YYYY-MM';
  50. } else {
  51. $mysql_format = '%Y';
  52. $pg_format = 'YYYY';
  53. }
  54. // === 3. Базовые параметры (все значения — через параметры!) ===
  55. $params = [$date1, $date2, (int)$id];
  56. // === 4. Дополнительное условие по router_id (если нужно) ===
  57. $router_condition = '';
  58. if (!empty($rgateway) && $rgateway > 0) {
  59. $router_condition = ' AND router_id = ?';
  60. $params[] = (int)$rgateway;
  61. }
  62. // === 5. Формируем запрос в зависимости от СУБД ===
  63. if ($db_type === 'mysql') {
  64. $sSQL = "
  65. SELECT
  66. router_id,
  67. DATE_FORMAT(ts, '$mysql_format') AS thour,
  68. SUM(byte_in) AS byte_in_sum,
  69. SUM(byte_out) AS byte_out_sum,
  70. MAX(ROUND(pkt_in / step)) AS pkt_in_max,
  71. MAX(ROUND(pkt_out / step)) AS pkt_out_max
  72. FROM user_stats_full
  73. WHERE ts >= ? AND ts < ? AND auth_id = ?$router_condition
  74. GROUP BY DATE_FORMAT(ts, '$mysql_format'), router_id
  75. ORDER BY thour" . ($rgateway > 0 ? '' : ', router_id');
  76. } elseif ($db_type === 'pgsql') {
  77. $sSQL = "
  78. SELECT
  79. router_id,
  80. TO_CHAR(ts, '$pg_format') AS thour,
  81. SUM(byte_in) AS byte_in_sum,
  82. SUM(byte_out) AS byte_out_sum,
  83. MAX(ROUND(pkt_in / step)) AS pkt_in_max,
  84. MAX(ROUND(pkt_out / step)) AS pkt_out_max
  85. FROM user_stats_full
  86. WHERE ts >= ? AND ts < ? AND auth_id = ?$router_condition
  87. GROUP BY TO_CHAR(ts, '$pg_format'), router_id
  88. ORDER BY thour" . ($rgateway > 0 ? '' : ', router_id');
  89. } else {
  90. throw new RuntimeException("Unsupported database driver: $db_type");
  91. }
  92. // === 6. Выполняем запрос ===
  93. $userdata = get_records_sql($db_link, $sSQL, $params);
  94. $sum_in = 0;
  95. $sum_out = 0;
  96. print "<tr align=center class=\"tr1\" onmouseover=\"className='tr2'\" onmouseout=\"className='tr1'\">\n";
  97. print "<td class=\"data\" colspan=2>".$auth['description']."</td>\n";
  98. print "<td class=\"data\" colspan=2><a href=/admin/reports/userdaydetail.php?id=$id&date_start=$date1&date_stop=$date2>TOP 10</a></td>\n";
  99. print "<td class=\"data\" colspan=2><a href=/admin/reports/userdaydetaillog.php?id=$id&date_start=$date1&date_stop=$date2>".WEB_report_detail."</a></td>\n";
  100. print "</tr>\n";
  101. foreach ($userdata as $row) {
  102. print "<tr align=center class=\"tr1\" onmouseover=\"className='tr2'\" onmouseout=\"className='tr1'\">\n";
  103. print "<td class=\"data\">" . $gateway_list[$row['router_id']] . "</td>\n";
  104. print "<td class=\"data\">" . $row['thour'] . "</td>\n";
  105. print "<td class=\"data\">" . fbytes($row['byte_in_sum']) . "</td>\n";
  106. print "<td class=\"data\">" . fbytes($row['byte_out_sum']) . "</td>\n";
  107. print "<td class=\"data\">" . fpkts($row['pkt_in_max']) . "</td>\n";
  108. print "<td class=\"data\">" . fpkts($row['pkt_out_max']) . "</td>\n";
  109. print "</tr>\n";
  110. $sum_in += $row['byte_in_sum'];
  111. $sum_out += $row['byte_out_sum'];
  112. }
  113. print "<tr align=center class=\"tr1\" onmouseover=\"className='tr2'\" onmouseout=\"className='tr1'\">\n";
  114. print "<td class=\"data\"><b>" . WEB_title_itog . "</b></td>\n";
  115. print "<td class=\"data\"><b> </b></td>\n";
  116. print "<td class=\"data\"><b>" . fbytes($sum_in) . "</b></td>\n";
  117. print "<td class=\"data\"><b>" . fbytes($sum_out) . "</b></td>\n";
  118. print "<td class=\"data\"><b></b></td>\n";
  119. print "<td class=\"data\"><b></b></td>\n";
  120. print "</tr>\n";
  121. ?>
  122. </table>
  123. <?php
  124. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  125. ?>