summaryrefslogtreecommitdiffstats
path: root/classes/lockedaccounts.class.php
blob: 508fe3338744b4d6d6009991507beedeb54a2694 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?

/**
 * Class to manage locked accounts
 */
class LockedAccounts
{

    /**
     * Lock an account
     *
     * @param int $UserID The ID of the user to lock
     * @param int $Type The lock type, should be a constant value
     * @param string $Message The message to write to user notes
     * @param string $Reason The reason for the lock
     * @param int $LockedByUserID The ID of the staff member that locked $UserID's account. 0 for system
     */
    public static function lock_account($UserID, $Type, $Message, $Reason, $LockedByUserID)
    {
        
        if ($LockedByUserID == 0) {
            $Username = "System";
        } else {
            G::$DB->query("SELECT Username FROM users_main WHERE ID = '" . $LockedByUserID . "'");
            list($Username) = G::$DB->next_record();
        }

        G::$DB->query("
                INSERT INTO locked_accounts (UserID, Type)
                VALUES ('" . $UserID . "', " . $Type . ")");
        Tools::update_user_notes($UserID, sqltime() . " - " . db_string($Message) . " by $Username\nReason: " . db_string($Reason) . "\n\n");
        G::$Cache->delete_value('user_info_' . $UserID);
    }

    /**
     * Unlock an account
     *
     * @param int $UserID The ID of the user to unlock
     * @param int $Type The lock type, should be a constant value. Used for database verification
     *                  to avoid deleting the wrong lock type
     * @param string $Reason The reason for unlock
     * @param int $UnlockedByUserID The ID of the staff member unlocking $UserID's account. 0 for system
     */
    public static function unlock_account($UserID, $Type, $Message, $Reason, $UnlockedByUserID)
    {
        if ($UnlockedByUserID == 0) {
            $Username = "System";
        } else {
            G::$DB->query("SELECT Username FROM users_main WHERE ID = '" . $UnlockedByUserID . "'");
            list($Username) = G::$DB->next_record();
        }

        G::$DB->query("DELETE FROM locked_accounts WHERE UserID = '$UserID' AND Type = '". $Type ."'");

        if (G::$DB->affected_rows() == 1) {
            G::$Cache->delete_value("user_info_" . $UserID);
            Tools::update_user_notes($UserID, sqltime() . " - " . db_string($Message) . " by $Username\nReason: " . db_string($Reason) . "\n\n");
        }
    }
}