<?php
session_start();
error_reporting(0);
include('../../includes/config.php');
require_once("../../includes/dbcontroller.php");
$db_handle = new DBController();
$ugroups=$_SESSION['ugroups'];
$ugroups = explode(",",$ugroups);

$role= $_SESSION['role'];
if($role!='Admin'){
	header("location:$website_url/");
	exit();
}
$uid=$_GET['id'];
if((!isset($_GET['id']))){
	header("location:$website_url$listusers_url");
	exit();
}
$account_query="SELECT Useremail FROM users where userid ='$uid'";
$account_data = current($db_handle->runQuery($account_query));
if(count($account_data)<1){
	echo "<script>alert('User Does not Exist')</script>";
	echo "<script>location.href = '$website_url$listusers_url';</script>";
}

if(isset($_POST['save'])){
	$password=$_POST['password'];
	$confirm_password=$_POST['confirm_password'];
	if($password===$confirm_password){
		$sql = "UPDATE users SET Password='".md5($_POST['password'])."' WHERE userid='".$_GET['id']."'";
		$result = $db_handle->executeQuery($sql);
		if ($result) {
			echo "<script>alert('Password Updated Succesfully')</script>";
			echo "<script>location.href = '$website_url$listusers_url';</script>";
		}
	}
	else{
		$extra=$_SERVER['REQUEST_URI'];
		header("location:$website_url$extra");
		$_SESSION['errmsg']="New Password and Confirm Password should be same";
		exit();
	}
}


include('../../includes/menu.php');
?>



<div class="container main-cont single-change-password">
	<h2 class="page-title">Change password for <?php echo $account_data['Useremail']; ?></h2>
	<span style="color:red;" >
		<?php
		echo htmlentities($_SESSION['errmsg']);
		?>
		<?php
		echo htmlentities($_SESSION['errmsg']="");
		?>
	</span>
	<div class="form-group">
		<form enctype="multipart/form-data" method="post" accept-charset="utf-8">
			<div class="col-lg-3 col-xs-12 col-sm-4  col-md-4 outer-cell">
				<div class="">
					<div class="frm-item">    
						<label for="password">New Password</label>            
						<input type="password" name="password" value="" class="form-control">
					</div>
				</div> 
			</div>
			<div class="clearfix"></div> 
			<div class="col-lg-3 col-xs-12 col-sm-4  col-md-4 outer-cell">
				<div class="">
					<div class="frm-item">    
						<label for="confirm_password">Confirm Password</label>            
						<input type="password" name="confirm_password" value="" class="form-control">
					</div>
				</div> 
			</div>
			<div class="clearfix"></div> 

			<div class="frm-btn">
				<input type="submit" name="save" value="Save" class="btn btn-primary btn-add">
			</div>
		</form>
	</div> 
</div>


<?php
include('../includes/footer.php');
include('../includes/webfooter.php');
?>