@extends('adminlte::page')
@section('content_header')
    <h1>User</h1>
@stop
<script src="//code.jquery.com/jquery.js"></script>
@section('content')
<div class="row">
    <!--row starts-->
    <div class="col-md-12">
        <div class="panel panel-primary">
            <div class="panel-heading">
                <h3 class="panel-title">
                   User Registration
                </h3>
            </div>
            <div class="panel-body">
                <form class="form-horizontal" action="{{url('updateuserdata')}}" method="post" id="action" onsubmit="return validation();">
                    <!-- CSRF Token -->
                    <input type="hidden" name="_token" value="{{csrf_token()}}">
                    <!--Office ID Hidden value-->
                    <input type="hidden" name="user_id" value="{{$user->id}}">                            
                    <div class="form-group">
                        <label class="col-md-3 control-label" for="addr">Full Name<span style="color: red;">*</span></label>
                        <div class="col-md-6">
                            <input id="name" name="name" class="form-control" value="{{$user->name}}" maxlength="100" required>
                        </div>
                    </div>    
                    <div class="form-group">
                        <label class="col-md-3 control-label" for="remarks">Email<span style="color: red;">*</span></label>
                        <div class="col-md-6">
                            <input id="email" name="email" class="form-control" value="{{$user->email}}" maxlength="250" onchange="validateEmail(this,'Email');" required>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label" for="name"><span style="color: red;">Fill password if there is any change</span></label>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label" for="name">Old Password</label>
                        <div class="col-md-6">
                            <input id="password" name="old_password" type="old_password" maxlength="100" placeholder="Enter the new password only if there is any change" class="form-control" value=""></div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label" for="name">Password<span style="color: red;">*</span></label>
                        <div class="col-md-6">
                            <input id="password" name="new_password" type="new_password" placeholder="Enter the password only if there is any change " class="form-control" maxlength="20" onchange="password_check();">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label" for="name">Retype Password<span style="color: red;">*</span></label>
                        <div class="col-md-6">
                            <input id="password_confirmation" name="password_confirmation" type="password" placeholder="Retype password only if there is any change" class="form-control" maxlength="20" onchange="password_check();">
                        </div>
                    </div>
                    
                    <!-- Form actions -->
                    <div class="form-position">
                        <div class="col-md-12 text-right">
                             <a href="{{url('user')}}"><button type="button" class="btn btn-responsive btn-danger btn-sm">Back</button></a>
                            <button type="submit" id="btn" class="btn btn-responsive btn-warning btn-sm">Update</button>
                        </div>
                    </div>
                </form>
            </div>
        </div> 
    </div>
    <!--md-12 ends-->
</div>
<script>
    ////////////////email checking/////////////////
    function validateEmail(emailField, fieldname)
    {
        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

        if (reg.test(emailField.value) == false) 
        {
            alert("Please enter correct email ID");
            emailField.value="";
            emailField.focus();
            return false;
        }
    }
    ///////////////////////////////////////////////////////////////////
    //////password check////////////////////////////////
    function password_check()
    {
      var pwd;
      var cpwd;
      pwd = document.getElementById("new_password").value;
      cpwd = document.getElementById("password_confirmation").value;
      if(pwd && cpwd)
      {
        if(pwd!=cpwd)
        {
            alert("Password and Confirm Password should be same.")
            document.getElementById("password_confirmation").value="";
            document.getElementById("new_password").value="";
            document.getElementById("new_password").focus();
            return false;
        }
      }
      return true;
    }
    /////////////////////////////////////////////////////
    function validation()
    {
        if(document.getElementById('email').value=="")
        {
            alert(" Please Enter the Email");
            document.getElementById('email').focus();
            return false;
        }

        if(document.getElementById('name').value=="")
        {
            alert(" Please Enter the Full Name");
            document.getElementById('name').focus();
            return false;
        }     
        document.getElementById("btn").disabled='true';       
        return true;
    }
</script>		                    
@stop