/**
 * Auto expire products on special
 */
function oos_expire_spezials()
{

    // Get database information
    $dbconn =& oosDBGetConn();
    $oostable =& oosDBGetTables();

    $specialstable = $oostable['specials'];
    $query = "SELECT specials_id
              FROM $specialstable
              WHERE status = '1'
                AND now() >= expires_date
                AND expires_date > 0";
    if (USE_DB_CACHE == '1') {
        $result =& $dbconn->CacheExecute(3600, $query);
    } else {
        $result =& $dbconn->Execute($query);
    }
    if (!$result) {return;}

    if ($result->RecordCount() > 0) {
        while ($specials = $result->fields)
        {
            oos_set_specials_status($specials['specials_id'], '0');

            // Move that ADOdb pointer!
            $result->MoveNext();
        }
    }
}
      $specialstable = $oostable['specials'];
      return $dbconn->Execute("UPDATE $specialstable SET status = '0', date_status_change = now() WHERE specials_id = '" . $specials_id . "'");
    } else {
      return -1;
    }
  }

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

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

  if (!empty($action)) {
    switch ($action) {
      case 'setflag':
        oos_set_specials_status($_GET['id'], $_GET['flag']);
        oos_redirect_admin(oos_href_link_admin($aFilename['specials'], '', 'NONSSL'));
        break;

      case 'insert':
        // insert a product on special
        if (substr($_POST['specials_price'], -1) == '%') {
          $productstable = $oostable['products'];
          $new_special_insert_result = $dbconn->Execute("SELECT products_id, products_price FROM $productstable WHERE products_id = '" . $_POST['products_id'] . "'");
          $new_special_insert = $new_special_insert_result->fields;
          $_POST['products_price'] = $new_special_insert['products_price'];
          $_POST['specials_price'] = ($_POST['products_price'] - (($_POST['specials_price'] / 100) * $_POST['products_price']));
        } elseif (OOS_PRICE_IS_BRUTTO == '1') {
          $tax_ratestable = $oostable['tax_rates'];
          $productstable = $oostable['products'];
          $sql = "SELECT tr.tax_rate