<?php
//
// +----------------------------------------------------------------------+
// |zen-cart Open Source E-commerce                                       |
// +----------------------------------------------------------------------+
// | Copyright (c) 2007-2008 Numinix Technology http://www.numinix.com    |
// |                                                                      |
// | Portions Copyright (c) 2003-2006 Zen Cart Development Team           |
// | http://www.zen-cart.com/index.php                                    |
// |                                                                      |
// | Portions Copyright (c) 2003 osCommerce                               |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at the following url:           |
// | http://www.zen-cart.com/license/2_0.txt.                             |
// | If you did not receive a copy of the zen-cart license and are unable |
// | to obtain it through the world-wide-web, please send a note to       |
// | license@zen-cart.com so we can mail you a copy immediately.          |
// +----------------------------------------------------------------------+
//  $Id: class.drop_down.php 88 2009-08-27 21:03:25Z numinix $
//
/**
 * Observer class used to handle reward points in an order
 *
 */
class dropDownObserver extends base 
{
	function dropDownObserver()
	{
		global $zco_notifier;
		$zco_notifier->attach($this, array('NOTIFY_HEADER_START_CHECKOUT_SUCCESS'));
	}
	
	function update(&$class, $eventID, $paramsArray) 
	{
    if (FEC_DROP_DOWN == 'true' || FEC_GIFT_MESSAGE == 'true') {
      global $db;
      // find out the last order number generated for this customer account 
      $orders_query = "SELECT * FROM " . TABLE_ORDERS . "
                   WHERE customers_id = :customersID
                   ORDER BY date_purchased DESC LIMIT 1";
      $orders_query = $db->bindVars($orders_query, ':customersID', $_SESSION['customer_id'], 'integer');
      $orders = $db->Execute($orders_query);
      $orders_id = $orders->fields['orders_id'];
      
      // use order-id generated by the actual order process
      // this uses the SESSION orders_id, or if doesn't exist, grabs most recent order # for this cust (needed for paypal et al).
      // Needs reworking in v1.4 for checkout-rewrite
      $zv_orders_id = (isset($_SESSION['order_number_created']) && $_SESSION['order_number_created'] >= 1) ? $_SESSION['order_number_created'] : $orders_id;
      $orders_id = $zv_orders_id;
      
      // get the value of the selected dropdown
      $dropdown = zen_db_input($_SESSION['dropdown']);
      $gift_message = zen_db_input($_SESSION['gift-message']);
      
      // add selected dropdown option to the orders table
      $db->Execute("UPDATE  " . TABLE_ORDERS . "
                    SET dropdown = '" . $dropdown . "',
                        gift_message = '" . $gift_message . "'
                    WHERE orders_id = " . $orders_id . "
                    LIMIT 1");
      
      // unset the dropdown session
      unset($_SESSION['dropdown']);
      unset($_SESSION['gift-message']);
    }
	}
}
// eof