<?php
include("includes/site_info.php");
include('session_handler.inc');

$option_manager = new OptionManager();
$currencysym = $option_manager->GetValue('currency_symbol');
$currency = $option_manager->GetValue('currency');
$currencypoint = $option_manager->GetValue('currency_point');

$WUserID = $_SESSION['Sess_UserId'];
$WUsername = $_SESSION['Sess_UserName'];

$now = getdate();

$mode = $_REQUEST['mode'];
$amount = $_REQUEST['amount'];
$paymnt_method = $_REQUEST['paymnt_method'];
$email = $_REQUEST['email'];
$username = $_REQUEST['username'];
$paymentRef = $_REQUEST['paymentRef'];
$paymentRefNo = strtoupper(substr(str_replace($replace,'',md5($WUsername.date('Y-m-d H:i:s'))), 0, 12));

if($mode=="AddFund" && $paymnt_method=="cash") {
$memberS_query=mysql_query("SELECT mem_email FROM adverts LEFT JOIN members ON (adv_userid=mem_userid) WHERE adv_userid = '$WUserID' AND adv_approved='1'") or die(mysql_error());
$sqlS_array = mysql_fetch_object($memberS_query);

$q1_tra="select sum(amount) as balance from transactions where mem_userid=$WUserID and pstatus='approved'";
$row1_tra=mysql_fetch_array(mysql_query($q1_tra));
$balance=0;
if($row1_tra)
{
	$balance=(is_numeric($row1_tra["balance"]))?$row1_tra["balance"]:0;
}

$replace = array('O','0');
?>
<script type="text/javascript">
jQuery(document).ready(function(){
    jQuery("#addFund2").submit(function(){
	 	jQuery('#AddFundDIV').hide();
	 	jQuery('#sub_loading').show();

	var str = jQuery(this).serialize();
/*	alert(str);
*/
   		jQuery.ajax({
   		type: "POST",
   		url: "addFunds.php",
   		data: str,
   		success: function(result){
		jQuery('#sub_loading').hide();	
		jQuery('#AddFundDIV').html(result);
 		jQuery('#AddFundDIV').fadeIn('slow');
		}
 });

return false;
    });
});
   </script>

<table width="100%" border="0" cellpadding="0" cellspacing="0" class="white_back_t_xb">
	<tr class="grey_12 orange_row_back solid_line_separator">
		<td><div style="background-color:#0000FF; width:10px; height:10px; float:left; margin-top:3px; margin-right:5px;"><img src="images/spacer.gif" width="10" height="10" /></div>
			Add Cash to your Wauhaha Bank</td>
	</tr>
	<tr>
		<td align="center"><table border="0" cellpadding="0" cellspacing="0">
				<tr>
					<td align="left"><table border="0" cellspacing="0" cellpadding="0" class="p0">
							<tr>
								<td>Amount to be Added: </td>
								<td><strong><img src="images/iconPA_o.gif" border="0" align="absmiddle" />
									<?=$amount?>
									for
									<?=$currency.number_format($amount*$currencypoint,2)?>
									</strong></td>
							</tr>
							<tr>
								<td class="p0">Current Balance: </td>
								<td><strong><img src="images/iconPA_o.gif" border="0" align="absmiddle" />
									<?=$balance?>
									</strong></td>
							</tr>
							<tr>
								<td class="p0">Balance After Addition: </td>
								<td><strong class="blue_b"><img src="images/iconPA_o.gif" border="0" align="absmiddle" />
									<?=($balance+$amount)?>
									</strong></td>
							</tr>
						</table></td>
				</tr>
				<tr>
					<td align="left">&nbsp;</td>
				</tr>
				<tr>
					<td align="left"><span class="red_12">Don't forget to take the following information with you:</span></td>
				</tr>
				<tr>
					<td align="left"><strong>Your Email:
						<?=$sqlS_array->mem_email?>
						</strong></td>
				</tr>
				<tr>
					<td align="left"><strong>Your Username:
						<?=$WUsername?>
						</strong></td>
				</tr>
				<tr>
					<td align="left"><strong>Payment Reference Number:
						<?=$paymentRefNo?>
						</strong></td>
				</tr>
				<tr>
					<td align="left">&nbsp;</td>
				</tr>
				<tr>
					<td align="left">Bank Transfer Information:</td>
				</tr>
				<tr>
					<td align="left"><strong>Bank: Public Bank Berhad </strong></td>
				</tr>
				<tr>
					<td align="left"><strong>Swift: PBBEMYKL</strong></td>
				</tr>
				<tr>
					<td align="left"><strong>Branch: Taman Munshi Ibrahim Johor Bahru</strong> </td>
				</tr>
				<tr>
					<td align="left"><strong>Account Name: Wauhaha Sdn. Bhd. </strong></td>
				</tr>
				<tr>
					<td align="left"><strong>Account Number: 3153513626 </strong></td>
				</tr>
				<tr>
					<td>&nbsp;</td>
				</tr>
				<tr>
					<td align="center"><form method="post" name="addFund2" id="addFund2">
							<input name="mode" type="hidden" value="AddCash" />
							<input name="amount" type="hidden" value="<?=$amount?>" />
							<input name="paymnt_method" type="hidden" value="cash" />
							<input name="email" type="hidden" id="email" value="<?=$sqlS_array->mem_email?>" />
							<input name="username" type="hidden" id="username" value="<?=$WUsername?>" />
							<input name="paymentRef" type="hidden" id="paymentRef" value="<?=$paymentRefNo?>" />
							<input type="submit" name="Submit" value="Confirm" class="submit" />
							<input name="cancel" type="button" class="button" id="cancel" value="Cancel" onclick="javascript: jQuery.facebox.close(); return false;" />
						</form></td>
				</tr>
			</table></td>
	</tr>
</table>
<?php
	die;
}

