<?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_adminname"]) and $_SESSION["sess_adminname"]!= ""){
	$adminname = $_SESSION["sess_adminname"];
}else{
	header("Location:login.php");
	exit;
}

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

if ($_POST["btnChangePassword"] == CHANGE_PASSWORD) {
	
    $message = "" ;
    
	if (!isNotNull($txtOldPassword)) {
        $message .= "* ".OLD_PWD."<br>";
    }else{
		$sql = "SELECT admin_password FROM ".$tableprefix."settings ";
		$res = mysql_query($sql);
		if(mysql_num_rows($res)!=0){
			$row = mysql_fetch_array($res);
			$oldpassmd5 = $row["admin_password"];
			if(md5($txtOldPassword) != $oldpassmd5){
				$message .= "* ".OLD_MISMATCH."<br>";
			}else{
				if (!isNotNull($txtPassword)) {
			        $message .= "* ".PWD_EMPTY."<br>";
			    }
				if (!isNotNull($txtConfirmPassword)) {
			        $message .= "* ".CONFIRM_EMPTY."<br>";
			    }  
			    if (strcmp($txtPassword, $txtConfirmPassword) != 0) {
			        $message .= "* ".PWD_MISMATCH."<br>";
			    }
			}
		}
	} 

    if ($message != "") { // error
        $message = "<br>".MSG_CORRECT_THE_ERRORS."!<br>" . $message;
    } else { // no error so insert user details
		$sql = "UPDATE ".$tableprefix."settings SET 
			admin_password = '".addslashes(md5($txtPassword))."' ";
		mysql_query($sql);
		$message= PWD_UPD;
    } 
} 

include "../includes/htmltop.php";
?>


<body>
<center>
		
		<div align="left" id="layout">
				
				<!--header area start -->
				
<?php

	include_once("../includes/topheader_admin.php")

?>						
				
				<!--header area end -->
				
				
				<div align="left" class="main_body">
				<!--main body start -->
				
<?php
		include_once("../includes/admintopmenu.php")
?>				

			<div align="left" class="content_area">
			 <!--content area start -->
			<div align="left" class="page_title"><?php echo CHANGE_PASSWORD;?></div>
			<div align="center" class="text_information grey_tr"><?php echo $message?></div>
             <br>
			<div align="left">
			
			
			<table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
			
				<form name="frmChangePassword" action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST">
								
				<tr>
					<td width="40%" align="right" valign="middle"><?php echo CURRENT_PWD;?>&nbsp;<span class="required">*</span></td>
					<td width="4%" align="center" valign="middle">:</td>
					<td width="56%" align="left" valign="middle">
					  <input name="txtOldPassword" maxlength="30" class="textarea" type="password" tabindex="1"/>
					</td>
				  </tr>
				  <tr class="grey_tr">
					<td align="right" valign="middle"><?php echo NEW_PWD;?>&nbsp;<span class="required">*</span></td>
					<td align="center" valign="middle">:</td>
					<td align="left" valign="middle">
					  <input name="txtPassword" maxlength="30" class="textarea" type="password" tabindex="2"/>
					</td>
				  </tr>
				  <tr>
					<td align="right" valign="middle"><?php echo CONFIRM_PWD;?>&nbsp;<span class="required">*</span></td>
					<td align="center" valign="middle">:</td>
					<td align="left" valign="middle">
					  <input name="txtConfirmPassword" class="textarea"  maxlength="30" type="password" tabindex="3" />
					</td>
				  </tr>
				  
				  <tr>
					<td colspan="3" align="center">
						<input type="button" class="button" value="<?php echo BACK;?>" name="back" onClick="Javascript:history.go(-1)" tabindex="5">&nbsp;
						<input type="submit" class="button" value="<?php echo CHANGE_PASSWORD;?>" name="btnChangePassword" tabindex="4">
					</td>
				</tr>
				  
			</form>
				  
			</table>
			
			</div>
			
			</div>
					
					<div align="left" class="clear_float"><img src="images/clear_admin.gif" alt="" width="1" height="1" /></div>
				<!--main body end -->
			</div>


<?php
include "../includes/footer.php";
?>