<?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';
		if(isset($_SESSION[$controller->defaultReturn]) && !empty($_SESSION[$controller->defaultReturn]))
		{
			?>
			<input type="hidden" id="pjCfQuestionID_<?php echo $index; ?>" name="question_id" value="<?php echo $tpl['arr']['id'];?>" />
			<?php
			$reply_id = $_SESSION[$controller->defaultReturn]['rid'];
			if((int) $reply_id > 0)
			{
				?>
				<input type="hidden" id="pjCfReplyID_<?php echo $index; ?>" name="reply_id" value="<?php echo $reply_id;?>" />
				<?php
			}
			$_SESSION[$controller->defaultReturn] = array();
			unset($_SESSION[$controller->defaultReturn]);
		}
		if(isset($tpl['arr']))
		{ 
			$title = pjSanitize::html(stripslashes($tpl['arr']['question']));
			$minus_name = $controller->friendlyURL($title, '-');
			$plus_name = str_replace('-', "+", $minus_name);
			$url = str_replace("&", "%26", pjUtil::getPageURL());
			?>
			<div class="pjCfBody">
				<div class="panel panel-default pjCfTopickInner">
					<div class="panel-body pjCfTopickInnerBody">
						<div class="clearfix">
							<div class="pull-left pjCfTopickCategory">
								<span class="label label-default pjCfCategoryType" style="color: <?php echo $tpl['arr']['font_color']?>;background-color: <?php echo $tpl['arr']['background_color']?>;"><a style="color: <?php echo $tpl['arr']['font_color']?>;background-color: <?php echo $tpl['arr']['background_color']?>;" href="<?php echo $_SERVER['PHP_SELF'];?>?controller=pjLoad&amp;action=pjActionIndex&amp;category_id=<?php echo $tpl['arr']['category_id'];?>"><?php echo pjSanitize::html($tpl['arr']['category']);?></a></span><!-- /.label label-default pjCfCategoryType pjCfCategoryTypeOrange -->
							</div><!-- /.pull-left pjCfTopickCategory -->
				
							<div class="pull-right pjCfSocials">
								<ul class="list-inline">
									<li>
										<a href="https://www.facebook.com/sharer.php?u=<?php echo $url;?>&t=<?php echo $plus_name;?>" class="pjCfLinkFacebook" target="_blank">
											<i class="fa fa-facebook"></i>
										</a>
									</li>
				
									<li>
										<a href="https://twitter.com/intent/tweet?source=webclient&text=<?php echo $plus_name; ?>&url=<?php echo $url?>" class="pjCfLinkTwitter" target="_blank">
											<i class="fa fa-twitter"></i>
										</a>
									</li>
				
									<li>
										<a href="https://www.linkedin.com/shareArticle?mini=true&url=<?php echo $url?>&title=<?php echo $plus_name; ?>&source=<?php echo $url?>" class="pjCfLinkLinkedIn" target="_blank">
											<i class="fa fa-linkedin"></i>
										</a>
									</li>
								</ul>
							</div><!-- /.pull-right pjCfSocials -->
						</div><!-- /.clearfix -->
				
						<p class="pjCfTopickInnerTitle"><?php echo pjSanitize::html($tpl['arr']['question']);?> </p><!-- /.pjCfTopickInnerTitle -->
				
						<p class="pjCfTopickInnerMeta"><?php __('front_posted_by');?> <span><?php echo pjSanitize::html($tpl['arr']['name']);?></span> - <?php echo date($tpl['option_arr']['o_date_format'], strtotime($tpl['arr']['created'])) . ', ' . date($tpl['option_arr']['o_time_format'], strtotime($tpl['arr']['created']));?></p><!-- /.pjCfTopickInnerMeta -->
						<p></p>
						<div><?php echo nl2br(stripslashes($tpl['arr']['description']));?></div>
					</div><!-- /.panel-body pjCfTopickInnerBody -->
					
					<footer class="panel-footer pjCfCommentFoot">
						<?php
						if($tpl['can_reply'] == true)
						{ 
							?>
							<a href="#" class="pjCfReply" data-id=""><?php __('front_reply');?></a>
							<?php
						}else{
							?>
							<a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjLoad&amp;action=pjActionLogin&amp;qid=<?php echo $tpl['arr']['id']; ?>"><?php __('front_reply');?></a>
							<?php
						} 
						?>
					</footer><!-- /.panel-footer pjCfCommentFoot -->
				</div><!-- /.panel panel-default pjCfTopickInner -->
				
				<?php
				if(count($tpl['reply_arr']) > 0)
				{
					if(isset($_SESSION[$controller->defaultShowReply]) && $_SESSION[$controller->defaultShowReply])
					{
						?><input type="hidden" id="pjCfShowReply_<?php echo $index; ?>" name="show_reply_id" value="<?php echo $_SESSION[$controller->defaultShowReply];?>" /><?php
						unset($_SESSION[$controller->defaultShowReply]);
					}
					foreach($tpl['reply_arr'] as $v)
					{
						$avatar = PJ_INSTALL_URL . PJ_IMG_PATH . 'frontend/imgo.jpg';
						if(!empty($v['avatar_path']))
						{
							$avatar = PJ_INSTALL_URL . $v['avatar_path'];
						}
						?>
						<ul class="list-unstyled pjCfComments">
							<li id="pjCfComment_<?php echo $v['id']?>" class="pjCfComment">
								<div class="row">
									<div class="col-lg-2 col-md-2 col-sm-3 hidden-xs pjCfCommentImage">
										<img src="<?php echo $avatar;?>" alt="" />
									</div><!-- /.col-lg-2 col-md-2 col-sm-3 hidden-xs pjCfCommentImage -->
									
									<div class="col-lg-10 col-md-10 col-sm-9 col-xs-12">
										<div class="panel panel-default pjCfCommentContent">
											<header class="panel-heading clearfix pjCfCommentHead">
												<div class="pull-left">
													<p class="pjCfCommentAuthor">
														<span><?php echo $v['name'];?></span>
													</p><!-- /.pjCfCommentAuthor -->
						
													<p class="pjCfCommentMeta"><?php echo date($tpl['option_arr']['o_date_format'], strtotime($v['created'])) . ', ' . date($tpl['option_arr']['o_time_format'], strtotime($v['created']))?></p><!-- /.pjCfCommentMeta -->
												</div><!-- /.pull-left -->
						
												<div class="pull-right pjCfCommentActions">
													<ul class="list-inline">
														<?php
														if($tpl['can_rating'] == true)
														{ 
															?>
															<li class="pjCfLinkLike">
																<a href="#" class="pjCfVote" data-id="<?php echo $v['id']?>" data-vote="up">
																	<span id="pjCfLike_<?php echo $v['id'];?>"><?php echo $v['likes'];?></span>
																	<i class="fa fa-thumbs-up"></i>
																</a>
															</li>
							
															<li class="pjCfLinkDisLike">
																<a href="#" class="pjCfVote" data-id="<?php echo $v['id']?>" data-vote="down">
																	<i class="fa fa-thumbs-down"></i>
																	<span id="pjCfDisLike_<?php echo $v['id'];?>"><?php echo $v['dislikes'];?></span>
																</a>
															</li>
															<?php
														}
														if($tpl['option_arr']['o_reporting'] == 'yes')
														{ 
															?>
															<li>
																<a href="#" class="pjCfReport" data-id="<?php echo $v['id']?>"><i class="fa fa-exclamation-triangle"></i></a>
															</li>
															<?php
														}
														?>
													</ul><!-- /.list-inline -->
												</div><!-- /.pull-right pjCfCommentActions -->
											</header><!-- /.panel-heading clearfix pjCfCommentHead -->
						
											<div class="panel-body pjCfCommentBody">
												<?php echo stripslashes(nl2br(pjUtil::replaceURL($v['description'])));?>
											</div><!-- /.panel-body pjCfCommentBody -->
											<footer class="panel-footer pjCfCommentFoot">
												<?php
												if($tpl['can_reply'] == true)
												{ 
													?>
													<a href="#" class="pjCfReply" data-id="<?php echo $v['id']?>"><?php __('front_reply');?></a>
													<?php
												}else{
													?>
													<a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjLoad&amp;action=pjActionLogin&amp;qid=<?php echo $tpl['arr']['id']; ?>&amp;rid=<?php echo $v['id']; ?>"><?php __('front_reply');?></a>
													<?php
												} 
												?>
											</footer><!-- /.panel-footer pjCfCommentFoot -->
										</div><!-- /.panel panel-default pjCfCommentContent -->
										
										<?php
										if(!empty($tpl['sub_reply_arr'][$v['id']]))
										{
											?>
											<ul class="list-unstyled pjCfComments">
												<?php
												foreach($tpl['sub_reply_arr'][$v['id']] as $sub)
												{
													$avatar = PJ_INSTALL_URL . PJ_IMG_PATH . 'frontend/imgo.jpg';
													if(!empty($sub['avatar_path']))
													{
														$avatar = PJ_INSTALL_URL . $sub['avatar_path'];
													}
													?>
													<li id="pjCfComment_<?php echo $sub['id']?>" class="pjCfComment">
														<div class="row">
															<div class="col-lg-2 col-md-2 col-sm-3 hidden-xs pjCfCommentImage">
																<img src="<?php echo $avatar;?>" alt="" />
															</div><!-- /.col-lg-2 col-md-2 col-sm-3 hidden-xs pjCfCommentImage -->
								
															<div class="col-lg-10 col-md-10 col-sm-9 col-xs-12">
																<div class="panel panel-default pjCfCommentContent">
																	<header class="panel-heading clearfix pjCfCommentHead">
																		<div class="pull-left">
																			<p class="pjCfCommentAuthor">
																				<span><?php echo $sub['name'];?></span>
																			</p><!-- /.pjCfCommentAuthor -->
								
																			<p class="pjCfCommentMeta"><?php echo date($tpl['option_arr']['o_date_format'], strtotime($sub['created'])) . ', ' . date($tpl['option_arr']['o_time_format'], strtotime($sub['created']))?></p><!-- /.pjCfCommentMeta -->
																		</div><!-- /.pull-left -->
								
																		<div class="pull-right pjCfCommentActions">
																			<ul class="list-inline">
																				<?php
																				if($tpl['can_rating'] == true)
																				{ 
																					?>
																					<li class="pjCfLinkLike">
																						<a href="#" class="pjCfVote" data-id="<?php echo $sub['id']?>" data-vote="up">
																							<span id="pjCfLike_<?php echo $sub['id'];?>"><?php echo $sub['likes'];?></span>
																							<i class="fa fa-thumbs-up"></i>
																						</a>
																					</li>
													
																					<li class="pjCfLinkDisLike">
																						<a href="#" class="pjCfVote" data-id="<?php echo $sub['id']?>" data-vote="down">
																							<i class="fa fa-thumbs-down"></i>
																							<span id="pjCfDisLike_<?php echo $sub['id'];?>"><?php echo $sub['dislikes'];?></span>
																						</a>
																					</li>
																					<?php
																				}
																				if($tpl['option_arr']['o_reporting'] == 'yes')
																				{ 
																					?>
																					<li>
																						<a href="#" class="pjCfReport" data-id="<?php echo $sub['id']?>"><i class="fa fa-exclamation-triangle"></i></a>
																					</li>
																					<?php
																				} 
																				?>
																			</ul><!-- /.list-inline -->
																		</div><!-- /.pull-right pjCfCommentActions -->
																	</header><!-- /.panel-heading clearfix pjCfCommentHead -->
								
																	<div class="panel-body pjCfCommentBody">
																		<?php echo stripslashes(nl2br(pjUtil::replaceURL($sub['description'])));?>
																	</div><!-- /.panel-body pjCfCommentBody -->
								
																</div><!-- /.panel panel-default pjCfCommentContent -->
															</div><!-- /.col-lg-10 col-md-10 col-sm-9 col-xs-12 -->
														</div><!-- /.row -->
													</li><!-- /.pjCfComment -->
													<?php
												} 
												?>
											</ul><!-- /.list-unstyled pjCfComments -->
											<?php
										} 
										?>
									</div><!-- /.col-lg-10 col-md-10 col-sm-9 col-xs-12 -->
									
								</div><!-- /.row -->
							</li><!-- /.pjCfComment -->
						</ul><!-- /.list-unstyled pjCfComments -->
						<?php
					}
					if(count($tpl['reply_arr']))
					{
						?>
						<div class="pjCfActions">
							<div class="row">
								<div class="col-lg-offset-2 col-lg-10 col-md-offset-2 col-md-10 col-sm-12 col-xs-12">
									<?php include_once PJ_VIEWS_PATH . 'pjLoad/elements/reply_pagination.php';?>
								</div>
							</div>
						</div>
						<?php
					}
				} 
				?>	
			</div><!-- /.pjCfBody -->
			<?php
		}else{
			$front_err = pjSanitize::clean(__('front_err', true));
			?>
			<div class="pjCfBody">
				<div class="panel panel-default pjCfTopickInner">
					<div class="panel-body pjCfTopickInnerBody">
						<?php echo $front_err[$tpl['status']];?>
					</div>
				</div>
			</div>
			<?php
		} 
		?>
		<div class="modal fade pjCfReportModal" id="pjCfReportModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
		  	<div class="modal-dialog" role="document">
		    	<div class="modal-content">
		      		<div class="modal-body">
		        		<?php __('front_report_message');?>
		      		</div>
		      		<div class="modal-footer">
		        		<button type="button" class="btn btn-default pjCfBtn pjCfBtnSecondary" data-dismiss="modal"><?php __('front_btn_cancel');?></button>
		        		<button id="pjCfReportButton_<?php echo $index;?>" type="button" class="btn btn-default pjCfBtn pjCfBtnPrimary" data-id=""><?php __('front_btn_report');?></button>
		      		</div>
		    	</div>
		  	</div>
		</div>
	</div><!-- /.container-fluid pjCfContainer -->
