<?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 "../classes/cls_products.php";
include "../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_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;
}

$txtFirstName = $_POST["txtFirstName"];
$txtLastName = $_POST["txtLastName"];
$txtAddress1 = $_POST["txtAddress1"];
$txtAddress2 = $_POST["txtAddress2"];
$txtCity = $_POST["txtCity"];
$txtState = $_POST["bill_state"];
$ddlCountry = $_POST["bill_country"];
$txtZIP = $_POST["txtZIP"];
$txtEmail = $_POST["txtEmail"];
$txtPhone = $_POST["txtPhone"];
$txtFAX = $_POST["txtFAX"];
$txtPassword = $_POST["txtPassword"];
$txtConfirmPassword = $_POST["txtConfirmPassword"];
$txtWeb	=$_POST["txtWeb"];
$txtCompany=$_POST["txtCompany"];
$txtStore=$_POST["txtStore"];
$txtPaypalEmail = $_POST["txtPaypalEmail"];
$txtPaypalIDTOKEN= $_POST["txtPaypalIDTOKEN"];
$chkSandbox= $_POST["chkSandbox"];
$rdVacctionmode = $_POST["rdVaccationMode"];
$txtTimeZone    =   $_POST['txtTimeZone'];
if ($_POST["chkSandbox"]) {
    $chkSandbox = "Y";
} else {
    $chkSandbox = "N";
}

if ($_POST["btnSaveChanges"]) {
    $message = "" ;


    if (!isNotNull($txtCompany)) {
        $message .= VAL_MSG_CMP_NAME;
    }
    if (!isNotNull($txtStore)) {
    	//$message .= VAL_MSG_STORE;
    }else{
    	$txtStore = getStoreAlias($txtStore,$txtStore,$artistid);
    }
    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($txtZIP)) {
        $message .= VAL_MSG_ZIP;
    }


    if(!isNotNull($txtPhone)) {
        if(!check_phone($txtPhone,$ddlCountry)) {
            $message .= VAL_MSG_PHONE;
        }
    }

    if (!isNotNull($txtEmail)) {
        $message .= VAL_MSG_EMAIL;
    }
    else {
        if (!isValidEmail($txtEmail)) {
            $message .= VAL_MSG_INVALID_MAIL;
        }
    }


    if (!isNotNull($txtPaypalEmail)) {
        $message .= VAL_MSG_PAYPAL_MAIL;
    }
    else {
        if (!isValidEmail($txtPaypalEmail)) {
            $message .= VAL_MSG_INVALID_PAYPAL;
        }
    }




    $qry2 = "select email from  " . $tableprefix . "artists where email='" . addslashes($txtEmail) . "' AND artist_id <> '".addslashes($artistid)."' ";
    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."artists 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)."',
			company='".addslashes($txtCompany)."',
                        storename='".addslashes($txtStore)."',
			website='".addslashes($txtWeb)."',
                        is_vacation_mode='".addslashes($rdVacctionmode)."',    
			paypalemail='".addslashes($txtPaypalEmail)."',
                        seller_time_zone = '".addslashes($txtTimeZone)."'
			WHERE artist_id =  '".addslashes($artistid)."' ";
        mysql_query($sql) or die(mysql_error());


        // Update product status to vacation mode if seller status is in vacation mode // products will not display in
                $seller_vacation_mode   =    $rdVacctionmode;
                $productObjVo   =   new stdClass();
                $productObjVo->seller_vacation_mode     =   $seller_vacation_mode;
                $productObjVo->seller_id                =    $artistid;

                $nid            =    Products::manageSellerVacationSettingsMode($productObjVo);


        
        $message= MSG_PROFILE_UPDATE;
    }
}

$sql = "SELECT *
          FROM ".$tableprefix."artists
		 WHERE artist_id = '".addslashes($artistid)."' ";
