<?php
/**
 * JE GroupBuy package
 * @author J-Extension <contact@jextn.com>
 * @link http://www.jextn.com
 * @copyright (C) 2011 - 2012 J-Extension
 * @license GNU/GPL, see LICENSE.php for full license.
**/

// no direct access
defined('_JEXEC') or die;

if(!isset($_SESSION))
{
session_start();
$_SESSION['cart']="";
}

JHtml::addIncludePath(JPATH_COMPONENT.DS.'helpers');
$params		= JComponentHelper::getParams('com_jegroupbuy');

// Joomla predefined function for modal
	JHTML::_('behavior.modal');
?>
<style type="text/css">
.rsc_comment_container {
	clear:both;
	margin-bottom:14px;
	overflow:hidden;
	width:100%;
}

.productdetails table, tr, td
{
	border:none;
}
</style>
<script src="<?php echo  JURI::base();?>components/com_jegroupbuy/assets/js/addComment.js"></script>

<!-- Included javascript files and functions -->
<script type="text/javascript">
	Shadowbox.init();
</script>
<?php $addtocart_url =  JRoute::_('index.php?option=com_jegroupbuy&view=productdetails&task=addtoCart&action=add&tmpl=component&pid='.$this->items->id);

$payment_url =  JRoute::_('index.php?option=com_jegroupbuy&task=paymentDetails&pid='.$this->items->id, false);
$settings = $this->settings;
$comments = $this->comments;

$download_coupon= JRoute::_('index.php?option=com_jegroupbuy&task=downloadPdf&id='.(int) $this->items->id);

$continue_url		= "index.php?option=com_jegroupbuy&view=jegroupbuy";
$db	= JFactory::getDBO();
$query1		= $db->getQuery(true);

$query1->select('sum(quantity)');
$query1->from('#__jegroupbuy_payment AS p');
$query1->where('p.p_id = '.$this->items->id);
$db->setQuery($query1);

$number_of_bought		= $db->loadResult();

if(empty($number_of_bought))
{
	$number_of_bought = 0;
}
?>

