<?php
include("session_start.php");
include("session_check.php");
include("database.php");

extract($_GET);
	if(@$_POST['submit']!="")
	{
		extract($_POST);
		$user = $_POST['username'];
		
		$uname = "SELECT uname FROM login where username='$user'";
		//echo "SELECT uname FROM login where username='$user'";
		$uname_result = mysql_query($uname);
		$uname_row = mysql_fetch_array($uname_result);
		$uname = $uname_row['uname']; 
		//echo $uname; 
		
		$result = mysql_query("SELECT uname, username FROM login where username='$user' or uname='$uname'");
		//echo "SELECT uname, username FROM login where username='$user' or uname='$uname'";
		$num=mysql_num_rows($result);
		$row=mysql_fetch_assoc($result);
		
		/*echo $row['username'];
		echo $user;*/
		
		//if(trim($row['username'])==trim($user))
		if($num>0)
		{			
			?>
				<script language="javascript" type="text/javascript">
				alert("User name is already exist");
				window.location="create_user.php?id=<?php echo $_GET['id'];?>";
				</script>
			<?php
		}
		else
		{
			//echo("insert into login(uname,username,password,address,mobile,landline,email,cat) values ('$name','$username','$pass','$add','$mob','$ll','$email','$cat'"); exit;
			$query=mysql_query("insert into login(uname,username,password,address,mobile,landline,email,cat) values ('$name','$username','$pass','$add','$mob','$ll','$email','$cat')");
			if($query)
			{
				?>
					<script language="javascript" type="text/javascript">
                    alert("Inserted Successfully");
                    window.location="index_grid.php";
                    </script>
				<?php
			}
		}
	}
?>

<script type="text/javascript">


function trim(s)
{
return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
var error="";
var tfld = trim(fld.value); // value of field with whitespace trimmed off
var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;


if (!emailFilter.test(tfld))
{ //test email for illegal characters

error = "Please enter a valid email address.\n";
}
else if (fld.value.match(illegalChars)) {

error = "The email address contains illegal characters.\n";
} else {

}
return error;
}

