<?php
 	session_start(); 

	if(!isset($_SESSION['linkarisecrm']))
	{
		header('Location: index.php');
		return;
	}
	include("connect.php");
	
		date_default_timezone_set("Asia/Singapore");
				$mdate1= date('Y-m-d H:i:s');
				$mdate= date('d-m-Y');
	
	$cmpmid=$_SESSION['linkarisecmpmid'];
	$umid=$_SESSION['linkariseumid'];
	$username=$_POST['username'];
	$userstatus="Active";
	$usermobile=$_POST['usermobile'];
	
	
	$usersecurepasword=md5($_POST['userpassword']);
	$userloginid=$_POST['userloginid'];
	$ugroup="";

	$eve = "select * from res_user_master where usermobile='$usermobile'";
	$re = mysqli_query($conn, $eve);
	if(mysqli_num_rows($re) > 0)
	{
		$_SESSION['msg1'] = "Try Diffrent Mobile Number";
		header('Location: useradd.php');
		return;
	}
	else
	{	
		
			
			 $eve1 = "INSERT INTO res_user_master (companymid,username,userdesignation,usermobile,userloginid,usersecurepasword,userstatus,addedby,addedon,updatedby,updatedon) VALUES('$cmpmid','$username','User','$usermobile','$userloginid','$usersecurepasword','$userstatus','$umid','$mdate1','0','$mdate1')";
				if ($conn->query($eve1) === TRUE)
				{
					$last_id = $conn->insert_id;
		
		
				
				
				
			
				$_SESSION['msg'] = "user successfully added.";
			
				}
				else{
					$_SESSION['msg1'] = "Error";

				}
				
			
	
	}
	
	header('Location: user.php');
	return;
?>