#!/usr/bin/perl

open(TP,"/home/bbboy/public_html/bb/top.html");
@TP = <TP>;
close(TP);

open(BT,"/home/bbboy/public_html/bb/bottom.html");
@BT = <BT>;
close(BT);

$top = "Content-type:text/html\n\n";
foreach (@TP) {
$top .= $_;
}

foreach (@BT) {
$bott .= $_;
}
use CGI qw(:standard);

$query = new CGI;

if ($ENV{REMOTE_ADDR}=~/62.30.112/) {
	print "$top\nPlease go away.$bott";
	exit;
}

if (!cookie("username")) {
	print qq~$top <p>You aren't registered! You must register a username, and log in, before being able to create a board.<br><br>
<ul><li><a href="http://bb.bbboy.net/register.cgi"><b>Click here</b></a> to register a username.
<li><a href="javascript:;" onClick="var bo = window.open('http://bb.bbboy.net/support-login','login','width=310,height=185,resizable=1,scrollbars=no,menubar=no,status=no');"><b>Click here</b></a> to Log In.
</ul>
$bott~;
exit;
}

$usern = cookie("username");

if (!$query->param("plan")) {
print $top;
print qq~<p>You must choose a plan before attempting to sign up. Please go to the <a href="signup.shtml">signup page</a>.~;
print $bott;
}
elsif ($query->param("plan") eq "free") {
	print $top;
	print qq~Creating A Board On The 30-day Free Trial
<p>
<b>Step Three</b><br>
<ul><li>You have now chosen a pricing plan - the 30-day Free Trial and read and agreed to the terms and conditions. If you haven't, please <a href="signup.shtml">return to the signup page</a>. The last step is to enter your board's details.
</ul>
<p>
<style>
select,input {font-family:verdana; font-size:12px;}
</style>
Please fill in the details for the board you wish to own.
<br><Br><form action=create.cgi method=post>
<input type=hidden name=plan value=free1>
<input type=hidden name=username value="$usern"> You are logged in as <b>$usern</b> ( <a href="javascript:;" onClick="var bo = window.open('http://bb.bbboy.net/support-logout','logout','width=310,height=185,resizable=1,scrollbars=no,menubar=no,status=no');">Log Out?</a> )<br><br>
Choose a name for your board <font size=-2>(This will be part of your URL - http://frost.bbboy.net/<b>boardname</b>)</font> :<br>
<input type=text name=boardname> <br><br>
Choose a category:<br>
			<select name=cat>
			<option value="Arts">Arts<option value="Arts / Computer Art">Arts / Computer Art<option value="Arts / Animation">Arts / Animation<option value="Arts / Anime">Arts / Anime<option value="Arts / Comics/Cartoons">Arts / Comics/Cartoons<option value="Arts / Other">Arts / Other<option value="Business">Business<option value="Business / Home Based Businesses">Business / Home Based Businesses<option value="Business / Internet Businesses">Business / Internet Businesses<option value="Business / Other">Business / Other<option value="Computers & Internet">Computers & Internet<option value="Computers & Internet / Computer Help">Computers & Internet / Computer Help<option value="Computers & Internet / Web Design">Computers & Internet / Web Design<option value="Computers & Internet / Software Help">Computers & Internet / Software Help<option value="Computers & Internet /  Programing">Computers & Internet /  Programing<option value="Computers & Internet / Other">Computers & Internet / Other<option value="Debate">Debate<option value="Debate / Global Issues">Debate / Global Issues<option value="Debate / Political">Debate / Political<option value="Debate / Morality">Debate / Morality<option value="Debate / Other">Debate / Other<option value="Education">Education<option value="Education / Homework Help">Education / Homework Help<option value="Education / Public Awareness">Education / Public Awareness<option value="Education / Other">Education / Other<option value="Entertainment">Entertainment<option value="Entertainment / Literature & Writing">Entertainment / Literature & Writing<option value="Entertainment / Movies">Entertainment / Movies<option value="Entertainment / Television">Entertainment / Television<option value="Entertainment / Music">Entertainment / Music<option value="Entertainment / Other">Entertainment / Other<option value="Gaming">Gaming<option value="Gaming / Internet & Computer Gaming">Gaming / Internet & Computer Gaming<option value="Gaming / Board Games">Gaming / Board Games<option value="Gaming / Card Games">Gaming / Card Games<option value="Gaming / Role Playing Games">Gaming / Role Playing Games<option value="Gaming / Other">Gaming / Other<option value="Society and People">Society and People<option value="Society and People / Health">Society and People / Health<option value="Society and People / Parenting and Pregnancy">Society and People / Parenting and Pregnancy<option value="Society and People / Disability Support">Society and People / Disability Support<option value="Society and People / Religion & Faith">Society and People / Religion & Faith<option value="Society & People / Other">Society & People / Other<option value="Just for Fun">Just for Fun<option value="Just for Fun / Humor">Just for Fun / Humor<option value="Just for Fun / Cooking">Just for Fun / Cooking<option value="Just for Fun / Triva">Just for Fun / Triva<option value="Just for Fun / Other">Just for Fun / Other<option value="Sports & Travel">Sports & Travel<option value="Sports & Travel / Baseball">Sports & Travel / Baseball<option value="Sports & Travel / Basketball">Sports & Travel / Basketball<option value="Sports & Travel / Football">Sports & Travel / Football<option value="Sports & Travel / Hockey">Sports & Travel / Hockey<option value="Sports & Travel / Soccer">Sports & Travel / Soccer<option value="Sports & Travel / Stock Car Racing">Sports & Travel / Stock Car Racing<option value="Sports & Travel / Tennis">Sports & Travel / Tennis<option value="Sports & Travel / Wrestling">Sports & Travel / Wrestling<option value="Sports & Travel / Other">Sports & Travel / Other<option value="Misc">Misc</select> 
<br><Br><input type="submit" value="Create!">
<br><br><b>Stop!</b> Are you sure you don't want to sign up for our <b><a href="http://bb.bbboy.net/signup.shtml">Paid Services</a></b>? There's more features, no annoying banners or popups, and for only \$2.50/month! No? You can always upgrade later.</b>
</form>
We will not send you spam or "special offers" as some would call it. You will be notified by PM (not e-mail) when a new version of BbBoard is released, outlining the new features, and how to use them, for your convenience.
~;
	print $bott;
}
elsif ($query->param('plan') eq "free1") {
	my $bif = $query->param('boardname');
	$bif = lc $bif;
	$bif=~s/(\W| |-|_)//g;
	use LWP::Simple;
	if (-d "/boards/$bif" || get("http://azure.bbboy.net/${bif}-exists") || get("http://denim.bbboy.net/${bif}-exists") || get("http://emerald.bbboy.net/${bif}-exists")) {
		print qq~$top Sorry, The board name <b>$bif</b> has already been taken. Please press your back button and choose a different name. If you really want that name, you may be able to add some numbers onto the end, for example ${bif}84.$bott~;
		exit;
	}
	open(NW,">>/boards/all/newboards.cgi");
	print NW $query->param('username')."::::".$query->param('email')."::::".$query->param('boardname')."::::".$query->param('cat')."::::$ENV{REMOTE_ADDR}\n";
	close(NW);
	print $top;
	print qq~Creating A Board On The FREE Plan
<p>
<b>Thank you!</b><br>
<ul><li>Finished!
</ul>
<p>
That's all you need to do. You will recieve an e-mail within the next few hours with your board's details. Thanks for choosing Best Boards! Please note that we review each new board individually before they are created. Please don't re-submit this form if you don't recieve your board's details right away.
~;
print $bott;	
}
else {
	$plan = $query->param("plan");
$df = qq~You have chosen the fixed plan, so please enter an amount you wish to pay below - this is your "credit". Every month, \$2.50 will be deducted from your credit, so you are effectively pre-paying for several months. You will <b>not</b> be billed recurringly on your credit card - as soon as your credit runs low, you must make another payment.~ if ($plan eq "fixed");
$df = qq~You have chosen the variable plan, so please enter an amount you wish to pay below - this is your "credit". An amount of \$6 will be deducted from this credit for each GB of bandwidth (transfer) you use. You will <b>not</b> be billed recurringly on your credit card - as soon as your credit runs low, you must make another payment.~ if ($plan eq "variable");
		print $top;
		print qq~	Creating A Board On The $plan Plan
<p>
<b>Step Three</b><br>
<ul><li>You have now chosen a pricing plan - the $plan plan and read and agreed to the terms and conditions. If you haven't, please <a href="signup.shtml">return to the signup page</a>. The last step is to select a payment method and send payment. 
</ul>
<p>
<center><b><font size=2>Note: You must already have a <a href="register.cgi">user account</a> (FREE) before creating a board.</font></b></center><br><br>
We have made paying for Best Boards very easy for almost anyone, we hope. And to help you pay, we have compiled some detailed instructions on how exactly to go about your payment.<p>
You can pay by:
<ul><li><a href="create.cgi#Credit">Credit/Debit Card</a>
<ul><li><a href="#Creditonetime">One-time OR:
<li><a href="#Creditrecurring">Recurring
</ul>
<li><a href="create.cgi#NoChex">NoChex</a> (UK Only)
<li><a href="create.cgi#Cheque">Cheque / Money Order</a>
<li><a href="create.cgi#PayPal">PayPal</a>
</ul>

<p>
<a name="Credit"> </a><h3>Credit/Debit Card</h3>
You can securely pay with a credit card (Visa, Mastercard, American Express, Discover, Eurocard, and Visa-Debit, MasterCard-Debit, and Novus cards). All transactions are handled using a secure encrypted connection. Your credit card details are safe. 
<a name="Creditonetime"> </a><h4>One-Time Payment</h4>
To pay a one-time payment (you can always top up later if needed) by credit/debit card, using a completely secure server, please select the amount you wish to pay into your account at this stage - you can always top up later. On selecting a value, you will be taken to our credit card processor's secure order form. When the transaction has been processed, your message board will be set up within 24 hours. (If you need <i>Instant Access</i>, please see the <a href="#Creditrecurring">recurring order</a> section) <br><br>$df
<br><Br>
<script language=javascript>
arr = new Array();
arr[1] = arr[7] = 15;
arr[2] = arr[8] = 20;
arr[3] = arr[9] = 25;
arr[4] = arr[10] = 30;
arr[5] = arr[11] = 40;
arr[6] = arr[12] = 50;
</script>
<form>
<center><select name=howmuch onChange="document.location = 'http://www.clickbank.net/sell.cgi?link=bbboy/~;

$sseed = crypt(int(rand (1000000)), aun);
$sseed =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$sseed =~ s/\.//g;
$sseed =~ s/\|//g;
$sseed = substr($seed, 0, 7);

$seed = $usern;

print qq~' + this.options[this.selectedIndex].value + '/Fixed_Plan_' + arr[this.options[this.selectedIndex].value] + '&seed=$seed';">~ if ($plan eq "fixed");
print qq~' + this.options[this.selectedIndex].value + '/Variable_Plan_' + arr[this.options[this.selectedIndex].value] + '&seed=$seed';">~ if ($plan eq "variable");
if ($plan eq "fixed") {
	print qq~<option value=1>Please Select
	<option value=1>\$15
	<option value=2>\$20
	<option value=3>\$25
	<option value=4>\$30
	<option value=5>\$40
	<option value=6>\$50~;
}
else {
	print qq~<option value=7>Please Select
	<option value=7>\$15
	<option value=8>\$20
	<option value=9>\$25
	<option value=10>\$30
	<option value=11>\$40
	<option value=12>\$50~;
}
print qq~</select>
</center></form>
<a name="Creditrecurring"> </a>
<h4>OR: Recurring Payment</h4>

~;

if (!$query->param('upgrade')) {

print qq~To pay recurringly (every month, 3 months, 6 months or year), please choose the amount and period below. With a recurring payment, your board has <i>Instant Setup</i>. 
<b>If you wish to upgrade an existing board with a recurring payment, please <a href="create.cgi?plan=$plan&upgrade=1">click here</a></b>.
<script language=javascript>
function Pids(pid) {
        switch (pid) {
                case '01501': return 2;
                case '02001': return 3;
                case '02501': return 4;
                case '03001': return 5;
                case '04001': return 6;
                case '05001': return 7;
                case '06501': return 8;
                case '07501': return 10;
                case '10001': return 11;

                case '01503': return 12;
                case '02003': return 13;
                case '02503': return 14;
                case '03003': return 15;
                case '04003': return 16;
                case '05003': return 17;
                case '06503': return 18;
                case '07503': return 19;
                case '10003': return 20;

                case '01506': return 21;
                case '02006': return 22;
                case '02506': return 23;
                case '03006': return 24;
                case '04006': return 25;
                case '05006': return 27;
                case '06506': return 28;
                case '07506': return 29;
                case '10006': return 30;

                case '01512': return 31;
                case '02012': return 32;
                case '02512': return 33;
                case '03012': return 34;
                case '04012': return 35;
                case '05012': return 36;
                case '06512': return 37;
                case '07512': return 38;
                case '10012': return 39;

        }
}

function ConvNice(txt) {
        txt = txt.toLowerCase();
        txt = txt.replace(/[\\s\\W]+/g, '');
        return txt;
}

function CheckAll() {
        document.co.product_id.value = Pids(document.co.am.options[document.co.am.selectedIndex].value + '' + document.co.pd.options[document.co.pd.selectedIndex].value);
        var bid = ConvNice(document.co.bid.value)
        if (confirm('Your new board will be http://frost.bbboy.net/' + bid + ' . If you want to change the name of your board (' + bid + '), please click cancel here, and enter a different board name. Otherwise, please click OK to make payment.')) {
                document.co.bid.value = bid;
                return true;
        }
        else return false;

}
</script>

<form name=co method=get action="https://www.2checkout.com/cgi-bin/crbuyers/recpurchase.2c" onSubmit="return CheckAll();">
<input type=hidden name=product_id>
<input type=hidden name=sid value=65529>
<input type=hidden name=type value="newboard">
<input type=text name=bid> Choose a name for your board<br>
<input type=hidden name=plan value=fixed>
<select name=am>
<option value=015>\$15
<option value=020>\$20
<option value=025>\$25
<option value=030>\$30
<option value=040>\$40
<option value=050>\$50
<option value=065>\$65
<option value=075>\$75
<option value=100>\$100
</select>  <select name=pd>
<option value=01>Monthly
<option value=03>Every 3 Months
<option value=06>Every 6 Months
<option value=12>Yearly
</select>
<input type="submit" value="Create Board">
</form>~;
}
else {
	# it's an upgrade
	print qq~To pay recurringly (every month, 3 months, 6 months or year), please enter your BoardID below. With a recurring payment, your board has <i>Instant Upgrade</i>. 
<form name=up onSubmit="document.location = 'http://bb.bbboy.net/' + document.up.bid.value + '-upgradeboard'; return false;">
		<input type=text name=bid> Please enter your BoardID <br><input type=submit value="Upgrade with a recurring payment"></form>~;
}

print qq~<p><a name="NoChex"> </a><h3>NoChex</h3>
NoChex (<a href="http://www.nochex.com" target=_blank>www.Nochex.com</a>) allows anyone in the UK to make payments easily.<p>
<ol><li>If you don't currently have a Nochex account, <a href="http://www.nochex.com" target=_blank>click here</a> and sign up. 
<p><li>Once you have loaded enough money into your account (<a href="http://www.xe.com" target=_blank>Click here</a> for a currency convertor), click on "Send money".
<p><li>For the e-mail address, enter "bbboy\@bbboy.net", and enter the current value of however much you wish to pay into your account here, but in British Sterling. (<a href="http://www.xe.com" target=_blank>Click here</a> for a currency convertor!) ~;
print qq~\$2.50 will be charged every month. If you wish to pre-pay now for more than a month, simply send a multiple of \$2.50.~ if ($plan eq "fixed");
print qq~Please make sure that you are familiar with Best Boards' credit scheme. We recommend that you credit at least \$15 into your Best Boards account to be safe, but you don't have to.~ if ($plan eq "variable");
print qq~<p><li>Please copy and paste the following into the "Message" box. Please make sure you copy and paste the following information exactly, entering the information where needed.<p>
<blockquote>
Username: <B>Type your EXACT username, case sensitive</b><br>
Email: <b>Type your email address</b><br>
Board Name: <b>Choose a name for your board</b><br>
Plan: $plan
</blockquote>
<p><li>Wait for your payment to be processed!
</ol>
<p><a name="Cheque"> </a><h3>Cheque / Money Order</h3>
<ol><li>If you wish to send money the old-fashioned way, by cheque or money order, please e-mail <a href="mailto:bbboy\@bbboy.net">bbboy\@bbboy.net</a> for the payee address, and enclose the following information on a seperate piece of paper.<p>
<blockquote>
Username: <B>Your EXACT username, case sensitive</b><br>
Email: <b>Your email address</b><br>
Board Name: <b>Choose a name for your board</b><br>
Plan: $plan
</blockquote>
<p><li>Make sure the cheque/money order is in UK funds (British Sterling - <a href="http://www.xe.com">Click here</a> for a currency convertor!). Your bank will be able to arrange this easily for you if you are not a UK resident. ~;
print qq~\$2.50 will be charged every month. If you wish to pre-pay now for more than a month, simply send a multiple of \$2.50..~ if ($plan eq "fixed");
print qq~Please make sure that you are familiar with Best Boards' credit scheme. We recommend that you credit at least \$15 into your Best Boards account to be safe, but you don't have to.~ if ($plan eq "variable");
print qq~<p><li>We will activate your board as soon as the cheque/money order arrives.
</ol>
<p><a name="PayPal"> </a><h3>PayPal</h3>
PayPal (<a href="https://www.paypal.com/refer/pal=AFLN9SPZ9FEYN" target=_blank>www.paypal.com</a>) allows you to send payment via Mastercard/Visa credit/debit card very easily, and securely.<p>
<ol><li>If you don't currently have a PayPal account, <a href="https://www.paypal.com/refer/pal=AFLN9SPZ9FEYN" target=_blank>click here</a> to sign up.
<P><li>Click the button below to make payment. You can credit any amount that you wish. <br><center><form action="https://www.paypal.com/cgi-bin/webscr" method="post" target=_blank>
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="payment\@bbboy.net">
<input type="hidden" name="item_name" value="Credit Your Account">
<input type="hidden" name="item_number" value="credit">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="http://bb.bbboy.net">
<input type="hidden" name="cancel_return" value="http://bb.bbboy.net">
<input type="image" src="http://images.paypal.com/images/x-click-but01.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form></center>
<p><li>Enter the amount of money you wish to credit into your account. Please note that we will not bill you recurringly - it's up to you to top up your credit when needed. 
~;
print qq~\$2.50 will be charged every month. If you wish to pre-pay now for more than a month, simply send a multiple of \$2.50..~ if ($plan eq "fixed");
print qq~Please make sure that you are familiar with Best Boards' credit scheme. We recommend that you credit at least \$15 into your Best Boards account to be safe, but you don't have to.~ if ($plan eq "variable");
print qq~<p><li>Please copy and paste the following into the "Notes" box. Please make sure you copy and paste the following information exactly, entering the information where needed.<p>
<blockquote>
Username: <B>Type your EXACT username, case sensitive</b><br>
Email: <b>Type your email address</b><br>
Board Name: <b>Choose a name for your board</b><br>
Plan: $plan
</blockquote>
<p><li>We will activate your board as soon as the payment arrives.
</ol>~;
		print $bott;
}