<form action="<?php echo JRoute::_('index.php'); ?>" name="productForm">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>
<h1 style="margin:0px; padding:6px;font-size: 28px;border:none;"><?php echo $this->items->title; ?></h1>
<link rel="stylesheet" type="text/css" href="<?php echo JURI::root().'components/com_jegroupbuy/assets/css/style.css'?>">
<table cellpadding="0" cellspacing="0" width="98%" border="0">
	<tr>
		<td width="100%">
			<table cellpadding="0" cellspacing="0" width="100%" border="0" class="productdetails">
				<tr>
				<!-- Currently Edited -->
					<td width="35%" valign="top">
						<table cellpadding="0" cellspacing="0" width="100%" border="0" >
							<tr>
								<td width="100%" style="padding:0px 15px 0 0; ">
									<table cellpadding="0" cellspacing="0" width="100%" border="0">
										<tr>
											<td width="100%" style="border:solid 1px #8BD3F6;background-color:#CFEEF6;">
												<table cellpadding="0" cellspacing="0" width="100%" border="0">
													<?php if($this->items->dealtype == "1"){ ?>
													<tr>
														<!-- Buy Pay Save-->
														<td align="center" valign="middle" id="anchor-price">
															<div id="price-tag<?php echo $this->params->get('show_overflowimage',0); ?>">
																<a id="style6play"  href="<?php echo $download_coupon; ?>"><?php echo JText::_("COM_JEGROUPBUY_DOWNLOAD"); ?></a>
															</div>
														</td>
													</tr>
													<?php }else{ ?>
													<tr>
														<!-- Buy Pay Save-->
														<td align="center" valign="middle" id="anchor-price">
															<div id="price-tag<?php echo $this->params->get('show_overflowimage',0); ?>">
																<a rel='{handler: "iframe",size:{x:580,y:350}}'  id="style6play" class="modal" href="<?php echo $addtocart_url; ?>">
																<?php echo JText::_("COM_JEGROUPBUY_BUY_FOR").$this->items->currencysymbol." ".$this->items->deal_price; ?></a>
															</div>
														</td>
													</tr>
													<tr>
														<td colspan="2"  id="proceed">
															<table width="100%" height="34" cellspacing="0" cellpadding="0" border="1" style="margin-top:5px;">
																<tr>
																	<td style="text-align:center;">
																		<a id="continue-shop" style="" href="<?php echo $continue_url; ?>" onclick="javascript:close123('<?php echo $continue_url; ?>');">Continue Shopping</a>
																	</td>
																	<td style="text-align:center;">
																		<a id="proceed-checkout" style="text-decoration:none;background:none;color:#000000;cursor:pointer;" href="<?php echo $payment_url; ?>" onclick="javascript:close123('<?php echo $payment_url; ?>');">Proceed Payment</a>
																	</td>
																</tr>
															</table>
														</td>
													</tr>
													<tr>
														<td style="font-weight:bold;">
															<table cellpadding="0" cellspacing="0" border="0" width="100%">
																<tr>
																	<td  align="center" style="border:1px solid #8BD3F6;height:40px;"><?php echo JText::_("COM_JEGROUPBUY_ACTUAL_VALUE")."<br/>".$this->items->currencysymbol." ".$this->items->product_price; ?></td>
																	<td  align="center" style="border:1px solid #8BD3F6;height:30px;"><?php echo JText::_("COM_JEGROUPBUY_YOU_SAVE")."<br/>".$this->items->currencysymbol." ".$this->items->you_save; ?></td>
																</tr>
															</table>
														</td>
													</tr>
													<?php } ?>
														<!-- Buy Pay Save-->
													</tr>
												</table>
											</td>
										</tr>

									</table>
								</td>
							</tr>
							<tr>
								<td style="padding:5px 15px 0px 0px;">
									<table width="100%">
										<tr>
											<td width="100%" id="timer-disp" align="center">
											<?php
												$db	= JFactory::getDBO();
												$query = "SELECT sum(quantity) FROM #__jegroupbuy_payment AS p WHERE p.p_id = ".$this->items->id;
												$db->setQuery($query);
												$number_of_bought		= $db->loadResult();

												if($number_of_bought == "")
												{
													$number_of_bought =0;
												}

												$total_products = $this->items->total_bought;

												unset($deal_date_sp);
												$deal_date = JHTML::_('date',  $this->items->deal_to_date, "Y-m-d");
												$deal_date_sp = explode("-",$deal_date);
											?>
											<span class="prod_timer" style="color:black;margin-left:20px;padding: 5px 7px 5px 6px;font-size: 12px;">
												<script language="JavaScript" type="text/javascript">
													TargetDate = "<?php echo $deal_date_sp[1]; ?>/<?php echo $deal_date_sp[2]; ?>/<?php echo $deal_date_sp[0]; ?> 11:59 PM";
													BackColor = "palegreen";
													ForeColor = "navy";
													pID = "<?php echo $this->items->id; ?>";
													eCheck = "<?php echo $this->items->expired; ?>";
													CountActive = true;
													CountStepper = -1;
													LeadingZero = true;
													number_of_bought = "<?php echo $number_of_bought; ?>";
													total_products = "<?php echo $total_products; ?>";
													DisplayFormat = "%%D%% <?php echo JText::_("COM_JEGROUPBUY_DAYS"); ?>, %%H%% <?php echo JText::_("COM_JEGROUPBUY_HOURS"); ?>, %%M%% <?php echo JText::_("COM_JEGROUPBUY_MINUTES"); ?>, %%S%% <?php echo JText::_("COM_JEGROUPBUY_SECONDS"); ?>.";
													FinishMessage = "<span style='color:red;'><?php echo JText::_("COM_JEGROUPBUY_EXPIRED"); ?></span>";
												</script>
												<script language="JavaScript" src="components/com_jegroupbuy/assets/js/countdown.js" type="text/javascript"></script>
											</span>
											</td>
										</tr>
									</table>
								</td>
							</tr>
							<tr>
								<td width="100%" style="padding:5px 15px 0 0;">
									<table cellpadding="0" cellspacing="0" width="100%" border="0">
										<tr>
											<td width="50%" id="bought-disp">
												<table cellpadding="0" cellspacing="0" border="0" width="100%">
													<tr>
														<td  align="center" style="font-size:18px;"><?php echo $this->number_of_bought." ".JText::_("COM_JEGROUPBUY_BOUGHT"); ?></td>
													</tr>
													<tr>
														<td  align="center" style="height:30px;font-size:16px;"><?php echo "Deal is on !"; ?></td>
													</tr>
												</table>
											</td>
										</tr>
									</table>
								</td>
							</tr>
							<?php
							if($settings->show_share) {
							?>
							<tr>
								<td width="100%" style="padding:5px 15px 0 0;">
									<table cellpadding="0" cellspacing="0" width="100%" border="0" height="65px">
										<tr>
											<td width="100%" id="share-disp">
												<table cellpadding="0" cellspacing="0" border="0" width="100%">
													<tr>
														<td align="center" id="share-with"><?php echo JText::_("COM_JEGROUPBUY_SHARE_WITH"); ?> </td>
													</tr>
													<tr>
														<td align="center"><span id="span-email"><?php echo JHtml::_('icon.email', $this->items->id, $params)."  Email "; ?></span>&nbsp;<span id="span-fb"><?php echo $this->faceBook."  Facebook "; ?></span>&nbsp;<span id="span-tw"><?php echo $this->twitter."  Twitter"; ?></span></td>
													</tr>
												</table>
											</td>
										</tr>
									</table>
								</td>
							</tr>
							<?php
							}
							if($settings->show_subscription)
							{
								if($this->com_count > 0)
								{ ?>
								<tr>
									<td width="100%" style="padding:0px 15px 0 0;">
										<table cellpadding="0" cellspacing="0" width="100%" border="0">
											<tr>
												<td width="100%" style="border:solid 1px #CACACA;height:45px;">
													<table cellpadding="0" cellspacing="0" border="0" width="100%">
														<tr>
															<td  align="left" style="padding-left:25px;height:30px;"><?php echo JText::_("COM_JEGROUPBUY_SUBSCRIBE_WITH"); ?>&nbsp;<?php echo $this->subscribeEmail."&nbsp;"; ?></td>
														</tr>
													</table>
												</td>
											</tr>
										</table>
									</td>
								</tr>
								<?php	}
							} ?>
						</table>
					</td>
					<td valign="center">
						<?php if($this->items->imageurl == '' || null){ ?>
							<img src="<?php echo JURI::base().'/components/com_jegroupbuy/assets/images/shopping.jpg'; ?>" height="200" border="0">
						<?php } else { ?>
							<img src="<?php echo $this->items->imageurl; ?>" height="300" width="400" border="0">
						<?php } ?>
					</td>
				<!-- Currently Edited -->
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td>
			&nbsp;
		</td>
	</tr>
	<tr>
		<td width="100%">
			<table width="100%">
				<tr>
					<td>
						<h2><?php echo JText::_("COM_JEGROUPBUY_PRODUCT_DESCRIPTION"); ?></h2>
					</td>
				</tr>
				<?php  if((empty($this->items->video) && ($this->params->get('show_video')==0 || $this->params->get('show_video')==1)) || (!empty($this->items->video) && $this->params->get('show_video')==0)){ ?>
					<tr>
						<td width="100%">
							<div style="float:left;width:60%;">
								<?php echo $this->items->description; ?>
							</div>
							<div style="float:right;width:40%;background:#EDF6FF;">
								<div style="padding:5px;">
									<h2 style="margin-left: 22px;color:#000000;font-family:Arial,Helvetica,FreeSans,sans-serif;"><?php echo ucfirst($this->shop->shop_name); ?></h2>
									<?php
									if($settings->show_googlemap)
									{
										echo $this->googlemap;
									}
									if($this->shop->shop_url != ""){
									?>
									<p style="margin:5px 0px 0px 22px;font-size:12px;font-family:Arial,Helvetica,FreeSans,sans-serif;"><span style="font-weight:bold;"><?php echo JText::_("COM_JEGROUPBUY_VISIT_US"); ?></span>
										<a rel="shadowbox" target="_blank" title= "<?php echo $this->shop->shop_url; ?>" text-decoration:"underline" align="center"  style="font-size:12px;" href= "<?php echo $this->shop->shop_url; ?>"><?php echo $this->shop->shop_url; ?></a>
									</p>
									<?php } if($this->shop->email != ""){ ?>
										<p style="margin:5px 0px 0px 22px;font-size:12px;font-family:Arial,Helvetica,FreeSans,sans-serif;"><span style="font-weight:bold;"><?php echo JText::_("COM_JEGROUPBUY_REACH_US"); ?></span><?php echo $this->shop->email; ?></p>
									<?php }  if($this->shop->address != ""){ ?>
										<p style="margin:5px 0px 0px 22px;font-size:13px;font-family:Arial,Helvetica,FreeSans,sans-serif;"><?php echo $this->shop->address; ?></p>
									<?php } ?>
								</div>
							</div>
						</td>
					</tr>
				<?php } ?>
			</table>
		</td>
	</tr> 
