Latest News: (loading..)
Tsimi

Discount Code BS

308 posts in this topic

And if someone could kindly code a check to display to customers would be very nice. At the moment the customer will think the code has been applied when it hasn't. Doesnt look professional.

 

It would be much appreciated.

 

You could just add a 'check code' button (that doesn't do anything) next to the coupon field. If they click it, the script on the field checks the code. If they don't click it, they can't complain!

raiwa and Tsimi like this

Share this post


Link to post
Share on other sites

Posted (edited)

@@CGhoST

 

Not sure what a message stack alert would achieve. Do you want to prevent the customer from continuing their checkout process if the code is wrong?

There are already icons in place that show if the code is valid or not. But if you want to have something more fool proof then as @@BrockleyJohn mentioned an empty button could be placed and the customer clicks on it after entering the code to validate it. Additional to that a small message could be displayed instead of the icons.

 

Open your ../ht_discount_code/ht_discount_code.php file and replace all with this

<?php
/*
  $Id$

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

  Copyright (c) 2017 osCommerce

  Released under the GNU General Public License

  Discount Code 4.2 BS
*/
?>
<script type="text/javascript">
    $(document).ready(function () {

        $('div.contentContainer div.contentText .form-group').parent().before('<h2><?php echo TEXT_DISCOUNT_CODE; ?></h2><div class="col-xs-12 col-sm-5">\n\
                    <span id="discount_code_status"></span>\n\
                        <div class="form-inline">\n\
                        <div class="form-group has-feedback">\n\
                                <input type="text" class="form-control" style="width:225px;" name="discount_code" value="<?php echo isset($sess_discount_code) ? $sess_discount_code : ''; ?>" id="discount_code" />\n\
                                <input class="btn btn-default" style="margin-top:-4px;" type="button" value="Apply">\n\
                        </div>\n\
                        </div>\n\
                </div> \n\
        <div class="clearfix"></div><hr>');

        var a = 0;
        discount_code_process();
        $('#discount_code').blur(function () {
            if (a == 0)
                discount_code_process();
            a = 0
        });
        $("#discount_code").keypress(function (event) {
            if (event.which == 13) {
                event.preventDefault();
                a = 1;
                discount_code_process();
            }
        });
        function discount_code_process() {
            if ($("#discount_code").val() != "") {
                $("#discount_code").attr("readonly", "readonly");
                $.post("discount_code.php", {discount_code: $("#discount_code").val()}, function (data) {
                    data == 1 ? $("#discount_code_status").empty().append('<div class="alert alert-success discount-alert"><i class="fa fa-check fa-lg" style="color:#00b100;"></i> <?php echo TEXT_DISCOUNT_CODE_SUCCESS;?><div>') : $("#discount_code_status").empty().append('<div class="alert alert-danger discount-alert"><i class="fa fa-ban fa-lg" style="color:#ff2800;"></i> <?php echo TEXT_DISCOUNT_CODE_ERROR;?><div>');
                    $("#discount_code").removeAttr("readonly");
                });
            }
        }
    });
</script>

I don't know why but I cannot post a margin-left css code here.

Just add .discount-alert with a margin-left and margin-right of -15px; into your user.css file

 

and finally add the language definitions into your english.php or whatever language you use.

define('TEXT_DISCOUNT_CODE_SUCCESS', 'Discount Code is valid.');
define('TEXT_DISCOUNT_CODE_ERROR', 'Discount Code is wrong or does not exist.');

Done! I hope that looks more professional.

Edited by Tsimi
raiwa and CGhoST like this

Share this post


Link to post
Share on other sites

Posted (edited)

@@Tsimi

 

Hi Tsimi,

I have a question about "Discount Codes BS" and shipping discount.
From Admin, when I enter a number in Discount field without % for shipping discount, shipping discount is applied/calculated like a percentage from catalog.
Is it normal ?

Listing codes from admin show € symblol nevertheless :

--------------------------------------------------------------------------------------​-------------------------------------------​--------------------------------

Discount Code        Applies to        Discount        Min Sub-Total          Expiry,           Orders      Status         Action  

INF10                     Shipping          100.00 €                                    02/05/2017            3            icon_status_green.gif  icon_status_red_light.gif
--------------------------------------------------------------------------------------​-------------------------------------------​--------------------------------

 

Otherwise, I have "E.U. VAT Intracom Number" addon installed from my store and I have adapted "ot_discount" class to fit with this one (tax calculating ok).
Let me know if your are interested (or anyone), I will post the changes applied to "ot_discount.php" file.

 

 

NB: For those who use Order Editor addon, you will find fix compatibility with Discount Code BS to modifiy your order with discount already applied (or add discount when editing order) : http://forums.oscommerce.com/topic/54032-new-complete-order-editing-tool/?p=1756325

Edited by milerwan

Share this post


Link to post
Share on other sites

@@milerwan,

 

In the sense that you can apply a discount code in the order editor, no, this is not supported. But why would you need to do this??

You can just add an additional line in totals with negative discount amount and type as a concept "discount".

 

rgds

Rainer

 

When you edit an order to change an address, or a phone, or email (and so on) with discount already registred :

- you lost tax calculation of the discount

- you lost discount substraction from the total

 

I have made a fix for that (see the link above). :)

Share this post


Link to post
Share on other sites

@@milerwan

 

Yes, that's normal.

Shipping can only be calculated in % so no matter if you enter 100 or 100% it is the same.

Share this post


Link to post
Share on other sites

@@Tsimi

 

Not sure what a message stack alert would achieve.

 

Lambros, my thought was it would just give feedback to the customer without adding any buttons or action required by the customer.  For example if you add a coupon and it was valid you'd get a message saying something like "your coupon has been applied to your order."  conversely if it wasn't valid it would say something like "Invalid coupon, please try entering it again or contact the shop owner".   Sending the message to the stack would then behave in the usual manner, hopefully in a way a customer is used to seeing ie. "Product X has been added to your cart" etc and would be formatted and styled like any other message sent to the stack.  I can't think of a reason why you'd want to do it in any other way.  In my view customers like things that work in a consistent way and require little, if any, effort on their part. 

 

If it helps, here is my dc_redirect.php file...does the same thing as the file you have in the root.

