<?php 
include ('../ro_head.php'); 
//include ('methodlist.php'); 
?>



<link rel="shortcut icon" href="favicon.ico"/>
<style type="text/css">
	h3{
		background-color: #c6deef;
		padding: 10px 0px 10px 20px;
		font-size: 18px;
	}

	.page-title {
 
    font-size: 21px;
 
    font-weight: 500;
    padding: 10px 20px;
}	
</style>
</head>
<script>
function validate() {
 // check if input is bigger than 3
 var value = document.getElementById('pass').value;
 
 if (value.length >4 && value.length <9 ) {
   
   return true; // keep form from submitting
 }
 
 else{
	
	alert("Password must be 5 to 8 characters.");
    return false;
 }
 
}

</script>

<!-- END HEAD -->
<!-- BEGIN CONTAINER -->
<div class="page-container">
<?php include_once("../ro_sidebar.php"); ?>
	
	<!-- BEGIN CONTENT -->
	<div class="page-content-wrapper">
		<div class="page-content">
			
			<h3 class="page-title">

			Change Password

			</h3>
			<!-- END PAGE HEADER-->

			<!-- BEGIN PAGE CONTENT-->

			<div class="row">

				<div class="col-md-12">	

				<?php 

				if(isset($_GET['msg'])){	
									
					if($_GET['msg']==2){


						echo "<div class='note note-danger'><p>
							NOTE: Your provided name is already exists.
							</p></div>";
					} 

				}          		

 			    ?>					



				<form class="form-horizontal form-row-seperated" onsubmit="return validate();" action="change-pass.php" method="post">			
								
                            <div class="form-group">


								<label class="col-md-2 control-label">
									Current Password: 
								</label>

								<div class="col-md-3">
									<input type="password" class="form-control" name="cpass" required>
								</div>

							</div>

							<div class="form-group">


								<label class="col-md-2 control-label">
									New Password: 
								</label>

								<div class="col-md-3">
									<input type="password" class="form-control" name="npass" id="pass" required>  note: password must be 5 to 8 characters.
								</div>

							</div>

							<div class="form-group">


								<label class="col-md-2 control-label">
									Retype New Password: 
								</label>

								<div class="col-md-3">
									<input type="password" class="form-control" name="npass2" required>
								</div>

							</div>

							<div class="form-group">
			                	<label class="col-sm-2 control-label" ></label>
			                	<input type='hidden' name='actionid' value='changepass'>
				                  <div class="col-sm-5"><button class="btn green"><i class="fa fa-check"></i> Change Password</button></div>
				                  <div class="col-sm-5">  </div>
		                	</div>	
			</form>				

			<!-- END PAGE HEADER-->
			<!-- BEGIN PAGE CONTENT-->

			<div class="row">

				<?php 

					if(isset($_GET['msg'])){	

						if($_GET['msg']==2){


							echo "<div class='note note-danger'><p>
								NOTE: Your provided name is already exists.
								</p></div>";
							} 

					}
 				?>

												
									<?php 
									//var_dump($_SESSION); 

									if($_REQUEST['actionid']=='changepass'){

										//var_dump($_POST);
										
										$cpass=sha1(mysqli_real_escape_string($con,$_POST["cpass"]));
										$npass=mysqli_real_escape_string($con,$_POST["npass"]);
										$npass2=mysqli_real_escape_string($con,$_POST["npass2"]);

										$sql="SELECT u_password from adminusers where u_name='$_SESSION[UNAME]'";
										//echo $sql;
										$rs = mysqli_query($con, $sql);
										$prow=mysqli_fetch_array($rs);
										$rowno=mysqli_num_rows($rs);

										if($rowno>0){

											if($cpass==$prow["u_password"]){

												if($npass==$npass2){

													$npass=sha1($npass);
													$result = mysqli_query($con, "update adminusers set u_password='$npass' where u_name='$_SESSION[UNAME]'");
													//$result=mysql_fetch_array($rs);
													
													if($result){

														echo "<div class='note note-success'><p>
														NOTE: You password is successfully updated.</p></div>";

													}
													else echo "not updated"; 
												}
												else{

													echo "<div class='note note-danger'><p>
														NOTE: Two new passwords are not same.</p></div>";
												}
											}
											else{

												echo "<div class='note note-danger'><p>
														NOTE: Your provided current password is not correct.</p></div>";
											}
										}
										else {

										//	session_destroy();
											header("location:index.php");

										}
									}	

									?>								

				</div>

			</div>

			<!-- END PAGE CONTENT-->

		</div>
	</div>
	<!-- END CONTENT -->
</div>
<!-- END CONTAINER -->
<!-- BEGIN FOOTER -->
<?php include_once("../ro_footer.php"); ?>
<!-- END FOOTER -->
<!-- BEGIN JAVASCRIPTS(Load javascripts at bottom, this will reduce page load time) -->
<!-- BEGIN CORE PLUGINS -->
<!--[if lt IE 9]>
<script src="../assets/global/plugins/respond.min.js"></script>
<script src="../assets/global/plugins/excanvas.min.js"></script> 
<![endif]-->
<?php include_once("../ro_js.php"); ?>

<!-- END PAGE LEVEL SCRIPTS -->
<script>
        jQuery(document).ready(function() {    
           Metronic.init(); // init metronic core components
Layout.init(); // init current layout
QuickSidebar.init(); // init quick sidebar
Demo.init(); // init demo features
          
        });
    </script>
<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>