<?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($_GET["aid"]) and $_GET["aid"] != "") {
    $aid = $_GET["aid"];
} else if (isset($_POST["aid"]) and $_POST["aid"] != "") {
    $aid = $_POST["aid"];
} 

if($begin == ""){
        $begin=0;
        $num=1;
        $numBegin=1;
}

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"];
}


$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)."'  AND  ar.affiliate_payment_id IS NULL " . $qryopt . "
		order by ar.registration_date DESC   ";
//echo $sql;
$sess_back= $_SERVER["PHP_SELF"] . "?begin=" . $begin . "&num=" . $num . "&numBegin=" . $numBegin . "&cmbSearchType=" . $cmbSearchType . "&txtSearch=" . $txtSearch;
$_SESSION["gbackurl"] = $sess_back;

$totalrows = mysql_num_rows(mysql_query($sql));

$navigate = pageBrowser($totalrows,10,10,"&cmbSearchType=$cmbSearchType&txtSearch=$txtSearch",$_GET[numBegin],$_GET[start],$_GET[begin],$_GET[num]);
$sql = $sql.$navigate[0];
$rs = mysql_query($sql);

include "../includes/htmltop.php";
?>
<script language="JavaScript" type="text/JavaScript">
function clickSearch()
{
	document.frmFeedbacks.submit();
}
function changeStatus(id){
	var frm = document.frmFeedbacks;
	if(Confirm("Are you sure you want to change the status of this record?")){
		document.frmFeedbacks.submit();
	}
}
</script>

