<?php 
/* ---------Multicart 2.0 Upgradation starts---------- */
include_once("classes/cls_utils.php");
$username_flag = 1;
$password_flag = 0;
/* ---------Multicart 2.0 Upgradation ends---------- */
$currencylistObj  =     Utils::getActiveCurrencyList();
if($currencylistObj->status==SUCCESS)
    {
        $currencylistObjVals    =  $currencylistObj->data;
    }

function using_ie() {
    $u_agent = $_SERVER['HTTP_USER_AGENT'];
    $ub = False;
    if (preg_match('/MSIE/i', $u_agent)) {
        $ub = True;
    }

    return $ub;
}

$userLoggedoutmsg   =   '';

if(isset($_REQUEST['logoff']) && $_REQUEST['logoff']=='1')
{
    $userLoggedoutmsg   =   MSG_USER_LOGGED_OUT;
    //$_SESSION['LOGOUT_MESSAGE'] =   '';
}

if (isset($_POST['loginbox'])) {

    $txtUserName = $_POST["txtUserName"];

    $txtPassword = $_POST["txtPassword"];
    /* $sql=" SELECT user_id,user_name,password FROM ".$tableprefix."users WHERE user_name='".addslashes($txtUserName)."' AND password = '".addslashes(md5($txtPassword))."' AND deleted = 'N'";
      $result=mysql_query($sql) or die(mysql_error());
      if(mysql_num_rows($result) > 0 ){
      $row = mysql_fetch_array($result);
      $message="Success!";
      $_SESSION["sess_username"] = $row["user_name"];
      $_SESSION["sess_userid"] = $row["user_id"]; */

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


    /* ---------Checking the password---------------- */

    $select_password = "SELECT password
                              FROM " . $tableprefix . "users
                             WHERE LOWER(user_name) = " . strtolower(GetSQLValueString($txtUserName, "text")) . "
                               AND deleted = 'N'";

    $result_password = mysql_query($select_password) or die(mysql_error());
    if (mysql_num_rows($result_password) > 0) {

        $password_row = mysql_fetch_assoc($result_password);

        if (GetSQLValueString($password_row['password'], "text") != GetSQLValueString(md5($txtPassword), "text")) {

            //$messagelog = "Invalid password !!";
            $password_flag = 1;
        }
    }

    //else
    //{

    /* ---------Checking the username---------------- */

    $select_username = "SELECT user_name FROM " . $tableprefix . "users
							WHERE password = " . GetSQLValueString(md5($txtPassword), "text") .
            " AND deleted = 'N'";

    $result_username = mysql_query($select_username) or die(mysql_error());
    if (mysql_num_rows($result_username) > 0) {

        while ($username_row = mysql_fetch_array($result_username)) {

            if (strtolower(GetSQLValueString($username_row['user_name'], "text")) == strtolower(GetSQLValueString($txtUserName, "text"))) {
                $username_flag = 0;
            }
        }
    }

    if ($username_flag == 1 && $password_flag == 0) {
        $messagelog = INVALID_USERNAME_TEXT;
    }

    if ($username_flag == 1 && $password_flag == 1) {
        $messagelog = INVALID_PASSWORD_TEXT;
    }

    //}

    if ($username_flag != 1 && $password_flag != 1) {

        $sql = " SELECT user_id,user_name,password FROM " . $tableprefix . "users
				WHERE user_name='" . addslashes($txtUserName) . "' AND password = '" . addslashes(md5($txtPassword)) . "' AND deleted = 'N'";
        $result = mysql_query($sql) or die(mysql_error());
        if (mysql_num_rows($result) > 0) {
            $row = mysql_fetch_array($result);
            $message = "Success!";
            $_SESSION["sess_username"] = $row["user_name"];
            $_SESSION["sess_userid"] = $row["user_id"];

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

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


            manageSession(3);

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

            if (!isVisitorCartEmpty(session_id())) {
                mergeVisitorCartToUserCart(session_id(), $row["user_id"]);
            }
            if ($action != "") {
                if ($action == "checkout") {
                    echo "<script>location.href='viewcart.php';</script>";
                    //header("Location:viewcart.php");
                    exit;
                }
            } else {

                /* --------Multicart 2.0 starts----------- */

                /* echo "<script>location.href='usermain.php';</script>"; */

                $currentPage = GetCurrentPageName();

                $referer = $_SERVER['HTTP_REFERER'];

                echo "<script>location.href='" . $referer . "';</script>";

                /* --------Multicart 2.0 ends----------- */

                //header("Location:usermain.php");
                exit;
            }
        } else {
            $messagelog = INVALID_USERNAME_PASSWORD_TEXT;
        }
    }

    /* ----------Multicart 2.0 Upgradation ends----------- */
} else if (isset($_POST['newuser'])) {
    echo "<script>location.href='register.php';</script>";
    exit;
}
?>
<style type="text/css">
    .textfield_search{
        width:205px;
        border:1px solid #cfcfcf;
        padding:4px;
        color:#333333;
    }

