function olc_address_label($customers_id, $address_id = 1, $html = false, $boln = '', $eoln = NEW_LINE)
{
    $address_query = olc_db_query("\n\t\tselect\n\t\tentry_firstname as firstname,\n\t\tentry_lastname as lastname,\n\t\tentry_company as company,\n\t\tentry_street_address as street_address,\n\t\tentry_suburb as suburb,\n\t\tentry_city as city,\n\t\tentry_postcode as postcode,\n\t\tentry_state as state,\n\t\tentry_zone_id as zone_id,\n\t\tentry_country_id as country_id\n\t\tfrom " . TABLE_ADDRESS_BOOK . "\n\t\twhere customers_id = '" . $customers_id . "' and address_book_id = '" . $address_id . APOS);
    $address = olc_db_fetch_array($address_query);
    $format_id = olc_get_address_format_id($address['country_id']);
    return olc_address_format($format_id, $address, $html, $boln, $eoln);
}
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_get_path($current_category_id = EMPTY_STRING)
{
    global $cPath_array;
    if (olc_not_null($current_category_id)) {
        $cp_size = sizeof($cPath_array);
        if ($cp_size == 0) {
            $cPath_new = $current_category_id;
        } else {
            $cPath_new = EMPTY_STRING;
            $sql0 = "select parent_id from " . TABLE_CATEGORIES . " where categories_id = '#'";
            $sql = str_replace(HASH, $cPath_array[$cp_size - 1], $sql0);
            $last_category_query = olc_db_query($sql);
            $last_category = olc_db_fetch_array($last_category_query);
            $sql = str_replace(HASH, $current_category_id, $sql0);
            $current_category_query = olc_db_query($sql);
            $current_category = olc_db_fetch_array($current_category_query);
            if ($last_category['parent_id'] == $current_category['parent_id']) {
                for ($i = 0, $n = $cp_size - 1; $i < $n; $i++) {
                    $cPath_new .= UNDERSCORE . $cPath_array[$i];
                }
            } else {
                for ($i = 0; $i < $cp_size; $i++) {
                    $cPath_new .= UNDERSCORE . $cPath_array[$i];
                }
            }
            $cPath_new .= UNDERSCORE . $current_category_id;
            if (substr($cPath_new, 0, 1) == UNDERSCORE) {
                $cPath_new = substr($cPath_new, 1);
            }
        }
    } else {
        $cPath_new = implode(UNDERSCORE, $cPath_array);
    }
    return 'cPath=' . $cPath_new;
}
function olc_get_categoriesstatus_for_product($product_id)
{
    $categorie_query = olc_db_query("\n\tSELECT\n\tcategories_id\n\tFROM " . TABLE_PRODUCTS_TO_CATEGORIES . "\n\tWHERE products_id=" . $product_id);
    while ($categorie_data = olc_db_fetch_array($categorie_query)) {
        return olc_check_categories_status($categorie_data['categories_id']) >= 1;
    }
}
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 olc_get_download($content_id)
{
    $content_query = olc_db_query("SELECT\n\t\t\t\t\tcontent_file,\n\t\t\t\t\tcontent_read\n\t\t\t\t\tFROM " . TABLE_PRODUCTS_CONTENT . "\n\t\t\t\t\tWHERE content_id='" . $content_id . APOS);
    $content_data = olc_db_fetch_array($content_query);
    // update file counter
    olc_db_query("SQL_UPDATE \n\t\t\t" . TABLE_PRODUCTS_CONTENT . " \n\t\t\tSET content_read='" . ($content_data['content_read'] + 1) . "'\n\t\t\tWHERE content_id='" . $content_id . APOS);
    // original filename
    $filename = DIR_FS_CATALOG . 'media/products/' . $content_data['content_file'];
    $backup_filename = DIR_FS_CATALOG . 'media/products/backup/' . $content_data['content_file'];
    // create md5 hash id from original file
    $orign_hash_id = md5_file($filename);
    clearstatcache();
    // create new filename with timestamp
    $timestamp = str_replace('.', '', microtime());
    $timestamp = str_replace(BLANK, '', $timestamp);
    $new_filename = DIR_FS_CATALOG . 'media/products/' . $timestamp . strstr($content_data['content_file'], '.');
    // rename file
    rename($filename, $new_filename);
    if (file_exists($new_filename)) {
        header("Content-type: application/force-download");
        header("Content-Disposition: attachment; filename=" . $new_filename);
        @readfile($new_filename);
        // rename file to original name
        rename($new_filename, $filename);
        $new_hash_id = md5_file($filename);
        clearstatcache();
        // check hash id of file again, if not same, get backup!
        if ($new_hash_id != $orign_hash_id) {
            copy($backup_filename, $filename);
        }
    }
}
function get_category_tree($parent_id = '0', $spacing = EMPTY_STRING, $exclude = EMPTY_STRING, $category_tree_array = EMPTY_STRING, $include_itself = false, $cPath = EMPTY_STRING)
{
    if ($parent_id == 0) {
        $cPath = EMPTY_STRING;
    } else {
        $cPath .= $parent_id . '_';
    }
    if (!is_array($category_tree_array)) {
        $category_tree_array = array();
    }
    if (sizeof($category_tree_array) < 1 && $exclude != '0') {
        $category_tree_array[] = array('id' => '0', 'text' => TEXT_TOP);
    }
    if ($include_itself) {
        $category_query = olc_db_query("\n\t\t\tselect cd.categories_name\n\t\t\tfrom " . TABLE_CATEGORIES_DESCRIPTION . " cd\n\t\t\tWHERE c.categories_status = '1' AND cd.language_id = '" . SESSION_LANGUAGE_ID . "'\n\t\t\tand cd.categories_id = '" . $parent_id . APOS);
        $category = olc_db_fetch_array($category_query);
        $category_tree_array[] = array('id' => $parent_id, 'text' => $category['categories_name']);
    }
    $categories_query = olc_db_query("\n\t\tselect\n\t\tc.categories_id,\n\t\tcd.categories_name,\n\t\tc.parent_id\n\t\tfrom " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd\n\t\twhere c.categories_id = cd.categories_id\n\t\tand cd.language_id = '" . SESSION_LANGUAGE_ID . "'\n\t\tand c.parent_id = '" . $parent_id . "'\n\t\tand c.categories_status = '1'\n\t\torder by c.sort_order, cd.categories_name");
    while ($categories = olc_db_fetch_array($categories_query)) {
        $categories_id = $categories['categories_id'];
        if ($exclude != $categories_id) {
            $category_tree_array[] = array('id' => $categories_id, 'text' => $spacing . $categories['categories_name'], 'link' => olc_href_link(FILENAME_DEFAULT, 'cPath=' . $cPath . $categories_id, NONSSL, false, true, false), 'pcount' => olc_count_products_in_category($categories_id));
            $category_tree_array = get_category_tree($categories_id, $spacing . '&nbsp;&nbsp;&nbsp;', $exclude, $category_tree_array, false, $cPath);
        }
    }
    return $category_tree_array;
}
function affiliate_insert($sql_data_array, $affiliate_parent = 0)
{
    // LOCK TABLES
    //   olc_db_query("LOCK TABLES " . TABLE_AFFILIATE . " WRITE");
    if ($affiliate_parent > 0) {
        $affiliate_root_query = olc_db_query("select affiliate_root, affiliate_rgt, affiliate_lft�from  " . TABLE_AFFILIATE . " where affiliate_id = '" . $affiliate_parent . "' ");
        // Check if we have a parent affiliate
        if ($affiliate_root_array = olc_db_fetch_array($affiliate_root_query)) {
            olc_db_query(SQL_UPDATE . TABLE_AFFILIATE . " SET affiliate_lft = affiliate_lft + 2 WHERE affiliate_root  =  '" . $affiliate_root_array['affiliate_root'] . "' and  affiliate_lft > " . $affiliate_root_array['affiliate_rgt'] . "  AND affiliate_rgt >= " . $affiliate_root_array['affiliate_rgt'] . BLANK);
            olc_db_query(SQL_UPDATE . TABLE_AFFILIATE . " SET affiliate_rgt = affiliate_rgt + 2 WHERE affiliate_root  =  '" . $affiliate_root_array['affiliate_root'] . "' and  affiliate_rgt >= " . $affiliate_root_array['affiliate_rgt'] . "  ");
            $sql_data_array['affiliate_root'] = $affiliate_root_array['affiliate_root'];
            $sql_data_array['affiliate_lft'] = $affiliate_root_array['affiliate_rgt'];
            $sql_data_array['affiliate_rgt'] = $affiliate_root_array['affiliate_rgt'] + 1;
            olc_db_perform(TABLE_AFFILIATE, $sql_data_array);
            $affiliate_id = olc_db_insert_id();
        }
        // no parent -> new root
    } else {
        $sql_data_array['affiliate_lft'] = '1';
        $sql_data_array['affiliate_rgt'] = '2';
        olc_db_perform(TABLE_AFFILIATE, $sql_data_array);
        $affiliate_id = olc_db_insert_id();
        olc_db_query(SQL_UPDATE . TABLE_AFFILIATE . " set affiliate_root = '" . $affiliate_id . "' where affiliate_id = '" . $affiliate_id . "' ");
    }
    // UNLOCK TABLES
    olc_db_query("UNLOCK TABLES");
    return $affiliate_id;
}
 function table()
 {
     global $order;
     if (!$order) {
         include_once ADMIN_PATH_PREFIX . DIR_WS_CLASSES . 'order.php';
         $order = new order();
     }
     $order_delivery_country = $order->delivery['country'];
     $this->code = 'table';
     $this->title = MODULE_SHIPPING_TABLE_TEXT_TITLE;
     $this->description = MODULE_SHIPPING_TABLE_TEXT_DESCRIPTION;
     $this->sort_order = MODULE_SHIPPING_TABLE_SORT_ORDER;
     $this->icon = '';
     $this->tax_class = MODULE_SHIPPING_TABLE_TAX_CLASS;
     $this->enabled = strtolower(MODULE_SHIPPING_TABLE_STATUS) == TRUE_STRING_S ? true : false;
     if ($this->enabled == true && (int) MODULE_SHIPPING_TABLE_ZONE > 0) {
         $check_flag = false;
         $check_query = olc_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . "\n\t\t\twhere geo_zone_id = '" . MODULE_SHIPPING_TABLE_ZONE . "'\n\t\t\tand zone_country_id = '" . $order_delivery_country['id'] . "' order by zone_id");
         while ($check = olc_db_fetch_array($check_query)) {
             if ($check['zone_id'] < 1) {
                 $check_flag = true;
                 break;
             } elseif ($check['zone_id'] == $order->delivery['zone_id']) {
                 $check_flag = true;
                 break;
             }
         }
         if ($check_flag == false) {
             $this->enabled = false;
         }
     }
 }
 function update_status()
 {
     global $order;
     $customer_id = $_SESSION['customer_id'];
     $check_order_query = olc_db_query("select orders_id from " . TABLE_ORDERS . " where customers_id = '" . $customer_id . APOS);
     $order_check = olc_db_num_rows($check_order_query);
     if ($order_check >= MODULE_PAYMENT_INVOICE_MIN_ORDER) {
         $check_flag = false;
     } else {
         if ($this->enabled == true && (int) MODULE_PAYMENT_INVOICE_ZONE > 0) {
             $check_flag = false;
             $check_query = olc_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_INVOICE_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
             while ($check = olc_db_fetch_array($check_query)) {
                 if ($check['zone_id'] < 1) {
                     $check_flag = true;
                     break;
                 } elseif ($check['zone_id'] == $order->delivery['zone_id']) {
                     $check_flag = true;
                     break;
                 }
             }
         }
         if ($check_flag == false) {
             $this->enabled = false;
         }
     }
     if ($this->enabled == true) {
         if ($order->content_type == 'virtual') {
             $this->enabled = false;
         }
     }
 }
