<?php
mt_srand();
$index = mt_rand(1, 9999);
$path = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME']));
$path = $path == '/' ? '' : $path;
$action = "";
if($tpl['option_arr']['o_seo_url'] == 'Yes')
{
	if(empty($tpl['option_arr']['o_job_page']))
	{
		$action = $path . '/job-home.html';
	}else{
		$action = $tpl['option_arr']['o_job_page'];
	}
}
?>
<div id="pjWrapper">
	<div class="container-fluid pjJlContainer">
		<?php include_once dirname(__FILE__) . '/elements/header.php';?>
		
		<div class="pjJlBody">
			<form action="<?php echo $action;?>" id="pjJLQuickSearch_<?php echo $index; ?>" method="get">
				<?php
				if ($tpl['option_arr']['o_seo_url'] == 'No' || ($tpl['option_arr']['o_seo_url'] == 'Yes' && !empty($tpl['option_arr']['o_job_page'])) )
				{ 
					?>
					<input type="hidden" name="controller" value="pjLoad" />
					<input type="hidden" name="action" value="pjActionJobs" />
					<?php
				} 
				?>
				<input type="hidden" name="job_search" value="1" />
				
				<?php include_once dirname(__FILE__) . '/elements/search.php';?>
				
				<div class="row pjJlResults">
					<?php include_once dirname(__FILE__) . '/elements/filter.php';?>

					<div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
						<div class="clearfix">
							<?php
							if($tpl['paginator']['total'] > 0)
							{ 
								?>
								<div class="pull-left pjJlResultsCounter">
									<p>
										<?php 
										if(count($tpl['arr']) < $tpl['paginator']['total'])
										{
											echo sprintf(__('front_search_result_of', true, true), '<strong> ' . count($tpl['arr']) . '</strong>', '<strong>' . $tpl['paginator']['total'] . '</strong>');
										}else{
											echo sprintf(__('front_search_result', true, true), '<strong> ' . count($tpl['arr']) . '</strong>');
										}
										if($tpl['has_filter'] == true)
										{
											if ($tpl['option_arr']['o_seo_url'] == 'No')
											{
												$home_url = $_SERVER['PHP_SELF'] . '?controller=pjLoad&amp;action=pjActionJobs';
											} else {
												if(empty($tpl['option_arr']['o_job_page']))
												{
													$home_url = $path .'/job-home.html';
												}else{
													$home_url = $tpl['option_arr']['o_job_page'];
												}
											}
											?>&nbsp;&nbsp;(<a href="<?php echo $home_url; ?>"><?php echo mb_strtolower(__('front_clear_filters', true), 'UTF-8');?></a>)<?php
										}
										?>
									</p>
								</div><!-- /.pull-left pjJlResultsCounter -->
	
								<div class="pull-right form-inline pjJlForm pjJlResultsSort">
									<div class="form-group">
										<label for=""><?php __('front_sort_by');?>: </label>
										
										<div class="form-control pjJlCustomSelect">
											<span class="caret"></span>
	
											<select name="sort_by" id="pjJLSortBy_<?php echo $index;?>">
												<?php
												foreach(__('sort_by', true) as $k => $v)
												{
													?><option value="<?php echo $k;?>"<?php echo isset($_GET['sort_by']) ? ($_GET['sort_by'] == $k ? ' selected="selected"' : NULL) : ($k == 'date' ? ' selected="selected"' : NULL);?>><?php echo $v;?></option><?php
												} 
												?>
											</select>
										</div><!-- /.form-control pjJlCustomSelect -->
									</div><!-- /.form-group -->
								</div><!-- /.pull-right form-inline pjJlForm pjJlResultsSort -->
								<?php
							}else{
								if ($tpl['option_arr']['o_seo_url'] == 'No')
								{
									$home_url = $_SERVER['PHP_SELF'] . '?controller=pjLoad&amp;action=pjActionJobs';
								} else {
									if(empty($tpl['option_arr']['o_job_page']))
									{
										$home_url = $path .'/job-home.html';
									}else{
										$home_url = $tpl['option_arr']['o_job_page'];
									}
								}
								?><p><?php __('front_label_no_found');?>  <?php if($tpl['has_filter'] == true) {?><a href="<?php echo $home_url; ?>"><?php __('front_clear_filters');?></a><?php }?></p><?php
							} 
							?>
						</div><!-- /.clearfix -->
						
						<?php
						if($tpl['paginator']['total'] > 0)
						{ 
							?>
							<div class="list-group pjJlListResults">
								<?php
								foreach ($tpl['arr'] as $v)
								{
									$job_title = pjSanitize::html($v['job_title']);
									if ($tpl['option_arr']['o_seo_url'] == 'No')
									{
										$url = $_SERVER['SCRIPT_NAME'] . '?controller=pjLoad&amp;action=pjActionView&amp;id=' . $v['id'] .(isset($_GET['iframe']) ? '&amp;iframe' : NULL);
									} else {
										$url = $path .'/'. $controller->friendlyURL($v['job_title']) . "-". $v['id'] . ".html";
									}
									$logo_url = '';
									if(!empty($v['logo']))
									{
										if(file_exists(PJ_INSTALL_PATH . $v['logo']))
										{
											$logo_url = PJ_INSTALL_URL . $v['logo'];
										}
									}
									$map = array(
										1 => 'pjJlResultTypeLightGreen',
										2 => 'pjJlResultTypeRed',
										3 => 'pjJlResultTypeBlue',
										4 => 'pjJlResultTypeOrange',
										5 => 'pjJlResultTypePurple',
										6 => 'pjJlResultTypeGreen'
									);
									?>
									<a href="<?php echo $url;?>" class="list-group-item pjJlResult">
										<div class="row">
											<?php
											if($logo_url != '')
											{ 
												?>
												<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pjJlResultImage">
													<img src="<?php echo $logo_url;?>" alt="" />
												</div><!-- /.col-lg-2 col-md-2 col-sm-2 col-xs-2 pjJlResultImage -->
												<?php
											} 
											?>
	
											<div class="<?php echo $logo_url != '' ? 'col-lg-10 col-md-10 col-sm-10 col-xs-10 pjJlResultContent' : 'col-lg-12 col-md-12 col-sm-12 col-xs-12 pjJlResultContent';?>">
												<div class="clearfix">
													<span class="pull-right label label-default pjJlResultType <?php echo $map[$v['type_id']]; ?>"><?php echo $v['type_title'];?></span>
													
													<p class="text-capitalize pjJlResultTitle"><?php echo html_entity_decode($job_title);?></p><!-- /.pjJlResultTitle -->
												</div><!-- /.clearfix -->
	
												<p class="pjJlResultSubTitle"><?php echo pjSanitize::html($v['category']);?></p><!-- /.pjJlResultSubTitle -->
	
												<ul class="list-inline pjJlResultMeta">
													<li>
														<dl>
															<dt><?php __('front_posted_on');?>: </dt>
															<dd class="text-capitalize"><?php echo date($tpl['option_arr']['o_date_format'], strtotime($v['created']));?></dd>
														</dl>
													</li>
													<?php
													if(!empty($v['company_name']))
													{
														?>
														<li>
															<dl>
																<dt><?php __('front_label_company_name');?>: </dt>
																<dd class="text-capitalize"><?php echo pjSanitize::html($v['company_name']);?></dd>
															</dl>
														</li>
														<?php
													}
													if(!empty($v['lang_city'])) 
													{
														?>
														<li>
															<dl>
																<dt><?php __('front_location');?>: </dt>
																<dd class="text-capitalize"><?php echo pjSanitize::html($v['lang_city']);?></dd>
															</dl>
														</li>
														<?php
													}else{
														if(!empty($v['address_city']))
														{
															?>
															<li>
																<dl>
																	<dt><?php __('front_location');?>: </dt>
																	<dd class="text-capitalize"><?php echo pjSanitize::html($v['address_city']);?></dd>
																</dl>
															</li>
															<?php
														}
													} 
													?>
												</ul><!-- /.list-inline pjJlResultMeta -->
												
												<p>
													<?php
													$description = str_replace("&nbsp;", " ", $v['job_description']);
													echo pjUtil::truncateDescription(pjUtil::html2txt(html_entity_decode($description)), 300, ' ');
													?>
												</p>
	
												<div class="pjJlResultActions">
													<button type="button" class="btn btn-default pjJlBtn pjJlBtnPrimary pjJlBtnViewDetails"><?php __('front_btn_view_details');?></button>
												</div><!-- /.pjJlResultActions -->
											</div><!-- /.col-lg-10 col-md-10 col-sm-10 col-xs-10 pjJlResultContent -->
										</div><!-- /.row -->
									</a>
									<?php
								} 
								?>
							</div><!-- /.list-group pjJlListResults -->
							<?php
							include_once dirname(__FILE__) . '/elements/pagination.php';
						} 
						?>
						
					</div><!-- /.col-lg-9 col-md-9 col-sm-8 col-xs-12 -->
				</div><!-- /.row pjJlResults -->
			</form>
		</div><!-- /.pjJlBody -->
	</div><!-- /.container-fluid pjJlContainer -->
</div><!-- /.pjWrapper -->