<?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(isset($_SESSION['membership']))
{
	$totaltopay=$_SESSION['membership']['plan_SubscriptionCharge'];
}else
{
header("Location:seller_plan_upgrade.php?sellerid=".$_SESSION["sess_artistid"]);
exit();
}

$currency_attributes=displayCurrencyType();

if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
	$_SESSION = array_map('stripslashes_deep', $_SESSION);
}

if(isset( $_SESSION["sess_artistid"]) and $_SESSION["sess_artistid"]!= ""){
	$userid = $_SESSION["sess_artistid"];
}

if(isset($_SESSION['membership']))
{
$totaltopay=$_SESSION['membership']['plan_SubscriptionCharge'];
}else
{
 header("Location:seller_plan_upgrade.php?sellerid=".$_SESSION["sess_artistid"]);
 exit();
}

/*-------function call to check whether cart contains digital or gift coupon products so as to hide shipping---*/

	//	$hide_shipping_division = hideShipping();

/*-------function call to check whether cart contains digital or gift coupon products so as to hide shipping------*/

$sql_artists = "SELECT * FROM ".$tableprefix."artists where artist_id=".$userid." ";
$res_artists = mysql_query($sql_artists );
$row_artists = mysql_fetch_array($res_artists);

$txtCCNumber = $_POST["txtCCNumber"];
$txtCVV2 = $_POST["txtCVV2"];
$txtMM = $_POST["txtMM"];
$txtYY = $_POST["txtYY"];

$txtFirstName = $row_artists["first_name"];
$txtLastName = $row_artists["last_name"] ;
$txtAddress = $row_artists["address1"];
$txtAddress1 =$txtAddress;
$txtCity = $row_artists["city"] ;
$txtState = $row_artists["state"];
$txtZIP = $row_artists["zip"];
$txtEmail= $row_artists["email"];
$ddlCountry = $row_artists["country"];
$txtPhone=$row_artists["phone"];

$currency_attributes = displayCurrencyType();





//$hide_shipping_division = hideShipping();
/*-------function call to check whether cart contains digital or gift coupon products so as to hide shipping------*/
//$check_shipping_enable = checkShippingEnable();




$paymentMethod = "CC";

//getting payment info
$sql = "SELECT * FROM ".$tableprefix."settings ";
$res = mysql_query($sql);
$row = mysql_fetch_array($res);

$txtAuthorizeLoginId = $row["authorize_loginid"];
$txtAuthorizeTransKey = $row["authorize_transkey"];
$txtCurrency = "USD";
$txtAuthorizeEmail = $row["authorize_email"];
$txtAuthorizeTestMode = $row["authorize_test_mode"];
if($txtAuthorizeTestMode == "Y"){
	$txtAuthorizeTestMode = "on";
}else{
	$txtAuthorizeTestMode = "off";
}

$gift_coupon_flag = 0;

$txtEnableAuthorize 	= getSettingsValue('vauthorize_enable');
$txtEnableBluepay       = getSettingsValue('vbluepay_enable');
$txtEnableFirstData	= getSettingsValue('vyourpay_enable');

