<?php
$action_url =  $_SERVER['PHP_SELF'];
if ($tpl['option_arr']['o_seo_url'] == 'Yes')
{
    $path = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME']));
    $path = $path == '/' ? '' : $path;
    $action_url = $path . '/index.html';
}
?>
<form id="frmYPFilterSort_<?php echo $index;?>" name="frmYPFilterSort" action="<?php echo $action_url; ?>" method="get">
	<?php
	if ($tpl['option_arr']['o_seo_url'] == 'No')
	{
		?>
		<input type="hidden" name="controller" value="pjListings" />
		<input type="hidden" name="action" value="pjActionIndex" />
		<?php
	}
	?>
	<input type="hidden" name="sortby" value="title" />
	<input type="hidden" name="direction" value="asc" />
    <div class="row pjYpResultsActions">
    	<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 pjYpOrderBy">
    		<p><?php __('label_order_by');?></p>
    		<?php
    		if(!isset($_GET['sortby']))
    		{
    			$_GET['sortby'] = 'title';
    			$_GET['direction'] = 'asc';
    		}
    		?>
    		<ul class="list-inline">
    			<?php
    			if(isset($_GET['sortby']) && $_GET['sortby'] == 'title')
    			{ 
    				?>
    				<li class="active">
    					<a href="#" data-sortby="title" data-direction="<?php echo isset($_GET['sortby']) ? ($_GET['sortby'] == 'title' ? ($_GET['direction'] == 'desc' ? 'asc' : 'desc') : 'asc') : 'asc'; ?>" class="pjYpSortby<?php echo isset($_GET['direction']) ? ' pjYpOrder' . ucfirst($_GET['direction']) : ' pjYpOrderAsc';?>">
    						<?php __('label_alphabetically');?>
    						<span class="caret"></span>
    					</a>
    				</li>
    				<?php
    			} else {
    				?>
    				<li>
    					<a href="#" data-sortby="title" data-direction="<?php echo isset($_GET['sortby']) ? ($_GET['sortby'] == 'title' ? ($_GET['direction'] == 'desc' ? 'asc' : 'desc') : 'asc') : 'asc'; ?>" class="pjYpSortby">
    						<?php __('label_alphabetically');?>
    					</a>
    				</li>
    				<?php
    			}
    			if(isset($_GET['sortby']) && $_GET['sortby'] == 'created')
    			{
    				?>
    				<li class="active">
    					<a href="#" data-sortby="created" data-direction="<?php echo isset($_GET['sortby']) ? ($_GET['sortby'] == 'created' ? ($_GET['direction'] == 'asc' ? 'desc' : 'asc') : 'desc') : 'desc'; ?>" class="pjYpSortby<?php echo isset($_GET['direction']) ? ' pjYpOrder' . ucfirst($_GET['direction']) : ' pjYpOrderAsc';?>">
    						<?php __('label_date_added');?>
    						<span class="caret"></span>
    					</a>
    				</li>
    				<?php
    			} else {
    				?>
    				<li>
    					<a href="#" data-sortby="created" data-direction="<?php echo isset($_GET['sortby']) ? ($_GET['sortby'] == 'created' ? ($_GET['direction'] == 'asc' ? 'desc' : 'asc') : 'desc') : 'desc'; ?>" class="pjYpSortby">
    						<?php __('label_date_added');?>
    					</a>
    				</li>
    				<?php
    			}
    			?>
    		</ul><!-- /.list-inline -->
    	</div><!-- /.col-lg-6 col-md-6 col-sm-6 col-xs-12 pjYpOrderBy -->
    
    	<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 pjYpFilters">
    		<select id="pjYpCategory_<?php echo $index;?>" name="category_id" class="form-control" data-url="<?php echo $filter_url;?>">
    			<option value=""><?php __('label_filter_by_category');?></option>
    			<?php
    			foreach($tpl['category_arr'] as $v)
    			{
    				?><option value="<?php echo $v['id']?>"<?php echo isset($_GET['category_id']) ? ($_GET['category_id'] == $v['id'] ? 'selected="selected"' : null ) : null;?>><?php echo $v['name'];?> (<?php echo $v['number_of_listings'];?>)</option><?php
    			} 
    			?>
    		</select>
    	</div><!-- /.col-lg-6 col-md-6 col-sm-6 col-xs-12 pjYpFilters -->
    </div><!-- /.row pjYpResultsActions -->
</form>