<?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" id="prod_container">
<tr>
<td align="right" style="padding:5px 35px 5px 0px;">
<?php echo JText::_("COM_JEGROUPBUY_CATEGORY"); ?>&nbsp;
<?php
 echo JHTML::_('select.genericlist', $this->cNameOption , 'cid', 'class="inputbox" size="1" onChange="document.adminForm.submit();"', 'id','name', $this->cid);
?>
</td>
</tr>
<link rel="stylesheet" type="text/css" href="<?php echo JURI::root().'components/com_jegroupbuy/assets/images/layout2/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();
	$k = 1;
	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:%M:%S");
		$deal_date1 = JHTML::_('date',  $split_date[0]." 23:59:00", "%Y-%m-%d %H:%M:%S");
		$today_date1 = JHTML::_('date',  time(), "%Y-%m-%d %H:%M:%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");
		//echo $deal_date;
		$query = "SELECT count(*) FROM #__jegroupbuy_payment AS p 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&task=productdetails&pid='.$items->id);
		}
		?>
		<tr class="<?php echo "row$k"; ?>">
			<td>
				<table width="96%"  border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td class="table_t_l"></td>
						<td class="table_t_m"></td>
						<td class="table_t_r"></td>
					</tr>
					<tr>
						<td class="table_m_l">
						</td>
						<td class="table_m_m" >
							<table width="100%"  border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td  width="150" height="110">
										<table width="100%"  border="0" cellpadding="0" cellspacing="0">
											<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 = "100%;" src="<?php echo JURI::base().'/components/com_jegroupbuy/assets/images/shopping.jpg'; ?>" border="0">
													<?php } else { ?>
													<img style="margin:0px;padding-top:10px;" width = "100%;" src="<?php echo JURI::base().'images/jegroupbuy/category/'.$items->imageurl; ?>"  border="0">
													<?php } ?>
													</a>
												</td>
											</tr>
										</table>
									</td>
									<td style="padding:8px;">
										<table width="100%"  border="0" cellpadding="0" cellspacing="0">
											<tr>
												<td>
													<table width="100%"  border="0" cellpadding="0" cellspacing="0">
														<tr>
															<td>
																<table width="100%"  border="0" cellpadding="0" cellspacing="0">
																	<tr>
																		<td class="product_name_icon">
																		</td>
																		<td align="left">
																			<span class="prod_title"><a href="<?php echo $product_rul; ?>" style="text-decoration:none;color:#171717;"><?php echo $this->limit_characters( $items->title, 15 ); ?></a></span>
																		</td>
																	</tr>
																</table>
															</td>
														</tr>

														<tr>
															<td style="padding:5px 0px 5px 0px;">
																<table width="100%"  border="0" cellpadding="0" cellspacing="0">
																	<tr>
																		<td class="innertable_t_l"></td>
																		<td class="innertable_t_m"></td>
																		<td class="innertable_t_r"></td>
																	</tr>
																	<tr>
																		<td class="innertable_m_l"></td>
																		<td class="innertable_m_m">
																		<table width="100%"  border="0" cellpadding="0" cellspacing="0">
																			<tr>
																				<td width="55%">
																					<table width="100%"  border="0" cellpadding="0" cellspacing="0">
																						<tr>
																							<td class="buynow_left">
																							</td>
																							<td class="buynow_middle" style="padding-left:8px;">
																							<span class="prod_buy_now"><?php echo JText::_("COM_JEGROUPBUY_BUYNOW"); ?></span>
																							</td>
																							<td class="buynow_right">
																							</td>
																						</tr>
																					</table>
																				</td>
																				<td width="45%">
																					<table width="100%"  border="0" cellpadding="3" cellspacing="0">
																						<tr>
																							<td align="center">
																								<span class="prod_deal_price_label"><?php echo JText::_("COM_JEGROUPBUY_DEAL_PRICE"); ?></span>
																							</td>
																						</tr>
																						<tr>
																							<td align="center">
																								<span class="prod_deal_price"><?php
																								if($items->currencysymbol == "1") $symbol = "&#36";
																								elseif($items->currencysymbol == "2") $symbol = "&#163";
																								elseif($items->currencysymbol == "3") $symbol = "&#165";
																								elseif($items->currencysymbol == "4") $symbol = "&#128";
																								else $symbol = "INR";
																								echo $symbol.' '.$items->deal_price; ?></span>
																							</td>
																						</tr>
																					</table>
																				</td>
																			</tr>
																		</table>
																		</td>
																		<td class="innertable_m_r"></td>
																	</tr>
																	<tr>
																		<td class="innertable_b_l"></td>
																		<td class="innertable_b_m"></td>
																		<td class="innertable_b_r"></td>
																	</tr>
																</table>
															</td>
														</tr>
														<tr>
															<td>
																<table width="100%"  border="0" cellpadding="0" cellspacing="0">
																	<tr>
																		<td class="moreinfo_icon">
																		</td>
																		<td align="left">
																			&nbsp;<a href="<?php echo $product_rul; ?>" style="text-decoration:none;color:#017793;"><?php echo JText::_("COM_JEGROUPBUY_MOREINFO"); ?></a>
																		</td>
																	</tr>
																</table>
															</td>
														</tr>
													</table>
												</td>
												<td width="250" align="center" style="padding-left:8px;">
													<table width="90%"  border="0" cellpadding="0" cellspacing="0">
														<tr>
															<td width="33%" style="padding-left:5px;" align="left"><b><?php echo JText::_("COM_JEGROUPBUY_DEAL_VALUE"); ?></b>
															</td>
															<td width="33%" style="padding-left:5px;" align="left"><b><?php echo JText::_("COM_JEGROUPBUY_DEAL_DISCOUNT"); ?></b>
															</td>
															<td width="33%" style="padding-left:5px;" align="left"><b><?php echo JText::_("COM_JEGROUPBUY_DEAL_YOUSAVE"); ?></b>
															</td>
														</tr>
														<tr>
															<td width="33%" style="padding:5px;" class="price_detials<?php echo $k; ?>">
																<table width="100%"  border="0" cellpadding="0" cellspacing="0">
																	<tr>
																		<td class="price_box" align="center">
																		<b><?php echo $symbol.' '.$items->product_price; ?></b>
																		</td>
																	</tr>
																</table>
															</td>
															<td width="33%" style="padding:5px;" class="price_detials<?php echo $k; ?>">
																<table width="100%"  border="0" cellpadding="0" cellspacing="0">
																	<tr>
																		<td class="price_box" align="center">
																		<b><?php echo $items->product_discount."%"; ?></b>
																		</td>
																	</tr>
																</table>
															</td>
															<td width="33%" style="padding:5px;" class="price_detials<?php echo $k; ?>">
																<table width="100%"  border="0" cellpadding="0" cellspacing="0">
																	<tr>
																		<td class="price_box" align="center">
																		<b><?php echo $symbol.' '.$items->you_save; ?></b>
																		</td>
																	</tr>
																</table>
															</td>
														</tr>
														<tr>
															<td colspan="3">&nbsp;</td>
														</tr>
														<tr>
															<td colspan="3">
																<table width="100%"  border="0" cellpadding="0" cellspacing="0">
																	<tr>
																		<td align="center">
																		<?php echo sprintf(JText::_("COM_JEGROUPBUY_NUMBER_OF_COUPONS"),$number_of_bought,$total_products); ?>
																		</td>
																	</tr>
																	<tr>
																	<td align="center">
																		<?php
																		//$deal_date = JHTML::_('date',  $items->deal_to_date, "Y-m-d");
																		unset($deal_date_sp);
																		$deal_date_sp = explode("-",$deal_date);
																		?>
																		<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>
							</table>
						</td>
						<td class="table_m_r">
						</td>
					</tr>
					<tr>
						<td class="table_b_l">
						</td>
						<td class="table_b_m">
						</td>
						<td class="table_b_r">
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
		<?php
			$k = 1 - $k;
	}
}
?>
<tr>
	<td>
		<div id="je-pagination" >
			 <?php echo $this->pageNav->getListFooter(); ?>
		</div>
	</td>
</tr>
<tr>
	<td>&nbsp;</td>
</tr>
<?php if($this->settings == '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="jegroupbuy"/>
</form>
