<?php
/*
  $Id: specials.php,v 1.41 2003/06/29 22:50:52 hpdl Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

  require('includes/application_top.php');

  require(DIR_WS_CLASSES . 'currencies.php');
  $currencies = new currencies();

function tep_date_raws($date) {
    return substr($date, 0, 4) . substr($date, 5, 2) . substr($date, 8, 2);
}

function tep_date_now() {
	return date('Y').date('m').date('d');
}  

function checkdatenumber($startdate,$enddate)
{
	$is_ok=0;
	if (tep_date_raw($startdate)>tep_date_raw($enddate))
	{
		$is_ok=0;
	}
	else
	{
		    $check_query = tep_db_query("select * from specials_daily s where  not (UNIX_TIMESTAMP(date_format(s.star_date,'%Y%m%d')) > UNIX_TIMESTAMP('" . tep_date_raws($enddate) . "') or UNIX_TIMESTAMP(date_format(s.end_date,'%Y%m%d')) < UNIX_TIMESTAMP('" . tep_date_raws($startdate) . "'))");
			if (tep_db_num_rows($check_query)>0) 
				$is_ok=0;
			else
				$is_ok=1;
	}
	return $is_ok;
}


function checkdatenumber_up($startdate,$enddate,$sid)
{
	$is_ok=0;
	if (tep_date_raw($startdate)>tep_date_raw($enddate))
	{
		$is_ok=0;
	}
	else
	{
		    $check_query = tep_db_query("select * from specials_daily s where  not (UNIX_TIMESTAMP(date_format(s.star_date,'%Y%m%d')) > UNIX_TIMESTAMP('" . tep_date_raws($enddate) . "') or UNIX_TIMESTAMP(date_format(s.end_date,'%Y%m%d')) < UNIX_TIMESTAMP('" . tep_date_raws($startdate) . "')) and s.specials_daily_id <> '".(int)$sid."'");
			if (tep_db_num_rows($check_query)>0) 
				$is_ok=0;
			else
				$is_ok=1;
	}
	return $is_ok;
}


  function tep_set_weeklyspecials_status($specials_id, $status) {
    if ($status == '1') {


	//replace the price for the old product
			  $old_query = tep_db_query("select products_id,new_price,old_price,star_date,end_date from specials_daily where specials_daily_id = '" . (int)$specials_id . "'");
			  $oldp = tep_db_fetch_array($old_query);
			  $old_products_id = $oldp['products_id'];
			  $old_products_price = $oldp['old_price'];
			  $new_products_price = $oldp['new_price'];
			  $star_date = $oldp['star_date'];
			  $end_date = $oldp['end_date'];
	//end replace
		      if ((tep_db_query("update specials_daily set status = '1' where specials_daily_id = '" . (int)$specials_id . "'")==true) && (tep_date_raws($end_date)>=tep_date_now() && tep_date_raws($star_date)<=tep_date_now()))
				{
				  tep_db_query("update products set products_price='".$new_products_price."' where products_id='".(int)$old_products_id."' limit 1");
				}
      return 0;

    } elseif ($status == '0') {

	//replace the price for the old product
			  $old_query = tep_db_query("select products_id,new_price,old_price from specials_daily where specials_daily_id = '" . (int)$specials_id . "'");
			  $oldp = tep_db_fetch_array($old_query);
			  $old_products_id = $oldp['products_id'];
			  $old_products_price = $oldp['old_price'];
			  $new_products_price = $oldp['new_price'];
	//end replace
		      if (tep_db_query("update specials_daily set status = '0' where specials_daily_id = '" . (int)$specials_id . "'")==true)
				{
				  tep_db_query("update products set products_price='".$old_products_price."' where products_id='".(int)$old_products_id."' limit 1");
				}
      return 0;

    } else {
      return -1;
    }
  }


  function check_code_is_existed($code)
{
			$is_exist=0;
			  $p_query = tep_db_query("select products_id from  products where products_status=1 and upper(code) = upper('" . $code . "')");
			  $ppp = tep_db_fetch_array($p_query);
			  $products_id = $ppp['products_id'];
				if ($products_id>0)
				{
					  $s_query = tep_db_query("select * from  specials where products_id = '" . (int)$products_id . "'");
						if (tep_db_num_rows($s_query)>0)
							$is_exist=1;
				}
			return $is_exist;
}


  $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');

  if (tep_not_null($action)) {
    switch ($action) {
      case 'setflag':
        tep_set_weeklyspecials_status($HTTP_GET_VARS['id'], $HTTP_GET_VARS['flag']);

        tep_redirect(tep_href_link('specials_daily.php', (isset($HTTP_GET_VARS['page']) ? 'page=' . $HTTP_GET_VARS['page'] . '&' : '') . 'sID=' . $HTTP_GET_VARS['id'], 'NONSSL'));
        break;
      case 'insert':
        $specials_code = tep_db_prepare_input($HTTP_POST_VARS['specials_code']);
        $specials_price = tep_db_prepare_input($HTTP_POST_VARS['specials_price']);
        $specials_start_date = tep_db_prepare_input($HTTP_POST_VARS['startdate']);
        $specials_end_date = tep_db_prepare_input($HTTP_POST_VARS['enddate']);

if (empty($specials_code) || empty($specials_price) || empty($specials_start_date) || empty($specials_end_date))
{
        tep_redirect(tep_href_link('specials_daily.php', 'page=' . $HTTP_GET_VARS['page']));
}
else
{
		if (checkdatenumber($specials_start_date,$specials_end_date)<=0)
		{
	    	    tep_redirect(tep_href_link('specials_daily.php', 'page=' . $HTTP_GET_VARS['page']));
		}
		else
		{
		//get products (products id,  products price)
				 if (check_code_is_existed($specials_code)==1)
					{
							tep_redirect(tep_href_link('specials_daily.php', 'page=' . $HTTP_GET_VARS['page']));
					}
					else
					{
		
						  $new_special_insert_query = tep_db_query("select products_id, products_price from " . TABLE_PRODUCTS . " where products_status=1 and upper(code) = upper('" . $specials_code . "')");
						  $new_special_insert = tep_db_fetch_array($new_special_insert_query);
						  $products_id = $new_special_insert['products_id'];
						  $products_price = $new_special_insert['products_price'];
				//get end
		
				
				//get max sort it start
		/*
								  $max_sort=0;
								  $get_max_query = tep_db_query("select max(sort) as max_sort from specials_daily");
								  $spe = tep_db_fetch_array($get_max_query);
								  $max_sort=$spe['max_sort'];
								  if (($max_sort=="") || ($max_sort<=0))
										$max_sort=1;
								  else
										$max_sort++;
		*/
				//get end
				
		//echo "id==".(int)$products_id;
						if ((int)$products_id >0 )
						{
							if (tep_db_query("insert into specials_daily (products_id, new_price,old_price,star_date,end_date, status) values ('" . (int)$products_id . "', '" . tep_db_input($specials_price) . "', '" . $products_price . "', '".$specials_start_date."', '".$specials_end_date."','0')")==true && (tep_date_raws($specials_end_date)>=tep_date_now() && tep_date_raws($specials_start_date)<=tep_date_now()))
							{
								//replace the price for this product
								tep_db_query("update products set products_price='".tep_db_input($specials_price)."' where products_id='".(int)$products_id."' limit 1");
								//end replace
							}
						}		
						tep_redirect(tep_href_link('specials_daily.php', 'page=' . $HTTP_GET_VARS['page']));
					}
		}
}
        break;
      case 'update':
        $specials_daily_id = tep_db_prepare_input($HTTP_POST_VARS['specials_daily_id']);
        $specials_code = tep_db_prepare_input($HTTP_POST_VARS['specials_code']);
        $specials_price = tep_db_prepare_input($HTTP_POST_VARS['specials_price']);
        $specials_start_date = tep_db_prepare_input($HTTP_POST_VARS['startdate']);
        $specials_end_date = tep_db_prepare_input($HTTP_POST_VARS['enddate']);

