<?php
/*
	osCommerce, Open Source E-Commerce Solutions 
	http://www.oscommerce.com 
	
	Copyright (c) 2003 osCommerce 
	
	 
	
	Freeway eCommerce 
	http://www.openfreeway.org
	Copyright (c) 2007 ZacWare
	
	osConcert, Online Seat Booking 
  	http://www.osconcert.com

  	Copyright (c) 2009-2013 osConcert

	Released under the GNU General Public License
*/



// Set flag that this is a parent file
	define( '_FEXEC', 1 );
	
  require('includes/application_top.php');

  $navigation->remove_current_page();

  require(DIR_WS_LANGUAGES . $FSESSION->language . '/' . FILENAME_POPUP_COUPON_HELP);
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<style><!--
BODY { margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; }
//--></style>
<body marginwidth="10" marginheight="10" topmargin="10" bottommargin="10" leftmargin="10" rightmargin="10">

<?php
  $coupon_query = tep_db_query("select * from " . TABLE_COUPONS . " where coupon_id = '" . tep_db_input($FREQUEST->getvalue('cID')) . "'");
  $coupon = tep_db_fetch_array($coupon_query);
  $coupon_desc_query = tep_db_query("select * from " . TABLE_COUPONS_DESCRIPTION . " where coupon_id = '" . tep_db_input($FREQUEST->getvalue('cID')) . "' and language_id = '" . (int)$FSESSION->languages_id . "'");
  $coupon_desc = tep_db_fetch_array($coupon_desc_query);
  $text_coupon_help = TEXT_COUPON_HELP_HEADER;
  $text_coupon_help .= sprintf(TEXT_COUPON_HELP_NAME, $coupon_desc['coupon_name']);
  if (tep_not_null($coupon_desc['coupon_description'])) $text_coupon_help .= sprintf(TEXT_COUPON_HELP_DESC, $coupon_desc['coupon_description']);
  $coupon_amount = $coupon['coupon_amount'];
  switch ($coupon['coupon_type']) {
    case 'F':
    $text_coupon_help .= sprintf(TEXT_COUPON_HELP_FIXED, $currencies->format($coupon['coupon_amount']));
    break;
    case 'P':
    $text_coupon_help .= sprintf(TEXT_COUPON_HELP_FIXED, number_format($coupon['coupon_amount'],2). '%');
    break;
    case 'S':
    $text_coupon_help .= TEXT_COUPON_HELP_FREESHIP;
    break;
    default:
  }
  if ($coupon['coupon_minimum_order'] > 0 ) $text_coupon_help .= sprintf(TEXT_COUPON_HELP_MINORDER, $currencies->format($coupon['coupon_minimum_order']));
  $text_coupon_help .= sprintf(TEXT_COUPON_HELP_DATE, format_date($coupon['coupon_start_date']),format_date($coupon['coupon_expire_date'])); 
  $text_coupon_help .= '<b>' . TEXT_COUPON_HELP_RESTRICT . '</b>';
  $text_coupon_help .= '<br><br>' .  TEXT_COUPON_HELP_CATEGORIES;
  $coupon_get=tep_db_query("select restrict_to_categories from " . TABLE_COUPONS . " where coupon_id='".tep_db_input($FREQUEST->getvalue('cID'))."'");
  $get_result=tep_db_fetch_array($coupon_get);

  $cat_ids = preg_split("/[,]/", $get_result['restrict_to_categories']);
  for ($i = 0; $i < count($cat_ids); $i++) {
    $result = tep_db_query("SELECT * FROM categories, categories_description WHERE categories.categories_id = categories_description.categories_id and categories_description.language_id = '" . (int)$FSESSION->languages_id . "' and categories.categories_id='" . (int)$cat_ids[$i] . "'");
    if ($row = tep_db_fetch_array($result)) {
    $cats .= '<br>' . $row["categories_name"];
    } 
  }
  if ($cats=='') $cats = '<br>NONE';
  $text_coupon_help .= $cats;
  $text_coupon_help .= '<br><br>' .  TEXT_COUPON_HELP_PRODUCTS;
  $coupon_get=tep_db_query("select restrict_to_products,restrict_to_events from " . TABLE_COUPONS . "  where coupon_id='".tep_db_input($FREQUEST->getvalue('cID'))."'");
  $get_result=tep_db_fetch_array($coupon_get);

  $pr_ids = preg_split("/[,]/", $get_result['restrict_to_products']);
  for ($i = 0; $i < count($pr_ids); $i++) {
    $result = tep_db_query("SELECT * FROM products, products_description WHERE products.products_id = products_description.products_id and products_description.language_id = '" . (int)$FSESSION->languages_id . "'and products.products_id = '" . (int)$pr_ids[$i] . "'");
    if ($row = tep_db_fetch_array($result)) {
      $prods .= '<br>' . $row["products_name"];
    }
  }
  if ($prods=='') $prods = '<br>NONE';
  $text_coupon_help .= $prods;
  
  $ev_ids= preg_split("/[,]/", $get_result['restrict_to_events']);
  	for ($i = 0; $i < count($ev_ids); $i++) {
    $result = tep_db_query("SELECT * FROM events e, events_description ed WHERE e.events_id = ed.events_id and ed.language_id = '" . (int)$FSESSION->languages_id . "'and e.events_id = '" . (int)$ev_ids[$i] . "'");
    if ($row = tep_db_fetch_array($result)) {
      $events .= '<br>' . $row["events_name"];
    }
  }
  if ($events=='') $events = '<br>NONE';
  $text_coupon_help .= '<br><br>' .  TEXT_COUPON_HELP_EVENTS;
  $text_coupon_help .= $events;
  


  $info_box_contents = array();
  $info_box_contents[] = array('text' => HEADING_COUPON_HELP);


  new infoBoxHeading($info_box_contents, true, true);

?>
<table width="100%" align="center" cellpadding="2" cellspacing="3">
	<tr><td class="smallText"><?php echo $text_coupon_help;?></td></tr>
</table>
<p class="smallText" align="right"><?php echo '<a href="javascript:window.close()">' . TEXT_CLOSE_WINDOW . '</a>'; ?></p>

</body>
</html>
<?php require('includes/application_bottom.php'); ?>