<?PHP
$query_c="select ";
$query_c.="coupon_terms, ";				// 0
$query_c.="coupon_discount_type, ";		// 1
$query_c.="coupon_discount_percent, ";	// 2
$query_c.="coupon_discount_whole, ";	// 3
$query_c.="aid ";						// 4
$query_c.="from ";
$query_c.="addon_specs ";
$query_c.="where ";
$query_c.="coupon_code='".addslashes(trim($coupon_code))."'";

$rs_c=mysql_fetch_row(mysql_query($query_c));

$coupon_terms=stripslashes(trim($rs_c[0])); # 1 == one time; 2 == monthly;
$coupon_discount_type=stripslashes(trim($rs_c[1])); # 1 == %; 2 == whole dollar amount;
$coupon_discount_percent=stripslashes(trim($rs_c[2]));
$coupon_discount_whole=stripslashes(trim($rs_c[3]));
$aid=stripslashes(trim($rs_c[4]));

$ct_=substr_count($group_addons, "|");
$ex=explode("|", $group_addons);
for($i=0; $i<=$ct_; $i++) { if ($aid===$ex[$i]) { $group_test=true; } }

if (isset($group_test))
	{
	# 1. figure out one time or monthly
	if ($coupon_terms==1&&strcmp("2checkout", strtolower($payment_type_name))!=0) # one time
		{
		if ($coupon_discount_type==1) # %
			{
			# - %
			$sub_total_due_today=($total_due_today-$total_reoccur);
			$convert_to_percent=($coupon_discount_percent/100);
			$discounted_total_due_today=$total_reoccur-($total_reoccur*$convert_to_percent);
			$new_total_due_today=$sub_total_due_today+$discounted_total_due_today;
			if ($discounted_total_due_today+$setup_cost<=0) { $invalid=true; } # added 7/23/2003 rockwell to fix bug (+$setup_cost) 
			else { $total_due_today=$new_total_due_today; $used_coupon="<font color='#990000'>* ".$text_reflectsonetimediscount." ".$coupon_discount_percent."% ".$text_offhostingfees.".</font>";}
			}
		else if ($coupon_discount_type==2) # whole dollar amount
			{
			# - WHOLE DOLLAR
			$sub_total_due_today=($total_due_today-$total_reoccur);
			$discounted_total_due_today=$total_reoccur-$coupon_discount_whole;
			$new_total_due_today=$sub_total_due_today+$discounted_total_due_today;
			if ($discounted_total_due_today+$setup_cost<=0) { $invalid=true; } # added 7/23/2003 rockwell to fix bug (+$setup_cost)
			else { $total_due_today=$new_total_due_today; $used_coupon="<font color='#990000'>* ".$text_reflectsonetimediscount." ".($currency.sprintf("%01.2f", $coupon_discount_whole).$currency_type).".$text_offhostingfees.</font>";}
			}
		}
	else if ($coupon_terms==2&&strcmp("2checkout", strtolower($payment_type_name))!=0) # monthly
		{
		if ($coupon_discount_type==1) # %
			{
			# - %
			# do today's totals
			$sub_total_due_today=($total_due_today-$total_reoccur);
			$convert_to_percent=($coupon_discount_percent/100);
			$discounted_total_due_today=$total_reoccur-($total_reoccur*$convert_to_percent);
			$new_total_due_today=$sub_total_due_today+$discounted_total_due_today;
			if ($discounted_total_due_today+$setup_cost<=0) { $invalid=true; } # added 7/23/2003 rockwell to fix bug (+$setup_cost)
			else 
				{ 
				$total_due_today=$new_total_due_today; 
				$total_reoccur=$discounted_total_due_today;
				$used_coupon="<font color='#990000'>* ".$text_reflectsdiscount." ".$coupon_discount_percent."% ".$text_offhostingfees.".</font>"; 
				$xused_coupon="<font color='#990000'>* ".$text_reflectsdiscount." ".$coupon_discount_percent."%.</font>"; 
				}
			}
		else if ($coupon_discount_type==2) # whole dollar amount
			{ 
			# - WHOLE DOLLAR 
			$sub_total_due_today=($total_due_today-$total_reoccur);
			$discounted_total_due_today=$total_reoccur-$coupon_discount_whole;
			$new_total_due_today=$sub_total_due_today+$discounted_total_due_today;
			if ($discounted_total_due_today+$setup_cost<=0) { $invalid=true; } # added 7/23/2003 rockwell to fix bug (+$setup_cost)
			else 
				{ 
				$total_due_today=$new_total_due_today; 
				$total_reoccur=$discounted_total_due_today;
				$used_coupon="<font color='#990000'>* ".$text_reflectsdiscount." ".($currency.sprintf("%01.2f", $coupon_discount_whole).$currency_type)." ".$text_offhostingfees.".</font>";
				$xused_coupon="<font color='#990000'>* ".$text_reflectsdiscount." ".($currency.sprintf("%01.2f", $coupon_discount_whole).$currency_type).".</font>";
				}
			}
		}
	}
