<?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 "../includes/arrays.inc.php";
include_once "../classes/cls_user.php";

$json = file_get_contents('http://getcitydetails.geobytes.com/GetCityDetails?fqcn='. getClientIP());
$json = file_get_contents('http://getcitydetails.geobytes.com/GetCityDetails?fqcn=182.72.159.3');
$data = json_decode($json);
$timezone = $data->geobytestimezone;

if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}
//=========================Select Details from Settings Table==================
$sql2 = "SELECT * FROM ".$tableprefix."settings "	;
$res2 = mysql_query($sql2);
if(mysql_num_rows($res2)!= 0) {
    $rw = mysql_fetch_array($res2);
    $artistcommission =$rw["artist_commission"] ;
    $sellerapproval=$rw["approve_sellers"];
    $defaultflatrate=$rw["default_flatrate"];
    $additionalflatrate=$rw["additional_flatrate"];
    if($sellerapproval==1) { // if approval is automatic then set Staus =Y
        $txtapprovesellers="Y";
    } // end if
    else { // if seller is not
        $txtapprovesellers="NN";
    } //end else

}
//=================================================================================

$txtUserName = $_POST["txtUserName"];
$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"];
$txtTimeZone    =   $_POST['txtTimeZone'];

if(!empty($txtStore)){
$txtStore = getStoreAlias($txtStore,$txtStore);
}
$adminCurrency	= GetAdminCurrency();
$txtCurrency = $adminCurrency['currency_code'];

$txtPaypalEmail = $_POST["txtPaypalEmail"];
$txtPaypalIDTOKEN= $_POST["txtPaypalIDTOKEN"];
$chkSandbox= $_POST["chkSandbox"];

if ($_POST["chkSandbox"]) {
    $chkSandbox = "Y";
} else {
    $chkSandbox = "N";
}

$registered = false;


