<?php
mt_srand();
$index = mt_rand(1, 9999);
?>
<div id="pjWrapper">
	<div class="container-fluid pjYpContainer">
		<?php include_once ROOT_PATH . PJ_TEMPLATE_PATH . 'default/elements/header.php';?>
		
		<div class="pjYpBody">
			<?php
			if (@$_GET['controller'] == 'pjListings' && @$_GET['action'] == 'pjActionView')
			{
				$back = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $_SERVER['PHP_SELF'] .'?controller=pjListings&amp;action=pjActionIndex'. (isset($_GET['iframe']) ? '&amp;iframe' : NULL);
				?>
				<div class="pjYpResultsActions">
					<a href="<?php echo $back;?>" class="btn btn-default pjYpBtnBack">
						<span class="glyphicon glyphicon-triangle-left"></span>
						<?php __('label_back');?>
					</a>
				</div><!-- /.pjYpResultsActions -->
				<?php
			} 
			if(isset($tpl['arr']) && !empty($tpl['arr']))
			{
				$listing_title = pjSanitize::html(stripslashes($tpl['arr']['listing_title']));
				
				$minus_name = $controller->friendlyURL($listing_title, '-');
				$plus_name = str_replace('-', "+", $minus_name);
				
				$url = str_ireplace("&amp;", "%26", pjUtil::currPageURL());
				$url = str_ireplace("&", "%26", $url);
				?>
				
				<div class="panel panel-default pjYpResultInner">
					<header class="panel-heading">
						<p class="panel-title"><?php echo stripslashes($tpl['arr']['listing_title'])?></p><!-- /.panel-title -->
					</header><!-- /.panel-heading -->
	
					<div class="panel-body">
						<div class="row">
							<?php
							if (count($tpl['gallery_arr']) > 0)
							{ 
								?>
								<div class="col-lg-7 col-md-7 col-sm-6 col-xs-12">
									<div class="pjYpResultMainImage">
										<a rel="pjYpGallery" class="pjYpFancybox" href="<?php echo PJ_INSTALL_URL . $tpl['gallery_arr'][0]['large_path']; ?>">
											<img src="<?php echo PJ_INSTALL_URL . $tpl['gallery_arr'][0]['large_path']; ?>" alt="" />
										</a>
									</div><!-- /.pjYpResultMainImage -->
									<?php
									unset($tpl['gallery_arr'][0]); 
									if(!empty($tpl['gallery_arr']))
									{
										?>
										<div class="row pjYpThumbs">
											<?php
											foreach ($tpl['gallery_arr'] as $k => $v)
											{ 
												?>
												<div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pjYpThumb">
													<a href="<?php echo PJ_INSTALL_URL . $v['large_path']; ?>" rel="pjYpGallery" class="thumbnail pjYpFancybox" title="<?php echo htmlspecialchars(stripslashes($v['alt'])); ?>">
														<div class="pjYpThumbInner">
															<img src="<?php echo PJ_INSTALL_URL . $v['medium_path']; ?>" alt="<?php echo htmlspecialchars(stripslashes($v['alt'])); ?>" />
														</div><!-- /.pjYpThumbInner -->
													</a>
												</div><!-- /.col-lg-3 col-md-3 col-sm-3 col-xs-3 pjYpThumb -->
												<?php
											} 
											?>
										</div><!-- /.row pjYpThumbs -->
										<?php
									} 
									?>
								</div><!-- /.col-lg-7 col-md-7 col-sm-6 col-xs-12 -->
								<?php
							} 
							?>
	
							<div class="col-lg-5 col-md-5 col-sm-6 col-xs-12">
								<ul class="list-group pjYpContacts">
									<?php
									if (!empty($tpl['arr']['email']))
									{
										?>
										<li class="list-group-item pjYpContact">
											<a href="mailto:<?php echo $tpl['arr']['email'];?>">
												<span class="glyphicon glyphicon-envelope"></span>
												<?php echo $tpl['arr']['email'];?>
											</a>
										</li><!-- /.list-group-item pjYpContact -->
										<?php
									}
									if (!empty($tpl['arr']['phone']))
									{
										?>
										<li class="list-group-item pjYpContact">
											<p>
												<span class="glyphicon glyphicon-phone-alt"></span>
												<strong><?php echo stripslashes($tpl['arr']['phone']); ?></strong>
											</p>
										</li><!-- /.list-group-item pjYpContact -->
										<?php
									}
									if (!empty($tpl['arr']['fax']))
									{
										?>
										<li class="list-group-item pjYpContact">
											<p>
												<span class="glyphicon glyphicon-phone-alt"></span>
												<strong><?php echo stripslashes($tpl['arr']['fax']); ?></strong>
											</p>
										</li><!-- /.list-group-item pjYpContact -->
										<?php
									}
									if (!empty($tpl['arr']['url']))
									{
										?>
										<li class="list-group-item pjYpContact">
											<a href="<?php echo $tpl['arr']['url']?>" target="_blank">
												<span class="glyphicon glyphicon-globe"></span>
												<?php echo $tpl['arr']['url']?>
											</a>
										</li><!-- /.list-group-item pjYpContact -->
										<?php
									}
									$location = array();
									if(!empty($tpl['arr']['address_content']))
									{
										$_address_arr = explode("\n", $tpl['arr']['address_content']);
										$address_arr = array();
										foreach($_address_arr as $v)
										{
											$address_arr[] = trim($v);
										}
										$location[] = join(", ", $address_arr);
									}
									if(!empty($tpl['arr']['address_city']))
									{
										$location[] = $tpl['arr']['address_city'];
									}
									if(!empty($tpl['arr']['address_state']))
									{
										$location[] = $tpl['arr']['address_state'];
									}
									if(!empty($tpl['arr']['address_postcode']))
									{
										$location[] = $tpl['arr']['address_postcode'];
									}
									if(!empty($tpl['arr']['country_title']))
									{
										$location[] = $tpl['arr']['country_title'];
									}
									if(!empty($location))
									{
										?>
										<li class="list-group-item pjYpContact">
											<p>
												<span class="glyphicon glyphicon-home"></span>
												<?php echo implode(', ', $location) ?>
											</p>
										</li><!-- /.list-group-item pjYpContact -->
										<?php
									}
									?>
									<li class="list-group-item pjYpContact">
										<ul class="list-inline pjYpSocials">
											<?php
											if ($tpl['arr']['address_map'] == 1)
											{ 
												?>
												<li>
													<a id="yp_directions" class="pjYpLinkDirection" data-pj-toggle="collapse" href="#pjYpFormDirection" aria-expanded="false" aria-controls="pjYpFormDirection">direction</a>
												</li>
												<?php
											} 
											?>
	
											<li>
												<a href="#" class="pjYpLinkContact" data-pj-toggle="modal" data-pj-target="#pjYpFormContact" lang="<?php echo PJ_INSTALL_FOLDER; ?>index.php?controller=pjListings&action=pjActionSharing&id=<?php echo $tpl['arr']['id'];?>">mail</a>
	
												<div class="modal fade pjYpResultContact" id="pjYpFormContact" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
													<div class="modal-dialog">
														<div class="modal-content">
															<?php
															$listing_title = pjSanitize::html(stripslashes($tpl['arr']['listing_title']));
															if ($tpl['option_arr']['o_seo_url'] == 'No')
															{
																$msg_url = PJ_INSTALL_URL . 'index.php?controller=pjListings&amp;action=pjActionView&amp;id=' . $tpl['arr']['id'] .(isset($_GET['iframe']) ? '&amp;iframe' : NULL);
															} else {
																$msg_url = PJ_INSTALL_URL . $controller->friendlyURL($tpl['arr']['listing_title']) . "-". $tpl['arr']['id'] . ".html";
															} 
															?>
															<form id="frmYpSharing_<?php echo $index;?>" action="<?php echo PJ_INSTALL_FOLDER;?>index.php?controller=pjListings&amp;action=pjActionSendSharing" method="post" class="pjYpFormContact" data-toggle="validator" role="form">
																<header class="modal-header pjYpFormHead">
																	<button type="button" class="close" data-dismiss="modal" aria-label="Close">&times;</button>
																
																	<p class="modal-title pjYpFormTitle"><?php __('front_sharing_title');?></p><!-- /.modal-title -->
																</header><!-- /.modal-header pjYpFormHead -->
																
																<div class="modal-body pjYpFormBody">
																	<div class="form-group">
																		<label for=""><?php __('label_to')?>:</label>
	
																		<input type="email" name="to" class="form-control required email" data-msg-required="<?php __('label_email_required');?>" data-msg-email="<?php __('label_email_invalid');?>"/>
	
																		<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
																	</div><!-- /.form-group -->
	
																	<div class="form-group">
																		<label for=""><?php __('label_from')?>:</label>
	
																		<input type="email" name="from" class="form-control required email" data-msg-required="<?php __('label_email_required');?>" data-msg-email="<?php __('label_email_invalid');?>"/>
	
																		<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
																	</div><!-- /.form-group -->
	
																	<div class="form-group">
																		<label for=""><?php __('label_subject')?>: </label>
	
																		<input type="text" name="subject" value="<?php echo $listing_title;?>" class="form-control required" data-msg-required="<?php __('front_field_required');?>"/>
																		<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
																	</div><!-- /.form-group -->
	
																	<div class="form-group">
																		<label for=""><?php __('label_message')?>: </label>
	
																		<textarea name="message" cols="30" rows="10" class="form-control required" data-msg-required="<?php __('front_field_required');?>"><?php echo $msg_url;?></textarea>
																		<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
																	</div><!-- /.form-group -->
																</div><!-- /.modal-body pjYpFormBody -->
																
																<footer class="modal-footer pjYpFormFoot">
																	<button type="button" class="btn btn-default pjYpBtn pjYpBtnSecondary" data-dismiss="modal"><?php __('button_cancel'); ?></button>
	
																	<button type="submit" class="btn btn-default pjYpBtn pjYpBtnPrimary"><?php __('button_send'); ?></button>
																</footer><!-- /.modal-footer pjYpFormFoot -->
															</form><!-- /.pjYpFormContact -->
														</div><!-- /.modal-content -->
													</div><!-- /.modal-dialog -->
												</div><!-- /#pjYpFormContact.modal fade pjYpResultContact -->
											</li>
	
											<li><a href="https://www.facebook.com/sharer.php?u=<?php echo $url;?>&t=<?php echo $plus_name;?>" class="pjYpLinkFacebook" target="_blank">facebook</a></li>
											<li><a href="https://twitter.com/intent/tweet?source=webclient&text=<?php echo $plus_name; ?>&url=<?php echo $url?>" class="pjYpLinkTwitter" target="_blank">twitter</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="pjYpLinkLinkedIn" target="_blank">LinkedIn</a></li>
											
											
											
										</ul><!-- /.list-inline pjYpSocials -->
										
										<div id="yp_address_container" class="collapse pjYpFormDirection">
											<label><?php __('label_enter_address');?></label>
											<input type="text" id="yp_start_address" name="address" class="form-control" lang="<?php echo PJ_INSTALL_FOLDER; ?>index.php?controller=pjListings&action=pjActionGetLatLng"/> 
										</div>
									</li><!-- /.list-group-item pjYpContact -->
									<?php
									if ($tpl['arr']['address_map'] == 1 && !isset($_POST['address']))
									{ 
										if (!empty($tpl['arr']['lat']) && !empty($tpl['arr']['lng']))
										{
											?>
											<li id="yp_view_map" class="list-group-item pjYpContact">
												<div id="yp_view_map_canvas" class="pjYpMap" ></div><!-- /.pjYpMap -->
											</li><!-- /.list-group-item pjYpContact -->
											<?php
											$ypHtml = $ypAddress = array();
											if (!empty($tpl['arr']['address_content']))
											{
												$_address_arr = explode("\n", $tpl['arr']['address_content']);
												$address_arr = array();
												foreach($_address_arr as $v)
												{
													$address_arr[] = stripslashes(trim($v));
												}
												$ypAddress[] = join(", ", $address_arr);
											}
											if (!empty($tpl['arr']['address_city']))
											{
												$ypAddress[] = stripslashes($tpl['arr']['address_city']);
											}
											if (!empty($tpl['arr']['address_state']))
											{
												$ypAddress[] = stripslashes($tpl['arr']['address_state']);
											}
											
											if (!empty($tpl['arr']['address_postcode']))
											{
												$ypAddress[] = stripslashes($tpl['arr']['address_postcode']);
											}
											if (!empty($tpl['arr']['country_title']))
											{
												$ypAddress[] = stripslashes($tpl['arr']['country_title']);
											}
												
											$ypHtml[] = '<div class="yp-info-window">';
											if (!empty($tpl['arr']['listing_title']))
											{
												$ypHtml[] = '<div class="yp-info-window-head">'.str_replace('\'', '\\\'', $tpl['arr']['listing_title']).'<\/div>';
											}
											$ypHtml[] = '<div class="yp-info-window-block"><span>'. __('label_address', true) . '<\/span>: ' . join(", ", $ypAddress) . '<\/div>';
												
											$ypHtml[] = '<\/div>';
										}
									} 
									?>
								</ul><!-- /.list-group pjYpContacts -->
							</div><!-- /.col-lg-5 col-md-5 col-sm-6 col-xs-12 -->
						</div><!-- /.row -->
					</div><!-- /.panel-body -->
					<?php
					if ($tpl['arr']['address_map'] == 1)
					{ 
						?>
						<div class="panel-body" style="display: none;">
							<div class="row" id="yp_direction_container">
								<div class="col-lg-7 col-md-7 col-sm-6 col-xs-12 pull-right">
									<div class="pjYpMap pjYpMapDirection" id="yp_direction_map">
										
									</div><!-- /.pjYpMap pjYpMapDirection -->
								</div><!-- /.col-lg-7 col-md-7 col-sm-6 col-xs-12 pull-right -->
	
								<div class="col-lg-5 col-md-5 col-sm-6 col-xs-12 pull-left pjYpDirectionResults">
									<p class="pjYpDirectionResultsTitle"><?php __('label_directions');?>: </p><!-- /.pjYpDirectionResultsTitle -->
	
									<div class="pre-scrollable" id="yp_direction_list"></div><!-- /.pre-scrollable -->
								</div><!-- /.col-lg-5 col-md-5 col-sm-6 col-xs-12 pull-left pjYpDirectionResults -->
							</div><!-- /.row -->
						</div>
						<?php
					} 
					?>
	
					<footer class="panel-footer pjYpListingDesc">
						<p><strong><?php __('label_description');?>:</strong></p>
						<p><?php echo stripslashes($tpl['arr']['listing_description']);?></p>
					</footer><!-- /.panel-footer -->
				</div><!-- /.panel panel-default pjYpResultInner -->
				<?php
			}else{
				__('front_listing_not_exist');
			} 
			?>
		</div><!-- /.pjYpBody -->
	</div><!-- /.container-fluid pjYpContainer -->
</div><!-- #pjWrapper -->