<?php
	if(!empty($this->items->video) && $this->params->get('show_video')==1){ ?>
		<tr>
			<td width="100%">
				<div>
					<?php echo $this->items->description; ?>
				</div>
			</td>
		</tr>
		<tr>
			<td width="100%" style="padding-top:10px;">
				<?php $v = $this->items->video;
				$play = explode("=", $v, 2); ?>
				<div style="float:left;width:55%;border:1px solid;" class="popup">
					<object>
						<param name="movie" value="http://www.youtube.com/v/<?php  echo $play[1]; ?>?fs=1&amp;hl=en_US&amp;rel=0">
						<param name="allowFullScreen" value="true">
						<param name="allowscriptaccess" value="always">
						<embed type="application/x-shockwave-flash" src="http://www.youtube.com/v/<?php  echo $play[1]; ?>?fs=1&amp;hl=en_US&amp;rel=0" mce_src="http://www.youtube.com/v/<?php  echo $play[1]; ?>?fs=1&amp;hl=en_US&amp;rel=0" allowscriptaccess="always" id="videoobject" allowfullscreen="true">
					</object>
				</div>
				<div style="float:right;width:40%;background:#EDF6FF;">
					<div style="padding:5px;">
						<h2 style="margin-left: 22px;color:#000000;font-family:Arial,Helvetica,FreeSans,sans-serif;"><?php echo ucfirst($this->shop->shop_name); ?></h2>
						<?php
						if($settings->show_googlemap)
						{
							echo $this->googlemap;
						}
						if($this->shop->shop_url != ""){
						?>
						<p style="margin:5px 0px 0px 22px;font-size:12px;font-family:Arial,Helvetica,FreeSans,sans-serif;"><span style="font-weight:bold;"><?php echo JText::_("COM_JEGROUPBUY_VISIT_US"); ?></span>
							<a rel="shadowbox" target="_blank" title= "<?php echo $this->shop->shop_url; ?>" text-decoration:"underline" align="center"  style="font-size:12px;" href= "<?php echo $this->shop->shop_url; ?>"><?php echo $this->shop->shop_url; ?></a>
						</p>
						<?php } if($this->shop->email != ""){ ?>
							<p style="margin:5px 0px 0px 22px;font-size:12px;font-family:Arial,Helvetica,FreeSans,sans-serif;"><span style="font-weight:bold;"><?php echo JText::_("COM_JEGROUPBUY_REACH_US"); ?></span><?php echo $this->shop->email; ?></p>
						<?php }  if($this->shop->address != ""){ ?>
							<p style="margin:5px 0px 0px 22px;font-size:13px;font-family:Arial,Helvetica,FreeSans,sans-serif;"><?php echo $this->shop->address; ?></p>
						<?php } ?>
					</div>
				</div>
			</td>
		</tr>
<?php
	}
