<?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;
?>
<form action="<?php echo JRoute::_('index.php'); ?>" method="post" name="adminForm">
<table width="100%" cellpadding="0" cellspacing="0" class="searchBox">
<td>

<link rel="stylesheet" type="text/css" href="<?php echo JURI::root().'components/com_jegroupbuy/assets/images/layout3/css/style.css'?>">
<div id="respOutput"></div>

<input type="hidden" name="path" value="<?php echo JURI::base();?>">
<?php
if(count( $this->items ) )
{
	$db	= JFactory::getDBO();
	foreach ($this->items as $items)
	{

		$split_date = explode(" ",$items->deal_to_date);
		$deal_date1 = JHTML::_('date',  $split_date[0]." 23:59:00", "Y-m-d h:i:s");
		$today_date1 = JHTML::_('date',  time(), "Y-m-d h:i:s");
		$total_products = $items->total_bought;
		$deal_date = JHTML::_('date',  $items->deal_to_date, "Y-m-d");
		$today_date = JHTML::_('date',  time(), "Y-m-d");
		$query		= $db->getQuery(true);
		$query->select('count(*)');
		$query->from('#__jegroupbuy_payment AS p');
		$query->where('p.p_id = '.$items->id);
		$db->setQuery($query);
		$number_of_bought		= $db->loadResult();

		if(($number_of_bought >= $total_products) || (strtotime($today_date1) > strtotime($deal_date1)))
		{
			if($items->expired == 0)
			{
				$sql = "UPDATE #__jegroupbuy_product SET expired = 1 WHERE id=".$items->id;
				$db->setQuery($sql);
				$db->query();
				$items->expired = 1;
			}
		}else
		{
			if($items->expired == 1)
			{
				$sql = "UPDATE #__jegroupbuy_product SET expired = 0 WHERE id=".$items->id;
				$db->setQuery($sql);
				$db->query();
				$items->expired = 0;
			}
		}

		if($items->expired > 0)
		{
			$product_rul = "javascript:void(0);";
		}else
		{
			$product_rul = JRoute::_('index.php?option=com_jegroupbuy&view=productdetails&pid='.$items->id);
		}
		?>
		<div style="width:250px;margin:5px;" class="prod_container" id="prod_container">
		<div style="position:relative;">
			<table width="100%" border="0" cellapdding="0" cellspacing="0">
				<tr>
					<td>
						&nbsp;
					</td>
				</tr>
				<tr>
					<td>
						&nbsp;
					</td>
				</tr>
				<tr>
					<td align="center">
						<div class="product_top_head">
							<table width="100%" border="0" cellapdding="0" cellspacing="0">
								<tr>
									<td width="60%" class="phed_middle_img" align="center">
										<h2 style="margin:0px;padding:0px;color:#FFFFFF;"><?php echo JText::_("COM_JEGROUPBUY_DEAL_PRICE"); ?></h2>
									</td>
									<td width="40%" style="background-color:#FFD02E;" align="center">
										<h2 style="margin:0px;color:#000000;"><?php echo  $items->currencysymbol.' '.$items->deal_price; ?></h2>
									</td>
								</tr>
							</table>
						</div>
					</td>
				</tr>
				<tr>
					<td style="border:solid 1px #AFC6D6;">
						<table width="100%" align="center" border="0" cellapdding="0" cellspacing="0" style="padding:5px;">
							<tr>
								<td colspan="2" style="background-color:#03556B;border-bottom:solid 1px #077694;">
									<table width="100%" align="center" border="0" cellapdding="0" cellspacing="0">
										<tr height="45">
											<td>&nbsp;</td>
										</tr>
										<tr>
											<td align="center" ><a href="<?php echo $product_rul; ?>" style="text-decoration:none;padding:0px;margin:0px;">
												<?php if($items->imageurl == '' || null) { ?>
												<img style="margin:0px;padding-top:10px;" width = "77%;" src="<?php echo JURI::base().'/components/com_jegroupbuy/assets/images/shopping.jpg'; ?>" border="0">
												<?php } else { ?>
												<img style="margin:0px;padding-top:10px;" width = "77%;" src="<?php echo $items->imageurl; ?>"  border="0">
												<?php } ?></a>
											</td>
										</tr>
										<tr height="45">
											<td colspan="2" align="center">
												<span class="prod_title"><a href="<?php echo $product_rul; ?>" style="text-decoration:none;color:#FFFFFF;"><?php echo $this->limit_characters( $items->title, 15 ); ?></a></span>
											</td>
										</tr>
									</table>
								</td>
							</tr>
							<!--<tr>
								<td colspan="2" style="border:solid 2px #FFFFFF;height:39px;">
									<table width="100%" align="center" border="0" cellapdding="0" cellspacing="0">
										<tr>
											<td align="center" class="deal_price_msg" valign="middle" width="60%" style="height:39px;">
												<h2 style="margin:0px;padding:0px;color:#FFFFFF;"><?php echo JText::_("COM_JEGROUPBUY_DEAL_PRICE"); ?></h2>
											</td>
											<td align="center" class="deal_price_arrow"  valign="middle" width="40%" style="height:39px;">
												<h2 style="margin:0px;padding:0px;color:#FFFFFF;"><?php echo $items->deal_price; ?></h2>
											</td>
										</tr>
									</table>
								</td>
							</tr>-->
							<tr>
								<td colspan="2" >
										<table width="100%" align="center" border="0" cellapdding="0" cellspacing="0" style="color:#FFFFFF;background-color:#023F51;">
													<tr>
														<td width="100%">
															<table width="100%" align="center" border="0" cellapdding="0" cellspacing="0" >
																<tr>
																	<td width="33.3%" align="center" style="height:33px;">
																		<?php echo JText::_("COM_JEGROUPBUY_DEAL_VALUE"); ?>
																	</td>
																	<td width="33.3%" align="center" style="height:33px;">
																		<?php echo JText::_("COM_JEGROUPBUY_DEAL_DISCOUNT"); ?>
																	</td>
																	<td width="33.3%" align="center" style="height:33px;">
																		<?php echo JText::_("COM_JEGROUPBUY_DEAL_YOUSAVE"); ?>
																	</td>
																</tr>
															</table>
														</td>
													</tr>
													<tr>
														<td width="100%">
															<table width="100%" align="center" border="0" cellapdding="0" cellspacing="0" style="color:#FBF911;border-bottom:dotted 1px #FFFFFF;">
																<tr>
																	<td width="33.3%" align="center" valign="top" style="height:33px;" >
																		<b><?php echo  $items->currencysymbol.' '.$items->product_price; ?></b>
																	</td>
																	<td width="33.3%" align="center" valign="top" style="height:33px;" >
																		<b><?php echo $items->product_discount."%"; ?></b>
																	</td>
																	<td width="33.3%" align="center" valign="top" style="height:33px;" >
																		<b><?php echo  $items->currencysymbol.' '.$items->you_save; ?></b>
																	</td>
																</tr>
															</table>
														</td>
													</tr>
													<tr>
														<td width="100%">
															<table width="100%" align="center" border="0" cellapdding="0" cellspacing="0" >
																<tr>
																	<td align="center" style="padding:5px;">
																		<?php echo sprintf(JText::_("COM_JEGROUPBUY_NUMBER_OF_COUPONS"),$number_of_bought,$total_products); ?>
																	</td>
																</tr>
																<tr>
																	<td align="center" style="padding:5px;">
																		<?php
																		//$deal_date = JHTML::_('date',  $items->deal_to_date, "Y-m-d");
																		unset($deal_date_sp);
																		$deal_date_sp = explode("-",$deal_date);
																		?>
															                <p><?php echo JText::_("COM_JEGROUPBUY_TIME_LEFT_TO_BUY"); ?></p>
																			<span class="prod_timer">
																                <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 $items->id; ?>";
																                eCheck = "<?php echo $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>
												</table>
											</td>
										</tr>
								</table>
							</td>
						</tr>
					<tr height="28">
						<td>
							<div class="product_footer_bg">
								<div class="product_footer_left">
									<div class="product_footer_right">
								</div>
							</div>
						</div>
					</td>
				</tr>
			</table>

			</div>
		</div>
		<?php
	}
}
?>

</td>
</tr>
<tr>
	<td>
		<!-- Area for pagination -->
			<div id="jefaqpro-paginationarea" style="text-align : center;">
				<!-- Limit Box Drop down -->
				<div class="je-limitbox">
					<label for="limit">
						<?php echo JText::_('JGLOBAL_DISPLAY_NUM'); ?>
					</label>
					<?php echo $this->pagination->getLimitBox(); ?>
				</div>

				<?php
				if( $this->pagination->get('pages.total') > 1) {
				?>
					<!-- Page counter display -->
					<div class="je-pagecounter">
						<?php
							echo $this->pagination->getPagesCounter();
						?>
					</div>

					<!-- Pagination with page links -->
					<div  id="je-pagination" class="pagination">
						<?php echo $this->pagination->getPagesLinks(); ?>
					</div>
				<?php
				}
				?>
			</div>
		<!-- End for pagination -->
	</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="option" value="com_jegroupbuy"/>
<input type="hidden" name="view" value="category"/>
</form>
