function query($order_id)
 {
     $order_query = olc_db_query("\n\t\tselect\n\t\tcustomers_name,\n\t\tcustomers_cid,\n\t\tcustomers_id,\n\t\tcustomers_company,\n\t\tcustomers_street_address,\n\t\tcustomers_suburb,\n\t\tcustomers_city,\n\t\tcustomers_postcode,\n\t\tcustomers_state,\n\t\tcustomers_country,\n\t\tcustomers_telephone,\n\t\tcustomers_email_address,\n\t\tcustomers_address_format_id,\n\t\tdelivery_name,\n\t\tdelivery_company,\n\t\tdelivery_street_address,\n\t\tdelivery_suburb,\n\t\tdelivery_city,\n\t\tdelivery_postcode,\n\t\tdelivery_state,\n\t\tdelivery_country,\n\t\tdelivery_address_format_id,\n\t\tbilling_name,\n\t\tbilling_company,\n\t\tbilling_street_address,\n\t\tbilling_suburb,\n\t\tbilling_city,\n\t\tbilling_postcode,\n\t\tbilling_state,\n\t\tbilling_country,\n\t\tbilling_address_format_id,\n\t\tbilling_invoice_number,\n\t\tpayment_method,\n\t\tcc_type,\n\t\tcc_owner,\n\t\tcc_number,\n\t\tcc_expires,\n\t\tcomments,\n\t\tcurrency,\n\t\tcurrency_value,\n\t\tdate_purchased,\n\t\torders_status,\n\t\torders_trackcode,\n\t\tlast_modified,\n\t\tpayment_id,\n\t\tcustomers_status,\n\t\tcustomers_status_name,\n\t\tcustomers_status_image,\n\t\tcustomers_ip,\n\t\tlanguage,\n\t\tcustomers_status_discount\n\t\tfrom " . TABLE_ORDERS . " where\n\t\torders_id = '" . olc_db_input($order_id) . APOS);
     $order = olc_db_fetch_array($order_query);
     $totals_query = olc_db_query("select title, text from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . olc_db_input($order_id) . "' order by sort_order");
     while ($totals = olc_db_fetch_array($totals_query)) {
         $this->totals[] = array('title' => $totals['title'], 'text' => $totals['text']);
     }
     $this->info = array('order_id' => $order_id, 'currency' => $order['currency'], 'currency_value' => $order['currency_value'], 'payment_method' => $order['payment_method'], 'status' => $order['customers_status'], 'status_name' => $order['customers_status_name'], 'status_image' => $order['customers_status_image'], 'status_discount' => $order['customers_status_discount'], 'cc_type' => $order['cc_type'], 'cc_owner' => $order['cc_owner'], 'cc_number' => $order['cc_number'], 'cc_expires' => $order['cc_expires'], 'comments' => $order['comments'], 'language' => $order['language'], 'date_purchased' => $order['date_purchased'], 'payment_id' => $order['payment_id'], 'orders_status' => $order['orders_status'], 'orders_trackcode' => $order['orders_trackcode'], 'last_modified' => $order['last_modified']);
     $this->customer = array('name' => $order['customers_name'], 'id' => $order['customers_id'], 'company' => $order['customers_company'], 'csID' => $order['customers_cid'], 'shop_id' => $order['shop_id'], 'id' => $order['customers_id'], 'cIP' => $order['customers_ip'], 'street_address' => $order['customers_street_address'], 'suburb' => $order['customers_suburb'], 'city' => $order['customers_city'], 'postcode' => $order['customers_postcode'], 'state' => $order['customers_state'], 'country' => $order['customers_country'], 'format_id' => $order['customers_address_format_id'], 'telephone' => $order['customers_telephone'], 'email_address' => $order['customers_email_address']);
     $this->delivery = array('name' => $order['delivery_name'], 'company' => $order['delivery_company'], 'street_address' => $order['delivery_street_address'], 'suburb' => $order['delivery_suburb'], 'city' => $order['delivery_city'], 'postcode' => $order['delivery_postcode'], 'state' => $order['delivery_state'], 'country' => $order['delivery_country'], 'format_id' => $order['delivery_address_format_id']);
     $this->billing = array('name' => $order['billing_name'], 'company' => $order['billing_company'], 'street_address' => $order['billing_street_address'], 'suburb' => $order['billing_suburb'], 'city' => $order['billing_city'], 'postcode' => $order['billing_postcode'], 'state' => $order['billing_state'], 'country' => $order['billing_country'], 'format_id' => $order['billing_address_format_id'], 'billing_invoice_number' => $order['billing_invoice_number']);
     $index = 0;
     $orders_products_query = olc_db_query("\n\t\t\tselect\n\t\t\torders_products_id,\n\t\t\tproducts_name,\n\t\t\tproducts_id,\n\t\t\tproducts_model,\n\t\t\tproducts_price,\n\t\t\tproducts_tax,\n\t\t\tproducts_quantity,\n\t\t\tfinal_price,\n\t\t\tallow_tax,\n\t\t\tproducts_discount_made\n\t\t\tfrom " . TABLE_ORDERS_PRODUCTS . "\n\t\t\twhere\n\t\t\torders_id ='" . olc_db_input($order_id) . APOS);
     while ($orders_products = olc_db_fetch_array($orders_products_query)) {
         $this->products[$index] = array('id' => $orders_products['products_id'], 'orders_products_id' => $orders_products['orders_products_id'], 'qty' => $orders_products['products_quantity'], 'name' => $orders_products['products_name'], 'model' => $orders_products['products_model'], 'tax' => $orders_products['products_tax'], 'price' => $orders_products['products_price'], 'discount' => $orders_products['products_discount_made'], 'final_price' => $orders_products['final_price'], 'allow_tax' => $orders_products['allow_tax'], 'auctionid' => $orders_products['auctionid']);
         $subindex = 0;
         $attributes_query = olc_db_query("\n\t\t\t\tselect\n\t\t\t\tproducts_options,\n\t\t\t\tproducts_options_values,\n\t\t\t\tproducts_options_id,\n\t\t\t\tproducts_options_values_id,\n\t\t\t\toptions_values_price,\n\t\t\t\tprice_prefix from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id = '" . olc_db_input($order_id) . "' and orders_products_id = '" . $orders_products['orders_products_id'] . APOS);
         if (olc_db_num_rows($attributes_query)) {
             while ($attributes = olc_db_fetch_array($attributes_query)) {
                 $this->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options'], 'value' => $attributes['products_options_values'], 'option_id' => $attributes['products_options_id'], 'value_id' => $attributes['products_options_values_id'], 'prefix' => $attributes['price_prefix'], 'price' => $attributes['options_values_price']);
                 $subindex++;
             }
         }
         $index++;
     }
 }
function olc_display_banner($action, $identifier)
{
    if ($action == 'dynamic') {
        $banners_query = olc_db_query(SELECT_COUNT . " as count from " . TABLE_BANNERS . " where status = '1' and banners_group = '" . $identifier . APOS);
        $banners = olc_db_fetch_array($banners_query);
        if ($banners['count'] > 0) {
            $banner = olc_random_select("select banners_id, banners_title, banners_image, banners_html_text from " . TABLE_BANNERS . " where status = '1' and banners_group = '" . $identifier . APOS);
        } else {
            return '<b>OLC ERROR! (olc_display_banner(' . $action . ', ' . $identifier . ') -> No banners with group \'' . $identifier . '\' found!</b>';
        }
    } elseif ($action == 'static') {
        if (is_array($identifier)) {
            $banner = $identifier;
        } else {
            $banner_query = olc_db_query("select banners_id, banners_title, banners_image, banners_html_text from " . TABLE_BANNERS . " where status = '1' and banners_id = '" . $identifier . APOS);
            if (olc_db_num_rows($banner_query)) {
                $banner = olc_db_fetch_array($banner_query);
            } else {
                return '<b>OLC ERROR! (olc_display_banner(' . $action . ', ' . $identifier . ') -> Banner with id \'' . $identifier . '\' not found, or status inactive</b>';
            }
        }
    } else {
        return '<b>OLC ERROR! (olc_display_banner(' . $action . ', ' . $identifier . ') -> Unknown $action parameter value - it must be either \'dynamic\' or \'static\'' . HTML_B_END;
    }
    if (olc_not_null($banner['banners_html_text'])) {
        $banner_string = $banner['banners_html_text'];
    } else {
        $banner_string = HTML_A_START . olc_href_link(FILENAME_REDIRECT, 'action=banner&goto=' . $banner['banners_id']) . '" target="_blank">' . olc_image(DIR_WS_IMAGES . 'banner/' . $banner['banners_image'], $banner['banners_title']) . HTML_A_END;
    }
    olc_update_banner_display_count($banner['banners_id']);
    return $banner_string;
}
function olc_random_select($query, $rows = 1)
{
    global $random_rows;
    $random_product = '';
    $random_query = olc_db_query($query);
    $num_rows = olc_db_num_rows($random_query);
    if ($num_rows > 1) {
        $num_rows1 = $num_rows - 1;
        for ($row = 1; $row <= $rows; $row++) {
            $tries = 0;
            $random_row = olc_rand(0, $num_rows1);
            $random_row_store = "|" . $random_row . "|";
            $include_row = true;
            while (!(strpos($random_rows, $random_row_store) === false)) {
                $tries++;
                if ($tries > 10) {
                    $include_row = false;
                    break;
                } else {
                    $random_row = olc_rand(0, $num_rows1);
                }
            }
            if ($include_row) {
                $random_rows .= $random_row_store;
                olc_db_data_seek($random_query, $random_row);
                $random_product[] = olc_db_fetch_array($random_query);
            }
        }
    } else {
        if ($num_rows > 0) {
            $random_product[] = olc_db_fetch_array($random_query);
        }
    }
    return $random_product;
}
 function check()
 {
     if (!isset($this->_check)) {
         $check_query = olc_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_ORDER_TOTAL_SUBTOTAL_NO_TAX_STATUS'");
         $this->_check = olc_db_num_rows($check_query);
     }
     return $this->_check;
 }
function olc_expire_specials()
{
    $specials_query = olc_db_query("select specials_id from " . TABLE_SPECIALS . " where status = '1' and now() >= expires_date and expires_date > 0");
    if (olc_db_num_rows($specials_query)) {
        while ($specials = olc_db_fetch_array($specials_query)) {
            olc_set_specials_status($specials['specials_id'], '0');
        }
    }
}
function olc_currency_exists($code)
{
    $currency_code = olc_db_query("select currencies_id from " . TABLE_CURRENCIES . " where code = '" . $code . APOS);
    if (olc_db_num_rows($currency_code)) {
        return $code;
    } else {
        return false;
    }
}
Example #7
0
function olc_get_address_format_id($country_id)
{
    $address_format_query = olc_db_query("select address_format_id as format_id from " . TABLE_COUNTRIES . " where countries_id = '" . $country_id . APOS);
    if (olc_db_num_rows($address_format_query)) {
        $address_format = olc_db_fetch_array($address_format_query);
        return $address_format['format_id'];
    } else {
        return '1';
    }
}
Example #8
0
function olc_get_zone_name($country_id, $zone_id, $default_zone = '')
{
    $zone_query = olc_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . $country_id . "' and zone_id = '" . $zone_id . APOS);
    if (olc_db_num_rows($zone_query)) {
        $zone = olc_db_fetch_array($zone_query);
        return $zone['zone_name'];
    } else {
        return $default_zone;
    }
}
function olc_get_languages_directory($code)
{
    $language_query = olc_db_query("select languages_id, directory from " . TABLE_LANGUAGES . " where code = '" . $code . APOS);
    if (olc_db_num_rows($language_query)) {
        $lang = olc_db_fetch_array($language_query);
        $_SESSION['languages_id'] = $lang['languages_id'];
        return $lang['directory'];
    } else {
        return false;
    }
}
function olc_activate_banners()
{
    $banners_query = olc_db_query("select banners_id, date_scheduled from " . TABLE_BANNERS . " where date_scheduled != ''");
    if (olc_db_num_rows($banners_query)) {
        while ($banners = olc_db_fetch_array($banners_query)) {
            if (date('Y-m-d H:i:s') >= $banners['date_scheduled']) {
                olc_set_banner_status($banners['banners_id'], '1');
            }
        }
    }
}
function olc_get_affiliate_tax_rate($class_id, $country_id, $zone_id)
{
    $tax_query = olc_db_query("select SUM(tax_rate) as tax_rate from " . TABLE_TAX_RATES . " tr left join " . TABLE_ZONES_TO_GEO_ZONES . " za ON tr.tax_zone_id = za.geo_zone_id left join " . TABLE_GEO_ZONES . " tz ON tz.geo_zone_id = tr.tax_zone_id\n    \tWHERE (za.zone_country_id IS NULL OR za.zone_country_id = '0' OR za.zone_country_id = '" . $country_id . "') AND (za.zone_id IS NULL OR za.zone_id = '0' OR za.zone_id = '" . $zone_id . "') AND tr.tax_class_id = '" . $class_id . "' GROUP BY tr.tax_priority");
    if (olc_db_num_rows($tax_query)) {
        $tax_multiplier = 0;
        while ($tax = olc_db_fetch_array($tax_query)) {
            $tax_multiplier += $tax['tax_rate'];
        }
        return $tax_multiplier;
    } else {
        return 0;
    }
}
function olc_get_manufacturers($manufacturers_array = '')
{
    $manufacturers_query = olc_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name");
    if (olc_db_num_rows($manufacturers_query)) {
        if (!is_array($manufacturers_array)) {
            $manufacturers_array = array();
        }
        $manufacturers_array[] = array('id' => EMPTY_STRING, 'text' => TEXT_ALL_MANUFACTURERS);
        while ($manufacturers = olc_db_fetch_array($manufacturers_query)) {
            $manufacturers_array[] = array('id' => $manufacturers['manufacturers_id'], 'text' => $manufacturers['manufacturers_name']);
        }
    }
    return $manufacturers_array;
}
function olc_get_tax_description($class_id, $country_id, $zone_id)
{
    $tax_query = olc_db_query("select tax_description from " . TABLE_TAX_RATES . " tr left join " . TABLE_ZONES_TO_GEO_ZONES . " za on (tr.tax_zone_id = za.geo_zone_id) left join " . TABLE_GEO_ZONES . " tz on (tz.geo_zone_id = tr.tax_zone_id) where (za.zone_country_id is null or za.zone_country_id = '0' or za.zone_country_id = '" . $country_id . "') and (za.zone_id is null or za.zone_id = '0' or za.zone_id = '" . $zone_id . "') and tr.tax_class_id = '" . $class_id . "' order by tr.tax_priority");
    if (olc_db_num_rows($tax_query)) {
        $tax_description = '';
        while ($tax = olc_db_fetch_array($tax_query)) {
            $tax_description .= $tax['tax_description'] . ' + ';
        }
        $tax_description = substr($tax_description, 0, -3);
        return $tax_description;
    } else {
        return TEXT_UNKNOWN_TAX_RATE;
    }
}
function olc_findTitle($current_pid, $languageFilter)
{
    $query = "SELECT * FROM " . TABLE_PRODUCTS_DESCRIPTION . " where language_id = '" . SESSION_LANGUAGE_ID . "' AND products_id = '" . $current_pid . APOS;
    $result = olc_db_query($query);
    $matches = olc_db_num_rows($result);
    if ($matches) {
        while ($line = olc_db_fetch_array($result, olc_db_ASSOC)) {
            $productName = $line['products_name'];
        }
        return $productName;
    } else {
        return "Something isn't right....";
    }
}
Example #15
0
function olc_gv_account_update($customer_id, $gv_id)
{
    $customer_gv_query = olc_db_query("select amount from " . TABLE_COUPON_GV_CUSTOMER . " where customer_id = '" . $customer_id . APOS);
    $coupon_gv_query = olc_db_query("select coupon_amount from " . TABLE_COUPONS . " where coupon_id = '" . $gv_id . APOS);
    $coupon_gv = olc_db_fetch_array($coupon_gv_query);
    if (olc_db_num_rows($customer_gv_query) > 0) {
        $customer_gv = olc_db_fetch_array($customer_gv_query);
        $new_gv_amount = $customer_gv['amount'] + $coupon_gv['coupon_amount'];
        // new code bugfix
        $gv_query = olc_db_query(SQL_UPDATE . TABLE_COUPON_GV_CUSTOMER . " set amount = '" . $new_gv_amount . "' where customer_id = '" . $customer_id . APOS);
        // original code $gv_query = olc_db_query(SQL_UPDATE . TABLE_COUPON_GV_CUSTOMER . " set amount = '" . $new_gv_amount . APOS);
    } else {
        $gv_query = olc_db_query(INSERT_INTO . TABLE_COUPON_GV_CUSTOMER . " (customer_id, amount) values ('" . $customer_id . "', '" . $coupon_gv['coupon_amount'] . "')");
    }
}
function checkAttribute($current_value_id, $current_pid, $current_product_option_id)
{
    global $attribute_value_price, $sortorder, $attribute_value_weight, $attribute_value_weight_prefix, $attribute_value_prefix, $attribute_value_model, $attribute_value_stock, $posCheck, $negCheck, $posCheck_weight, $negCheck_weight;
    $query = "SELECT * FROM " . TABLE_PRODUCTS_ATTRIBUTES . " where options_values_id = '" . $current_value_id . "' AND products_id = ' " . $current_pid . "' AND options_id = '" . $current_product_option_id . APOS;
    $result = olc_db_query($query);
    $isFound = olc_db_num_rows($result);
    if ($isFound) {
        while ($line = olc_db_fetch_array($result, olc_db_ASSOC)) {
            $attribute_value_price = $line['options_values_price'];
            $sortorder = $line['sortorder'];
            $attribute_value_prefix = $line['price_prefix'];
            $attribute_value_weight_prefix = $line['weight_prefix'];
            $attribute_value_model = $line['attributes_model'];
            $attribute_value_stock = $line['attributes_stock'];
            $attribute_value_weight = $line['options_values_weight'];
            if ($attribute_value_prefix == '+') {
                $posCheck = ' SELECTED';
                $negCheck = '';
            } else {
                $posCheck = '';
                $negCheck = ' SELECTED';
            }
            if ($attribute_value_weight_prefix == '+') {
                $posCheck_weight = ' SELECTED';
                $negCheck_weight = '';
            } else {
                $posCheck_weight = '';
                $negCheck_weight = ' SELECTED';
            }
        }
        return true;
    } else {
        $attribute_value_price = '';
        $sortorder = '';
        $attribute_value_weight = '';
        $attribute_value_prefix = '';
        $attribute_value_weight_prefix = '';
        $attribute_value_model = '';
        $attribute_value_stock = '';
        $posCheck = '';
        $negCheck = '';
        $posCheck_weight = '';
        $negCheck_weight = '';
        return false;
    }
}
Example #17
0
function olc_expire_banners()
{
    $banners_query = olc_db_query("select b.banners_id, b.expires_date, b.expires_impressions, sum(bh.banners_shown) as banners_shown from " . TABLE_BANNERS . " b, " . TABLE_BANNERS_HISTORY . " bh where b.status = '1' and b.banners_id = bh.banners_id group by b.banners_id");
    if (olc_db_num_rows($banners_query)) {
        while ($banners = olc_db_fetch_array($banners_query)) {
            if (olc_not_null($banners['expires_date'])) {
                if (date('Y-m-d H:i:s') >= $banners['expires_date']) {
                    olc_set_banner_status($banners['banners_id'], '0');
                }
            } elseif (olc_not_null($banners['expires_impressions'])) {
                if ($banners['banners_shown'] >= $banners['expires_impressions']) {
                    olc_set_banner_status($banners['banners_id'], '0');
                }
            }
        }
    }
}
function paypal_remove_order($order_id)
{
    include_once PAYPAL_IPN_DIR . 'inc.php';
    $ipn_query = olc_db_query("select payment_id from " . TABLE_ORDERS . " where orders_id = '" . (int) $order_id . APOS);
    if (olc_db_num_rows($ipn_query)) {
        // this is a ipn order (PayPal or StormPay)
        $ipn_order = olc_db_fetch_array($ipn_query);
        $paypal_id = $ipn_order['payment_id'];
        $txn_query = olc_db_query("select txn_id from " . TABLE_PAYPAL . " where paypal_id ='" . (int) $paypal_id . APOS);
        $txn = olc_db_fetch_array($txn_query);
        olc_db_query(DELETE_FROM . TABLE_PAYPAL . " where paypal_id = '" . (int) $paypal_id . APOS);
        olc_db_query(DELETE_FROM . TABLE_PAYPAL . " where parent_txn_id = '" . olc_db_input($txn['txn_id']) . APOS);
        if (defined('TABLE_PAYPAL_AUCTION')) {
            olc_db_query(DELETE_FROM . TABLE_PAYPAL_AUCTION . " where paypal_id = '" . (int) $paypal_id . APOS);
        }
    }
    olc_db_query(DELETE_FROM . TABLE_ORDERS_SESSION_INFO . " where orders_id = '" . (int) $order_id . APOS);
}
Example #19
0
function olc_get_product_path($products_id)
{
    $cPath = EMPTY_STRING;
    $category_query = olc_db_query("\n\tselect\n\tp2c.categories_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c\n\twhere\n\tp.products_id = '" . (int) $products_id . "' and\n\tp.products_status = '1' and\n\tp.products_id = p2c.products_id\n\tlimit 1");
    if (olc_db_num_rows($category_query)) {
        $category = olc_db_fetch_array($category_query);
        $categories_id = $category['categories_id'];
        $categories = array();
        olc_get_parent_categories($categories, $categories_id);
        $categories = array_reverse($categories);
        $cPath = implode(UNDERSCORE, $categories);
        if ($cPath) {
            $cPath .= UNDERSCORE;
        }
        $cPath .= $categories_id;
    }
    return $cPath;
}
function olc_get_tax_rate_export($class_id, $country_id = -1, $zone_id = -1)
{
    global $currency;
    // calculate currencies
    if ($country_id == -1 && $zone_id == -1) {
        $country_id = STORE_COUNTRY;
        $zone_id = STORE_ZONE;
    }
    $tax_query = olc_db_query("select sum(tax_rate) as tax_rate from " . TABLE_TAX_RATES . " tr left join " . TABLE_ZONES_TO_GEO_ZONES . " za on (tr.tax_zone_id = za.geo_zone_id) left join " . TABLE_GEO_ZONES . " tz on (tz.geo_zone_id = tr.tax_zone_id) where (za.zone_country_id is null or za.zone_country_id = '0' or za.zone_country_id = '" . $country_id . "') and (za.zone_id is null or za.zone_id = '0' or za.zone_id = '" . $zone_id . "') and tr.tax_class_id = '" . $class_id . "' group by tr.tax_priority");
    if (olc_db_num_rows($tax_query)) {
        $tax_multiplier = 1.0;
        while ($tax = olc_db_fetch_array($tax_query)) {
            $tax_multiplier *= 1.0 + $tax['tax_rate'] / 100;
        }
        return ($tax_multiplier - 1.0) * 100;
    } else {
        return 0;
    }
}
Example #21
0
function olc_count_products_in_category($category_id, $include_inactive = false)
{
    $products_count = 0;
    if (SHOW_COUNTS == TRUE_STRING_S) {
        if (!$include_inactive) {
            $products_status = "\n\t\tp.products_status = '1' and\n";
        }
        $products_query = olc_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c\n\t\twhere\t" . $products_status . "\n\t\tp.products_id = p2c.products_id and\n\t\tp2c.categories_id = '" . $category_id . APOS);
        $products = olc_db_fetch_array($products_query);
        $products_count += $products['total'];
        $child_categories_query = olc_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . $category_id . APOS);
        if (olc_db_num_rows($child_categories_query)) {
            while ($child_categories = olc_db_fetch_array($child_categories_query)) {
                $products_count += olc_count_products_in_category($child_categories['categories_id'], $include_inactive);
            }
        }
    }
    return $products_count;
}
Example #22
0
function create_coupon_code($salt = "secret", $length = SECURITY_CODE_LENGTH)
{
    $ccid = md5(uniqid("", "salt"));
    $ccid .= md5(uniqid("", "salt"));
    $ccid .= md5(uniqid("", "salt"));
    $ccid .= md5(uniqid("", "salt"));
    srand((double) microtime() * 1000000);
    // seed the random number generator
    $random_start = @rand(0, 128 - $length);
    $good_result = 0;
    while ($good_result == 0) {
        $id1 = substr($ccid, $random_start, $length);
        $query = olc_db_query("select coupon_code from " . TABLE_COUPONS . " where coupon_code = '" . $id1 . APOS);
        if (olc_db_num_rows($query) == 0) {
            $good_result = 1;
        }
    }
    return $id1;
}
function parse_sql_file($file_name, $is_olc_file, &$tables, &$text_array, &$insert_array, &$text_array_search, &$keys_array, &$table_charset, $default_charset, &$struct_count, &$data_count)
{
    if (defined('TABLE_PREFIX_COMMON')) {
        $error0 = 'Fehler beim Öffnen der Datei "#"!';
        $fp = @fopen($file_name, 'r');
        if ($fp) {
            $not_is_olc_file = !$is_olc_file;
            $check_charset = true;
            $not_is_olc_file && $not_is_version_5;
            $charset_len = strlen(DEFAULT_CHARSET);
            $not_found_charset = true;
            $file_offset = 0;
            $not_insert_into_found = true;
            while ($line = fgets($fp)) {
                $line = trim($line);
                $struct_count++;
                if ($line) {
                    $char1 = substr($line, 0, 1);
                    if (strpos(COMMENTS, $char1) !== false) {
                        continue;
                    } elseif (strpos($line, SEMI_COLON) !== false) {
                        if ($not_is_olc_file) {
                            if ($check_charset) {
                                $pos = strpos($line, DEFAULT_CHARSET);
                                if ($pos !== false) {
                                    $pos += $charset_len;
                                    $pos1 = strpos($line, BLANK, $pos);
                                    if ($pos1 === false) {
                                        $pos1 = strpos($line, SEMI_COLON, $pos);
                                    }
                                    $charset = strtolower(substr($line, $pos, $pos1 - $pos));
                                    $table_charset[$table_name] = $charset;
                                }
                            }
                        }
                    } else {
                        $uc_line = strtoupper($line);
                        if (strpos($uc_line, MY_INSERT_INTO) === false) {
                            if (strpos($uc_line, DROP_TABLE) === false) {
                                $pos = strpos($uc_line, CREATE_TABLE);
                                if ($pos !== false) {
                                    //Set new table name
                                    $line = rtrim(str_replace(LPAREN, EMPTY_STRING, $line));
                                    $pos = strrpos($line, BLANK);
                                    $table_name = substr($line, $pos + 1);
                                    if (REMOVE_PREFIX) {
                                        $table_name_p = $table_name;
                                        $table_name = str_replace(TABLE_PREFIX_COMMON, EMPTY_STRING, $table_name);
                                    }
                                    $table_name = strtolower(str_replace(APOS_S, EMPTY_STRING, $table_name));
                                    if ($is_olc_file) {
                                        $tables[] = $table_name;
                                        if ($check_charset) {
                                            $status_query = str_replace(HASH, $table_name_p, SHOW_TABLE_STATUS);
                                            $status = olc_db_query($status_query);
                                            if (olc_db_num_rows($status) > 0) {
                                                $status = olc_db_fetch_array($status);
                                                $charset = $status[COLLATION_FIELD];
                                                $table_charset[$table_name] = $charset;
                                            }
                                        }
                                    }
                                } else {
                                    if (strpos($line, KEY) !== false) {
                                        if ($not_is_olc_file) {
                                            $keys_array[$table_name][] = $line;
                                        }
                                    } else {
                                        //Found field, extract field name
                                        $line = str_replace(APOS_S, EMPTY_STRING, $line);
                                        if (substr($line, -1) == COMMA) {
                                            $line = substr($line, 0, strlen($line) - 1);
                                        }
                                        $line = TILDE . $line;
                                        if ($not_is_olc_file) {
                                            $text_array[] = $table_name . $line;
                                        }
                                        $pos = strpos($line, BLANK);
                                        if ($pos !== false) {
                                            $line = substr($line, 0, $pos);
                                        }
                                        $line = $table_name . $line;
                                        if ($is_olc_file) {
                                            $text_array[] = $line;
                                        } else {
                                            $text_array_search[] = $line;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    /*
                    else
                    {
                    $not_insert_into_found=false;
                    break;
                    }
                    */
                }
                //$file_offset=ftell($fp);		//Get current file pointer position
            }
            if ($is_olc_file) {
                sort($text_array);
            }
            $open_new_file = $is_olc_file || $not_insert_into_found;
            if ($open_new_file) {
                fclose($fp);
                if ($is_olc_file) {
                    $file_name = OLCOMMERCE_SQL;
                } else {
                    global $import_data_file_name;
                    $file_name = $import_data_file_name;
                }
            } else {
                fseek($fp, $file_offset);
                //reposition file to last line
            }
            //Identify/remove "INSERT INTO"s, which must not be applied from the import data!
            if ($open_new_file) {
                $fp = @fopen($file_name, 'r');
            }
            if ($fp) {
                if ($not_is_olc_file) {
                    //sort($text_array_search);
                    $data_for_table_len = strlen(DATA_FOR_TABLE);
                    $data_for_table_len_1 = strlen(DATA_FOR_TABLE_1);
                    $pos = strrpos($file_name, DOT);
                    $fp1 = substr($file_name, $pos);
                    $file_name_1 = str_replace($fp1, '_neu' . $fp1, $file_name);
                    @unlink($file_name_1);
                    $fp1 = @fopen($file_name_1, 'w');
                    if ($fp1) {
                        $insert_into_active = false;
                        fputs($fp1, NEW_LINE);
                    } else {
                        return str_replace(HASH, str_replace(ADMIN_PATH_PREFIX, EMPTY_STRING, $file_name_1), $error0);
                    }
                }
                $insert_into_len = strlen(MY_INSERT_INTO);
                while ($line = fgets($fp)) {
                    $data_count++;
                    if ($line) {
                        $pos = strpos($line, MY_INSERT_INTO);
                        $tline = trim($line);
                        if ($pos === false || $insert_into_active) {
                            if ($not_is_olc_file) {
                                if ($insert_into_active) {
                                    $insert_into_active = substr($tline, -1) != SEMI_COLON;
                                } elseif (REMOVE_PREFIX) {
                                    $pos = strpos($line, DATA_FOR_TABLE);
                                    if ($pos === false) {
                                        $pos = strpos($line, DATA_FOR_TABLE_1);
                                        $len = $data_for_table_len_1;
                                    } else {
                                        $len = $data_for_table_len;
                                    }
                                    if ($pos !== false) {
                                        $s = trim(substr($line, $pos + $len));
                                        $s1 = str_replace(APOS_S, EMPTY_STRING, $s);
                                        if (binary_search($tables, $s1)) {
                                            //Only apply prefix to tables belonging to OL-Commerce!
                                            $line = str_replace($s1, TABLE_PREFIX_COMMON . $s1, $line);
                                        }
                                    }
                                }
                                if ($not_is_in_ignore_table) {
                                    fputs($fp1, $line);
                                }
                            }
                        } else {
                            $pos += $insert_into_len;
                            $pos1 = strpos($line, BLANK, $pos);
                            $table_name = substr($line, $pos, $pos1 - $pos);
                            if ($is_olc_file) {
                                $table_name = str_replace(INSTALL_TABLE_PREFIX_COMMON, EMPTY_STRING, $table_name);
                            } else {
                                if (REMOVE_PREFIX) {
                                    $line = str_replace(TABLE_PREFIX_COMMON, EMPTY_STRING, $line);
                                }
                            }
                            $table_name = str_replace(APOS_S, EMPTY_STRING, $table_name);
                            $is_in_ignore_table = binary_search($insert_array, $table_name);
                            //in_array($table_name,$insert_array);
                            $not_is_in_ignore_table = !$is_in_ignore_table;
                            if ($not_is_olc_file) {
                                if ($is_in_ignore_table) {
                                    $not_is_in_ignore_table = strpos(ALLOW_IMPORT_TABLES, $table_name) !== false;
                                    if ($not_is_in_ignore_table) {
                                        $is_in_ignore_table = false;
                                        $s = $table_name;
                                        if (REMOVE_PREFIX) {
                                            $s = TABLE_PREFIX_COMMON . $s;
                                        }
                                        fputs($fp1, TRUNCATE_TABLE . APOS_S . $s . APOS_S . SEMI_COLON . NEW_LINE);
                                    }
                                }
                            }
                            if ($is_in_ignore_table) {
                                if ($insert_into_active) {
                                    $insert_into_active = substr($tline, -1) != SEMI_COLON;
                                }
                            } else {
                                if ($is_olc_file) {
                                    //Identify "INSERT INTO"s, which must not be applied from the import data!
                                    $insert_array[] = $table_name;
                                } else {
                                    //Modify "INSERT INTO"s!
                                    $insert_into_active = substr($tline, -1) != SEMI_COLON;
                                    $line = str_replace(MY_INSERT_INTO, INSERT_IGNORE_INTO, $line);
                                    if (REMOVE_PREFIX) {
                                        if (binary_search($tables, $table_name)) {
                                            //Only apply prefix to tables belonging to OL-Commerce!
                                            $pos = strpos($line, $table_name);
                                            $line = substr($line, 0, $pos) . TABLE_PREFIX_COMMON . substr($line, $pos);
                                        }
                                    }
                                    fputs($fp1, $line);
                                }
                            }
                        }
                    }
                }
                if ($is_olc_file) {
                    sort($insert_array);
                } else {
                    fclose($fp1);
                    $import_data_file_name = $file_name_1;
                }
                return true;
            } else {
                $show_error = true;
            }
        } else {
            $show_file_error = true;
        }
        if ($show_file_error) {
            $error = str_replace(HASH, str_replace(ADMIN_PATH_PREFIX, EMPTY_STRING, $file_name), $error0);
        }
    } else {
        $error = 'Unzulässiges System';
    }
    return $error;
}
 */
 olc_smarty_init($module_smarty, $cache_id);
 $basket_query = olc_db_query(SELECT_ALL . TABLE_CUSTOMERS_BASKET_SAVE_BASKETS . $where_cid . ' order by basket_date_added DESC');
 if (olc_db_num_rows($basket_query)) {
     require_once DIR_FS_INC . 'olc_draw_radio_field.inc.php';
     require_once DIR_FS_INC . 'olc_draw_checkbox_field.inc.php';
     require_once DIR_FS_INC . 'olc_get_prid.inc.php';
     require_once DIR_FS_INC . 'olc_get_smarty_config_variable.inc.php';
     $module_content = array();
     while ($basket = olc_db_fetch_array($basket_query)) {
         $basket_id = $basket['customers_basket_id'];
         $show_order_details = $basket_id == $bid;
         if ($show_order_details) {
             $where_bid = $sql_where . "customers_basket_id='" . $basket_id . APOS;
             $products_basket_query = olc_db_query(SELECT_ALL . TABLE_CUSTOMERS_BASKET_SAVE . $where_bid);
             if (olc_db_num_rows($products_basket_query) > 0) {
                 $products_query_sql0 = olc_standard_products_query();
                 /*
                 $products_query_sql0="
                 select
                 p.products_id,
                 pd.products_name,
                 p.products_image,
                 p.products_model,
                 p.products_price,
                 p.products_discount_allowed,
                 p.products_weight,
                 p.products_tax_class_id
                 from " .
                 TABLE_PRODUCTS . " p, " .
                 TABLE_PRODUCTS_DESCRIPTION . " pd
 function check()
 {
     if (!isset($this->_check)) {
         $check_query = olc_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_2CHECKOUT_STATUS'");
         $this->_check = olc_db_num_rows($check_query);
     }
     return $this->_check;
 }
                break;
        }
        $from_date = mktime(0, 0, 0, $month_f, $day_f, $year_f);
        $date_from = date($date_format, $from_date);
        $to_date = mktime(0, 0, 0, $month_t, $day_t, $year_t);
        $date_to = date($date_format, $to_date);
        if ($show_add_data) {
            $text .= $lparen . strftime($date_format_text, $from_date) . $rparen;
        }
        if ($show_date_range) {
            $text .= HTML_BR . ltrim($lparen . strftime($date_format_1, $from_date)) . $sep . ltrim(strftime($date_format_1, $to_date)) . $rparen;
        }
        $conv_query = str_replace($param1, $date_from, $conv_query_raw);
        $conv_query = str_replace($param2, $date_to, $conv_query);
        $conv_query = olc_db_query($conv_query);
        if (olc_db_num_rows($conv_query)) {
            $have_no_entry = true;
            $current_content .= '
  <tr>
' . str_replace(HASH, $text, $line);
            while ($conv = olc_db_fetch_array($conv_query)) {
                $count = $conv[$count_text];
                if ($count) {
                    $have_no_entry = false;
                    $current_content .= str_replace(HASH, olc_format_price($conv[$value_text], 1, 1), $line_right) . str_replace(HASH, olc_format_price($conv[$avg_text], 1, 1), $line_right) . str_replace(HASH, $count, $line_right);
                } else {
                    break;
                }
            }
            if ($have_no_entry) {
                $current_content .= $no_entry_line;
     $where_str .= $sql_and . "<= " . $pto_to_check / CURRENCY_VALUE . RPAREN;
 }
 $order_str = ' group by pd.products_name order by pd.products_name';
 $products_listing_sql_main = $select_str . $from_str . $where_str . $order_str;
 if (defined("MODULE_TAG_CLOUD_STATUS") && MODULE_TAG_CLOUD_STATUS == TRUE_STRING_L && !olc_not_null($_GET['categories_id']) && !olc_not_null($_GET['manufacturers_id']) && !strlen($_GET['pfrom']) && !strlen($_GET['pto']) && ($cloudTag = $keywords) != EMPTY_STRING) {
     $s = 'tag_cloud_tags';
     if (!isset($_SESSION[$s])) {
         $_SESSION[$s] = array();
     }
     $cloudTag = substr($cloudTag, 0, 64);
     if (!in_array($cloudTag, $_SESSION[$s])) {
         $_SESSION[$s][] = $cloudTag;
         $cloudTag = addslashes($cloudTag);
         $cloudLang = SESSION_LANGUAGE_ID;
         $tagTest = olc_db_fetch_array(olc_db_query(SELECT_COUNT . "AS count " . "FROM \n\t\t\t\tmodule_tag_cloud " . "WHERE \n\t\t\t\ttag = '" . $cloudTag . "' AND language_id = " . $cloudLang));
         $prodTest = olc_db_num_rows(olc_db_query("SELECT 1 " . $from_str . $where_str . " LIMIT 1"));
         if ($prodTest) {
             if (!isset($_GET["searchTagCloud"])) {
                 if ($tagTest["count"]) {
                     olc_db_query("UPDATE module_tag_cloud " . "SET searches = searches + 1, not_found = 0 " . "WHERE tag = '" . $cloudTag . "' AND language_id = " . $cloudLang);
                 } else {
                     $cloudInfos = olc_db_fetch_array(olc_db_query("SELECT AVG(searches + offset) AS offset " . "FROM module_tag_cloud " . "WHERE language_id = " . $cloudLang));
                     $minSearches = (int) MODULE_TAG_CLOUD_MIN_SEARCHES;
                     if ($minSearches < 1) {
                         $minSearches = 1;
                     }
                     olc_db_query("INSERT INTO module_tag_cloud " . "SET " . "tag = '" . $cloudTag . "'," . (isset($cloudInfos["offset"]) ? "offset = " . round($cloudInfos["offset"] - 1) . "," : "") . "language_id = " . $cloudLang . "," . "inserted = NOW()");
                     $deleteQuery = olc_db_query("SELECT tag " . "FROM module_tag_cloud " . "WHERE language_id = " . $cloudLang . " " . "ORDER BY searches + offset DESC, inserted DESC " . "LIMIT " . (int) MODULE_TAG_CLOUD_MAX_TAGS . ", 1000");
                     while ($delTag = olc_db_fetch_array($deleteQuery)) {
                         olc_db_query("DELETE FROM module_tag_cloud " . "WHERE tag = '" . addslashes($delTag["tag"]) . "' AND language_id = " . $cloudLang);
                     }
</td>
                <td class="dataTableContent"><?php 
    if (eregi('^(.*)' . olc_session_name() . '=[a-f,0-9]+[&]*(.*)', $whos_online['last_page_url'], $array)) {
        echo $array[1] . $array[2];
    } else {
        echo $whos_online['last_page_url'];
    }
    ?>
&nbsp;</td>
              </tr>
<?php 
}
?>
              <tr>
                <td class="smallText" colspan="7"><?php 
echo sprintf(TEXT_NUMBER_OF_CUSTOMERS, olc_db_num_rows($whos_online_query));
?>
</td>
              </tr>
            </table></td>
<?php 
$heading = array();
$contents = array();
if ($info) {
    $heading[] = array('text' => HTML_B_START . TABLE_HEADING_SHOPPING_CART . HTML_B_END);
    if (STORE_SESSIONS == 'mysql') {
        $session_data = olc_db_query("select value from " . TABLE_SESSIONS . " WHERE sesskey = '" . $info . APOS);
        $session_data = olc_db_fetch_array($session_data);
        $session_data = trim($session_data['value']);
    } else {
        if (file_exists(olc_session_save_path() . '/sess_' . $info) && filesize(olc_session_save_path() . '/sess_' . $info) > 0) {
function general_db_conct($query_1)
{
    $result_1 = olc_db_query($query_1);
    $num_of_rows = olc_db_num_rows($result_1);
    for ($i = 0; $i < $num_of_rows; $i++) {
        $fields = olc_db_fetch_row($result_1);
        $a_to_pass[$i] = $fields[$y = 0];
        $b_to_pass[$i] = $fields[++$y];
        $c_to_pass[$i] = $fields[++$y];
        $d_to_pass[$i] = $fields[++$y];
        $e_to_pass[$i] = $fields[++$y];
        $f_to_pass[$i] = $fields[++$y];
        $g_to_pass[$i] = $fields[++$y];
        $h_to_pass[$i] = $fields[++$y];
        $i_to_pass[$i] = $fields[++$y];
        $j_to_pass[$i] = $fields[++$y];
        $k_to_pass[$i] = $fields[++$y];
        $l_to_pass[$i] = $fields[++$y];
        $m_to_pass[$i] = $fields[++$y];
        $n_to_pass[$i] = $fields[++$y];
        $o_to_pass[$i] = $fields[++$y];
    }
    return array($a_to_pass, $b_to_pass, $c_to_pass, $d_to_pass, $e_to_pass, $f_to_pass, $g_to_pass, $h_to_pass, $i_to_pass, $j_to_pass, $k_to_pass, $l_to_pass, $m_to_pass, $n_to_pass, $o_to_pass);
}
&nbsp;</td>
              </tr>
<?php 
        }
        ?>
             </table></td>
<?php 
        $heading = array();
        $contents = array();
        $coupon_description_query = olc_db_query("select coupon_name from " . TABLE_COUPONS_DESCRIPTION . " where coupon_id = '" . $_GET['cid'] . "' and language_id = '" . SESSION_LANGUAGE_ID . APOS);
        $coupon_desc = olc_db_fetch_array($coupon_description_query);
        $count_customers = olc_db_query("select * from " . TABLE_COUPON_REDEEM_TRACK . " where coupon_id = '" . $_GET['cid'] . "' and customer_id = '" . $cInfo->customer_id . APOS);
        $heading[] = array('text' => '<b>[' . $_GET['cid'] . ']' . COUPON_NAME . BLANK . $coupon_desc['coupon_name'] . HTML_B_END);
        $contents[] = array('text' => HTML_B_START . TEXT_REDEMPTIONS . HTML_B_END);
        $contents[] = array('text' => TEXT_REDEMPTIONS_TOTAL . '=' . olc_db_num_rows($cc_query));
        $contents[] = array('text' => TEXT_REDEMPTIONS_CUSTOMER . '=' . olc_db_num_rows($count_customers));
        $contents[] = array('text' => '');
        ?>
    <td width="25%" valign="top">
<?php 
        $box = new box();
        echo $box->infoBox($heading, $contents);
        echo '            </td>' . NEW_LINE;
        break;
    case 'preview_email':
        $coupon_query = olc_db_query("select coupon_code from " . TABLE_COUPONS . " where coupon_id = '" . $_GET['cid'] . APOS);
        $coupon_result = olc_db_fetch_array($coupon_query);
        $coupon_name_query = olc_db_query("select coupon_name from " . TABLE_COUPONS_DESCRIPTION . " where coupon_id = '" . $_GET['cid'] . "' and language_id = '" . SESSION_LANGUAGE_ID . APOS);
        $coupon_name = olc_db_fetch_array($coupon_name_query);
        switch ($_POST['customers_email_address']) {
            case '***':