<?php
$STORE = @$_SESSION[$controller->defaultStore]; 
?>
<div class="pjPcs-head">
	<div class="row">
		<div class="col-lg-6 col-sm-7">
			<div class="pjPcs-heading"><?php echo pjSanitize::html($tpl['product_arr']['name']);?></div><!-- /.pjPcs-heading -->
		</div><!-- /.col-sm-8 -->
		<?php
		if(isset($STORE['model_' . $_GET['product_id']]) && !empty($STORE['model_' . $_GET['product_id']]))
		{ 
			?>
			<div class="col-lg-6 col-sm-5">
				<div class="row">
					<div class="col-md-3 col-sm-5">
						<label class="pjPcs-control-label"><?php __('front_filter_by');?>:</label>
					</div><!-- /.col-sm-4 -->
	
					
					<?php
					$show_locale = false;
					if(isset($_SESSION[$controller->defaultLangMenu]) && $_SESSION[$controller->defaultLangMenu] == 'show')
					{
						if (!isset($_GET['locale']) || (int) $_GET['locale'] <= 0)
						{
							if (isset($tpl['locale_arr']) && is_array($tpl['locale_arr']) && !empty($tpl['locale_arr']) && count($tpl['locale_arr']) > 1)
							{
								$show_locale = true;
							}
						}
					}
					if($show_locale == true)
					{
						?>
						<div class="col-md-5 col-sm-7">
							<select id="pcCategory_<?php echo $_GET['index'];?>" name="category_id" class="form-control pjPcs-select">
								<option value="">----</option>
								<?php
								foreach($tpl['category_arr'] as $k => $v)
								{
									?><option value="<?php echo $v['id'];?>"<?php echo isset($_GET['category_id']) && (int) $_GET['category_id'] > 0 ? ($v['id'] == $_GET['category_id'] ? ' selected="selected"' : null) : null;?>><?php echo pjSanitize::html($v['name']);?></option><?php
								} 
								?>
							</select>
						</div><!-- /.col-sm-8 -->
							
						<div class="col-md-4 col-sm-7 col-xs-6 col-md-offset-0 col-sm-offset-5 pjPcs-language">
							<div class="dropdown">
								<?php
								$selected_title = null;
								$selected_src = NULL;
								foreach ($tpl['locale_arr'] as $locale)
								{
									if ($controller->getLocaleId() == $locale['id'])
									{
										$selected_title = $locale['language_iso'];
										$lang_iso = explode("-", $selected_title);
										if(isset($lang_iso[1]))
										{
											$selected_title = $lang_iso[1];
										}
										if (!empty($locale['flag']) && is_file(PJ_INSTALL_PATH . $locale['flag']))
										{
											$selected_src = PJ_INSTALL_URL . $locale['flag'];
										} elseif (!empty($locale['file']) && is_file(PJ_FRAMEWORK_LIBS_PATH . 'pj/img/flags/' . $locale['file'])) {
											$selected_src = PJ_INSTALL_URL . PJ_FRAMEWORK_LIBS_PATH . 'pj/img/flags/' . $locale['file'];
										}
										break;
									}
								} 
								?>
								<button id="dLabel" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="btn btn-primary btn-block">
									<img src="<?php echo $selected_src; ?>" alt="">
									<span class="title"><?php echo mb_strtoupper($selected_title, 'UTF-8'); ?></span>
									<span class="caret"></span>
								</button>
								
								<ul class="dropdown-menu" aria-labelledby="dLabel">
									<?php
									foreach ($tpl['locale_arr'] as $locale)
									{
										$selected_src = NULL;
										if (!empty($locale['flag']) && is_file(PJ_INSTALL_PATH . $locale['flag']))
										{
											$selected_src = PJ_INSTALL_URL . $locale['flag'];
										} elseif (!empty($locale['file']) && is_file(PJ_FRAMEWORK_LIBS_PATH . 'pj/img/flags/' . $locale['file'])) {
											$selected_src = PJ_INSTALL_URL . PJ_FRAMEWORK_LIBS_PATH . 'pj/img/flags/' . $locale['file'];
										}
										?>
										<li>
											<a href="#" class="pcSelectorLocale<?php echo $controller->getLocaleId() == $locale['id'] ? ' pjHbBtnActive' : NULL; ?>" data-id="<?php echo $locale['id']; ?>" data-dir="<?php echo $locale['dir']; ?>">
												<img src="<?php echo $selected_src; ?>" alt="">
												<?php echo pjSanitize::html($locale['name']); ?>
											</a>
										</li>
										<?php
									}
									?>
								</ul>
							</div>
						</div>
						<?php
					}else{
						?>
						<div class="col-md-9 col-sm-7">
							<select id="pcCategory_<?php echo $_GET['index'];?>" name="category_id" class="form-control pjPcs-select">
								<option value="">----</option>
								<?php
								foreach($tpl['category_arr'] as $k => $v)
								{
									?><option value="<?php echo $v['id'];?>"<?php echo isset($_GET['category_id']) && (int) $_GET['category_id'] > 0 ? ($v['id'] == $_GET['category_id'] ? ' selected="selected"' : null) : null;?>><?php echo pjSanitize::html($v['name']);?></option><?php
								} 
								?>
							</select>
						</div><!-- /.col-sm-8 -->
							
						<?php
					}
					?>
				</div><!-- /.row -->
			</div><!-- /.col-sm-4 -->
			<?php
		} 
		?>
	</div><!-- /.row -->
	<div class="row">
		<div class="col-md-12 col-sm-12">
			<div class="pjPcs-description">
				<?php
				if(!empty($tpl['product_arr']['thumb_path']) && file_exists(PJ_INSTALL_PATH . $tpl['product_arr']['thumb_path']))
				{
					?><img src="<?php echo PJ_INSTALL_URL . $tpl['product_arr']['thumb_path'];?>" alt=""><?php
				} 
				?>
				<?php echo !empty($tpl['product_arr']['description']) ? nl2br(pjSanitize::clean($tpl['product_arr']['description'])) : '';?>
			</div><!-- /.pjPcs-description -->
		</div>
	</div>
	<?php
	if(!empty($tpl['model_arr']))
	{ 
		?>
		<div class="row">
			<div class="col-lg-6 col-sm-7">
				<p><?php __('front_select_models');?>:</p>
			</div>
		</div>
		<div class="row">
			<?php
			foreach($tpl['model_arr'] as $v)
			{ 
				?>
				<div class="col-md-3 col-sm-6">
					<label class="btn btn-primary pjPcs-checkbox" data-id="<?php echo $v['id']?>">
						<input type="checkbox" <?php echo isset($STORE['model_' . $_GET['product_id']]) && in_array($v['id'], $STORE['model_' . $_GET['product_id']]) ? ' checked="checked"' : null; ?>>
		
						<?php echo pjSanitize::clean($v['name']);?>
					</label>
				</div><!-- /.col-md-3 -->
				<?php
			} 
			?>
		</div><!-- /.row -->
		<?php
	} 
	?>
