<?php

/**
* @version 2.6.4
* @package Joomla 1.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
*/

session_start();

ob_start();

define( '_JEXEC', 1 );

$_SESSION['old_path'] = getcwd();

chdir('../../');

define('JPATH_BASE', getcwd() );

define( 'DS', DIRECTORY_SEPARATOR );

require_once("configuration.php");

require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );

require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

$mainframe =& JFactory::getApplication('site');

// set the language

$database = &JFactory::getDBO();
$_REQUEST['custom'] = $_REQUEST['shopping-cart_merchant-private-data'];
$data = explode('|',$_REQUEST['custom']);

			foreach($data as $key=>$value){

				if(substr($value,0,7)=='session'){

					$arr = explode("=",$value);

					$paypal_session_id = $arr[1];

					break;

				}

			}

			 $sql  = "select * from #__dtregister_session where id=$paypal_session_id";

			 $database->setQuery($sql);

			 $database->query();
             echo $database->getQuery();
			 $row = $database->loadObjectList();
       $session_data = $data ;
			 $data = unserialize($row[0]->data);
       $dt_userId = $row[0]->user_id ;
			
			 $_SESSION = $data;
			
			   if(isset($_SESSION['__default']['registry']->_registry['application']['data']->lang) && $_SESSION['__default']['registry']->_registry['application']['data']->lang !=""){
			     $lang_code =  $_SESSION['__default']['registry']->_registry['application']['data']->lang ;
				   $query = "select * from #__languages where code='".$lang_code."' and active=1" ;
				   $database->setQuery($query);
           $database->query();
			     $row = $database->loadObject();
				   $_REQUEST['lang'] = $row->shortcode ;
			   }
			
			 $lang =& JFactory::getLanguage();
ob_start();
$mainframe->initialise();
JPluginHelper::importPlugin('system');

$mainframe->triggerEvent('onAfterInitialise');
$mainframe->route();
$mainframe->triggerEvent('onAfterRoute');
$mainframe->triggerEvent('onAfterDispatch');
$lang->load('com_dtregister');

include(JPATH_SITE."/components/com_dtregister/dtregister.php");
ob_clean();
 
$xml_response = isset($HTTP_RAW_POST_DATA)?
                    $HTTP_RAW_POST_DATA:file_get_contents("php://input");
if (get_magic_quotes_gpc()) {
  $xml_response = stripslashes($xml_response);
}
//require_once( JPATH_SITE.'/components/com_dtregister/lib/payment/gcheckout/gc_xmlparser.php');
 
 /* 
        $xml_parser = new gc_xmlparser($request);
        $this->root = $this->xml_parser->GetRoot();
        $this->data = $this->xml_parser->GetData();*/
var_dump(htmlentities($xml_response));
$paypal_session_id = session_restore();

if($_REQUEST['_type']=='new-order-notification' && !$dt_userId){
  
  $_SESSION['register']['transaction_id'] = $_REQUEST['google-order-number'] ;
  
  $_SESSION['register']['payment_type'] = 'GoogleCheckout' ;
   if($session_data[0]=='registeration'){
    $userId = saveInfo('GoogleCheckout',1);
	  echo $sql = "update #__dtregister_session set user_id='".$userId."' where id=".$paypal_session_id;
	  $database->setQuery($sql);
	  $database->query();

   }elseif($session_data[0]=='duepay'){
      
	  saveduepayment('GoogleCheckout',1);
   }else if($session_data[0]=='change' || $session_data[0]=='cancel'){
      saveuser('GoogleCheckout',1);
   }
              
}
echo $msg = ob_get_clean();

if(isset($_SESSION['old_path']))
chdir($_SESSION['old_path']);

?>