<?php
/*
  $Id$

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

  Copyright (c) 2016 osCommerce

  Released under the GNU General Public License

*/

  require('includes/application_top.php');

  if (!tep_session_is_registered('coupon')) tep_session_register('coupon');
  //this needs to be set before the order object is created, but we must process it after
  $coupon = tep_db_prepare_input($HTTP_POST_VARS['coupon']);

  if (tep_not_null($coupon)) {  
  
  include(DIR_WS_CLASSES . 'order.php');
    $order = new order;

	if( is_object( $order->coupon ) ) { //verify coupon
     $order->coupon->verify_code();
	}
   
    if( (!$order->coupon->is_errors()) && is_object( $order->coupon )) { //if we have passed all tests (no error message)
		$messageStack->add_session('product_action', ENTRY_DISCOUNT_COUPON_SUCCESS, 'success');
	}else{
		$messageStack->add_session('product_action', implode( ' ', $order->coupon->get_messages() ), 'warning');
	}
	
  }
  
  if (!tep_not_null($coupon)) $messageStack->add_session('product_action', ENTRY_DISCOUNT_COUPON_NO_ENTRY, 'warning');
  tep_redirect(tep_href_link('shopping_cart.php', 'SSL' ) );
 ?>

Dan

 

 

Share this post


Link to post
Share on other sites

@@BrockleyJohn

 

Thanks for such a simple idea :-)

 

@@Tsimi

 

Thank you so much for taking the time and giving that code. Thats ideal.

Share this post


Link to post
Share on other sites

Posted (edited)

@@Tsimi @@raiwa

Ok I understand. :)


Tsimi and Raiwa, in France (and maybe in other European countries), the legislation requires that the order total display :
- Total amount with tax (native in osc)
- Total taxes incl. (native in osc)
- Total amount without tax (need to add specific order_total module)

I have made this new module by creating these files :

1. Create includes/modules/order_total/ot_total_ht.php :

<?php
/*
  $Id$

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

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

  class ot_total_ht {
    var $title, $output;

    function ot_total_ht() {
      $this->code = 'ot_total_ht';
      $this->title = MODULE_ORDER_TOTAL_TOTAL_HT_TITLE;
      $this->description = MODULE_ORDER_TOTAL_TOTAL_HT_DESCRIPTION;
      $this->enabled = ((MODULE_ORDER_TOTAL_TOTAL_HT_STATUS == 'true') ? true : false);
      $this->sort_order = MODULE_ORDER_TOTAL_TOTAL_HT_SORT_ORDER;

      $this->output = array();
    }

    function process() {
      global $order, $currencies;

      $this->output[] = array('title' => $this->title . ':',
                              'text' => $currencies->format($order->info['total_ht'], true, $order->info['currency'], $order->info['currency_value']),
                              'value' => $order->info['total_ht']);
    }

    function check() {
      if (!isset($this->_check)) {
        $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_ORDER_TOTAL_TOTAL_HT_STATUS'");
        $this->_check = tep_db_num_rows($check_query);
      }

      return $this->_check;
    }

    function keys() {
      return array('MODULE_ORDER_TOTAL_TOTAL_HT_STATUS', 'MODULE_ORDER_TOTAL_TOTAL_HT_SORT_ORDER');
    }

    function install() {
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Affichage du total HT', 'MODULE_ORDER_TOTAL_TOTAL_HT_STATUS', 'true', 'Voulez-vous montrer le total HT de la commande ?', '6', '1','tep_cfg_select_option(array(\'true\', \'false\'), ', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Ordre de tri', 'MODULE_ORDER_TOTAL_TOTAL_HT_SORT_ORDER', '5', 'Ordre de tri pour l\'affichage (Le plus petit nombre est montré en premier).', '6', '2', now())");
    }

    function remove() {
      tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }
  }
?>

2. Create includes/languages/english/modules/order_total/ot_total_ht.php :

<?php
/*
  $Id$

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

  Copyright (c) 2002 osCommerce

  Released under the GNU General Public License
*/

  define('MODULE_ORDER_TOTAL_TOTAL_HT_TITLE', 'Total VAT Excl.');
  define('MODULE_ORDER_TOTAL_TOTAL_HT_DESCRIPTION', 'Order Total VAT Excluded.');
?>

3. Edit includes/classes/order.php and add "total_ht" calculating at the end :

      if (DISPLAY_PRICE_WITH_TAX == 'true') {
        $this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost'];
      } else {
        $this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost'];
      }
	// Add total_ht calaculating
	  $this->info['total_ht'] = $this->info['total'] - $this->info['tax'];
	// Add total_ht calaculating
    }
  }
?>

4. Edit includes/modules/order_total/ot_discount.php and add "total_ht" calculating at the end of "function process" :

                    $order->info['total'] -= $discount;
                    if (DISPLAY_PRICE_WITH_TAX != 'true') $order->info['total'] -= tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
                    if (!empty($order_tax)) $order->info['tax'] = $order_tax;
                    $shipping_discount = 'true';
                  }
                } //.eof $check['shipping']
              } // eof check newsletter and order number
            }
          }
        }
      }

	// Add total_ht calculating
	  $order->info['total_ht'] = $order->info['total'] - $order->info['tax'];
	// Add total_ht calaculating

      if (!empty($discount)) {
        $this->output[] = array('title' => (($shipping_discount == 'true')? TEXT_SHIPPING_DISCOUNT : TEXT_DISCOUNT) . (strpos($check['discount_values'], '%') ? ' ' . $check['discount_values'] . ' ' : '') . (!empty($order_info) ? ' (' . $sess_discount_code . ')' : '') . ':',
                                'text' => '<font color="#ff0000">-' . $currencies->format($discount, true, $order->info['currency'], $order->info['currency_value']) . '</font>',
                                'value' => -$discount);
      }
    }

With this new module and the 2 modifications, you have this kind of display from catalog :

Sub-total TTC:                       24.00 €
Discount (INF10):                 -10.00 €
Shipping cost (0.07kg):            5.40 €
Total Incl. Tax:                        19.40 €
VAT 20%:                                 3.23 €
Total Excl. Tax:                       16.17 €

 

Calculating is 100% correct from catalog regardless of the discount method applied.

 

---------------------------------------------------

 

Now I have an issue when I edit the order from Order Editor, the Total Excl. Tax is not proper recalculated because the discount is not taken into account :

 

Sub-total TTC:                       24.00 €                      24.00 €
Discount (INF10):                 -10.00 €          ->           0.00 €
Shipping cost (0.07kg):            5.40 €                        5.40 €
Total Incl. Tax:                        19.40 €           ->       29.40 €
VAT 20%:                                 3.23 €                        3.23 €
Total Excl. Tax:                    24.50 €                      24.50 € 

 

