<?php
	session_start();
	if (!isset($_SESSION['view_id']))
		header("Location: index.php");

	$user_name = $_POST['user_name'];
	$password = $_POST['password'];
	$view_id = $_POST['selectAccessLevel'];

	include "../connect/db_connection.php";
	
	//First check to see if user exists.
	$query = "SELECT * FROM users WHERE `UserID` = '$user_name'";
	$result = mysql_query($query, $bwb_link);
	$row = mysql_fetch_array($result);
	$tmp_user_name = $row["UserID"];
	if ($tmp_user_name)
	{
		echo "$user_name already exists in database.  Click <a href=\"users.php\" title=\"here\">here</a> to enter a different user name.";
		exit;
	}
	// Add user to database.
	if ($view_id == 1)
		$access_level = "admin";
	elseif ($view_id == 2)
		$access_level = "user";
	elseif ($view_id == 3)
		$access_level = "reseller";
	$query = "INSERT INTO users SET UserID='$user_name', `password`='$password', AccessLevel='$access_level'";
	$result = mysql_query($query, $bwb_link);
	
	header("Location: users.php");
	
?>
