<? 
require_once "include/application.php"; 
require_once "include/function.php";

if($btnAdd){
	if(!$active)$active="No";
	

	if(count($access)>0)$acc="@,".implode(",", $access);
	else $acc="@";
	

	$sql="INSERT INTO `user` (id,pwd,access,name,oldpwd,active,blockdelete) values ";
	$sql.=" ('$username','".md5($pwd)."','$acc',\"$name\",'$pwd','$active','$block')";
	@mysql_query($sql) or die(mysql_error());

	print("<script type='text/javascript'>alert('User is added.')</script>");
	print("<script type='text/javascript'>location.href='user.php'</script>");
}

?>

<!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=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="sddm.css" >
<script src="include/validation.js" type="text/javascript"></script>
<script type="text/javascript">
message = ("Sorry, you are not allowed to enter any spaces");
function nospaces(which) {
x = which.value
if (navigator.appName == "Netscape" ) {
if (e.which == 32) {
alert (message);
return false
}
}
if (navigator.appName == "Microsoft Internet Explorer") {
if (event.keyCode == 32) {
alert (message);
return false;
}
}
x = x.replace(/\s/g,""); // remove the unwanted space
document.form.username.value = x;
}
</script>

<title><? echo TITLE?></title></head>
<body>

<table width="1024" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#f1efd8">
  <tr>
    <td  colspan="2" align="center"><? require_once "include/header.php"; ?></td>
  </tr>
  <tr>
    <td colspan="2" align="center">&nbsp;</td>
  </tr>
  <tr>
    <td width="185" valign="top" bgcolor="e6f3f9">
	
<? require_once "include/columnLeft.php";
if(array_search("User",$menulist)==false)
		print("<script type='text/javascript'>location.href='index.php'</script>");

 ?>	</td>
    <td width="834" valign="top">
	<form name="form" method="post" action="<?=$PHP_SELF ?>"  ONSUBMIT="return ValidateAddUser(this)">
	  <table width="800" height="250" border="0" align="center" cellpadding="0" cellspacing="0">


	  <tr>
        
        <td valign="top"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="100%" height="30" class="TitleH3">Add User </td>
          </tr>
          <tr>
            <td height="1" bgcolor="#B8ED83"></td>
          </tr>
          <tr>
            <td ><? echo "<div class='Msg'>$action_msg</div>" ?>&nbsp;</td>
          </tr>

        </table>
          <table border="0" cellpadding="2" width="100%" cellspacing="1" class="small">
            <tr>
              <td height="30" colspan="2" class="TextH1"><strong class="MenuTitle">LOGIN INFORMATION </strong></td>
            </tr>
            <tr>
              <td height="1" colspan="2" bgcolor="#999999"></td>
            </tr>
            <tr>
              <td width="199" class="TextH1">Username : <span class="require">*</span></td>
              <td width="493" class="TextH1"><input name="username" type="text" class="small" id="username" value="<? echo $username ?>" maxlength="10" onkeydown="nospaces(this)"/>
                <span class="subItem"> (Maximun10 characters, no space)</span></td>
            </tr>
            <tr>
              <td class="TextH1">Name :<span class="require">*</span></td>
              <td class="TextH1"><input name="name" type="text" class="small" id="name" value="<? echo $name ?>" size="50" maxlength="50" /></td>
            </tr>
            <tr>
              <td class="TextH1">Password : <span class="require">*</span></td>
              <td class="TextH1"><input name="pwd" type="text" class="small" id="pwd" value="<? echo $pwd ?>" maxlength="20" />
                <input type="button" class="btn" tabindex="2" onClick="javascript:formSubmit()" value="Generate">  
                <span class="subItem"> (Minimum 6 characters)</span></td>
            </tr>
            <tr>
              <td class="TextH1">Confirm Password : <span class="require">*</span></td>
              <td class="TextH1"><input name="cpwd" type="password" class="small" id="cpwd" value="<? echo $cpwd ?>" maxlength="20" /></td>
            </tr>
            <tr>
              <td valign="top" class="TextH1">Access Level :</td>
              <td class="TextH1"><select name="access[]" size="7" multiple="multiple" id="access">
                <? include_once "groupaccess.inc.php"; ?>
                              </select>
                <? staymultifocus("form","access",$access) ?></td>
            </tr>
            <tr class="editTbl">
              <th height="23" class="TextH1"><div align="left">Block Delete Record :</div></th>
              <td class="TextH1"><input name="block" type="checkbox" id="block" value="Yes" checked="checked" <?=($block=="Yes" ? "CHECKED" : " ")?> />              </td>
            </tr>
            <tr class="editTbl">
              <th height="23" class="TextH1"><div align="left">Active :</div></th>
              <td class="TextH1"><input name="active" type="checkbox" value="Yes" checked="checked" <?=($active=="Yes" ? "CHECKED" : " ")?> />              </td>
            </tr>
            <tr>
              <td height="30" colspan="2" class="text12">&nbsp;</td>
            </tr>
            <tr>
              <td height="1" colspan="2" bgcolor="#999999"></td>
            </tr>
            <tr>
              <td height="30" colspan="2" class="TextH1"><span class="require">* Denotes a require_onced field</span></td>
            </tr>
            <tr>
              <td colspan="2" class="text12">
                  <input name="btnAdd" type="submit" class="btn" id="btnAdd" value="ADD" onclick="return confirm('Are you sure ?')"/>
&nbsp;                <input name="btnBack" type="button" class="btn" id="btnBack" onclick="location.href='user.php'" value="BACK" />              </td>
            </tr>
          </table></td>

      </tr>
 
    </table><br />
	</form>	</td>
  </tr>
  <tr>
    <td colspan="2" bgcolor="#333333" class="Footer" align="center"><br />
    <? require_once "footer.php"; ?></td>
  </tr>
</table>
</body>
</html>
