<?php
ob_start();
$user_post=$_SESSION['post'];
$sql=mysql_query("SELECT * FROM `tbl_admin` WHERE id='$userid'");
$rows=mysql_fetch_array($sql);
$oldpass = $rows['password'];
 if(isset($_REQUEST['sub']))
 {
   $new= $_REQUEST['new'];
   $con=$_REQUEST['con'];   
	if($_REQUEST['old']==$oldpass)
	{
		if($new!=$con)
		{
			$_SESSION['match']= "Does Not Match";
		}
		else
		{
			mysql_query("update `tbl_admin` set password='$new'");
			$_SESSION['sucs']="Password Changed Successfully";
		}
	}
	else
	{
		$_SESSION['old_msg']="Wrong Password";
	}
	//header("location:home.php?page=my_profile");
 }
                 ?>
<script type="text/javascript"> 
	    $(".passw").on("keydown", function (e) {
			return e.which !== 32;
		});
</script>
<div class="row-fluid">
    <div class="span6">                    
        <div class="block-fluid ucard clearfix">
                
                <div class="info">                                                                
                    <ul class="rows">
                        <li class="heading">Change Password</li>
                        
                               <form  method="post">                               
                        <li>
                            <div class="title" style="color:#000;">Old Password:&nbsp;&nbsp;&nbsp;</div>
                            <div class="text"><input type="password" name="old"  required/>  <?php if(isset($_SESSION['old_msg'])){ ?><p style="color:#F00; font-size:16px;"><?php echo $_SESSION['old_msg']; unset($_SESSION['old_msg']);?></p><?php } ?></div>
                            
                        </li>
                        <li>
                            <div class="title" style="color:#000;">New Password:&nbsp;&nbsp;</div>
                            <div class="text"><input type="password" name="new" required pattern="[a-zA-Z0-9]+" title="Space not allowed"/> <?php if(isset($_SESSION['match'])){ ?><p style="color:#F00; font-size:16px;"><?php echo $_SESSION['match']; unset($_SESSION['match']);?></p><?php } ?></div>
                           
                        </li>
                        <li>
                            <div class="title" style="color:#000;">Confirm Password:&nbsp;&nbsp;&nbsp;</div>
                            <div class="text"><input type="password" name="con" required pattern="[a-zA-Z0-9]+" title="Space not allowed"/> <?php if(isset($_SESSION['sucs'])){ ?><p style="color:#0F6; font-size:16px;"><?php echo $_SESSION['sucs']; unset($_SESSION['sucs']);?></p><?php } ?></div>
                            
                        </li>
                        <li>
                            <div class="text"><input type="submit" name="sub" class="btn btn-block" value="Change Password"  style="width: 50%; height: 100%;"/></div>
                        </li>
                       </form>
                    </ul>                                                      
                </div>                        
        </div>
    </div>                                
    <div class="span6">        
        <div class="head clearfix">
            <div class="isw-favorite"></div>
            <h1>Recent activity</h1>
        </div>                
        <div class="block-fluid scrollBox withList">
            <div class="scroll" style="height: 200px;">
                <ul class="list">
                <?php 
                    $sql = mysql_query("select * from `user_login_detail` where uid = '".$_SESSION['userid']."' order by id desc");
                    while($data = mysql_fetch_array($sql))
                    {
                 ?>
                 <li> <?php echo $rows['name']; ?>, Logged in at <?php echo date('d-m-Y h:i:s A',strtotime($data['last_login'])); ?> &nbsp;&nbsp;Last Ip Used: <?php echo $data['ip']; ?></li>
               <?php } ?>
                </ul>    
            </div>
        </div>
    </div>                 
</div>