<?php 
/*
##################################################################
#                       PHP 4&5 MySQL 4&5                        #
##################################################################
#           Copyright (c) 2004-2008 Armia Systems Inc            #
##################################################################
#               This file is part of Cybermatch site             #
##################################################################
#    Developed By: simi (simi@armia.com)                         #

##################################################################
#               Developed On:   03-23-2009                       #
##################################################################
#               Modified By:                                     #
##################################################################
#               Modified On:                                     #
##################################################################
# 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.                                         #
##################################################################
*/

require_once ("config.inc.php");
require_once ("includes/mysql.inc.php");
require_once ("includes/arrays.inc.php");
require_once ("classes/settings.class.php");
require_once ("classes/userside.class.php");
require_once ("classes/misc.class.php");

if (!isset($_SESSION['register_id']) OR $_SESSION['register_id'] == "") {
	header("Location: register.php");
	exit();
}

$arrSettings	= array();
$script		= "";
$message	= "";

if (!$objDB) 
{
	$message	= "Unable to Locate Database Server.";
}//end if
else 
{
	$objS			= new settings($objDB);
	$objU			= new userside($objDB);
        $objM		= new misc($objDB);
	$objS->set_variables();
}//end else
$checktypemode=($_GET['stype']!='')?$_GET['stype']:$_POST['stype'];
if($checktypemode!='')
{
	$_SESSION['sess_register_stype']=$checktypemode;
}//end if
else
{
	$checktypemode=$_SESSION['sess_register_stype'];
}//end else
include_once ("title.inc.php");
include_once ("tophtml.inc.php");

require_once('gc/library/googlecart.php');
require_once('gc/library/googleitem.php');
require_once('gc/library/googleshipping.php');
require_once('gc/library/googletax.php');
require_once('gc/library/googleresponse.php');
require_once('gc/library/googlemerchantcalculations.php');
require_once('gc/library/googleresult.php');

$_SESSION['txtGoogleId']=$siteSettings["googleid"];
$_SESSION['txtGoogleKey']=$siteSettings["googlekey"];
$_SESSION['chkGoogleSandbox']=$siteSettings["enablegooglesandbox"];
$_SESSION['sess_gc_amount']=$objS->membership_amount;
$_SESSION['sess_site_name']=$siteSettings["sitename"];
$_SESSION['sess_site_secure_url']=$siteSettings["site_secure_url"];
$_SESSION['register_id']=$_SESSION['register_id'];

$gc_status=($_GET['gc_status']!='')?$_GET['gc_status']:'failure';

