<?php 
include "includes/header.php"; 
include "includes/Mdme-functions.php";
include "common/dpselect-functions.php";
?>  



<div class="wrapper">
    <div class="container">
        <!-- Page-Title - START -->
        <div class="row">
            <div class="col-sm-12">										
                <h4 class="page-title">User Information</h4>				
            </div>
        </div>
		<!-- Page-Title - END -->	
		<form id="jvalidate" name="frmUser" role="form" class="form-horizontal" action="#" method="post" enctype="multipart/form-data" >
		<input type="hidden" name="action" value="<?php echo $act; ?>" />
		<input type="hidden" name="edit_id" id="edit_id" value="<?php echo $edit_id; ?>"  />
			<div class="card-box">
				
				<div class="row">
					
					<div class="col-sm-6">
						<div class="form-group">
							<label>First Name<span class="text-danger">*</span></label>							
							<input type="text" class="form-control jsrequired" name="txtuser_firstname" id="txtuser_firstname" value="<?php echo $res_ed['user_firstname']; ?>" />
						</div>
						
						<div class="form-group">
							<label>Last Name</label>							
							<input type="text" class="form-control" name="txtuser_lastname" id="txtuser_lastname" value="<?php echo $res_ed['user_lastname']; ?>" />
						</div>	
						
						<div class="form-group">
							<label>Email Id as Login Id<span class="text-danger">*</span></label>							
							<input type="text" class="form-control jsrequired email" name="txtuser_email" id="txtuser_email"
							<?php if ($act == 'update') { ?> readonly="readonly" <?php } ?> value="<?php echo $res_ed['user_email']; ?>" />
						</div>	
						
						<?php if($edit_id == ""){ ?>
						<div class="form-group">
							<label>Password</label>							
							<input type="password" class="form-control jsrequired password" name="txtuser_password" id="txtuser_password" value="" />
						</div>
						<?php } ?>	
						
					</div>
					
					<div class="col-sm-6">
						<div class="form-group">
							<label for="userName">Role<span class="text-danger">*</span></label>							
							<?php 
							echo getSelectBox_rolelist($db,'txtRoleId','jsrequired',$res_ed['RoleId']);
							?>
						</div>
						<div class="form-group">
							<label>Photo</label>							
							
							<?php 
							if (!empty($res_ed['user_photo']) && ($act == 'update')) { 
								if(file_exists(CAAROOTADMIN_DIR."/uploads/adminusers/".$res_ed['user_photo']))
								{ ?>
									<img id="preview_img" src="uploads/adminusers/<?php echo $res_ed['user_photo']; ?>" width="50px" align="absmiddle"/>
								<?php
								}
								else{ ?>
									<img id="preview_img" src="uploads/NoImageAvailable.png" width="50px" align="absmiddle"/>
								<?php }
								} 
							?>					
												  
							<input id="user_photo" name="user_photo" type="file" class="file form-control" data-show-upload="false" data-show-caption="true" accept="image/jpeg,image/png,jpg|png" /> Allowed Extension ( jpg, png, gif )
							
						</div>
						
						<div class="form-group">
							<label>Status</label>							
							<input type="checkbox" id="chkstatus" name="chkstatus" class="form-control" <?php echo $chk; ?> />
						</div>
						
					</div>
					
				</div>
				
				<div class="row">
					<div class="col-sm-8">
						
					</div>
					
					<div class="col-sm-4">
						
						<div class="form-group">
							<div class="btn-group pull-right m-t-15">
							
							<button class="btn btn-primary waves-effect waves-light" type="button" onClick="javascript:funSubmtWithImg('frmUser','userinfo_actions.php','jvalidate','user','userinfo_mng.php');" >Submit</button>	
											 
							<button class="btn btn-secondary waves-effect m-l-5" type="button" onClick="javascript:funCancel('frmUser','jvalidate','user','userinfo_mng.php');" >Cancel</button>							
								
							
							</div>
							
							
						</div>
						
					</div>
				
					
					
				</div>
				
				
			</div>
		</form>
							

<!-- Change Password Modal - START -->
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">Change Password</h4>
				</div>
				
				<div class="modal-body">  
					<div class="form-group row">
						<label class="col-md-3 col-xs-12 control-label">Password</label>
						<div class="col-md-6 col-xs-12">                                            
							<div class="input-group">
								<input type="password" class="form-control " name="newpwd" id="newpwd" value=""/>
							</div>                                            
						</div>
					</div>			
					
					<div class="form-group row">
						<label class="col-md-3 col-xs-12 control-label">Confirm Password</label>
						<div class="col-md-6 col-xs-12">                                            
							<div class="input-group">
								<input type="password" class="form-control " name="newcnfrmpwd" id="newcnfrmpwd" value=""/>
							</div>                                            
						</div>
					</div>
							
				</div>
				
				<div class="modal-footer">
					<!--<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>-->
					<button type="button" class="btn btn-primary" onclick="pwdchange();">Update Password</button>
				</div>
				
			</div>
		</div>
	</div>

 <!-- Change Password Modal - END -->		

<?php include "includes/footer.php";  ?> 
	</div> <!-- container -->
</div> <!-- End wrapper -->

<?php include "includes/footer_script.php";  ?> 


<script type="text/javascript"> 

$("document").ready(function(){

    $("#user_photo").change(function() {
        $("#preview_img").css("display","none");
    });
});


function pwdchange(){	  
	if($('#newpwd').val() == '' || $('#newcnfrmpwd').val() == ''){
		 alert('Please Enter password and Confirm Password Details');
	}	
	else if($('#newpwd').val()!=$('#newcnfrmpwd').val()){
		 alert('Password not matches');
	}
	else{
		var user_id = $('#edit_id').val(); 
		var user_email = $('#txtuser_email').val(); 		
		var new_pwd = $('#newpwd').val();
		$.ajax({
			url: 'userinfo_pwdchange.php',
			type: 'POST',
			data: 'user_id='+user_id+'&user_email='+user_email+'&new_pwd='+new_pwd+'',
			success: function(result) {	 														
					if(result =='success'){	
						alert("Password has been changed successfully");						
						$('#myModal').modal('hide');						
		 		    }						
					else {
                        alert(result);	
					}   
			}
		}); 				
	}
 }

</script>



</body>
</html>
	  