<?PHP
include "../inc/connect.php";

// Start Form Handler

// set payment method to inactive
if (isset($act)) 
	{
	mysql_query("update payment_process set status='1' where pid='".addslashes(trim($id))."'");
	}

// set payment method to active
if (isset($unact)) 
	{
	mysql_query("update payment_process set status='0' where pid='".addslashes(trim($id))."'");
	}

// set payment attributes
if (isset($submit)) 
	{
	// special for plug n pay only
	if (isset($plug))
		{
		@sort ($card_allowed);
		@reset ($card_allowed);
		$ct=1;
		while (@list($key,$value)=@each($card_allowed))
			{
			$ca=@count($card_allowed);
			@$cards_allowed.=$card_allowed[$key].(($ca==$ct)?"":",");
			$ct++;
			}
		}

	@mysql_query("update payment_process set paypal_address='".addslashes(trim($paypal_address))."', checkout_sid='".addslashes(trim($checkout_sid))."', paysystems_companyid='".addslashes(trim($paysystems_companyid))."', plugnpay_subject='".addslashes(trim($plugnpay_subject))."', plugnpay_publisheremail='".addslashes(trim($plugnpay_publisheremail))."', plugnpay_publishername='".addslashes(trim($plugnpay_publishername))."', plugnpay_cardallowed='".addslashes(trim($cards_allowed))."', bymail_to='".addslashes(trim($bymail_to))."', bymail_address1='".addslashes(trim($bymail_address1))."', bymail_address2='".addslashes(trim($bymail_address2))."', bymail_city='".addslashes(trim($bymail_city))."', bymail_state='".addslashes(trim($bymail_state))."', bymail_zip='".addslashes(trim($bymail_zip))."' where pid='".addslashes(trim($id))."'");
	}

// End Form Handler

// Do we have an id yet?
// if not, start with the first ABC sorted record in the payment_process table
if (!isset($id))
	{
	$ct_first_record=mysql_fetch_row(mysql_query("select pid from payment_process order by name asc limit 0, 1"));
	$id=$ct_first_record[0];
	}

