Index: admin/signup.php
===================================================================
--- admin/signup.php	(revision 6652)
+++ admin/signup.php	(working copy)
@@ -11,7 +11,30 @@
 *******************************************************************************/
 ?>
 <?php
-error_reporting(E_ALL);
+
+	unset($found_user);
+	
+	# inital includes
+	require_once 'include_all.php';
+	require_once ($ESPCONFIG['include_path']."/lib/vulabdatalib.php");
+    esp_init_adodb();
+    
+	# lets see if there are any users in the database
+	$users_sql = 'SELECT * FROM user';
+	$users_res = execute_sql($users_sql);
+	if (!$users_res) {
+	}
+	$users_num = $users_res->RecordCount();
+    
+    if ($users_num > 0) { $found_user = true; } else { $found_user = false; }
+
+    # if there is no users found, aka this is the first user, lets make them a superuser
+    if ($found_user == true) {
+    	$realm = 'auto';
+    } else {
+    	$realm = 'superuser';
+    }    
+
 if (isset($_REQUEST['Register']))
 {
 	$required_fields = array(
@@ -35,18 +58,17 @@
 		if (!($_REQUEST[$field] == $_REQUEST['c'.$field]))
 			error_non_confirmed();
 	}
-	require_once 'include_all.php';
-	require_once ($ESPCONFIG['include_path']."/lib/vulabdatalib.php");
-    esp_init_adodb();
+    
+    	
     $sql = "INSERT INTO $ESPCONFIG[user_table] VALUES('','$_REQUEST[username]',PASSWORD('$_REQUEST[password]'),'$_REQUEST[fname]','$_REQUEST[lname]','$_REQUEST[email]','$_REQUEST[type]','N')";
     $result = execute_sql($sql);
     
     if ($_REQUEST['type'] == 'Y')
     {
-	    $sql = "INSERT INTO `designer` VALUES ('$_REQUEST[username]',PASSWORD('$_REQUEST[password]'),'BASIC','auto','$_REQUEST[fname]','$_REQUEST[lname]','$_REQUEST[email]','Y','N','N','N','N','N','N',now(),NULL)";
+	    $sql = "INSERT INTO `designer` VALUES ('$_REQUEST[username]',PASSWORD('$_REQUEST[password]'),'BASIC','$realm','$_REQUEST[fname]','$_REQUEST[lname]','$_REQUEST[email]','Y','N','N','N','N','N','N',now(),NULL)";
     	$result = execute_sql($sql);
 	}
-	$sql = "INSERT INTO `respondent` VALUES('$_REQUEST[username]',PASSWORD('$_REQUEST[password]'),'BASIC','auto','$_REQUEST[fname]','$_REQUEST[lname]','$_REQUEST[email]','N',now(),NULL)";
+	$sql = "INSERT INTO `respondent` VALUES('$_REQUEST[username]',PASSWORD('$_REQUEST[password]'),'BASIC','$realm','$_REQUEST[fname]','$_REQUEST[lname]','$_REQUEST[email]','N',now(),NULL)";
 		
     $result = execute_sql($sql);
     
@@ -81,38 +103,75 @@
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><head>
 <title>OpenVULab Registration</title>
-<link rel="stylesheet" href="http://vulabdev.silkwire.com/vulab-dev/public/css/default.css" type="text/css">
+<script type="text/javascript" src="http://vulab.fluidproject.org/js/default.js"></script>
+	<script type="text/javascript" src="http://vulab.fluidproject.org/js/jquery-1.2.6.pack.js"></script>
+    <script type="text/javascript" src="http://vulab.fluidproject.org/js/jquery.ajaxContent.js"></script>
+    <script type="text/javascript" src="http://vulab.fluidproject.org/js/vulab.admin.js"></script>
+
+    <script type="text/javascript" src="http://vulab.fluidproject.org/js/jquery.form.js"></script>
+    <script type="text/javascript" src="http://vulab.fluidproject.org/js/thickbox.js"></script>
+
+    <link rel="stylesheet" href="http://vulab.fluidproject.org/js/thickbox.css" type="text/css" media="screen" />
+    
+<link href="http://vulab.fluidproject.org/admin/style.css" rel="stylesheet" type="text/css" />
+<style type="text/css">
+.row {
+	margin:10px;
+}
+</style>
 </head>
 <body id="auth">
-<div class="headerGraphic"></div><div class="login"><h1>OpenVULab Registration</h1>
-<form name="loginform" id="loginform"  method="post">
-<fieldset><legend>Registration</legend>
-<h1>All fields are required unless marked otherwise</h1>
-<?php
-	if ($error != null)
-		echo '<h2 style="color:red">ERROR: '.$error.'</h2>';
-?>
-<div class="row"><label for="username">Username:</label><input type="text" size="20" name="username" />
-</div><div class="row">
-<label for="password">Password:</label><input type="password" name="password" />
-</div><div class="row">
-<label for="password">Confirm Password:</label><input type="password" name="cpassword" />
-</div><div class="row">
-<label for="password">First Name (optional):</label><input type="text" name="fname" />
-</div><div class="row">
-<label for="password">Last Name (optional):</label><input type="text" name="lname" />
-</div><div class="row">
-<label for="password">E-Mail Address:</label><input type="text" name="email" />
-</div><div class="row">
-<label for="password">Confirm E-Mail Address:</label><input type="text" name="cemail" />
-</div><div class="row">
-<label for="password">I am a:</label><select name="type">
-	<option value="Y">Researcher</option>
-	<option value="N" SELECTED>Tester</option>
-</select>
-</div><div class="row">
-<input type="submit" name="Register" value="Submit" /><input type="reset" value="Clear" /></div></fieldset>
-</form>
+<?php 	include(realpath('.')."/include/head.inc"); ?>
+<div id="signup" style='padding-left:40px;text-align:left;'>
+	<div class="headerGraphic"></div><div class="login"><h1>OpenVULab Registration</h1>
+	<form name="loginform" method="post">
+	<fieldset>
+	<strong>All fields are required unless marked otherwise</strong>
+	<?php
+		if ($error != null)
+			echo '<h2 style="color:red">ERROR: '.$error.'</h2>';
+	?>
+	<div class="row">Username: <input type="text" size="20" name="username" />
+	</div><div class="row">
+	Password: <input type="password" name="password" />
+	</div><div class="row">
+	Confirm Password: <input type="password" name="cpassword" />
+	</div><div class="row">
+	First Name: <input type="text" name="fname" />
+	</div><div class="row">
+	Last Name: <input type="text" name="lname" />
+	</div><div class="row">
+	E-Mail Address: <input type="text" name="email" />
+	</div><div class="row">
+	Confirm E-Mail Address: <input type="text" name="cemail" />
+	</div><div class="row">
+	I am a: <select name="type">
+	<?php
+		# lets see if there are any users in the database
+		$users_sql = 'SELECT * FROM user';
+		$users_res = execute_sql($users_sql);
+		if (!$users_res) {
+		}
+		$users_num = $users_res->RecordCount();
+	
+		echo $users_num;
+	# if there are no users, lets make the first user a researcher aka admin aka superuser aka root
+	 if ($users_num < 1) {
+	?>
+		<option value="Y">Admin User</option>
+	<?php
+	} else {
+	?>
+		<option value="Y">Researcher</option>
+		<option value="N" SELECTED>Tester</option>
+	<?php
+	}
+	?>
+	</select>
+	</div><div class="row">
+	<input type="submit" name="Register" value="Register" /><input type="reset" value="Clear" /></div></fieldset>
+	</form>
+	</div>
 </div>
 </body>
 </html>