if (empty($specials_code) || empty($specials_price) || empty($specials_start_date) || empty($specials_end_date) || empty($specials_daily_id))
{
        tep_redirect(tep_href_link('specials_daily.php', 'page=' . $HTTP_GET_VARS['page']));
}
else
{
		if (checkdatenumber_up($specials_start_date,$specials_end_date,$specials_daily_id)<=0)
		{
	    	    tep_redirect(tep_href_link('specials_daily.php', 'page=' . $HTTP_GET_VARS['page']));
		}
		else
		{
				 if (check_code_is_existed($specials_code)==1)
					{
							tep_redirect(tep_href_link('specials_daily.php', 'page=' . $HTTP_GET_VARS['page']));
					}
					else
					{

					//replace the price for the old product
							  $old_query = tep_db_query("select products_id,old_price,status from specials_daily where specials_daily_id = '" . (int)$specials_daily_id . "'");
							  $oldp = tep_db_fetch_array($old_query);
							  $old_products_id = $oldp['products_id'];
							  $old_products_price = $oldp['old_price'];
							  $status = $oldp['status'];
							  tep_db_query("update products set products_price='".$old_products_price."' where products_id='".(int)$old_products_id."' limit 1");
					//end replace
				
					
					//get products (products id,  products price)
							  $new_special_insert_query = tep_db_query("select products_id, products_price from " . TABLE_PRODUCTS . " where products_status=1 and upper(code) = upper('" . $specials_code . "')");
							  $new_special_insert = tep_db_fetch_array($new_special_insert_query);
							  $products_id = $new_special_insert['products_id'];
							  $products_price = $new_special_insert['products_price'];
					//get end
					
							if (tep_db_query("update specials_daily set new_price = '" . tep_db_input($specials_price) . "',old_price = '" . $products_price . "', products_id = '" . (int)$products_id . "', star_date = '" . $specials_start_date . "', end_date = '" . $specials_end_date . "' where specials_daily_id = '" . (int)$specials_daily_id . "'")==true && $status==1  && (tep_date_raws($specials_end_date)>=tep_date_now() && tep_date_raws($specials_start_date)<=tep_date_now()))
							{
										//replace the price for this product
										tep_db_query("update products set products_price='".tep_db_input($specials_price)."' where products_id='".(int)$products_id."' limit 1");
										//end replace
							}
					
							tep_redirect(tep_href_link('specials_daily.php', 'page=' . $HTTP_GET_VARS['page'] . '&sID=' . $specials_daily_id));
					}
		}
}
        break;
      case 'deleteconfirm':
        $specials_daily_id = tep_db_prepare_input($HTTP_GET_VARS['sID']);

	//replace the price for the old product
			  $old_query = tep_db_query("select products_id,old_price from specials_daily where specials_daily_id = '" . (int)$specials_daily_id . "'");
			  $oldp = tep_db_fetch_array($old_query);
			  $old_products_id = $oldp['products_id'];
			  $old_products_price = $oldp['old_price'];
	//end replace
		      if (tep_db_query("delete from specials_daily where specials_daily_id = '" . (int)$specials_daily_id . "'")==true)
				{
				  tep_db_query("update products set products_price='".$old_products_price."' where products_id='".(int)$old_products_id."' limit 1");
				}

        tep_redirect(tep_href_link('specials_daily.php', 'page=' . $HTTP_GET_VARS['page']));
        break;
    }
  }
