<?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_store.php";
include_once "../classes/cls_user.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_artistid"]) and $_SESSION["sess_artistid"]!= ""){
	$artistid = $_SESSION["sess_artistid"];
}else{
	header("Location:login.php");
	exit;
}


if(checkArtistExpired($artistid)){
	header("Location:seller_plan_upgrade.php?sellerid=".$artistid);
	exit;
}

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

if ($_POST["btnChangePassword"]) {
    $message = "" ;
	if (!isNotNull($txtOldPassword)) {
        $message .= MSG_OLD_PASS_REQ;
    }else{
		$sql = "SELECT password FROM ".$tableprefix."artists WHERE artist_id = '".addslashes($artistid)."' ";
		$res = mysql_query($sql);
		if(mysql_num_rows($res)!=0){
			$row = mysql_fetch_array($res);
			$oldpassmd5 = $row["password"];
			if(md5($txtOldPassword) != $oldpassmd5){
				$message .= MSG_OLD_PASS_MIS;
			}else{
				if (!isNotNull($txtPassword)) {
			        $message .= MSG_PASS_EMPTY;;
			    }
				if (!isNotNull($txtConfirmPassword)) {
			        $message .= MSG_CON_PASS;
			    }  
			    if (strcmp($txtPassword, $txtConfirmPassword) != 0) {
			        $message .= MSG_NEW_PASS_MIS;
			    }
			}
		}
	} 
	
    if ($message != "") { // error
        $message = VAL_MSG_PLS_CORRECT . $message;
    } else { // no error so insert user details
                $sellerInfoVo               =    new stdClass();
                $sellerInfoVo->seller_id    =   $_SESSION["sess_artistid"];
                $sellerInfoVo->password     =   md5($txtPassword);
                $selleifId                  =   Store::updateSellerPassword($sellerInfoVo);

                $sql = "UPDATE ".$tableprefix."users SET 
			password = '".addslashes(md5($txtPassword))."'
			WHERE seller_id =  '".addslashes($sellerInfoVo->seller_id)."'
			";
		mysql_query($sql);

//Update Buyer account password if single account enabled
         $user_seller_previlge_added = 'N';
        if($_SESSION["sess_artistid"]!='') {
         $userObj   =     Store::get_buyer_account_info($_SESSION["sess_artistid"]);
         if($userObj->status==SUCCESS)  {
                    $userid     = $userObj->data;
         }
         if($userid>0)
             {
                    $user_seller_previlge_added     =    'Y';
             }

        }
                if($user_seller_previlge_added=='Y'){
                        $buyerInfoVo               =        new stdClass();
                        $buyerInfoVo->buyer_id     =        $userid;
                        $buyerInfoVo->password     =        md5($txtPassword);
                        $buyerId                   =        User::updateBuyerPassword($buyerInfoVo);
                }

		
		$message= MSG_PASS_UPDT;
    } 
} 
include "../includes/htmltop.php";
?>


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

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

?>
				
				<!--header area end -->
				
				
				
				
				<div align="left" class="main_body">
				<!--main body start -->
				
				
				
<?php
		include_once("../includes/artisttopmenu.php")
?>		
																					
								
					<div align="left" class="content_area">
					
					<!--content area start -->
							
					<div align="left" class="page_title"><?php echo TEXT_CH_PASS;?></div>
					<div align="center" class="text_information grey_tr"><?php echo $message?></div>
            		<br>
											
					<div align="left">		
																						
					<form name="frmChangePassword" action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST">
					<input type="hidden" name="artistid" value="<?php echo htmlentities($artistid);?>">
						<table cellpadding="0" cellspacing="0" align="center" class="manage_table" width="100%">
							<tr><td colspan="3">&nbsp;</td></tr>
							<tr><td colspan="3" align="right"><span class="required">*</span>&nbsp;<?php echo MSG_FIELD_MANDATORY; ?></td></tr>
							<tr><td width="42%" align="right" ><?php echo TEXT_OLD; ?><?php echo TEXT_PASS;?>&nbsp;<span class="required">*</span></td>
							<td width="1%" >&nbsp;</td><td width="57%" align="left"><input class="textarea" type="password" value="" name="txtOldPassword" id="txtOldPassword"  maxlength="30" ></td></tr>
							<tr><td align="right" ><?php echo TEXT_PASS;?>&nbsp;<span class="required">*</span></td>
							<td >&nbsp;</td><td align="left"><input class="textarea" type="password" value="" name="txtPassword"  maxlength="30" ></td></tr>
							<tr><td align="right" ><?php echo TEXT_CONF; ?><?php echo TEXT_PASS; ?>&nbsp; <span class="required">*</span></td>
							<td >&nbsp;</td><td align="left"><input class="textarea" type="password" value="" name="txtConfirmPassword"  maxlength="30"></td></tr>
							<tr><td colspan="3">&nbsp;</td></tr>
							<tr>
								<td colspan="3" align="center">
									
									<input type="button" value="&nbsp;&nbsp;<?php echo BTN_BACK;?>&nbsp;&nbsp;" class="button" name="Back" onClick="Javascript:history.go(-1);">
                                                                        <input type="submit" value="<?php echo BTN_CHANG_PASS;?>" name="btnChangePassword" class="button">
								</td>
							</tr>
							
						</table>
					</form>
					
				</div>
						
						
				<!--content area end-->
								
				</div>
				
								
					<div align="left" class="clear_float"><img src="<?php echo $imagefolder;?>/clear.gif" alt="" width="1" height="1" /></div>
				<!--main body end -->
				</div>
				
				
<?php
	include "../includes/footer.php";
?>
<script type="text/javascript">
window.onload=function(){
document.getElementById("txtOldPassword").focus();
}

</script>
