<? include("../settings.php"); ?>
<? include("session.php"); ?>
<?
    if (isset($_REQUEST['submit'])){
            $insert = array(
                "registrant_salutation" => $_REQUEST['registrant_salutation'],
                "registrant_fullname" => $_REQUEST['registrant_fullname'],
				"registrant_firstname" => $_REQUEST['registrant_firstname'],
				"registrant_lastname" => $_REQUEST['registrant_lastname'],
				"registrant_designation" => $_REQUEST['registrant_designation'],
				"registrant_organisation" => $_REQUEST['registrant_organisation'],
				"registrant_badgecolour" => $_REQUEST['registrant_badgecolour'],
				"registrant_email" => $_REQUEST['registrant_email'],
				"breakout" => $_REQUEST['breakout'],
				"industry_category" => $_REQUEST['industry_category'],
				"registrant_diet" => $_REQUEST['registrant_diet'],
				"registrant_allergy" => $_REQUEST['registrant_allergy'],
				"remarks" => $_REQUEST['remarks'],
				"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];
                if($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_sn"=>$registrant_sn,"registrant_type"=>$prefixes[0]['role_name']);
                    $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, 3, "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, transaction 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>
