<?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_affiliateid"]) and $_SESSION["sess_affiliateid"]!= ""){
	$affiliateid = $_SESSION["sess_affiliateid"];
}else{
	header("Location:login.php");
	exit;
}
$txtUserName = stripslashes($_POST["txtUserName"]);
$txtFirstName = stripslashes($_POST["txtFirstName"]);
$txtLastName = stripslashes($_POST["txtLastName"]);
$txtAddress1 = stripslashes($_POST["txtAddress1"]);
$txtAddress2 = stripslashes($_POST["txtAddress2"]);
$txtCity = stripslashes($_POST["txtCity"]);
$txtState = stripslashes($_POST["bill_state"]);
$ddlCountry = stripslashes($_POST["ddlCountry"]);
$txtZIP = stripslashes($_POST["txtZIP"]);
$txtEmail = stripslashes($_POST["txtEmail"]);
$txtPhone = stripslashes($_POST["txtPhone"]);
$txtFAX = stripslashes($_POST["txtFAX"]);
$txtPassword = stripslashes($_POST["txtPassword"]);
$txtConfirmPassword = stripslashes($_POST["txtConfirmPassword"]);
$txtTaxId = stripslashes($_POST["txtTaxId"]);

if ($_POST["btnSaveChanges"]) {
    $message = "" ;
	if (!isNotNull($txtFirstName)) {
        $message .= VAL_MSG_FIRST_NAME;
    }
	/*if(isNotNull($txtFirstName))
	{
	
	 if(!preg_match("/^[a-zA-Z ]+$/", $txtFirstName))
	 { 
	   $message .= "* First name accepts alphabets only !! <br>";
	 }
	}*/
	if (!isNotNull($txtLastName)) {
        $message .= VAL_MSG_LAST_NAME;
    }
	/*if(isNotNull($txtLastName))
	{
	 if(!preg_match("/^[a-zA-Z ]+$/", $txtLastName))
	 { 
	   $message .= "* Last name accepts alphabets only !! <br>";
	 }
	}*/

	if (!isNotNull($txtAddress1)) {
        $message .= VAL_MSG_ADDR_NAME;
    } 
	if (!isNotNull($txtCity)) {
        $message .= VAL_MSG_CITY;
    }   
	if (!isNotNull($txtState)) {
        $message .= VAL_MSG_STATE;
    }
       if(!isNotNull($ddlCountry)){
       $message .= VAL_MSG_COUNT;    
    }
	if (!isNotNull($txtEmail)) {
        $message .= VAL_MSG_EMAIL;
    }
	if(isNotNull($txtPhone))
	{ 
		if(!check_phone($txtPhone,$ddlCountry))
		{
		 $message .= VAL_MSG_PHONE;
		}
	}
	/*if(isNotNull($txtFAX))
	{
		if(!check_fax($txtFAX))
		{
		 $message .= "* Fax number should be valid !!<br>";
		}
	} */
	if (!isValidEmail($txtEmail)) {
	        $message .= VAL_MSG_INVALID_MAIL;
	    } 
	/*else{
		if (($ddlCountry == "US" || $ddlCountry == "UM") && strlen($txtZIP)!=5) {
	        $message .= "* Zipcode must contain 5 characters! <br>";
	    } 
	}*/
	
    $qry2 = "select email from  " . $tableprefix . "affiliates where email='" . addslashes($txtEmail) . "' AND affiliate_id <> '".addslashes($affiliateid)."' ";
    if (mysql_num_rows(mysql_query($qry2)) > 0) {
        $message .= MSG_EMAIL_ADDR.htmlentities($txtEmail).MSG_ALREADY_USE;
    } 

    if ($message != "") { // error
        $message = VAL_MSG_PLS_CORRECT. $message;
    } else { // no error so insert user details
		$sql = "UPDATE ".$tableprefix."affiliates SET 
			first_name = '".addslashes($txtFirstName)."',
			last_name = '".addslashes($txtLastName)."',
			address1 = '".addslashes($txtAddress1)."',
			address2 = '".addslashes($txtAddress2)."',
			city = '".addslashes($txtCity)."',
			state = '".addslashes($txtState)."',
			country = '".addslashes($ddlCountry)."',
			phone = '".addslashes($txtPhone)."',
			fax = '".addslashes($txtFAX)."',
			zip = '".addslashes($txtZIP)."',
			email = '".addslashes($txtEmail)."',
			taxid = '".addslashes($txtTaxId)."'
			WHERE affiliate_id =  '".addslashes($affiliateid)."'
			";
		mysql_query($sql);
		$message= MSG_PROFILE_UPDATE;
    } 
} 
$sql = "SELECT * FROM ".$tableprefix."affiliates WHERE affiliate_id = '".addslashes($affiliateid)."' ";
$result = mysql_query($sql);
if(mysql_num_rows($result) != 0){
	$row = mysql_fetch_array($result);
	$txtFirstName = stripslashes($row["first_name"]);
	$txtLastName = stripslashes($row["last_name"]);
	$txtAddress1 = stripslashes($row["address1"]);
	$txtAddress2 = stripslashes($row["address2"]);
	$txtCity = stripslashes($row["city"]);
	$txtState = stripslashes($row["state"]);
	$ddlCountry = stripslashes($row["country"]);
	$txtPhone = stripslashes($row["phone"]);
	$txtFAX = stripslashes($row["fax"]);
	$txtZIP = stripslashes($row["zip"]);
	$txtEmail = stripslashes($row["email"]);
	$txtTaxId = stripslashes($row["taxid"]);
	$txtUserName = stripslashes($row["affiliate_name"]);}
