Execute($countries); $countries_array = array('countries_name' => $countries_values->fields['countries_name'], 'countries_iso_code_2' => $countries_values->fields['countries_iso_code_2'], 'countries_iso_code_3' => $countries_values->fields['countries_iso_code_3']); } else { $countries = "select countries_name from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$countries_id . "'"; $countries_values = $db->Execute($countries); $countries_array = array('countries_name' => $countries_values->fields['countries_name']); } } else { $countries = "select countries_id, countries_name from " . TABLE_COUNTRIES . " order by countries_name"; $countries_values = $db->Execute($countries); while (!$countries_values->EOF) { $countries_array[] = array('countries_id' => $countries_values->fields['countries_id'], 'countries_name' => $countries_values->fields['countries_name']); $countries_values->MoveNext(); } } return $countries_array; } /* * Alias function to zen_get_countries() */ function zen_get_country_name($country_id) { $country_array = zen_get_countries($country_id); return $country_array['countries_name']; } /** * Alias function to zen_get_countries, which also returns the countries iso codes * * @param int If set limits to a single country */ function zen_get_countries_with_iso_codes($countries_id) { return zen_get_countries($countries_id, true); } /* * Return the zone (State/Province) name * TABLES: zones */ function zen_get_zone_name($country_id, $zone_id, $default_zone) { global $db; $zone_query = "select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country_id . "' and zone_id = '" . (int)$zone_id . "'"; $zone = $db->Execute($zone_query); if ($zone->RecordCount()) { return $zone->fields['zone_name']; } else { return $default_zone; } } /* * Returns the zone (State/Province) code * TABLES: zones */ function zen_get_zone_code($country_id, $zone_id, $default_zone) { global $db; $zone_query = "select zone_code from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country_id . "' and zone_id = '" . (int)$zone_id . "'"; $zone = $db->Execute($zone_query); if ($zone->RecordCount() > 0) { return $zone->fields['zone_code']; } else { return $default_zone; } } /* * validate products_id */ function zen_products_id_valid($valid_id) { global $db; $check_valid = $db->Execute("select p.products_id from " . TABLE_PRODUCTS . " p where products_id='" . (int)$valid_id . "' limit 1"); if ($check_valid->EOF) { return false; } else { return true; } } /** * Return a product's name. * * @param int The product id of the product who's name we want * @param int The language id to use. If this is not set then the current language is used */ function zen_get_products_name($product_id, $language = '') { global $db; if (empty($language)) $language = $_SESSION['languages_id']; $product_query = "select products_name from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$product_id . "' and language_id = '" . (int)$language . "'"; $product = $db->Execute($product_query); return $product->fields['products_name']; } /** * Return a product's stock count. * * @param int The product id of the product who's stock we want */ function zen_get_products_stock($products_id) { global $db; $products_id = zen_get_prid($products_id); $stock_query = "select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'"; $stock_values = $db->Execute($stock_query); return $stock_values->fields['products_quantity']; } /** * Check if the required stock is available. * * If insufficent stock is available return an out of stock message * * @param int The product id of the product whos's stock is to be checked * @param int Is this amount of stock available * * @TODO naughty html in a function */ function zen_check_stock($products_id, $products_quantity) { $stock_left = zen_get_products_stock($products_id) - $products_quantity; $out_of_stock = ''; if ($stock_left < 0) { $out_of_stock = '' . STOCK_MARK_PRODUCT_OUT_OF_STOCK . ''; } return $out_of_stock; } /* * List manufacturers (returned in an array) */ function zen_get_manufacturers($manufacturers_array = '', $have_products = false) { global $db; if (!is_array($manufacturers_array)) $manufacturers_array = array(); if ($have_products == true) { $manufacturers_query = "select distinct m.manufacturers_id, m.manufacturers_name from " . TABLE_MANUFACTURERS . " m left join " . TABLE_PRODUCTS . " p on m.manufacturers_id = p.manufacturers_id where p.manufacturers_id = m.manufacturers_id and (p.products_status = 1 and p.products_quantity > 0) order by m.manufacturers_name"; } else { $manufacturers_query = "select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name"; } $manufacturers = $db->Execute($manufacturers_query); while (!$manufacturers->EOF) { $manufacturers_array[] = array('id' => $manufacturers->fields['manufacturers_id'], 'text' => $manufacturers->fields['manufacturers_name']); $manufacturers->MoveNext(); } return $manufacturers_array; } /* * Check if product has attributes */ function zen_has_product_attributes($products_id, $not_readonly = 'true') { global $db; if (PRODUCTS_OPTIONS_TYPE_READONLY_IGNORED == '1' and $not_readonly == 'true') { // don't include READONLY attributes to determin if attributes must be selected to add to cart $attributes_query = "select pa.products_attributes_id from " . TABLE_PRODUCTS_ATTRIBUTES . " pa left join " . TABLE_PRODUCTS_OPTIONS . " po on pa.options_id = po.products_options_id where pa.products_id = '" . (int)$products_id . "' and po.products_options_type != '" . PRODUCTS_OPTIONS_TYPE_READONLY . "' limit 1"; } else { // regardless of READONLY attributes no add to cart buttons $attributes_query = "select pa.products_attributes_id from " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . (int)$products_id . "' limit 1"; } $attributes = $db->Execute($attributes_query); if ($attributes->recordCount() > 0 && $attributes->fields['products_attributes_id'] > 0) { return true; } else { return false; } } /* * Check if product has attributes values */ function zen_has_product_attributes_values($products_id) { global $db; $attributes_query = "select sum(options_values_price) as total from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "'"; $attributes = $db->Execute($attributes_query); if ($attributes->fields['total'] != 0) { return true; } else { return false; } } /* * Find category name from ID, in indicated language */ function zen_get_category_name($category_id, $fn_language_id) { global $db; $category_query = "select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . $category_id . "' and language_id = '" . $fn_language_id . "'"; $category = $db->Execute($category_query); return $category->fields['categories_name']; } /* * Find category description, from category ID, in given language */ function zen_get_category_description($category_id, $fn_language_id) { global $db; $category_query = "select categories_description from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . $category_id . "' and language_id = '" . $fn_language_id . "'"; $category = $db->Execute($category_query); return $category->fields['categories_description']; } /* * Return a product's category * TABLES: products_to_categories */ function zen_get_products_category_id($products_id) { global $db; $the_products_category_query = "select products_id, master_categories_id from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'"; $the_products_category = $db->Execute($the_products_category_query); return $the_products_category->fields['master_categories_id']; } /* * Return category's image * TABLES: categories */ function zen_get_categories_image($what_am_i) { global $db; $the_categories_image_query= "select categories_image from " . TABLE_CATEGORIES . " where categories_id= '" . $what_am_i . "'"; $the_products_category = $db->Execute($the_categories_image_query); return $the_products_category->fields['categories_image']; } /* * Return category's name from ID, assuming current language * TABLES: categories_description */ function zen_get_categories_name($who_am_i) { global $db; $the_categories_name_query= "select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id= '" . $who_am_i . "' and language_id= '" . $_SESSION['languages_id'] . "'"; $the_categories_name = $db->Execute($the_categories_name_query); return $the_categories_name->fields['categories_name']; } /* * Return a product's manufacturer's name, from ID * TABLES: products, manufacturers */ function zen_get_products_manufacturers_name($product_id) { global $db; $product_query = "select m.manufacturers_name from " . TABLE_PRODUCTS . " p, " . TABLE_MANUFACTURERS . " m where p.products_id = '" . (int)$product_id . "' and p.manufacturers_id = m.manufacturers_id"; $product =$db->Execute($product_query); return ($product->RecordCount() > 0) ? $product->fields['manufacturers_name'] : ""; } /* * Return a product's manufacturer's image, from Prod ID * TABLES: products, manufacturers */ function zen_get_products_manufacturers_image($product_id) { global $db; $product_query = "select m.manufacturers_image from " . TABLE_PRODUCTS . " p, " . TABLE_MANUFACTURERS . " m where p.products_id = '" . (int)$product_id . "' and p.manufacturers_id = m.manufacturers_id"; $product =$db->Execute($product_query); return $product->fields['manufacturers_image']; } /* * Return a product's manufacturer's id, from Prod ID * TABLES: products */ function zen_get_products_manufacturers_id($product_id) { global $db; $product_query = "select p.manufacturers_id from " . TABLE_PRODUCTS . " p where p.products_id = '" . (int)$product_id . "'"; $product =$db->Execute($product_query); return $product->fields['manufacturers_id']; } /* * Return attributes products_options_sort_order * TABLE: PRODUCTS_ATTRIBUTES */ function zen_get_attributes_sort_order($products_id, $options_id, $options_values_id) { global $db; $check = $db->Execute("select products_options_sort_order from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and options_id = '" . (int)$options_id . "' and options_values_id = '" . (int)$options_values_id . "' limit 1"); return $check->fields['products_options_sort_order']; } /* * return attributes products_options_sort_order * TABLES: PRODUCTS_OPTIONS, PRODUCTS_ATTRIBUTES */ function zen_get_attributes_options_sort_order($products_id, $options_id, $options_values_id, $lang_num = '') { global $db; if ($lang_num == '') $lang_num = (int)$_SESSION['languages_id']; $check = $db->Execute("select products_options_sort_order from " . TABLE_PRODUCTS_OPTIONS . " where products_options_id = '" . (int)$options_id . "' and language_id = '" . $lang_num . "' limit 1"); $check_options_id = $db->Execute("select products_id, options_id, options_values_id, products_options_sort_order from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id='" . (int)$products_id . "' and options_id='" . (int)$options_id . "' and options_values_id = '" . (int)$options_values_id . "' limit 1"); return $check->fields['products_options_sort_order'] . '.' . str_pad($check_options_id->fields['products_options_sort_order'],5,'0',STR_PAD_LEFT); } /* * check if attribute is display only */ function zen_get_attributes_valid($product_id, $option, $value) { global $db; // regular attribute validation $check_attributes = $db->Execute("select attributes_display_only, attributes_required from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id='" . (int)$product_id . "' and options_id='" . (int)$option . "' and options_values_id='" . (int)$value . "'"); $check_valid = true; // display only cannot be selected if ($check_attributes->fields['attributes_display_only'] == '1') { $check_valid = false; } // text required validation if (preg_match('/^txt_/', $option)) { $check_attributes = $db->Execute("select attributes_display_only, attributes_required from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id='" . (int)$product_id . "' and options_id='" . (int)preg_replace('/txt_/', '', $option) . "' and options_values_id='0'"); // text cannot be blank if ($check_attributes->fields['attributes_required'] == '1' && (empty($value) && !is_numeric($value))) { $check_valid = false; } } return $check_valid; } /* * Return Options_Name from ID */ function zen_options_name($options_id) { global $db; $options_id = str_replace('txt_','',$options_id); $options_values = $db->Execute("select products_options_name from " . TABLE_PRODUCTS_OPTIONS . " where products_options_id = '" . (int)$options_id . "' and language_id = '" . (int)$_SESSION['languages_id'] . "'"); return $options_values->fields['products_options_name']; } /* * Return Options_values_name from value-ID */ function zen_values_name($values_id) { global $db; $values_values = $db->Execute("select products_options_values_name from " . TABLE_PRODUCTS_OPTIONS_VALUES . " where products_options_values_id = '" . (int)$values_id . "' and language_id = '" . (int)$_SESSION['languages_id'] . "'"); return $values_values->fields['products_options_values_name']; } /* * configuration key value lookup * TABLE: configuration */ function zen_get_configuration_key_value($lookup) { global $db; $configuration_query= $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key='" . $lookup . "'"); $lookup_value= $configuration_query->fields['configuration_value']; if ( !($lookup_value) ) { $lookup_value='' . $lookup . ''; } return $lookup_value; } /* * Return products description, based on specified language (or current lang if not specified) */ function zen_get_products_description($product_id, $language = '') { global $db; if (empty($language)) $language = $_SESSION['languages_id']; $product_query = "select products_description from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$product_id . "' and language_id = '" . (int)$language . "'"; $product = $db->Execute($product_query); return $product->fields['products_description']; } /* * look up the product type from product_id and return an info page name (for template/page handling) */ function zen_get_info_page($zf_product_id) { global $db; $sql = "select products_type from " . TABLE_PRODUCTS . " where products_id = '" . (int)$zf_product_id . "'"; $zp_type = $db->Execute($sql); if ($zp_type->RecordCount() == 0) { return 'product_info'; } else { $zp_product_type = $zp_type->fields['products_type']; $sql = "select type_handler from " . TABLE_PRODUCT_TYPES . " where type_id = '" . (int)$zp_product_type . "'"; $zp_handler = $db->Execute($sql); return $zp_handler->fields['type_handler'] . '_info'; } } /* * Get accepted credit cards * There needs to be a define on the accepted credit card in the language file credit_cards.php example: TEXT_CC_ENABLED_VISA */ function zen_get_cc_enabled($text_image = 'TEXT_', $cc_seperate = ' ', $cc_make_columns = 0) { global $db; $cc_check_accepted_query = $db->Execute(SQL_CC_ENABLED); $cc_check_accepted = ''; $cc_counter = 0; if ($cc_make_columns == 0) { while (!$cc_check_accepted_query->EOF) { $check_it = $text_image . $cc_check_accepted_query->fields['configuration_key']; if (defined($check_it)) { $cc_check_accepted .= constant($check_it) . $cc_seperate; } $cc_check_accepted_query->MoveNext(); } } else { // build a table $cc_check_accepted = '
' . constant($check_it) . ' | ' . "\n"; } $cc_check_accepted_query->MoveNext(); $cc_counter++; if ($cc_counter >= $cc_make_columns) { $cc_check_accepted .= '