<?php session_start();
		if (isset($_SESSION['logged']) && $_SESSION['logged'] == 'yes'){
			include ('scripts/classes.php'); //Retrieve functions
			if ($_SESSION['lang']=="EN"){ $lang="EN"; include ('lang/en.php'); }elseif ($_SESSION['lang']=="GR"){ $lang="GR"; include('lang/gr.php'); }else {$lang="EN"; include ('lang/en.php');}	
			$user = $_SESSION['user'];
			$array = getGlobalSettings(); //Retrieve Global Settings	
			
            $page_title = $lbl_page_title_user_pass; //Assign Page Title
			$mode=$lbl_mode_change_pass; //Assign Mode
			
			if (isset($_POST['but_submit'])){
    			$username = $_SESSION['user'];
    			$newpass1 = $_POST['newpass1'];
    			$newpass2 = $_POST['newpass2'];

    			//update password
    			mysqli_query($mysqli, "SET NAMES 'utf8'" ); //Gia Ellinika
    			$update = mysqli_query($mysqli, "UPDATE users SET password = password('$newpass1') WHERE username='$username'") or die("Query failed : " . mysqli_error($mysqli));	
    			mysqli_close($mysqli); 				
    			?>
    			<script type="text/javascript">window.location = "main.php";
                    alert('<?php echo $lbl_password_changed ?>'); 
    			</script>
    			<?php 
			}else{
			
?>	
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $page_title ?></title>
<link rel="shortcut icon" href="img/favicon.png" />
<link href="cms1.css" rel="stylesheet" type="text/css" /> 
<script src="scripts/gen_validatorv4.js" type="text/javascript"></script>
</head>
<body>
<script>top.document.title=self.document.title;</script>
	<div>
		<fieldset>
		<legend><?php echo $mode ?></legend>
				<div class="critical" id="change_pass_errorloc">
				</div>
			<div class="align-left">
   			<form name="change_pass" id="change_pass" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
				<table class="width-100-percent">
					<tr><td class="align-left" width="160"><label class="labels"><?php echo $lbl_grid_username ?></label></td>
					 <td><input type="text" name="usaname" class="addform" disabled="disabled" value="<?php echo $user; ?>"/></td>
					</tr>
					<tr><td class="align-left"><label class="labels"><?php echo $lbl_new_pass ?></label></td>
					<td><input type="password" name="newpass1" class="password" style="margin-left:5px; height:10px"/></td></tr>	
					<tr><td class="align-left"><label class="labels"><?php echo $lbl_new_pass_confirm ?></label></td>
					<td><input type="password" name="newpass2" class="password" style="margin-left:5px; height:10px"/></td></tr>
					<tr><td colspan="2" class="align-right">
						<input name="but_submit" type="submit" class="button" value="<?php echo $lbl_button_save ?>" />
						<input name="but_back" type="button" class="button" value="<?php echo $lbl_button_back ?>" onclick="window.location='main.php';" />
					</td></tr>
				</table>
			</form>
            <script>
             var frmvalidator  = new Validator("change_pass");
            	frmvalidator.EnableOnPageErrorDisplaySingleBox();
            	frmvalidator.EnableMsgsTogether();
            
            	frmvalidator.addValidation("newpass1","req","<?php echo $lbl_error_pass_req ?>");
            	frmvalidator.addValidation("newpass1","minlen=5","<?php echo $lbl_error_pass_min_len_5 ?>");
            	frmvalidator.addValidation("newpass1","eqelmnt=newpass2", "<?php echo $lbl_error_pass_confirm ?>");
            </script>
			</div>
		</fieldset>
	</div>
</body>
</html>			
<?php
    }//not submitted
} else {
    header('Location: login.php');
}
?>