<?php

class Out extends Controller {

	/**
	 * @param $f3 \Base
	 * @param $params
	 */
	public function processAdClick($f3, $param){
		$id = $f3->get('PARAMS.id');
		if (empty($id)) return;

		$ad = new \Models\Ad();
		$ad->load(array('_id=? AND status=1',$id));
		if ($ad->dry()) return;

		$userAgent=empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
		\In::InsertStatsQueue($f3, 0, 0, 1, $id, null, null, null, null, null, null, $userAgent);

		$url = '';
		switch ($ad->type){
			case 'banner':
				$url=$ad->type_banner->url;
				break;
			case 'textlink':
				$url=$ad->type_textlink->url;
				break;
			case 'video':
				$url=$ad->type_video->url;
				break;
		}

		header('Location: '.$url);
	}

}