Skip to content
Snippets Groups Projects
start.class.php 2.01 KiB
Newer Older
Eric Laufer's avatar
Eric Laufer committed
<?php

Eric Laufer's avatar
Eric Laufer committed
	private $db;
	private $session = array();
	private $grund;
	private $error = 0;
	private $meldung = '';
	private $konto;
	private $reload = 0;
	private $ip;
	
	public function __construct(){
Eric Laufer's avatar
Eric Laufer committed
		global $datenbank,$_SESSION,$grundconfig;
		$this->db = $datenbank;
		$this->session = $this->db->escape($_SESSION);
		$this->grund = $grundconfig;
		$this->ip = $_SERVER['REMOTE_ADDR'];
		$this->konto = Classloader('kontobuchung');
Eric Laufer's avatar
Eric Laufer committed
	}
	
	public function StartAbruf(){
		$this->ReloadCheck();
		if($this->error == 0){
			$new_reload = $this->grund->reload_start + time();
			$this->db->insert(PREFIX . RELOAD, array("ip" => $this->ip,"uid" => $this->db->escape($this->session['uid']),"tan" => 'startseitenaufruf',"bis" => $new_reload));
			$this->StatistikUpgrade();
			$this->konto->set_var($this->session['uid'],$this->grund->verdienst_start,'+','System Startseitenverg&uuml;tung');
Eric Laufer's avatar
Eric Laufer committed
			$this->meldung = '<b>Du hast gerade '.number_format($this->grund->verdienst_start,2,',','.').' für diesen Aufruf erhalten!</b>';
		}
		$aus = array("error" => $this->error, "meldung" => $this->meldung);
		return $aus;
	}
	
	private function StartLog(){
		$array = array(
			"uid" => $this->session['uid'],
			"datum" => time(),
			"betrag" => $this->grund->verdienst_start
		);
		$this->db->insert(PREFIX . START_LOG, $array);
Eric Laufer's avatar
Eric Laufer committed
	private function StatistikUpgrade(){
		$row = $this->db->get_row("SELECT s_verdienst,s_aufrufe FROM ". PREFIX . KONTO ." WHERE uid = '". $this->session['uid'] ."' ",true);
		$s_aufruf = $row->s_aufrufe + 1;
		$s_verdienst = $row->s_verdienst + $this->grund->verdienst_start;
		$this->db->update(PREFIX . KONTO, array("s_aufrufe" => $s_aufruf, "s_verdienst" => $s_verdienst ),array("uid" => $this->session['uid']) );
	}
	
	private function ReloadCheck(){
		if($this->db->num_rows("SELECT * FROM ". PREFIX . RELOAD ." WHERE uid = '".$this->session['uid']."' and tan = 'startseitenaufruf' and bis >= '".time()."'") != 0){
			$this->error = 1;
			$this->meldung .= ERROR_RELOAD_START_AKTIV;
		}
	}
}