<?php
include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";

if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}

if(isset( $_SESSION["sess_affiliateid"]) and $_SESSION["sess_affiliateid"]!= ""){
	$affiliateid = $_SESSION["sess_affiliateid"];
}else{
	header("Location:login.php");
	exit;
}


if(isset($_GET["txtSearch"]) and $_GET["txtSearch"]!=""){
	$txtSearch = $_GET["txtSearch"];
	$cmbSearchType = $_GET["cmbSearchType"];
}else if(isset($_POST["txtSearch"]) and $_POST["txtSearch"]!=""){
	$txtSearch = $_POST["txtSearch"];
	$cmbSearchType = $_POST["cmbSearchType"];
}

if(isset($_POST['gotoPage']))
{

	header("Location:".$_SERVER['PHP_SELF']."?page=".$_POST['gotoPage']);
	
		
}

$qryopt="";
if($txtSearch != ""){
   if($cmbSearchType == "username"){
            $qryopt .= "  AND  ar.user_name like '" . addslashes($txtSearch) . "%'";
   }else if($cmbSearchType == "useremail"){
            $qryopt .= "  AND  ar.user_email like '" . addslashes($txtSearch) . "%'";
   }else if($cmbSearchType == "datereg"){
   		$dt = $txtSearch;
		$arrdt = explode("-",$dt) ;
		$day = $arrdt[1];
		$month = $arrdt[0];
		$year = $arrdt[2];
		$dt = $year."-". $month ."-".$day;
		$qryopt .= "  AND  ar.registration_date like '" . addslashes($dt) . "%'";
   }else if($cmbSearchType == "paid"){
   		$txtSearch = strtoupper(substr($txtSearch,0,1));
		if($txtSearch =="Y"){
			$qryopt .= "  AND  ar.affiliate_payment_id IS NOT NULL ";
		}else if($txtSearch =="N"){
			$qryopt .= "  AND  ar.affiliate_payment_id IS NULL ";
		}

   }
}

 $sql=" SELECT ar.* FROM ".$tableprefix."affiliate_registrations ar
		WHERE ar.affiliate_id = '".addslashes($affiliateid)."'  " . $qryopt . "
		order by ar.registration_date DESC ";
		
  /* $sql=" SELECT ar.* FROM ".$tableprefix."users ar
		WHERE ar.affiliate_id = '".addslashes($affiliateid)."'  " . $qryopt . "
		order by ar.date_registered DESC ";*/
		
		
	if(!(isset($pagenum)))
	{
		$pagenum = 1;
	} 
	
	$limit = 10;
	
	if(empty($page))
	{
		$page = 1;
	}
	
	$result=mysql_query($sql) or die(mysql_error());						
	
	$totalrows = mysql_num_rows($result);
	
	$limitvalue = ($page - 1) * $limit;
	
	$query_string = " LIMIT $limitvalue, $limit";
	
	$sql = $sql.$query_string;
	   
	$rs = mysql_query($sql) or die(mysql_error());

	$numofpages = ceil($totalrows / $limit);
include "../includes/htmltop.php";
?>

<script language="JavaScript" type="text/JavaScript">
function clickSearch()
{
	document.frmFeedbacks.submit();
}
function changeStatus(id){
	var frm = document.frmFeedbacks;
	if(Confirm(<?php echo QTN_CHNG_ST;?>)){
		document.frmFeedbacks.submit();
	}
}
</script>
<body>
		
		<center>
		
		<div align="left" id="layout">
		
		
				
				
				<!--header area start -->
<?php

	include_once("../includes/topheader_affiliate.php")

?>
				
				<!--header area end -->
				
				
				
				
				<div align="left" class="main_body">
				<!--main body start -->
				
				
				
<?php
		include_once("../includes/afftopmenu.php")
?>		
																					
								
					<div align="left" class="content_area">
					
					<!--content area start -->
							
					<div align="left" class="page_title"><?php echo TEXT_REGS;?></div>
					<div align="center" class="text_information grey_tr"><?php echo $message?></div>
            		<br>
											
					<div align="left">		
					
					<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="post" name="frmFeedbacks">
																										
					<table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_top">
						<tr>
							<td width="90%" align=left valign="top" class='toplinksCopy' ><?php echo TEXT_SEARCH;?> ::
								<select name="cmbSearchType" class="textarea">
									<option value="username"  <?php if($cmbSearchType == "username" || $cmbSearchType == ""){ echo("selected"); } ?> ><?php echo TEXT_USER_NAME;?></option>
									<option value="useremail"  <?php if($cmbSearchType == "useremail"){ echo("selected"); } ?> ><?php echo TEXT_USR_EMAIL;?></option>
									<option value="datereg"  <?php if($cmbSearchType == "datereg"){ echo("selected"); } ?>><?php echo TEXT_DT_REGSTD?> <?php echo TEXT_MM_DD_YY;?></option>
									<option value="paid"  <?php if($cmbSearchType == "paid"){ echo("selected"); } ?>><?php echo TEXT_PAID;?></option>
								</select> &nbsp;
								<input type="text" name="txtSearch" size="20" maxlength="50" value="<?php echo(htmlentities($txtSearch)); ?>"  onKeyPress="if(window.event.keyCode == '13'){ return false; }" class="textarea">