</div><!-- /#pjWrapper -->

<?php
$image = PJ_INSTALL_URL . PJ_IMG_PATH . 'frontend/imgo.jpg';
if($controller->checkLogin())
{
	$USER = $_SESSION[$controller->defaultFrontUser];
	if(!empty($USER['avatar_path']))
	{
		$image = PJ_INSTALL_URL . $USER['avatar_path'];
	}
} 
?>

<div id="pjCfPostReplyClone_<?php echo $index;?>" style="display: none;">
	<ul id="pjCfCommentsReply_{INDEX}" class="list-unstyled pjCfComments pjCfCommentsReply">
		<li class="pjCfComment">
			<div class="row">
				<div class="col-lg-2 col-md-2 col-sm-3 hidden-xs pjCfCommentImage">
					<img src="<?php echo $image;?>" alt="" />
				</div><!-- /.col-lg-2 col-md-2 col-sm-3 hidden-xs pjCfCommentImage -->

				<div class="col-lg-10 col-md-10 col-sm-9 col-xs-12">
					<form id="pjCfReplyForm_{INDEX}" data-toggle="validator" role="form">
						<input type="hidden" name="post_reply" value="1" />
						<input type="hidden" name="category_id" value="<?php echo $tpl['arr']['category_id'];?>" />
						<input type="hidden" name="question_id" value="<?php echo $tpl['arr']['id'];?>" />
						<input type="hidden" name="reply_id" value="" />
						<input type="hidden" name="redirect_url" value="<?php echo pjUtil::getPageURL();?>" />
						
						<div class="panel panel-default pjCfCommentContent pjCfForm pjCfFormComment">
							<header class="panel-heading clearfix pjCfCommentHead">
								<div class="pull-left">
									<p><strong><?php __('front_post_a_reply');?></strong></p>
								</div><!-- /.pull-left -->
								<div class="pull-right pjCfCommentActions">
									<?php
									if($controller->checkLogin())
									{
										?><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjLoad&amp;action=pjActionProfile"><?php __('front_menu_my_account');?></a><?php
									} else {
										?><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjLoad&amp;action=pjActionLogin&amp;qid=<?php echo $tpl['arr']['id'];?>{REPLYID}"><?php __('front_menu_login');?></a><?php 
									}
									?>
									
									<button class="pjCfBtn pjCfBtnClose" data-index="{INDEX}">
										<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
									</button>
								</div><!-- /.pull-right pjCfCommentActions -->
							</header><!-- /.panel-heading clearfix pjCfCommentHead -->
							
							<div class="panel-body pjCfCommentBody">
								<div id="pjCfReplyMessage_{INDEX}" class="alert" role="alert" style="display: none;"></div>
								<div class="row">
									<?php
									if($controller->checkLogin())
									{ 
										?>
										<div class="col-lg-5 col-md-5 col-sm-6 col-xs-12">
											<div class="form-group">
												<input type="text" name="name" class="form-control required" value="<?php echo pjSanitize::html($USER['name']);?>" readonly="readonly"/>
											</div><!-- /.form-group -->
										</div><!-- /.col-lg-5 col-md-5 col-sm-6 col-xs-12 -->
	
										<div class="col-lg-5 col-md-5 col-sm-6 col-xs-12">
											<div class="form-group">
												<input type="email" name="email" class="form-control required" value="<?php echo pjSanitize::html($USER['email']);?>" readonly="readonly"/>
											</div><!-- /.form-group -->
										</div><!-- /.col-lg-5 col-md-5 col-sm-6 col-xs-12 -->
										<input type="hidden" name="user_id" value="<?php echo $USER['id'];?>"/>
										<?php
									}else{
										?>
										<div class="col-lg-5 col-md-5 col-sm-6 col-xs-12">
											<div class="form-group">
												<input type="text" name="name" class="form-control required" placeholder="<?php __('front_your_name');?>" data-msg-required="<?php __('front_field_required');?>"/>
												<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
											</div><!-- /.form-group -->
										</div><!-- /.col-lg-5 col-md-5 col-sm-6 col-xs-12 -->
	
										<div class="col-lg-5 col-md-5 col-sm-6 col-xs-12">
											<div class="form-group">
												<input type="email" name="email" class="form-control required email" placeholder="<?php __('front_email_address');?>" data-msg-required="<?php __('front_field_required');?>" data-msg-email="<?php __('front_email_invalid');?>"/>
												<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
											</div><!-- /.form-group -->
										</div><!-- /.col-lg-5 col-md-5 col-sm-6 col-xs-12 -->
										<?php
									} 
									?>

									<div class="col-lg-10 col-md-10 col-sm-12 col-xs-12">
										<div class="form-group">
											<textarea name="description" cols="30" rows="10" class="form-control required" placeholder="<?php __('front_your_reply');?>" data-msg-required="<?php __('front_field_required');?>"></textarea>
											<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
										</div><!-- /.form-group -->
									</div><!-- /.col-lg-10 col-md-10 col-sm-12 col-xs-12 -->
									<?php
									if($tpl['use_captcha'] == true)
									{ 
										?>
										<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
											<div class="form-group pjCfCaptcha">
												<img class="pjCfCaptchaImage" src="<?php echo PJ_INSTALL_FOLDER; ?>index.php?controller=pjFront&amp;action=pjActionCaptcha&amp;rand=<?php echo rand(1, 999999); ?>" alt="CAPTCHA"/>
												<input type="text" name="captcha" class="form-control required" maxlength="6" autocomplete="off" placeholder="<?php __('front_captcha');?>" data-msg-required="<?php __('front_field_required');?>" data-msg-remote="<?php __('front_captcha_incorrect');?>"/>
												<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
											</div><!-- /.form-group pjCfCaptcha -->
										</div><!-- /.col-lg-4 col-md-4 col-sm-6 col-xs-12 -->
										<?php
									} 
									?>
								</div><!-- /.row -->
							</div><!-- /.panel-body pjCfCommentBody -->
							
							<footer class="panel-footer pjCfCommentFoot">
								<button type="submit" class="btn btn-default pjCfBtn"><?php __('front_btn_submit');?></button>
							</footer><!-- /.panel-footer pjCfCommentFoot -->
						</div><!-- /.panel panel-default pjCfCommentContent pjCfForm pjCfFormComment -->
					</form>
				</div><!-- /.col-lg-10 col-md-10 col-sm-9 col-xs-12 -->
			</div><!-- /.row -->
		</li><!-- /.pjCfComment -->
	</ul><!-- /.list-unstyled pjCfComments pjCfCommentsReply -->
</div>

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