<?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["paymentid"]) and $_GET["paymentid"]!= ""){
	$paymentid = $_GET["paymentid"];
}else if(isset( $_POST["paymentid"]) and $_POST["paymentid"]!= ""){
	$paymentid = $_POST["paymentid"];
}else{
	header("Location:affpayments.php");
	exit;
}

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


$txtPaymentMethod = $_POST["txtPaymentMethod"];
$txtComments = $_POST["txtComments"];
$txtPaymentDate = $_POST["txtPaymentDate"];

if(isset($_POST["btnSaveChanges"])){
	if(isNotNull($txtPaymentDate)){
		$txtPaymentDate = dateFormat($txtPaymentDate,"m/d/Y" ,"Y-m-d" );
	}
	$sql ="UPDATE  ".$tableprefix."affiliate_payments SET 
		payment_method = '".addslashes($txtPaymentMethod)."',
		comments= '".addslashes($txtComments)."',
		payment_date = '".addslashes($txtPaymentDate)."'
		WHERE 	affiliate_payment_id = '".addslashes($paymentid)."'
		";
	$res = mysql_query($sql);
	//echo "<br>".$sql;
	$message = CHANGES_SAVED_SUCCESSFULLY;
}


$sql = "SELECT ap.*, a.affiliate_name FROM ".$tableprefix."affiliate_payments ap INNER JOIN  ".$tableprefix."affiliates a ON ap.affiliate_id = a.affiliate_id  WHERE affiliate_payment_id = '".addslashes($paymentid)."' ";
$result = mysql_query($sql);
if(mysql_num_rows($result) != 0){
	$row = mysql_fetch_array($result);
	$txtAffiliateName = $row["affiliate_name"];
	$txtTotalPaid = $row["amount_paid"];
	$txtPaymentMarkedDate = (isNotNull($row["date_marked_for_payment"]) ? dateFormat($row["date_marked_for_payment"],"Y-m-d","m/d/Y") : "");
	$txtPaymentDate = (isNotNull($row["payment_date"] and ($row["payment_date"]!= "0000-00-00")) ? dateFormat($row["payment_date"],"Y-m-d","m/d/Y") : "");
	$txtComments = $row["comments"];
	$txtPaymentMethod = $row["payment_method"];
}
include "../includes/htmltop.php";
?>
<link href="../style/calendar-win2k-cold-1.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../includes/calendar.js"></script>
<script type="text/javascript" src="../includes/calendar-setup.js"></script>
<script type="text/javascript" src="../includes/calendar-en.js"></script>
<SCRIPT>
function confirmDelete(){
	if(confirm("<?php echo ARE_YOU_SURE_DELETE_RECORD; ?>") ){
		return true;
	}
	return false;
}
</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"><?php //include("../includes/subtab.php");?></div-->

							
					<div align="left" class="page_title">Affiliate Payment Details (#<?php echo $paymentid;?>)</div>
					<div align="center" class="text_information grey_tr"><?php echo $message?></div>
                    <br>
											
					<form name="frmPaymentDetails" action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST">
					<input type="hidden" name="paymentid" value="<?php echo htmlentities($paymentid);?>">
					<input type="hidden" name="aid" value="<?php echo htmlentities($aid);?>">
					<div align="left">
						
					<table width="100%" border="0" cellpadding="2" cellspacing="2" class="manage_top">
					
					<tr><td align="left" >Affiliate Name&nbsp;</td><td >&nbsp;</td><td align="left"><?php echo htmlentities($txtAffiliateName);?></td></tr>
					<tr><td align="left" >Total Paid/Payable&nbsp;</td><td >&nbsp;</td><td align="left"><?php echo htmlentities($txtTotalPaid);?></td></tr>
					<tr><td align="left" >Date Marked for Payment&nbsp;</td><td >&nbsp;</td><td align="left"><?php echo htmlentities($txtPaymentMarkedDate);?></td></tr>
					<tr>
						<td align="left" >Date of Actual Payment&nbsp;</td>
						<td >&nbsp;</td>
						<td align="left">
							<input type="text" name="txtPaymentDate" size="30" id="txtPaymentDate" class="textbox" readonly value="<?php echo $txtPaymentDate?>">
							<input type="button" value="V" id="button1" name="button1"  class="button" style=" width:20px;height:18px">
								<script type="text/javascript">
									 Calendar.setup({
									 inputField            : "txtPaymentDate",
									 button               : "button1",
									 ifFormat              : "%m/%d/%Y",       // format of the input field
									 showsTime             : true,
									 timeFormat             : "24"
									 });
								</script>
						</td>
					</tr>
					<tr><td align="left" >Payment Method&nbsp;</td><td >&nbsp;</td><td align="left"><input type="text" value="<?php echo htmlentities($txtPaymentMethod);?>"  class="textbox" name="txtPaymentMethod" size="30" maxlength="100"></td></tr>
					<tr><td align="left" valign="top">Comments&nbsp;</td><td >&nbsp;</td><td align="left"><TEXTAREA name="txtComments" rows="8" cols="45" class="textbox"><?php echo htmlentities($txtComments);?></TEXTAREA></td></tr>
					<tr><td colspan="3"></tr>
					<tr><td colspan="3" align="center"><input type="submit" value="<?php echo BTN_SAVE_CHANGES; ?>" name="btnSaveChanges" class="button">&nbsp;&nbsp;<input type="button" class="button" value="<?php echo BACK; ?>" name="btnBack" onClick="window.location.href='affpayments.php?aid=<?php echo $aid;?>'" ></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";
?>																																					