if (isset($_POST["btnCompleteOrder"]))
 {
	$message = "";

	$paymentsuccessful = false;


	$paymenterror = "";

   if($txtEnableAuthorize == 'Y')
{

	$referrer =  $_SERVER["HTTP_REFERER"];
    $qry1="select max(order_id)+1 as ordid from " . $tableprefix . "orders";
    $excqry1=mysql_query($qry1);
    $row1=mysql_fetch_array($excqry1);
    $Inv_id=$row1['ordid'];
    $Cust_id = $_SESSION["sess_userid"];
    $Cust_ip = getClientIP();
	
    $Company = "-NA-";
    $Phone=$txtPhone;
    if($txtLastName=="")
      $txtLastName="-NA-";
	
	require "../authorize.php";//process the card and return result. Comment this line and uncomment the two lines below to make payment test mode

	//$paymentsuccessful = true;
	// = "TEST1234444";
}
elseif($txtEnableBluepay=='Y') {



		$txtBluepayAccountId = getSettingsValue('bluepay_accountid');

		$txtBluepaySecretKey = getSettingsValue('bluepay_secretkey');

		$mode  = getSettingsValue('bluepay_test_mode');


		$card_expiry    = $txtMM.substr($txtYY,-2);
		include "../includes/Bluepay.php";
		$bp = new Services_Bluepay();
		$bp->setValue("ACCOUNT_ID", $txtBluepayAccountId);
		$bp->setValue("SECRET_KEY", $txtBluepaySecretKey);
		$bp->setValue("TRANS_TYPE", 'SALE');
		$bp->setValue("MODE", $mode);		# Default is TEST --> Set to LIVE for live tx
		$bp->setValue("AMOUNT", $totaltopay);	# ODD returns Approved, EVEN returns Declined in TEST mode
		$bp->setValue("PAYMENT_ACCOUNT", $txtCCNumber);	# Card Number
		$bp->setValue("CARD_EXPIRE", $card_expiry);
		$bp->setValue("NAME1", $txtFirstName);
		$bp->setValue("NAME2", $txtLastName);
		$bp->setValue("PHONE", $txtPhone);
		$bp->setValue("EMAIL", $txtEmail);
		$bp->setValue("COMPANY_NAME", SITE_NAME);
		$tamperProofSeal=md5($txtBluepaySecretKey.$txtBluepayAccountId.$totaltopay.$mode);
		$bp->setValue("TAMPER_PROOF_SEAL", $tamperProofSeal);
		$bp->setValue("ADDR1", $txtAddress1);
		$bp->setValue("CITY", $txtCity);
		$bp->setValue("STATE", $txtState);
		$bp->setValue("ZIP", $txtZIP);
		$bp->setValue("COUNTRY", $ddlCountry);
		$bp->bp20post();
		$transactionid = $bp->getValue("TRANS_ID");
		$paymentsuccessful = false;
		if($transactionid != "" && $bp->getValue("MESSAGE")	== "Approved Sale" && $bp->getValue("STATUS")== "1") {
		$paymentsuccessful = true;
		}
		else {

	 $paymenterror = "Sorry, the transaction cannot be processed";
                  }
        }elseif($txtEnableFirstData=='Y')
		{
			include_once "../includes/firstData.php";


			$mylphp=new firstData;



		if(getSettingsValue('vyourpay_mode')=='TEST')
		{
			//$myorder["host"]       = "208.72.248.102";   //secure.linkpt.net for Live
			$myorder["host"]       = "staging.linkpt.net";

                        $myorder["result"]     = "LIVE";

		}
		else
		{
			$myorder["host"]       = "secure.linkpt.net";   //secure.linkpt.net for Live
			$myorder["result"]     = "LIVE";
		}
			$myorder["port"]       = "1129";

			//##Merchantinfo
			$myorder["keyfile"]    = "pem/".getSettingsValue('vyourpay_certificate_file'); # Change this to the name and location of your certificate file
			$myorder["configfile"] =trim(getSettingsValue('vyourpay_storeid')); # Change this to your store number
			//## Orderoptions

			 $myorder["ordertype"]    = "SALE" ; //The type of transaction. The possible values are SALE,PREAUTH,VOID,POSTAUTH,CREDIT, CALCSHIPPING

			$yearlen=strlen($txtYY);

			if($yearlen>2)
			{
				$CardYear= substr($txtYY,-2);
			}
			# card info
			$myorder["cardnumber"]   = $txtCCNumber ;
			$myorder["cardexpmonth"] = $txtMM;
			$myorder["cardexpyear"]  = $CardYear;
			$myorder["cvmindicator"] = "provided";
			$myorder["cvmvalue"]     =  $txtCVV2;
			//## Payment
			//$myorder["subtotal"]    = $totaltopay;
			//$myorder["tax"]         = number_format($totaltaxrate,2,".","");
			//$myorder["shipping"]    = number_format($shipping_cost,2,".","");
			//$myorder["vattax"]      = "0.00";
			$myorder["chargetotal"] = number_format($totaltopay,2,".","");
			// ## Billing
			$myorder["name"]      = $txtFirstName;
			$myorder["address1"]  = $txtAddress1;
			$myorder["address2"]  = $txtAddress2;
			$myorder["city"]      = $txtCity;
			$myorder["state"]     = $txtState;
			$myorder["country"]   = $ddlCountry;
			$myorder["phone"]     = $txtPhone;
			$myorder["email"]     = $txtEmail;
			$myorder["fax"]    	  = $txtFAX;
			$myorder["addrnum"]   = '';   # Required for AVS. The numeric portion of the street address If not provided, transactions will downgrade.
			$myorder["zip"]       = $txtZIP; # Required for AVS. Billing zip or postal code If not provided, transactions will downgrade.
			//$items = array();
			//$myorder["items"][0] = $items; # put array of items into hash

			$myorder["comments"] = "Seller Registration  Information with  ".SITE_NAME." online store";

			$result = $mylphp->curl_process($myorder);  # use curl methods

			$transactionid		=	$result["r_ordernum"];


			if($transactionid != "" && $result["r_approved"] == "APPROVED") {
				$paymentsuccessful = true;
			}
			if ($result["r_approved"] != "APPROVED")	// transaction failed, print the reason
			{
				if($result["r_error"]=='<')
                                {
                                   $paymenterror = "Unable to process your payment. Try again later.";
                                }
                                  else
                                  {
                                    $paymenterror=$result["r_error"];
                                  }

				$msg_error=$paymenterror;
				$_SESSION['PAYMENT_ERROR']=$result["r_error"];
			}


}
	
if($paymentsuccessful)
{ 
	
	$select_Plan = "SELECT plan_Period
								   FROM ".$tableprefix."sellerPlans
								   WHERE plan_Id = ".trim($_SESSION['membership']['plan_Id']);
	$result_Plan = mysql_query($select_Plan) or die(mysql_error());
	$result_Plan = mysql_fetch_assoc($result_Plan);	
	if($result_Plan['plan_Period']=="M")
	$noOfDays=30;
	if($result_Plan['plan_Period']=="Y")
	$noOfDays=365;
	

$_SESSION['SES_MEMPLAN']=$_SESSION['membership']['plan_Id'];

	if($paypal_check==0)
	{ // check if paypal is success

		$sql = "UPDATE " .$tableprefix. "artists SET sellerPlanID =".$_SESSION['membership']['plan_Id']." , plan_expired='N'  WHERE artist_id =".$_SESSION['sess_artistid'];
		mysql_query($sql);
		$orderid = mysql_insert_id();
		
		$fromDate= date("Y-m-d");
		$endDate= date("Y-m-d",strtotime("+".$noOfDays." day"));
	

		$sql = "INSERT INTO " .$tableprefix. "artists_membershipDetails (artist_id, artist_memStartDate, artist_memEndDate,plan_Id,plan_SubscriptionCharge,transaction_id) VALUES
				(".$_SESSION['sess_artistid'].",'".$fromDate."','".$endDate."',".$_SESSION['membership']['plan_Id'].",".$_SESSION['membership']['plan_SubscriptionCharge'].",'".$transacttion_id."')";
		mysql_query($sql);
		$orderid = mysql_insert_id();
	}		

		
} 

if($paymentsuccessful)
	{ // check if paypal is success
	unset($_SESSION['membership']);
	unset($_SESSION['SESS_pay_amount']);
	unset($_SESSION['SESS_insertQry']);
	$_SESSION['PAY_MESSAGE']="Plan Upgraded Successfully.";
	
	$sellerapproval	=getSettingsValue('approve_sellers');
	
 	}		
	
}

