<?php
	if(!isset($_SESSION)) session_start();
	/*
		UserCake Version: 1.4
		http://usercake.com
		
		Developed by: Adam Davis
	*/
	require_once("demosettings.php");
	require_once("userCake/models/config.php");
	include("loginCheckPoint.php");
	include_once("authorizations.php");
	//include_once("C:/xampp/htdocs/iventitymatcherhtm/bsw/utils.php");

	$userdetails = fetchUserDetails($_SESSION['username']);
	
	
	if ($userdetails['Group_ID'] != 0)
	{
	    die($_SESSION['username']." - You are not allowed to register new users");
	}
	
	
	//Prevent the user visiting the logged in page if he/she is already logged in
	if(isUserLoggedIn()) { header("Location: account.php"); die(); }
?>

<?php
	/* 
		Below is a very simple example of how to process a new user.
		 Some simple validation (ideally more is needed).
		
		The first goal is to check for empty / null data, to reduce workload here
		we let the user class perform it's own internal checks, just in case they are missed.
	*/

//Forms posted
if(!empty($_POST))
{
		require_once 'sqlTable.php';
		$email = trim($_POST["email"]);
		$username = trim($_POST["username"]);
		$password = trim($_POST["password"]);
		$confirm_pass = trim($_POST["passwordc"]);
		$roleSelect = trim($_POST["RoleSelect"]);
		$mysqli = sqlCreateConnection("register");
		$errors = registerNewUser($mysqli, $username, $password, $confirm_pass, $email, $roleSelect);
	}
?>
<!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>
<title>Registration</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="style.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/script.js"></script>
<!-- CuFon: Enables smooth pretty custom font rendering. 100% SEO friendly. To disable, remove this section -->
<script type="text/javascript" src="js/cufon-yui.js"></script>
<script type="text/javascript" src="js/arial.js"></script>
<script type="text/javascript" src="js/cuf_run.js"></script>

 <script src="jquery/jquery.js" type="text/javascript"></script>
  <script src="jquery/jquery-ui.custom.js" type="text/javascript"></script>
  <script src="jquery/jquery.cookie.js" type="text/javascript"></script>
  <script src="jquery-ui/development-bundle/ui/jquery.ui.tabs.js"></script>
  <script src="jquery-ui/development-bundle/ui/jquery.effects.core.js"></script>
<script src="jquery-ui/development-bundle/ui/jquery.effects.blind.js"></script>

<link type="text/css" href="jquery-ui/css/ui-lightness/jquery-ui-1.8.17.custom.css" rel="stylesheet" />
<script type="text/javascript" src="jquery-ui/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="jquery-ui/js/jquery-ui-1.8.17.custom.min.js"></script>
		
  <link href="src/skin/ui.dynatree.css" rel="stylesheet" type="text/css" id="skinSheet">
  <script src="src/jquery.dynatree.js" type="text/javascript"></script>
<script type="text/javascript" src="js/ivcommon.js"></script>
  <style>
 td {
	border-right: 0px solid #C1DAD7;
	border-bottom: 0px solid #C1DAD7;
	background: #fff;
	padding: 6px 6px 6px 12px;
	color: #4f6b72;
}
.filestdhd{
	color:gray; 
	font-weight:bold;
	background:lightgray;
}
.filestdev{
	color:white; 
	background:#e58a42;
}
.filestdod{
	color:white; 
	background:#e58a42;
}

  </style>


</head>
<body onunload="">
 <div class="top-banner">
	 <a href="senddoc.php"><img src="images/intuscan-img.png" /></a>
	 <p style="padding:0 10px 10px 10px; float:right;"><b>1.2.0.1 (demo version)</b></p>
 </div>
<div class="main">
  <div class="header">
    <div class="header_block">

      <div class="clr"></div>
    </div>
    <div class="clr"></div>
  </div>
  <div class="content">
      <div class="mainbar">
        <div class="article">
		<?php
        	if(!empty($_POST)){
        		if(count($errors) > 0){
        ?>
        			<div>
        			<?php
        				echo "<p style=\"color: red; font-weight:bold;\">" . $errors[0] . "</p>";
        			?>
        			</div>     
        <?php
        		}
        		else{
        		
        			echo "<h2>Registration completed successfully. Click <a href=\"javascript:gotoPage('login', {})\">here</a> to login</h2>";
        			die();
        		}
        		
        	}
        ?> 
        
                <form name="newUser" id="newUser" action="register.php" method="post">
                	<table align="center">
                		<tr>
                			<td>
                				Username
                			</td>
                			<td>
                				<?php
                					echo "<input type=\"text\" name=\"username\" value=\"" . $username . "\"/>";
                				?>
                			</td>
                		</tr>
                		<tr>
                			<td>
                				Password
                			</td>
                			<td>
                				<input type="password" name="password" />
                			</td>
                		</tr>
                		<tr>
                			<td>
                				Confirm Password
                			</td>
                			<td>
                				<input type="password" name="passwordc" />
                			</td>
                		</tr>
                		<tr>
                			<td>
                				Email
                			</td>
                			<td>
                				<input type="text" name="email" />
                			</td>
                		</tr>
                		<tr>
                			<td>
                				User Role
                			</td>
                			<td>
                				<select name="RoleSelect" id="RoleSelect">
                					<option value="0">Admin</option>
                					<option value="1">Private</option>
                					<option value="2">Viewer</option>
                					<option value="3">Contributor</option>
                					</select>
                			</td>
                		</tr>
                		<tr>
                			<td></td>
                			<td>
                				<a href="javascript:document.forms['newUser'].submit();"><img src="images/submit.gif" alt="submit"></a>
                			</td>
                		</tr>
                	</table>
                </form>
			</div>
		</div>
      <div class="clr"></div>
  </div>
</div>
<div class="footer">
    <div class="footer_resize">
    	<p>
    	<div class="logo">
    		<img src="images/logo.jpg" width="100"/>  
    	</div>
    	</p>
    	<p class="lf">© Copyright <a href="#">www.intuview.com</a></p>
      <div class="clr"></div>
    </div>
  </div>
</body>


