<?php  
// $mainTitleForAdmin = 'Administrators';
// if($this->admin_model->login_type == 'Admin'){
// 	$mainTitleForAdmin = 'Sub Administrators';
	
// }else if($this->admin_model->login_type == 'SubAdmin'){
// 	$mainTitleForAdmin = 'Users';
// }

$mainTitleForAdmin ="Profile";

$pageTitle = 'My Account'; 
$adminRow = $this->admin_model->getAdminRow($this->admin_model->login_id); 
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">

<title><?php echo $pageTitle; ?> - ACP - <?php echo site_name(); ?></title>

<?php $this->load->view('admin/ap_top'); ?>


<script type="text/javascript">
    $(document).ready(function(){
	  $(document).on('change', "#changeUserPassword", function() {
	 	if($(this).is(':checked') == true){
			$('.changePass').show();	
		}else {
			$('.changePass').hide();	
		}
	});
	 
}); 
 
    function validateAccountForm(){
	clrErr();
	$errStaus = false; 
   	if(validateFormFields('name','Please enter the name.',''))$errStaus=true;
	if(validateFormFields('username','Please enter the username.','validUsername'))$errStaus=true;
	if(validateFormFields('email','Please enter the E-mail.','validEmail'))$errStaus=true;
 	if($('#changeUserPassword').length && $('#changeUserPassword').is(':checked') ){
		if(validateFormFields('password','Please enter the password.',''))$errStaus=true;
		if(validateFormFields('password2','Please enter confirm the password.',''))$errStaus=true;
		if(($('#password').val() != "" && $('#password2').val() != "") && ($('#password').val() !=  $('#password2').val()) ){
			setMsg('password2','Password mismatching! Please try again.');$errStaus=true;
		}
 	 }
	 if($errStaus == false){
 		var userEmail = $('#email').val(); 
		var username = $('#username').val(); 
		var user_id = '<?php echo $this->admin_model->login_id ?>'; 
		var baseURL = "<?php echo base_url('admin/ajax/isExistsData'); ?>";
		$.ajax({
				url:baseURL, 
				async: false,
				 type: 'POST',
				 cache: false,
					data: 'userEmail='+userEmail+'&user_id='+user_id+'&username='+username,
				success:function (resdata) {
					var resObj = jQuery.parseJSON( resdata );
					if(resObj.email == 'exist') {setMsg('email','Email already being used!');$errStaus=true;}
					 if(resObj.username == 'exist') {setMsg('username','Username already being used!');$errStaus=true;}
 				}
			});
	}
	//return false;	
  	if($errStaus == false){
		return true;
	}else{
		return false;	
	}
 }
</script>

