function xtc_get_subcategories(&$subcategories_array, $parent_id = 0)
{
    $subcategories_query = "select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . xtc_db_input((int) $parent_id) . "'";
    $subcategories_query = xtDBquery($subcategories_query);
    while ($subcategories = xtc_db_fetch_array($subcategories_query, true)) {
        $subcategories_array[sizeof($subcategories_array)] = $subcategories['categories_id'];
        if ($subcategories['categories_id'] != $parent_id) {
            xtc_get_subcategories($subcategories_array, $subcategories['categories_id']);
        }
    }
}
 $subcat_join = '';
 $subcat_where = '';
 $tax_where = '';
 $cats_list = '';
 $left_join = '';
 // fsk18 lock
 $fsk_lock = $_SESSION['customers_status']['customers_fsk18_display'] == '0' ? " AND p.products_fsk18 != '1' " : "";
 // group check
 $group_check = GROUP_CHECK == 'true' ? " AND p.group_permission_" . $_SESSION['customers_status']['customers_status_id'] . "=1 " : "";
 // manufacturers check
 $manu_check = $manufacturers_id !== false ? " AND p.manufacturers_id = '" . $manufacturers_id . "' " : "";
 //include subcategories if needed
 if ($categories_id !== false) {
     if (isset($_GET['inc_subcat']) && $_GET['inc_subcat'] == '1') {
         $subcategories_array = array();
         xtc_get_subcategories($subcategories_array, $categories_id);
         $subcat_join = " LEFT OUTER JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " AS p2c ON (p.products_id = p2c.products_id) ";
         $subcat_where = " AND p2c.categories_id IN ('" . $categories_id . "' ";
         foreach ($subcategories_array as $scat) {
             $subcat_where .= ", '" . $scat . "'";
         }
         $subcat_where .= ") ";
     } else {
         $subcat_join = " LEFT OUTER JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " AS p2c ON (p.products_id = p2c.products_id) ";
         $subcat_where = " AND p2c.categories_id = '" . $categories_id . "' ";
     }
 }
 // price by currency
 $NeedTax = false;
 if ($pfrom || $pto) {
     $rate = xtc_get_currencies_values($_SESSION['currency']);