Do you see a fix for this ?
 

Edited by milerwan

Share this post


Link to post
Share on other sites

Is this bug normal when Discount number is greater than sub-total ? :

 

post-136115-0-69562500-1493753381_thumb.jpg

Share this post


Link to post
Share on other sites

Posted (edited)

Another bug when DISPLAY_PRICE_WITH_TAX from admin is disabled.
Total is wrong for me :
 

post-136115-0-03974100-1493754491_thumb.jpg

Edited by milerwan

Share this post


Link to post
Share on other sites

Posted (edited)

With this new module and the 2 modifications, you have this kind of display from catalog :

 

Sub-total TTC:                       24.00 €

Discount (INF10):                 -10.00 €

Shipping cost (0.07kg):            5.40 €

Total Incl. Tax:                        19.40 €

VAT 20%:                                 3.23 €

Total Excl. Tax:                       16.17 €

 

Calculating is 100% correct from catalog regardless of the discount method applied.

 

---------------------------------------------------

 

Now I have an issue when I edit the order from Order Editor, the Total Excl. Tax is not proper recalculated because the discount is not taken into account :

 

Sub-total TTC:                       24.00 €                      24.00 €

Discount (INF10):                 -10.00 €          ->           0.00 €

Shipping cost (0.07kg):            5.40 €                        5.40 €

Total Incl. Tax:                        19.40 €           ->       29.40 €

VAT 20%:                                 3.23 €                        3.23 €

Total Excl. Tax:                    24.50 €                      24.50 € 

 

Do you see a fix for this ?

 

 

 

@@milerwan  Gwenn....does changing the sort order help?....see this thread

 

Dan

Edited by Dan Cole

Share this post


Link to post
Share on other sites

Posted (edited)

As Dan mentioned sort order is important. It is even mentioned inside the install manual.

If you change the sort order the discount addon might not work properly.

Edited by Tsimi

Share this post


Link to post
Share on other sites

Posted (edited)

@@milerwan  Gwenn....does changing the sort order help?....see this thread

 

Dan

 

Hi Dan,

I have added new order_total module that shows "Total Excl. Tax", 100% work from catalog but, from Order Editor, when editing order, Discount amount is not applied to this new field.

 

From Order Editor, currently I have :

 

Sub-total TTC:                       24.00 €       

Discount (INF10):                 -10.00 €      

Shipping cost (0.07kg):            5.40 €     

Total Incl. Tax:                        19.40 €       

VAT 20%:                                 3.23 €        

Total Excl. Tax:                    24.50 €        

 

 

But the expected result must be :

 

Sub-total TTC:                       24.00 €       

Discount (INF10):                 -10.00 €      

Shipping cost (0.07kg):            5.40 €     

Total Incl. Tax:                        19.40 €       

VAT 20%:                                 3.23 €        

Total Excl. Tax:                    16.17 €        

 

 

Here is my last version of order_total module Total Amount Excl. Tax (VAT) with no core change : http://addons.oscommerce.com/info/9568

 

Anyone can install it and try to find a fix. ;)

Edited by milerwan

Share this post


Link to post
Share on other sites

@@milerwan Gwenn does the sort order change when you edit the order using Order Editor?  If you check the sort order after entering an order on the customer side of the shop and then edit it via the order editor, do they change?  Just a thought....

 

Dan

Share this post


Link to post
Share on other sites

Posted (edited)

@@Dan Cole

The sort_order does not affect the result.
Just try my module and you will see what I mean.

I think "Order Editor" needs core changes to apply "ot_custom/discount" to this new class (ot_total_ht) because when I edit the edit_order.php or edit_order_ajax.php, t
he addition of "ot_custom/discount" value to "ot_total" value is forced :
 

            $new_order_totals[] = array('title' => $ot_title,
										'text' => $currencies->format($ot_value, true, $order->info['currency'], $order->info['currency_value']),
                                        'value' => $ot_value,
// Add ot_discount
//                                        'code' => 'ot_custom_' . $j,
                                        'code' => 'ot_discount',
// Add ot_discount
                                        'sort_order' => $j);
            $order->info['total'] += $ot_value;
			$written_ot_totals_array[] = $ot_class;
		    $written_ot_titles_array[] = $ot_title;
            $j++;

$order->info['total'] += $ot_value;

This line adds $ot_value to $order->info['total'] but it has no impact on total_ht.

 

 

Here is the structure of my ot_total_ht class :

    function process() {
      global $order, $currencies;

	  reset($order->info['tax_groups']);
      while (list($key, $value) = each($order->info['tax_groups'])) {
		if (DISPLAY_PRICE_WITH_TAX == 'true') {
		  $total_ht = $order->info['total'] - $value;
		} else {
		  $total_ht = $order->info['total'] + $value;
		}
//      $this->output[] = array('title' => $this->title . ':',
		$this->output[] = array('title' => (DISPLAY_PRICE_WITH_TAX == 'true' ? MODULE_ORDER_TOTAL_TOTAL_HT_TITLE : MODULE_ORDER_TOTAL_TOTAL_TTC_TITLE) .':',
								'text' => $currencies->format($total_ht, true, $order->info['currency'], $order->info['currency_value']),
								'value' => $total_ht);
      }
    }
Edited by milerwan

Share this post


Link to post
Share on other sites

Posted (edited)

@@milerwan  Gwenn....I'm afraid I'm a bit confused...lets back up....is there some reason this needs to be in a module rather than in the actual edit_order.php or edit_order_ajax.php file which is working nicely at this point?  Would it be easier just to make the changes you want to either of those files?   If you have it working there you could then pull it out and put it in a module if you want. 

 

Dan

 

PS:  Should this conversation be moved to the order editor thread so we can let Lambros have his thread back?

Edited by Dan Cole

Share this post


Link to post
Share on other sites

"Exclude specials" is only available if products, categories or manufacturer is selected.

 

Is it possible to provide a selection in each box for all products or all categories or all Manufacturers.

 

Why i ask this is if i want to provide discount to all products but want to exclude discount / special products then i need to highlight all products in box .. when save discount then the "applies to" column becomes HUGE as i have nearly 20,000 products.

 

It would be nice to have a all products or all categories or all Manufacturers option.

 

Thank you for all the support and suggestions being provided.

Share this post


Link to post
Share on other sites

