<?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';?>
		
		<div class="panel panel-default pjCfBody pjCfResults">
			<header class="panel-heading pjCfResultsHead">
				<div class="row">
					<div class="col-lg-5 col-md-5 col-sm-6 col-xs-12">
						<p><?php __('front_category');?></p>
					</div><!-- /.col-lg-5 col-md-5 col-sm-6 col-xs-12 -->

					<div class="col-lg-7 col-md-7 col-sm-6 hidden-xs">
						<p><?php __('front_questions');?></p>
					</div><!-- /.col-lg-7 col-md-7 col-sm-6 hidden-xs -->
				</div><!-- /.row -->
			</header><!-- /.panel-heading pjCfResultsHead -->
			
			<ul class="list-group pjCfCategories pjCfResultsBody">
				<?php
				if(count($tpl['category_arr']) > 0)
				{
					foreach($tpl['category_arr'] as $v)
					{
						?>
						<li class="list-group-item pjCfTopick">
							<div class="row">
								<div class="col-lg-5 col-md-5 col-sm-6 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['id'];?>"><?php echo pjSanitize::html($v['name']);?></a></p><!-- /.label label-default pjCfCategoryType pjCfCategoryTypeGreen -->
									<?php
									if(!empty($v['description']))
									{ 
										?>
										<p><?php echo stripslashes(nl2br($v['description']));?></p>
										<?php
									} 
									?>
								</div><!-- /.col-lg-5 col-md-5 col-sm-6 col-xs-12 -->
	
								<div class="col-lg-7 col-md-7 col-sm-6 col-xs-12">
									<ul class="list-unstyled">
										<?php
										$question_arr = $v['question']; 
										foreach($question_arr as $q)
										{
											$seconds = $q['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=' . $q['id'];
											if($tpl['option_arr']['o_seo_url'] == 'Yes')
											{
												$path = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME']));
												$path = $path == '/' ? '' : $path;
												$url = $path .'/'. $controller->friendlyURL($q['question']) . "-". $q['id'] . ".html";
											}
											?>
											<li>
												<a href="<?php echo $url;?>"><?php echo pjSanitize::html($q['question']);?></a><span class="pjCfTopickActiveFrom"> <?php echo !empty($q['last_reply']) ? (!empty($ago_arr) ? join(" ", $ago_arr) : __('front_just_now', true)) : NULL;?></span>
											</li>
											<?php
										} 
										?>
									</ul><!-- /.list-unstyled -->
								</div><!-- /.col-lg-7 col-md-7 col-sm-6 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-5 col-md-5 col-sm-6 col-xs-12">
								<?php __('front_no_categories_found');?>
							</div>
						</div>
					</li>
					<?php
				}
				?>
			</ul><!-- /.list-group pjCfCategories pjCfResultsBody -->
			
		</div><!-- /.panel panel-default pjCfBody pjCfResults -->
		
	</div><!-- /.container-fluid pjCfContainer -->
</div><!-- /#pjWrapper -->

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