if(isset($_POST["txtUserName"])) {

    $message = "" ;
    if (!isNotNull($txtUserName)) {
        $message .= VAL_MSG_UNAME;
    } else {
        $qry = "SELECT  LOWER(artist_name) FROM  " . $tableprefix . "artists WHERE artist_name='" . strtolower(addslashes($txtUserName)) . "' ";
        if (mysql_num_rows(mysql_query($qry)) > 0) {
            $message .= VAL_MSG_UNAME_EXIST;
        }
    }
    /*if (!isValidUsername($txtUserName)) {
        $message .= VAL_MSG_INVALID_UNAME;
    }*/
    if (!isNotNull($txtPassword)) {
        $message .= VAL_MSG_PASS_EMP;
    }
    if (!isNotNull($txtConfirmPassword)) {
        $message .= VAL_MSG_CPASS_EMP;
    }
    if (strcmp($txtPassword, $txtConfirmPassword) != 0) {
        $message .= VAL_MSG_PASS_MISS;
    }
    if (!isNotNull($txtStore)) {
        $message .= VAL_MSG_STORE_NAME;
    }
    if (!isNotNull($txtFirstName)) {
        $message .= VAL_MSG_FIRST_NAME;
    }
    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_COUNTRY;
    }
    if (!isNotNull($txtZIP)) {
        $message .= VAL_MSG_ZIP;
    }
  /*  elseif($txtZIP==0 || (strlen($txtZIP)!=5 && $ddlCountry=="US")) {
        $message .= "* Enter valid Zip code! <br>";
    }*/
    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 (!isNotNull($txtEmail)) {
        $message .= VAL_MSG_EMAIL;
    } else {
        if (!isValidEmail($txtEmail)) {
            $message .= VAL_MSG_INVALID_MAIL;
        }
    }
    //added for checking the whether seller plans are added after enabling it from admin
    $sql_sett1 = "SELECT enable_membership  FROM ".$tableprefix."settings ";
    $res1 = mysql_query($sql_sett1);
    $row1 = mysql_fetch_array($res1);
    if($row1["enable_membership"]=="Y") {

        $sql_plan_cnt_qury  = "SELECT COUNT(".$tableprefix."sellerPlans.plan_Id) AS SellerPlanCount
                                       FROM ".$tableprefix."sellerPlans";
        $plan_qry_rslt = mysql_query($sql_plan_cnt_qury) or die(mysql_error());
        if(mysql_num_rows($plan_qry_rslt) > 0) {
            $plan_cnt_rslt_set = mysql_fetch_object($plan_qry_rslt);
            $plan_count = $plan_cnt_rslt_set->SellerPlanCount;
        }
        if($plan_count == 0) {
            $message .= VAL_MSG_CONT_ADMIN;
        }
    }

    $row = mysql_fetch_array(mysql_query("SELECT enable_buyerToseller  FROM ".$tableprefix."settings "));

    if (!isNotNull($txtPaypalEmail)) {
        $message .= VAL_MSG_PAYPAL_MAIL;
    }//end if
    else {
        if (!isValidEmail($txtPaypalEmail)) {
            $message .= VAL_MSG_INVALID_PAYPAL;
        }//end if
    }//end else
    /* if (!isNotNull($txtPaypalIDTOKEN))
            {
                    $message .= "* Identity Token cannot be empty! <br>";
            }//end if*/


    $qry2 = "select email from  " . $tableprefix . "artists where email='" . addslashes($txtEmail) . "'";
    if (mysql_num_rows(mysql_query($qry2)) > 0) {
        $message .= "* The email address '".htmlentities($txtEmail)."' is already in use!. <br>";
    }
     /*echo $message;
    exit;*/

    if ($message != "") { // error
        $message = VAL_MSG_PLS_CORRECT . $message;
    }
    else { // no error so insert user details
        $sql_artists = "INSERT INTO ".$tableprefix."artists (
			artist_name,
			password,
			first_name,
			last_name,
			address1,
			address2,
			city,
			state,
			country,
			phone,
			fax,
			zip,
			email,
            commission,
			vseller_currency,
			date_registered,
			company,
                        storename,
			website,
			defaultflatrate,
			additionalflatrate,paypalemail,vapproved,seller_time_zone) VALUES (
			'".addslashes($txtUserName)."',
			'".addslashes(md5($txtPassword))."',
			'".addslashes($txtFirstName)."',
			'".addslashes($txtLastName)."',
			'".addslashes($txtAddress1)."',
			'".addslashes($txtAddress2)."',
			'".addslashes($txtCity)."',
			'".addslashes($txtState)."',
			'".addslashes($ddlCountry)."',
			'".addslashes($txtPhone)."',
			'".addslashes($txtFAX)."',
			'".addslashes($txtZIP)."',
			'".addslashes($txtEmail)."',
    		'".addslashes($artistcommission)."',
			'".addslashes($txtCurrency)."',
			now(),
			'".addslashes($txtCompany)."',
                        '".addslashes($txtStore)."',
			'".addslashes($txtWeb)."',
			'".$defaultflatrate."',
			'".$additionalflatrate."',
			'".$txtPaypalEmail."',
			'".addslashes($txtapprovesellers)."',
                        '".addslashes($txtTimeZone)."'
			)";

        $sql_sett = "SELECT enable_membership  FROM ".$tableprefix."settings ";
        $res = mysql_query($sql_sett);
        $row = mysql_fetch_array($res);
        if($row["enable_membership"]=="Y") {
            $sql_plan = "SELECT plan_Period,plan_SubscriptionCharge FROM ".$tableprefix."sellerPlans WHERE plan_Id =".$_POST['subOption'];
            $res = mysql_query($sql_plan);
            $res_data=mysql_fetch_array($res);
            if($res_data['plan_Period']=="F")
                $paymentFlag=0;
            else
                {
                    if($res_data['plan_SubscriptionCharge']>0)
                        $paymentFlag=1;
                    else
                        {
                            $paymentFlag=0;
                        }
                }
        }//end if
        if($paymentFlag==1) {
            unset($_SESSION['SESS_insertQry']);

            $_SESSION['SESS_insertQry'][]=$sql_artists;
            $_SESSION['SESS_insertQry'][]=$_POST['subOption'];
            $_SESSION['SESS_insertQry'][]=$_POST;
            header("Location:chooseYourPlan.php");
            exit();
        }//end if

        mysql_query($sql_artists) or die(mysql_error());
        $userid = mysql_insert_id();

        $artistid=$userid;
        $_SESSION["sess_artistid"] 	 = $userid;

        //$_SESSION["sess_artistid"] 	 = $userid;
        //Check for plan status and then update if user has selected free /trail plan.

        $row = mysql_fetch_array(mysql_query("SELECT enable_membership  FROM ".$tableprefix."settings "));
        if($row["enable_membership"]=="Y") {
            if($res_data['plan_Period']=="F") {
                //--------------------------------------------------------------------

                $sql = "UPDATE " .$tableprefix."artists SET sellerPlanID =".$_POST['subOption']." WHERE artist_id =".$artistid;
                mysql_query($sql);
                $orderid = mysql_insert_id();
                $noOfDays=30;
                $fromDate= date("Y-m-d");
                $endDate= date("Y-m-d",strtotime("+".$noOfDays." day"));

                $sql = "INSERT INTO " .$tableprefix."artists_membershipDetails (artist_id, artist_memStartDate, artist_memEndDate,plan_Id,plan_SubscriptionCharge) VALUES
						(".$artistid.",'".$fromDate."','".$endDate."',".$_POST['subOption'].",0)";
                mysql_query($sql);
                $orderid = mysql_insert_id();


            }//end if
            if($res_data['plan_Period']!="F" && $res_data['plan_SubscriptionCharge']<=0) {
                //--------------------------------------------------------------------

                $sql = "UPDATE " .$tableprefix."artists SET sellerPlanID =".$_POST['subOption']." WHERE artist_id =".$artistid;
                mysql_query($sql);
                $orderid = mysql_insert_id();
                if($res_data['plan_Period']=="Y")
                    $noOfDays=365;
                if($res_data['plan_Period']=="M")
                    $noOfDays=30;
                $fromDate= date("Y-m-d");
                $endDate= date("Y-m-d",strtotime("+".$noOfDays." day"));

                $sql = "INSERT INTO " .$tableprefix."artists_membershipDetails (artist_id, artist_memStartDate, artist_memEndDate,plan_Id,plan_SubscriptionCharge) VALUES
						(".$artistid.",'".$fromDate."','".$endDate."',".$_POST['subOption'].",0)";
                mysql_query($sql);
                $orderid = mysql_insert_id();


            }
        }//end if
        // ends here

        $userfullname = $txtFirstName;
        if($txtLastName != "") {
            $userfullname .= " ". $txtLastName;
        }
        $to = $txtEmail;

        /*---------Multicart 2.0 Upgradation------------*/

        $subject = MSG_SELLER_ACC.stripslashes(SITE_NAME);


        /*-------Email Template Reading Fuction Call--------*/

        $mailcontent = readEmailTemplate('seller_registration','artists');

        //echo $mailcontent;exit;
        $mailcontent = str_replace('[first_name]',$txtFirstName,$mailcontent);
        $mailcontent = str_replace('[last_name]',$txtLastName,$mailcontent);
        $mailcontent = str_replace('[user_name]',$txtUserName,$mailcontent);
        $mailcontent = str_replace('[password]',$txtPassword,$mailcontent);



        /*---------------Seller Login Url-------------------*/


        if($sellerapproval==3 ) { // check if seller approval is through Email - Activation
            $userid=base64_encode($userid);
            
            $mailcontent.="\r\n"."<font color='green'><b>".MSG_CLICK_LINK."</b></font>\r\n\n";
            $mailcontent.="\r\n"."<a href=".SITE_URL."/sellers_activation.php?aid=$userid&status='Y'>".MSG_CLICK_HERE."</a>\r\n\n";

        } // end email activation check
        if($sellerapproval==1) {
            $mailcontent .= "\r\n".MAIL_PLAN_PURCHASE_TEXT_CLICK."&nbsp;<a href=".SITE_URL."/sellers>".MAIL_PLAN_PURCHASE_TEXT_HERE."</a> ".MAIL_PLAN_PURCHASE_TEXT_TO_LOGIN."\r\n\n";
        }
        if($sellerapproval==2) {
            $mailcontent .= "\r\n\n\n\n\n"."<font color='green'><b>".MSG_ACC_APPRV_ADMIN.".</b></font>\r\n\n";
        }



        /*---------------Seller Login Url-------------------*/

        /*------------Seller Store Url---------------------*/

