<? 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>Abstract Submission Portal</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>
<?
	if (isset($_REQUEST['confirm']) && $_REQUEST['confirm']!=""){
		$insert = array(
			"user_login" => $_REQUEST['user_login'],
			"user_name" => $_REQUEST['user_name'],
			"user_login" => $_REQUEST['user_login'],
			"user_password" => $_REQUEST['user_password'],
			"user_principle" => $_REQUEST['user_principle']
		);
		$db->insert("tbl_abstract_user", $insert);
		
		$user_idarr = $db->run("SELECT LAST_INSERT_ID() as id;");
        $user_id = $user_idarr[0]['id'];
		
		if ($_REQUEST['topic_id']!=0){
			$insert = array(
				"user_id" => $user_id,
				"topic_id" => $_REQUEST['topic_id']
			);
			$db->insert("tbl_topic_user", $insert);
		}
		echo "<script>alert('User added.');window.location='user_admin.php';</script>";
	}
?>

<? include("nav_menu.php"); ?>
<div class="well">
<div class="content" bgcolor="#FFFFD0">
<div class="col-12 feature">
    <div class="panelCheck">
    <div class="panel-heading">
		<h3 class 'panel-title'>Add User</h3>
       
    </div>
		
	  

    <form name="camps" method='POST' action="" enctype="multipart/form-data" class="form-horizontal" role="form">
	
	<div class="panel panel-primary" id="child">
        
		
		<div class="panel panel-primary">
			
			<div class="panel-body">    
				<div class="form-group">
					<label for="user_login" class="col-lg-4 control-label">User Login</label>
					<div class="col-lg-6">
						<input type="text" name="user_login" id="user_login" class="form-control" required>
					</div>
				</div>
				<div class="form-group">
					<label for="user_name" class="col-lg-4 control-label">User Name</label>
					<div class="col-lg-6">
						<input type="text" name="user_name" id="user_name" class="form-control" required>
					</div>
				</div>
				<div class="form-group">
					<label for="user_password" class="col-lg-4 control-label">User Password</label>
					<div class="col-lg-6">
						<input type="password" name="user_password" id="user_password" class="form-control" required>
					</div>
				</div>
				<div class="form-group">
					<label for="user_name" class="col-lg-4 control-label">PC?</label>
					<div class="col-lg-6">
						<select name="user_principle" id="user_principle" class="form-control">
							<option value='0'>No</option>
							<option value='1'>Yes</option>
						</select>
					</div>
				</div>
				<div class="form-group">
					<label for="user_name" class="col-lg-4 control-label">Topic</label>
					<div class="col-lg-6">
						<select name="topic_id" id="topic_id" class="form-control"><option value='0'>Please Select</option>
							<?
								$results = $db->select("tbl_topic");
								foreach($results as $result){
									echo "<option value='".$result['topic_id']."'>".$result['topic_name']."</option>";
								}
							?>
						</select>
					</div>
				</div>
				<center>
					<input type="submit" name="confirm" value="Add" class="btn btn-success">
				</center>
			</div>
		</div>
		
		
    </form>
	
</div>
    </div>
<script>
	selectrelation();
	selecterelation();
	chkTransport();
</script>
</div>
</div>
</body>
</html>