if($settings->show_comments == "1")
{
?>
	<tr>
		<td>
			&nbsp;
		</td>
	</tr>
	<tr>
		<td>
			<h2><?php echo JText::_("COM_JEGROUPBUY_COMMENTS"); ?></h2>
		</td>
	</tr>
	<tr>
		<td>
			&nbsp;
		</td>
	</tr>
	<tr>
		<td>
			<div id="commentContainer">

		<table cellpadding="0" cellspacing="0" width="100%">
			<tr>
		<?php
			$k = 0;
			$bgclr = '';
			foreach($this->comments as $row)
			{
				if($k == 0)
				{
					$bgclr = "#F8F8F8";
				} else {
					$bgclr = "#FAFDF5";
				}
		?>
		<tr>
			<td style="border: 1px solid rgb(0, 0, 0);background-color:<?php echo $bgclr; ?>;border-color:#F1F1F1;padding:5px 15px 5px 10px;">
				<table cellpadding="0" cellspacing="0" width="100%">
					<tr>
						<td width="50%" style="padding:5px;border-bottom:dotted 1px #999999;">
							<b><?php echo $row->name; ?></b>&nbsp; <i><?php echo JHTML::_('date',$row->cdate, JText::_('DATE_FORMAT_LC4')); ?></i>
						</td>
					</tr>
					<tr>
						<td width="100%" style="padding:5px;">
							<?php
							$order   = array("\r\n", "\n", "\n\r", "\t");
							$replace = '<br/>';
							$comments = str_replace($order, $replace, $row->comments);
							$comments =  chunk_split ($comments,80, "<br/>");
							echo $comments;
							?>
						</td>
					</tr>
					<tr>
						<td>&nbsp;</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
		<?php
			$k = 1 - $k;
		}
		?>
		</table>
			</div>
		</td>
	</tr>
	<?php
	$user = JFactory::getUser();
	if (!$user->get('guest')) {
		if($this->userid > 0)
		{ ?>
			<tr>
				<td>
					<textarea cols="80" rows="6" name="comment"></textarea><br/>
				</td>
			</tr>
			<tr>
				<td align="left">
					<input style="padding:6px 8px 11px;" onclick="addComment();" type="button" name="commentButton" class="button" value="Comment"/>
				</td>
			</tr>
	<?php
 		}
	} else { ?>
		<tr>
			<td align="left">
				<?php echo JText::_("COM_JEGROUPBUY_LOGIN"); ?>
			</td>
		</tr>
	<?php
	}
} ?>
</table>
</td>
</tr>
<tr>
	<td>&nbsp;</td>
</tr>
<?php
 if($this->params->get('show_footertext',1)) { ?>
	<tr>
		<td>
			<p class="copyright" align="center">
				<?php require_once( JPATH_COMPONENT . DS . 'copyright' . DS . 'copyright.php' ); ?>
			</p>
		</td>
	</tr>
<?php } ?>
</table>
<input type="hidden" name="path" value="<?php echo JURI::base(); ?>"/>
<input type="hidden" name="pid" value="<?php echo $this->items->id; ?>"/>
</form>