// send the friendly url in mail based on config settings

        if($enable_seller_friendly == "Y") {
            $select_seller_name = "SELECT artist_name FROM ".$tableprefix."artists WHERE artist_id = ".$artistid;
            $result_seller_name = mysql_query($select_seller_name) or die(mysql_error());

            if(mysql_num_rows($result_seller_name) > 0) {

                $seller_name_row = mysql_fetch_assoc($result_seller_name);
                $txtSellerName = $seller_name_row['artist_name'];
            }
            $friendly_url = SITE_URL."/store/".$txtSellerName;
        }
        else {
            $friendly_url = SITE_URL."/showportfolio.php?artistid=".$artistid;
        }

        $mailcontent .= "\r\n"."<font color='#FF0000'>".MAIL_PLAN_PURCHASE_TEXT_SELLER_STORE_URL."</font>"."\r\n\n";
        $mailcontent .= "<b>".$friendly_url."</b>\n\n";



        /*------------Seller Store Url---------------------*/


        $headers  = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
        $headers .= "From: ".SITE_EMAIL."<".SITE_EMAIL.">" . "\r\n";
        $headers .= "Reply-To: ".SITE_NAME."<".SITE_EMAIL.">" . "\r\n";
        $headers .= "Return-Path: ".SITE_NAME."<noreply@".SITE_EMAIL.">" . "\r\n";
        //$headers .= "Organization: ".SITE_NAME."\r\n";


        $mailcontent = nl2br($mailcontent);

        //$mail_send_details = "<html><head><link href='".SITE_URL."/style/template1-admin.css' rel='stylesheet' type='text/css'></head><body><center><div align='left' id='layout'><div align='left' class='header'><div align='left' class='logo'><img src=".$logofolder."/".$logoimage." width='125' height='39'/></div></div><div>".$mailcontent."</div></div><div align='left' class='clear_float'><img src=".$imagefolder."/clear.gif width=1 height=1/></div></div></div></center></body></html>";
        $mail_send_details = '<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <title >'.SITE_NAME.'</title>
  <link href="./themes/'. $active_template[4].' rel="stylesheet" type="text/css">
</head>
<body>

<table width="103%" cellspacing="10" cellpadding="0" bgcolor="#EAEAEA">
   <tr>
     <td align="center" valign="top">

         <table width="600" border="0" cellpadding="0" cellspacing="0" bordercolor="#EAEAEA" bgcolor="#FFFFFF" class="manage_table">
            <tr>
               <td align="right" >
              </td>
            </tr>
            <tr>
               <td valign="middle" align="left"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                 <tr>
                   <td  bgcolor="#EAEAEA" > <img src='.SITE_URL.'/banners/'.getSettingsValue('site_logo').' width="125" height="60"/></td>
                 </tr>
               </table></td>
            </tr>
            <tr>
              <td align="center" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="10">
                <tr>
                  <td align="left"><p>'.$mailcontent.'</p>
                  </td>
                </tr>
              </table></td>
            </tr>
            <tr>
               <td align="center" bgcolor="#EAEAEA" class="footer">
                  <p>&nbsp;</p>
              </td>
            </tr>
       </table>

     </td>
   </tr>
</table>


