Completed
Push — work-fleets ( 837dd8...8a98bd )
by SuperNova.WS
05:20
created

adm_user_analyze.php ➔ checkSuspicious()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
c 1
b 0
f 0
nc 2
nop 4
dl 0
loc 13
rs 9.4285
1
<?php
2
3
/**
4
 * adm_payment.php
5
 *
6
 * @version 1.0
7
 * @copyright 2013 by Gorlum for http://supernova.ws
8
 */
9
define('INSIDE', true);
10
define('INSTALL', false);
11
define('IN_ADMIN', true);
12
13
require('../common.' . substr(strrchr(__FILE__, '.'), 1));
14
15
if ($user['authlevel'] < 3) {
16
  AdminMessage(classLocale::$lang['adm_err_denied']);
17
}
18
19
// define('SESSION_INTERRUPT', 15*60); // Можно увеличить до 4 часов - никито не может сидеть 2 суток с перерывом менее 4 часов
0 ignored issues
show
Unused Code Comprehensibility introduced by
52% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
20
// define('SUSPICIOUS_LONG', 2 * 60*60); // Тогда это увеличиваем до, скажем суток - и там смотрим
21
22
define('SESSION_INTERRUPT', 1 * 60 * 60); // Можно увеличить до 4 часов - никито не может сидеть 2 суток с перерывом менее 4 часов
23
define('SUSPICIOUS_LONG', 16 * 60 * 60); // Тогда это увеличиваем до, скажем суток - и там смотрим
24
25
$last_id = 0;
26
$session_list = array();
27
$query = db_counter_list_by_week();
28
$session = array();
29
if ($row = db_fetch($query)) {
30
  $session = array(
31
    0 => strtotime($row['visit_time']), // start
32
    1 => strtotime($row['visit_time']), // end
33
  );
34
  $last_id = $row['user_id'];
35
}
36
37
/**
38
 * @param $session
39
 * @param $session_list
40
 * @param $last_id
41
 * @param $row
42
 */
43
function checkSuspicious(&$session, &$session_list, &$last_id, &$row) {
44
  $session[2] = $session[1] - $session[0];
45
  if ($session[2] > SUSPICIOUS_LONG) {
46
    $session[2] = pretty_time($session[2]);
47
    $session[0] = date(FMT_DATE_TIME_SQL, $session[0]);
48
    $session[1] = date(FMT_DATE_TIME_SQL, $session[1]);
49
    $session_list[$last_id][] = $session;
50
  }
51
  $session = array(
52
    0 => $row['visit_time'], // start
53
    1 => $row['visit_time'], // end
54
  );
55
}
56
57
while ($row = db_fetch($query)) {
58
  $row['visit_time'] = strtotime($row['visit_time']);
59
  if ($last_id == $row['user_id']) {
60
    // Тот же юзер
61
    if ($row['visit_time'] - $session[1] <= SESSION_INTERRUPT) { // Та же сессия
62
      $session[1] = $row['visit_time'];
63
    } else {
64
      // Новая сессия
65
      checkSuspicious($session, $session_list, $last_id, $row);
66
    }
67
  } else {
68
    checkSuspicious($session, $session_list, $last_id, $row);
69
//    $session[2] = $session[1] - $session[0];
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
70
//    if ($session[2] > SUSPICIOUS_LONG) {
71
//      $session[2] = pretty_time($session[2]);
72
//      $session[0] = date(FMT_DATE_TIME_SQL, $session[0]);
73
//      $session[1] = date(FMT_DATE_TIME_SQL, $session[1]);
74
//      $session_list[$last_id][] = $session;
75
//    }
76
//    $session = array(
77
//      0 => $row['visit_time'], // start
78
//      1 => $row['visit_time'], // end
79
//    );
80
    $last_id = $row['user_id'];
81
  }
82
}
83
84
if ($last_id) {
85
  checkSuspicious($session, $session_list, $last_id, $row);
86
//  $session[2] = $session[1] - $session[0];
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
87
//
88
//  if ($session[2] > SUSPICIOUS_LONG) {
89
//    $session[2] = pretty_time($session[2]);
90
//    $session[0] = date(FMT_DATE_TIME_SQL, $session[0]);
91
//    $session[1] = date(FMT_DATE_TIME_SQL, $session[1]);
92
//    $session_list[$last_id][] = $session;
93
//  }
94
}
95
96
print("<table border='1'>");
97
print("<tr>");
98
print("<td>ID</td><td>Username</td><td>Start</td><td>End</td><td>Length</td>");
99
print("<td>Last online</td>");
100
print("</tr>");
101
foreach ($session_list as $user_id => $value) {
102
  $user_record = DBStaticUser::getOnlineTime($user_id);
103
  foreach ($value as $interval_data) {
104
    print("<tr>");
105
    print("<td>{$user_id}</td><td>{$user_record['username']}</td><td>{$interval_data[0]}</td><td>{$interval_data[1]}</td><td>{$interval_data[2]}</td>");
106
    print("<td>" . date(FMT_DATE_TIME_SQL, $user_record['onlinetime']) . "</td>");
107
    print("</tr>");
108
  }
109
}
110
print("</table>");
111