Cyber....as mentioned previously I don't use the Discount Codes add on but the one I use has a global setting to exclude specials....have a look the admin area where you installed Discount Codes and see if there is a global setting to control that.  If not you'll probably have to live with the way it is or have it coded for you.

 

Dan

Share this post


Link to post
Share on other sites

Posted (edited)

@@Dane Cole

 

There is a "Exclude Discount" setting. But it only become available when you choose a product or a category or a product.

 

If someone could code a global Exclude Discount Setting will be very much appreciated.

 

Also i mentioned earlier in the posts the order total of Estimated Order Totals does not work.

 

Please see screenshot:

 

http://tinypic.com/r/wjdyxk/9

Edited by CGhoST

Share this post


Link to post
Share on other sites

Posted (edited)

@@CGhoST

 

If someone could code a global Exclude Discount Setting will be very much appreciated.

 

Hopefully someone who uses this add on will chime in or help you out....otherwise you could get a quote for the work in the commercial forum and maybe donate it back to the community.

 

Also i mentioned earlier in the posts the order total of Estimated Order Totals does not work.

 

Have you tried changing the sort order for the order total modules?  If you haven't done so already try moving the discount to just below the subtotal.

 

Dan

Edited by Dan Cole

Share this post


Link to post
Share on other sites

@@Dan Cole

 

Thats the first thing i did but no change. If you apply the discount in Shopping Cart the estimate does not work. But If you apply the discount in Shopping Cart then goto checkout confirmation and then back to Shopping Cart. Than total shows correctly.

 

So from what i understand if you apply in checkout the total is correct but if you apply the code in Shopping Cart the balance is not correct unless you goto checkout confirmation.

Share this post


Link to post
Share on other sites

Anyone who has insatalled the modular shopping cart and estimate could you verify if it works for you please

Share this post


Link to post
Share on other sites

Anyone who has insatalled the modular shopping cart and estimate could you verify if it works for you please

 

I was just going to ask if you used the modular shopping cart....I assume you do.  I like mine works fine but I'm off to have a look.  I'll post an image shortly.

 

Dan

Share this post


Link to post
Share on other sites

Thanks for asking that question @@CGhoST Looks like I had the order totals messed up from when I was working on the order_editor with Gwenn.  In any event, I sorted that out and here is what the order total section looks like on my site.   Try setting your order totals to the same sort order and see what you end up with. 

 

post-182953-0-35919000-1494073708_thumb.jpg

 

Dan

 

Share this post


Link to post
Share on other sites

@@raiwa @@Tsimi

From the code creation page in admin, I have added a "Generate Random Code" button + javasript code.

This can be nice for those who lack imagination when it comes to finding an original discount code. ;)

 

 

In "admin/discount_codes.php", replace all code by this one :

