<?php

if(isset($_POST['btnLogout']))
{
	session_start();
	session_destroy();
} 
include('rights.php');
include('config.php');
include('includes/_admin_top.php');

?>

<div class="flex flex-col md:flex-row">
	<?php include('includes/_admin_menus.php') ?>

	<div class="main-content flex-1 bg-gray-100 md:mt-2 pb-24 md:pb-5">
		<div class="bg-blue-800 p-2 shadow text-xl text-white">
                <div class="d-table">
                	<div class="pull-left">
                	<h3 class="font-bold pl-2">Profile Setting</h3>
                </div>
                <div class="pull-right">
                	
                </div>
                </div>
         </div>

         <div class="w-full col-md-12 p-3 " id="stickerpackstable">
         		<div class="card">
         			<div class="card-body">
         				<div class="col-sm-12">
         					<div class="form-group">
	                            <label>User Name / Login Name </label>
	                            	<input name="Publisher" id="Publisher" type="text" value="<?php echo $__username ?>" class="form-control" placeholder="StickerAdmin">
	                        </div>
	                        <div class="d-table">
	                        	<div class="pull-right">
	                        		<button class="btn btn-sm btn-success" type="button" onclick="ChangeUserName()"> <i class="fa fa-pen"></i> update </button>
	                        	</div>
	                        </div>
         				</div>
         			</div>
         		</div>
				<br>
         		<div class="card">
         			<div class="card-body">
         				<div class="col-sm-12">
         					<div class="form-group">
	                            <label>Password </label>
	                            	<input name="currentPassword" id="currentPassword" type="text"  class="form-control" placeholder="Current Password">
	                        </div>

	                        <div class="form-group">
	                            <label>New Password </label>
	                            	<input name="newPassword" id="newPassword" type="text"  class="form-control" placeholder="Current Password">
	                        </div>

	                        <div class="form-group">
	                            <label>Retype new Password </label>
	                            	<input name="renewpassword" id="renewpassword" type="text"  class="form-control" placeholder="Current Password">
	                        </div>
	                        <div class="d-table">
	                        	<div class="pull-right">
	                        		<button class="btn btn-sm btn-success" type="button" onclick="changePassword()"> <i class="fa fa-pen"></i> change Password </button>
	                        	</div>
	                        </div>
         				</div>
         			</div>
         		</div>
         </div>

	</div>
</div>
<?php  include('includes/_admin_bottom.php')?>

<script type="text/javascript">
	
	function ChangeUserName()
	{
		if($('#Publisher').val() !="")
		{
			HoldOn.open()
			$.ajax({
			    url:'apis/changeusername.php?username='+ $('#Publisher').val(),
			    method:'GET',
			    success:function(data){
			    	HoldOn.close()
			    	if(data=="success")
			    	{
			    		ShowSuccess("UserName Changed Successfully");
			    	}
			    	else
			    	{
						ShowError("Erorr ! Unable to change username");	    		
			    	}
			    },
			    error:function()
			    {
			    	ShowError("Erorr ! Unable to change username");	    		
			    }
			});
		}
		else
		{
			ShowError("UserName is required");
		}
		
	}


	function validatePassword()
	{
		if($('#currentPassword').val()=="")
		{
			ShowError("Please enter Current Password");
			return false;
		}
		if($('#newPassword').val()=="")
		{
			ShowError("Please enter new Password");
			return false;
		}
		if($('#renewpassword').val()=="")
		{
			ShowError("Please ee enter new Password");
			return false;
		}

		if(  $('#newPassword').val() != $('#renewpassword').val())
		{
			ShowError("Password nnot match");
			return false;
		}
		return true;
	}

	function changePassword()
	{
		if(validatePassword()==true)
		{
			HoldOn.open();
			$.ajax({
				url:'apis/changepassword.php?currentPassword='+  $('#currentPassword').val()+'&newPassword='+$('#newPassword').val(),
				method:'GET',
				success:function(data)
				{
					HoldOn.close();
					if(data !="success")
					{
						ShowError(data);	    		
					}
					else
					{
						ShowSuccess("password Changed Successfully");	
					}
				}
			})
		}
	}

</script>