<?php
/*
 * ipn_error.php
 *
 * PHP Toolkit for PayPal v0.51
 * http://www.paypal.com/pdn
 *
 * Copyright (c) 2004 PayPal Inc
 *
 * Released under Common Public License 1.0
 * http://opensource.org/licenses/cpl.php
 *
 */

// this is an include file - no functionality when
// called directly
chdir('../../');
include("includes/myconnect.php");
require("includes/currencies.php");
$currencies = new currencies();

include_once('paypal_standard/includes/global_config.inc.php'); 
create_csv_file("uploadedimages/ipn_error.txt",$_REQUEST);
if (isset($_REQUEST['invoice']) && is_numeric($_REQUEST['invoice']) && ($_REQUEST['invoice'] > 0)) {
$orderID = $_REQUEST['invoice'];
$userid = $_REQUEST["custom"];

$invoiceID = str_pad($orderID, 4, "0", STR_PAD_LEFT);
$order_status_id = 5;

$order_query = mysql_query("select orders_id from dmc_orders where orders_id = $orderID and customers_id = $userid limit 1");
$order_total = mysql_num_rows($order_query);
if ($order_total > 0) {
	$comment = $_REQUEST["payment_status"];
	if ($_REQUEST["payment_status"]=="Pending"){
	$comment .= "; " . $_REQUEST['pending_reason'];
	} elseif (($_REQUEST['payment_status'] == 'Reversed') || ($_REQUEST['payment_status'] == 'Refunded')) {
	$comment .= "; " . $_REQUEST['reason_code'];
	}
	
	$update =  mysql_query("Update dmc_orders set orders_status=$order_status_id, last_modified = 'now()' where orders_id=$orderID") or die(mysql_error());

	$sql5="INSERT INTO dmc_orders_status_history (orders_id, orders_status_id, date_added, customer_notified, comments) values ('$orderID', '$order_status_id', now(), '0','PayPal IPN Invalid [$comment]')";
	$myquery5 = mysql_query($sql5) or die(mysql_error());

}
}
else
{
	die('This page is not directly accessible');
}


?>