<?php
require_once("header.php");
require_once("menu.php");
//error_reporting(0);


    $id = $_SESSION['user_id'];
	$role = $_SESSION['role_id'];
    $ex = $obj->fetch_user($id,$role);
    $row = mysqli_fetch_array($ex);

if(isset($_POST['update']))
{   
    $user_info['user_id'] = $_POST['user_id'];
    $user_info['user_name'] = $_POST['user_name'];
    $user_info['email_id'] = $_POST['email_id'];
	$user_info['contact_no'] = $_POST['contact_no'];
	$user_info['address'] = $_POST['address']; 
	$server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $upload_dir = '../uploads/profile/';
        
        if(!empty($_FILES['profile']))
        {            
            $tempname = $_FILES['profile']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['profile']['name'];
            move_uploaded_file($tempname,$upload_name);
            $user_info['profile'] = $server_url."/".$upload_name;
        }
   
    $ex = $obj->update_profile($user_info);
    echo '<script>window.location="profile.php"</script>';
}

?>

<div id="layoutSidenav_content">
<main class="mt-4">
    <div class="container-fluid">
        
        <div class="card mb-4">
            <div class="card-header">
                <i class="fas fa-check-square mr-1"></i>Add User Details
               
            </div>
            <div class="card-body">
                <form method="post" name="frm" id="frm" enctype="multipart/form-data">
                   <input type="hidden" name="user_id" value="<?php echo $id;?>">
                    
                    
					
					<div class="form-group">
                        <label>Name</label>
                        <input type="text" class="form-control" name="user_name" required value="<?php echo $row['user_name'];?>">
                    </div>
					<div class="form-group">
                        <label>Email</label>
                        <input type="text" class="form-control" name="email_id" required value="<?php echo $row['email_id'];?>">
                    </div>
					<div class="form-group">
                        <label>Contact No</label>
                        <input type="text" class="form-control" name="contact_no" required value="<?php echo $row['contact_no'];?>">
                    </div>
					
					<div class="form-group">
                        <label>Address</label>
                        <textarea id="w3review" name="address" rows="4" cols="50" class="form-control"><?php echo $row['address'];?>
                  </textarea>
				  </div>
					
					<div class="form-group">
                        <label>Profile Pic</label><br>
                       <input type="file" class="" name="profile" value="<?php echo $row['profile'];?>">
                     </div>
					 
                        <button type="submit" class="btn btn-primary" name="update">Update</button>
                   
                </form> 
            </div>
        </div>
    </div>
</main>



<?php require_once("footer.php");?>

