<?php
if(!defined('R_P')) exit('Access Denied');
$code = trim($_GET['u']);
if(!ereg('^[a-z0-9]+$', $code)) qbase::showmsg("error request");
$_output = qdb::queryFirst("select * from ".TABLEPRE."url where code = '{$code}' ");
if(empty($_output)) qbase::showmsg("not found");
if(AJAX || JSONP){
	if(!qbase::UpdateCount('d',$_output['viewtime'])){
		$_output['dview'] = 0;
	}
	$data = array('status'=>200, 'dview'=>$_output['dview'], 'views'=>$_output['views']);
	echo qbase::xmlPrint(qbase::jsonencode($data));
}else{
	if(qbase::UpdateCount('d',$_output['viewtime'])){
			 $setup = " , dview=dview+1 ";   
	}else{
			 $setup = " , dview=1 ";  
	}
	qdb::query("update ".TABLEPRE."url set views = views + 1 {$setup} , viewtime = '{$_SERVER['REQUEST_TIME']}' where id = '{$_output['id']}' ");
	header("location:" . $_output['url']);
}
?>