<? include("../settings.php"); ?>
<? include("session.php"); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>SP Admin Panel</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Include all CSS/JS -->
        <!-- Bootstrap -->
    <link href="css/bootstrap.css" rel="stylesheet">
    <link href="css/jquery.dataTables.css" rel="stylesheet">
    <link href="http://cdn.datatables.net/responsive/1.0.1/css/dataTables.responsive.css" rel="stylesheet">
    

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="js/jquery-2.1.1.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
    <script src="js/jquery.dataTables.min.js"></script>
    <script src="http://cdn.datatables.net/responsive/1.0.1/js/dataTables.responsive.js"></script>

    <!-- End of all CSS/JS -->
      <script>
          
      </script>
    
   </head>
<body>


<? include("nav_menu.php"); ?>
    <?
        if (isset($_REQUEST['submit'])){
            $insert = 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']
            );
            $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"){
                $results = $db->select("tbl_registrant","registrant_id = :search1",$bind);
                $result = $results[0];
                if($result['registrant_number']=="0" || $result['registrant_number']==""){
                    $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);
                //echo $registrant_sn;
                $update = array ("registrant_sn"=>$registrant_sn);
                $db->update("tbl_registrant", $update, "registrant_id = :search1", $bind);            
                echo "<script>alert('Delegate added.');</script>";
            }            
            echo "<script>alert('Delegate Added');</script>";
        }
    ?>
      <div class="well">
<div class="content" bgcolor="#FFFFD0">
<div class="col-12 feature">
<div class="panelCheck">
    <div class="panel-heading">
        <h3 class "panel-title"><strong>SP Admin Panel - Add Delegate</strong></h3>
    </div>

    
    <div class="well well-lg">
        <form class="form-horizontal" method="post" action="">
        
		<div class='form-group'>
            <label for='registrant_papernumber' class='col-lg-4 control-label'>Registrant Type</label>
            <div class='col-lg-6 text-left'>
                <input type="text" class="form-control" name="registrant_type" id="registrant_type">
            </div>
        </div>
        <div class='form-group'>
            <label for='registrant_salutation' class='col-lg-4 control-label'>Salutation</label>
            <div class='col-lg-6 text-left'>
                <input type="text" class="form-control" name="registrant_salutation" id="registrant_salutation">
            </div>
        </div> 
		<div class='form-group'>
            <label for='registrant_fullname' class='col-lg-4 control-label'>First Name</label>
            <div class='col-lg-6 text-left'>
                <input type="text" class="form-control" name="registrant_firstname" id="registrant_firstname">
            </div>
        </div>
		<div class='form-group'>
            <label for='registrant_fullname' class='col-lg-4 control-label'>Last Name</label>
            <div class='col-lg-6 text-left'>
                <input type="text" class="form-control" name="registrant_lastname" id="registrant_lastname">
            </div>
        </div>		
        <div class='form-group'>
            <label for='registrant_fullname' class='col-lg-4 control-label'>Full Name</label>
            <div class='col-lg-6 text-left'>
                <input type="text" class="form-control" name="registrant_fullname" id="registrant_fullname">
            </div>
        </div>
		<div class='form-group'>
            <label for='registrant_designation' class='col-lg-4 control-label'>Designation</label>
            <div class='col-lg-6 text-left'>
                <input type="text" class="form-control" name="registrant_designation" id="registrant_designation">
            </div>
        </div>
        <div class='form-group'>
            <label for='registrant_organisation' class='col-lg-4 control-label'>Organisation</label>
            <div class='col-lg-6 text-left'>
                <input type="text" class="form-control" name="registrant_organisation" id="registrant_organisation">
            </div>
        </div>
		<div class='form-group'>
            <label for='registrant_email' class='col-lg-4 control-label'>Email</label>
            <div class='col-lg-6 text-left'>
                <input type="text" class="form-control" name="registrant_email" id="registrant_email">
            </div>
        </div>
		<div class='form-group'>
            <label for='registrant_diet' class='col-lg-4 control-label'>Diet</label>
            <div class='col-lg-6 text-left'>
                <input type="text" class="form-control" name="registrant_diet" id="registrant_diet">
            </div>
        </div>
		<div class='form-group'>
            <label for='registrant_badge' class='col-lg-4 control-label'>Badge Colour</label>
            <div class='col-lg-6 text-left'>
                <input type="text" class="form-control" name="registrant_badge" id="registrant_badge">
            </div>
        </div>
		<div class='form-group'>
            <label for='registrant_country' class='col-lg-4 control-label'>Country</label>
            <div class='col-lg-6 text-left'>
                <input type="text" class="form-control" name="registrant_country" id="registrant_country">
            </div>
        </div>
        <div class='form-group'>
            <label for='remarks' class='col-lg-4 control-label'>Remarks</label>
            <div class='col-lg-6 text-left'>
                <input type="text" class="form-control" name="remarks" id="remarks">
            </div>
        </div>
		<div class='form-group'>
            <label for='registrant_paid' class='col-lg-4 control-label'>Payment Status</label>
            <div class='col-lg-6 text-left'>
				<input type="text" class="form-control" name="registrant_paid" id="registrant_paid">
            </div>
        </div> 
		<div class='form-group'>
            <label for='registrant_paymentmode' class='col-lg-4 control-label'>Payment Mode</label>
            <div class='col-lg-6 text-left'>
                <input type="text" class="form-control" name="registrant_paymentmode" id="registrant_paymentmode">
            </div>
        </div>
		<div class='form-group'>
            <label for='registrant_amount' class='col-lg-4 control-label'>Amount</label>
            <div class='col-lg-6 text-left'>
                <input type="text" class="form-control" name="registrant_amount" id="registrant_amount">
            </div>
        </div>
		<div class='form-group'>
            <label for='role_id' class='col-lg-4 control-label'>Delegate Role</label>
            <div class='col-lg-4'>
                <select class='form-control' id='role_id' name='role_id'><option value="">Please Select</option>
                 <?
                    $output = "";
                    $roles = $db->select("tbl_role");
                    foreach ($roles as $role){
                            echo "<option value='".$role['role_id']."'>".$role['role_name']." - ".$role['role_prefix']."</option>";
                    }
                    echo $output;
                ?>            
                </select>
            </div>
        </div>
		
        </div>            
            <center>
            <button type="submit" name="submit" class="btn btn-info">Add New Delegate</button>
            <button type="reset" class="btn btn-default">Cancel</button>
            </center>
        </form>        
        
        
    </div>
    
<!-- /.modal -->
</div>
</div>
</div>
</div>
</body>
</html>