<body>
<table width="804" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr>
		<td align="center" bgcolor="#C15628">
			<table width="802" border="0" align="center" cellpadding="0" cellspacing="0">
				<tr>
					<td bgcolor="#000000">
						<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
            				<tr>
              					<td>
									<table width="100%"  border="0" cellspacing="0" cellpadding="0" class="maintext">
                  						<tr>
                    						<td>
												<?php include "../includes/topheader_admin.php";?>
												<table width="100%"  border="0" cellspacing="0" cellpadding="0">
													<tr>
														<td valign="top" bgcolor="#FFFFFF">
															<?php 
																include "../includes/admintopmenu.php"; 
																include "../includes/dotline.php";
																//include "includes/centermain.php"; 
															?>
																<table width="100%"  border="0" cellspacing="0" cellpadding="0">
																<tr>
																	<td style="width:1px" class="siteborder"><img src="../images/spacer.gif"></td>
																	<td width="98%">
																		<table width="100%"  border="0" cellspacing="0" cellpadding="0">
																			<tr>
																				<td align="center" valign="top">
																					<p>&nbsp;</p>
																						                                   
																						<table width="100%">
																							<tr>
																								<td>
																									<!-- ***************************************************** -->
																									<form action="<?php echo $_SERVER["PHP_SELF"];?>" method="post" name="frmFeedbacks">
																										<input type="hidden" name="aid" value="<?php echo  htmlentities($aid)?>" >
																										<table width="98%"  border="0" cellpadding="0" cellspacing="0" class=listingborder align="center">
																											<tr>
																												<td class=listingtdbgcolor>
																													<table width="100%"  border="0" cellpadding="2" cellspacing="1" class="maintext">
																														<tr align="center" bgcolor="#FFFFFF"><td align="center" colspan="7" class="infomessage"><?php echo $message?></td></tr>
																														<tr bgcolor="#FFFFFF" valign="top">
																															<td align="right" colspan="7" valign="top" >
																																<table width="100%" border=0  >
																																	<tr>
                                                                                                                                                                                                                                                                            <td width="100%" align=right valign="baseline" class="" >Search ::&nbsp;
																																			<select name="cmbSearchType" class="selectbox">
																																				<option value="username"  <?php if($cmbSearchType == "username" ){ echo("selected"); } ?> ><?php echo USER_NAME;?></option>
																																				<option value="useremail"  <?php if($cmbSearchType == "useremail"){ echo("selected"); } ?> ><?php echo USER_EMAIL;?></option>
																																				<option value="datereg"  <?php if($cmbSearchType == "datereg"){ echo("selected"); } ?>><?php echo DATE_REGISTERED;?></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="textbox">
																																			&nbsp;
																																			<a href="javascript:clickSearch();" class="search_button"><?php echo BTN_SEARCH; ?></a>&nbsp;
																																		</td>
																																	</tr>
																																</table>
																															
																															</td>
																														</tr>
																														<tr bgcolor="#FFFFFF"><td align="left" colspan="7"><?php echo("Listing $navigate[1] of $totalrows results."); ?></td></tr>
																														<tr class=listingband>
																															<td>#</td>
																															<td><?php echo AFFILIATE;?></td>
																															<td><?php echo USER_NAME;?></td>
																															<td><?php echo USER_EMAIL;?></td>
																															<td><?php echo DATE_REGISTERED;;?></td>
																															<td><?php echo REFERRAL_CHARGE;?> ($)</td>
																															<td><?php echo PAID;?>?</td>
																														</tr>
																														<?php
																														$i=$begin+1;
																														$total = 0;
																														while($row = mysql_fetch_array($rs)){
																															$link = "<a href='affiliateregdetails.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"]!=""? "Y":"N";
																															if($txtPaid=="N"){
																																$check = "<input type='checkbox' name='chkreg[]' value='" . $row["registration_id"] . "' > ";
																															}else{
																																$check = "&nbsp;";
																															}
																															
																														?>
																														<tr bgcolor="#FFFFFF"> 
																															<td><?php echo $check;?></td>
																															<td><?php echo $link .htmlentities($row["affiliate_name"])."</a>";?></td>
																															<td><?php echo $link .htmlentities($row["user_name"])."</a>";?></td>
																															<td><?php echo $link .htmlentities($row["user_email"])."</a>";?></td>
																															<td><?php echo $link .htmlentities($txtRegistrationDate)."</a>";?></td>
																															<td><?php echo $link .htmlentities($row["referral_charge"])."</a>";?></td>
																															<td><?php echo $link .htmlentities($txtPaid)."</a>";?></td>
																														</tr>
																														<?php
																														$i++;
																														$total+= $row["referral_charge"];
																														}
																														?>
																														<tr bgcolor="#FFFFFF"><td align="right" colspan="5"><b>Total</b>&nbsp;</td><td align="left" colspan="2"><font color="RED"><b><?php echo $total; ?></b></font></td></tr>
																														<tr bgcolor="#FFFFFF"><td align="center" colspan="7"><?php echo($navigate[2]); ?></td></tr>
																														<tr bgcolor="#FFFFFF"><td align="center" colspan="7">&nbsp;</td></tr>
																														<tr class=listingband>
																															<td colspan="7">&nbsp;</td>
																														</tr>
																														
																														<tr bgcolor="#FFFFFF">
																																<td colspan="7" align="center">
																																	<?php 
																																	if(isNotNull($check)){ ?>
																																		<input type="submit" class="button" name="btnSettleSelected" value="Settle Selected" >
																																	<?php
																																	}
																																	?>
																																	&nbsp;&nbsp;
																																	<input type="button" name="btnBack" class="button" value="Back" onClick="window.location.href='editaffiliate.php?affiliateid=<?php echo $aid;?>';" >
																																</td>
																														</tr>
																														
																													</table>
																												</td>
																											</tr>
																										</table>
																									</form>
																									
																									
																									
																									
																									
																									
																									
																									<!-- ***************************************************** -->
																								</td>
																							</tr>
																						</table>
																					
                             														
																				</td>
                                											</tr>
                           												</table>
                             										</td>
                              										<td style="width:1px" class="siteborder"><img src="../images/spacer.gif"></td>
                                  								</tr>
                     										</table>	
															<?php
																include "../includes/dotline.php";
																include "../includes/adminbottommenu.php";
																include "../includes/bottomband.php";
															?>
														</td>
                          							</tr>
                      							</table>
											</td>
                  						</tr>
									</table>
								</td>
 							</tr>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<?php
include "../includes/footer.php";
?>
</body>
</html>



