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


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

if($_POST["btnSaveChanges"] == "Save Changes"){
	if(isNotNull($txtPaymentDate)){
		$txtPaymentDate = dateFormat($txtPaymentDate,"m/d/Y" ,"Y-m-d" );
	}
	$sql ="UPDATE  ".$tableprefix."artist_payments SET 
		payment_method = '".addslashes($txtPaymentMethod)."',
		comments= '".addslashes($txtComments)."',
		payment_date = '".addslashes($txtPaymentDate)."'
		WHERE 	artist_payment_id = '".addslashes($paymentid)."'
		";
	//$res = mysql_query($sql);
	//echo "<br>".$sql;
	$message = "Changes saved successfully!";
}
$sql=" SELECT o.*, u.user_name, u.email, sum(od.product_price * od.product_quantity) as total FROM ".$tableprefix."orders o 
		INNER JOIN ".$tableprefix."users u ON o.user_id = u.user_id 
		INNER JOIN ".$tableprefix."order_details od ON o.order_id = od.order_id 
		WHERE od.item_status = '2' AND od.order_id = '".addslashes($orderid)."'
		" . $qryopt . " GROUP BY od.order_id ORDER BY o.order_date DESC   ";

$result = mysql_query($sql);
if(mysql_num_rows($result) != 0){
	$row = mysql_fetch_array($result);
	$txtArtistName = $row["artist_name"];
	$txtOrderNumber = $row["order_id"];
	$txtOrderTotal = $row["total_amount"];
	$txtTotalPaid = $row["amount_paid"];
	$txtArtistCommission = $row["commission_percentage"]; 
	$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("Are you sure you want to delete this record?") ){
		return true;
	}
	return false;
}
</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 name="frmPaymentDetails" action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST">
																									<input type="hidden" name="paymentid" value="<?php echo htmlentities($paymentid);?>">
																										<table cellpadding="2" cellspacing="2" width="70%">
																											<tr><td colspan="3" align="center">Payment Details</tr>
																											<tr><td colspan="3"></tr>
																											<tr><td colspan="3" class="message" align="left"><?php echo $message;?></tr>
																											<tr><td colspan="3"></tr>
																											<tr><td align="left" >Artist Name&nbsp;</td><td >&nbsp;</td><td ><?php echo htmlentities($txtArtistName);?></td></tr>
																											<tr><td align="left" >Order Number &nbsp;</td><td >&nbsp;</td><td ><?php echo htmlentities($txtOrderNumber);?></td></tr>
																											<tr><td align="left" >Order Total&nbsp;</td><td >&nbsp;</td><td ><?php echo htmlentities($txtOrderTotal);?></td></tr>
																											<tr><td align="left" >Artist Commission(%)&nbsp;</td><td >&nbsp;</td><td ><?php echo htmlentities($txtArtistCommission);?></td></tr>
																											<tr><td align="left" >Total Paid to Artist&nbsp;</td><td >&nbsp;</td><td ><?php echo htmlentities($txtTotalPaid);?></td></tr>
																											<tr><td align="left" >Date Marked for Payment&nbsp;</td><td >&nbsp;</td><td ><?php echo htmlentities($txtPaymentMarkedDate);?></td></tr>
																											<tr>
																												<td align="left" >Date of Actual Payment&nbsp;</td>
																												<td >&nbsp;</td>
																												<td >
																													<input type="text" name="txtPaymentDate" size="30" id="txtPaymentDate" class="textbox" readonly value="<?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 ><input type="text" value="<?php echo htmlentities($txtPaymentMethod);?>" name="txtPaymentMethod" size="30" maxlength="100"></td></tr>
																											<tr><td align="left" valign="top">Comments&nbsp;</td><td >&nbsp;</td><td ><TEXTAREA name="txtComments" rows="8" cols="45"><?php echo htmlentities($txtComments);?></TEXTAREA></td></tr>
																											<tr><td colspan="3"></tr>
																											<tr><td colspan="3" align="center"><input type="submit" value="Save Changes" name="btnSaveChanges">&nbsp;&nbsp;<input type="button" class="button" value="Back" name="btnBack" onClick="window.location.href='payments.php'" ></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>