function validate()
{
	 if((document.create_user.name.value) == "")
	 {
			alert("Fill Up Empty Name Fields");
			document.create_user.name.focus();
			return false;
	
	 }
	 else if((document.create_user.username.value) == "")
	 {
			alert("Fill Up Empty Username Fields");
			document.create_user.username.focus();
			return false;
	
	 }
	 else if((document.create_user.pass.value) == "")
	 {
			alert("Fill Up Empty Password Fields");
			document.create_user.pass.focus();
			return false;
	
	 }
	else if((document.create_user.add.value) == "")
	 {
			alert("Fill Up Empty Address Fields");
			document.create_user.add.focus();
			return false;
	
	 }
	 else if((document.create_user.mob.value) == "")
	 {
			alert("Fill Up Empty Mobile Number");
			document.create_user.mob.focus();
			return false;
	 }
	 else if(isNaN(document.create_user.mob.value))
	 {
			alert("Mobile number is not valid");
			document.create_user.mob.focus();
			return false;
	 }
	 else if(document.create_user.mob.value!="" && document.create_user.mob.value.length < 10)
	 {
			 alert("Mobile no is less than 10 digit");
			 document.create_user.mob.focus();
			 return false;
	 } 
	 else if((document.create_user.ll.value) == "")
	 {
			alert("Fill Up Empty Land Line Number");
			document.create_user.ll.focus();
			return false;
	
	 }
	 else if( document.create_user.email.value == "")
	 {
			alert("Fill Up Empty Email Id Fields");
			document.create_user.email.focus();
			return false;
	 }
	 else if( document.create_user.email.value!="" && validateEmail(document.create_user.email))
	 {
		alert("Enter correct email id.");
		return false;
	 }
 return true;
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Survey Application</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" type="text/css" href="css/page.css">
<link href="css/admincss.css" rel="stylesheet" type="text/css">

<link rel="stylesheet" type="text/css" href="css/ddsmoothmenu.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="js/ddsmoothmenu.js">
</script>

<script type="text/javascript">

ddsmoothmenu.init({
	mainmenuid: "smoothmenu1", //menu DIV id
	orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
	classname: 'ddsmoothmenu', //class added to menu's outer DIV
	//customtheme: ["#1c5a80", "#18374a"],
	contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})



</script>
</head>

<body class="body">

<div id="wrap" >
  
  
  <div id="top">
    <?php include("header.php"); ?>
    <!--<div id="ban"><table width="1004" align="left"  >
  <tr>
    <td width="234"  align="left"  valign="top" ><img src="images/logoss.jpg" border="0" /></td>
    <td  valign="top" style="padding-top:5px;" width="758"  align="right" ><table align="left" width="707">
  <tr>
    <td width="386" align="left"><div ><a href="#" id="bantext1">REQUEST A DEMO</a></div></td>
    <td width="167" align="left"><div ><a href="#" id="bantext2">DOWNLOADS</a></div></td>
    <td width="138" align="left"><div ><a href="#" id="bantext2">DOWNLOADS</a></div></td>
  </tr>
  <tr>
    <td colspan="3" align="center" class="banquot">Be Smart and Survey Smartly </td>
  </tr>
</table></td>
    
    
  </tr>
</table>
    </div>-->
    
    </div>
    </div>
   <div id="menuholder"><?php include("adminmenu.php"); ?></div>
   <div id="contholder">
   
    
    <!--<div id="nav">
     <ul>
     <li><a href="adminhome.php" id="home_on">HOME</a></li>
        <li><a href="adminproducts.php" id="products_on">PRODUCTS</a></li>
		<li><a href="adminfeatures.php" id="features_on">FEATURES</a></li>
        <li><a href="adminadvantages.php" id="advantages_on">ADVANTAGES</a></li>
        <li><a href="adminhowitworks.php" id="howitworks_on">HOW IT WORKS</a></li>
        <li><a href="adminhelp.php" id="help_on">HELP</a></li>
        <li><a href="admincontactus.php" id="contactus_on">CONTACT US</a></li>
    
    </ul>
    
    </div>-->
    
    
    	<div id="contdata">
   <?php //include("header.php"); ?><br />
<form name="create_user" method="post" action="" >
	<table border="1"  align="center" width="60%"  bordercolor="#2a4a73">
		<tr>
			<td bgcolor="#a9c1de" class="f"> Insert New User Details </td>
		</tr>
        
        <tr>
        	<td>
            	<table width="100%">
                <tr>
                	<td> <br /></td>
                </tr>
                <tr>
        			<td>
						<table border="1" cellpadding="2" cellspacing="2" width="80%" align="center" bordercolor="#bcd5e7" style="border-collapse:collapse">
						<tr>
    						<td colspan="3" align="left" ><font class="font4" ><b>Insert New User Details</b> </font></td>
  						</tr>
                        
        					<div align="left"> <font color="#FF0000" face="Verdana" size="2"> * Items marked with an asterisk (*) are required </font>  </div>
        				    <br>
						<tr>
							<td>
                    			<table style="margin-top:10px" border="0" align="left">
                              
                                 
            					<tr>
    								<td ><font class="font4"><b> <font color="#FF0000" > * </font> Name :</b></font> </td>
    								<td><input type="text" name="name" id="name" maxlength="13" /></td>
    							</tr>
                                <tr>
    								<td ><font class="font4"> <b> <font color="#FF0000" > * </font> Username :</b></font> </td>
    								<td><input type="text" name="username" id="username" maxlength="13" /></td>
    							</tr>
                                <tr>
    								<td ><font class="font4"><b> <font color="#FF0000" > * </font> Password :</b></font> </td>
    								<td><input type="password" name="pass" id="pass" maxlength="13" /></td>
    							</tr>
                                <tr>
    								<td><font class="font4"><b>Address:</b></font> </td>
    								<td><textarea name="add" id="add" cols="17" rows="3" ></textarea></td>
    							</tr>
                                <tr>
    								<td ><font class="font4"><b>Mobile :</b></font> </td>
    								<td><input type="text" name="mob" id="mob" maxlength="10" /></td>
    							</tr>
                                <tr>
    								<td><font class="font4"><b>Landline :</b></font> </td>
    								<td><input type="text" name="ll" id="ll" maxlength="20" /></td>
    							</tr>
                                <tr>
    								<td ><font class="font4"><b>Email Id :</b></font> </td>
    								<td><input type="text" name="email" id="email" /></td>
    							</tr>
                                <tr>
    								<td ><font class="font4"><b>Category :</b></font> </td>
    								<td><input type="radio" name="cat" id="cat" value="admin"> Admin </input>
                                    	<input type="radio" name="cat" id="cat" value="user" checked> User </input>
                                    </td>
    							</tr>
                                
    							</table>
                    		</td>
        				</tr>
    					
						</table>
            		</td>
				</tr>
                
        		</table>
            </td>
        </tr>
		
	</table>
    <br />
    <table border="1" align="center" width="60%"  bordercolor="#2a4a73">
    	<tr>
			<td bgcolor="#a9c1de" class="f"align="right"><input type="submit"  name="submit" id="submit" value="Submit" onClick="return validate();" style="text-decoration:none" class="button_c"> 
           <a href="index_grid.php " style="text-decoration:none"><input type="reset" name="reset" id="reset" value="Cancel" style="text-decoration:none" class="button_c"></td> 
            
		</tr>
    </table>
</form>
	<?php include("footer.php"); ?>	
		</div>
    
   
    

    	
   </div> 

<!--<div id="footer">Copyright © 2012.Smart Survey All Rights Reserved.Website Designed & Developed by Kalpak Solutions</div>-->





</body>
</html>