</head>
<body>
    
     <div class="wrapper" >
            
        <?php $this->load->view('admin/navbar'); ?>
            
		<div class="main-panel" style="background-color: #DEE2E6;height: auto;">
		    <div class="content">
				<div class="page-inner">
					<div class="page-header">
						<h4 class="page-title"><?php echo $mainTitleForAdmin ; ?></h4>
						<ul class="breadcrumbs">
							<li class="nav-home">
								<a href="<?php echo base_url('admin/dashboard');?>">
									<i class="flaticon-home"></i>
								</a>
							</li>
							<!--<li class="separator">-->
							<!--	<i class="flaticon-right-arrow"></i>-->
							<!--</li>-->
							<!--<li class="nav-item">-->
							<!--	<a href="<?php //echo base_url('admin/admin_accounts/my_account');?>"><?php //echo $mainTitleForAdmin; ?></a>-->
							<!--</li>-->
							<li class="separator">
								<i class="flaticon-right-arrow"></i>
							</li>
							<li class="nav-item">
								<a href="#"><?php echo $pageTitle; ?></a>
							</li>
						</ul>
					</div>
					<div class="row">
						<div class="col-md-12">
							<div class="card">
							    
								<div class="card-header">
									<h4 class="card-title">Update Profile</h4>
								</div>
								
								<!--notifiactions-->
    							<div class="container" id="">
                                    <?php 
                             		$errMsg = validation_errors('* ');
                            		if(empty($errMsg)){ $errMsg = $this->session->flashdata('errMsg');  }
                            		$warningMsg = $this->session->flashdata('warningMsg');
                            		$successMsg = $this->session->flashdata('successMsg');
                            		if(isset($errMsg) && !empty($errMsg)){ echo showMessage($errMsg,'error'); }  
                            		if(isset($warningMsg) && !empty($warningMsg)){ echo showMessage($warningMsg,'warning'); }
                            		if(isset($successMsg) && !empty($successMsg)){ echo showMessage($successMsg,'success'); }
                            	?>
                                </div>
								
								<div class="card-body">
								    
								    <!--<form action="<?php //echo $_SERVER['REQUEST_URI']?>" method="POST" enctype="multipart/form-data">-->
							        <?php echo form_open_multipart( 'admin/admin_accounts/my_account',array('name' => 'accAgrmtFrm', 'id' => 'accAgrmtFrm','onSubmit' => 'return validateAccountForm()'));?>
										        
    										    <div class="form-group form-inline" id="div_name">
    												<label for="inlineinput" class="col-md-2 col-form-label"> Name <span style="color:red;">&nbsp;*</span></label>
    												<div class="col-md-6 p-0" >
    												    <?php   $data = array('name' => 'name','value' => set_value('name',isset($adminRow->accountFirstname)?$adminRow->accountFirstname:$this->input->post('name')),
    												            'id' => 'name', 'placeholder'=>'Enter your name here', 'class'=>'form-control input-full required');
                                      						 echo form_input($data);
                                    					?>
    													<p class="text-danger err_msg" id="err_name"></p>
    												</div>
    											</div>
    											
    											<div class="form-group form-inline" id="div_username">
    												<label for="inlineinput" class="col-md-2 col-form-label"> Username <span style="color:red;">&nbsp;*</span></label>
    												<div class="col-md-6 p-0">
    												    <?php   $data = array('name' => 'username', 'value'=>set_value('username',isset($adminRow->accountUsername)?$adminRow->accountUsername:$this->input->post('username')),
    												            'id' => 'username', 'placeholder'=>'Enter your username here', 'class'=>'form-control input-full required');
                                      						 echo form_input($data);
                                    					?>
														<p class="text-danger err_msg" id="err_username"></p>
    												</div>
    											</div>
    											
    											<div class="form-group form-inline" id="div_email">
    												<label for="inlineinput" class="col-md-2 col-form-label">Email Address <span style="color:red;">&nbsp;*</span></label>
    												<div class="col-md-6 p-0">
    												    <?php   $data = array( 'name' => 'email','value' => set_value('email',isset($adminRow->accountEmail)?$adminRow->accountEmail:$this->input->post('email')),
    												            'id' => 'email',  'placeholder'=> 'Enter your Email here', 'class' => 'form-control input-full required');
                                     						 echo form_input($data);
                                    					?>
    													<p class="text-danger err_msg" id="err_email"></p>
    												</div>
    											</div>
    											
    											<!--<div class="form-group form-inline">-->
    											<!--	<label for="inlineinput" class="col-md-2 col-form-label">Profile Image</label>-->
    											<!--	<div class="col-md-6 p-0">-->
    											<!--		<input type="file" class="form-control input-full"  name="profile_image" >-->
    											<!--	</div>-->
    											<!--</div>-->
    											
    											<div class="form-check form-inline">
    												<label class="form-check-label col-md-2" for="changeUserPassword">
    												    <?php
                                    		                $changePass = array( 'name' => 'changeUserPassword', 'id' => 'changeUserPassword',  'value' => '1' , 'class'=> 'form-check-input' );  
                                         					echo form_checkbox($changePass);	
                                     					?>
    													<span class="form-check-sign"> Change Password </span>
    													<p class="text-danger err_msg" id="err_changeUserPassword"></p>
    												</label>
    											</div>
        											
    											<div class="form-group form-inline changePass" style="display:none" id="div_password">
    												<label for="inlineinput" class="col-md-2 col-form-label">Password</label>
    												<div class="col-md-6 p-0">
    												     <?php   
    												        $data = array( 'name' => 'password',  'id' => 'password',  'placeholder' => 'Enter your Password here',
    												        'class' => 'form-control input-full required', 'maxlength' => '20' ,'minlength' => '6');
                                     						 echo form_password($data);
                                 						 ?>
    													<p class="text-danger err_msg" id="err_password"></p>
    												</div>
    											</div>
    											
    											<div class="form-group form-inline changePass" style="display:none" id="div_password2">
    												<label for="inlineinput" class="col-md-2 col-form-label">Confirm Password</label>
    												<div class="col-md-6 p-0">
												        <?php   
												            $data = array( 'name' => 'password2',  'id' => 'password2',  'placeholder' => 'Enter your Confirm Password here',
												            'class' => 'form-control input-full required', 'maxlength' => '20','minlength' => '6');
                                 						    echo form_password($data);
                             						    ?>
    													<p class="text-danger err_msg" id="err_password2"></p>
    												</div>
    											</div>
    											
    											<br>
    											
    											<div class="form-group form-inline">
        												<label for="inlineinput" class="col-md-2 col-form-label "></label>
        												<div class="col-md-6 p-0">
        												    <?php   $data = array( 'name' => 'myAccountBtn','value' => 'true', 'id' => 'myAccountBtn',  
        												            'type' => 'submit','content' => 'Submit', 'class' => 'btn btn-success',  );
        												            
                                                 				echo form_button($data);
                                                 				
                                                				//         $data = array( 'name' => 'resetBtn','value' => 'true', 'id' => 'resetBtn',
                                                				//         'type' => 'reset','content' => 'Cancel', 'class' => 'btn btn-warning', 'onclick' => 'window.location.href=document.referrer'   );
                                                				
                                                				// echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                                                				
                                                 			// 	echo form_button($data) ;     
                                                 				?>
        												</div>
        											</div>
    									    
								        <?php echo form_close();?>
									    <!--</form> -->
								</div>
							</div>
						</div>
					</div>
					
				</div>
			</div>
			
		    <!--<footer class="footer">-->
			    <?php //footer();?>
			<!--</footer>-->
			
		</div>
	</div>
	
</body>
</html>