<?php
include("access.php");
include("include/admin.class.php");
include("include/conf.class.php");
$userinfo=$cartCore->get_user_info($CARTUSERNAME);
$cartCore->get_headder_customer();
$cartCore->view_welcome_customer($userinfo['FULL_NAME'],$userinfo['IMAGE']);
if($COMPANY_ID=='CUSTOMER'){$cartCore->view_customer_sidebar($userinfo['USER_ID'],$TOKEN_ID);}else{$cartCore->view_sidebar($userinfo['USER_ID'],$TOKEN_ID);}
$cartCore->view_credit($COMPANY_ID);
?>


       <!-- top navigation -->
        <div class="top_nav">
          <div class="nav_menu">
            <nav>
              <div class="nav toggle">
                <a id="menu_toggle"><i class="fa fa-bars"></i></a>
              </div>

              <ul class="nav navbar-nav navbar-right">
              
              
              <?=$cartCore->view_userprofile($userinfo['USER_ID'],$userinfo['FULL_NAME'],$userinfo['IMAGE'],$TOKEN_ID,$COMPANY_ID,$bk)?>

                <li role="presentation" class="dropdown">
                  <a href="javascript:;" class="dropdown-toggle info-number" data-toggle="dropdown" aria-expanded="false">
                    <i class="fa fa-envelope-o"></i>
                    <span class="badge bg-green"><?=$cartAdminMain->getMessageCount($userinfo['USERNAME'])?></span>
                  </a>
                  <ul id="menu1" class="dropdown-menu list-unstyled msg_list" role="menu">
                  <?=$cartAdminMain->getUserMessage($userinfo['USERNAME'])?>
                    <li>
                      <div class="text-center">
                        <a href="message.php?token_id=<?=$TOKEN_ID?>&pid=<?=$cartCore->md5_base64_encode($userinfo['USERNAME'])?>">
                          <strong>See All Alerts</strong>
                          <i class="fa fa-angle-right"></i>
                        </a>
                      </div>
                    </li>
                  </ul>
                </li>
              </ul>
            </nav>
          </div>
        </div>
        <!-- /top navigation -->

        <!-- page content -->
        <div class="right_col" role="main">
          <div class="">
            <div class="page-title">
              <div class="title_left">
                <h3>User Profile</h3>
              </div>
            </div>
            
            <div class="clearfix"></div>

            <div class="row">
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>User Report <small>Activity report</small></h2>
                    <ul class="nav navbar-right panel_toolbox">
                      <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                      </li>
                    </ul>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
                    <div class="col-md-3 col-sm-3 col-xs-12 profile_left">
                      <div class="profile_img">
                        <div id="crop-avatar">
                          <!-- Current avatar -->
                          <img class="img-responsive avatar-view" src="data:image/png;base64,<?=$userinfo['IMAGE']?>" alt="Avatar" title="Change the avatar">
                        </div>
                      </div>
                      <h3><?=$userinfo['FULL_NAME']?></h3>

                      <ul class="list-unstyled user_data">
                      <?php
					  if($COMPANY_ID=='CUSTOMER')
					  {
						  $customer_info=$cartCore->fetch_customer_details_by_userid($userinfo['USER_ID']);
						  echo '<li><i class="fa fa-map-marker user-profile-icon"></i> '.$customer_info['ADDRESS'].', '.$customer_info['COUNTRY'].'</li>';
					  }
					  ?>
                      </ul>

                    </div>
                    <div class="col-md-9 col-sm-9 col-xs-12">

                      <div class="profile_title">
                        <div class="col-md-6">
                          <h2>User Activity Report</h2>
                        </div>
                        <div class="col-md-6">
                          <div class="ln_solid"></div>
                <!-- Button to trigger modal -->
<button class="btn btn-info btn-lg" data-toggle="modal" data-target="#password_reset">
   Password Reset
</button>
<button class="btn btn-info btn-lg" data-toggle="modal" data-target="#edit_profile">
   Profile Edit
</button>

<!-- Modal -->
<div class="modal fade" id="password_reset" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <!-- Modal Header -->
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">&times;</span>
                    <span class="sr-only">Close</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">Password Reset</h4>
            </div>
            
            <!-- Modal Body -->
            <div class="modal-body">
                <p class="statusMsg"></p>
                <form role="form">		
                    <div class="form-group">
                        <label for="inputEmail">Last Password</label>
                        <input type="text" class="form-control" id="inputLastPassword" placeholder="Last Password"/>
                         <input type="hidden" class="form-control" id="inputUsername" value="<?=$cartCore->md5_base64_encode($CARTUSERNAME)?>"/>
                    </div>
                    <div class="form-group">
                        <label for="inputEmail">New Password</label>
                        <input type="text" class="form-control" id="inputNewPassword" placeholder="Desire Password"/>
                    </div>
                </form>
            </div>
            
            <!-- Modal Footer -->
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary submitBtn" onclick="submitResetForm()">SUBMIT</button>
            </div>
        </div>
    </div>