if($mode=="AddCash" && $paymnt_method=="cash") {
$camount = $amount*$currencypoint;
$query="insert into transactions (mem_userid,amount,description,date_submitted,ptype,currency,currency_value,paymentRef,currency_rate) values ($WUserID,$amount,'Offline Payment (Cash or Cheque)','".date("YmdHis",time())."', 'PA','$currency', '$camount','$paymentRef','$currencypoint')";
//echo $query;
$result=mysql_query($query,$link) or die(mysql_error());

?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="white_back_t_xb">
	<tr class="grey_12 orange_row_back solid_line_separator">
		<td><div style="background-color:#0000FF; width:10px; height:10px; float:left; margin-top:3px; margin-right:5px;"><img src="images/spacer.gif" width="10" height="10" /></div>
			Add Cash to your Wauhaha Bank</td>
	</tr>
	<tr>
		<td align="center"><table border="0" cellpadding="0" cellspacing="0">
				<tr>
					<td><img src="images/iconPA_o.gif" border="0" align="absmiddle" /> <strong>
						<?=$amount?>
						</strong> has been added to your Wauhaha Bank with status <strong>Pending</strong>. Please keep track of your email and <strong>My Bank</strong> for the latest payment status. </td>
				</tr>
				<tr>
					<td>&nbsp;</td>
				</tr>
				<tr>
					<td><span class="red_12">* Reminder: </span></td>
				</tr>
				<tr>
					<td>Wauhaha requires your payment to clear before service is granted. You will receive an email confirmation when this payment clears.</td>
				</tr>
				<tr>
					<td>If your information is missing, your payment will be delayed or rejected. </td>
				</tr>
				<tr>
					<td>Please submit only one payment per Payment Reference Number.</td>
				</tr>
				<tr>
					<td>&nbsp;</td>
				</tr>
				<tr>
					<td align="center"><form action="printCashInfo.php" method="post" name="printInfo" target="myWindow" id="printInfo" onsubmit="window.open('', 'myWindow', 'width=500,height=500,status=yes,resizable=no,scrollbars=no')">
							<input name="mode" type="hidden" value="PrintCash" />
							<input name="amount" type="hidden" value="<?=$amount?>" />
							<input name="paymnt_method" type="hidden" value="cash" />
							<input name="email" type="hidden" id="email" value="<?=$email?>" />
							<input name="username" type="hidden" id="username" value="<?=$username?>" />
							<input name="paymentRef" type="hidden" id="paymentRef" value="<?=$paymentRef?>" />
							<input type="submit" name="Submit" value="Print Out Your Information" class="submit" onclick="javascript: jQuery.facebox.close();" />
							<input name="cancel" type="button" class="button" id="cancel" value="Cancel" onclick="javascript: jQuery.facebox.close(); return false;" />
						</form></td>
				</tr>
			</table></td>
	</tr>
</table>
<?php
	die;
}