<?php
/*
  $Id$

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

  Copyright (c) 2016 osCommerce

  Released under the GNU General Public License

  Discount Code 4.1 BS
*/

  require('includes/application_top.php');

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

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

        tep_redirect(tep_href_link('discount_codes.php', 'page=' . $_GET['page']));
        break;
      case 'insert':
        if (!empty($_POST['discount_codes']) && !empty($_POST['discount_values'])) {
		  $exclude_specials = isset($_POST['exclude_specials']) ? (int) $_POST['exclude_specials'] : 0;
          $sql_data_array = array('products_id' => '',
                                  'categories_id' => '',
                                  'manufacturers_id' => '',
                                  'excluded_products_id' => '',
                                  'customers_id' => '',
                                  'orders_total' => '0',
                                  'shipping' => '0',
                                  'newsletter' => (int)$_POST['newsletter'],
                                  'order_number' => (int)$_POST['order_number'],
                                  'order_info' => (int)$_POST['order_info'],
                                  'exclude_specials' => $exclude_specials,
                                  'discount_codes' => tep_db_prepare_input($_POST['discount_codes']),
                                  'discount_values' => tep_db_prepare_input($_POST['discount_values']),
                                  'minimum_order_amount' => tep_db_prepare_input($_POST['minimum_order_amount']),
                                  'expires_date' => empty($_POST['expires_date']) ? '0000-00-00' : tep_db_prepare_input($_POST['expires_date']),
                                  'number_of_use' => (int)$_POST['number_of_use'],
                                  'number_of_products' => 0);

          $error = true;
          if ((int)$_POST['applies_to'] == 1) {
            if (isset($_POST['products_id']) && is_array($_POST['products_id']) && sizeof($_POST['products_id']) > 0) {
              $sql_data_array['products_id'] = implode(',', $_POST['products_id']);
              $error = false;
            }
          } elseif ((int)$_POST['applies_to'] == 2) {
            if (isset($_POST['categories_id']) && is_array($_POST['categories_id']) && sizeof($_POST['categories_id']) > 0) {
              $sql_data_array['categories_id'] = implode(',', $_POST['categories_id']);
              $error = false;
            }
          } elseif ((int)$_POST['applies_to'] == 3) {
            $sql_data_array['orders_total'] = 1; // total
            $error = false;
          } elseif ((int)$_POST['applies_to'] == 4) {
            if (isset($_POST['manufacturers_id']) && is_array($_POST['manufacturers_id']) && sizeof($_POST['manufacturers_id']) > 0) {
              $sql_data_array['manufacturers_id'] = implode(',', $_POST['manufacturers_id']);
              $error = false;
            }
          } elseif ((int)$_POST['applies_to'] == 5) {
            $sql_data_array['orders_total'] = 2; // subtotal
            $error = false;
          } elseif ((int)$_POST['applies_to'] == 6) {
            $sql_data_array['shipping'] = 2; // shipping
            $error = false;
		  }
		  
          if ((int)$_POST['applies_to'] == 2 || (int)$_POST['applies_to'] == 4) {
		      if (isset($_POST['excluded_products_id']) && is_array($_POST['excluded_products_id']) && sizeof($_POST['excluded_products_id']) > 0) {
              $sql_data_array['excluded_products_id'] = implode(',', $_POST['excluded_products_id']);
            }
          }

          if ((int)$_POST['applies_to'] != 3 && !empty($_POST['number_of_products'])) {
            $sql_data_array['number_of_products'] = (int)$_POST['number_of_products'];
          }

          if (!empty($_POST['customers']) && $_POST['customers'] == 1) {
            if (is_array($_POST['customers_id']) && sizeof($_POST['customers_id']) > 0) {
              $sql_data_array['customers_id'] = implode(',', $_POST['customers_id']);
            }
          }

          if (!empty($_POST['newsletter']) && $_POST['newsletter'] == 1) {
            $sql_data_array['newsletter'] = (int)$_POST['newsletter'];
          }

          if (!empty($_POST['order_number']) && $_POST['order_number'] > 0) {
            $sql_data_array['order_number'] = (int)$_POST['order_number'];
          }

          if ($error == false) {
            if (empty($_GET['dID'])) {
              tep_db_perform('discount_codes', $sql_data_array);
              $messageStack->add_session(SUCCESS_DISCOUNT_CODE_INSERTED, 'success');
            } else {
              tep_db_perform('discount_codes', $sql_data_array, 'update', "discount_codes_id = '" . (int)$_GET['dID'] . "'");
              $messageStack->add_session(SUCCESS_DISCOUNT_CODE_UPDATED, 'success');
            }
            tep_redirect(tep_href_link('discount_codes.php'));
          }
        }
        $action = 'new';
        break;
      case 'deleteconfirm':
        tep_db_query("delete from customers_to_discount_codes where discount_codes_id = '" . (int)$_GET['dID'] . "'");
        tep_db_query("delete from discount_codes where discount_codes_id = '" . (int)$_GET['dID'] . "' limit 1");

        $messageStack->add_session(SUCCESS_DISCOUNT_CODE_REMOVED, 'success');

        tep_redirect(tep_href_link('discount_codes.php', 'page=' . $_GET['page']));
        break;
    }
  }

  require('includes/classes/currencies.php');
  $currencies = new currencies();

  require('includes/template_top.php');
  if ($action == 'new') {
?>
<?php echo tep_draw_form('new_discount_code', 'discount_codes.php', (isset($_GET['page']) ? 'page=' . $_GET['page'] . '&' : '') . 'action=insert' . (isset($_GET['dID']) ? '&dID=' . (int)$_GET['dID'] : '')); ?>
    <table border="0" width="100%" cellspacing="0" cellpadding="2">
      <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>
<?php
    $dInfo = new objectInfo(array('products_id' => '',
                                  'categories_id' => '',
                                  'manufacturers_id' => '',
                                  'excluded_products_id' => '',
                                  'customers_id' => '',
                                  'orders_total' => '2',
                                  'shipping' => '',
                                  'newsletter' => '',
                                  'order_number' => '',
                                  'order_info' => '',
                                  'exclude_specials' => '',
                                  'discount_codes' => substr(md5(uniqid(rand(), true)), 0, 8),
                                  'discount_values' => '',
                                  'minimum_order_amount' => '',
                                  'expires_date' => '',
                                  'number_of_orders' => '',
                                  'number_of_use' => '1',
                                  'number_of_products' => '1',
                                  'status' => ''));

    if (isset($_GET['dID'])) {
      $discount_code_query = tep_db_query("select * from discount_codes where discount_codes_id = '" . (int)$_GET['dID'] . "'");
      $discount_code = tep_db_fetch_array($discount_code_query);

      $dInfo->objectInfo($discount_code);

      if (!empty($discount_code['products_id'])) $dInfo->products_id = explode(',', $discount_code['products_id']);
      if (!empty($discount_code['categories_id'])) $dInfo->categories_id = explode(',', $discount_code['categories_id']);
      if (!empty($discount_code['manufacturers_id'])) $dInfo->manufacturers_id = explode(',', $discount_code['manufacturers_id']);
      if (!empty($discount_code['excluded_products_id'])) $dInfo->excluded_products_id = explode(',', $discount_code['excluded_products_id']);
      if (!empty($discount_code['customers_id'])) $dInfo->customers_id = explode(',', $discount_code['customers_id']);
      if ($discount_code['minimum_order_amount'] == '0.0000') $dInfo->minimum_order_amount = '';
      if ($discount_code['expires_date'] == '0000-00-00') $dInfo->expires_date = '';
      if ($discount_code['number_of_use'] == 0) $dInfo->number_of_use = '';
      if ($discount_code['number_of_products'] == 0) $dInfo->number_of_products = '';
    }

    $manufacturers_array = array();
    $manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from manufacturers order by manufacturers_name");
    while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {
      $manufacturers_array[] = array('id' => $manufacturers['manufacturers_id'],
                                     'text' => $manufacturers['manufacturers_name']);
    }
?>

<script language="javascript">
$(document).ready(function() {
    if (<?php echo ((basename($PHP_SELF) == 'discount_codes.php' && isset($action) && $action == 'new') ? 'true' : 'false')?>) {
        onload();
    }
});
function applies_to_onclick() {
  var a = document.new_discount_code.applies_to, b = document.getElementById("excluded_products_id"), c = document.getElementById("number_of_products"), d = document.getElementById("exclude_specials");
  for (var i = 0, n = a.length; i < n; i++) if (a[i].checked) { b.disabled = (a[i].value == 2 || a[i].value == 4 ? false : true); c.disabled = (a[i].value == 3 || a[i].value == 5 || a[i].value == 6 ? true : false); d.disabled = (a[i].value == 3 || a[i].value == 5 || a[i].value == 6 ? true : false) }
}
function customers_onclick() {
  var d = document.getElementById("customers"), e = document.getElementById("customers_id"); e.disabled = !d.checked;
}
function onload() {
  SetFocus();
  applies_to_onclick();
  customers_onclick();
}

var Password = {
//  _pattern : /[a-zA-Z0-9_\-\+\.]/,
  _pattern : /[a-zA-Z0-9]/,
  
  _getRandomByte : function()
  {
    // http://caniuse.com/#search=getrandomvalues
    if(window.crypto && window.crypto.getRandomValues)
    {
      var result = new Uint8Array(1);
      window.crypto.getRandomValues(result);
      return result[0];
    }
    else if(window.msCrypto && window.msCrypto.getRandomValues)
    {
      var result = new Uint8Array(1);
      window.msCrypto.getRandomValues(result);
      return result[0];
    }
    else
    {
      return Math.floor(Math.random() * 256);
    }
  },
  
  generate : function(length)
  {
    return Array.apply(null, {'length': length})
      .map(function()
      {
        var result;
        while(true)
        {
          result = String.fromCharCode(this._getRandomByte());
          if(this._pattern.test(result))
          {
            return result;
          }
        }
      }, this)
      .join('');
  }
};
</script>

      <tr>
        <td><table border="0" cellspacing="0" cellpadding="2">
		  <tr>
		    <td class="main" colspan="4"><?php echo TEXT_DISCOUNT_EXPL; ?></td>
			<td><input type="button" value="Generate Random Code" onclick="document.getElementById('code').value = Password.generate(8)"></td>
		  </tr>
          <tr>
            <td class="main"><?php echo TEXT_DISCOUNT_CODE; ?></td>
            <td class="main"><?php echo tep_draw_input_field('discount_codes', $dInfo->discount_codes, 'size="8" id="code"', true); ?></td>
            <td width="50"></td>
            <td class="main"><?php echo TEXT_NUMBER_OF_USE; ?></td>
            <td class="main"><?php echo tep_draw_input_field('number_of_use', $dInfo->number_of_use, 'size="4"'); ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_DISCOUNT; ?></td>
            <td class="main"><?php echo tep_draw_input_field('discount_values', $dInfo->discount_values, 'size="8"', true); ?></td>
            <td></td>
            <td class="main"><?php echo TEXT_NUMBER_OF_PRODUCTS; ?></td>
            <td class="main"><?php echo tep_draw_input_field('number_of_products', $dInfo->number_of_products, 'size="4" id="number_of_products"'); ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_MINIMUM_ORDER_SUB_TOTAL; ?></td>
            <td class="main"><?php echo tep_draw_input_field('minimum_order_amount', $dInfo->minimum_order_amount, 'size="8"'); ?></td>
            <td></td>
            <td class="main" colspan="2"><?php echo '<label>' . tep_draw_checkbox_field('order_info', '1', $dInfo->order_info == 1) . ' ' . TEXT_ORDER_INFO . '</label>'; ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_EXPIRY; ?></td>
            <td class="main"><?php echo tep_draw_input_field('expires_date', $dInfo->expires_date, 'id="expires_date" size="12"'); ?></td>
            <td></td>
            <td class="main" colspan="2"><?php echo '<label>' . str_replace('name="exclude_specials"', 'name="exclude_specials" id="exclude_specials"', tep_draw_checkbox_field('exclude_specials', '1', $dInfo->exclude_specials == 1)) . ' ' . TEXT_EXCLUDE_SPECIALS . '</label>'; ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td><table border="0" cellspacing="0" cellpadding="2">
          <tr>
            <td class="main"><?php echo TEXT_APPLIES_TO; ?></td>
            <td width="5"></td>
            <td class="main"><?php echo '<label>' . str_replace('<input type="radio"', '<input onclick="applies_to_onclick();" type="radio"', tep_draw_radio_field('applies_to', '5', $dInfo->orders_total == 2)) . ' ' . TEXT_ORDER_SUBTOTAL . '</label>'; ?></td>
            <td width="5"></td>
            <td class="main"><?php echo '<label>' . str_replace('<input type="radio"', '<input onclick="applies_to_onclick();" type="radio"', tep_draw_radio_field('applies_to', '6', $dInfo->shipping == 2)) . ' ' . TEXT_SHIPPING . '</label>'; ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo '<label>' . str_replace('<input type="radio"', '<input onclick="applies_to_onclick();" type="radio"', tep_draw_radio_field('applies_to', '1', is_array($dInfo->products_id))) . ' ' . TEXT_PRODUCTS . '</label>'; ?></td>
            <td></td>
            <td class="main"><?php echo '<label>' . str_replace('<input type="radio"', '<input onclick="applies_to_onclick();" type="radio"', tep_draw_radio_field('applies_to', '2', is_array($dInfo->categories_id))) . ' ' . TEXT_CATEGORIES . '</label>'; ?></td>
            <td></td>
            <td class="main"><?php echo '<label>' . str_replace('<input type="radio"', '<input onclick="applies_to_onclick();" type="radio"', tep_draw_radio_field('applies_to', '4', is_array($dInfo->manufacturers_id))) . ' ' . TEXT_MANUFACTURERS . '</label>'; ?></td>
          </tr>
<?php
    $products_id = '';
    $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_price, s.specials_new_products_price from (products p, products_description pd) left join specials s on (p.products_id = s.products_id and s.status = '1' and ifnull(s.expires_date, now()) >= now()) where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by products_name");
    while ($products = tep_db_fetch_array($products_query)) {
      $products_id .= '<option value="' . $products['products_id'] . '">' . $products['products_name'] . ' (' . (empty($products['specials_new_products_price']) ? '' : $currencies->format($products['specials_new_products_price']) . '/') . $currencies->format($products['products_price']) . ')</option>';
    }
    $products_id .= '</select>';

    $excluded_products_id = '<select name="excluded_products_id[]" size="10" multiple style="width: 280px;" id="excluded_products_id">' . $products_id;
    $products_id = '<select name="products_id[]" size="10" multiple style="width: 280px;">' . $products_id;

    if (is_array($dInfo->products_id)) {
      foreach ($dInfo->products_id as $v) {
        $products_id = str_replace('<option value="' . $v . '">', '<option value="' . $v . '" selected>', $products_id);
      }
    }

    if (is_array($dInfo->excluded_products_id)) {
      foreach ($dInfo->excluded_products_id as $v) {
        $excluded_products_id = str_replace('<option value="' . $v . '">', '<option value="' . $v . '" selected>', $excluded_products_id);
      }
    }

    $categories_id = str_replace('<select name="categories_id">', '<select name="categories_id[]" size="10" multiple style="width: 280px;">', tep_draw_pull_down_menu('categories_id', tep_get_category_tree('0', '', '0')));
    if (is_array($dInfo->categories_id)) {
      foreach ($dInfo->categories_id as $v) {
        $categories_id = str_replace('<option value="' . $v . '">', '<option value="' . $v . '" selected>', $categories_id);
      }
    }

    $manufacturers_id = str_replace('<select name="manufacturers_id">', '<select name="manufacturers_id[]" size="10" multiple style="width: 280px;">', tep_draw_pull_down_menu('manufacturers_id', $manufacturers_array));
    if (is_array($dInfo->manufacturers_id)) {
      foreach ($dInfo->manufacturers_id as $v) {
        $manufacturers_id = str_replace('<option value="' . $v . '">', '<option value="' . $v . '" selected>', $manufacturers_id);
      }
    }
?>
          <tr>
            <td class="main"><?php echo $products_id; ?></td>
            <td></td>
            <td class="main"><?php echo $categories_id; ?></td>
            <td></td>
            <td class="main"><?php echo $manufacturers_id; ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_EXCLUDED_PRODUCTS; ?></td>
            <td></td>
            <td class="main"><?php echo '<label>' . str_replace('<input type="checkbox"', '<input type="checkbox" id="customers" onclick="customers_onclick();"', tep_draw_checkbox_field('customers', '1', is_array($dInfo->customers_id))) . ' ' . TEXT_CUSTOMERS . '</label>'; ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo $excluded_products_id; ?></td>
            <td></td>
<?php
    $customers_id = '<select name="customers_id[]" size="10" multiple style="width: 280px;" id="customers_id">';
    $customers_query = tep_db_query("select customers_id, concat(customers_lastname, ', ', customers_firstname, ' (', customers_email_address, ')') as customers_info from customers order by customers_lastname, customers_firstname");
    while ($customers = tep_db_fetch_array($customers_query)) {
      $customers_id .= '<option value="' . $customers['customers_id'] . '">' . $customers['customers_info'] . '</option>';
    }
    $customers_id .= '</select>';

    if (is_array($dInfo->customers_id)) {
      foreach ($dInfo->customers_id as $v) {
        $customers_id = str_replace('<option value="' . $v . '">', '<option value="' . $v . '" selected>', $customers_id);
      }
    }
?>
            <td class="main"><?php echo $customers_id; ?></td>
            <td></td>
            <td class="main"><?php echo '<label>' . TEXT_NEWSLETTER_CUSTOMERS . ': ' . '<input type="checkbox" id="newsletter"', tep_draw_checkbox_field('newsletter', '1', $dInfo->newsletter == 1) . '</label>'; ?>
            <br><br><?php echo '<label>' . TEXT_ORDER_CUSTOMERS . ': ' . tep_draw_input_field('order_number', $dInfo->order_number, 'size="4"') . '</label><br>' . TEXT_ORDER_CUSTOMERS_NOTE; ?>
          </tr>
        </table>

<script type="text/javascript">
$('#expires_date').datepicker({
  dateFormat: 'yy-mm-dd'
});
</script>

        </td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
          <tr>
            <td class="smallText" align="right" valign="top" nowrap><?php echo tep_draw_button(IMAGE_SAVE, 'disk', null, 'primary') . tep_draw_button(IMAGE_CANCEL, 'close', tep_href_link('discount_codes.php', (isset($_GET['page']) ? 'page=' . $_GET['page'] . '&' : '') . (isset($_GET['dID']) ? 'dID=' . (int)$_GET['dID'] : ''))); ?></td>
          </tr>
        </table></td>
      </tr>
    </table>
  </form>
<?php
  } else {
?>

    <table border="0" width="100%" cellspacing="0" cellpadding="2">
      <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>
<?php
?>
      <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" alt="<?php echo TABLE_HEADING_MINIMUM_ORDER_AMOUNT_FULL; ?>" title=" <?php echo TABLE_HEADING_MINIMUM_ORDER_AMOUNT_FULL; ?> "><?php echo TABLE_HEADING_MINIMUM_ORDER_AMOUNT; ?></td>
                <td class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_EXPIRY; ?></td>
                <td class="dataTableHeadingContent" align="center" alt="<?php echo TABLE_HEADING_NUMBER_OF_ORDERS_FULL; ?>" title=" <?php echo TABLE_HEADING_NUMBER_OF_ORDERS_FULL; ?> "><?php echo TABLE_HEADING_NUMBER_OF_ORDERS; ?></td>
                <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_STATUS; ?></td>
                <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?> </td>
              </tr>
<?php
    $discount_codes_query_raw = "select * from discount_codes order by discount_codes_id desc";
    $discount_codes_split = new splitPageResults($_GET['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)) {
      $applies_to = '';
      if (!empty($discount_codes['orders_total'])) {
		if ($discount_codes['orders_total'] == 2) {
          $applies_to = TEXT_ORDER_SUBTOTAL;
        } 
	  } elseif (!empty($discount_codes['shipping'])) {
		if ($discount_codes['shipping'] == 2) {
          $applies_to = TEXT_SHIPPING;
        }  
	  } elseif (!empty($discount_codes['products_id'])) {
        $applies_to = TEXT_PRODUCTS;
        $product_query = tep_db_query("select products_name from products_description where products_id in (" . $discount_codes['products_id'] . ") and language_id = '" . (int)$languages_id . "' order by products_name");
        while ($product = tep_db_fetch_array($product_query)) {
          $applies_to .= (empty($applies_to) ? '' : '<br>') . $product['products_name'];
        }
      } elseif (!empty($discount_codes['categories_id'])) {
        $applies_to = TEXT_CATEGORIES;
        $category_query = tep_db_query("select c.categories_id from categories c, categories_description cd where c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' and c.categories_id in (" . $discount_codes['categories_id'] . ") order by c.parent_id, cd.categories_name");
        while ($category = tep_db_fetch_array($category_query)) {
          $applies_to .= (empty($applies_to) ? '' : '<br>') . tep_output_generated_category_path($category['categories_id']);
        }
      } else {
        $applies_to = TEXT_MANUFACTURERS;
        $manufacturer_query = tep_db_query("select manufacturers_name from manufacturers where manufacturers_id in (" . $discount_codes['manufacturers_id'] . ") order by manufacturers_name");
        while ($manufacturer = tep_db_fetch_array($manufacturer_query)) {
          $applies_to .= (empty($applies_to) ? '' : '<br>') . $manufacturer['manufacturers_name'];
        }
      }
      if (!empty($discount_codes['excluded_products_id'])) {
        $applies_to .= '<br>' . TEXT_EXCLUDED_PRODUCTS;
        $product_query = tep_db_query("select products_name from products_description where products_id in (" . $discount_codes['excluded_products_id'] . ") and language_id = '" . (int)$languages_id . "' order by products_name");
        while ($product = tep_db_fetch_array($product_query)) {
          $applies_to .= (empty($applies_to) ? '' : '<br>') . $product['products_name'];
        }
      }

      if ((!isset($_GET['dID']) || (isset($_GET['dID']) && ($_GET['dID'] == $discount_codes['discount_codes_id']))) && !isset($dInfo) && (substr($action, 0, 3) != 'new')) {
        $dInfo = new objectInfo($discount_codes);
      }

      if (isset($dInfo) && is_object($dInfo) && ($discount_codes['discount_codes_id'] == $dInfo->discount_codes_id)) {
        echo '              <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link('discount_codes.php', 'page=' . $_GET['page'] . '&dID=' . $dInfo->discount_codes_id) . '\'">' . "\n";
      } else {
        echo '              <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link('discount_codes.php', 'page=' . $_GET['page'] . '&dID=' . $discount_codes['discount_codes_id']) . '\'">' . "\n";
      }
?>
                <td class="dataTableContent"><?php echo $discount_codes['discount_codes']; ?></td>
                <td class="dataTableContent"><?php echo $applies_to; ?></td>
                <td class="dataTableContent" align="center">
			    <?php 
			      switch ($discount_codes['discount_values']) {
				    case strpos($discount_codes['discount_values'], '%') == true:
                      $discount_codes_value = $discount_codes['discount_values'];
                      break;
            	    default:
            	      $discount_codes_value = $currencies->format($discount_codes['discount_values']);	 
            	  }     
				  echo $discount_codes_value; 
			    ?>
			    </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']); ?> </td>
                <td class="dataTableContent" align="center"><?php echo $discount_codes['number_of_orders']; ?></td>
                <td class="dataTableContent" align="right">
<?php
      if ($discount_codes['status'] == '1') {
        echo tep_image('images/icon_status_green.gif', 'Active', 10, 10) . '  <a href="' . tep_href_link('discount_codes.php', 'page=' . $_GET['page'] . '&dID=' . $discount_codes['discount_codes_id'] . '&action=setflag&flag=0') . '">' . tep_image('images/icon_status_red_light.gif', 'Set Inactive', 10, 10) . '</a>';
      } else {
        echo '<a href="' . tep_href_link('discount_codes.php', 'page=' . $_GET['page'] . '&dID=' . $discount_codes['discount_codes_id'] . '&action=setflag&flag=1') . '">' . tep_image('images/icon_status_green_light.gif', 'Set Active', 10, 10) . '</a>  ' . tep_image('images/icon_status_red.gif', 'Inactive', 10, 10);
      }
?></td>
                <td class="dataTableContent" align="right"><?php if (isset($dInfo) && is_object($dInfo) && ($discount_codes['discount_codes_id'] == $dInfo->discount_codes_id)) { echo tep_image('images/icon_arrow_right.gif', ''); } else { echo '<a href="' . tep_href_link('discount_codes.php', 'page=' . $_GET['page'] . '&dID=' . $discount_codes['discount_codes_id']) . '">' . tep_image('images/icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?> </td>
              </tr>
<?php
    }
?>
              <tr>
                <td colspan="8"><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, $_GET['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, $_GET['page']); ?></td>
                  </tr>
                  <tr>
                    <td class="smallText" align="right" colspan="2"><?php echo tep_draw_button(IMAGE_NEW_DISCOUNT_CODE, 'plus', tep_href_link('discount_codes.php', 'action=new')); ?></td>
                  </tr>
                </table></td>
              </tr>
            </table></td>
<?php
  $heading = array();
  $contents = array();
  switch ($action) {
    case 'delete':
      $heading[] = array('text' => '<strong>' . $dInfo->discount_codes . '</strong>');

      $contents = array('form' => tep_draw_form('discount_codes', 'discount_codes.php', 'page=' . $_GET['page'] . '&dID=' . $dInfo->discount_codes_id . '&action=deleteconfirm'));
      $contents[] = array('text' => TEXT_INFO_DELETE_INTRO);
      $contents[] = array('align' => 'center', 'text' => '<br />' . tep_draw_button(IMAGE_DELETE, 'trash', null, 'primary') . tep_draw_button(IMAGE_CANCEL, 'close', tep_href_link('discount_codes.php', 'page=' . $_GET['page'] . '&dID=' . $_GET['dID'])));
      break;
    default:
      if (is_object($dInfo)) {
        $heading[] = array('text' => '<strong>' . $dInfo->discount_codes . '</strong>');

        $contents[] = array('align' => 'center', 'text' => tep_draw_button(IMAGE_EDIT, 'document', tep_href_link('discount_codes.php', 'page=' . $_GET['page'] . '&dID=' . $dInfo->discount_codes_id . '&action=new')) . tep_draw_button(IMAGE_DELETE, 'trash', tep_href_link('discount_codes.php', 'page=' . $_GET['page'] . '&dID=' . $dInfo->discount_codes_id . '&action=delete')));
        $contents[] = array('text' => '<br />');
        if ($dInfo->order_info == 1) $contents[] = array('text' => tep_image('images/icons/tick.gif', TABLE_HEADING_ORDER_INFO_FULL) . ' ' . TABLE_HEADING_ORDER_INFO_FULL);
        if ($dInfo->exclude_specials == 1) $contents[] = array('text' => tep_image('images/icons/tick.gif', TEXT_EXCLUDE_SPECIALS) . ' ' . TEXT_EXCLUDE_SPECIALS);
        if ($dInfo->newsletter == 1) $contents[] = array('text' => tep_image('images/icons/tick.gif', TEXT_NEWSLETTER) . ' ' . TEXT_NEWSLETTER);
        if ($dInfo->order_number > 0) $contents[] = array('text' => tep_image('images/icons/tick.gif', TEXT_ORDER_NUMBER) . ' ' . TEXT_ORDER_NUMBER . $dInfo->order_number);
        if ($dInfo->number_of_use != 0) $contents[] = array('text' => TABLE_HEADING_NUMBER_OF_USE . ' ' . $dInfo->number_of_use);
        if ($dInfo->number_of_products != 0) $contents[] = array('text' => TABLE_HEADING_NUMBER_OF_PRODUCTS . ' ' . $dInfo->number_of_products);
        if (!empty($dInfo->customers_id)) {
          $select_string = '';
          $customers_query = tep_db_query("select concat(customers_lastname, ', ', customers_firstname, ' (', customers_email_address, ')') as customers_info from customers where customers_id in (" . $dInfo->customers_id . ") order by customers_lastname, customers_firstname");
          while ($customers = tep_db_fetch_array($customers_query)) {
            $select_string .= (empty($select_string) ? '' : '<br>') . $customers['customers_info'];
          }
          if (!empty($select_string)) {
            $contents[] = array('text' => '<br />' . TEXT_INFO_CUSTOMERS . '<br />' . $select_string);
          }
        }
      }
      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>
<?php
  }

  require('includes/template_bottom.php');
  require('includes/application_bottom.php');
?>

Enjoy !

frankl and Tsimi like this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now