<?php 
include("../config.php");
if(!empty($_POST)){
	$name       		 = mysqli_real_escape_string($conn, $_POST['name']);
	$mobile       		 = mysqli_real_escape_string($conn, $_POST['mobile']);
	$username       	 = mysqli_real_escape_string($conn, $_POST['username']);
	$email       		 = mysqli_real_escape_string($conn, $_POST['email']);
	$updated_datetime    = date('Y-m-d H:i:s');
	$updated_id          = $_SESSION['user_detail']['id'];

	if($_POST["id"] != ''){
  	 	$type               = 'profile_update';
		$user_id            = $_SESSION['user_detail']['id'];
		$data               = serialize($_POST);
  	 	$insert = "UPDATE `users` SET `name`='".$name."',`email`='".$email."',`mobile`='".$mobile."',`username`='".$username."',`updated_id`='".$updated_id."',`updated_datetime`='".$updated_datetime."' WHERE id = '".$_POST['id']."'";
  	 	$result = mysqli_query($conn,$insert) or die( mysqli_error($conn) );
  	 	
		$activiti = "INSERT INTO `activities`(`type`, `user_id`, `data`, `created_id`, `created_datetime`, `updated_id`, `updated_datetime`) VALUES ('".$type."','".$user_id."','".$data."','".$created_id."','".$created_datetime."','".$updated_id."','".$updated_datetime."')";
    	$acttivity_res = mysqli_query($conn,$activiti);

    }
  echo json_encode( array('response' => 1, 'msg' => 'PROFILE UPDATED....!!!', 'alert' => 1, 'redirect' => 'index.php?page=dashboard.php') );die();
}else{
  echo json_encode( array('response' => 2, 'msg' => 'Opps', 'alert' => 1, 'redirect' => 'index.php?page=user_management/user-profile.php') );die();
} 