<? include("../settings.php"); ?>
<? include("session.php"); ?>
<?
    if (isset($_REQUEST['submit'])){
            $insert = array(
                "registrant_papernumber" => $_REQUEST['registrant_papernumber'],
				"registrant_papertype" => $_REQUEST['registrant_papertype'],
				"registrant_category" => $_REQUEST['registrant_category'],
				"registrant_type" => $_REQUEST['registrant_type'],
				"registrant_selection" => $_REQUEST['registrant_selection'],
				"registrant_salutation" => $_REQUEST['registrant_salutation'],
				"registrant_familyname" => $_REQUEST['registrant_familyname'],
				"registrant_fullname" => $_REQUEST['registrant_fullname'],
				"registrant_organisation" => $_REQUEST['registrant_organisation'],
				"registrant_mailing" => $_REQUEST['registrant_mailing'],
				"registrant_city" => $_REQUEST['registrant_city'],
				"registrant_postal" => $_REQUEST['registrant_postal'],
				"registrant_country" => $_REQUEST['registrant_country'],
				"registrant_email" => $_REQUEST['registrant_email'],
				"registrant_cc" => $_REQUEST['registrant_cc'],
				"registrant_telephone" => $_REQUEST['registrant_telephone'],
				"registrant_diet" => $_REQUEST['registrant_diet'],
				"badgecolour" => $_REQUEST['badgecolour'],
				"remarks" => $_REQUEST['remarks'],
				"presentdate" => $_REQUEST['presentdate'],
				"presenttime" => $_REQUEST['presenttime'],
				"presentvenue" => $_REQUEST['presentvenue'],
				"registrant_paymentmode" => $_REQUEST['registrant_paymentmode'],
				"registrant_paid" => $_REQUEST['registrant_paid'],
				"registrant_cocktail_attend" => $_REQUEST['registrant_cocktail_attend'],
				"registrant_extra_cocktail" => $_REQUEST['registrant_extra_cocktail'],
				"registrant_dinner_attend" => $_REQUEST['registrant_dinner_attend'],
				"registrant_extra_dinner" => $_REQUEST['registrant_extra_dinner'],
				"registrant_total" => $_REQUEST['registrant_total'],
				"role_id" => $_REQUEST['role_id']
            );        
            $db->insert("tbl_registrant", $insert);
            
            $results = $db->run("select last_insert_id() as lastid;");
            $registrant_id = $results[0]['lastid'];
            
            $bind = array(
                ":search1" => $registrant_id
            );
            if ($_REQUEST['role_id']!="0"){
                //echo "this is the new id $bind";
               // print_r($bind);
                $results = $db->select("tbl_registrant","registrant_id = :search1",$bind);
                $result = $results[0];
                //print_r($result);
                if($result['registrant_number']=="0" || $result['registrant_number']==""){
                    $numbers = $db->select("tbl_id");
                    //print_r($numbers);
                    $registrant_number = $numbers[0]['id_itself'];
                    //echo $registrant_number;
                    $increase = $registrant_number + 1;
                    $bindid = array(":search1" => 1);
                    $updateid = array("id_itself" => $increase);
                    $db->update("tbl_id", $updateid, "id= :search1", $bindid);
                    $update = array ("registrant_number"=>$registrant_number);
                    $db->update("tbl_registrant", $update, "registrant_id = :search1", $bind);
                }else{
                    $registrant_number = $result['registrant_number'];
                }

                $bindid = array(":search1" => $_REQUEST['role_id']);
                $prefixes = $db->select("tbl_role","role_id=:search1",$bindid);
                $prefix = $prefixes[0]['role_prefix'];
                $registrant_sn = $prefix.str_pad($registrant_number, 4, "0", STR_PAD_LEFT);
                $update = array ("registrant_sn"=>$registrant_sn);
                $db->update("tbl_registrant", $update, "registrant_id = :search1", $bind);            

            }            
            
        }

?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>
Processing
</title>
<!-- Meta Tags -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

</head>

<body>
<form id="Paypal" name="Paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<!-- testing link -->
<!-- www.sandbox.paypal.com/cgi-bin/webscr-->
<!-- live link -->
<!-- www.paypal.com/cgi-bin/webscr-->

	<center>
		<font face="Arial" size="3">Please wait, processing...</font>
		<?
			
				echo "<script>alert('Added');window.location='walkin.php'</script>";
			
		?>
	</center>
	<input type="hidden" name="business" value="anthony_goh@splanner.com.sg">
	 
	<!-- live acount -->
	<!--<input type="hidden" name="business" value="lanne@watsons.com.sg"> -->
	<!-- once paypal email confirmed will start using this email -->
	<!--<input type="hidden" name="business" value="paypal@watsons.com.sg"> -->
	<!-- <input type="hidden" name="business" value="john.s_1338724364_biz@gmail.com"> -->
	<input type="hidden" name="cmd" value="_cart" />
	<input type="hidden" name="upload" value="1" />
	
</form>

</body>

</html>