$result = mysql_query($sql);
if(mysql_num_rows($result) != 0) {
    $row = mysql_fetch_array($result);  
    
	    $txtFirstName = $row["first_name"];
	    $txtLastName = $row["last_name"];
	    $txtAddress1 = $row["address1"];
	    $txtAddress2 = $row["address2"];
	    $txtCity = $row["city"];
	    $txtState = $row["state"];
	    $ddlCountry = $row["country"];
	    $txtPhone = $row["phone"];
	    $txtFAX = $row["fax"];
	    $txtZIP = $row["zip"];
	    $txtEmail = $row["email"];
	    $txtWeb	= $row["website"];
	    $txtCompany=$row["company"];
	    $txtStore=$row["storename"];
	    $chkSandbox		  = $row['enablepaypalsandbox'];
	    $txtPaypalIDTOKEN  = $row['paypalidentitytoken'];
	    $txtPaypalEmail       = $row['paypalemail'];
	    $txtUserName = $row['artist_name'];
	    $txtCurrency = $row['vseller_currency'];
            $rdVacctionmode = $row['is_vacation_mode'];
            $txtTimeZone    =  $row['seller_time_zone'];
    //fetch currency symbol
}
$countrylist = makeCountryList();
include "../includes/htmltop.php";
?>
<script src="../js/jquery.js"></script>
<script type="text/javascript">
    $( document ).ready(function() {
   
        var storeURL = $.trim($("input[name='txtStore']").val());     
        var storeURLNew = storeURL.replace(/[^a-z0-9-\s]/gi, '').replace(/[_\s]/g, '-');
        
        $('#mashable').html(storeURLNew);
        $("input[name='txtStore']").val(storeURLNew);
		if(storeURL == ""){
			 var user = $("input[name='txtUserName']").val();
		     var userNew = user.replace(/[^a-z0-9-\s]/gi, '').replace(/[_\s]/g, '-');
		     $('#mashable').html(userNew);
		}
        $("input[name='txtStore']").keyup(function() {
            storeURL = $.trim($("input[name='txtStore']").val());
            storeURLNew = storeURL.replace(/[^a-z0-9-\s]/gi, '').replace(/[_\s]/g, '-');
            $('#mashable').html(storeURLNew);
            $("input[name='txtStore']").val(storeURLNew);
            if(storeURL == ""){
   			 var user = $("input[name='txtUserName']").val();
   		     var userNew = user.replace(/[^a-z0-9-\s]/gi, '').replace(/[_\s]/g, '-');
   		     $('#mashable').html(userNew);
   			}
        });
    });
   
</script>

