<?php
include("inc.top.php");
$q=new Cdb;
$q2=new Cdb;

//	$t->set_file("content", "view_campains.ag.html");
//	$t->set_file("campaign_row_file", "view_campains_row.html");
	$t->set_file("content", "statistics_row.html");
//	$t->set_file("content", "view_campains_row.html");
	
	get_logged_info();
	//echo $id;
	if (!$page) $page=1;
	for ($i=0;$i<=floor($total/200); $i++)
	{
		$pages.="<a style='cursor:pointer; text-decoration:underline; color:#0000FF' onClick=\"xmlHttp('view_campains.row.php?id=$id&total=$total&page='+".($i+1).",'camp_".$id."_td','get');\">".($i+1)."</a> | ";
		
	}
	$ocontent="<div align=center>".substr($pages,0, strlen($pages)-2)."</div><br>";
	$page=($page-1)*200;
		$q2->query("SELECT c.name AS aff_name, a.name, a.email, a.mails_sent, a.nr_joined, a.camp_id, a.date_click, a.ip, a.not_mail, a.aff FROM track a, track c WHERE a.camp_id='".$id."'  AND (a.aff=c.id OR a.aff=0 )AND a.id!=1 GROUP BY a.id LIMIT $page,200");
	//	echo "SELECT c.name AS aff_name, a.name, a.email, a.mails_sent, a.nr_joined, a.camp_id, a.date_click, a.ip, a.not_mail, a.aff FROM track a, track c WHERE a.camp_id='".$id."'  AND (a.aff=c.id OR a.aff=0 )AND a.id!=1 GROUP BY a.id";
		$stats = '';
		while ($q2->next_record()){

			if ($q2->f("mails_sent"))
				$total_mails += $q2->f("mails_sent");
			if ($q2->f("nr_joined"))
				$total_joined += $q2->f("nr_joined");
			if ($q2->f("not_mail"))	
				$total_unsub++;
			if ($q2->f("date_click") != "0000-00-00 00:00:00")	
				$total_click++;
			$t->set_var("name",$q2->f("name"));
			$t->set_var("email",$q2->f("email"));
			$t->set_var("mails_sent",$q2->f("mails_sent"));
			$t->set_var("nr_joined",$q2->f("nr_joined"));
			$t->set_var("date_click",($q2->f("date_click") == "0000-00-00 00:00:00" ? "Not Clicked" : $q2->f("date_click")));
			$t->set_var("ip",$q2->f("ip"));
			$t->set_var("not_mail",($q2->f("not_mail") ? "Yes" : "No"));
			$t->set_var("aff",($q2->f("aff_name") != '' ? $q2->f("aff_name") : "None"));
			$stats .= $t->parse("statistics", "content", true);
		}
//		$t->set_var("total",$q2->nf());
//		$t->set_var("total_mails",$total_mails);
//		$t->set_var("total_joined",$total_joined);
//		$t->set_var("total_unsub",$total_unsub);
//		$t->set_var("total_click",$total_click);
//		$t->set_var("statistics", $stats);
//		$t->parse("fields_row", "view_campains_row.html", true);
//		$t->unset_var("border_".($q->f("border_table") ? $q->f("border_table") : '0'));
//		$t->unset_var("size_".($q->f("size") ? $q->f("size") : '0'));
//		$t->unset_var("style_".($q->f("style") ? $q->f("style") : '0'));
//		$t->unset_var($font_select ? $font_select : 'Arial');
	

//			$t->set_file("menu_html", "member.area.menu.html");
//			
//			$t->parse("menu", "menu_html");

	echo '<td colspan="333">
<table width="100%" border="1" style="border-collapse:collapse">
	<tr>
		<td><strong>Name</strong></td>
		<td><strong>E-Mail</strong></td>
		<td><strong>Number of mails sent to friends</strong></td>
		<td><strong>Number of friends joined</strong></td>
		<td><strong>Date click</strong></td>
		<td><strong>IP</strong></td>
		<td><strong>Unsubscribed</strong></td>
		<td><strong>Referer</strong></td>
	</tr>
',$stats.'<tr><td colspan="8"'.$ocontent.'</td></tr></table>
</td>';
//echo '<td colspan="333">csdcasdfasdfasdfasf</td>';
	
//include("inc.bottom.php");
?>