</style>



<script language="javascript" type="text/javascript">


    function clearText(thefield,id){
        if (thefield.defaultValue==thefield.value)
            thefield.value = ""
        identity=document.getElementById(id);
        identity.className='textfield';
    }

    function clearText1(thefield,id){
        if (thefield.defaultValue==thefield.value)
            thefield.value = ""
        identity=document.getElementById(id);
        identity.className='textfield_search';
    }

    function openuserhelp()
    {

        var url = './help/userhelp/index.html'
        window.open(url,"Help","scrollbars=yes");
    }
    $(document).ready(function(){
        var ie7 = false;
       /* if ( $.browser.msie ) {
            if( $.browser.version == 7.0)
            {
                ie7 = true;
            }
        }*/


        if(ie7 == true)
        {
            $(".fandtlinks").css('margin','-12px');

        }


    });


</script>

<!--Hidden Fields for Ajax Data  Reference Do Not Delete-->
<input type="hidden" name="siteurl" id="siteurl" value="<?php echo SITE_URL;?>">
<input type="hidden" name="USER_ID"  id="USER_ID" value="<?php echo $_SESSION["sess_userid"];?>">
<input type="hidden" name="gusetLogin"  id="gusetLogin" value="<?php echo $_SESSION['guest_login'];?>">
<!--End Hidden Fileds-->
<div id="wrapper">
	<div class="container">
			<div class="row">
				<div class="col-sm-6 col-lg-4 col-md-4 ">
					<div class="logo_sec">
						<div class="logo">
							<a href="<?php echo SITE_URL ?>/index.php">
								<img src="<?php echo SITE_URL ?>/banners/<?php echo $logoimage ?>" alt=""  border="0" />
							</a>
						</div>
					</div>
				</div>
				<div class="col-sm-12 col-lg-8 col-md-8">
					<section>
						<div class="header_rt_top">
							<div class="row">
							<div class="header_rt_top_item_rt">
                            
							<div class="col-sm-12 col-lg-9 col-md-9">
								<div class="hdr_toprt_leftsec">
                                 <?php if($_SESSION["sess_artistid"]!='') { ?>
                              
                                <div class="sellerdash"><a href="<?php echo SITE_URL ?>/sellers/artistmain.php" ><?php  echo HOME_LINK_SELLER_DASHBOARD;?></a></div>
                               
                            <?php } ?>
                                
                                
                                
								<div class="header_rt_top_item_mycart">
									<a href="<?php echo SITE_URL ?>/viewcart.php">
									<?php echo CART_TEXT;?> 
									<span>
										<?php
													if ($_SESSION["sess_userid"] != "") {
														echo GetUserCartCount($_SESSION["sess_userid"]);
													} else {
														echo GetVisitorCartCount(session_id());
													}
										?> 
									</span>
									</a>
								</div>
								<div class="header_rt_top_item_login">
									
									
									 <?php if($userLoggedoutmsg!=''){ ?>
            
															<!--<span class="success_message" align="left"><?php echo $messagelog; ?></span>-->
															
															<?php } ?>
											   
									<?php
									if (isset($_SESSION["sess_userid"]) and $_SESSION["sess_userid"] != "") {
										
									} //else if (basename($_SERVER['PHP_SELF']) != "login.php" and $_SESSION['guest_login'] == '') {
									else if ($_SESSION['guest_login'] == '') {
										?>
										
											<a href="<?php echo SITE_URL?>/login.php">Login</a> / <a href="<?php echo SITE_URL?>/register.php">Sign Up</a>
											
													<?php /* User loginbox
													<div class="login_sec"><!-- onSubmit="return checkLoginForm();" -->
														<form name="frmLogin" action="<?php echo SITE_URL ?>/index.php" method="POST">
															
															<h6><?php echo USER_LOGIN_TEXT;?><span><?php echo $messagelog; ?></span></h6>
									
									
															<input name="txtUserName" type="text"  class="textfield2" value="" placeholder="<?php echo USERNAME_TEXT;?>" size="20"  id="txtUserName"/>
									
															<input name="txtPassword" type="password"  class="textfield2" value="" placeholder="<?php echo PASSWORD_TEXT;?>" size="20" id="txtPassword"/>
									
															<input name="loginbox" type="submit" class="button" value="<?php echo SUBMIT_BUTTON;?>" />
									
														</form>
									
														<p>&nbsp;<a href="register.php"><?php echo REGISTRATION_LINK_TEXT;?></a> &nbsp;|&nbsp;
															<a href="forgotpassword.php"><?php echo FORGOTPASSWORD_LINK_TEXT;?></a></p>
														<div class="clear"></div>
													</div>
													
													*/ ?>
													
													
									<?php } ?>
									<?php
									if ($_SESSION["sess_userid"] != "" && $_SESSION['guest_login'] == '') {		
									
										$select_user_name = "SELECT first_name,last_name,password FROM " . $tableprefix . "users WHERE user_id = " . $_SESSION["sess_userid"];									
										$result_user_name = mysql_query($select_user_name) or die(mysql_error());									
										if (mysql_num_rows($result_user_name) > 0) {									
											$user_name_row = mysql_fetch_assoc($result_user_name);
											?>
									
														<div class="login_sec2">
																<a href="<?php echo SITE_URL ?>/myaccount.php" class=""><?php echo $user_name_row['first_name'] ?>&nbsp;<?php echo $user_name_row['last_name'] ?></a> /
									
															
															<a href="<?php echo SITE_URL ?>/logout.php" class=""><?php echo LOGOUT_TEXT; ?></a>
									
														</div>
									
														<?php
													}
												} else { 
                                                                                                 
                                                                                                 
													if ((isset($_SESSION["guest_login"]) && $_SESSION['guest_login'] != '') || isset($_GET['guest_login']) ) {  
														?>
														<div class="login_sec2">
															<?php echo GUEST; ?>/
									
															<a href="<?php echo SITE_URL ?>/logout.php" ><?php echo LOGOUT_TEXT; ?></a>
														</div>
									
											<?php
										}
									}
									?>
									
												<?php /*
												
												<?php
												if (basename($_SERVER['PHP_SELF']) == "login.php" && $_SESSION["sess_userid"] == "") {
													?>
									
													<div class="login_sec"> &nbsp;</div>
									
												<?php } ?>
									
												*/ ?>
									
								</div>
								<div class="clear"></div>
								</div>
								
							</div>
                            

                           
                                                            
							

                            
                            <div class="col-sm-12 col-lg-3 col-md-3">
								<div class="header_rt_top_currency">
									<?php
										if ($adminCurrency['currency_code'] != '') {
											$currency_code = $adminCurrency['currency_code'];
										} else {
											$currency_code = 'USD';
										}
				
										if ($_SESSION['SESS_currency_type'] == '') {
											$_SESSION['SESS_currency_type'] = $adminCurrency['currency_code'];
										}
										?>
									<input type="hidden" value="<?php echo $currency_code; ?>" name="currency_type">
											<?php
											if (getSettingsValue('enable_multicurrency') == 'Y') {
												?>
										<form name="frmCurrencyType" method="post">
				
											<div class="topnavsec1">
											
												<select name="currency_type" class="topsearch_fld" onChange="Javascript:document.frmCurrencyType.submit();">
													<?php
													$currency_type = $_SESSION['SESS_currency_type'];
												//echo $currency_type;exit;
													if ($currency_type == '') {
														$currency_type = 'USD';
													}                                                              
												
													foreach($currencylistObjVals as $currency_row ) {
												
														if ($currency_type == $currency_row->vcurrency_code) {
												
															$currency_selected = "selected";
														} else {
															$currency_selected = "";
														}
														?>
														<option value="<?php echo $currency_row->vcurrency_code ?>" <?php echo $currency_selected ?>><?php echo $currency_row->vcurrency_name ?></option>
				
											<?php
										}
										?>
												</select>
											</div>
				
										</form>
									<?php } ?>
								</div>
								</div>
							</div>
							<div class="clear"></div>
							</div>
						</div>
					</section>
					<div class="clear"></div>
					<section>
						<?php
						if (strstr($_SERVER['SCRIPT_FILENAME'], 'index.php') == TRUE) {
							$link_selected_index = "activelink";
						} elseif (strstr($_SERVER['SCRIPT_FILENAME'], 'userfavorites.php') == TRUE) {
							$link_selected_favorites = "activelink";
						} elseif (strstr($_SERVER['SCRIPT_FILENAME'], 'categorydetail.php') == TRUE) {
							$link_selected_category = "activelink";
						} elseif (strstr($_SERVER['SCRIPT_FILENAME'], 'viewcart.php') == TRUE) {
							$link_selected_cart = "activelink";
						} elseif (strstr($_SERVER['SCRIPT_FILENAME'], 'postfeedback.php') == TRUE) {
							$link_selected_feedback = "activelink";
						} elseif (strstr($_SERVER['SCRIPT_FILENAME'], 'faq.php') == TRUE) {
							$link_selected_faq = "activelink";
						} elseif (strstr($_SERVER['SCRIPT_FILENAME'], 'about_us.php') == TRUE) {
							$link_selected_aboutus = "activelink";
						} elseif (strstr($_SERVER['SCRIPT_FILENAME'], 'contact_us.php') == TRUE) {
							$link_selected_contactus = "activelink";
						} elseif (strstr($_SERVER['SCRIPT_FILENAME'], 'help.php') == TRUE) {
							$link_selected_help = "activelink";
						} elseif (strstr($_SERVER['SCRIPT_FILENAME'], 'allseller.php') == TRUE) {
							$link_selected_sellers = "activelink";
						} elseif (strstr($_SERVER['SCRIPT_FILENAME'], 'site-feedback.php') == TRUE) {
							$link_selected_feedback = "activelink";
						}
						?>
					<nav class="navbar navbar-inverse" role="navigation">
						<div class="navbar-header">
							<button type="button" class="navbar-toggle toglemenu_blk" data-toggle="collapse" data-target=".navbar-ex1-collapse">
								<span class="sr-only">Toggle navigation</span>
								<span class="fleft">My Menu</span>
								<span class="togglemenu_rtsec">
									<span class="icon-bar"></span>
									<span class="icon-bar"></span>
									<span class="icon-bar"></span>
								</span>
							</button>
							
						</div>
						<!-- Collect the nav links, forms, and other content for toggling -->
						<div class="collapse navbar-collapse navbar-ex1-collapse">
							<ul class="nav navbar-nav">
								<li><a href="<?php echo SITE_URL ?>/index.php" class="<?php echo $link_selected_index ?>"><?php echo HOME_LINK;?></a></li>
                                                                
                                                                <?php /*$enablefavorite = getSettingsValue("enable_favourites");
                                                                if ($_SESSION["sess_userid"] != "" && $_SESSION['guest_login'] == '' && $enablefavorite =="Y") {	?>
                                                                <li><a href="<?php echo SITE_URL ?>/userfavorites.php" class="<?php echo $link_selected_favorites ?>"><?php echo FAVORITES_LINK;?></a></li>                                                                
                                                                <?php } */?>
								<li><a href="<?php echo SITE_URL ?>/categorydetail.php" class="<?php echo $link_selected_category ?>"><?php echo CATALOG_LINK;?></a></li>								
								<li><a href="<?php echo SITE_URL ?>/allseller.php" class="<?php echo $link_selected_sellers; ?>"><?php echo SELLER_LINK;?></a></li>
													<?php
													$enableAffiliate = getSettingsValue('enable_affiliates');
													if ($enableAffiliate == 'Y') {
														?>
									<li><a href="<?php echo SITE_URL ?>/affiliates/login.php"><?php echo AFFILIATES_LINK;?></a></li>
													<?php } ?>							
								<li><a href="<?php echo SITE_URL?>/contact_us.php" id="<?php echo $link_selected_index?>"><?php echo CONTACT_LINK ;?></a></li>
								
							</ul>
						</div>
						<!-- /.navbar-collapse -->
					</nav>
					</section>
				</div>
			</div>
        </div>
        <!-- /.container -->
		<div class="clear"></div>
	 	<!-- .greycat -->
		<div class="greycat">
		<div class="container">
			<div class="row">
				<div class="col-sm-6 col-lg-8 col-md-8 ">
					<?php
					include_once("includes/categorylist.php");
					?>
				</div>
				<div class="col-sm-6 col-lg-4 col-md-4 ">
					 <form action="<?php echo SITE_URL ?>/search.php" method="get" name="frmSearch">
                        <input name="chkProductName" type="hidden" value="on">
                        <input name="chkIncludeSubcategories" type="hidden" value="on">
                        <input name="sd" type="hidden" value="1">
                        	<div align="right" class="search_area">
								<input type="text" class="search_box" name="txtSearch" value="<?php echo isset($_REQUEST["txtSearch"])?stripslashes($_REQUEST["txtSearch"]):''; ?>" placeholder="<?php echo SEARCH_TEXT ?>" />
								<input name="Submit" type="submit" class="search_btn"   value=""/>
                        	</div>
                    </form>
				</div>
			</div>
		</div>
		</div>
	 	<!-- /.greycat -->
		
<!-- Content Area Start -->
    <div class="contentarea">
        <!-- content Area Right start -->
        <div class="">