</div><!-- /.pjPcs-head -->
	
<?php
if(isset($STORE['model_' . $_GET['product_id']]) && !empty($STORE['model_' . $_GET['product_id']]))
{
	$model_id_arr = $STORE['model_' . $_GET['product_id']];
	$number_of_categories = count($tpl['category_arr']);
	$number_of_models = count($model_id_arr);
	if($number_of_models > 0 && $number_of_categories > 0)
	{
		?>
		<div class="pjPcs-body">
			<div class="table-responsive pjPcs-table-responsive">
				<table class="pjPcs-table pjPcs-table-main">
					<thead>
						<tr>
							<th colspan="<?php echo $number_of_models + 1;?>"><strong><?php __('front_models');?></strong></th>
						</tr>
					</thead>
	
					<tbody>
						<tr>
							<td> <strong><?php __('front_models');?></strong></td>
							<?php
							foreach($tpl['model_arr'] as $v)
							{ 
								if(isset($STORE['model_' . $_GET['product_id']]) && in_array($v['id'], $STORE['model_' . $_GET['product_id']]))
								{
									?>
									<td><?php echo pjSanitize::clean($v['name']);?></td>
									<?php
								}
							} 
							?>
						</tr>
	
						<tr>
							<td> <strong><?php __('front_image');?></strong></td>
							<?php
							foreach($tpl['model_arr'] as $v)
							{ 
								if(isset($STORE['model_' . $_GET['product_id']]) && in_array($v['id'], $STORE['model_' . $_GET['product_id']]))
								{
									?>
									<td data-th="<?php echo pjSanitize::clean($v['name']);?>">
										<div class="pjPcs-image">
											<?php
											if(!empty($v['thumb_path']) && file_exists(PJ_INSTALL_PATH . $v['thumb_path']))
											{ 
												?><img src="<?php echo PJ_INSTALL_URL . $v['thumb_path'];?>" alt=""><?php
											}else{
												?><img src="<?php echo PJ_INSTALL_URL . PJ_IMG_PATH . 'frontend/150x100.png';?>" alt=""><?php
											} 
											?>
										</div><!-- /.pjPcs-image -->
									</td>
									<?php
								}
							} 
							?>
						</tr>
	
						<tr>
							<td> <strong><?php __('front_description');?></strong></td>
							<?php
							foreach($tpl['model_arr'] as $v)
							{ 
								if(isset($STORE['model_' . $_GET['product_id']]) && in_array($v['id'], $STORE['model_' . $_GET['product_id']]))
								{
									?>
									<td data-th="<?php echo pjSanitize::clean($v['name']);?>"><?php echo !empty($v['description']) ? nl2br(pjSanitize::clean($v['description'])) : '';?></td>
									<?php
								}
							} 
							?>
						</tr>
					</tbody>
				</table>
			</div><!-- /.table-responsive -->
			<?php
			foreach($tpl['category_arr'] as $k => $category)
			{
				if(isset($_GET['category_id']) && (int) $_GET['category_id'] > 0 )
				{
					if($_GET['category_id'] != $category['id'])
					{
						continue;
					}
				}
				?>
				<div class="table-responsive pjPcs-table-responsive">
					<table class="pjPcs-table">
						<thead>
							<tr>
								<th><strong><?php echo pjSanitize::clean($category['name'])?></strong></th>
								<th colspan="<?php echo $number_of_models;?>"><?php echo !empty($category['description']) ? nl2br(pjSanitize::clean($category['description'])) : '';?> <a href="javascript:void(0);" class="pjPcs-table-btn-toggle"></a></th>
							</tr>
						</thead>
		
						<tbody>
							<tr>
								<td> <strong><?php __('front_models');?></strong></td>
								<?php
								foreach($tpl['model_arr'] as $v)
								{ 
									if(in_array($v['id'], $model_id_arr))
									{
										?><td><?php echo pjSanitize::clean($v['name']);?></td><?php
									}
								} 
								?>
							</tr>
							<?php
							if(isset($category['features']) && !empty($category['features']))
							{ 
								$feature_arr = $category['features'];
								foreach($feature_arr as $feature)
								{
									?>
									<tr>
										<td> 
											<strong><?php echo pjSanitize::clean($feature['title']);?></strong>
											<?php
											if(!empty($feature['thumb_path']) && file_exists(PJ_INSTALL_PATH . $feature['thumb_path'])) 
											{
												?><div class="pjPcs-image"><img src="<?php echo PJ_INSTALL_URL . $feature['thumb_path'];?>" alt=""></div><?php 
											}
											if(!empty($feature['description']))
											{
												?><p><?php echo htmlspecialchars(stripslashes($feature['description']));?></p><?php
											}
											?>
										</td>
										<?php
										foreach($tpl['model_arr'] as $model)
										{
											if(in_array($model['id'], $model_id_arr))
											{ 
												$value = '&nbsp;';
												if(isset($tpl['grid_arr'][$feature['id']][$model['id']]))
												{
													$cell = $tpl['grid_arr'][$feature['id']][$model['id']];
													if(isset($cell['title']) && $cell['title'] != '')
													{
														$value = htmlspecialchars(stripslashes($cell['title']));
													}
												}
												?><td data-th="<?php echo pjSanitize::clean($model['name']);?>"><?php echo $value;?></td><?php
											}
										} 
										?>
									</tr>
									<?php
								}
							}
							?>
						</tbody>
					</table>
				</div><!-- /.table-responsive -->
			<?php
		}
		?>
		</div>
		<?php
	}
} 
?>