<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com � 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php
include "includes/config.php";
include "includes/session.php";
include "includes/functions.php";

if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE); 
} 

if(isset( $_SESSION["sess_userid"]) and $_SESSION["sess_userid"]!= ""){
	$userid = $_SESSION["sess_userid"];
}else{
	header("Location:login.php");
	exit;
}

$txtOldPassword = $_POST["txtOldPassword"];
$txtPassword = $_POST["txtPassword"];
$txtConfirmPassword = $_POST["txtConfirmPassword"];

if (isset($_POST["btnChangePassword"])) {
	
    $message = "" ;
    
	if (!isNotNull($txtOldPassword)) {
        $message .= OLD_PWD_REQUIRED_TEXT." <br>";
    }else{
		$sql = "SELECT password FROM ".$tableprefix."users WHERE user_id = '".addslashes($userid)."' ";
		$res = mysql_query($sql);
		if(mysql_num_rows($res)!=0){
			$row = mysql_fetch_array($res);
			$oldpassmd5 = $row["password"];
			if(md5($txtOldPassword) != $oldpassmd5){
				$message .= OLD_PWD_MISMATCH_TEXT." <br>";
			}else{
				if (!isNotNull($txtPassword)) {
			        $message .= NEW_PWD_EMPTY_TEXT." <br>";
			    }
				if (!isNotNull($txtConfirmPassword)) {
			        $message .= CONFIRM_PWD_EMPTY_TEXT." <br>";
			    }  
			    if (strcmp($txtPassword, $txtConfirmPassword) != 0) {
			        $message .= NEW_PWD_MISMATCH_TEXT." <br>";
			    }
			}
		}
	} 
	
	
   

    if ($message != "") { // error
        $message = "<br>".CORRECT_ERRORS_TEXT."<br>" . $message;
    } else { // no error so insert user details
		$sql = "UPDATE ".$tableprefix."users SET 
			password = '".addslashes(md5($txtPassword))."'
			WHERE user_id =  '".addslashes($userid)."'
			";
		mysql_query($sql);
		$message= PWD_UPDATE_SUCCESS_TEXT;
    } 
} 

/*display the active template*/

$active_template = displayTemplate();


include "includes/htmltop.php";

/* Top File Name */

include_once ("includes/".$active_template[0]);

?>


<div align="left" class="main_body">
			<!--mainbody area start -->
			
		<!--center content area start-->		

		<form name="frmChangePassword" action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST">
		<input type="hidden" name="userid" value="<?php echo $userid;?>">
		
		<div align="left" id="item_details">
	
	
		<!--items display area start -->
	
		<div align="left" id="items_top_area">
				
				<div align="left" id="items_top_area_ttl"><?php echo CHANGE_PWD_TEXT;?></div>
		</div>
		
		<div class="text_information" align="center"><?php echo $message?></div>
		
		<div>
		
		
				<fieldset>
				<div class="chng_pass">
				<table cellpadding="2" cellspacing="2" width="100%">
				<tr>
						<td colspan="3" align="right"><span class="required">*</span><?php echo MANDATORY_FIELDS_TEXT;?></td>
				</tr>
				<tr><td colspan="3"></tr>
				<tr><td width="25%" align="left" ><?php echo OLD_PWD_TEXT;?>&nbsp;<span class="required">*</span></td><td width="1%" align="left">&nbsp;</td><td width="74%" align="left"><input class="textarea" type="password" value="" name="txtOldPassword" size="32" maxlength="30"  tabindex="1"></td></tr>
				<tr><td align="left" ><?php echo PASSWORD_TEXT;?>&nbsp;<span class="required">*</span></td><td >&nbsp;</td><td align="left"><input class="textarea" type="password" value="" name="txtPassword" size="32" maxlength="30"  tabindex="2"></td></tr>
				<tr><td align="left" ><?php echo CONFIRM_PWD_TEXT;?> &nbsp; <span class="required">*</span></td><td >&nbsp;</td><td align="left"><input class="textarea" type="password" value="" name="txtConfirmPassword" size="32" maxlength="30"   tabindex="3"></td></tr>
				<tr><td colspan="3"></tr>
				<tr>
					<td colspan="3" align="center">
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<input type="button" value="<?php echo ACCOUNT_BACK_BUTTON;?>" name="btnBack"  class="button" onClick="window.location.href='myaccount.php'">
					<input type="submit" value="<?php echo CHANGE_PWD_TEXT;?>" name="btnChangePassword" class="button"  tabindex="4">
				  </td>
				</tr>
			</table>
			<div class="clear"></div>
			</div>
			</fieldset>
		</div>	
	
	
		<div align="left" class="float_clear1"></div>
					
					
		 <!--items display area end -->
		  </div>
		
		</form>
		<!--center content area end-->	


		
		<!--mainbody area end -->
        </div>
	




				

<?php
include "includes/".$active_template[2];	/* Bottom File Name */
?>																