<a href="javascript:clickSearch();"><img src='<?php echo $imagefolder;?>/go.jpg' border='0'></a>
							</td>
						</tr>
					</table>
					
					</form>
					
					</div>
						
					<div align="left">
					
					<form action="" method="post" name="frmFeedbacks1">
					
					  <table border="0" width="100%" cellpadding="0" cellspacing="0" class="manage_table">
                        <tr class="form_header">
                          <th><?php echo TEXT_USER_NAME;?></th>
                          <th><?php echo TEXT_USR_FULNAME;?></th>
                          <th><?php echo TEXT_USR_EMAIL;?></th>
                          <th><?php echo TEXT_DT_PURCHASD?></th>
                          <th align="center"><?php echo  TEXT_AMT_PURCHSD;?> ( <?php echo $adminCurrency['currency_symbol'];?> )</th>
                          <th align="center"><?php echo TEXT_REF_CHARG;?> ( <?php echo $adminCurrency['currency_symbol'];?> )</th>
                          <th width="15%"><?php echo TEXT_PAID;?></th>
                        </tr>
                        <?php
if(mysql_num_rows($result) > 0 )
{
	$i = 1;
	$total = 0;
	while($row = mysql_fetch_array($rs)){
	
		/* "<br>".$sql_1=" SELECT ar.* FROM ".$tableprefix."affiliate_registrations ar
		WHERE ar.affiliate_id = '".addslashes($affiliateid)."' and user_id=\"".$row["user_id"]."\"  " . $qryopt . "
		order by ar.registration_date DESC ";
		$rs_1 = mysql_query($sql_1) or die(mysql_error());
		$row_affiliate = mysql_fetch_array($rs_1);*/
	
		$txtUserName = $row["user_name"];
		$link = "<a href='regdetails.php?rid=".$row["registration_id"]."'>";
		$txtRegistrationDate = (isNotNull($row["registration_date"] and ($row["registration_date"]!= "0000-00-00")) ? dateFormat($row["registration_date"],"Y-m-d","m/d/Y") : "");
		$txtUserFullName = $row["user_first_name"];
		$txtUserFullName.= $row["user_last_name"]!=""? " ".$row["user_last_name"]:"";
		//$txtPaid = $row["affiliate_payment_id"]!=""? "Yes":"No";
		$txtPaid = $row["affiliate_payment_id"]!=""? TEXT_YES:TEXT_NO;
?>
                        <tr>
                          <td align="left"><?php echo $link .htmlentities($txtUserName)."</a>";?></td>
                          <td align="left"><?php echo $link .htmlentities($txtUserFullName)."</a>";?></td>
                          <td align="left"><?php echo $link .htmlentities($row["user_email"])."</a>";?></td>
                          <td align="left"><?php echo $link .htmlentities($txtRegistrationDate)."</a>";?></td>
                          <td align="center"><?php if($row["user_totalpurchasedamount"])echo $link .htmlentities(number_format($row["user_totalpurchasedamount"], 2, '.', ''))."</a>";else echo "Not yet purchased product";?></td>
                          <td align="center"><?php if($row["referral_charge"])echo $link .htmlentities(number_format($row["referral_charge"], 2, '.', ''))."</a>";else echo "-";?></td>
                          <td align="center" class=""><?php echo $link .htmlentities($txtPaid)."</a>";?></td>
                        </tr>
                        <?php
	$i++;
	$total+= $row["referral_charge"];
	}
	if($total>0)
	{
	?>
                        <tr class="whitebg">
                          <td align="right" colspan="5"><b><?php echo TEXT_TOTAL;?></b>&nbsp;</td>
                          <td align="right" ><font color="RED"><b><?php echo $total; ?></b></font></td>
                          <td>&nbsp;</td>
						  
                        </tr>
                        <?php
	}
}
else
{
										
?>
                        <tr>
                          <td align="center" valign="middle" colspan="6"  class="text_information"><?php echo TEXT_NO_RECORD;?>!!</td>
                        </tr>
                        <?php										
}	
if($page > 1)
{
	$pageprev = $page-1;
	
	$previous_page = "<a href=".$_SERVER['PHP_SELF']."?page=$pageprev alt='Previous' border='0' class='small_gray_button'>prev</a>";
	
}
																				
													
if($page < $numofpages)
{
	$pagenext = ($page + 1);
	
	$next = "<a href=".$_SERVER['PHP_SELF']."?page=$pagenext alt='Next' border='0' class='small_gray_button'>next</a>";
	
}	
if($page < $numofpages || $page > 1)
{
?>
                        <tr>
                          <td class="page_nos"  align="center" colspan="7">
						  	<table width="100%" border="0" cellspacing="10" cellpadding="0">
								<tr align="left" valign="middle">
									<td width="21%" align="right"><?php echo $previous_page?></td>
									<td width="23%" align="right">
										Page(s) <?php echo $page ?>/<?php echo $numofpages?>&nbsp;&nbsp;Goto
									</td>
									<td width="8%" align="right">
										<select class="textarea2" name="gotoPage" style="padding:4px 5px; margin-bottom:1px; ">
											<?php
											for($i=1;$i<=$numofpages;$i++)
											{		
											if($i == $_GET['page'])
											{
											$page_selected = "selected";
											}
											else
											{
											$page_selected = "";
											}
											?>
											<option value="<?php echo $i?>" <?php echo $page_selected?>><?php echo $i?></option>
											<?php
											}
											?>
										</select>
									</td>
									<td width="7%">
										<a onClick="Javascript:document.frmFeedbacks1.submit();" class="go_button_2">Go</a>
									</td>
									<td width="41%" align="center"><?php echo $next?></td>
								</tr>
							</table>
						</td>
                        </tr>
						<?php
						}
						?>
                      </table>
					</form>
					  </div>
				<!--content area end-->
				</div>
					<div align="left" class="clear_float"><img src="<?php echo $imagefolder;?>/clear.gif" alt="" width="1" height="1" /></div>
				<!--main body end -->
				</div>
<?php
	include "../includes/footer.php";
?>