<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_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="billCountrySelect" name="cs_config_country_field" id="cs_config_country_field">
                            <input type="hidden" value="billStateSelect" 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="txtUserName" value="<?php echo htmlentities($txtUserName);?>">
                            <input type="hidden" name="userid" value="<?php echo htmlentities($artistid);?>">
                            <table cellpadding="0" cellspacing="0" align="center" class="manage_table" width="100%">
                                <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_USER_NAME;?></td>
                                    <td width="2%" >&nbsp;</td>
                                    <td width="56%" align="left"><b><?php echo $txtUserName;?></b></td>
                                </tr>
                                <tr>
                                    <td align="right" ><?php echo TEXT_CURRENCY;?></td>
                                    <td >&nbsp;</td>
                                    <td align="left"><b><?php echo htmlentities($txtCurrency);?></b></td>
                                </tr>
                                <tr>
                                    <td align="right" ><?php echo TEXT_COMPANY;?>&nbsp;<span class="required">*</span></td>
                                    <td >&nbsp;</td>
                                    <td align="left"><input name="txtCompany" type="text" class="textarea" id="txtCompany" value="<?php echo stripslashes($txtCompany);?>"  maxlength="20"></td>
                                </tr>
                                 <tr>
                                    <td align="right" ><?php echo TEXT_STORENAME;?>&nbsp;<!-- <span class="required">*</span> --></td>
                                    <td >&nbsp;</td>
                                    <td align="left"><input name="txtStore" type="text" class="textarea" id="txtStore" value="<?php echo stripslashes($txtStore);?>"  maxlength="20"></td>
                                </tr>
                                 <tr>
                                    <td align="right" ><?php echo TEXT_SELLER_STORE_URL;?>&nbsp;</td>
                                    <td >&nbsp;</td>
                                    <td align="left">
                                        
                                        <?php echo SITE_URL; ?><?php if($enable_seller_friendly == "Y") { ?>/stores/<?php } else { ?>/showportfolio.php?storename=<?php } ?><span id="mashable"></span>
                                    </td>
                                </tr>
                                <tr><td align="right" ><?php echo TEXT_FIRST_NAME;?>&nbsp;<span class="required">*</span></td>
                                    <td >&nbsp;</td><td align="left"><input  class="textarea" type="text" value="<?php echo stripslashes($txtFirstName);?>" name="txtFirstName"  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 stripslashes($txtLastName);?>" name="txtLastName"  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 stripslashes($txtAddress1);?>" name="txtAddress1"  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 stripslashes($txtAddress2);?>" name="txtAddress2" size="40" maxlength="100"></td></tr>
                                <tr><td align="right" ><?php echo TEXT_CITY;?>&nbsp;<span class="required">*</span></td>
                                    <td align="left">&nbsp;</td><td align="left"><input type="text"  class="textarea" value="<?php echo stripslashes($txtCity);?>" name="txtCity" maxlength="100"></td></tr>
                                <tr><td align="right"><?php echo TEXT_COUNTRY;?>&nbsp;<span class="required">*</span></td>
                                    <td align="left">&nbsp;</td><td align="left">
                                        <select id='billCountrySelect'  class='textarea' name='bill_country' onchange='updateState(this.id)'>
                                        </select>
                                    </td></tr>
                                <tr>
                                    <td align="right"><?php echo TEXT_STATE;?><span class="required">*</span></td>
                                    <td align="left">&nbsp;</td>
                                    <td align="left"> <select id='billStateSelect' class='textarea' name='bill_state'>
                                        </select> <SCRIPT  type="text/javascript">initCountry(); </SCRIPT> </td>
                                </tr>

                                <tr><td align="right" ><?php echo TEXT_ZIP;?>&nbsp;<span class="required">*</span></td>
                                    <td >&nbsp;</td><td align="left"><input type="text" value="<?php echo stripslashes($txtZIP);?>" class="textarea" name="txtZIP"  maxlength="20"></td></tr>


                                <tr>
                                    <td align="right" ><?php echo TEXT_WEBSITE;?></td>
                                    <td >&nbsp;</td>
                                    <td align="left"><input name="txtWeb" type="text" class="textarea" id="txtWeb" value="<?php echo stripslashes($txtWeb);?>"  maxlength="20"></td>
                                </tr>

                                <tr>
                                    <td align="right" ><?php echo TEXT_PHONE;?><span class="required">*</span></td>
                                    <td >&nbsp;</td><td align="left"><input type="text" value="<?php echo stripslashes($txtPhone);?>"  class="textarea" name="txtPhone"  maxlength="100"></td></tr>
                                
                                 <tr>
                                    <td align="right" ><?php echo TEXT_TIME_ZONE;?><span class="required">*</span></td>
                                    <td >&nbsp;</td><td align="left"><?php echo makeTimeZoneList('textarea',$txtTimeZone);?></td></tr>
                                
                                <tr><td align="right" ><?php echo TEXT_FAX;?></td>
                                    <td >&nbsp;</td><td align="left"><input type="text" value="<?php echo stripslashes($txtFAX);?>"  class="textarea" name="txtFAX"  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 stripslashes($txtEmail);?>"  class="textarea" name="txtEmail"  maxlength="100"></td></tr>
                                <tr><td colspan="3">&nbsp;</td></tr>

                                <tr>
                                    <td align="right"><?php echo TEXT_PAYPAL_MAILID;?>&nbsp;<span class="required">*</span></td>
                                    <td></td>
                                    <td><input type="text" class="textarea" value="<?php echo htmlentities(stripslashes($txtPaypalEmail));?>" name="txtPaypalEmail"  maxlength="100" onMouseOver="fixedtooltip('Please Enter Pay Pal Email Address .',this,event,'220px');" onMouseout="delayhidetip();"></td>
                                </tr>
                                
                                <tr>
                                    <td align="right"><?php echo TEXT_VACCATION_MODE;?>&nbsp;<span class="required">*</span></td>
                                    <td></td>
                                    <td>                                                                        
                                        <input type="radio" name="rdVaccationMode" value="Y" <?php if ($rdVacctionmode  == "Y") {   echo "checked"; } elseif($rdVacctionmode==NULL){echo "checked";}?>><?php echo TEXT_YES;?>                                   
                                        <input type="radio" name="rdVaccationMode" value="N" <?php if ($rdVacctionmode  == "N") {   echo "checked"; }?>><?php echo TEXT_NO;?>
                                    </td>
                                </tr>
                                
                                <tr>  <td colspan="3" align="center" class="text_information"> <?php echo  SELLER_VACATION_MODE_NOTE;?></td></tr>

                                <tr>
                                    <td colspan="3" align="center">
                                        <input type="submit" value="<?php echo BTN_SAVE_CHANGE;?>" name="btnSaveChanges"  class="button" >
                                    </td>
                                </tr>
                                <tr><td colspan="3">&nbsp;</td></tr>
                                <tr><td colspan="3">&nbsp;</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";
?>