function UseCase1() 
{
	$google_id		= $_SESSION['txtGoogleId']; // Merchant ID
	$google_key		= $_SESSION['txtGoogleKey']; // Merchant Key
	$google_demo	= $_SESSION['chkGoogleSandbox']; // "YES" if in test mode, "NO" if in live mode
	$cost			= $_SESSION['sess_gc_amount']; // price
	$currency 		= 'USD';
	$_SESSION['register_id']=$_SESSION['register_id'];

	$amount=$_SESSION['sess_gc_amount'];

	if ($google_demo == "YES")
		$server_type	= "sandbox";
	else
		$server_type	= "checkout";

	// Create a new shopping cart object
	$cart = new GoogleCart($google_id, $google_key, $server_type, $currency);

	// Add items to the cart
	$item_1 = new GoogleItem($_SESSION['sess_site_name'], // Item name
						 'Registration Process', // Item description
						 1, // Quantity
						 $cost); // Unit price

	$cart->AddItem($item_1);

	// continue link page
	$cart->SetContinueShoppingUrl($_SESSION['sess_site_secure_url']."/google_register.php?paytype=gc&uid=".$_SESSION['register_id']."&gc_status=success");

	$cart->AddRoundingPolicy("HALF_UP", "PER_LINE");

	$cart->SetMerchantPrivateData('googleregister-'.$_SESSION['register_id']);

	// Display Google Checkout button
	echo $cart->CheckoutButtonCode("LARGE");
}//end google usecase


	//calculation starts here
	if(isset($gc_status) && $gc_status=='success')
	{
   		$gc_flag = true;
    	$gc_err = "";
		if ($google_demo == "YES")
    		$gc_tran = "TEST-".time();
		else
			$gc_tran = time();

		$_SESSION['register_id']=$_GET['uid'];
		$_SESSION['sess_TransId']=$gc_tran;
    
    	if ($gc_flag==true) 
		{
        	// Start of the transaction  for adding a user since payment is successfull
        	$txnid = $gc_tran;
       		// ////////////////////////////////////////////////////////////////////////////////////
        	// check if txnid alredy there to prevent refresh
        	//$sql="select * from ".TABLEPREFIX."payments where vTxn_Id='".addslashes($txnid)."' and vMethod='GC'";
                $sql="select * from ".TABLEPREFIX."payments where vReason='Profile Registration' and vMethod='GC' AND nUser_Id='".$_SESSION['register_id']."'";

       	    $result = mysql_query($sql) or die(mysql_error());
        	if(mysql_num_rows($result)==0)
			{
				$_SESSION['sess_Paymode']='GC';
				
            	$message	= $objU->register_authorize($_SESSION['register_id']);

				if ($message == "") 
				{
					$_SESSION['txtGoogleId']='';
					$_SESSION['txtGoogleKey']='';
					$_SESSION['chkGoogleSandbox']='';
					$_SESSION['sess_site_name']='';
					$_SESSION['register_id']='';
					$_SESSION['sess_site_secure_url']='';
					$_SESSION['sess_TransId']='';

					header("Location:register_success.php");
					exit();
				}//end if
            }//end if
			else if(mysql_num_rows($result)>0)
			{
                $gc_flag = true;
                header("Location:register_success.php");
					exit();
				$gc_err="Transaction Error .Please contact <a href='mailto:".$config['adminMail']."'>".$config['adminMail']."</a>";
            }//end else
        }//end if
		else 
		{
            $gc_flag = false;
			$gc_err='Payment process not completed successfully.';
        }//end else
    }//end if
?>
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td valign="top" ><table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="72%" valign="top"><div class="search-rslts"><table width="100%"  border="0" cellspacing="0" cellpadding="5">
          <tr>
            <td>              <table width="100%"  border="0" cellspacing="0" cellpadding="5">
              <tr>
                   <td width="100%" class="inenr-hd"><h2>Pay Now</h2></td>
                
              </tr>
            </table>
<table width="100%"  border="0" cellspacing="0" cellpadding="10">
                <tr>
                  <td><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td class="headings2">Click below to complete the purchase of your <?php echo $objS->ValidityDayMembership ?> day(s) subscription</td>
                    </tr>
                  </table>
                    <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td><img src="images/spacer.gif" width="1" height="10"></td>
                      </tr>
                    </table>
                    <table width="100%"  border="0" cellspacing="0" cellpadding="5">
					<?php if(isset($message) && trim($message)!='')
					      {
					?>
                    <tr align="center">
                      <td colspan="3" class="maintext1 warning"><?php echo $message;?></td>
                      </tr>
					<?php }//end if?>
					<?php if($gc_flag == false && $gc_err!='')
					      {
					?>
                    <tr align="center">
                      <td colspan="3" class="maintext1 warning"><?php echo $gc_err;?></td>
                      </tr>
					<?php }//end if?>
                    <tr>
                      <td width="54%" class="maintext1">Amount Pay</td>
                      <td width="46%" colspan="2" class="maintext1">$ <?php echo $objS->membership_amount?></td>
                    </tr>
                    <tr align="center">
                      <td colspan="3" class="maintext1"><?php 
if(isset($gc_status) && $gc_status!='success')
{
?>	
                     While using Google CheckOut as payment option, you have to wait for the approval from Administrator of the site for further steps even after successful payment. <br>
		<br>
		<b>Waiting for the secure payment interface ....</b><br>
		<br><br>
		<?php UseCase1(); ?>
<?php
}//end else
?></td>
                      </tr>
                  </table>
                    </td>
                </tr>
              </table>
              <div id="hide"><?php echo $script?></div>
			</td>
          </tr>
        </table></div></td>
        <td width="28%" valign="top"><?php //include_once ("left.inc.php");?></td>
      </tr>
    </table> 
      </td>
  </tr>
</table>
<?php include_once('bottomhtml.inc.php');?>