</body>
</html>';

       // $to         =   'armiatester@gmail.com';
        $mailsent = mail($to, $subject, $mail_send_details, $headers);

        // **********************************************************************Send Mail To Administrator


        $subject_admin = MAIL_NEW_SELLER_REG." ".SITE_NAME;

        /*-------Email Template Reading Fuction Call--------*/

        $mailcontent_admin = readEmailTemplate('seller_registration_admin','artists');

        $mailcontent_admin = str_replace('[user_name]',$txtUserName,$mailcontent_admin);

        $mailcontent_admin = str_replace('[password]',$txtPassword,$mailcontent_admin);

        $mailcontent_admin = str_replace('[firstname]',$txtFirstName,$mailcontent_admin);

        $mailcontent_admin = str_replace('[lastname]',$txtLastName,$mailcontent_admin);

        /*---------------User Login Url-------------------*/

        $mailcontent_admin .= "\r\n";
        $mailcontent_admin .= "\r\n".MAIL_PLAN_PURCHASE_TEXT_CLICK."&nbsp;<a href=".SITE_URL."/admin/login.php>".MAIL_PLAN_PURCHASE_TEXT_HERE."</a> ".MAIL_PLAN_PURCHASE_TEXT_TO_LOGIN_TO_VIEW_DETAILS."\r\n\n";

        /*---------------User Login Url-------------------*/

        $from= "From: ".SITE_EMAIL."\n";
        $headers  = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
        $headers .= "From: ".SITE_EMAIL."<".SITE_EMAIL.">" . "\r\n";
        $headers .= "Reply-To: ".SITE_NAME."<".SITE_EMAIL.">" . "\r\n";
        $headers .= "Return-Path: ".SITE_NAME."<".SITE_EMAIL.">"."\r\n";
        $headers .= "Organization: ".SITE_NAME."\r\n";

        $mailcontent_admin = nl2br($mailcontent_admin);

        //$mail_send_details_admin = "<html><head><link href='".SITE_URL."/style/template1-admin.css' rel='stylesheet' type='text/css'></head><body><center><div align='left' id='layout'><div align='left' class='header'><div align='left' class='logo'><img src=".$logofolder."/".$logoimage." width='125' height='39'/></div></div><div>".$mailcontent_admin."</div></div><div align='left' class='clear_float'><img src=".$imagefolder."/clear.gif width=1 height=1/></div></div></div></center></body></html>";



         $mail_send_details_admin = '<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <title >'.SITE_NAME.'</title>
  <link href="./themes/'. $active_template[4].' rel="stylesheet" type="text/css">
</head>
<body>

<table width="103%" cellspacing="10" cellpadding="0" bgcolor="#EAEAEA">
   <tr>
     <td align="center" valign="top">

         <table width="600" border="0" cellpadding="0" cellspacing="0" bordercolor="#EAEAEA" bgcolor="#FFFFFF" class="manage_table">
            <tr>
               <td align="right" >
              </td>
            </tr>
            <tr>
               <td valign="middle" align="left"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                 <tr>
                   <td  bgcolor="#EAEAEA" > <img src='.SITE_URL.'/banners/'.getSettingsValue('site_logo').' width="125" height="60"/></td>
                 </tr>
               </table></td>
            </tr>
            <tr>
              <td align="center" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="10">
                <tr>
                  <td align="left"><p>'.$mailcontent_admin.'</p>
                  </td>
                </tr>
              </table></td>
            </tr>
            <tr>
               <td align="center" bgcolor="#EAEAEA" class="footer">
                  <p>&nbsp;</p>
              </td>
            </tr>
       </table>

     </td>
   </tr>
</table>


</body>
</html>';


        $adminemail	=getSettingsValue('site_email');

        $mailsent = mail($adminemail, $subject_admin, $mail_send_details_admin, $headers);

        /*-------function call to manage the different sessions--------*/

        manageSession(2);

        if($sellerapproval==1) { // set for Autonmatic Aproval

            $_SESSION["sess_artistname"] = $txtUserName;
            $_SESSION["sess_artistid"] 	 = $userid;

            // Ending Session for User, Affiliates
            if(isset($_SESSION["sess_userid"]) and $_SESSION["sess_userid"]!= "") { // Logging Out User  from same window
              if(function_exists('session_unregister')){
                session_unregister($_SESSION["sess_userid"]);
              }
              else{
                  unset($_SESSION["sess_userid"]);
              }

            }
            if(isset($_SESSION["sess_affiliateid"]) and $_SESSION["sess_affiliateid"]!= "") { // Logging OutSeller  from same window
                if(function_exists('session_unregister')){
                   session_unregister($_SESSION["sess_artistid"]);
                }
                else{
                        unset($_SESSION["sess_artistid"]);
                }

            }
            // End check
            header("Location:artistmain.php");
            exit();
        } // end if
        //end if

        if($sellerapproval==3) { // Aproval After Email Confirmation
               $_SESSION["sess_artistid"] ='';
                unset($_SESSION['sess_artistid']);
            header("Location:validate.php?approval=3");
            exit;
        } // end if
        if($sellerapproval==2) { // Aproval After Email Confirmation
             $_SESSION["sess_artistid"] ='';
             unset($_SESSION['sess_artistid']);
            header("Location:validate.php?approval=2");
            exit;
        } // end if


        //$message = "Registration successfully completed! Please <a class='links' href='login.php'><b>login here.</b></a>";

        /*---------Multicart 2.0 Upgradation------------*/

        $txtUserName = "";
        $txtFirstName = "";
        $txtLastName = "";
        $txtAddress1 = "";
        $txtAddress2 ="";
        $txtCity = "";
        $txtState = "";
        $ddlCountry ="";
        $txtZIP = "";
        $txtEmail ="";
        $txtPhone = "";
        $txtFAX ="";
        $txtPassword = "";
        $txtConfirmPassword = "";
        $registered= true;

    }
}
$countrylist = makeCountryList();

/*------------Selecting the added currencies by Admin-------------------*/

$select_currency = "SELECT vcurrency_name,vcurrency_code
					FROM ".$tableprefix."currency_master WHERE vactive = 'Y'";