if($mode=="AddFund" && $paymnt_method=="paypal") {
$memberS_query=mysql_query("SELECT mem_email FROM adverts LEFT JOIN members ON (adv_userid=mem_userid) WHERE adv_userid = '$WUserID' AND adv_approved='1'") or die(mysql_error());
$sqlS_array = mysql_fetch_object($memberS_query);

$q1_tra="select sum(amount) as balance from transactions where mem_userid=$WUserID and pstatus='approved'";
$row1_tra=mysql_fetch_array(mysql_query($q1_tra));
$balance=0;
if($row1_tra)
{
	$balance=(is_numeric($row1_tra["balance"]))?$row1_tra["balance"]:0;
}

$replace = array('O','0');
$paymentRefNo = strtoupper(substr(str_replace($replace,'',md5($WUsername.date('Y-m-d H:i:s'))), 0, 12));
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="white_back_t_xb">
	<tr class="grey_12 orange_row_back solid_line_separator">
		<td><div style="background-color:#0000FF; width:10px; height:10px; float:left; margin-top:3px; margin-right:5px;"><img src="images/spacer.gif" width="10" height="10" /></div>
			Add Funds Through PayPal</td>
	</tr>
	<tr>
		<td align="center"><table border="0" cellpadding="0" cellspacing="0">
				<tr>
					<td align="left"><table border="0" cellspacing="0" cellpadding="0" class="p0">
							<tr>
								<td>Amount to be Added: </td>
								<td><strong><img src="images/iconPA_o.gif" border="0" align="absmiddle" />
									<?=$amount?>
									for
									<?=$currency.number_format($amount*$currencypoint,2)?>
									</strong></td>
							</tr>
							<tr>
								<td class="p0">Current Balance: </td>
								<td><strong><img src="images/iconPA_o.gif" border="0" align="absmiddle" />
									<?=$balance?>
									</strong></td>
							</tr>
							<tr>
								<td class="p0">Balance After Addition: </td>
								<td><strong class="blue_b"><img src="images/iconPA_o.gif" border="0" align="absmiddle" />
									<?=($balance+$amount)?>
									</strong></td>
							</tr>
						</table></td>
				</tr>
				<tr>
					<td align="left">&nbsp;</td>
				</tr>
				<tr>
					<td align="center"><form action="printCashInfo.php" method="post" name="paypal" target="myWindow" id="paypal" onsubmit="myWindow = window.open('', 'myWindow', 'width=500,height=500,status=yes,resizable=no,scrollbars=no'); myWindow.focus(); return false;">
							<input type="submit" name="Submit" value="Continue to Paypal Payment" class="submit" />
							<input name="cancel" type="button" class="button" id="cancel" value="Cancel" onclick="javascript: jQuery.facebox.close(); return false;" />
						</form>
						<?php /*?><form method="post" action= "https://www.sandbox.paypal.com/cgi-bin/webscr" name="addFund3" id="addFund3" >
							<!--					<form method="post" name="addFund3" id="addFund3" action="https://www.paypal.com/cgi-bin/webscr">
-->
							<input type="hidden" name="cmd" value="_xclick">
							<input type="hidden" name="business" value="<?php echo $rs_a["_paypal_id"]; ?>">
							<input type="hidden" name="item_name" value="Add Funds to Wauhaha Bank">
							<input type="hidden" name="item_number" value="<?=$paymentRefNo?>">
							<input name="amount" type="hidden" id="amount" value="<?=$amount*$currencypoint?>" />
							<input type="hidden" name="currency_code" value="<?php echo $currency;?>">
							<input type="hidden" name="return" value="<?php echo $rs_a["site_root"]; ?>/thanks.php">
							<input type="hidden" name="cancel_return" value="<?php echo $rs_a["site_root"]; ?>/cancelpurchase.php">
							<input type="hidden" name="custom" value="<?=$WUsername?>">
							<input type="hidden" name="rm" value="2">
							<input type="hidden" name="notify_url" value="<?php echo $rs_a["site_root"]; ?>/ipn/ipn.php">
							<input type="hidden" name="no_note" value="1">
							<input type="hidden" name="description" value="Added Funds through PayPal">
							
							
						</form><?php */?></td>
				</tr>
			</table></td>
	</tr>
</table>
<?php
	die;
}


