<?php require_once('Connections/oprmConn.php'); 
if(isset($_REQUEST['token'])) {
mysql_select_db($database_oprmConn, $oprmConn);
$query_getProj = "select * FROM weby_users where user_id = '$_GET[user]' and token = '$_GET[token]' and status in ('P','A')";
$getProj = mysql_query($query_getProj, $oprmConn) or die(mysql_error());
$row_getProj = mysql_fetch_assoc($getProj);
$totalRows_getProj = mysql_num_rows($getProj);

if($totalRows_getProj>0) {
if($row_getProj['token'] == $_GET['token']) {
;
} else { echo "Link broken. Please try one more time1"; exit(); }
} else { echo "Link broken. Please try one more time2"; exit(); }

} else { echo "Link broken. Please try one more time3"; exit(); }

if(isset($_POST['new_password'])) {
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$a = 0;
//$olp = md5($_REQUEST['current_password']);
//if($olp == $row_Recordset1['password']) {
mysql_select_db($database_oprmConn, $oprmConn);
$np = md5($_REQUEST['new_password']);
$query_Recordset1 = "update weby_users set password = '$np', token = '00000' WHERE weby_users.user_id = '$_REQUEST[user_id]' and status in ('P','A')";
$Recordset1 = mysql_query($query_Recordset1, $oprmConn) or die(mysql_error());
$msg = "Password setup successfully.";
$a = 1;

if($row_getProj['status']!='A') {
$msg .= "<br>But Your account is not in Active. Please contact administrator";
$a = 2;
}
//} else {
//$msg = "Old Password is wrong. Please try one more time.";
//}

}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>SS WEB TECHNOLOGIES- Change Password</title>
<link href="css/style.css" type="text/css" rel="stylesheet"/>
 <script type="text/javascript">
<!--
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }
//-->

function checkP(){
if(document.getElementById("new_password").value != document.getElementById("confirm_password").value) {
alert("New password and Confirm password should be same");
document.getElementById("new_password").focus();
return false;
}
}
    </script>
</head>

<body>
	<div class="wrapper">
   	  <?php  require_once('includes/header.php'); ?> 
        <div class="content_container">
            <div class="content_wrapper">
                <div class="tools_wrapper">
                <h3>Change Password</h3>
                    <font color="#FF6600"><?php echo $msg; ?></font>
                <?php if($a==0) { ?> 
      <form action="#" method="post" class="ch_pwd_form" onsubmit="return checkP()">
      <div class="login_wrap">
      <input name="user_id" type="hidden" id="user_id" value="<?php echo $_REQUEST['user']; ?>" />
        
        <div class="field_item clear_fix">
          <div class="label"><label>New Password</label></div>
          <div class="input"><input name="new_password" id="new_password" type="password"  size="35" /></div>
        </div>
        <div class="field_item clear_fix">
          <div class="label"><label>Conform Password</label></div>
          <div class="input"><input name="confirm_password" id="confirm_password" type="password"  size="35" /></div>
        </div>
        <div class="action_butt">
            <input name="submit" id="submit" type="submit" class="ch_button" value="Submit"  />
        </div>
      </div>
    </form>
    <?php } ?>
                </div>
            </div>
        </div>
    </div>
    <?php  require_once('includes/footer.php'); ?> 
</body>
</html>
