Newer
Older
Christoph Zysik
committed
<?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 addContentToReload( $cid, $uid, $ip, $until )
{
$sql = 'INSERT INTO `'.DB_PREFIX.'_content_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 isCampaignInReload( $cid, $uid, $ip )
{
}
public function isContentInReload( $cid, $uid, $ip )
{
}
Christoph Zysik
committed
public function invalidateAlreadyRunningAd( $uid, $ip )
{
$result = false;
Christoph Zysik
committed
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->getIsClickableById( $id, $ip, $uid, $zeit );
if( false !== $kamp )
Christoph Zysik
committed
{
$until = $zeit + $kamp->reload;
Christoph Zysik
committed
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
$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;
}
}