<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com � 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?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_adminname"]) and $_SESSION["sess_adminname"]!= ""){
	$adminname = $_SESSION["sess_adminname"];
}else{
	header("Location:login.php");
	exit;
}
if (isset($_GET["aid"]) and $_GET["aid"] != "") {
    $aid = $_GET["aid"];
} else if (isset($_POST["aid"]) and $_POST["aid"] != "") {
    $aid = $_POST["aid"];
} else{
	header("Location:affiliates.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.*,a.affiliate_name FROM ".$tableprefix."affiliate_registrations ar INNER JOIN ".$tableprefix."affiliates a ON a.affiliate_id = ar.affiliate_id
	 	 WHERE  ar.affiliate_id='".addslashes($aid)."' " . $qryopt . "
		order by ar.registration_date DESC ";



	if(!(isset($pagenum)))
	{
		$pagenum = 1;
	} 
	
	$limit = getSettingsValue('npagination_limit');
	
	$page = isset($_GET['page'])? trim($_GET['page']):1;

	
	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 CONFIRM_CHANGE_STATUS;?>")){
		document.frmFeedbacks.submit();
	}
}
</script>

<body>
<center>
		
		<div align="left" id="layout">
				<!--header area start -->
<?php
	include_once("../includes/topheader_admin.php")
?>
				<!--header area end -->
				<div align="left" class="main_body">
				<!--main body start -->
<?php
		include_once("../includes/admintopmenu.php")
?>		
					<div align="left" class="content_area">
					<!--content area start -->
					<div align="left" class="page_title"><?php echo AFF_REG;?></div>
					<div align="center" class="text_information"><?php echo $message?></div>
					<form action="<?php echo $_SERVER["PHP_SELF"];?>" method="post" name="frmFeedbacks">
						<input type="hidden" name="aid" value="<?php echo  htmlentities($aid)?>" >
					<div align="left">
					<table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
						  <tr>
							<th width="4%" align="center" valign="middle">#</th>
							<th width="10%" align="left" valign="middle"><?php echo AFFILIATE;?></th>
							<th width="13%" align="left" valign="middle"><?php echo USER_NAME;?></th>
							<th width="13%" align="left" valign="middle"><?php echo USER_EMAIL;?></th>
							<th width="15%" align="center" valign="middle"><?php echo DATE_PURCHASE;?></th>
							<th width="20%" align="center" valign="middle"><?php echo AMT_PURCHASE;?> ( <?php echo $adminCurrency['currency_symbol'];?> )</th>
							<th width="17%" align="center" valign="middle"><?php echo REFERRAL_CHARGE;?> ( <?php echo $adminCurrency['currency_symbol'];?> )</th>
							<th width="8%" align="center" valign="middle" colspan="2"><?php echo PAID;?></th>
						  </tr>
<?php
$total = 0;
$i = 1;
if(mysql_num_rows($result) > 0 )
{
	while($row = mysql_fetch_array($rs))
	{
		$link = "<a class=links href='affiliateregdetails.php?rid=".$row["registration_id"]."' class='smalllink'>";
		$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"]!=""? "Y":"N";
		if($txtPaid=="N"){
			$check = "<input type='checkbox' name='chkreg[]' value='" . $row["registration_id"] . "' class='checkbox'> ";
		}else{
			$check = "&nbsp;";
		}

?>
				<tr>
					<td align='left'><?php echo $i;?></td>
					<td align='left'><?php echo $link .($row["affiliate_name"])."</a>";?></td>
					<td align='left'><?php echo $link .($row["user_name"])."</a>";?></td>
					<td align='left'><?php echo $link .htmlentities($row["user_email"])."</a>";?></td>
					<td align='center'><?php echo $link .htmlentities($txtRegistrationDate)."</a>";?></td>
					<td align='center'><?php echo $link .htmlentities($row["user_totalpurchasedamount"])."</a>";?></td>
					<td align='center'><?php echo $link .htmlentities($row["referral_charge"])."</a>";?></td>
					<td align='center'><?php echo $link .htmlentities($txtPaid)."</a>";?></td>
				</tr>
<?php
				$i++;
				$total+= $row["referral_charge"];
				}
					}
					else
					{
										
?>										
					<tr>
						<td align="center" valign="middle" colspan="9" class="text_information"><?php echo NO_REC_FOUND;?></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'>".TEXT_PREV."</a>";
					
				}
																								
																	
				if($page < $numofpages)
				{
					$pagenext = ($page + 1);
					
					$next = "<a href=".$_SERVER['PHP_SELF']."?page=$pagenext alt='Next' border='0' class='small_gray_button'>".TEXT_NEXT."</a>";
					
				}	
?>				
				
<?php						
				
				
				if($total >0)
				{
?>
				<tr><td align="right" colspan="6"><b><?php echo TOTAL_TEXT;?>&nbsp;:</b>&nbsp;</td><td align="right" ><font color="RED"><b><?php echo $total; ?></b></font></td><td>&nbsp;</td></tr>
<?php 
				}
?>
				<tr>
					<td colspan="8" align="center">
						<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">
									<?php echo PAGE_TEXT;?> <?php echo $page ?>/<?php echo $numofpages?>&nbsp;&nbsp;
									<?php echo GO_TO;?>
								</td>
								<td width="8%" align="right">
									<select 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.frmFeedbacks.submit();" class="go_button_2"><?php echo GO; ?></a>
								</td>
								<td width="41%" align="center"><?php echo $next?></td>
							</tr>
						</table>
      				  </td>
					</tr>
				<tr><td align="center" colspan="8">&nbsp;</td></tr>
				</table>
					</td></tr>

				<tr>
						<td colspan="7" align="center">
<?php
	if(isNotNull($check))
	{
?>
								<input type="button" name="btnSettleAffRegistrations" value="<?php echo SETTLE_PEND_REG_TEXT;?>" class='button' onClick="window.location.href='settleaffregistrations.php?aid=<?php echo $aid;?>';" >
<?php
	}
?>
							&nbsp;&nbsp;
							<input type="button" name="btnBack" class="button" value="<?php echo BACK;?>" onClick="window.location.href='editaffiliate.php?affiliateid=<?php echo $aid;?>';" >
						</td>
				</tr>

							</table>
						</td>
					</tr>
				</table>
			
			</div>
						
						
				<!--content area end-->
								
				</div>
				
				</form>
				
					<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";
?>																						