Skip to content

Commit 1550553

Browse files
committed
[ADDED] Validate all users option
1 parent 54a1452 commit 1550553

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

scripts/validate_users.php

100644100755
Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
// Include all settings and classes
99
require_once('shared.inc.php');
10-
11-
$timeLimitInDays = 90;
10+
11+
$options = getopt("d:a");
12+
isset($options['d']) ? $timeLimitInDays = (int)$options['d'] : $timeLimitInDays = 90;
13+
isset($options['a']) ? $allUsers = true : $allUsers = false;
1214
$notifyStaleUsers = False;
1315

1416
// Fetch all users
@@ -19,54 +21,53 @@
1921

2022
$currentTime = time();
2123
$totalSavings = 0;
22-
23-
foreach ($users as $user)
24-
{
24+
25+
foreach ($users as $user) {
2526
$id = $user['id'];
2627
$isAdmin = $user['is_admin'];
2728
$username = $user['username'];
2829
$loggedIp = $user['loggedIp'];
2930
$lastLogin = $user['last_login'];
3031
$coinAddress = $user['coin_address'];
3132
$mailAddress = $user['email'];
32-
33+
3334
$everLoggedIn = !empty($lastLogin);
3435
$timeDelta = $currentTime - $lastLogin;
3536
$lastLoginInDays = round(abs($timeDelta)/60/60/24, 0);
36-
37-
if($lastLoginInDays < $timeLimitInDays)
37+
38+
if(!$allUsers && $lastLoginInDays < $timeLimitInDays)
3839
continue;
39-
40+
4041
// get transactions summary for the user
41-
$summary = $transaction->getTransactionSummary($id);
42+
$summary = $transaction->getTransactionSummary($id);
4243
$transactions_exists = !empty($summary);
43-
44+
4445
// get balances
4546
$balances = $transaction->getBalance($id);
4647
$confirmedBalance = $balances['confirmed'];
47-
$totalSavings += $confirmedBalance;
48-
48+
$totalSavings += $confirmedBalance;
49+
4950
$staleAccount = $everLoggedIn == false && $transactions_exists == false;
50-
51+
5152
if ($notifyStaleUsers) {
5253
$subject = "Account at " . $setting->getValue('website_name') . "!";
5354
$body = "Hi ". $username .",\n\nWe have discovered \
5455
your username as inactive. Your last login is older than 90 days, \
5556
please reactivate your Account if you want to mine again, \
5657
else it will be deleted in 30 days.\n\nBalance left: ". $confirmedBalance . " " . $config['currency'] . "\n\nCheers";
57-
58+
5859
if (mail($mailAddress, $subject, $body)) {
5960
echo("Email successfully sent!");
6061
} else {
6162
echo("Email delivery failed...");
6263
}
6364
}
6465

65-
printf($mask, $id, $username, $mailAddress,
66+
printf($mask, $id, $username, $mailAddress,
6667
$loggedIp, strftime("%Y-%m-%d %H:%M:%S", $lastLogin), $lastLoginInDays, $everLoggedIn ? 'yes' : 'no',
6768
$transactions_exists ? 'yes' : 'no', round($confirmedBalance,8),
68-
$staleAccount ? 'yes' : 'no' );
69+
$staleAccount ? 'yes' : 'no' );
6970
}
7071

7172
echo "Total balance of stale accounts: $totalSavings" . PHP_EOL;
72-
?>
73+
?>

0 commit comments

Comments
 (0)