$result_currency = mysql_query($select_currency) or die(mysql_error());


/*------------Selecting the added currencies by Admin-------------------*/


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

// Check whether Seller Plans Enabled or not
$row_mebership= mysql_fetch_array(mysql_query("SELECT enable_membership  FROM ".$tableprefix."settings "));

if($row_mebership["enable_membership"]=="Y") {
    $sql_Plans = "SELECT plan_Id, plan_Title,plan_Description,plan_Status,plan_SubscriptionCharge
		    FROM ".$tableprefix."sellerPlans WHERE plan_Status='Y'";
    $res_Plans = mysql_query($sql_Plans) or die(mysql_error());

    $sellerPlanRows	= mysql_num_rows($res_Plans);
}
$adminCurrency	= GetAdminCurrency();

$txtCurrency = $adminCurrency['currency_code'];
$deafultCountry  = $currencyBasedCountries[$txtCurrency];

if($_SESSION["sess_userid"]!='') {
        $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;
                    if($activated_seller_id>0)
                        {
                             $seller_activated_status   =   'Y';
                        }
            }
}
?>
<script src="../js/jquery.js"></script>
<script type="text/javascript">
    $( document ).ready(function() {

        var storeURL = $.trim($("input[name='txtStore']").val());
        var storeURLNew = "";

        if(storeURL!=""){

            storeURLNew = storeURL.replace(/[^a-z0-9-\s]/gi, '').replace(/[_\s]/g, '-');
        }


        $('#mashable').html(storeURLNew);
        $("input[name='txtStore']").val(storeURLNew);

        $("input[name='txtStore']").keyup(function() {
            storeURL = $.trim($("input[name='txtStore']").val());
            if(storeURL!=""){


            storeURLNew = storeURL.replace(/[^a-z0-9-\s]/gi, '').replace(/[_\s]/g, '-');
            $('#mashable').html(storeURLNew);
            $("input[name='txtStore']").val(storeURLNew);
            } else {
                var user = $("input[name='txtUserName']").val();
                var userNew = user.replace(/[^a-z0-9-\s]/gi, '').replace(/[_\s]/g, '-');
                $('#mashable').html(userNew);
            }
        });
    });

</script>
<script src="../js/registration_ajax.js"></script>
<script src="../js/javascript_check.js"></script>
<script type="text/javascript" language="javascript1.1">

    function init() {
        document.getElementById('txtUserName').focus();
    }
    window.onload = init;

    function checkSellerFriendly()
    {

        if(document.frmRegister.checkFriendly.value == "Y")
        {

            if(document.frmRegister.txtUserName.value != "")
            {
                document.getElementById("mashable").innerHTML = trimSpaces(document.frmRegister.txtUserName.value);
            }//end if
        }//end if
    }//end function

<?php
$row = mysql_fetch_array(mysql_query("SELECT enable_buyerToseller FROM ".$tableprefix."settings "));
if($row["enable_buyerToseller"]=="Y") {
    ?>
        function checkArtistRegisterForm()
        {


            var form_name = new Array('txtUserName','txtPassword','txtConfirmPassword','txtStore','txtCompany','txtFirstName','txtLastName','txtAddress1','bill_country','bill_state','txtCity','txtZIP','txtPhone','txtEmail','txtPaypalEmail');
            var display_name = new Array('<?php echo TEXT_USER_NAME;?>','<?php echo TEXT_PASS;?>','<?php echo TEXT_CONF;?><?php echo TEXT_PASS;?>','<?php echo TEXT_STORE;?>','<?php echo TEXT_COMPANY;?>','<?php echo TEXT_FIRST_NAME;?>','<?php echo TEXT_LAST_NAME;?>','<?php echo TEXT_ADDR1;?>','<?php echo COUNTRY_TEXT; ?>','<?php echo TEXT_STATE; ?>','<?php echo TEXT_CITY;?>','<?php echo TEXT_ZIP;?>','<?php echo TEXT_PHONE;?>','<?php echo TEXT_EMAIL;?>','<?php echo TEXT_PAYPAL_MAILID;?>');
            var count = 13;
            var email = document.frmRegister.txtEmail.value;
            var phone = document.frmRegister.txtPhone.value;
			var msgappend="<?php echo VAL_MSG_REQ; ?>";

            if(check_fields('frmRegister',form_name,display_name,count,msgappend))
            {
                if(email != '')
                {
                    if(!echeck(email))
                    {
                        return false;
                    }
                }
                showListArtistRegistration(document.frmRegister.txtUserName.value,document.frmRegister.txtEmail.value);
            }//end if
            else
            {
                return false;
            }//end else


        }//end function
    <?php
}//end if
else {
    ?>
        function checkArtistRegisterForm()
        {
            var form_name = new Array('txtUserName','txtPassword','txtConfirmPassword','txtStore','txtCompany','txtFirstName','txtLastName','txtAddress1','bill_country','bill_state','txtCity','txtZIP','txtPhone','txtEmail','txtPaypalEmail');
            var display_name = new Array('<?php echo TEXT_USER_NAME;?>','<?php echo TEXT_PASS;?>','<?php echo TEXT_CONF;?><?php echo TEXT_PASS;?>','<?php echo TEXT_STORE;?>','<?php echo TEXT_COMPANY;?>','<?php echo TEXT_FIRST_NAME;?>','<?php echo TEXT_LAST_NAME;?>','<?php echo TEXT_ADDR1;?>','<?php echo COUNTRY_TEXT; ?>','<?php echo TEXT_STATE; ?>','<?php echo TEXT_CITY;?>','<?php echo TEXT_ZIP;?>','<?php echo TEXT_PHONE;?>','<?php echo TEXT_EMAIL;?>','<?php echo TEXT_PAYPAL_MAILID;?>');
            var count = 14;
            var email = document.frmRegister.txtEmail.value;
            var phone = document.frmRegister.txtPhone.value;

            if(check_fields('frmRegister',form_name,display_name,count))
            {
                if(email != '')
                {
                    if(!echeck(email))
                    {
                        return false;
                    }
                }
                showListArtistRegistration(document.frmRegister.txtUserName.value,document.frmRegister.txtEmail.value);
            }//end if
            else
            {
                return false;
            }//end else


        }//end function
    <?php
}//end else
?>


    function numbersonly(e){
        var unicode=e.charCode? e.charCode : e.keyCode
        if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
            if (unicode<48||unicode>57) //if not a number
                return false //disable key press
        }
    }


