<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
define('IN_IORANGE', true);
include('../include/init.php');

$target = url('index');

if (empty($_GET['v']) || empty($_GET['aid']) || !$iorange_id)
{
	iforward($target);
}

$adid = intval($_GET['aid']);
$validKey = trim($_GET['v']);

$row = $db->select()
		  ->from(Adtmp::table())
		  ->where(array('valid_key'=>$validKey))
		  ->find(true);
if (empty($row))
{
	iforward($target);
}

if ($_SESSION['user']['ads'])
{
    $_SESSION['user']['ads'] = 0;
    iCredits::single($iorange_id, $username)->addMoney($row['point']);
}

$ad = $db->select()
		 ->from(Ad::table())
		 ->where(array('adid'=>$adid))
		 ->find(true);
$target = $ad['url'];

$db->delete(Adtmp::table())
   ->where(array('valid_key'=>$validKey))
   ->q();
iforward($target);