function olc_get_products_special_price($product_id)
{
    global $special_info;
    $product_query = olc_db_query("select specials_new_products_price, expires_date from " . TABLE_SPECIALS . " where products_id = '" . $product_id . "' and status");
    $special_info = olc_db_fetch_array($product_query);
    return $special_info['specials_new_products_price'];
}
function olc_get_countries($countries_id = '', $with_iso_codes = false)
{
    $countries_id_text = 'countries_id';
    $countries_name_text = 'countries_name';
    $select = "select countries_name";
    $select_countries_id = $select . ", " . $countries_id_text;
    $from = " from " . TABLE_COUNTRIES;
    $countries_array = array();
    if (olc_not_null($countries_id)) {
        $where = $from . " where countries_id = '" . $countries_id . APOS;
        if ($with_iso_codes) {
            $countries_iso_code_text = 'countries_iso_code_';
            $countries_iso_code_2_text = $countries_iso_code_text . '2';
            $countries_iso_code_3_text = $countries_iso_code_text . '3';
            $countries = olc_db_query($select_countries_id . ", " . $countries_iso_code_2_text . $where);
            $countries_values = olc_db_fetch_array($countries);
            $countries_array = array($countries_name_text => $countries_values[$countries_name_text], $countries_iso_code_2_text => $countries_values[$countries_iso_code_2_text], $countries_iso_code_3_text => $countries_values[$countries_iso_code_3_text]);
        } else {
            $countries = olc_db_query($select . $where);
            $countries_values = olc_db_fetch_array($countries);
            $countries_array = array($countries_name_text => $countries_values[$countries_name_text]);
        }
    } else {
        $countries = olc_db_query($select_countries_id . $from . " order by " . $countries_name_text);
        while ($countries_values = olc_db_fetch_array($countries)) {
            $countries_array[] = array($countries_id_text => $countries_values[$countries_id_text], $countries_name_text => $countries_values[$countries_name_text]);
        }
    }
    return $countries_array;
}
function olc_get_vpe_name($vpeID)
{
    $vpe_query = "SELECT products_vpe_name FROM " . TABLE_PRODUCTS_VPE . " WHERE language_id='" . SESSION_LANGUAGE_ID . "' and products_vpe_id='" . $vpeID . APOS;
    $vpe_query = olc_db_query($vpe_query);
    $vpe = olc_db_fetch_array($vpe_query);
    return $vpe['products_vpe_name'];
}
 function update_status()
 {
     global $order;
     if ($this->enabled == true && (int) MODULE_PAYMENT_BARZAHL_ZONE > 0) {
         $check_flag = false;
         $check_query = olc_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_BARZAHL_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
         while ($check = olc_db_fetch_array($check_query)) {
             if ($check['zone_id'] < 1) {
                 $check_flag = true;
                 break;
             } elseif ($check['zone_id'] == $order->delivery['zone_id']) {
                 $check_flag = true;
                 break;
             }
         }
         if ($check_flag == false) {
             $this->enabled = false;
         }
     }
     if ($this->enabled == true) {
         if ($order->content_type == 'virtual') {
             $this->enabled = false;
         }
     }
 }