if (isset($_POST["btnCancelOrder"])) {
	$message = "";
	$redirecturl = SITE_URL."/sellers/seller_plan_upgrade.php?sellerid=".$_SESSION["sess_artistid"];
	header("Location:$redirecturl");
	exit;
}




include "../includes/htmltop.php";
?>


		
		<body>
		
		<center>
		
		<div align="left" id="layout">
		
		
				
				
				<!--header area start -->
<?php

	include_once("../includes/topheader_seller.php")

?>
				
				<!--header area end -->
				
				
				
				
				<div align="left" class="main_body">
				<!--main body start -->
				
				
				
<?php
		//include_once("../includes/artisttopmenu.php")
?>		
																					
	<script language="javascript" src="../includes/function.js"></script>
<script language="javascript" >
function validateForm(){
	var frm = window.document.frmPayment;
    if (frm.txtCCNumber.value.length == 0 ) {
		alert('<?php echo MSG_VALID_CREDIT_CARD_NUMBER; ?>');
		return false;
	}else if (frm.txtMM.value.length == 0 || frm.txtYY.value.length == 0 || frm.txtYY.value < 2005 || frm.txtMM.value > 12 ) {
		alert('<?php echo MSG_VALID_CREDIT_CARD_EXPIRY; ?>');
		return false;
	}else{
		return true;
	}
}


function onlyNumeric(){
         if (event.keyCode<48||event.keyCode>57)
         return false;
}

function checkNumber(t) {
        if(t.value.length == 0 ||  isNaN(t.value) || t.value.substr(0,1) == " " || parseInt(t.value) < 0) {
                t.value="";
        }
}

</script>							
					<div align="left" class="content_area">
					
					<!--content area start -->
					<div class="text_information" align="center"><?php echo $paymenterror?></div>
            		<br>
											
					<div align="left">																			
		<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="post" name="frmPayment" >
		<input type="hidden" name="userid" value="<?php echo $userid ?>">
        <input type="hidden" name="totaltopay" value="<?php echo $totaltopay?>">
        <input type="hidden" name="paymentMethod" value="<?php echo $paymentMethod?>">
					
			<input type="hidden" name="userid" value="<?php echo htmlentities($userid);?>">
		<fieldset>
		<table width="100%" border="0" cellspacing="2" cellpadding="2" class="manage_table">
<?php