# --------------------------------------------------------------------------------------------------------------
if (strcmp("mail in payment", strtolower($payment_type_name))==0)
	{
	echo"<input type='hidden' name='total_due_today' value='".base64_encode(trim($total_due_today))."'>\n";
	echo"<input type='hidden' name='total_due_reoccur' value='".base64_encode(trim($total_reoccur))."'>\n";
	}
else if (strcmp("paypal", strtolower($payment_type_name))==0)
	{
	if ($free_trial==1)
		{
		echo"<input type='hidden' name='a1' value='0'>\n";
		echo"<input type='hidden' name='p1' value='".$free_trial_length."'>\n";
		echo"<input type='hidden' name='t1' value='M'>\n";
		
		echo"<input type='hidden' name='a2' value='".sprintf("%01.2f", $total_due_today)."'>\n";
		echo"<input type='hidden' name='p2' value='".trim($term)."'>\n";
		echo"<input type='hidden' name='t2' value='M'>\n";
		}
	else
		{
		echo"<input type='hidden' name='a1' value='".sprintf("%01.2f", $total_due_today)."'>\n";
		echo"<input type='hidden' name='p1' value='".trim($term)."'>\n";
		echo"<input type='hidden' name='t1' value='M'>\n";
		}

	echo"<input type='hidden' name='a3' value='".sprintf("%01.2f", $total_reoccur)."'>\n";
	}
else if (strcmp("paysystems tpp-pro", strtolower($payment_type_name))==0)
	{
	echo"<input type='hidden' name='total' value='".sprintf("%01.2f",($total_due_today))."'>\n";
	echo"<input type='hidden' name='repeatamount' value='".sprintf("%01.2f", $total_reoccur)."'>\n";
	}
else if (strcmp("worldpay future pay", strtolower($payment_type_name))==0)
	{	
	echo"<input type='hidden' name='amount' value='".sprintf("%01.2f",($total_due_today))."'>\n";
	echo"<input type='hidden' name='normalAmount' value='".sprintf("%01.2f", $total_reoccur)."'>\n";
	}
# --------------------------------------------------------------------------------------------------------------

// update totals in session history to save query later
$query1="update ";
$query1.="session_history ";
$query1.="set ";
$query1.="total_due_today='".addslashes(trim($total_due_today))."', ";
$query1.="total_due_reoccur='".addslashes(trim($total_reoccur))."', ";
$query1.="locked='1' ";
$query1.="where sid='".addslashes(trim($sid))."'";

mysql_query($query1);

# start new ----------------------------------------------------------------------------------------------------
if (strcmp("mail in payment", strtolower($payment_type_name))==0) { $parse_out2="<img src='".$http_images."/mailin.gif'>"; }
if (strcmp("paypal", strtolower($payment_type_name))==0) { $parse_out2="<img src='".$http_images."/paypal.gif'>"; }
if (strcmp("paysystems tpp-pro", strtolower($payment_type_name))==0) { $parse_out2="<img src='".$http_images."/paysystems.gif'>"; }
if (strcmp("2checkout", strtolower($payment_type_name))==0) { $parse_out2="<img src='".$http_images."/2checkout.gif'>"; }
if (strcmp("worldpay future pay", strtolower($payment_type_name))==0) { $parse_out2="<img src='".$http_images."/worldpay.gif'>"; }
if (strcmp("authorize.net", strtolower($payment_type_name))==0) { $parse_out2="<img src='".$http_images."/authorize.gif'>"; }
?>