Newer
Older
Christoph Zysik
committed
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/*
* TODO
* nothing checks wether user landed on blacklist...
* blacklist check is broken currently anyway
* please fix me
*/
class Ptc
{
private $database;
private $campaigns;
public function __construct($database, $campaigns)
{
$this->database = $database;
$this->campaigns = $campaigns;
}
public function addCampaignToReload( $cid, $uid, $ip, $until )
{
$sql = 'INSERT INTO `'.DB_PREFIX.'_campaign_reloads`
(`ip`, `uid`, `cid`, `until`) VALUES
(:aip, :auid, :acid, :auntil) ON DUPLICATE KEY UPDATE
`until` = :buntil ';
$sql_params = array(
':aip' => $ip,
':auid' => $uid,
':acid' => $cid,
':auntil'=> $until,
':buntil'=> $until,
);
return $this->database->rawInsert( $sql, $sql_params );
}
public function invalidateAlreadyRunningAd( $uid, $ip )
{
$result = false;
if( isset($_SESSION['current_ad']) )
{
$tan = ( isset($_SESSION['current_ad']['tan']) ) ? $_SESSION['current_ad']['tan'] : false;
$art = ( isset($_SESSION['current_ad']['art']) ) ? $_SESSION['current_ad']['art'] : '';
$id = ( isset($_SESSION['current_ad']['id']) ) ? $_SESSION['current_ad']['id'] : 0;
if( 0 !== $id )
{
$kamp = $this->campaigns->getById( $id );
if( 0 < $kamp['count'] )
{
$until = time() + $kamp['data']->reload;
$this->addCampaignToReload( $id, $uid, $ip, $until );
}
}
unset( $_SESSION['current_ad'] );
$result = true;
}
return $result;
}
public function setCurrentRunningAd( $art, $cid, $tan )
{
$_SESSION['current_ad']['art'] = $art;
$_SESSION['current_ad']['id'] = $cid;
$_SESSION['current_ad']['tan'] = $tan;
$_SESSION['current_ad']['time'] = time();
$_SESSION['current_ad']['paid'] = false;
}
public function handleAdPayout( $cid, $adtype, $uid, $ip, $preis, $verdienst, $msg = 'Paid4Action', $billanzcat = 'Werbebereich' )
{
$result = true;
// TODO adtype dependent counter table
db_query("UPDATE `".DB_PREFIX."_kontodaten` SET `klicks` = `klicks` + 1, `kv` = `kv` + ".$verdienst.", `fc_klicks` = `fc_klicks` + 1 WHERE `uid` = ".$uid); // Hier Zusatz für Fakeschutz
kontobuchung ('+', $verdienst, create_code(14), $uid, 1, $msg);
refumsatz ($verdienst, $uid);
// TODO add handler $adtype dependent
rallysystem ($uid, '1', $verdienst);
bilanz($preis, $verdienst, $billanzcat, $msg);
return $result;
}
function checkAdOkAndPay( $cid, $uid, $ip )
{
$result = false;
$time = time();
$data = $this->campaigns->getIsClickableById( $cid, $ip, $uid, $time );
if ( false !== $data )
{
$timepassed = ( $time - $_SESSION['current_ad']['time'] ) +1;
if( $timepassed >= $data->aufendhalt )
{
$until = $time + $data->reload;
$this->handleAdPayout( $cid, $data->werbeart, $uid, $ip, $data->preis, $data->verdienst );
$this->addCampaignToReload( $cid, $uid, $ip, $until );
$this->campaigns->decreaseAvailCountById( $cid, 1 );
$_SESSION['current_ad']['paid'] = true;
$result = true;
}
}
return $result;
}
}