function olc_get_products_stock($products_id)
{
    $products_id = olc_get_prid($products_id);
    $stock_query = olc_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . $products_id . APOS);
    $stock_values = olc_db_fetch_array($stock_query);
    return $stock_values['products_quantity'];
}
 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 splitPageResults(&$current_page_number, $max_rows_per_page, &$sql_query, &$query_num_rows)
 {
     if (empty($current_page_number)) {
         $current_page_number = 1;
     }
     $pos_to = strlen($sql_query);
     $pos_from = strpos($sql_query, ' from', 0);
     $pos_group_by = strpos($sql_query, ' group by', $pos_from);
     if ($pos_group_by < $pos_to && $pos_group_by != false) {
         $pos_to = $pos_group_by;
     }
     $pos_having = strpos($sql_query, ' having', $pos_from);
     if ($pos_having < $pos_to && $pos_having != false) {
         $pos_to = $pos_having;
     }
     $pos_order_by = strpos($sql_query, ' order by', $pos_from);
     if ($pos_order_by < $pos_to && $pos_order_by != false) {
         $pos_to = $pos_order_by;
     }
     $reviews_count_query = olc_db_query("select count(*) as total " . substr($sql_query, $pos_from, $pos_to - $pos_from));
     $reviews_count = olc_db_fetch_array($reviews_count_query);
     $query_num_rows = $reviews_count['total'];
     $num_pages = ceil($query_num_rows / $max_rows_per_page);
     if ($current_page_number > $num_pages) {
         $current_page_number = $num_pages;
     }
     $offset = $max_rows_per_page * ($current_page_number - 1);
     if ($offset < 0) {
         $offset = 0;
     }
     $sql_query .= " limit " . $offset . ", " . $max_rows_per_page;
 }
 function dp()
 {
     if (!$order) {
         include_once ADMIN_PATH_PREFIX . DIR_WS_CLASSES . 'order.php';
         $order = new order();
     }
     $order_delivery_country = $order->delivery['country'];
     $this->code = 'dp';
     $this->title = MODULE_SHIPPING_DP_TEXT_TITLE;
     $this->description = MODULE_SHIPPING_DP_TEXT_DESCRIPTION;
     $this->sort_order = MODULE_SHIPPING_DP_SORT_ORDER;
     $this->icon = DIR_WS_ICONS . 'shipping_dp.gif';
     $this->tax_class = MODULE_SHIPPING_DP_TAX_CLASS;
     $this->enabled = strtolower(MODULE_SHIPPING_DP_STATUS) == TRUE_STRING_S ? true : false;
     if ($this->enabled == true && (int) MODULE_SHIPPING_DP_ZONE > 0) {
         $check_flag = false;
         $check_query = olc_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_DP_ZONE . "' and zone_country_id = '" . $order_delivery_country['id'] . "' order by zone_id");
         while ($check = olc_db_fetch_array($check_query)) {
             if ($check['zone_id'] < 1) {
                 $check_flag = true;
                 break;
             } elseif ($check['zone_id'] == $order->delivery['zone_id']) {
                 $check_flag = true;
                 break;
             }
         }
         if ($check_flag == false) {
             $this->enabled = false;
         }
     }
     /**
      * CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED
      */
     $this->num_dp = 6;
 }
 function get_order_total()
 {
     global $order, $cart;
     $order_total = $order->info['total'];
     // Check if gift voucher is in cart and adjust total
     $products = $cart->get_products();
     for ($i = 0; $i < sizeof($products); $i++) {
         $t_prid = olc_get_prid($products[$i]['id']);
         $gv_query = olc_db_query("select products_price, products_tax_class_id, products_model from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . APOS);
         $gv_result = olc_db_fetch_array($gv_query);
         if (ereg('^GIFT', addslashes($gv_result['products_model']))) {
             $qty = $cart->get_quantity($t_prid);
             $products_tax = olc_get_tax_rate($gv_result['products_tax_class_id']);
             if ($this->include_tax == FALSE_STRING_S) {
                 $gv_amount = $gv_result['products_price'] * $qty;
             } else {
                 $gv_amount = ($gv_result['products_price'] + olc_calculate_tax($gv_result['products_price'], $products_tax)) * $qty;
             }
             $order_total = $order_total - $gv_amount;
         }
     }
     if ($this->include_tax == FALSE_STRING_S) {
         $order_total = $order_total - $order->info['tax'];
     }
     if ($this->include_shipping == FALSE_STRING_S) {
         $order_total = $order_total - $order->info['shipping_cost'];
     }
     return $order_total;
 }
function olc_oe_get_allow_tax($customers_id)
{
    $customer_query = olc_db_query("select customers_status from " . TABLE_CUSTOMERS . " where customers_id  = '" . $customers_id . APOS);
    $customer = olc_db_fetch_array($customer_query);
    $allow_query = olc_db_query("select customers_status_show_price_tax from " . TABLE_CUSTOMERS_STATUS . " where customers_status_id  = '" . $customer['customers_status'] . APOS);
    $allow = olc_db_fetch_array($allow_query);
    return $allow['customers_status_show_price_tax'];
}
function olc_get_shipping_status_name($shipping_status_id)
{
    $status_query = olc_db_query("SELECT\n   shipping_status_name,\n   shipping_status_image\n   FROM " . TABLE_SHIPPING_STATUS . "\n   where shipping_status_id = '" . $shipping_status_id . "'\n   and language_id = '" . SESSION_LANGUAGE_ID . APOS);
    $status_data = olc_db_fetch_array($status_query);
    $shipping_statuses = array();
    $shipping_status = array('name' => $status_data['shipping_status_name'], 'image' => $status_data['shipping_status_image']);
    return $shipping_status;
}
 function currencies()
 {
     $this->currencies = array();
     $currencies_query = olc_db_query("select code, title, symbol_left, symbol_right, decimal_point, thousands_point, decimal_places, value from " . TABLE_CURRENCIES);
     while ($currencies = olc_db_fetch_array($currencies_query)) {
         $this->currencies[$currencies['code']] = array('title' => $currencies['title'], 'symbol_left' => $currencies['symbol_left'], 'symbol_right' => $currencies['symbol_right'], 'decimal_point' => $currencies['decimal_point'], 'thousands_point' => $currencies['thousands_point'], 'decimal_places' => $currencies['decimal_places'], 'value' => $currencies['value']);
     }
 }
function olc_update_whos_online($url = EMPTY_STRING)
{
    if (ISSET_CUSTOMER_ID) {
        $wo_customer_id = CUSTOMER_ID;
        $customer_query = olc_db_query(SELECT . "customers_firstname, customers_lastname from " . TABLE_CUSTOMERS . " where customers_id = '" . $_SESSION['customer_id'] . APOS);
        $customer = olc_db_fetch_array($customer_query);
        $wo_full_name = addslashes($customer['customers_firstname'] . BLANK . $customer['customers_lastname']);
    } else {
        $wo_full_name = $_SESSION['customers_status']['customers_status_name'];
        $wo_customer_id = 0;
    }
    $wo_session_id = olc_session_id();
    //$wo_ip_address = getenv('REMOTE_ADDR');
    olc_get_ip_info(&$smarty);
    $wo_ip_address = $_SESSION['CUSTOMERS_IP'];
    $pos = strpos($wo_ip_address, RPAREN);
    if ($pos !== false) {
        $wo_ip_address = substr($wo_ip_address, 0, $pos + 1);
    }
    if (!$url) {
        $url = addslashes(getenv('REQUEST_URI'));
    }
    $wo_last_page_url = str_replace(DIR_WS_CATALOG, EMPTY_STRING, $url);
    $pos = strpos($wo_last_page_url, 'start_debug');
    //Eliminate debugger parameters
    if ($pos === false) {
        $pos = strpos($wo_last_page_url, 'DBGSESSION');
        //Eliminate debugger parameters
    }
    if ($pos !== false) {
        $wo_last_page_url = substr($wo_last_page_url, 0, $pos - 1);
    }
    if (USE_AJAX) {
        $pos = strpos($wo_last_page_url, AJAX_ID);
        if ($pos !== false) {
            $wo_last_page_url = substr($wo_last_page_url, 0, $pos - 1) . substr($wo_last_page_url, $pos + strlen(AJAX_ID));
        }
    }
    $current_time = time();
    //Do garbage collection in session db
    _sess_gc(EMPTY_STRING);
    //Delete all from "whos_online" without a session entry
    //olc_db_query(DELETE_FROM . TABLE_WHOS_ONLINE. ' WHERE session_id NOT IN (SELECT sesskey FROM '.TABLE_SESSIONS.RPAREN);
    $sesskey = TABLE_SESSIONS . '.sesskey';
    olc_db_query('DELETE ' . TABLE_WHOS_ONLINE . '  FROM ' . TABLE_WHOS_ONLINE . COMMA_BLANK . TABLE_SESSIONS . ' WHERE ' . TABLE_WHOS_ONLINE . '.session_id = ' . $sesskey . ' AND ' . $sesskey . ' IS NULL');
    $sql_data = array('customer_id' => $wo_customer_id, 'full_name' => $wo_full_name, 'session_id' => $wo_session_id, 'time_last_click' => $current_time, 'last_page_url' => $wo_last_page_url);
    $sql_where = "session_id = '" . $wo_session_id . APOS;
    $stored_customer_query = olc_db_query("select count(*) as count from " . TABLE_WHOS_ONLINE . " where " . $sql_where);
    $stored_customer = olc_db_fetch_array($stored_customer_query);
    if ($stored_customer['count'] > 0) {
        $sql_action = 'update';
    } else {
        $sql_data = array_merge($sql_data, array('ip_address' => $wo_ip_address, 'time_entry' => $current_time));
        $sql_action = 'insert';
        $sql_where = EMPTY_STRING;
    }
    olc_db_perform(TABLE_WHOS_ONLINE, $sql_data, $sql_action, $sql_where);
}
function olc_oe_get_options_values_name($products_options_values_id, $language = '')
{
    if (empty($language)) {
        $language = SESSION_LANGUAGE_ID;
    }
    $product_query = olc_db_query("select products_options_values_name from " . TABLE_PRODUCTS_OPTIONS_VALUES . " where products_options_values_id = '" . $products_options_values_id . "' and language_id = '" . $language . APOS);
    $product = olc_db_fetch_array($product_query);
    return $product['products_options_values_name'];
}
function olc_get_short_description($product_id, $language = '')
{
    if (empty($language)) {
        $language = SESSION_LANGUAGE_ID;
    }
    $product_query = olc_db_query("select products_short_description from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . $product_id . "' and language_id = '" . $language . APOS);
    $product = olc_db_fetch_array($product_query);
    return $product['products_short_description'];
}
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_get_products_mo_images($products_id = '')
{
    $mo_query = "select image_id, image_nr, image_name from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . $products_id . "' ORDER BY image_nr";
    $products_mo_images_query = olc_db_query($mo_query);
    while ($row = olc_db_fetch_array($products_mo_images_query)) {
        $results[$row['image_nr'] - 1] = $row;
    }
    return $results;
}
 function main()
 {
     $this->SHIPPING = array();
     // prefetch shipping status
     $status_query = xtDBquery("SELECT\n                                     shipping_status_name,\n                                     shipping_status_image,shipping_status_id\n                                     FROM " . TABLE_SHIPPING_STATUS . "\n                                     where language_id = '" . (int) $_SESSION['languages_id'] . "'");
     while ($status_data = olc_db_fetch_array($status_query, true)) {
         $this->SHIPPING[$status_data['shipping_status_id']] = array('name' => $status_data['shipping_status_name'], 'image' => $status_data['shipping_status_image']);
     }
 }
function olc_has_category_subcategories($category_id)
{
    $child_category_query = olc_db_query("select count(*) as count from " . TABLE_CATEGORIES . " where parent_id = '" . $category_id . APOS);
    $child_category = olc_db_fetch_array($child_category_query);
    if ($child_category['count'] > 0) {
        return true;
    } else {
        return false;
    }
}
function olc_update_banner_display_count($banner_id)
{
    $banner_check_query = olc_db_query("select count(*) as count from " . TABLE_BANNERS_HISTORY . " where banners_id = '" . $banner_id . "' and date_format(banners_history_date, '%Y%m%d') = date_format(now(), '%Y%m%d')");
    $banner_check = olc_db_fetch_array($banner_check_query);
    if ($banner_check['count'] > 0) {
        olc_db_query(SQL_UPDATE . TABLE_BANNERS_HISTORY . " set banners_shown = banners_shown + 1 where banners_id = '" . $banner_id . "' and date_format(banners_history_date, '%Y%m%d') = date_format(now(), '%Y%m%d')");
    } else {
        olc_db_query(INSERT_INTO . TABLE_BANNERS_HISTORY . " (banners_id, banners_shown, banners_history_date) values ('" . $banner_id . "', 1, now())");
    }
}