</script>

	<link href="<?php echo $site_url; ?>/themes/<?php echo $active_template[4] ?>" rel="stylesheet" type="text/css">
	<link href="<?php echo $site_url; ?>/themes/responsive/css/commonstyle.css" rel="stylesheet" type="text/css">
	<link href="<?php echo $site_url; ?>/themes/responsive/css/bootstrap.min.css" rel="stylesheet" type="text/css">
	<link href="<?php echo $site_url; ?>/themes/responsive/css/bootstrap.css" rel="stylesheet" type="text/css">
	<link href="<?php echo $site_url; ?>/style/bootstrap-modal-bs3patch.css" rel="stylesheet" type="text/css">
	<link href="<?php echo $site_url; ?>/style/bootstrap-modal.css" rel="stylesheet" type="text/css">
	<link href="<?php echo $site_url; ?>/themes/responsive/css/font-awesome.css" rel="stylesheet" type="text/css">
	<link href="<?php echo $site_url; ?>/themes/responsive/css/font-awesome.min.css" rel="stylesheet" type="text/css">
	
	<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
	<script type="text/javascript" language="javascript" src="<?php echo $site_url; ?>/themes/responsive/js/bootstrap.js"></script>
	<script type="text/javascript" language="javascript" src="<?php echo $site_url; ?>/themes/responsive/js/bootstrap.min.js"></script>
	<script type="text/javascript" language="javascript" src="<?php echo $site_url; ?>/js/bootstrap-modalmanager.js"></script>
	<script type="text/javascript" language="javascript" src="<?php echo $site_url; ?>/js/bootstrap-modal.js"></script>
	<script type="text/javascript" language="javascript" src="<?php echo $site_url; ?>/themes/responsive/js/responsivemobilemenu.js"></script>
	<script type="text/javascript" language="javascript" src="<?php echo $site_url; ?>/themes/responsive/js/responsive-tables.js"></script>
				
