<?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 pjCfForm pjCfFormAccess pjCfFormAccount">
			<header class="panel-heading text-center pjCfFormHead">
				<p class="panel-title pjCfFormTitle"><?php __('front_menu_my_account');?></p><!-- /.panel-title pjCfFormTitle -->
			</header><!-- /.panel-heading text-center pjCfFormHead -->
			
			<div class="panel-body pjCfFormBody">
				<form id="pjSFProfileForm_<?php echo $index;?>" action="<?php echo $_SERVER['PHP_SELF'];?>?controller=pjLoad&amp;action=pjActionProfile" method="post" data-toggle="validator" role="form" autocomplete="off" enctype="multipart/form-data">
				
					<input type="hidden" name="profile" value="1" />
					<input type="hidden" name="id" value="<?php echo $tpl['arr']['id'];?>" />
					
					<div class="row">
						<div class="col-lg-5 col-md-5 col-sm-6 col-xs-12 pjCfFormAside">
							<?php
							if (in_array((int) $tpl['option_arr']['o_rf_include_avatar'], array(2,3)))
							{ 
								?>
								<div class="pjCfAddFile">
									<label><?php __('front_avatar');?>: </label>
									
									<div class="pjCfAddFileImage">
										<img src="<?php echo !empty($tpl['arr']['avatar_path']) ? PJ_INSTALL_URL . $tpl['arr']['avatar_path'] : PJ_INSTALL_URL . PJ_IMG_PATH . 'frontend/imgo.jpg';?>" alt="" />
									</div><!-- /.pjCfAddFileImage -->
	
									<div class="btn btn-default pjCfBtn pjCfBtnFile pjCfBtnUpload">
										<?php echo !empty($tpl['arr']['avatar_path']) && is_file(PJ_INSTALL_PATH . $tpl['arr']['avatar_path']) ? __('front_change') : __('front_add_file');?>
								
										<input type="file" name="avatar" class="pjCfFileUploadField<?php echo (int) $tpl['option_arr']['o_rf_include_avatar'] === 3 && empty($tpl['arr']['avatar_path']) ? ' required' : NULL; ?>" data-msg-extension="<?php __('front_file_extensions');?>"/>
									</div>
	
									<a href="#" class="btn btn-default pjCfBtn pjCfBtnFile pjCfBtnReset"><?php __('front_reset_image');?></a>
								</div><!-- /.pjCfAddFile -->
								<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
								<?php
							} 
							?>
						</div><!-- /.col-lg-5 col-md-5 col-sm-6 col-xs-12 pjCfFormAside -->
						
						<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 pjCfFormContent">
							<?php
							if(isset($tpl['err']))
							{
								$front_err = pjSanitize::clean(__('front_err', true));
								$msg = $front_err[$tpl['err']];
								$msg = str_replace("{MAXSIZE}", ini_get('post_max_size'), $msg);
								$msg = str_replace("{POSTSIZE}", ini_get('upload_max_filesize'),$msg);
								?>
								<div class="alert alert-danger" role="alert"><?php echo $msg;?></div>
								<?php
							}
							if(isset($tpl['msg']))
							{
								$front_msg = pjSanitize::clean(__('front_msg', true));
								?>
								<div class="alert alert-success" role="alert"><?php echo $front_msg[$tpl['msg']];?></div>
								<?php
							}
							if (in_array((int) $tpl['option_arr']['o_rf_include_name'], array(2,3)))
							{ 
								?>
								<div class="form-group">
									<label for=""><?php __('front_full_name');?>: </label>
						
									<input type="text" name="name" value="<?php echo pjSanitize::html($tpl['arr']['name']);?>" class="form-control<?php echo (int) $tpl['option_arr']['o_rf_include_name'] === 3 ? ' required' : NULL; ?>" data-msg-required="<?php __('front_field_required');?>"/>
									
									<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
								</div><!-- /.form-group -->
								<?php
							}
							if (in_array((int) $tpl['option_arr']['o_rf_include_email'], array(2,3)))
							{ 
								?>
								<div class="form-group">
									<label for=""><?php __('front_email_address');?>: </label>
									
									<input type="email" name="email" value="<?php echo pjSanitize::html($tpl['arr']['email']);?>" class="form-control email<?php echo (int) $tpl['option_arr']['o_rf_include_email'] === 3 ? ' required' : NULL; ?>" data-msg-required="<?php __('front_field_required');?>" data-msg-email="<?php __('front_email_invalid');?>" data-msg-remote="<?php __('front_email_in_used');?>"/>
									<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
								</div><!-- /.form-group -->
								<?php
							}
							if (in_array((int) $tpl['option_arr']['o_rf_include_password'], array(2,3)))
							{ 
								?>
								<div class="form-group">
									<label for=""><?php __('front_password');?>: </label>
									
									<input type="password" id="pjSFPassword" name="password" value="<?php echo pjSanitize::html($tpl['arr']['password']);?>" class="form-control<?php echo (int) $tpl['option_arr']['o_rf_include_password'] === 3 ? ' required' : NULL; ?>" data-msg-required="<?php __('front_field_required');?>"/>
									<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
								</div><!-- /.form-group -->
								<?php
							}
							if (in_array((int) $tpl['option_arr']['o_rf_include_website'], array(2,3)))
							{ 
								?>
								
								<div class="form-group">
									<label for=""><?php __('front_website');?>: </label>
									
									<input type="text" name="website" value="<?php echo pjSanitize::html($tpl['arr']['website']);?>" class="form-control<?php echo (int) $tpl['option_arr']['o_rf_include_website'] === 3 ? ' required' : NULL; ?>" data-msg-required="<?php __('front_field_required');?>"/>
									<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
								</div><!-- /.form-group -->
								<?php
							}
							if (in_array((int) $tpl['option_arr']['o_rf_include_phone'], array(2,3)))
							{ 
								?>
								<div class="form-group">
									<label for=""><?php __('front_phone');?>: </label>
									
									<input type="text" name="phone" value="<?php echo pjSanitize::html($tpl['arr']['phone']);?>" class="form-control<?php echo (int) $tpl['option_arr']['o_rf_include_phone'] === 3 ? ' required' : NULL; ?>" data-msg-required="<?php __('front_field_required');?>"/>
									<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
								</div><!-- /.form-group -->
								<?php
							}
							if (in_array((int) $tpl['option_arr']['o_rf_include_address'], array(2,3)))
							{
								?>
								<div class="form-group">
									<label for=""><?php __('front_address');?>: </label>
									
									<input type="text" name="address" value="<?php echo pjSanitize::html($tpl['arr']['address']);?>" class="form-control<?php echo (int) $tpl['option_arr']['o_rf_include_address'] === 3 ? ' required' : NULL; ?>" data-msg-required="<?php __('front_field_required');?>"/>
									<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
								</div><!-- /.form-group -->
								<?php
							}
							if (in_array((int) $tpl['option_arr']['o_rf_include_city'], array(2,3)))
							{ 
								?>
								<div class="form-group">
									<label for=""><?php __('front_city');?>: </label>
									
									<input type="text" name="city" value="<?php echo pjSanitize::html($tpl['arr']['city']);?>" class="form-control<?php echo (int) $tpl['option_arr']['o_rf_include_city'] === 3 ? ' required' : NULL; ?>" data-msg-required="<?php __('front_field_required');?>"/>
									<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
								</div><!-- /.form-group -->
								<?php
							}
							if (in_array((int) $tpl['option_arr']['o_rf_include_state'], array(2,3)))
							{ 
								?>
								<div class="form-group">
									<label for=""><?php __('front_state');?>: </label>
									
									<input type="text" name="state" value="<?php echo pjSanitize::html($tpl['arr']['state']);?>" class="form-control<?php echo (int) $tpl['option_arr']['o_rf_include_state'] === 3 ? ' required' : NULL; ?>" data-msg-required="<?php __('front_field_required');?>"/>
									<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
								</div><!-- /.form-group -->
								<?php
							}
							if (in_array((int) $tpl['option_arr']['o_rf_include_zip'], array(2,3)))
							{ 
								?>
								<div class="form-group">
									<label for=""><?php __('front_zip');?>: </label>
									
									<input type="text" name="zip" value="<?php echo pjSanitize::html($tpl['arr']['zip']);?>" class="form-control<?php echo (int) $tpl['option_arr']['o_rf_include_zip'] === 3 ? ' required' : NULL; ?>" data-msg-required="<?php __('front_field_required');?>"/>
									<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
								</div><!-- /.form-group -->
								<?php
							}
							if (in_array((int) $tpl['option_arr']['o_rf_include_country'], array(2,3)))
							{ 
								?>
								<div class="form-group">
									<label for=""><?php __('front_country');?>: </label>
									
									<select name="country_id" class="form-control<?php echo (int) $tpl['option_arr']['o_rf_include_country'] === 3 ? ' required' : NULL; ?>" data-msg-required="<?php __('front_field_required');?>">
										<option value="">-- <?php __('front_choose'); ?>--</option>
										<?php
										foreach ($tpl['country_arr'] as $k => $v)
										{
											?><option value="<?php echo $v['id']; ?>"<?php echo $tpl['arr']['country_id'] == $v['id'] ? ' selected="selected"' : NULL;?>><?php echo $v['country_title']; ?></option><?php
										}
										?>
									</select>
									<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
								</div><!-- /.form-group -->
								<?php
							} 
							?>
							<div class="form-group">
								<button type="submit" class="btn btn-default pjCfBtn pjCfBtnPrimary"><?php __('front_btn_save');?></button>
							</div><!-- /.form-group -->
						</div><!-- /.col-lg-6 col-md-6 col-sm-6 col-xs-12 pjCfFormContent -->
					</div><!-- /row -->
				</form>
			</div><!-- /.panel-body pjCfFormBody -->
		</div><!-- /.panel panel-default pjCfBody pjCfForm pjCfFormAccess pjCfFormAccount -->
		
		<?php
		if(count($tpl['question_arr']) > 0)
		{
			$column = 'last_reply';
			if(isset($_GET['column']))
			{
				$column = $_GET['column'];
			}
			?>
			<form id="pjCfFormActivity_<?php echo $index;?>" method="get" role="search" style="display:none;">
				<input type="hidden" value="pjLoad" name="controller">
				<input type="hidden" value="pjActionProfile" name="action">
				<input type="hidden" value="1" name="pjPage">
				<input type="hidden" value="<?php echo isset($_GET['column']) ? $_GET['column'] : 'created'; ?>" name="column">
				<input type="hidden" value="<?php echo isset($_GET['direction']) ? $_GET['direction'] : 'DESC'; ?>" name="direction">
			</form>
			<div<?php echo isset($_GET['pjPage']) ? ' id="pjCfActivity_'.$index.'"' : NULL; ?> 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']?>;"><?php echo pjSanitize::html($v['category'])?></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 implode("<br/>", $ago_arr);?></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
						}
					} 
					?>
				</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 -->
			<?php
		} 
		?>
		
	</div><!-- /.container-fluid pjCfContainer -->
</div><!-- /#pjWrapper -->

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