<? 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_salutation" => $_REQUEST['registrant_salutation'],
				"registrant_fullname" => $_REQUEST['registrant_fullname'],
				"registrant_designation" => $_REQUEST['registrant_designation'],
				"registrant_organisation" => $_REQUEST['registrant_organisation'],
				"registrant_email" => $_REQUEST['registrant_email'],
				"registrant_contact" => $_REQUEST['registrant_contact'],
				"registrant_country" => $_REQUEST['registrant_country'],
				"registrant_reception" => $_REQUEST['registrant_reception'],
				"registrant_dinner" => $_REQUEST['registrant_dinner'],
				"registrant_diet" => $_REQUEST['registrant_diet'],
				"registrant_paid" => $_REQUEST['registrant_paid'],
				"registrant_badge" => $_REQUEST['registrant_badge'],
				"remarks" => $_REQUEST['remarks'],
				"role_id" => $_REQUEST['role_id']
            );
            $db->insert("tbl_registrant", $insert);
            //print_r($_REQUEST);
			//print_r($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($results);
                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>";
        }
    ?>
      <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_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'>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_contact' class='col-lg-4 control-label'>Contact</label>
            <div class='col-lg-6 text-left'>
                <input type="text" class="form-control" name="registrant_contact" id="registrant_contact">
            </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='registrant_reception' class='col-lg-4 control-label'>Welcome Reception</label>
            <div class='col-lg-6 text-left'>
                <input type="text" class="form-control" name="registrant_reception" id="registrant_reception">
            </div>
        </div>
		<div class='form-group'>
            <label for='registrant_dinner' class='col-lg-4 control-label'>Banquet Dinner</label>
            <div class='col-lg-6 text-left'>
                <input type="text" class="form-control" name="registrant_dinner" id="registrant_dinner">
            </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_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_paid' class='col-lg-4 control-label'>Payment</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='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='role_id' class='col-lg-4 control-label'> Role</label>
			<div class='col-lg-4'>
				<select class='form-control' id='role_id' name='role_id'>
				 <?
					$output = "";
					$roles = $db->select("tbl_role");
					foreach ($roles as $role){
						if ($role['role_id']==$result['role_id'])
							echo "<option value='".$role['role_id']."' selected>".$role['role_name']." - ".$role['role_prefix']."</option>";
						else
							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>