</div>
<?php
if($COMPANY_ID=='CUSTOMER')
{
?>
<!-- Modal -->
<div class="modal fade" id="edit_profile" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <!-- Modal Header -->
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">&times;</span>
                    <span class="sr-only">Close</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">Profile Details</h4>
            </div>
            
            <!-- Modal Body -->
            <div class="modal-body">
                <p class="statusMsg2"></p>
                <form role="form">
                    <div class="form-group">
                        <label for="inputEmail">Full Name</label>
                        <input type="text" class="form-control" id="inputFullname" value="<?=$customer_info['FULL_NAME']?>"/>
                        <input type="hidden" class="form-control" id="inputUserid" value="<?=$cartCore->md5_base64_encode($customer_info['USER_ID'])?>"/>
                    </div>
                    <div class="form-group">
                        <label for="inputEmail">Address</label>
                        <input type="text" class="form-control" id="inputAddress" value="<?=$customer_info['ADDRESS']?>"/>
                    </div>
                    <div class="form-group">
                        <label for="inputEmail">Country</label>
                        <select id="inputCountry" class="form-control">
                        <?=$cartAdminMain->get_country_by_selected_option($customer_info['COUNTRY'])?>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="inputEmail">Telephone</label>
                        <input type="text" class="form-control" id="inputTelephone" value="<?=$customer_info['TELEPHONE']?>"/>
                    </div>
                    <div class="form-group">
                        <label for="inputEmail">Personal Email</label>
                        <input type="email" class="form-control" id="inputEmail" value="<?=$customer_info['EMAIL']?>"/>
                    </div>
                </form>
            </div>
            
            <!-- Modal Footer -->
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary submitBtn" onclick="submitProfileForm()">SUBMIT</button>
            </div>
        </div>
    </div>
</div>
<?php } 
else
{ 
?>
<div class="modal fade" id="edit_profile" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <!-- Modal Header -->
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">&times;</span>
                    <span class="sr-only">Close</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">You cannot edit profile</h4>
            </div>
            
            <!-- Modal Body -->
            <div class="modal-body">
            </div>
            
        </div>
     </div>
</div>
<?php }

?>                        </div>
                      </div>
                     

                      <div class="" role="tabpanel" data-example-id="togglable-tabs">
                        
                        <div id="myTabContent" class="tab-content">
                          
                          
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- /page content -->

        <!-- footer content --><?=$cartCore->get_footer();?>
        <!-- /footer content -->
      </div>
    </div>

   <!-- jQuery -->
    <script src="../vendors/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="../vendors/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- FastClick -->
    <script src="../vendors/fastclick/lib/fastclick.js"></script>
    <!-- NProgress -->
    <script src="../vendors/nprogress/nprogress.js"></script>
    <!-- validator -->
    <script src="../vendors/validator/validator.js"></script>

    <!-- Custom Theme Scripts -->
    <script src="../build/js/custom.min.js"></script>
    
    <!-- Custom Scripts -->
    
     <script>
function submitResetForm(){
    var old_pass = $('#inputLastPassword').val();
	var new_pass = $('#inputNewPassword').val();
	var username = $('#inputUsername').val();
	 if(old_pass.trim() == '' ){
        alert('Please enter old password.');
        $('#inputLastPassword').focus();
        return false;
    }else if(new_pass.trim() == ''){
        alert('Please enter new password.');
        $('#iinputNewPassword').focus();
        return false;
    }else{
        $.ajax({
            type:'POST',
            url:'reset_password.php',
            data:'passwordResetSubmit=1&oldpassword='+old_pass+'&newpassword='+new_pass+'&username='+username,
            beforeSend: function () {
                $('.submitBtn').attr("disabled","disabled");
                $('.modal-body').css('opacity', '.5');
            },
            success:function(msg){
                if(msg == 'ok'){
                    $('#inputLastPassword').val('');
					$('#inputNewPassword').val('');
                    $('.statusMsg').html('<span style="color:green;">Your Password has been reset</p>');
                }else{
                    $('.statusMsg').html('<span style="color:red;">Someting wrong with your old password. Please Check</span>');
                }
                $('.submitBtn').removeAttr("disabled");
                $('.modal-body').css('opacity', '');
            }
        });
    }
}
</script>

<script>
function submitProfileForm(){
    var Fullname = $('#inputFullname').val();
	var Address = $('#inputAddress').val();
	var userid = $('#inputUserid').val();
	var Country = $('#inputCountry').val();
	var Telephone = $('#inputTelephone').val();
	var Email = $('#inputEmail').val();
	var reg = /^[A-Z0-9._%+-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i;
	
	 if(Fullname.trim() == '' ){
        alert('Please enter Full Name.');
        $('#inputFullname').focus();
        return false;
    }else if(Address.trim() == ''){
        alert('Please enter Address.');
        $('#inputAddress').focus();
        return false;
    }
	else if(userid.trim() == ''){
        alert('Please refresh the page.');
        return false;
    }
	else if(Country.trim() == ''){
        alert('Please select a Country.');
        $('#inputCountry').focus();
        return false;
    }
	else if(Telephone.trim() == ''){
        alert('Please enter telephone number.');
        $('#inputTelephone').focus();
        return false;
    }
	else if(Email.trim() == ''){
        alert('Please enter Email.');
        $('#inputEmail').focus();
        return false;
    }
	else if(Email.trim() != '' && !reg.test(Email)){
        alert('Please enter valid email.');
        $('#inputEmail').focus();
        return false;
    }
	else{
        $.ajax({
            type:'POST',
            url:'reset_password.php',
            data:'profileEditSubmit=1&FULLNAME='+Fullname+'&ADDRESS='+Address+'&USERID='+userid+'&COUNTRY='+Country+'&TELEPHONE='+Telephone+'&EMAIL='+Email,
            beforeSend: function () {
                $('.submitBtn').attr("disabled","disabled");
                $('.modal-body').css('opacity', '.5');
            },
            success:function(msg){
                if(msg == 'ok'){
                    $('.statusMsg2').html('<span style="color:green;">Your details has been updated</p>');
                }else{
                    $('.statusMsg2').html('<span style="color:red;">Someting went wrong when update profile details</span>');
                }
                $('.submitBtn').removeAttr("disabled");
                $('.modal-body').css('opacity', '');
            }
        });
    }
}
</script>

 

  </body>
</html>