|
1
|
|
|
<?php |
|
2
|
|
|
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1; |
|
3
|
|
|
|
|
4
|
|
|
class Payout Extends Base { |
|
5
|
|
|
protected $table = 'payouts'; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Check if the user has an active payout request already |
|
9
|
|
|
* @param account_id int Account ID |
|
10
|
|
|
* @return boolean bool True of False |
|
11
|
|
|
**/ |
|
12
|
|
|
public function isPayoutActive($account_id) { |
|
13
|
|
|
$stmt = $this->mysqli->prepare("SELECT id FROM $this->table WHERE completed = 0 AND account_id = ? LIMIT 1"); |
|
14
|
|
|
if ($stmt && $stmt->bind_param('i', $account_id) && $stmt->execute( )&& $stmt->store_result() && $stmt->num_rows > 0) |
|
15
|
|
|
return true; |
|
16
|
|
|
return $this->sqlError('E0048'); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Insert a new payout request |
|
21
|
|
|
* @param account_id int Account ID |
|
22
|
|
|
* @param strToken string Token to confirm |
|
23
|
|
|
* @return data mixed Inserted ID or false |
|
24
|
|
|
**/ |
|
25
|
|
|
public function createPayout($account_id=NULL, $strToken) { |
|
26
|
|
|
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id) VALUES (?)"); |
|
27
|
|
|
if ($stmt && $stmt->bind_param('i', $account_id) && $stmt->execute()) { |
|
28
|
|
|
$insert_id = $stmt->insert_id; |
|
29
|
|
|
// twofactor - consume the token if it is enabled and valid |
|
30
|
|
|
if ($this->config['twofactor']['enabled'] && $this->config['twofactor']['options']['withdraw']) { |
|
|
|
|
|
|
31
|
|
|
$tValid = $this->token->isTokenValid($account_id, $strToken, 7); |
|
|
|
|
|
|
32
|
|
|
if ($tValid) { |
|
33
|
|
|
$delete = $this->token->deleteToken($strToken); |
|
34
|
|
|
if (!$delete) { |
|
35
|
|
|
$this->log->log("info", "User $account_id requested manual payout but failed to delete payout token"); |
|
36
|
|
|
$this->setErrorMessage('Unable to delete token'); |
|
37
|
|
|
return false; |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
} else { |
|
40
|
|
|
$this->log->log("info", "User $account_id requested manual payout using an invalid payout token"); |
|
41
|
|
|
$this->setErrorMessage('Invalid token'); |
|
42
|
|
|
return false; |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
return $insert_id; |
|
46
|
|
|
} |
|
47
|
|
|
return $this->sqlError('E0049'); |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Mark a payout as processed |
|
52
|
|
|
* @param id int Payout ID |
|
53
|
|
|
* @return boolean bool True or False |
|
54
|
|
|
**/ |
|
55
|
|
|
public function setProcessed($id) { |
|
56
|
|
|
$stmt = $this->mysqli->prepare("UPDATE $this->table SET completed = 1 WHERE id = ? LIMIT 1"); |
|
57
|
|
|
if ($stmt && $stmt->bind_param('i', $id) && $stmt->execute()) |
|
58
|
|
|
return true; |
|
59
|
|
|
return $this->sqlError('E0051'); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$oPayout = new Payout(); |
|
64
|
|
|
$oPayout->setDebug($debug); |
|
65
|
|
|
$oPayout->setLog($log); |
|
66
|
|
|
$oPayout->setMysql($mysqli); |
|
67
|
|
|
$oPayout->setConfig($config); |
|
68
|
|
|
$oPayout->setToken($oToken); |
|
69
|
|
|
$oPayout->setErrorCodes($aErrorCodes); |
|
70
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: