<?php
@session_start();
@ob_start();
$conn = mysql_connect('localhost', 'akhilagya', 'abhinay@2018AB') or die ("connection not found");
	mysql_select_db('laabh') or die ("connection not found");
//include "header.php"; 
//$objIms->loginpage_alter();
	
	
	if(isset($_POST["Save"])){
	$file_name = $_FILES['logo']['name'];
		  $ext = pathinfo($file_name , PATHINFO_EXTENSION);
		    $renm = $_REQUEST['uname'];
		   $file_name=$renm.".".$ext;
		$file_tmp =$_FILES['logo']['tmp_name'];
		$file_type=$_FILES['logo']['type'];	
	
	
	
        $desired_dir="uploads/";
        if(empty($errors)==true){
            if(is_dir($desired_dir)==false){
                mkdir("$desired_dir", 0700);		// Create directory if it does not exist
            }
            if(is_dir("$desired_dir/".$file_name)==false){
                move_uploaded_file($file_tmp,"$desired_dir/".$file_name);
            }else{									// rename the file if another one exist
                $new_dir="$desired_dir/".$file_name.time();
                 rename($file_tmp,$new_dir) ;				
            }
}
	
	$sql_ins="INSERT INTO `registration` (`name`, `phone`, `address`, `org_name`, `org_logo`, `gstin`, `state`, `city`, `pin`) VALUES ('".$_REQUEST['name']."', '".$_REQUEST['phone']."', '".$_REQUEST['address']."', '".$_REQUEST['org']."', '$file_name', '".$_REQUEST['gstin']."', '".$_REQUEST['state']."', '".$_REQUEST['city']."', '".$_REQUEST['pin']."');";
					 
					 $res_ins=mysql_query($sql_ins);
					 $reg_id=mysql_insert_id();
					 
					 $sql_cash="INSERT INTO `system_login` (`reg_id`, `preveledge`, `emailid`, `password`, `lastlogin_date`, `last_time`, `ipaddress`, `creation_date`, `status`) VALUES ('$reg_id', '0', '".$_REQUEST['uname']."', '".md5($_REQUEST['pwd'])."', '', '', '".$_SERVER['REMOTE_ADDR']."', CURRENT_TIMESTAMP, '1');";
					 $res_cash=mysql_query($sql_cash);
					 $user_id=mysql_insert_id();
					$ip=$_SERVER['REMOTE_ADDR'];
					 $sql_usr="INSERT INTO `tbl_user_status_and_plan` (`user_id`, `access_type`, `plan_type`, `upgrade_date`, `start_date`, `expiry_date`, `stampdate`, `ip_address`) VALUES ('$user_id', 'Trial Version', '', '', '".date('Y-m-d')."', '".date('Y-m-d', strtotime('+30 day'))
."', CURRENT_TIMESTAMP, '$ip');";
					 
					 $res_usr=mysql_query($sql_usr);
					
					 ?>
					 <script>
					 alert('success');
					 location='login.php';
					 </script>
					 <?php }
?>
<!DOCTYPE HTML>
<html>

<head>
	<title>Laabh</title>
	<!-- Meta-Tags -->
	<link rel="shortcut icon" href="images/icon.png" />
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta charset="utf-8">
	
	<script>
		addEventListener("load", function () {
			setTimeout(hideURLbar, 0);
		}, false);

		function hideURLbar() {
			window.scrollTo(0, 1);
		}
	</script>
	<!-- //Meta-Tags -->
	<!-- Stylesheets -->
	<link href="log_css/font-awesome.css" rel="stylesheet">
	<link href="log_css/style.css" rel='stylesheet' type='text/css' />
	<!--// Stylesheets -->
	<!--fonts-->
	<!-- title -->
	<link href="//fonts.googleapis.com/css?family=Josefin+Slab:100,300,400,600,700" rel="stylesheet">
	<link href="//fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800" rel="stylesheet">
	<!--//fonts-->
	<style>
	body {
  /*background: linear-gradient(to right, #123C58, #67A9D3);*/
 /* background: radial-gradient(circle, #FFFFFF, #FFFFFF, #FFFFFF);*/
}
.w3ls-login form{ border-radius:20px;}
.w3ls-login form {
    position: relative;
    max-width: 600px;
    margin: 0 5vw;
    padding: 4px;
	}
	
	.table > tbody > tr > td, .table > tbody > tr > th, .table > tfoot > tr > td, .table > tfoot > tr > th, .table > thead > tr > td, .table > thead > tr > th {
    padding:5px;
	padding-top:0px;
	padding-bottom:0px;
}
.agile-field-txt {
    flex-basis: 100%;
    -webkit-flex-basis: 100%;
    margin-bottom: 3px;
	}
	.w3ls-login input[type="text"], .w3ls-login input[type="password"] { padding:10px;}
	
	.select {
    width: 100%;
    color: #000;
    outline: none;
    font-size: 16px;
    letter-spacing: 0.5px;
    /* line-height: 25px; */
    padding: 10px;
    box-sizing: border-box;
    border: none;
    box-shadow: 3px 0px 12px rgba(0, 0, 0, 0.49);
    -webkit-appearance: none;
    font-family: 'Source Sans Pro', sans-serif;
    background: #fff;
}

.header h2 {
    font-size: 52px;
    color: #fff ;
    font-family: 'Josefin Slab', sans-serif;
    font-weight: 700;
    text-transform: capitalize;
    letter-spacing: 2px;
    text-shadow: 2px 2px 3px #212121;
	
}
	</style>

</head>
<!--<body style="background:url(images/blur.jpg);  background-repeat: no-repeat;
    background-size:100%;">-->
<body style=" ">
<div class="container" style="">
<div class="header" style="background:">

			<h2 align="left" style="margin-left:20px; margin-top:10px;">
				<a href="index.php" style="color:#FFFFFF">
					<span style="color:#06d56c">L</span>aabh</a>
			</h2>
			
		</div>
</div>
	<h1 style="color:#fff; margin-top:-5px ">Registration </h1><br>
	<div class="w3ls-login box box--big" style="margin-top:-80px; padding:10px; background: ">
		<!-- form starts here -->
		<form  method="post" enctype="multipart/form-data" style="background:#fff">
		
			<!--<img src="images/icon.png" style="height:90px; width:90px;" alt="" />-->
			<table class="table">
			<tr>
			<td><div class="agile-field-txt">
				<label>
					<i class="fa fa-user" aria-hidden="true"></i> Name</label>
				<input type="text" name="name" id="name"  required="" />
			</div></td>
			<td><div class="agile-field-txt">
				<label>
					<i class="fa fa-phone" aria-hidden="true"></i> Phone</label>
				<input type="text" name="phone"  id="phone" required="" />
			</div></td>
			</tr>
			<tr>
			<td><div class="agile-field-txt">
				<label>
					<i class="fa fa-address-card" aria-hidden="true"></i> Address</label>
				<input type="text" name="address" id="address"  required="" />
			</div></td>
			<td><div class="agile-field-txt">
				<label>
					<i class="fa fa-home" aria-hidden="true"></i> Org Name</label>
				<input type="text" name="org" id="org" required="" />
			</div></td>
			</tr>
			<tr>
			<td><div class="agile-field-txt">
				<label>
					<i class="fa fa-list" aria-hidden="true"></i> GSTIN</label>
				<input type="text" name="gstin" id="gstin"  required="" />
			</div></td>
			<td><div class="agile-field-txt">
				<label>
					<i class="fa fa-file" aria-hidden="true"></i> State</label>
				<select name="state" id="state"  class="select" required="" >
				<option value="">-State-</option>
				<?php 
							$sqlc="select * from tbl_state";
							//echo $sqlc;
							$c=mysql_query($sqlc);
							if(mysql_num_rows($c)>0){
							while($cs=mysql_fetch_array($c))
							{?>
        <option value="<?=$cs["id"];?>" >
        <?=$cs["name"];?>
        </option>
        <?php }}?>
				
				</select>
				
			</div></td>
			</tr>
			<tr>
			<td><div class="agile-field-txt">
				<label>
					<i class="fa fa-home" aria-hidden="true"></i> City</label>
				<input type="text" name="city" id="city" required="" />
			</div></td>
			<td><div class="agile-field-txt">
				<label>
					<i class="fa fa-home" aria-hidden="true"></i> Pin</label>
				<input type="text" name="pin" id="pin"  required="" />
			</div></td>
			</tr>
			</table>
			
			<div class="agile-field-txt" style="">
				<label>
					<i class="fa fa-user" aria-hidden="true"></i> Username</label>
				<input type="text" name="uname" id="uname" onBlur="chk()"  placeholder=" " required="" />
				<p align="left" id="u_exist" style="color:#FF0000; display:none;">User name already exist...</p>
			</div>
			<div class="agile-field-txt">
				<label>
					<i class="fa fa-lock" aria-hidden="true"></i> password</label>
				<input type="password" name="pwd" id="pwd"  required="" id="myInput"  />
			
			</div>
			<div class="agile-field-txt" style=" margin-top:5px;">
				<label>
					<i class="fa fa-file-photo-o" aria-hidden="true"></i> Logo</label>
				<input type="file"  name="logo" id="logo" required="" />
				<div class="agile-right">
					
					<a href="login.php" >Login Here..</a>
				</div>
			</div>
			<!-- script for show password -->
			<script>
				function myFunction() {
					var x = document.getElementById("myInput");
					if (x.type === "password") {
						x.type = "text";
					} else {
						x.type = "password";
					}
				}
			</script>
			<!-- //end script -->
			<div class="w3ls-bot">
				<div class="switch-agileits">
					
					
				</div>
				<input type="submit" name="Save" value="Register">
			</div>
		</form>
	</div>
	<!-- //form ends here -->
	<!--copyright-->
	<div class="copy-wthree">
		
		
	</div>
	 <script src="js/lib/jquery/jquery.min.js"></script>
	<script>
	function chk(){
	$('#u_exist').hide();
	var uname = $('#uname').val();
	
			$.ajax({
		type: "POST",
		url: "check_user.php",
		data: "uname="+uname+"&type=reg",
		 dataType: 'json', 
		cache: false,
		success: function(data)
			{
				var emailid = data[0];
				
				if(emailid == uname){
				$('#uname').focus();
				$('#uname').val('');
				$('#u_exist').show();
				}
				
				
				
				
			}
			});
   
			
			
	}
	</script>
	<script type="text/javascript">
$(document).ready(function () {

    //Disable full page
    $("body").on("contextmenu",function(e){
        return false;
    });
    
    
});
</script>

	<!--//copyright-->
</body>
</html>
