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

}

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

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

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

     $sql  = "SELECT ap.*,a.affiliate_name,ao.billing_first_name,ao.billing_last_name
           FROM ".$tableprefix."affiliate_payments ap
	 INNER JOIN  ".$tableprefix."affiliates a 
	         ON ap.affiliate_id = a.affiliate_id  INNER  JOIN ".$tableprefix."orders ao ON ao.order_id = ap.order_id " . $qryopt . "
		  AND ap.affiliate_id = '".addslashes($affiliateid)."'
	   order by ap.date_marked_for_payment 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";
	
?>
<link rel="stylesheet" href="<?php echo SITE_URL; ?>/style/jquery-ui.css">
<script src="<?php echo SITE_URL; ?>/js/jquery-ui.js"></script>

<script language="JavaScript" type="text/JavaScript">
   
$(document).ready(function () {
        $("#datepicker").datepicker({
                dateFormat: 'mm/dd/yy',
                maxDate: '0'
       
         });
      
    $("#cmbSearchType").on("change",function(){
        if(this.value=='datepaid'){
             $("#textSelector").hide();
             $("#dateSelector").show();
             $("#txtSearch").attr("disabled","disabled");
             $("#datepicker").removeAttr("disabled");
            
        }else{
             $("#textSelector").show();
             $("#dateSelector").hide();
             $("#datepicker").attr("disabled","disabled");
             $("#txtSearch").removeAttr("disabled");
             
        }
        
        
    });
});
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>
		
		<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_PAYMENTS;?></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">
                                                    
                                                         <?php
                                                         $dateblock = "none";
                                                         if($cmbSearchType!='datepaid'){
                                                                    $txtBlock = "display";
                                                                    $dateblock = "none";
                                                                    $txtSearch1 = $txtSearch; 
                                                                     $disabled1   = "";
                                                                     $disabled2   = "disabled=disabled";
                                                           } else{
                                                                    $txtBlock = "none";
                                                                    $dateblock = "display";
                                                                    $txtSearch2 = $txtSearch; 
                                                                    $disabled1   = "disabled=disabled";
                                                                    $disabled2   = "";
                                                          }
                                                           
                                                           ?>
							<tr>
								<td width="90%" align=left valign="top" class='toplinksCopy'><?php echo TEXT_SEARCH;?> ::
									<select name="cmbSearchType"  id="cmbSearchType" class="textarea">
										<option value="orderid"  <?php if($cmbSearchType == "orderid" || $cmbSearchType == ""){ echo("selected"); } ?>><?php echo TEXT_ORDER;?> #</option>
										<option value="datepaid"  <?php if($cmbSearchType == "datepaid"){ echo("selected"); } ?>><?php echo TEXT_DATE_PAID;?><?php //echo TEXT_MM_DD_YY;?></option>
									</select> &nbsp;
                                                                       <span id="textSelector" style="display:<?php echo $txtBlock; ?>"  >
                                        <input type="text" <?php echo $disabled1; ?> name="txtSearch" id="txtSearch" size="20" maxlength="50" value="<?php echo(htmlentities($txtSearch1)); ?>"  onKeyPress="if(window.event.keyCode == '13'){ return false; }"  class="textarea">
                                   </span>
                                    <span id="dateSelector" style="display:<?php echo $dateblock; ?>" >
                                        <input type="text" <?php echo $disabled2; ?> name="txtSearch" id="datepicker" size="20" maxlength="50" value="<?php echo(htmlentities($txtSearch2)); ?>"   class="textarea">
                                    </span>
									
								<a href="javascript:clickSearch();" class="go_button_2"><?php echo GO_BUTTON; ?></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 align="left"><?php echo TEXT_USER_NAME;?> <!-- Buyers Name --></th>
						<th align="left"><?php echo TEXT_AMT_PAID;?></th>
						<td class=boxalternatecolor2><?php echo TEXT_ORDER;?> #</td>
						<!--<td>Order Total</td>
						<td>Commission (%)</td> -->
						<th width="3%">&nbsp;</th>
						<th colspan="3" align="center"><?php echo TEXT_DATE_PAID;?><?php echo TEXT_MM_DD_YY;?></th>
						<th width="11%">&nbsp;</th>
					</tr>
<?php
if(mysql_num_rows($result) > 0 )
{
	$i = 1;
	$total = 0;
	while($row = mysql_fetch_array($rs)){
	if($row["affiliate_id"]==$affiliateid)
	{
	
		$link = "<a class='links' href='viewpayment.php?paymentid=".$row["affiliate_payment_id"]."'>";
		$txtPaymentDate = (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") : "");
?>
					<tr class="whitebg">
						<td><?php if($row["billing_first_name"]){echo stripslashes(ucwords($row["billing_first_name"]))." ".stripslashes(ucwords($row["billing_last_name"]));}else{echo "Not available";}?></td>
						<td><?php /* echo $link .htmlentities(substr($row["affiliate_name"],0,40 ))."</a>"; */ ?>
                          <?php echo $adminCurrency['currency_symbol']."&nbsp;".$link .htmlentities(number_format($row["amount_paid"],2,".",''))."</a>";?></td>
						<td align='center' class=boxalternatecolor2><?php echo $link .htmlentities($row["order_id"])."</a>";?></td>
						<!--<td align="right"><?php echo $link .htmlentities($row["total_amount"])."</a>";?></td>
						<td align="right"><?php echo $link .htmlentities($row["commission_percentage"])."</a>";?></td> -->
						<td align="center">&nbsp;</td>
						<td align="center" colspan="3" ><?php echo $link .$txtPaymentDate."</a>";?></td>
						<td align="center">&nbsp;</td>
					</tr>
<?php
	$i++;
	$total+= $row["amount_paid"];
	}
	}
	if($total>0)
	{?>
						<tr class="whitebg">
						  <td width="27%" colspan="1" align="right">&nbsp;</td>
						  <td width="20%" align="right" class="boxalternatecolor">&nbsp;</td>
						  <td colspan="5"></td>
					  </tr>
						<tr class="whitebg"><td align="right" colspan="1">&nbsp;</td><td align="left" class="boxalternatecolor"><b>Total</b>&nbsp;<font color="RED"><b><?php echo number_format($total,2,".",''); ?></b></font></td>
						<td colspan="5"></td>
						</tr>
	<?php 
	}
}
else
{
										
?>					
							<tr>
									<td align="center" valign="middle" colspan="7"  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'>".TEXT_PAGES_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="8">
												<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 TEXT_PAGES; ?> <?php echo $page ?>/<?php echo $numofpages?>&nbsp;&nbsp;<?php echo TEXT_GOTO; ?>
														</td>
														<td width="8%" align="right">
															<select name="gotoPage" class="textarea2" 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"><?php echo GO_BUTTON; ?></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";
?>