<?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";
include_once "classes/cls_user.php";
include_once "classes/cls_store.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"];


//**********************************************Multicart3.0 Additions********************
// //Check Seller Privelege added to this account

    $sellerAccObj   =    User::is_seller_account_activated($_SESSION["sess_userid"]);

    $seller_activated_status        =   'N';
    //echopre($sellerAccObj);

        if($sellerAccObj->status==SUCCESS)
            {
                    $sellerAccObjVal            =   $sellerAccObj->data;
                    $seller_activated_status    =   $sellerAccObjVal->is_seller;
                    $activated_seller_id        =   $sellerAccObjVal->seller_id;
            }
    
           
//**********************************************Multicart3.0 Additions********************
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);

         if($seller_activated_status=='Y')  {
                        $sellerInfoVo               =    new stdClass();
                        $sellerInfoVo->seller_id    =  $activated_seller_id;
                        $sellerInfoVo->password     =  md5($txtPassword);
                        $selleifId                  =    Store::updateSellerPassword($sellerInfoVo);
         }
                //Update password of seller account if seller status enabled 
                
                
		$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]);

?>


<!--mainbody area start -->
<div class="main_body">
	<div class="container">
		<div class="row">
			<!--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">
	
			<div class="col-sm-12 col-lg-4 col-md-4"></div>
			<div class="col-sm-12 col-lg-4 col-md-4">
			<div align="left" id="items_top_area">
					<div align="center" id="items_top_area_ttl">
						<?php echo CHANGE_PWD_TEXT;?>
						<div class="clear"></div>
					</div>
			</div>
			<div class="text_information" align="center"><?php echo $message?></div>
			<div class="clear"></div>
			<div class="form_wrapper">
				<div class="register_form_outer">
					<div class="registrationform_container">						
						<div class="field_wrapper formfield_row">
                                                    <label><?php echo OLD_PWD_TEXT; ?><span class="required">*</span></label>
                                                    <input placeholder="<?php echo OLD_PWD_TEXT;?>" class="form-control" type="password" value="" name="txtOldPassword" size="32" maxlength="30"  tabindex="1">                                                    						
						</div>
                                            
						<div class="field_wrapper formfield_row">
                                                        <label><?php echo PASSWORD_TEXT; ?><span class="required">*</span></label>
							<input class="form-control" type="password" value="" placeholder="<?php echo PASSWORD_TEXT;?>" value="" name="txtPassword" size="32" maxlength="30"  tabindex="1">                                                        
                                                </div>        
						
                                                <div class="field_wrapper formfield_row">
                                                        <label><?php echo CONFIRM_PWD_TEXT; ?><span class="required">*</span></label>
							<input class="form-control" type="password" placeholder="<?php echo CONFIRM_PWD_TEXT;?> " value="" name="txtConfirmPassword" size="32" maxlength="30"   tabindex="3">                                                        
						</div>
                                            
						<div class="field_wrapper formfield_row">
								<div class="secondarypannel">
								<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">
								</div>
						</div>
						
						<div class="clear"></div>
					</div>
					<div class="clear"></div>
			</div>
		</div>
		</div>		
		<div class="clear"></div>			
		
			
	
		<div align="left" class="float_clear1"></div>
					
					
		 <!--items display area end -->
		  </div>
		
		</form>
		<!--center content area end-->	


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




				

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