<? include ("../settings.php"); ?>
<? include ("session.php"); ?>
<?
    if (isset($_REQUEST['registrant_id']) && $_REQUEST['registrant_id']>0){
        
        $update = array(
			"registrant_type" => $_REQUEST['registrant_type'],
			"registrant_salutation" => $_REQUEST['registrant_salutation'],
			"registrant_firstname" => $_REQUEST['registrant_firstname'],
			"registrant_lastname" => $_REQUEST['registrant_lastname'],
			"registrant_fullname" => $_REQUEST['registrant_fullname'],
			"registrant_designation" => $_REQUEST['registrant_designation'],
			"registrant_organisation" => $_REQUEST['registrant_organisation'],
			"registrant_country" => $_REQUEST['registrant_country'],
			"registrant_email" => $_REQUEST['registrant_email'],
			"registrant_diet" => $_REQUEST['registrant_diet'],
			"registrant_badge" => $_REQUEST['registrant_badge'],
			"registrant_country" => $_REQUEST['registrant_country'],
			"remarks" => $_REQUEST['remarks'],
			"registrant_paid" => $_REQUEST['registrant_paid'],
			"registrant_paymentmode" => $_REQUEST['registrant_paymentmode'],
			"registrant_amount" => $_REQUEST['registrant_amount'],
			"role_id" => $_REQUEST['role_id']
        );
        $bind = array(
            ":search1" => $_REQUEST['registrant_id']
        );
        
        $db->update("tbl_registrant", $update, "registrant_id = :search1", $bind);
        
        
        if ($_REQUEST['role_id']!="0"){
            $results = $db->select("tbl_registrant","registrant_id = :search1",$bind);
            $result = $results[0];
            if($result['registrant_number']=="" || $result['registrant_number']=="0"){
                $numbers = $db->select("tbl_id");
                $registrant_number = $numbers[0]['id_itself'];
                $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);            
            
        }
        
        echo "1";
        
    }


?>