Location: PHPKode > scripts > Discount Code module for osCommerce > discount-code-module-for-oscommerce/catalog/admin/discount_codes.php
<?php
/*
  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License

  Discount Code
  http://high-quality-php-coding.com/
*/

  require('includes/application_top.php');

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

  if (tep_not_null($action)) {
    switch ($action) {
      case 'setflag':
        tep_db_query("update " . TABLE_DISCOUNT_CODES . " set status = '" . (int)$HTTP_GET_VARS['flag'] . "' where discount_codes_id = '" . (int)$HTTP_GET_VARS['dID'] . "' limit 1");

        tep_redirect(tep_href_link(FILENAME_DISCOUNT_CODES, 'page=' . $HTTP_GET_VARS['page']));
        break;
      case 'insert':
        if (!empty($HTTP_POST_VARS['discount_codes']) && !empty($HTTP_POST_VARS['discount_values'])) {
          $sql_data_array = array('discount_codes' => tep_db_prepare_input($HTTP_POST_VARS['discount_codes']),
                                  'discount_values' => tep_db_prepare_input($HTTP_POST_VARS['discount_values']),
                                  'minimum_order_amount' => tep_db_prepare_input($HTTP_POST_VARS['minimum_order_amount']),
                                  'expires_date' => empty($HTTP_POST_VARS['day']) && empty($HTTP_POST_VARS['month']) && empty($HTTP_POST_VARS['year']) ? '0000-00-00' : tep_db_prepare_input($HTTP_POST_VARS['year']) . '-' . tep_db_prepare_input($HTTP_POST_VARS['month']) . '-' . tep_db_prepare_input($HTTP_POST_VARS['day']));

          switch ((int)$HTTP_POST_VARS['applies_to']) {
            case 1:
              $sql_data_array = array_merge($sql_data_array, array('products_id' => (int)$HTTP_POST_VARS['products_id']));
              break;
            case 2:
              $sql_data_array = array_merge($sql_data_array, array('categories_id' => (int)$HTTP_POST_VARS['categories_id']));
              break;
            case 3:
              $sql_data_array = array_merge($sql_data_array, array('orders_total' => 1));
              break;
          }

          tep_db_perform(TABLE_DISCOUNT_CODES, $sql_data_array);
        }

        tep_redirect(tep_href_link(FILENAME_DISCOUNT_CODES));
        break;
      case 'delete':
        tep_db_query("delete from " . TABLE_CUSTOMERS_TO_DISCOUNT_CODES . " where discount_codes_id = '" . (int)$HTTP_GET_VARS['dID'] . "'");
        tep_db_query("delete from " . TABLE_DISCOUNT_CODES . " where discount_codes_id = '" . (int)$HTTP_GET_VARS['dID'] . "' limit 1");

        tep_redirect(tep_href_link(FILENAME_DISCOUNT_CODES, 'page=' . $HTTP_GET_VARS['page']));
        break;
    }
  }

  require(DIR_WS_CLASSES . 'currencies.php');
  $currencies = new currencies();
?>
<!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/javascript/calendar.css">
<script language="JavaScript" src="includes/javascript/calendarcode.js"></script>
<script language="javascript">
function confirm_delete(a, b) { if (confirm(a)) window.location = b }
</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="0">
      <tr>
        <td><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>
      <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"><?php echo TABLE_HEADING_DISCOUNT_CODE; ?></td>
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_APPLIES_TO; ?></td>
                <td class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_DISCOUNT; ?></td>
                <td class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_MINIMUM_ORDER_AMOUNT; ?></td>
                <td class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_EXPIRY; ?></td>
                <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_STATUS; ?>&nbsp;</td>
                <td class="dataTableHeadingContent">&nbsp;</td>
              </tr>
<?php
  if (isset($HTTP_GET_VARS['page']) && ($HTTP_GET_VARS['page'] > 1)) $rows = $HTTP_GET_VARS['page'] * MAX_DISPLAY_SEARCH_RESULTS - MAX_DISPLAY_SEARCH_RESULTS;
  $discount_codes_query_raw = "select dc.discount_codes_id, dc.products_id, dc.categories_id, dc.orders_total, dc.discount_codes, dc.discount_values, dc.minimum_order_amount, dc.expires_date, dc.status, pd.products_name from discount_codes dc left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on (dc.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "') order by dc.discount_codes_id desc";
  $discount_codes_split = new splitPageResults($HTTP_GET_VARS['page'], MAX_DISPLAY_SEARCH_RESULTS, $discount_codes_query_raw, $discount_codes_query_numrows);
  $discount_codes_query = tep_db_query($discount_codes_query_raw);
  while ($discount_codes = tep_db_fetch_array($discount_codes_query)) {
?>
              <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)">
                <td class="dataTableContent"><?php echo $discount_codes['discount_codes']; ?></td>
                <td class="dataTableContent"><?php echo !empty($discount_codes['orders_total']) ? TEXT_ORDER_TOTAL : (!empty($discount_codes['products_id']) ? TEXT_PRODUCT . ' ' . $discount_codes['products_name'] : TEXT_CATEGORY . ' ' . tep_output_generated_category_path($discount_codes['categories_id'])); ?></td>
                <td class="dataTableContent" align="center"><?php echo strpos($discount_codes['discount_values'], '%') === false ? $currencies->format($discount_codes['discount_values']) : $discount_codes['discount_values']; ?>&nbsp;</td>
                <td class="dataTableContent" align="center"><?php echo $discount_codes['minimum_order_amount'] == '0.0000' ? '-' : $currencies->format($discount_codes['minimum_order_amount']); ?></td>
                <td class="dataTableContent" align="center"><?php echo $discount_codes['expires_date'] == '0000-00-00' ? '-' : tep_date_short($discount_codes['expires_date']); ?>&nbsp;</td>
                <td class="dataTableContent" align="right">