<script>


    var xmlhttp1;

    function showDesc(str)
    {
        xmlhttp1=GetXmlHttpObject1();

        var subOption=str;
        //document.getElementById("subOption").value;
        if(subOption!=""){
            if (xmlhttp1==null)
            {
                alert ("<?php echo ALERT_HTTP;?>");
                return;
            }
            var url="getPlanDetails.php";
            url=url+"?planID="+subOption;
            url=url+"&sid="+Math.random();
            xmlhttp1.onreadystatechange=stateChanged1;
            xmlhttp1.open("GET",url,true);
            xmlhttp1.send(null);
        }else{
            document.getElementById('showDisc').style.display = "none";

        }
    }

    function stateChanged1()
    {
        if (xmlhttp1.readyState==4)
        {
            var resText=xmlhttp1.responseText;
            var resText=resText.split("~IscriptsIamamcdelimiterIscripts~");
            document.getElementById('planCharge').innerHTML="<strong>"+resText[3]+"&nbsp;&nbsp;(<?php echo $adminCurrency['currency_symbol'];?> "+resText[1]+")</strong>";
            document.getElementById('palnID').value=resText[0];
            document.getElementById('planDescription').innerHTML=resText[2];
            document.getElementById('showDisc').style.display = "block";

        }
    }

    function GetXmlHttpObject1()
    {
        if (window.XMLHttpRequest)
        {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            return new XMLHttpRequest();
        }
        if (window.ActiveXObject)
        {
            // code for IE6, IE5
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
        return null;
    }
</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")
                        ?>
                <?php
                if($_POST['bill_state']!='') {
                    $bill_state	= $_POST['bill_state'];
                }
                ?>
				
				<div class="col-sm-12 col-lg-4 col-md-4"></div>
				
				<div class="col-sm-12 col-lg-4 col-md-4">
					<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">
								<h3><?php echo TEXT_SELLER_REG;?></h3>								
								
								<form name="frmRegister" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"], ENT_QUOTES, 'UTF-8')?>" 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 -->
								<?php
								$ddlCountry = $ddlCountry == ""?$deafultCountry:$ddlCountry;
								?>
								<input type="hidden" value="<?php echo $ddlCountry;?>" name="billCountryDefault" id="billCountryDefault">
								<input type="hidden" value="<?php echo $bill_state;?>"   name="billStateDefault"   id="billStateDefault">
								<SCRIPT type="text/javascript" SRC="../js/country-state.js"></SCRIPT>
								<?php
                                                                if($seller_activated_status=='N') {
                                                                    ?>
                                                                        <div class="field_wrapper formfield_row">
											<div class="createacc_link">
												<p>
													<span class="required">*</span>&nbsp;<?php echo SELLER_PREVILEGE_ACTIVATION_NOTE;?>
												</p>
											</div>
									</div>
                                                                <?php
                                                                }
								if(!$registered) {
	
									?>
									<div class="sellerreg_styles">
									<?php
                                    if($row_mebership["enable_membership"]=="Y" && $sellerPlanRows==0) {

                                        ?>
	                                	<div class="field_wrapper formfield_row"><?php echo VAL_MSG_NO_ACTIVE_PLAN;?> <?php echo getSettingsValue('site_email');?> .</div>
                                    <?php
                                    }
                                    else {
                                        ?>
										
										<div class="field_wrapper formfield_row">
											<div class="createacc_link">
												<p>
													<span class="required">*</span>&nbsp;<?php echo MSG_FIELD_MANDATORY;?>
												</p>
											</div>	
										</div>
										
										<?php
                                            if($row_mebership["enable_membership"]=="Y") {

                                                if($sellerPlanRows>0) {
                                                    $seller_plan_id = mysql_result($res_Plans,0,'plan_Id')	;
                                                    @mysql_data_seek($res_Plans,0);
                                                    ?>
										<script language="javascript">
											showDesc(<?php echo $seller_plan_id;?>);
										</script>								
										<div class="field_wrapper formfield_row">
											<label><?php echo TEXT_MEMBER_TYPE;?> <span class="required">*</span></label>
											<select name="subOption" id="subOption" class="form-control" onchange="showDesc(this.value)">
											<!--<option value="">Choose your plan here</option> -->
													<?php

													while($data_plan=mysql_fetch_array($res_Plans)) {
														$subCharge=number_format($data_plan['plan_SubscriptionCharge'],2,".","");
														echo '<option value="'.$data_plan['plan_Id'].'"';
														echo	'>'.$data_plan['plan_Title'].'['.$adminCurrency['currency_symbol'] .'&nbsp;'.$subCharge.']</option>';
													}//end while loop
													?>			</select>
												<?php
											}//end if
											?>
										</div>
										
										<div class="field_wrapper formfield_row">
											<div id="showDisc" style="display:none;">
												<div class="sel_plantype">
													<div align="justify" id="planCharge"></div>
													<div align="justify" id="planDescription"></div>											
												</div>
											</div>
										</div>
										<input type="hidden" name="palnID"  id="palnID" value="">
                                                <?php
                                            }//end if
                                            ?>
										<div class="field_wrapper formfield_row">
											<label><?php echo TEXT_USER_NAME;?>&nbsp;<span class="required">*</span></label>
											<input class="form-control" type="text" value="<?php echo $txtUserName;?>" name="txtUserName" id="txtUserName"  maxlength="100" onKeyDown="checkSellerFriendly();" onChange="checkSellerFriendly();" onKeyUp="checkSellerFriendly();" >
                                            <input type="hidden" name="checkFriendly" value="<?php echo $enable_seller_friendly?>">
										</div>
										<!--Multicart 2.0 Upgradation Starts-->
										<?php
											if($enable_seller_friendly == "Y") {
										?>										
										<div class="field_wrapper formfield_row">
											<label><?php echo TEXT_SELLER_STORE_URL;?></label>
											<span class="storeurl">
											<?php echo SITE_URL?>/store/<span id="mashable"></span>
											</span>
										</div>
										<?php
                                            }
                                         ?>
                                    	<!--Multicart 2.0 Upgradation Ends-->
										
										<div class="field_wrapper formfield_row">
											<label><?php echo TEXT_PASS;?> <span class="required">*</span></label>
											<input class="form-control" type="password" value="" name="txtPassword"  maxlength="30">
										</div>										
										<div class="field_wrapper formfield_row">
											<label><?php echo TEXT_CONF;?><?php echo TEXT_PASS;?> <span class="required">*</span></label>
											<input class="form-control" type="password" value="" name="txtConfirmPassword"  maxlength="30">
										</div>
										<div class="field_wrapper formfield_row">
											<label><?php echo TEXT_STORENAME;?> <span class="required">*</span></label>
											<label><?php echo stripslashes($txtStore);?></label>
											<input name="txtStore" type="text" class="form-control" id="txtStore" value="<?php echo stripslashes($txtStore);?>"  maxlength="20">
										</div>
										<div class="field_wrapper formfield_row">
											<label><?php echo TEXT_COMPANY;?> <span class="required">*</span></label>
											<input name="txtCompany" type="text" class="form-control" id="txtCompany" value="<?php echo $txtCompany; ?>"  maxlength="20">
										</div>
										<div class="field_wrapper formfield_row">
											<label><?php echo TEXT_FIRST_NAME;?> <span class="required">*</span></label>
											<input class="form-control" type="text" value="<?php echo $txtFirstName;?>" name="txtFirstName"  maxlength="100">
										</div>
										<div class="field_wrapper formfield_row">
											<label><?php echo TEXT_LAST_NAME;?> <span class="required">*</span></label>
											<input class="form-control" type="text" value="<?php echo $txtLastName;?>" name="txtLastName"  maxlength="100">
										</div>
										<div class="field_wrapper formfield_row">
											<label><?php echo TEXT_ADDR1;?> <span class="required">*</span></label>
											<input class="form-control" type="text" value="<?php echo $txtAddress1;?>" name="txtAddress1"  maxlength="100">
										</div>
										<div class="field_wrapper formfield_row">
											<label><?php echo TEXT_ADDR2;?></label>
											<input type="text" class="form-control" value="<?php echo $txtAddress2;?>" name="txtAddress2"  maxlength="100">
										</div>
										<div class="field_wrapper formfield_row">
											<label><?php echo TEXT_COUNTRY;?> <span class="required">*</span></label>
											<select id='billCountrySelect' name='bill_country'  class='form-control' onchange='updateState(this.id)' style="width:100%;"></select>
										</div>
										<div class="field_wrapper formfield_row">
											<label><?php echo TEXT_STATE;?><span class="required">*</span></label>
											<select id='billStateSelect' class='form-control' name='bill_state' style="width:100%;">
                                        	</select> <SCRIPT  type="text/javascript">initCountry(); </SCRIPT>
										</div>
										<div class="field_wrapper formfield_row">
											<label><?php echo TEXT_CITY;?>&nbsp;<span class="required">*</span></label>
											<input type="text" class="form-control" value="<?php echo $txtCity;?>" name="txtCity"  maxlength="100">
										</div>
										<div class="field_wrapper formfield_row">
											<label><?php echo TEXT_ZIP;?>&nbsp;<span class="required">*</span></label>
											<input type="text" value="<?php echo $txtZIP;?>" class="form-control" name="txtZIP"  maxlength="20">
										</div>
										<div class="field_wrapper formfield_row">
											<label><?php echo TEXT_WEBSITE;?></label>
											<input name="txtWeb" type="text" class="form-control" id="txtWeb" value="<?php echo $txtWeb;?>"  maxlength="20">
										</div>
										<div class="field_wrapper formfield_row">
											<label><?php echo TEXT_PHONE;?> <span class="required">*</span></label>
											<!-- onkeypress="return numbersonly(event)" --><input type="text" value="<?php echo $txtPhone;?>" class="form-control" name="txtPhone"  maxlength="100"   />
										</div>
										<div class="field_wrapper formfield_row">
											<label><?php echo TEXT_FAX;?></label>
											<input type="text" value="<?php echo $txtFAX;?>" class="form-control" name="txtFAX"  maxlength="100">
										</div>
										<div class="field_wrapper formfield_row">
											<label><?php echo TEXT_EMAIL;?>&nbsp;<span class="required">*</span></label>
											<input name="txtEmail" type="text" class="form-control" value="<?php echo $txtEmail;?>" size="40"  maxlength="100">
										</div>
                                                                                <div class="field_wrapper formfield_row">
											<label><?php echo TEXT_TIME_ZONE;?>&nbsp;<span class="required">*</span></label>
                                                                                        <?php echo makeTimeZoneList('form-control');?>
                                                                                </div>
										<!--
										<div class="field_wrapper formfield_row">
											<label>Currency&nbsp;<span class="required">*</span></label>
											<select name="txtCurrency" class="textarea">
												<?php
												if(mysql_num_rows($result_currency) > 0) {
													while($result_currency_row = mysql_fetch_array($result_currency)) {
													?>
												<option value="<?php echo $result_currency_row['vcurrency_code']?>"><?php echo $result_currency_row['vcurrency_name']?></option>
													<?php
													}
												}
												?>
											</select>
										</div>
																				
										<?php
                                            $row = mysql_fetch_array(mysql_query("SELECT enable_buyerToseller FROM ".$tableprefix."settings "));
                                        ?>
										<div class="field_wrapper formfield_row">
											<label><input type="checkbox" id="chkSandbox" name="chkSandbox" <?php if (isset($chkSandbox) and ($chkSandbox == "Y")) {
                                                echo " CHECKED ";} ?>> Paypal Sandbox/Test mode (Uncheck to change to real mode)
											</label>
											Start a new account
											<a href="https://www.paypal.com/us/mrb/pal=NCGEZ2VF6YL62" target="_blank"><img src="../images/paypal_small.jpg" width="77" height="30" border="0" alt="Start A New Account" title="Start A New Account"></a>
										</div>
										-->
										<div class="field_wrapper formfield_row">
											<label><?php echo TEXT_PAYPAL_MAILID;?>&nbsp;<span class="required">*</span></label>
											<input type="text" class="form-control" value="<?php echo $txtPaypalEmail;?>" name="txtPaypalEmail"  maxlength="100" onMouseOver="fixedtooltip('<?php echo PAYPAL_EMAIL_ADDRESS_TOOLTIP; ?>',this,event,'220px');" onMouseout="delayhidetip();">
										</div>
										<div class="field_wrapper formfield_row">
											<input type="button" value="<?php echo BTN_BACK;?>" class="login_btn" name="Back" onClick="Javascript:history.go(-1);">
                                            <input type="button" value="<?php echo BTN_REG;?>" class="login_btn" name="btnRegister" onClick="return checkArtistRegisterForm();">
										</div>
										
										<?php } // end else Plan Enabled check ?>
	                                <div class="clear"></div>
									</div>
								 <?php
									}
									else {		
										?>
										<div class="text_information grey_trtext_information grey_tr" align="center"><?php echo $message;?></div>
										<?php
									}
		
									?>
								</form>
							<div class="clear"></div>
							</div>
						</div>
					</div>
				</div>
				
				<div class="col-sm-12 col-lg-4 col-md-4"></div>
				<div class="clear"></div>
            </div>
			

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