echo("
<!--- Start Header --->
	<table width='100%' cellpadding='2' cellspacing='0' border='0'>
		<tr>
			<td align='left' valign='top'><a href='".$http_admin."/index.php'><img border='0' src='".$http_images."/menu_arrow_back.gif'></a>Manage Payment Processors</td>
			<td align='right' valign='top'><font size='1'>Today is ".date("l F d Y").", the current time is: ".date("h:i:s a")."</font></td>
		</tr>
		<tr>
			<td colspan='2' align='left' valign='top'><hr></td>
		</tr>
		<tr>
			<td align='left' valign='top'><img border='0' src='".$http_images."/space.gif' width='190' height='1'></td>
			<td align='left' valign='top'><img border='0' src='".$http_images."/space.gif' width='403' height='1'></td>
		</tr>
	</table>
<!--- End Header --->

<!--- Start Main Process --->
	<table width='100%' cellpadding='2' cellspacing='0' border='0'>
		<tr>
			<td width='50%' align='left' valign='top'>

<!--- Start Process Menu --->
	<table width='100%' cellpadding='2' cellspacing='0' border='0'>
		<tr>
			<td align='left' valign='top'><b>Current Payment Processors</b></td>
		</tr>
	</table>
	<table width='100%' cellpadding='2' cellspacing='0' border='0'>
	");
// loop through processors in db
$row0=mysql_query("select pid, name, status from payment_process order by name asc");
while ($rs0=mysql_fetch_row($row0))
	{
	echo("
		<tr>
			<td width='40%' align='left' valign='top'><a href='".$http_admin."/payment_process.php?id=".$rs0[0]."".((trim($rs0[2])=="0")?"&ny=5":"")."'><img border='0' src='".$http_images."/".(($id==$rs0[0])?"menu_arrow.gif'":"space.gif' width='15' height='9'").">".stripslashes($rs0[1])."</a></td>
			<td width='60%' align='left' valign='top'>".((trim($rs0[2])=="0")?"[<a href='".$http_admin."/payment_process.php?id=".$rs0[0]."&act=5'>activate</a>]":"[<a href='".$http_admin."/payment_process.php?id=".$rs0[0]."&unact=5'>de-activate</a>]")."</td>
		</tr>
		");
	}
echo("
		<tr>
			<td width='40%' align='left' valign='top'><img border='0' src='".$http_images."/space.gif' width='195' height='1'></td>
			<td width='60%' align='left' valign='top'><img border='0' src='".$http_images."/space.gif' width='95' height='1'></td>
		</tr>
	</table>
<!--- End Process Menu --->

			</td>
			<td width='50%' align='left' valign='top'>

<!--- Start Process Details --->
	");

$rs1=mysql_fetch_row(mysql_query("select name, paypal_address, checkout_sid, paysystems_companyid, plugnpay_subject, plugnpay_publisheremail, plugnpay_publishername, plugnpay_cardallowed, bymail_to, bymail_address1, bymail_address2, bymail_city, bymail_state, bymail_zip from payment_process where pid='".addslashes(trim($id))."'"));
echo("
	<form action='".$PHP_SELF."' method='POST'>
	<input type='hidden' name='id' value='".trim($id)."'>
	<table width='100%' cellpadding='2' cellspacing='0' border='0'>
		<tr>
			<td><b>".stripslashes($rs1[0])." Configuration</b></td>
		</tr>
		<tr>
			<td><img src='".$http_images."/space.gif' width='345' height='1'></td>
		</tr>
	</table>
	");

// build pay - mod details
if (ereg("2checkout", strtolower(trim($rs1[0])))==true)
	{
	// 2Checkout
	if (isset($ny))
		{
		echo("
			<table width='100%' cellpadding='2' cellspacing='0' border='0'>
				<tr>
					<td>Please activate this payment gateway first.</td>
				</tr>
				<tr>
					<td><img src='".$http_images."/space.gif' width='345' height='1'></td>
				</tr>
			</table>
			");
		}
	else
		{
		echo("
			<table width='100%' cellpadding='2' cellspacing='0' border='0'>
				<tr>
					<td size='25%' align='left' valign='top'>2Checkout SID:</td>
					<td size='75%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='checkout_sid' value='".stripslashes($rs1[2])."'></td>
				</tr>
				<tr>
					<td size='25%' align='left' valign='top'></td>
					<td size='75%' align='left' valign='top'><input ".$button_style." type='submit' name='submit' value='Edit Now &gt'></td>
				</tr>
				<tr>
					<td size='25%' align='left' valign='top'><img src='".$http_images."/space.gif' width='149' height='1'></td>
					<td size='75%' align='left' valign='top'><img src='".$http_images."/space.gif' width='195' height='1'></td>
				</tr>
			</table>
			</form>
			");
		}
	}
if (ereg("paypal", strtolower(trim($rs1[0])))==true)
	{
	// PayPal
	if (isset($ny))
		{
		echo("
			<table width='100%' cellpadding='2' cellspacing='0' border='0'>
				<tr>
					<td>Please activate this payment gateway first.</td>
				</tr>
				<tr>
					<td><img src='".$http_images."/space.gif' width='345' height='1'></td>
				</tr>
			</table>
			");
		}
	else
		{
		echo("
			<table width='100%' cellpadding='2' cellspacing='0' border='0'>
				<tr>
					<td size='25%' align='left' valign='top'>PayPal Address:</td>
					<td size='75%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='paypal_address' value='".stripslashes($rs1[1])."'></td>
				</tr>
				<tr>
					<td size='25%' align='left' valign='top'></td>
					<td size='75%' align='left' valign='top'><input ".$button_style." type='submit' name='submit' value='Edit Now &gt'></td>
				</tr>
				<tr>
					<td size='25%' align='left' valign='top'><img src='".$http_images."/space.gif' width='149' height='1'></td>
					<td size='75%' align='left' valign='top'><img src='".$http_images."/space.gif' width='195' height='1'></td>
				</tr>
			</table>
			</form>
			");
		}
	}
else if (ereg("tpp-pro", strtolower(trim($rs1[0])))==true)
	{
	// TPP-PRO
	if (isset($ny))
		{
		echo("
			<table width='100%' cellpadding='2' cellspacing='0' border='0'>
				<tr>
					<td>Please activate this payment gateway first.</td>
				</tr>
				<tr>
					<td><img src='".$http_images."/space.gif' width='345' height='1'></td>
				</tr>
			</table>
			");
		}
	else
		{
		echo("
			<table width='100%' cellpadding='2' cellspacing='0' border='0'>
				<tr>
					<td size='25%' align='left' valign='top'>TPP-PRO CompanyID:</td>
					<td size='75%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='paysystems_companyid' value='".stripslashes($rs1[3])."'></td>
				</tr>
				<tr>
					<td size='25%' align='left' valign='top'></td>
					<td size='75%' align='left' valign='top'><input ".$button_style." type='submit' name='submit' value='Edit Now &gt'></td>
				</tr>
				<tr>
					<td size='25%' align='left' valign='top'><img src='".$http_images."/space.gif' width='149' height='1'></td>
					<td size='75%' align='left' valign='top'><img src='".$http_images."/space.gif' width='195' height='1'></td>
				</tr>
			</table>
			</form>
			");
		}
	}
else if (ereg("plug n pay", strtolower(trim($rs1[0])))==true)
	{
	// Plug N Pay
	if (isset($ny))
		{
		echo("
			<table width='100%' cellpadding='2' cellspacing='0' border='0'>
				<tr>
					<td>Please activate this payment gateway first.</td>
				</tr>
				<tr>
					<td><img src='".$http_images."/space.gif' width='345' height='1'></td>
				</tr>
			</table>
			");
		}
	else
		{
		echo("
			<input type='hidden' name='plug' value='5'>
			<table width='100%' cellpadding='2' cellspacing='0' border='0'>
				<tr>
					<td size='25%' align='left' valign='top'>Return Email Subject:</td>
					<td size='75%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='plugnpay_subject' value='".stripslashes($rs1[4])."'></td>
				</tr>
				<tr>
					<td size='25%' align='left' valign='top'>Publisher Email:</td>
					<td size='75%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='plugnpay_publisheremail' value='".stripslashes($rs1[5])."'></td>
				</tr>
				<tr>
					<td size='25%' align='left' valign='top'>Publisher Name:</td>
					<td size='75%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='plugnpay_publishername' value='".stripslashes($rs1[6])."'></td>
				</tr>
				<tr>
					<td colspan='2' align='left' valign='top'>Choose all that apply below:</td>
				</tr>
				<tr>
					<td size='25%' align='left' valign='top'><input type='checkbox' name='card_allowed[Visa]' value='Visa'".((ereg("Visa", stripslashes($rs1[7]))==true)?" checked":"")."> Visa</td>
					<td size='75%' align='left' valign='top'><input type='checkbox' name='card_allowed[Mastercard]' value='Mastercard'".((ereg("Mastercard", stripslashes($rs1[7]))==true)?" checked":"")."> Mastercard</td>
				</tr>
				<tr>
					<td size='25%' align='left' valign='top'><input type='checkbox' name='card_allowed[Amex]' value='Amex'".((ereg("Amex", stripslashes($rs1[7]))==true)?" checked":"")."> Amex</td>
					<td size='75%' align='left' valign='top'><input type='checkbox' name='card_allowed[Discover]' value='Discover'".((ereg("Discover", stripslashes($rs1[7]))==true)?" checked":"")."> Discover</td>
				</tr>
				<tr>
					<td size='25%' align='left' valign='top'><input type='checkbox' name='card_allowed[JCB]' value='JCB'".((ereg("JCB", stripslashes($rs1[7]))==true)?" checked":"")."> JCB</td>
					<td size='75%' align='left' valign='top'><input type='checkbox' name='card_allowed[Diners]' value='Diners'".((ereg("Diners", stripslashes($rs1[7]))==true)?" checked":"")."> Diners</td>
				</tr>
				<tr>
					<td size='25%' align='left' valign='top'><input type='checkbox' name='card_allowed[MYAR]' value='MYAR'".((ereg("MYAR", stripslashes($rs1[7]))==true)?" checked":"")."> MYAR</td>
					<td size='75%' align='left' valign='top'></td>
				</tr>
				<tr>
					<td size='25%' align='left' valign='top'></td>
					<td size='75%' align='left' valign='top'><input ".$button_style." type='submit' name='submit' value='Edit Now &gt'></td>
				</tr>
				<tr>
					<td size='25%' align='left' valign='top'><img src='".$http_images."/space.gif' width='149' height='1'></td>
					<td size='75%' align='left' valign='top'><img src='".$http_images."/space.gif' width='195' height='1'></td>
				</tr>
			</table>
			</form>
				");
		}
	}
else if (ereg("tpp-sale", strtolower(trim($rs1[0])))==true)
	{
	// Revcomm
	if (isset($ny))
		{
		echo("
			<table width='100%' cellpadding='2' cellspacing='0' border='0'>
				<tr>
					<td>Please activate this payment gateway first.</td>
				</tr>
				<tr>
					<td><img src='".$http_images."/space.gif' width='345' height='1'></td>
				</tr>
			</table>
			");
		}
	else
		{
		echo("
			<table width='100%' cellpadding='2' cellspacing='0' border='0'>
				<tr>
					<td>This payment gateway is now active.</td>
				</tr>
				<tr>
					<td><img src='".$http_images."/space.gif' width='345' height='1'></td>
				</tr>
			</table>
			");
		}
	}
else if (ereg("mail in", strtolower(trim($rs1[0])))==true)
	{
	// Revcomm
	if (isset($ny))
		{
		echo("
			<table width='100%' cellpadding='2' cellspacing='0' border='0'>
				<tr>
					<td>Please activate this payment gateway first.</td>
				</tr>
				<tr>
					<td><img src='".$http_images."/space.gif' width='345' height='1'></td>
				</tr>
			</table>
			");
		}
	else
		{
		echo("
			<table width='100%' cellpadding='2' cellspacing='0' border='0'>
				<tr>
					<td size='25%' align='left' valign='top'>Mail to:</td>
					<td size='75%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='bymail_to' value='".stripslashes($rs1[8])."'></td>
				</tr>
				<tr>
					<td size='25%' align='left' valign='top'>Mailing Address:</td>
					<td size='75%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='bymail_address1' value='".stripslashes($rs1[9])."'></td>
				</tr>
				<tr>
					<td size='25%' align='left' valign='top'></td>
					<td size='75%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='bymail_address2' value='".stripslashes($rs1[10])."'></td>
				</tr>
				<tr>
					<td size='25%' align='left' valign='top'>City:</td>
					<td size='75%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='bymail_city' value='".stripslashes($rs1[11])."'></td>
				</tr>
				<tr>
					<td size='25%' align='left' valign='top'>State:</td>
					<td size='75%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='bymail_state' value='".stripslashes($rs1[12])."'></td>
				</tr>
				<tr>
					<td size='25%' align='left' valign='top'>Postal Code:</td>
					<td size='75%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='bymail_zip' value='".stripslashes($rs1[13])."'></td>
				</tr>
				<tr>
					<td size='25%' align='left' valign='top'></td>
					<td size='75%' align='left' valign='top'><input ".$button_style." type='submit' name='submit' value='Edit Now &gt'></td>
				</tr>
				<tr>
					<td size='25%' align='left' valign='top'><img src='".$http_images."/space.gif' width='149' height='1'></td>
					<td size='75%' align='left' valign='top'><img src='".$http_images."/space.gif' width='195' height='1'></td>
				</tr>
			</table>
			</form>
			");
		}
	}
echo("
<!--- End Process Details --->

			</td>
		</tr>
	</table>
	");
// End Main Process
mysql_close($dblink);
?>