?>
<!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; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<script language="javascript" src="includes/general.js"></script>
<link rel="stylesheet" type="text/css" href="includes/calendar/dateselector.css">
<script language="JavaScript" src="includes/calendar/popup_lib.js"></script>
<script language="JavaScript" src="includes/calendar/dateselector.js"></script>
<script language="JavaScript" type="text/JavaScript" src='function.js'></script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onload="SetFocus();">
<div id="popupcalendar" class="text"></div>
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr>
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
    </table></td>
<!-- body_text //-->
    <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
            <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
          </tr>
        </table></td>
      </tr>
<?php
  if ( ($action == 'new') || ($action == 'edit') ) {
    $form_action = 'insert';
    if ( ($action == 'edit') && isset($HTTP_GET_VARS['sID']) ) {
      $form_action = 'update';

      $product_query = tep_db_query("select p.products_id,p.code, pd.products_name, p.products_price, s.specials_daily_id,s.new_price,s.old_price,s.star_date,s.end_date from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, specials_daily s where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = s.products_id and s.specials_daily_id = '" . (int)$HTTP_GET_VARS['sID'] . "' order by s.star_date");
      $product = tep_db_fetch_array($product_query);

      $sInfo = new objectInfo($product);
    } else {
      $sInfo = new objectInfo(array());

// create an array of products on special, which will be excluded from the pull down menu of products
// (when creating a new product on special)
      $specials_array = array();
      $specials_query = tep_db_query("select p.products_id from " . TABLE_PRODUCTS . " p, specials_daily s where s.products_id = p.products_id");
      while ($specials = tep_db_fetch_array($specials_query)) {
        $specials_array[] = $specials['products_id'];
      }
    }
?>


      <tr><form name="new_special" <?php echo 'action="' . tep_href_link('specials_daily.php', tep_get_all_get_params(array('action', 'info', 'sID')) . 'action=' . $form_action, 'NONSSL') . '"'; ?> method="post"><?php if ($form_action == 'update') echo tep_draw_hidden_field('specials_daily_id', $HTTP_GET_VARS['sID']); ?>
        <td><br><table border="0" cellspacing="0" cellpadding="2">
          <tr>
            <td class="main"><?php echo TEXT_SPECIALS_PRODUCT; ?>&nbsp;</td>
            <td class="main"><?php echo tep_draw_input_field('specials_code', (isset($sInfo->code) ? $sInfo->code : ''));?>&nbsp;&nbsp;&nbsp;Product Name:<?=(isset($sInfo->products_name) ? $sInfo->products_name : '')?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_SPECIALS_SPECIAL_PRICE; ?>&nbsp;</td>
            <td class="main"><?php echo tep_draw_input_field('specials_price', (isset($sInfo->new_price) ? $sInfo->new_price : '')); ?>&nbsp;&nbsp;&nbsp;Old Price:<?=(isset($sInfo->products_price) ? $sInfo->old_price : '')?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_SPECIALS_EXPIRES_DATE; ?><br><small>(YYYY-MM-DD)</small>&nbsp;</td>
            <td class="main"><input name="startdate" type="text" id="startdate" size="12" class='bg' readonly value="<?=(isset($sInfo->star_date) ? substr($sInfo->star_date,0,10) : '')?>" ><img src='images/date_selector.gif' class="MouseHandle" width='16' height='18' vspace='0' hspace='3' border='0' onClick="popUpCalendar(this , new_special.startdate, 'yyyy-mm-dd');" alt="select start date" >&nbsp;-&nbsp;<input name="enddate" type="text" id="enddate" size="12" class='bg' readonly  value="<?=(isset($sInfo->end_date) ? substr($sInfo->end_date,0,10) : '')?>"><img src='images/date_selector.gif' class="MouseHandle" width='16' height='18' vspace='0' hspace='3' border='0' onClick="popUpCalendar(this , new_special.enddate, 'yyyy-mm-dd');" alt="select end date" ></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
          <tr>
            <td class="main"><br><?php echo TEXT_SPECIALS_PRICE_TIP; ?></td>
            <td class="main" align="right" valign="top"><br><?php echo (($form_action == 'insert') ? tep_image_submit('button_insert.gif', IMAGE_INSERT) : tep_image_submit('button_update.gif', IMAGE_UPDATE)). '&nbsp;&nbsp;&nbsp;<a href="' . tep_href_link('specials_daily.php', 'page=' . $HTTP_GET_VARS['page'] . (isset($HTTP_GET_VARS['sID']) ? '&sID=' . $HTTP_GET_VARS['sID'] : '')) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>'; ?></td>
          </tr>
        </table></td>
      </form></tr>
<?php
  } else {
?>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent" width="2%">Code</td>
                <td class="dataTableHeadingContent" width="20%"><?php echo TABLE_HEADING_PRODUCTS; ?></td>
                <td class="dataTableHeadingContent" width="5%">Start Date</td>
                <td class="dataTableHeadingContent" width="5%">End Date</td>
                <td class="dataTableHeadingContent" width="5%" align="right"><?php echo TABLE_HEADING_PRODUCTS_PRICE; ?></td>
                <td class="dataTableHeadingContent" width="5%"align="right"><?php echo TABLE_HEADING_STATUS; ?></td>
                <td class="dataTableHeadingContent" width="5%" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
              </tr>
<?php
$currentcode="";
    $specials_query_raw = "select p.products_id, pd.products_name, p.products_price,p.code, s.specials_daily_id, s.new_price,s.old_price, s.status,s.star_date,s.end_date from " . TABLE_PRODUCTS . " p, specials_daily s, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = s.products_id order by s.star_date ,pd.products_name";
    $specials_split = new splitPageResults($HTTP_GET_VARS['page'], MAX_DISPLAY_SEARCH_RESULTS, $specials_query_raw, $specials_query_numrows);
    $specials_query = tep_db_query($specials_query_raw);
    while ($specials = tep_db_fetch_array($specials_query)) {
      if ((!isset($HTTP_GET_VARS['sID']) || (isset($HTTP_GET_VARS['sID']) && ($HTTP_GET_VARS['sID'] == $specials['specials_daily_id']))) && !isset($sInfo)) {
        $products_query = tep_db_query("select products_image from " . TABLE_PRODUCTS . " where products_id = '" . (int)$specials['products_id'] . "'");
        $products = tep_db_fetch_array($products_query);
        $sInfo_array = array_merge($specials, $products);
        $sInfo = new objectInfo($sInfo_array);
      }

      if (isset($sInfo) && is_object($sInfo) && ($specials['specials_daily_id'] == $sInfo->specials_daily_id)) {
        echo '                  <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link('specials_daily.php', 'page=' . $HTTP_GET_VARS['page'] . '&sID=' . $sInfo->specials_daily_id . '&action=edit') . '\'">' . "\n";
      } else {
        echo '                  <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link('specials_daily.php', 'page=' . $HTTP_GET_VARS['page'] . '&sID=' . $specials['specials_daily_id']) . '\'">' . "\n";
      }
?>
<?php
if ((tep_date_raws($specials['star_date'])<=tep_date_now()) && (tep_date_raws($specials['end_date'])>=tep_date_now()))
{
$currentcode=$specials['code'];
?>
                <td  class="dataTableContent"><font color="#FF00FF" size="+0.5"><?php echo $specials['code']; ?></font></td>
                <td  class="dataTableContent"><?php echo $specials['products_name']; ?></td>
<?
}
else
{
?>

                <td  class="dataTableContent"><?php echo $specials['code']; ?></td>
                <td  class="dataTableContent"><?php echo $specials['products_name']; ?></td>
<?
}
?>
                <td  class="dataTableContent"><?php echo substr($specials['star_date'],0,10); ?></td>
                <td  class="dataTableContent"><?php echo substr($specials['end_date'],0,10); ?></td>
                <td  class="dataTableContent" align="right"><span class="oldPrice"><?php echo $currencies->format($specials['old_price']); ?></span> <span class="specialPrice"><?php echo $currencies->format($specials['new_price']); ?></span></td>
                <td  class="dataTableContent" align="right">
<?php
      if ($specials['status'] == '1') {
        echo tep_image(DIR_WS_IMAGES . 'icon_status_green.gif', IMAGE_ICON_STATUS_GREEN, 10, 10) . '&nbsp;&nbsp;<a href="' . tep_href_link('specials_daily.php', 'action=setflag&flag=0&id=' . $specials['specials_daily_id'], 'NONSSL') . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_red_light.gif', IMAGE_ICON_STATUS_RED_LIGHT, 10, 10) . '</a>';
      } else {
        echo '<a href="' . tep_href_link('specials_daily.php', 'action=setflag&flag=1&id=' . $specials['specials_daily_id'], 'NONSSL') . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_green_light.gif', IMAGE_ICON_STATUS_GREEN_LIGHT, 10, 10) . '</a>&nbsp;&nbsp;' . tep_image(DIR_WS_IMAGES . 'icon_status_red.gif', IMAGE_ICON_STATUS_RED, 10, 10);
      }
?></td>
                <td class="dataTableContent" align="right"><?php if (isset($sInfo) && is_object($sInfo) && ($specials['specials_daily_id'] == $sInfo->specials_daily_id)) { echo tep_image(DIR_WS_IMAGES . 'icon_arrow_right.gif', ''); } else { echo '<a href="' . tep_href_link('specials_daily.php', 'page=' . $HTTP_GET_VARS['page'] . '&sID=' . $specials['specials_daily_id']) . '">' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
      </tr>
<?php
    }
?>
              <tr>
                <td colspan="4"><table border="0" width="100%" cellpadding="0"cellspacing="2">
                  <tr>
                    <td class="smallText" valign="top"><?php echo $specials_split->display_count($specials_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $HTTP_GET_VARS['page'], TEXT_DISPLAY_NUMBER_OF_SPECIALS); ?></td>
                    <td class="smallText" align="right"><?php echo $specials_split->display_links($specials_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $HTTP_GET_VARS['page']); ?></td>
                  </tr>
<?php
  if (empty($action)) {
?>
                  <tr>
                    <td colspan="3" align="right"><?php echo '<a href="' . tep_href_link('specials_daily.php', 'page=' . $HTTP_GET_VARS['page'] . '&action=new') . '">' . tep_image_button('button_new_product.gif', IMAGE_NEW_PRODUCT) . '</a>'; ?></td>
                    <td align="right">Current special product:<font color="#FF00FF" size="+0.5"><?=$currentcode?></font></td>
                  </tr>
<?php
  }
?>
                </table></td>
              </tr>
            </table></td>
<?php
  $heading = array();
  $contents = array();

  switch ($action) {
    case 'delete':
      $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_DELETE_SPECIALS . '</b>');

      $contents = array('form' => tep_draw_form('specials', 'specials_daily.php', 'page=' . $HTTP_GET_VARS['page'] . '&sID=' . $sInfo->specials_daily_id . '&action=deleteconfirm'));
      $contents[] = array('text' => TEXT_INFO_DELETE_INTRO);
      $contents[] = array('text' => '<br><b>' . $sInfo->products_name . '</b>');
      $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_delete.gif', IMAGE_DELETE) . '&nbsp;<a href="' . tep_href_link('specials_daily.php', 'page=' . $HTTP_GET_VARS['page'] . '&sID=' . $sInfo->specials_daily_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
      break;
    default:
      if (is_object($sInfo)) {
        $heading[] = array('text' => '<b>' . $sInfo->products_name . '</b>');

        $contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link('specials_daily.php', 'page=' . $HTTP_GET_VARS['page'] . '&sID=' . $sInfo->specials_daily_id . '&action=edit') . '">' . tep_image_button('button_edit.gif', IMAGE_EDIT) . '</a> <a href="' . tep_href_link('specials_daily.php', 'page=' . $HTTP_GET_VARS['page'] . '&sID=' . $sInfo->specials_daily_id . '&action=delete') . '">' . tep_image_button('button_delete.gif', IMAGE_DELETE) . '</a>');
        $contents[] = array('text' => '<br>' . TEXT_INFO_DATE_ADDED . ' ' . tep_date_short($sInfo->specials_date_added));
        $contents[] = array('text' => '' . TEXT_INFO_LAST_MODIFIED . ' ' . tep_date_short($sInfo->specials_last_modified));
        $contents[] = array('align' => 'center', 'text' => '<br>' . tep_info_image($sInfo->products_image, $sInfo->products_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT));
        $contents[] = array('text' => '<br>' . TEXT_INFO_ORIGINAL_PRICE . ' ' . $currencies->format($sInfo->products_price));
        $contents[] = array('text' => '' . TEXT_INFO_NEW_PRICE . ' ' . $currencies->format($sInfo->new_price));
        $contents[] = array('text' => '' . TEXT_INFO_PERCENTAGE . ' ' . number_format(100 - (($sInfo->new_price / $sInfo->products_price) * 100)) . '%');

        $contents[] = array('text' => '<br>' . TEXT_INFO_EXPIRES_DATE . ' <b>' . tep_date_short($sInfo->expires_date) . '</b>');
        $contents[] = array('text' => '' . TEXT_INFO_STATUS_CHANGE . ' ' . tep_date_short($sInfo->date_status_change));
      }
      break;
  }
  if ( (tep_not_null($heading)) && (tep_not_null($contents)) ) {
    echo '            <td width="25%" valign="top">' . "\n";

    $box = new box;
    echo $box->infoBox($heading, $contents);

    echo '            </td>' . "\n";
  }
}
?>
          </tr>
        </table></td>
      </tr>
    </table></td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
