<?php
	include('lock.php');
	
	if(isset($_POST['usergetadd']))
	{
	
	$user_name=$_POST['user_name'];
	$user_email=$_POST['user_email'];
	$user_password=md5($_POST['user_password']);
	$user_mobile=$_POST['user_mobile'];
	$user_department=$_POST['user_department'];
	$user_type=$_POST['user_type'];
	
	 $cdate=date('Y-m-d H:i:s');
	 $cby=$_SESSION['user_id'];
	 
	 //////// IMAGE UPLOAD SECTION 
	$user_photo = $_FILES["user_photo"]["name"];
	if($user_photo)
	{
	$randomno	=  rand(9999, 999999);
	$target_dir = "./task-image/";
	$categoryimg =$randomno.'-'.$user_photo;
	$target_categoryimg = $target_dir . basename($categoryimg);

	if(move_uploaded_file($_FILES["user_photo"]["tmp_name"], $target_categoryimg)){
    $categoryimgdata=$categoryimg;
	}
	else
	{
	$categoryimgdata='1.png';
	}	
	}
	else{
    $categoryimgdata=$_POST['user_photo_old'];	
	}
	 
	 
	
	@$usergetid=$_POST['usergetid'];
	if($usergetid > 0)
	{
		if($_POST['user_password']!='')
		{
		 $sql2 ="UPDATE `user_master` SET `user_name`='$user_name',`user_email`='$user_email',`user_mobile`='$user_mobile', `user_password`='$user_password',
		 `user_department`='$user_department',`user_changetime`='$cdate',`user_type`='$user_type',`user_photo`='$categoryimgdata' WHERE user_id='$usergetid'";	
	     mysqli_query($con, $sql2);	
		}
		else{
			$sql ="UPDATE `user_master` SET `user_name`='$user_name',`user_email`='$user_email',`user_mobile`='$user_mobile', 
			`user_department`='$user_department',`user_changetime`='$cdate',`user_type`='$user_type',`user_photo`='$categoryimgdata' WHERE user_id='$usergetid'";	
	       mysqli_query($con, $sql);
		}
	
	}
	else
	{
	$insertsql ="INSERT INTO `user_master`(`user_name`, `user_email`, `user_mobile`, `user_password`,`user_department`, `user_createtime`,`user_type`,`user_photo`) 
	VALUES ('$user_name','$user_email','$user_mobile', '$user_password','$user_department','$cdate','$user_type','$categoryimgdata')";
    $insertres = mysqli_query($con, $insertsql);	
	}
    
	
	
	}
	echo '<script> window.location="user-list"; </script>';
?>