<?php require_once('Connections/osense.php'); ?>
<?php
session_start();
$MM_authorizedUsers = "1";
$MM_donotCheckaccess = "false";
$ok=0;

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False;

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && false) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
$logu = $_POST['loginid'];

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
	//echo $theValue;
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

  $loginId  = GetSQLValueString($_POST['loginid'], "text");
  $passcode = GetSQLValueString($_POST['password'], "text");
//  $hisName  = GetSQLValueString($_POST['username'], "text");
  $hisName  = "authorized-user";
  $hisType  = GetSQLValueString($_POST['type'], "text");

//  echo $loginId." - ".$passcode." - ".$hisName." - ".$hisType."  ";
  $insertSQL = sprintf("INSERT INTO auth (loginid, password, username, type) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['loginid'], "text"),
                       GetSQLValueString($_POST['password'], "text"),
                       GetSQLValueString($hisName, "text"),
                       GetSQLValueString($_POST['type'], "text"));
//echo "$insertSQL";

  #mysql_select_db($database_osense, $osense);
  #$Result1 = mysql_query($insertSQL, $osense) or die(mysql_error());
$Result1 = mysqli_query( $osense,$insertSQL); 
  shell_exec("./createdir.pl $logu");
  $ok=1;  

}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Create Users</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {
	font-size: xx-large;
	font-weight: bold;
	color: #336666;
}
.border {
	border: medium solid #336666;
}
-->
</style>
<style>
	* {font-family:Arial, Helvetica, sans-serif;
		font-size:9pt;}
		
	/* table list */
	.table_list {border-collapse:collapse;
		border:solid #cccccc 1px;
		width:100%;}
	
	.table_list td {padding:5px;
		border:solid #efefef 1px;}
	
	.table_list th {background:#75b2d1;
		padding:5px;
		color:#ffffff;}
	
	.table_list tr.odd {background:#e1eff5;}
	
	.time_picker_div {padding:5px;
		border:solid #999999 1px;
		background:#ffffff;}
		
</style>
<link rel="stylesheet" type="text/css" href="sdmenu/sdmenu.css" />
	<script type="text/javascript" src="sdmenu/sdmenu.js"></script>
	<script type="text/javascript">
	// <![CDATA[
	var myMenu;
	window.onload = function() {
		myMenu = new SDMenu("my_menu");
		myMenu.init();
	};
	// ]]>
	</script>
	

<script type="text/javascript">	
	function clogid()
	{
  
	   var fname, lname, uname, lid;
	   fname = document.form1.firstname.value;
	   lname = document.form1.lastname.value;
	   uname = lname.slice(0,6);
	   lid = fname.slice(0,1);
	   lid = lid + uname;	   
	   uname = fname + " " + lname;
    // xi
	  // document.form1.loginid.value = lid;
	  // document.form1.loginid1.value = lid;
	   document.form1.username.value = uname;
  	 
     //alert(document.form1.loginid.value);
	   //document.getElementById('password').focus();	      

	}
</script>

</head>
<body>
<table width="1000" height="736" align="center" class="border">
  <tr>
    <td width="157"><div align="center"><img src="wname.jpg" width="150"><span class="style1"> </span></div></td>
    <td width="672"><div align="center"><span class="style1">NetEye</span></div></td>
    <td width="149"><span class="style1"><img src="wicon.jpg"></span></td>
  </tr>
  <tr height="640">
    <td width="157">
	<div style="float: left" id="my_menu" class="sdmenu">
      <div>
        <span>NetEye</span>
        <a href="home.php">Home</a>
        <a href="topology.php">Topology</a>
		<!--a href="registration.php">Registration Form</a-->

      </div>
	  <div>
		<span>MySpace</span>
        <?php
		if ($_SESSION['ilog']!="yes")
		{
		?> 
		<a href="login.php">Login</a>
		<?php
		}
		else
		{
		?> 
		<!--a href="logout.php">Logout</a-->
		<?php
		}
		?> 
		<a href="sjobs.php">Schedule jobs</a>
        <a href="myjobs.php">Manage jobs</a>
        <a href="nodebusy.php">Check nodes busy</a>
        <a href="cnodegrp1.php">Create node group</a>
        <a href="logout.php">Logout</a>
       <!--a href="sjobs1.php">Schedule new tier2 jobs</a-->
        <!--a href="myjobs1.php">Manage tier2 jobs</a-->
      </div>
      <div>
        <span>AdminSpace</span>
		<a href="inlogadd.php">Create Users</a>
		<a href="regman.php">Manage Registration</a>
      </div>

      <div class="collapsed">
        <span>Support</span>
        <a href=http://www.cs.wayne.edu/~hzhang/group/index.html>DNC Research Group</a>
      </div>

    </div>
	</td>
	<td colspan="2">
	<?php if ($ok==1) {
	echo "Login successfully created !"; 
        } else
	{?>	
	<div align="center">Welcome <?php $_SESSION['MM_Username'] ?> </div><br>
	<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
	  <table align="center" class="border">
		<tr valign="baseline">
		  <td align="right" nowrap><div align="left">First Name:<br> 
		    </div></td>
		  <td><input name="firstname" type="text" id="firstname" size="32"></td>
		  </tr>
		<tr valign="baseline">
		  <td align="right" nowrap><div align="left">Last Name: </div></td>
		  <td><input name="lastname" type="text" id="lastname" size="32"></td>
		  </tr>
		<tr valign="baseline">
		  <td width="112" align="right" nowrap><div align="left">Login ID:</div></td>
		  <!--td width="199"><input type="hidden" name="loginid" value="" size="32"-->
		  <td width="199"><input  name="loginid" value="" size="32">
					<!--input type="text" name="loginid1" value="" size="32" disabled--></td>
		</tr>
		<tr valign="baseline">
		  <td nowrap align="right"><div align="left">Password:</div></td>
		  <td><input type="password" name="password" id="password" value="" size="32" onClick="clogid()"></td>
		</tr>
		<!--<tr valign="baseline">
		  <td nowrap align="right"><div align="left">Username:</div></td>
		  <td><input type="hidden" name="username" value="" size="32"></td>
		  <td><input  name="username" value="" size="32"></td>
		</tr> -->
		<tr valign="middle">
		  <td nowrap align="right"><div align="left">Type:</div></td>
		  <td valign="baseline">
			<table>
			  <tr>
				<td><input name="type" type="radio" value="2" checked >
				  User</td>
				<td> 
			  </tr>
			  <tr>
				<td><input type="radio" name="type" value="1" >
				  Admin</td>
				<td> 
			  </tr>
			</table>
		</tr>
		<tr valign="baseline">
		  <td nowrap align="right"><div align="left"></div></td>
		  <td><input type="submit" value="Insert record"></td>
		</tr>
	  </table>
	  <input type="hidden" name="MM_insert" value="form1">
	</form>
	<?php }?>
    </td>
  </tr>
</table>
</body>
</html>
