<?
define("PARTNER_AUTHORIZATION",1);
include("../../../includes/common.php");

/*PAGE TITLE*/
$page_title = "Клики";

$header = "Клики";

$table = "partner_clicks";
/* pager start */
$params['tables'] = $table;
$params['nocheckfield']=true;
$params['s_prefix'] = $table;
$params['query'] = "select count(*) from $table where partner_id=$PARTNER_ID";

$pager = GetPagerParams($params);
/* pager end */


$table_headers = Array(
	"itter"=>Array("№","width=20 align=center"),
	"ip"=>Array("<a href='".$pager['new_sort']."$table".".ip' title='Sort'>IP</a>","width=100 align=center"),
	"proxy"=>Array("<a href='".$pager['new_sort']."$table".".proxy_ip' title='Sort'>Прокси</a>","width=100 align=center"),
	"referer"=>Array("<a href='".$pager['new_sort']."$table".".referer' title='Sort'>Реферер</a>","width=100 align=center"),
	"user_agent"=>Array("<a href='".$pager['new_sort']."$table".".user_agent' title='Sort'>Агент</a>","width=100 align=center"),
	"date"=>Array("<a href='".$pager['new_sort']."$table".".regdate' title='Sort'>Дата</a>","align=center"),
);

$query = "select $table.* from $table where partner_id=$PARTNER_ID ORDER BY ".$pager['sort_by']." ".$pager['sort_ord']
  ." LIMIT 10".$SETTINGS['admin_items_per_page']." OFFSET ".($pager['start_item']-1);

//echo $query;

$res = mysql_query($query);
//echo mysql_error();
$table_items=Array();
$itter =$pager['start_item'];
$i=0;

while ($row = mysql_fetch_object($res)){

	if($row->proxy_type==1){
	  $proxy_type = 'transparent';
	  $xls['proxy_type'] = $proxy_type;
	}
	elseif($row->proxy_type==2){
	  $proxy_type = "<b><font color=red>anonymous</font></b>";
	}
	else{
	  $proxy_type = '-';
	}
	
	if(trim($row->referer)!=""){
		$arr = parse_url(stripslashes($row->referer));
		$referer = "<a href='$row->referer' target=_blank>$arr[host]</a>";
	}
	else{
		$referer = "-";
	}


	$table_items[$itter] = Array(
		"id"=>array($row->id,"align=center"),
		"itter"=>array($itter,"align=center"),
		"ip"=>array("<a href='#' title='Просмотр инфо' onClick='ip_info(\"$row->ip\");return false;'>$row->ip</a>","align=center"),
		"proxy"=>array(($row->$row->proxy_ip!=""?"<a href='#' onClick='ip_info(\"$row->ip\");return false;'>$row->proxy_ip</a><br>":"").$proxy_type,"align=center"),
		"referer"=>array($referer,"align=center"),
		"user_agent"=>array(stripslashes($row->user_agent)),
		"date"=>Array(strftime("%d %b %Y<br><small>%H:%M:%S</small>",$row->regdate),"align=center"),
);
	$itter++;
}

$smarty->assign('page_title',"Клики");

$smarty->assign('error',$error);

/* table template */
$smarty->assign('pager',$pager);
$smarty->assign('table_headers',$table_headers);
$smarty->assign('table_items',$table_items);
$smarty->assign('table_width',"90%");
$smarty->assign('top_menu_tpl',"partner_clicks_menu.tpl");
$smarty->assign('main_tpl',"admin_list_table.tpl");
$smarty->assign('use_group_funcs',array_key_exists("group_funcs",$table_headers));

/* display content */
$smarty->display('partner_index.tpl');
?>