<?php
mt_srand();
$index = mt_rand(1, 9999);
?>
<div id="pjWrapper">
	<div class="container-fluid pjCfContainer">
		<?php 
		include_once PJ_VIEWS_PATH . 'pjLoad/elements/header.php';
		
		$column = 'last_reply';
		if(isset($_GET['column']))
		{
			$column = $_GET['column'];
		}
		?>
		
		<div class="panel panel-default pjCfBody pjCfResults">
			<header class="panel-heading pjCfResultsHead pjCfResultsFilters">
				<div class="row">
					<div class="col-lg-8 col-md-8 col-sm-8 col-xs-12">
						<div class="row">
							<div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
								<p><?php __('front_question');?></p>
							</div><!-- /.col-lg-9 col-md-9 col-sm-8 col-xs-12 -->
							
							<div class="col-lg-3 col-md-3 col-sm-4 hidden-xs">
								<a href="#" class="pjCfFilter<?php echo $column == 'category' ? ' pjCfActiveFilter' : NULL;?>" data-column="category" data-direction="<?php echo $column == 'category' ? (isset($_GET['direction']) ? ($_GET['direction'] == 'DESC' ? 'ASC' : 'DESC') : 'ASC' ) : 'ASC';?>">
									<?php __('front_category');?>
									<ul class="list-inline pjCfListCarets">
										<li<?php echo isset($_GET['direction']) ? ($_GET['direction'] == 'ASC' ? ' class="pjCfActive"' : NULL) : ' class="pjCfActive"';?>><i class="fa fa-caret-up"></i></li>
										<li<?php echo isset($_GET['direction']) ? ($_GET['direction'] == 'DESC' ? ' class="pjCfActive"' : NULL) : NULL;?>><i class="fa fa-caret-down"></i></li>
									</ul><!-- /.list-inline pjCfListCarets -->
								</a>
							</div><!-- /.col-lg-3 col-md-3 col-sm-4 hidden-xs -->
						</div><!-- /.row -->
					</div><!-- /.col-lg-8 col-md-8 col-sm-8 col-xs-12 -->

					<div class="col-lg-4 col-md-4 col-sm-4 hidden-xs">
						<div class="row">
							<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
								<p><?php __('front_posted_by');?></p>
							</div><!-- /.col-lg-4 col-md-4 col-sm-6 col-xs-12 -->
									
							<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
								<a href="#" class="pjCfFilter<?php echo $column == 'last_reply' ? ' pjCfActiveFilter' : NULL;?>" data-column="last_reply" data-direction="<?php echo (isset($_GET['direction']) ? ($column == 'last_reply' ? ($_GET['direction'] == 'DESC' ? 'ASC' : 'DESC') : 'ASC') : 'DESC' );?>">
									<?php __('front_activity');?>
									<ul class="list-inline pjCfListCarets">
										<li<?php echo isset($_GET['direction']) ? ($_GET['direction'] == 'ASC' ? ' class="pjCfActive"' : NULL) : ' class="pjCfActive"';?>><i class="fa fa-caret-up"></i></li>
										<li<?php echo isset($_GET['direction']) ? ($_GET['direction'] == 'DESC' ? ' class="pjCfActive"' : NULL) : NULL;?>><i class="fa fa-caret-down"></i></li>
									</ul><!-- /.list-inline pjCfListCarets -->
								</a>
							</div><!-- /.col-lg-4 col-md-4 col-sm-6 col-xs-12 -->
									
							<div class="col-lg-4 col-md-4 hidden-sm col-xs-12">
								<a href="#" class="pjCfFilter<?php echo $column == 'cnt_replies' ? ' pjCfActiveFilter' : NULL;?>" data-column="cnt_replies" data-direction="<?php echo $column == 'cnt_replies' ? (isset($_GET['direction']) ? ($_GET['direction'] == 'DESC' ? 'ASC' : 'DESC') : 'ASC' ) : 'ASC';?>">
									<?php __('front_replies');?>
									<ul class="list-inline pjCfListCarets">
										<li<?php echo isset($_GET['direction']) ? ($_GET['direction'] == 'ASC' ? ' class="pjCfActive"' : NULL) : ' class="pjCfActive"';?>><i class="fa fa-caret-up"></i></li>
										<li<?php echo isset($_GET['direction']) ? ($_GET['direction'] == 'DESC' ? ' class="pjCfActive"' : NULL) : NULL;?>><i class="fa fa-caret-down"></i></li>
									</ul><!-- /.list-inline pjCfListCarets -->
								</a>
							</div><!-- /.col-lg-4 col-md-4 hidden-sm col-xs-12 -->
						</div><!-- /.row -->
					</div><!-- /.col-lg-4 col-md-4 col-sm-4 hidden-xs -->
				</div><!-- /.row -->
			</header><!-- /.panel-heading pjCfResultsHead pjCfResultsFilters -->
			
			<ul class="list-group pjCfTopicks pjCfResultsBody">
				<?php
				if(count($tpl['question_arr']))
				{
					foreach($tpl['question_arr'] as $v)
					{						
						$seconds = $v['last_reply'];
						$diff_obj = pjUtil::secondsToTime($seconds);
						$ago_arr = array();
						if($diff_obj['days'] > 0)
						{
							$ago_arr[] = $diff_obj['days'] > 1 ? $diff_obj['days'] . ' ' . __('front_days', true) : $diff_obj['days'] . ' ' . __('front_day', true);
						}else{
							if($diff_obj['hours'] > 0)
							{
								$ago_arr[] = $diff_obj['hours'] > 1 ? $diff_obj['hours'] . ' ' . __('front_hours', true) : $diff_obj['hours'] . ' ' . __('front_hour', true);
							}
							if($diff_obj['minutes'] > 0)
							{
								$ago_arr[] = $diff_obj['minutes'] > 1 ?  $diff_obj['minutes'] . ' ' . __('front_minutes', true) : $diff_obj['minutes'] . ' ' . __('front_minute', true);
							}
						}
						
						$url = $_SERVER['PHP_SELF'] . '?controller=pjLoad&amp;action=pjActionView&amp;id=' . $v['id'];
						if($tpl['option_arr']['o_seo_url'] == 'Yes')
						{
							$path = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME']));
							$path = $path == '/' ? '' : $path;
							$url = $path .'/'. $controller->friendlyURL($v['question']) . "-". $v['id'] . ".html";
						}
						?>
						<li class="list-group-item pjCfTopick">
							<div class="row">
								<div class="col-lg-8 col-md-8 col-sm-8 col-xs-12">
									<div class="row">
										<div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
											<ul class="list-unstyled">
												<li class="pjCfTopickTitle">
													<a href="<?php echo $url;?>"><?php echo pjSanitize::html($v['question']);?></a>
												</li><!-- /.pjCfTopickTitle -->
												<p><?php echo pjSanitize::html($v['description']);?></p>
											</ul><!-- /.list-unstyled -->
										</div><!-- /.col-lg-9 col-md-9 col-sm-8 col-xs-12 -->
										
										<div class="col-lg-3 col-md-3 col-sm-4 col-xs-12">
											<p class="label label-default pjCfCategoryType" style="color: <?php echo $v['font_color']?>;background-color: <?php echo $v['background_color']?>;"><a style="color: <?php echo $v['font_color']?>;background-color: <?php echo $v['background_color']?>;" href="<?php echo $_SERVER['PHP_SELF'];?>?controller=pjLoad&amp;action=pjActionIndex&amp;category_id=<?php echo $v['category_id'];?>"><?php echo pjSanitize::html($v['category'])?></a></p><!-- /.label label-default pjCfCategoryType pjCfCategoryTypeOrange -->
										</div><!-- /.col-lg-3 col-md-3 col-sm-4 col-xs-12 -->
									</div><!-- /.row -->
								</div><!-- /.col-lg-8 col-md-8 col-sm-8 col-xs-12 -->
					
								<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12">
									<div class="row">
										<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
											<span class="visible-xs-inline"><?php __('front_by');?> </span>
											<p class="pjCfBtnTopicAuthor"><?php echo pjSanitize::html($v['name']);?></p>
										</div><!-- /.col-lg-4 col-md-4 col-sm-6 col-xs-12 -->
															
										<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
											<?php
											if(!empty($v['last_reply']))
											{ 
												?>
												<p><?php echo !empty($ago_arr) ? implode("<br/>", $ago_arr) : __('front_just_now', true);?></p>
												<?php
											} 
											?>
										</div><!-- /.col-lg-4 col-md-4 col-sm-6 col-xs-12 -->
															
										<div class="col-lg-4 col-md-4 hidden-sm hidden-xs">
											<p><strong><?php echo $v['cnt_replies'];?></strong></p>
										</div><!-- /.col-lg-4 col-md-4 hidden-sm hidden-xs -->
									</div><!-- /.row -->
								</div><!-- /.col-lg-4 col-md-4 col-sm-4 col-xs-12 -->
							</div><!-- /.row -->
						</li><!-- /.list-group-item pjCfTopick -->
						<?php
					}
				}else{
					?>
					<li class="list-group-item pjCfTopick">
						<div class="row">
							<div class="col-lg-8 col-md-8 col-sm-8 col-xs-12">
								<?php __('front_no_questions_found');?>
							</div>
						</div>
					</li>
					<?php 
				} 
				?>
			</ul><!-- /.list-group pjCfTopicks pjCfResultsBody -->
			<?php
			if(count($tpl['question_arr']))
			{
				include_once PJ_VIEWS_PATH . 'pjLoad/elements/pagination.php';
			}
			?>
		</div><!-- /.panel panel-default pjCfBody pjCfResults -->
	</div><!-- /.container-fluid pjCfContainer -->
</div><!-- /#pjWrapper -->

<?php include_once PJ_VIEWS_PATH . 'pjLoad/elements/loadjs.php';?>