<?php
      if ($discount_codes['status'] == '1') {
        echo tep_image(DIR_WS_IMAGES . 'icon_status_green.gif', 'Active', 10, 10) . '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_DISCOUNT_CODES, 'page=' . $HTTP_GET_VARS['page'] . '&dID=' . $discount_codes['discount_codes_id'] . '&action=setflag&flag=0') . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_red_light.gif', 'Set Inactive', 10, 10) . '</a>';
      } else {
        echo '<a href="' . tep_href_link(FILENAME_DISCOUNT_CODES, 'page=' . $HTTP_GET_VARS['page'] . '&dID=' . $discount_codes['discount_codes_id'] . '&action=setflag&flag=1') . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_green_light.gif', 'Set Active', 10, 10) . '</a>&nbsp;&nbsp;' . tep_image(DIR_WS_IMAGES . 'icon_status_red.gif', 'Inactive', 10, 10);
      }
?></td>
                <td class="dataTableContent" align="right"><?php echo '<a href="#" onclick="confirm_delete(\'' . TEXT_CONFIRM_MESSAGE . '\', \'' . tep_href_link(FILENAME_DISCOUNT_CODES, 'page=' . $HTTP_GET_VARS['page'] . '&dID=' . $discount_codes['discount_codes_id'] . '&action=delete') . '\'); return false;">' . tep_image(DIR_WS_ICONS . 'delete.gif', ICON_DELETE) . '</a>'; ?>&nbsp;</td>
              </tr>
<?php
  }
?>
            </table></td>
          </tr>
          <tr>
            <td colspan="7"><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr>
                <td class="smallText" valign="top"><?php echo $discount_codes_split->display_count($discount_codes_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $HTTP_GET_VARS['page'], TEXT_DISPLAY_NUMBER_OF_DISCOUNT_CODES); ?></td>
                <td class="smallText" align="right"><?php echo $discount_codes_split->display_links($discount_codes_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $HTTP_GET_VARS['page']); ?></td>
              </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
      <tr><?php echo tep_draw_form('new_discount_code', FILENAME_DISCOUNT_CODES, 'action=insert'); ?>
        <td><table border="0" cellspacing="0" cellpadding="2">
          <tr>
            <td colspan="3"><?php echo tep_draw_separator('pixel_trans.gif', '1', '20'); ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_DISCOUNT_CODE; ?></td>
            <td></td>
            <td class="main"><?php echo tep_draw_input_field('discount_codes', substr(md5(uniqid(rand(), true)), 0, 8), '', true); ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_DISCOUNT; ?></td>
            <td></td>
            <td class="main"><?php echo tep_draw_input_field('discount_values', '', '', true); ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_MINIMUM_ORDER_AMOUNT; ?></td>
            <td></td>
            <td class="main"><?php echo tep_draw_input_field('minimum_order_amount'); ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_APPLIES_TO; ?></td>
            <td class="main"><?php echo tep_draw_radio_field('applies_to', '1', true); ?></td>
            <td class="main"><?php echo TEXT_PRODUCT . '&nbsp;' . tep_draw_products_pull_down('products_id'); ?></td>
          </tr>
          <tr>
            <td></td>
            <td class="main"><?php echo tep_draw_radio_field('applies_to', '2'); ?></td>
            <td class="main"><?php echo TEXT_CATEGORY . '&nbsp;' . tep_draw_pull_down_menu('categories_id', tep_get_category_tree()); ?></td>
          </tr>
          <tr>
            <td></td>
            <td class="main"><?php echo tep_draw_radio_field('applies_to', '3'); ?></td>
            <td class="main"><?php echo TEXT_ORDER_TOTAL; ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_EXPIRY; ?></td>
            <td class="main"></td>
            <td class="main"><?php echo tep_draw_input_field('day', '', 'size="2" maxlength="2" class="cal-TextBox"') . tep_draw_input_field('month', '', 'size="2" maxlength="2" class="cal-TextBox"') . tep_draw_input_field('year', '', 'size="4" maxlength="4" class="cal-TextBox"'); ?><a class="so-BtnLink" href="javascript:calClick();return false;" onmouseover="calSwapImg('BTN_date', 'img_Date_OVER',true);" onmouseout="calSwapImg('BTN_date', 'img_Date_UP',true);" onclick="calSwapImg('BTN_date', 'img_Date_DOWN');showCalendar('new_discount_code','dteWhen','BTN_date');return false;"><?php echo tep_image(DIR_WS_IMAGES . 'cal_date_up.gif', 'Calendar', '22', '17', 'align="absmiddle" name="BTN_date"'); ?></a></td>
          </tr>
          <tr>
            <td colspan="3"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td colspan="3"><?php echo tep_image_submit('button_insert.gif', IMAGE_INSERT); ?></td>
          </tr>
        </table></td>
      </form></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'); ?>
Return current item: Discount Code module for osCommerce