<script type="text/javascript">
$(document).ready(function(){
	$("#frm-user").submit(function(e){
            if(!validate_user()){
                e.preventDefault();
            }
	});
        $("#user_email_address").blur(function(){
            var email = $("#user_email_address");
            var emailmsg = $("#msg_user_email_address");
            if(email.val()==""){
                email.addClass('error');email.focus();emailmsg.html('Please enter email address').show();
                return false;
            }
            if($("#user_id").length > 0){var user_id = $("#user_id").val();
            }else{var user_id = '';}
            $("#submit").prop('disabled', true);
            $.ajax({
                url: "useradd.php",
                data: 'act=validate_email&email='+email.val()+'&user_id='+user_id,
                method: 'POST',
                success: function(msg){
                    if(msg!=''){
                        email.addClass('error');email.focus();emailmsg.html(msg).show();
                        return false;
                    }else{
                        $("#submit").prop('disabled', false);
                        email.removeClass('error');emailmsg.hide();
                    }
                }
            });
	});
	
});
function validate_user(){
	var fname = $("#user_fname");var fnamemsg = $("#msg_user_fname");
	var lname = $("#user_lname");var lnamemsg = $("#msg_user_lname");
	var email = $("#user_email_address");var emailmsg = $("#msg_user_email_address");
	var phone = $("#user_phone");var phonemsg = $("#msg_user_phone");
	var emailFilter=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,4}))$/;
        if(fname.val()==''){fname.addClass('error');fname.focus();fnamemsg.html('Please enter first name').show();
            return false;
	}else{fname.removeClass('error');fnamemsg.hide();}
        if(lname.val()==''){lname.addClass('error');lname.focus();lnamemsg.html('Please enter last name').show();return false;
	}else{lname.removeClass('error');lnamemsg.hide();}
        if(email.val()==''){
          email.addClass('error');email.focus();emailmsg.html('Please enter email address').show();return false;
	}else if(email.val()!='' && !(emailFilter.test(email.val())) ){
	    email.addClass('error');email.focus();emailmsg.html('Please enter valid email address').show();return false;
	}
        if(phone.val()==''){phone.addClass('error');phone.focus();phonemsg.html('Please enter phone number').show();return false;
        }else{phone.removeClass('error');phonemsg.hide();}
       return true;
}

</script>
<div class="breadcrumb">
    <h1>Clinic Users</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>Add New Clinic User</li>
    </ul>
</div>
<div class="separator-breadcrumb border-top"></div>
<div class="row">
    <div class="col-md-12">
        <div class="card mb-4">
            <div class="card-body">
                <div class="card-title mb-3">Add New Clinic User</div>
                <form action="" id='frm-user' method="post" enctype="multipart/form-data">
                    <?php if(isset($userDetail->user_id) && $userDetail->user_id!=0) { ?>
                       <input type="hidden" id="user_id" name="user_id" value="<?php echo $userDetail->user_id ?>" />
                    <?php } ?>
                    <div class="row">
                    	<div class="col-md-6 form-group mb-3">
                            <label for="user_fname">First name <span class="asterisk">*</span></label>
                            <input type="text" class="form-control" id="user_fname" name="user_fname" value="<?php echo $userDetail->user_fname; ?>" placeholder="Enter first name">
                            <div class="invalid-tooltip" id="msg_user_fname"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="user_lname">Last name <span class="asterisk">*</span></label>
                            <input type="text" class="form-control" id="user_lname" name="user_lname" value="<?php echo $userDetail->user_lname; ?>" placeholder="Enter last name">
                            <div class="invalid-tooltip" id="msg_user_lname"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="user_email_address">Email address <span class="asterisk">*</span></label>
                            <input type="text" class="form-control" id="user_email_address" name="user_email_address" value="<?php echo $userDetail->user_email_address; ?>" placeholder="Enter email address">
                            <div class="invalid-tooltip" id="msg_user_email_address"></div>
                        </div>
                        <?php if(!isset($userDetail->useradmin_password) || $userDetail->useradmin_password==''){ ?>

                       <div class="col-md-6 form-group mb-3">
                            <label for="user_password">Password <span class="asterisk">*</span></label>
                            <input type="password" class="form-control" id="user_password" name="user_password" placeholder="Enter your password">
                            <div class="invalid-tooltip" id="msg_user_password"></div>
                        </div>

                       <div class="col-md-6 form-group mb-3">
                            <label for="user_repassword">Retype Password <span class="asterisk">*</span></label>
                            <input type="password" class="form-control" id="user_repassword" name="user_repassword" placeholder="Enter your password again">
                            <div class="invalid-tooltip" id="msg_user_repassword"></div>
                        </div>

                        <?php } ?>
                        <div class="col-md-2 form-group mb-3">
                            <label class="control-label">Owner</label>
                            <div class="controls">

                            <label class="switch switch-primary mr-3">
                                <input type="checkbox" id="user_owner" name="user_owner" <?php echo ($userDetail->user_owner=='1') ? "checked='checked'" : "" ?>>
                                <span class="slider"></span>
                            </label>
                            </div>
                        </div>
                        <div class="col-md-2 form-group mb-3">
                            <label class="control-label">Active/Inactive</label>
                            <div class="controls">

                            <label class="switch switch-primary mr-3">
                                <input type="checkbox" id="user_status" name="user_status" <?php echo ($userDetail->user_status=='1') ? "checked='checked'" : "" ?>>
                                <span class="slider"></span>
                            </label>
                            </div>
                        </div>
                        <?php if(is_null($userDetail->user_email_verified) && $userDetail->user_email_verified==''){ ?>
                        <div class="col-md-2 form-group mb-3">
                            <label class="control-label">Verified</label>
                            <div class="controls">

                            <label class="switch switch-primary mr-3">
                                <input type="checkbox" id="user_verified" name="user_verified">
                                <span class="slider"></span>
                            </label>
                            </div>
                        </div>
                        <?php } ?>
                        <div class="col-md-6 form-group mb-3">
                            <label for="user_faxEmail">Fax email address For Mango</label>
                            <input type="text" class="form-control" id="user_faxEmail" name="user_faxEmail" value="<?php echo $userDetail->user_faxEmail; ?>" placeholder="Enter fax email">
                            <div class="invalid-tooltip" id="msg_user_faxEmail"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="user_faxPassword">Fax email password For Mango </label>
                            <input type="password" class="form-control" id="user_faxPassword" name="user_faxPassword" value="<?php echo $userDetail->user_faxPassword; ?>" placeholder="Enter fax password">
                            <div class="invalid-tooltip" id="msg_user_faxPassword"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="user_emailHost">Fax email Host For Mango </label>
                            <input type="text" class="form-control" id="user_emailHost" name="user_emailHost" value="<?php echo $userDetail->user_emailHost; ?>" placeholder="Enter fax host">
                            <div class="invalid-tooltip" id="msg_user_emailHost"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="user_mangoCallUser">Mango Call User </label>
                            <input type="text" class="form-control" id="user_mangoCallUser" name="user_mangoCallUser" value="<?php echo $userDetail->user_mangoCallUser; ?>" placeholder="Enter fax host">
                            <div class="invalid-tooltip" id="msg_user_mangoCallUser"></div>
                        </div>

                        <div class="col-md-12">
                            <input type="submit" class="btn btn-primary" id="submit" name="submit" value="Submit">
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div> 