<?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($_GET["msg"]) and $_GET["msg"]!=""){
	$msg = $_GET["msg"];
	switch($msg){
		case "deleted": $message = "Feedback deleted successfully!";break;
		default:
			;
	} // switch
	
}

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

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

$qryopt="";
if($txtSearch != ""){
   if($cmbSearchType == "datepaid"){
   		$dt = $txtSearch;
		$arrdt = explode("/",$dt) ;
		$day = $arrdt[1];
		$month = $arrdt[0];
		$year = $arrdt[2];
		$dt = $year."-". $month ."-".$day;
		$qryopt .= "  AND  ap.payment_date like '" . addslashes($dt) . "%'";
   }
}

$sql=" SELECT ap.*,a.affiliate_name FROM ".$tableprefix."affiliate_payments ap 
		INNER JOIN  ".$tableprefix."affiliates a ON ap.affiliate_id = a.affiliate_id  WHERE ap.affiliate_id = '".addslashes($aid)."'  " . $qryopt . "  order by ap.payment_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.frmAffPayments.submit();
}
function changeStatus(id){
	var frm = document.frmAffPayments;
	if(Confirm("<?php echo CONFIRM_CHANGE_STATUS;?>")){
		document.frmAffPayments.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_PAYMENTS;?></div>
					<div align="center" class="text_information grey_tr"><?php echo $message?></div>
                    <br>
											
					

					<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="post" name="frmAffPayments">
						<input type="hidden" name="aid" value="<?php echo $aid;?>">
						
						<div align="left">
						
					<table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_top">
					
		  				</table>
				
					</div>
					
					<div align="left">
					
					<table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
					  <tr>
						<th width="13%" align="center" valign="middle"><?php echo AFFILIATE_NAME;?></th>
						<th width="21%" align="left" valign="middle"><?php echo AMOUNT_PAID_PAYABLE;?></th>
						<th width="22%" align="left" valign="middle"><?php echo DATE_MARKED_TEXT;?></th>
						<th colspan="6" align="left" valign="middle"><?php echo DATE_PAID_TEXT;?></th>
					  </tr>
					
<?php
if(mysql_num_rows($result) > 0 )
{
	while($row = mysql_fetch_array($rs))
	{
		$link = "<a class='links' href='affpaymentdetails.php?paymentid=".$row["affiliate_payment_id"]."&aid=".$aid."'>";
		$txtPaymentDate = (isNotNull($row["payment_date"] and ($row["payment_date"]!= "0000-00-00")) ? dateFormat($row["payment_date"],"Y-m-d","m/d/Y") : "");
		$txtPaymentMarkedDate = (isNotNull($row["date_marked_for_payment"] and ($row["date_marked_for_payment"]!= "0000-00-00")) ? dateFormat($row["date_marked_for_payment"],"Y-m-d","m/d/Y") : "");
		
		if($txtPaymentDate=='')
		{
			$txtPaymentDate= PAYMENT_NOT_YET_SETTLED;
		}	
?>
							
				<tr>
					<td align='left'><?php echo $link .htmlentities(substr($row["affiliate_name"],0,40 ))."</a>";?></td>
					<td align='left'><?php echo $link .htmlentities($row["amount_paid"])."</a>";?></td>
					<td align='left'><?php echo $link .htmlentities($txtPaymentMarkedDate)."</a>";?></td>
					<td align='left' colspan="5"><?php echo $link .$txtPaymentDate."</a>";?></td>
					
				</tr>
																														
																														
																														
																														
<?php
		$i++;
		
		}
	}
	else
	{
										
?>										
					<tr>
						<td align="center" valign="middle" colspan="8" 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'>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>";
					
				}	
?>				
				<tr>
					<td colspan="9" 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.frmAffPayments.submit();" class="go_button_2">Go</a>
								</td>
								<td width="41%" align="center"><?php echo $next?></td>
							</tr>
						</table>
					  </td>
					</tr>
						<tr>
							<td colspan="8" align="center"><input type="button" class="button" name="back" value="<?php echo BACK;?>" onClick="Javascript:history.go(-1)"></td>
						</tr>
						</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";
?>																						