$countrylist = makeCountryList();
include "../includes/htmltop.php";
?>


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

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

?>
				
				<!--header area end -->
				
				
				
				
				<div align="left" class="main_body">
				<!--main body start -->
				
				
				
<?php
		include_once("../includes/afftopmenu.php")
?>		
																					
								
					<div align="left" class="content_area">
					
					<!--content area start -->
							
					<div align="left" class="page_title"><?php echo TEXT_EDIT_PROFILE;?></div>
					<div align="center" class="text_information grey_tr"><?php echo $message?></div>
            		<br>
											
					<div align="left">																			
		
					<form name="frmProfile" action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST">
					
                                    <!-- The id of the country field(s).  If more than one, seperate with spaces -->
                                    <input type="hidden" value="ddlCountry" name="cs_config_country_field" id="cs_config_country_field">
                                    <input type="hidden" value="bill_state" name="cs_config_state_field"   id="cs_config_state_field">


                                    <!-- The id of the the fields holding the default values.  If more than one, seperate with spaces -->
                                    <input type="hidden" value="billCountryDefault" name="cs_config_country_default" id="cs_config_country_default">
                                    <input type="hidden" value="billStateDefault"   name="cs_config_state_default"   id="cs_config_state_default">
                                    <!-- The actual default values -->
                                    <input type="hidden" value="<?php echo $ddlCountry;?>" name="billCountryDefault" id="billCountryDefault">
                                    <input type="hidden" value="<?php echo $txtState;?>"   name="billStateDefault"   id="billStateDefault">
                                    <SCRIPT type="text/javascript" SRC="../js/country-state.js"></SCRIPT>
									
					<input type="hidden" name="userid" value="<?php echo ($affiliateid);?>">
						<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 align="right" ><?php echo TEXT_USER_NAME;?>&nbsp;<span class="required">*</span></td>
							  <td >&nbsp;</td>
							  <td align="left"><input name="txtUserName" type="text" class="textarea" id="txtUserName" value="<?php echo htmlentities($txtUserName);?>" size="30" maxlength="100" readonly></td>
						  </tr>
							<tr><td width="42%" align="right" ><?php echo TEXT_FIRST_NAME;?>&nbsp;<span class="required">*</span></td>
							<td width="4%" >&nbsp;</td><td width="54%" align="left"><input type="text" class="textarea" value="<?php echo ($txtFirstName);?>" name="txtFirstName" size="30" maxlength="100"></td></tr>
							<tr><td align="right" ><?php echo TEXT_LAST_NAME;?> &nbsp; <span class="required">*</span></td>
							<td >&nbsp;</td><td align="left"><input class="textarea"  type="text" value="<?php echo ($txtLastName);?>" name="txtLastName" size="30" maxlength="100"></td></tr>
							<tr><td align="right" ><?php echo TEXT_ADDR1;?>&nbsp; <span class="required">*</span></td>
							<td >&nbsp;</td><td align="left"><input class="textarea"  type="text" value="<?php echo ($txtAddress1);?>" name="txtAddress1" size="40" maxlength="100"></td></tr>
							<tr><td align="right" ><?php echo TEXT_ADDR2;?></td>
							<td >&nbsp;</td><td align="left"><input type="text" class="textarea"  value="<?php echo htmlentities($txtAddress2);?>" name="txtAddress2" size="40" maxlength="100"></td></tr>
							<tr><td align="right" ><?php echo TEXT_CITY;?>&nbsp;<span class="required">*</span></td>
							<td >&nbsp;</td><td align="left"><input type="text" class="textarea"  value="<?php echo($txtCity);?>" name="txtCity" size="30" maxlength="100"></td></tr>
							<tr><td align="right" ><?php echo TEXT_COUNTRY;?>&nbsp;<span class="required">*</span></td>
							<td >&nbsp;</td><td align="left">
							<select id="ddlCountry"  class='textarea2' name='ddlCountry' onchange='updateState(this.id)'>
                            </select>
							</td></tr>
							<tr>
							  <td align="right" ><?php echo TEXT_STATE;?>&nbsp;<span class="required">*</span></td>
							  <td >&nbsp;</td>
							  <td align="left">
							  <!-- <input type="text" class="textarea"  value="<?php echo htmlentities($txtState);?>" name="txtState" size="30" maxlength="100"> -->
							  <select id='bill_state' name='bill_state' class='textarea2'>
							  
							  </select>
                              <SCRIPT  type="text/javascript">initCountry(); </SCRIPT>
							  </td>
						  </tr>
							<tr><td align="right" ><?php echo TEXT_ZIP;?></td>
							<td >&nbsp;</td><td align="left"><input type="text" value="<?php echo htmlentities($txtZIP);?>" class="textarea"  name="txtZIP" size="30" maxlength="20"></td></tr>
							<tr><td align="right" ><?php echo TEXT_PHONE;?></td>
							<td >&nbsp;</td><td align="left"><input type="text" value="<?php echo htmlentities($txtPhone);?>" class="textarea"  name="txtPhone" size="30" maxlength="100"></td></tr>
							<tr><td align="right" ><?php echo TEXT_FAX;?></td>
							<td >&nbsp;</td><td align="left"><input type="text" value="<?php echo htmlentities($txtFAX);?>" class="textarea" name="txtFAX" size="30" maxlength="100"></td></tr>
							<tr><td align="right" ><?php echo TEXT_EMAIL;?>&nbsp;<span class="required">*</span></td>
							<td >&nbsp;</td><td align="left"><input type="text" value="<?php echo htmlentities($txtEmail);?>" class="textarea" name="txtEmail" size="30" maxlength="100"></td></tr>
							<tr><td align="right" ><?php echo TEXT_TAX_ID;?></td>
							<td >&nbsp;</td><td align="left"><input type="text" value="<?php echo htmlentities($txtTaxId);?>" class="textarea" name="txtTaxId" size="30" maxlength="100"></td></tr>
							<tr><td colspan="3">&nbsp;</td></tr>
							<tr><td colspan="3" align="center"><input type="submit" value="<?php echo BTN_SAVE_CHANGE;?>" name="btnSaveChanges" 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";
?>