<?php
$show_locale = false;

ob_start();
if (isset($tpl['locale_arr']))
{ 
	$cnt = count($tpl['locale_arr']);
	if ($cnt > 1)
	{
		$show_locale = true;
		$locale_id = $controller->pjActionGetLocale();
		?>
		<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12 pull-right text-right pjTsNav pjTsNavLanguage">
			<div class="btn-group" role="group" aria-label="navigation">
				<?php
				foreach ($tpl['locale_arr'] as $k => $locale)
				{ 
					?>
					<a href="#" data-id="<?php echo $locale['id']; ?>" class="btn btn-default pjTsBtn pjTsSelectorLocale<?php echo $locale_id==$locale['id'] ? ' pjTsBtnActive': NULL;?>">
						<img src="<?php echo PJ_INSTALL_URL . PJ_FRAMEWORK_LIBS_PATH; ?>pj/img/flags/<?php echo $locale['file']; ?>" alt="" />
					</a>
					<?php
				} 
				?>
			</div><!-- /.btn-group -->
		</div><!-- /.col-lg-4 col-md-4 col-sm-4 col-xs-12 pull-right text-right pjTsNav pjTsNavLanguage -->
		<?php
	}
}
$locale_content = ob_get_contents();
ob_end_clean();

ob_start();
if(!$controller->checkLogin())
{ 
	if($_GET['action'] == 'pjActionContact' || $_GET['action'] == 'pjActionAddTicket')
	{
		?>
		<a href="#" class="btn btn-default pjTsBtn pjTsMenuItem" data-hash="Login"><?php __('front_menu_login');?></a>
		<?php
	}
	if($_GET['action'] == 'pjActionForgotPassword')
	{
		if($tpl['option_arr']['o_post_ticket'] == 'everyone')
		{
			?>
			<a href="#" class="btn btn-default pjTsBtn pjTsMenuItem" data-hash="Contact"><?php __('front_menu_new_ticket'); ?></a>
			<?php
		} 
		?>
		<a href="#" class="btn btn-default pjTsBtn pjTsMenuItem" data-hash="Login"><?php __('front_menu_login');?></a>
		<?php
	}
	if($_GET['action'] == 'pjActionLogin' && $tpl['option_arr']['o_post_ticket'] == 'everyone')
	{
		if($tpl['option_arr']['o_post_ticket'] == 'everyone')
		{
			?>
			<a href="#" class="btn btn-default pjTsBtn pjTsMenuItem" data-hash="Contact"><?php __('front_menu_new_ticket'); ?></a>
			<?php
		} 
	}
}else{
	if($_GET['action'] == 'pjActionProfile')
	{
		?>
		<a href="#" class="btn btn-default pjTsBtn pjTsMenuItem" data-hash="Tickets"><?php __('front_menu_tickets'); ?></a>
		<a href="#" class="btn btn-default pjTsBtn pjTsMenuItem" data-hash="AddTicket"><?php __('front_menu_new_ticket'); ?></a>
		<?php
	}
	if($_GET['action'] == 'pjActionAddTicket')
	{
		?>
		<a href="#" class="btn btn-default pjTsBtn pjTsMenuItem" data-hash="Tickets"><?php __('front_menu_tickets'); ?></a>
		<a href="#" class="btn btn-default pjTsBtn pjTsMenuItem" data-hash="Profile"><?php __('front_menu_profile'); ?></a>
		<?php
	}
	if($_GET['action'] == 'pjActionIndex')
	{
		?>
		<a href="#" class="btn btn-default pjTsBtn pjTsMenuItem" data-hash="AddTicket"><?php __('front_menu_new_ticket'); ?></a>
		<a href="#" class="btn btn-default pjTsBtn pjTsMenuItem" data-hash="Profile"><?php __('front_menu_profile'); ?></a>
		<?php
	}
	?>
	<a href="#" class="btn btn-default pjTsBtn pjTsMenuItem" data-hash="Logout"><?php __('front_menu_logout'); ?></a>
	<?php
}
$menu_content = ob_get_contents();
ob_end_clean();
		
ob_start();
if($show_locale == false && $controller->checkLogin())
{ 
	?>
	<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12">
		<div class="form-horizontal pjTsForm">
			<div class="form-group">
				
				<input type="text" name="keyword" class="form-control pjTsSearchKeyword" value="<?php echo isset($_GET['keyword']) ? $_GET['keyword']: NULL;?>" placeholder="<?php __('front_search');?>"/>			
			</div><!-- /.form-group -->
		</div>
	</div>
	<?php
}
$search_content = ob_get_contents();
ob_end_clean();
	
if(!empty($locale_content) || !empty($menu_content) || !empty($search_content))
{
	?>
	<div class="row pjTsHeader">
		<?php
		if(!empty($locale_content))
		{
			echo $locale_content;
		}
		if(!empty($menu_content))
		{
			?>
			<div class="col-lg-8 col-md-8 col-sm-8 col-xs-12 pull-left pjTsNav">
				<div class="btn-group" role="group" aria-label="navigation">
					<?php echo $menu_content;?>
				</div><!-- /.btn-group -->
			</div><!-- /.col-lg-8 col-md-8 col-sm-8 col-xs-12 pull-left pjTsNav -->
			<?php
		}
		if(!empty($search_content))
		{
			echo $search_content;
		} 
		?>
	</div>
	<?php
}

if($show_locale == true && $controller->checkLogin())
{ 
	?>
	<div class="row pjTsHeader">
		<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12">
			<div class="form-horizontal pjTsForm">
				<div class="form-group">
					<input type="text" name="keyword" class="form-control pjTsSearchKeyword" value="<?php echo isset($_GET['keyword']) ? $_GET['keyword']: NULL;?>" placeholder="<?php __('front_search');?>"/>			
				</div><!-- /.form-group -->
			</div>
		</div>
	</div>
	<?php
} 
?>