authday.php 5.6 KB

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