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

$ruid = isset($_GET['ruid']) ? S::gp('ruid', 'G', 2) : 2;

$aid = $adList[rand(0, count($adList) - 1)];
$adUrl = url('ad', array('aid'=>$aid));
$ad = $db->select()->from(Ad::table())->where(array('adid'=>$aid))->find(true);
if (empty($ad) || !$ad['status'])
{
    $adUrl = url('index');
}
$isSpider = getrobot();
$ua = S::getServer('HTTP_USER_AGENT');
$valid = IS_MOBILE ? (CMOBILE ? 1 : 0) : 0;


$db->insert(EntranceLogs::table())->value(array('ua'=>$ua,'aid'=>$aid,'ruid'=>$ruid,'ip'=>ONLINE_IP,'createdate'=>CDATETIME,'date'=>CDATE,'valid'=>$valid,'isspider'=>$isSpider))->q();
$indexUrl = url('index');

$_SESSION['user']['reward'] = $ruid;
$_SESSION['user']['entrance_id'] = $db->getInsertId();
$_SESSION['user']['entrance_click'] = 1;

if (IS_MOBILE)
{
    backJump($indexUrl, $adUrl);
}
else
{
    iforward($indexUrl);
}