<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link rel="stylesheet" type="text/css" href="../css/main.css" />
<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>
<?php
include ("../navigation/header.php");
$page_name = "open page";
include ("../navigation/access.php");
include('../include/formValidations.php');

//$username = $_GET['user_name'];
$page = $_GET['page'];
$m = $_GET['m'];


$table_name = $_SESSION['db_prefix']."_users";
$user_query = "SELECT username, userid, password FROM $table_name WHERE username ='".$_SESSION['username']."' ";
$user_result = mySQL_query($user_query);
$user_name = mysql_result($user_result, 0, "username");
$user_id = mysql_result($user_result, 0, "userid");
$password = mysql_result($user_result, 0, "password");


if ($page=='hr_main.php') {$page="../hr_module/hr_main.php?period=day";}
if ($page=='hire_main.php') {$page="../hire/hire_main.php?period=day";}
if ($page=='user_list.php') {$page="../admin_module/user_list.php";}

  
?>
<script type="text/javascript">
function stopRKey(evt) {
  var evt = (evt) ? evt : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;}
}
document.onkeypress = stopRKey;
</script> 

<script type="text/javascript">
<!--
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
//-->
</script>

<link href="../css/popup.css" rel="stylesheet" type="text/css" />
</head>
<?php
if ($permission_num==1) {
	include ("../navigation/admin_sidebar.php");
?>
<body>

<div class="main_frame">
<table id="tableMain" > <!--begin of tableMain-->
    <tr>
      <td width="830" height="125" valign="top" >
  <div class="page_head_frame">
    <table width="809" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="385"><label class="label_page_head">Change password</label></td>
        <td align="right">&nbsp;</td>
      </tr>
    </table>
  </div>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <div class="standard_frame">

<form action="save_change_password.php" method="GET" name="form1" target="_top" id="form1">

<table width="290" border="0" align="center" cellpadding="0" cellspacing="0" class="list2">
  <tr>
    <td width="290" align="center"><label class="label_std">Change password for user:<b> <?php echo $user_name ?></b></label>
          
      <table width="300" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td height="40"><label class="std">old password:</label>
            <input type="hidden" name="user_id" id="user_id"  value="<?php echo $user_id ?>"/>
            <input type="hidden" name="return_page" id="return_page" value="<?php echo $page ?>" /></td>
          <td><input type="password" name="old_password_text" id="old_password_text" /></td>
        </tr>
        <tr>
          <td width="127" height="40"><label class="std">new password:</label>
            <br /></td>
          <td width="173"><input type="password" name="user_password_text" id="user_password_text" onkeyup="MM_callJS('removeWhitespaces()')"/></td>
        </tr>
        <tr>
          <td height="40"><label class="std">confirm password:</label>
            &nbsp;<br /></td>
          <td><input type="password" name="user_password_text2" id="user_password_text2" /></td>
        </tr>
        <tr>
          <td height="19" colspan="2" align="center"></td>
        </tr>
      </table>
      </td>
  </tr>
  <tr>
    <td align="center"><br />
      <input name="input" type="submit" value="Change" class="imagebutton"  />
      <input name="Reset" type="reset" class="imagebutton" id="button"  value="Cancel" /></form>
    </td>
  </tr>
</table>
</form></div>
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("old_password_text","req","Please enter your current password.");
  frmvalidator.addValidation("user_password_text","req","Please enter a password.");
  frmvalidator.addValidation("user_password_text2","req","Please re-type the password.");
  frmvalidator.addValidation("user_password_text","minlen=6","Mininum length for a password is 6 characters.");
  frmvalidator.addValidation("user_password_text","eqelmnt=user_password_text2","The confirmed password is not same as password");
</script>

 <!--end of tableMain-->
<?php

if ($m==1) {
	$action=$_GET['return_page'];
	
	?>
	<script type="text/javascript">
      alert('Your password was succesfully changed.');
	  window.location="<?php echo $action ?> ";
    </script>
<?php 
}
?>

<?php if ($m==2) { ?>
	<script type="text/javascript">
      alert('Changing of your password failed.\n\nYou entered the wrong password.\n\nYou can try again. If you fail to change your password, contact the system administrator.');
    </script>
<?php 
}
?>  

</body>
<?php } else {
    $_SESSION['denied_return'] = "admin_module/user_list.php";	
    include ("../navigation/admin_sidebar.php");?>
	<body onLoad="accessdenied(); return false">	
	</body>
<?php }
?>
</html>