<?php
/**************************************************************************************************
|
| iDocScript - Document Sharing Script
| http://www.idocscript.com
| webmaster@idocscript.com
|
|**************************************************************************************************
|
| By using this software you agree that you have read and acknowledged our End-User License 
| Agreement available at http://www.idocscript.com/eula.html and to be bound by it.
|
| Copyright (c) 2011 iDocScript.com. All rights reserved.
|**************************************************************************************************/

include("include/config.php");
include("include/functions/import.php");
$thebaseurl = $config['baseurl'];

if ($_SESSION['USERID'] != "" && $_SESSION['USERID'] >= 0 && is_numeric($_SESSION['USERID']))
{
	if($_REQUEST['change']!="")
	{
		$UID = intval(cleanit($_SESSION['USERID']));
		$query="SELECT password FROM members WHERE USERID='".mysql_real_escape_string($UID)."'";
        $executequery=$conn->execute($query);
        $getpass = $executequery->fields['password'];
		$encodedpass = md5($_POST['cpassword']);
		if ($encodedpass != $getpass )
		{
			$error = $lang['504'];
		}
		elseif ($_POST['npassword'] == "" )
		{
			$error = $lang['505'];
		}
		elseif ($_POST['npassword'] != $_POST['rnpassword'])
		{
			$error = $lang['506'];
		}
		else
		{
			if ($error == "")
			{
				$password = cleanit($_REQUEST['npassword']);
				$password = md5($password);
				$query="UPDATE members SET password='".mysql_real_escape_string($password)."' WHERE USERID='".mysql_real_escape_string($UID)."'";
				$conn->execute($query);
				
				if(mysql_affected_rows()>=1)
				{
					$message = $lang['507'];
				}
				else
				{
					$error = $lang['508'];
				}
			}
			else
			{
				$error = $lang['509'];
			}		
			
		}
	}
	$templateselect = "changepass.tpl";
}
else
{
	$redirect = base64_encode($thebaseurl."/changepass.php");
	header("Location:$config[baseurl]/login.php?redirect=$redirect");exit;
}

$pagetitle = $lang['24'];
STemplate::assign('pagetitle',$pagetitle);

//TEMPLATES BEGIN
STemplate::assign('error',$error);
STemplate::assign('message',$message);
STemplate::display('header.tpl');
STemplate::display($templateselect);
STemplate::display('footer.tpl');
//TEMPLATES END
?>