?>
<script type="text/javascript">
jQuery(document).ready(function(){
    jQuery("#addFund").submit(function(){
/*	if(isNaN(jQuery("input[name='amount']:checked").val()) || (jQuery("input[name='amount']:checked").val()== "") || jQuery("input[name='amount']:checked").val()<=0)
	{
		alert ('Please choose a point package!');
		return false;
	}
*/
	if(isNaN(jQuery("input[name='amount']").val()) || (jQuery("input[name='amount']").val()== "") || jQuery("input[name='amount']").val()<=0)
	{
		alert ('Please specify a non-zero positive numeric value!');
		jQuery("input[name='amount']").focus();
		jQuery("input[name='amount']").select();
		return false;
	}
	if(jQuery("input[name='paymnt_method']:checked").val()== "")
	{
		alert ('Please choose a payment method!');
		return false;
	}

	 	jQuery('#AddFundDIV').hide();
	 	jQuery('#sub_loading').show();

	var str = 'mode=AddFund&' + jQuery(this).serialize();

   		jQuery.ajax({
   		type: "POST",
   		url: "addFunds.php",
   		data: str,
   		success: function(result){
		jQuery('#sub_loading').hide();	
		jQuery('#AddFundDIV').html(result);
 		jQuery('#AddFundDIV').fadeIn('slow');
		}

 });
return false;
    });
});

function roundNumber(oform, rnum) { 
  rnum = Math.ceil(rnum);
  var newnumber = Math.round(rnum);
  var newfloat =Math.round(rnum*<?=$currencypoint?>*Math.pow(10,2))/Math.pow(10,2);
  if (isNaN(newnumber)) newnumber=0;
  if (isNaN(newfloat)) newfloat=0;
  oform["amount"].value = parseInt(newnumber);
  jQuery('#ActualAmount').html('<?=$currency?>'+parseFloat(newfloat).toFixed(2));
 }
   </script>
<div id="AddFundDIV" class="p5">
	<table width="100%" border="0" cellpadding="0" cellspacing="0" class="white_back_t_xb">
		<tr class="grey_12 orange_row_back solid_line_separator">
			<td><div style="background-color:#0000FF; width:10px; height:10px; float:left; margin-top:3px; margin-right:5px;"><img src="images/spacer.gif" width="10" height="10" /></div>
				Upgrade Your Account</td>
		</tr>
		<tr class="p0">
			<td><form method="post" name="addFund" id="addFund">
					<table border="0" cellpadding="0" cellspacing="0" class="p5">
						<tr>
							<td align="left">Paid members can upload more photos, access more WauhhHubs sections and features!<br/><br/>
								Upgrade to VIP member now with just USD30 per year and qualify for WauhhBiz network client reward plan!<br/><br/> 
								<strong>Please select required membership option below</strong></td>
						</tr>
						<tr>
							<td align="left"><div class="ml_50">
									<label>
									<input name="MLevel" type="radio" value="30" checked="checked" />
									<strong><img src="images/iconPA_o.gif" border="0" align="absmiddle" /> 300 (<?=$currency.number_format(300*$currencypoint,2)?>) - 1 year Membership</strong></label>
									<br />
								</div></td>
						</tr>
						<tr>
							<td align="left" valign="baseline">&nbsp;</td>
						</tr>
						<tr>
							<td align="left" valign="baseline"><strong>How would you like to pay?</strong></td>
						</tr>
						<tr>
							<td align="left" valign="baseline"><div class="ml_50">
									<!--<label>
									<input type="radio" name="paymnt_method" value="paypal" />
