 <?php

/**
* @version 2.8.18
* @package Joomla 2.5
* @subpackage DT Register
* @copyright Copyright (C) 2006 DTH Development
* @copyright contact dthdev@dthdevelopment.com
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*/

$_REQUEST['option'] = 'com_dtregister';
ob_start();
define( '_JEXEC', 1 );
global $oldpath;
$oldpath = getcwd();
chdir('../../');
define('JPATH_BASE', getcwd() );
define( 'DS', DIRECTORY_SEPARATOR );

function myErrorHandler($errno, $errstr, $errfile, $errline) {
	$log = false;
    switch ($errno) {
        case E_NOTICE:
        case E_USER_NOTICE:
            $errors = "Notice";
            break;
        case E_WARNING:
        case E_USER_WARNING:
            $errors = "Warning";
            break;
        case E_ERROR:
        case E_USER_ERROR:
            $errors = "Fatal Error";
			$log = true;
            break;
        default:
		    $log = true;
            $errors = "Unknown";
            break;
        }

      $debug = sprintf ("<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br /><br />\n", $errors, $errstr, $errfile, $errline);
   
      $debug .= sprintf("PHP %s:  %s in %s on line %d", $errors, $errstr, $errfile, $errline);
		//$debug = ob_get_clean();
	  $path = JPATH_BASE."/components/com_dtregister/lib/payment/ipnlog.html";
	  //if($log)
	  //file_put_contents($path,$debug,FILE_APPEND);
     
    return true;
}

// set to the user defined error handler

if (file_exists(JPATH_BASE . '/defines.php')) {
	include_once JPATH_BASE . '/defines.php';
}

if (!defined('_JDEFINES')) {
	define('JPATH_BASE', dirname(__FILE__));
	require_once JPATH_BASE.'/includes/defines.php';
}

require_once JPATH_BASE.'/includes/framework.php';

$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
JPluginHelper::importPlugin('system');
$lang =& JFactory::getLanguage();
$lang->load('com_dtregister');
JRequest::setVar('controller','payment');

 $mailtxt = var_export($_REQUEST,true);

if(isset($_REQUEST['rvar_return'])) {
  $_REQUEST['return'] = $_REQUEST['rvar_return'];
}
if(!isset($_REQUEST['task'])){
   $_REQUEST['task'] = 'restore';
}
set_error_handler("myErrorHandler");

  
//mail('lucky@dthdevelopment.com','IPN PAYWAY',$mailtxt);
   if($_REQUEST['task']=="notify" || isset($_REQUEST['cd_summary'])){ // cd_summary in payway notify 
   $_REQUEST['task'] = "notification";
   }
   if(!isset($_REQUEST['x_cust_id']) && $_REQUEST['task']=="cancel")  {
	  $baseurl = str_replace('components/com_dtregister/','',Juri::base()); 
	  
	  
	   $mainframe->redirect($baseurl.'index.php?option=com_dtregister&task=cancel&controller=payment&Itemid='.$Itemid);
    
	}
$mainframe->dispatch('com_dtregister');
if($_REQUEST['task']=="cancel"){
	 $baseurl = str_replace('components/com_dtregister/','',Juri::base()); 
	  
	  
	   $mainframe->redirect($baseurl.'index.php?option=com_dtregister&task=cancel&controller=payment&Itemid='.$Itemid);
}
die;
//chdir($oldpath);

die();
?>