if(!$paymentsuccessful)
{

?>
		
		<tr>
		  <td height="40" colspan="3"><h2><strong><?php echo TEXT_PAYMNT_DTLS; ?></strong></h2></td>
		  </tr>
		<tr>
			<td><?php echo LABEL_TOTAL_TO_PAY; ?></td>
			<td colspan="2">
<?php
  echo $adminCurrency['currency_symbol']." ".number_format($totaltopay,2,".","");
?></td>
		 </tr>
<?php	
  
	$check_shipping_enable = checkShippingEnable();
	if($check_shipping_enable == "Y" && $hide_shipping_division == 1)
	{
		 
		$shipping_cost = $_SESSION['SESS_upscost'];
				
				
?>		

		
				<td><?php echo LABEL_GRAND_TOTAL; ?></td>
			<td align="left" colspan="2"><input type="hidden" name="cart_total" value="1000">
	<?php 				
						 echo $currency_attributes[0];
   						 echo "&nbsp;";
						$grandtotal=$display_total ;
						echo number_format($grandtotal,2,".","");
		}
		else
		{
																																					
	?> 
	
		<input type="hidden" name="cart_total" value="<?php echo $display_total;?>">
	
	<?php
	
		}
	
	?>
	
		  
		  <tr>
			<td width="25%"><?php echo LABEL_CARD_NUMBER; ?></td>
			<td width="28%" align="left"><input type=text name="txtCCNumber" maxlength=16 class=textbox value="<?php echo $txtCCNumber?>" size="30"></td>
		  </tr>
		  <tr>
			<td><?php echo LABEL_CARD_VALIDATION_CODE; ?></td>
			<td><input type="text" name="txtCVV2" maxlength="10" class="textbox" value="<?php echo $txtCVV2?>" size="15">&nbsp;
			</td>
			<td width="47%"></td>
		  </tr>
		  <tr>
			<td><?php echo LABEL_EXPIRATION_DATE; ?></td>
			<td colspan="2">
			<select name="txtMM" onBlur="javascript:checkNumber(this);" tabindex="3">
			<?php 
			for($i=1;$i<13;$i++)
			{
			if($i<10)
			$val = "0".$i;
			else
			$val = $i;
			?>
			<option value="<?php echo $val;?>" <?php if($val==$txtMM || $i==$txtMM) echo "selected";?>><?php echo $val;?></option>
			<?php
			}
			?>
			</select>
			<select name="txtYY" id="txtYY" onBlur="javascript:checkNumber(this);" tabindex="4">
			<?php 
			for($j=date("Y");$j<(date("Y")+35);$j++)
			{
j
			?>
			<option value="<?php echo $j;?>" <?php if($j==$txtYY) echo "selected";?>><?php echo $j;?></option>
			<?php
			}
			?>
			</select>
			
			</td>
		  </tr>

		  <tr>
			<td colspan="3">&nbsp;</td>
		  </tr>
		  
		  <tr>
			 <td colspan="3" align="center">
				   <input type="submit"  name="btnCancelOrder" value="<?php echo BTN_CANCEL_SUBSCRIPTION; ?>" class="button" onclick="">
				  <input type="submit"  name="btnCompleteOrder" value="<?php echo BTN_COMPLETE_SUBSCRIPTION; ?>" class="button" onclick="return validateForm();">&nbsp;&nbsp;

			</td>
		  </tr>
		<?php
		 }
		 else
		 {
		 
			if($check_shipping_enable == "Y")
			{
                                                    if(function_exists('session_unregister')){
                                                    session_unregister('SESS_upstype');

                                                    session_unregister('SESS_upscost');

                                                    session_unregister('SESS_upsweight');
                                                }else{
                                                                    unset($_SESSION['SESS_upstype']);
                                                                    unset($_SESSION['SHIPPING_TOTAL']);
                                                                    unset($_SESSION['SESS_upsweight']);
                                                      }
			}	
		 ?>

		<tr>
			<td colspan="3" align="center" class="text_information">
				<?php echo MSG_PAYMENT_COMPLETED; ?> <br><br>
			
					<?php echo $_SESSION['PAY_MESSAGE'];?>
			</td>
		</tr>
		<tr>
			<td colspan="3">&nbsp;</td>
		</tr>
		<tr>
			<td colspan="3" align="center">
				<input type='button' value='<?php echo BTN_HOME; ?>'  class='button' onClick="window.location.href='<?php echo SITE_URL?>/sellers/artistmain.php'">
&nbsp;&nbsp;			</td>
		</tr>

<?php


 }
 
?>
   		</table>
		</fieldset></form>
				
				</div>
										
				<!--content area end-->
								
				</div>
				
								

					<div align="left" class="clear_float"><img src="<?php echo $imagefolder;?>/clear.gif" alt="" width="1" height="1" /></div>
				<!--main body end -->
				</div>
				
				
<?php
	include "../includes/footer.php";
?>