PayPal</label>
									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-->
									<label>
									<input name="paymnt_method" type="radio" value="cash" checked />
									Cash/Cheque</label>
								</div></td>
						</tr>
						<tr>
							<td align="center" valign="baseline">&nbsp;</td>
						</tr>
						<tr>
							<td align="center"><input type="submit" name="Submit" value="Submit" class="submit" />
								<input name="cancel" type="button" class="button" id="cancel" value="Cancel" onclick="javascript: jQuery.facebox.close(); return false;" />
							</td>
						</tr>
						<tr>
							<td align="center">&nbsp;</td>
						</tr>
						<tr>
							<td class="blue_12"><table border="0" cellspacing="0" cellpadding="0" width="100%">
									<tr>
										<td><p align="center"><strong>WauhhBiz network Client Reward    calculation rules</strong> </p></td>
									</tr>
									<tr>
										<td></td>
									</tr>
									<tr>
										<td></td>
									</tr>
									<tr>
										<td><table border="1" cellspacing="1" cellpadding="0">
												<tr>
													<td width="213"><p>Monthly new client development </p></td>
													<td width="167"><p>the number of clients</p></td>
													<td width="131"><p>Reward from top up</p></td>
												</tr>
												<tr>
													<td width="213"><p>Direct Client</p></td>
													<td width="167"><p>1 to 9</p></td>
													<td width="131"><p>5%</p></td>
												</tr>
												<tr>
													<td width="213"></td>
													<td width="167"><p>10 and above</p></td>
													<td width="131"><p>10%</p></td>
												</tr>
												<tr>
													<td width="213"><p>Direct Group new Client</p></td>
													<td width="167"><p>30 and above</p></td>
													<td width="131"><p>5%</p></td>
												</tr>
											</table>
											<p align="center">&nbsp;</p>
											<table border="1" cellspacing="1" cellpadding="0">
												<tr>
													<td width="209"><p>Auto Qualify of client accumulated</p></td>
													<td width="173"><p>the number of clients achieved</p></td>
													<td width="125"><p>Reward from top up</p></td>
												</tr>
												<tr>
													<td width="209"><p>Direct Client </p></td>
													<td width="173"><p>10 to 99</p></td>
													<td width="125"><p>5%</p></td>
												</tr>
												<tr>
													<td width="209"></td>
													<td width="173"><p>100 and above</p></td>
													<td width="125"><p>10%</p></td>
												</tr>
												<tr>
													<td width="209"><p>Direct Group Client</p></td>
													<td width="173"><p>1000 and above</p></td>
													<td width="125"><p>5%</p></td>
												</tr>
											</table>
											<p align="center">&nbsp;</p>
											<p>Example 1:    Assuming that your new direct client in the first month of calendar was 15 client sign up through your link, with an average USD100 per payment of top up, your monthly reward as follows:</p>
											<br />
											<br />
											<p align="center" style="letter-spacing:-1px;">USD100 × 15 client × 10% = USD150</p>
											<br />
											<br />
											<p>Example 2: You had six months to participate in Client development on network, and there are 100 old client that the average monthly top up amounted to USD50/client, this month you have developed 30 new customers each paying an average of USD200 and , your direct group this month client achieved 50 client and each paying an average of USD100, Reward are:</p>
											<br />
											<br />
											<p align="center" style="letter-spacing:-1px;">(USD50 × 100 Client) + (USD200 × 30 Client) x 10% + (USD100 × 50 Client) x 5% = USD1350 </p>
											<br />
											<br />
											<p>Example 3: A year later, the development of your direct customer total reached 200, with an average monthly top up amounted to USD50 / client, this month you are a new development of 15 new client, an average of USD200 per payment and , your direct group client accumulated 1000 client and each paying an average of USD50, Reward are:</p>
											<br />
											<br />
											<p align="center" style="letter-spacing:-1px;">( USD50 × 200 Client) + (USD200 × 15 Client) x 10% + (USD50 × 1000 Client) x 5% = USD3800 </p>
											<br />
											<br />
											<ol style="padding: 30px; color:#000">
												<li style="padding-bottom: 10px;">All final calculation base on monthly closing end day of month calendar from report generated</li>
												<li style="padding-bottom: 10px;"> All old client accumulated calculation of reward are excluding new client sales of the month calendar</li>
												<li style="padding-bottom: 10px;">All reward factor are follow by the above chart from performance of which ever higher of client development</li>
											</ol></td>
									</tr>
								</table>
								
								<p>&nbsp;</p>
								<p style="color:#FF0000">* Account auto maintain for USD10 per month applicable to sales.<br/><br/>* Please, note that if you're upgrading to a higher membership level, remaining time on your current membership level will be lost.</p></td>
						</tr>
					</table>
				</form></td>
		</tr>
	</table>
</div>
