Auto Parts & Supplies News:





   Copyright © 2005 Wellingborough England directory return array(filesize($filename), $width, $height); } # # Determine that $userfile is image file with non zero size # function func_is_image_userfile($userfile, $userfile_size, $userfile_type) { if (($userfile != "none") && ($userfile != "") && ($userfile_size > 0) && (substr($userfile_type, 0, 6) == 'image/')) return true; else return false; } # # Send mail abstract function # $from - from/reply-to address # function func_send_mail($to, $subject_template, $body_template, $from, $to_admin, $crypted=false) { global $mail_smarty; global $config, $customer_language, $admin_language; if ($to_admin or !$customer_language) $mail_smarty->assign ("lng", $admin_language); else $mail_smarty->assign ("lng", $customer_language); $mail_smarty->assign ("config", $config); $mail_message = $mail_smarty->fetch("$body_template"); $mail_subject = chop($mail_smarty->fetch("$subject_template")); if (($config["PGP"]["enable_pgp"]=="Y") and ($crypted)) { $mail_message = func_pgp_encrypt ($mail_message); } // ini_set("SMTP", '62.149.18.10'); ini_set("sendmail_from",'admin@kinoclub.com.ua'); mail($to,$mail_subject,$mail_message,($config["General"]["html_mail"]=="Y"?"Content-Type: text/html\n":"")."From: $from\nReply-to: $from\nX-Mailer: PHP/".phpversion()); } function func_send_simple_mail($to, $subject, $body, $from) { global $config; // ini_set("sendmail_path", '/usr/lib/sendmail'); // ini_set("SMTP", "62.149.18.10"); ini_set("sendmail_from", 'admin@kinoclub.com.ua'); mail($to,$subject,$body,($config["General"]["html_mail"]=="Y"?"Content-Type: text/html\n":"")."From: $from\nReply-to: $from\nX-Mailer: PHP/".phpversion()); } # # Simple crypt function. Returns an encrypted version of argument. # Does not matter what type of info you encrypt, the function will return # a string of ASCII chars representing the encrypted version of argument. # Note: text_crypt returns string, which length is 2 time larger # function text_crypt_symbol($c) { # $c is ASCII code of symbol. returns 2-letter text-encoded version of symbol global $START_CHAR_CODE; return chr($START_CHAR_CODE + ($c & 240) / 16).chr($START_CHAR_CODE + ($c & 15)); } function text_crypt($s) { global $START_CHAR_CODE, $CRYPT_SALT; if ($s == "") return $s; $enc = rand(1,255); # generate random salt. $result = text_crypt_symbol($enc); # include salt in the result; $enc ^= $CRYPT_SALT; for ($i = 0; $i < strlen($s); $i++) { $r = ord(substr($s, $i, 1)) ^ $enc++; if ($enc > 255) $enc = 0; $result .= text_crypt_symbol($r); } return $result; } function text_decrypt_symbol($s, $i) { # $s is a text-encoded string, $i is index of 2-char code. function returns number in range 0-255 global $START_CHAR_CODE; return (ord(substr($s, $i, 1)) - $START_CHAR_CODE)*16 + ord(substr($s, $i+1, 1)) - $START_CHAR_CODE; } function text_decrypt($s) { global $START_CHAR_CODE, $CRYPT_SALT; if ($s == "") return $s; $enc = $CRYPT_SALT ^ text_decrypt_symbol($s, 0); for ($i = 2; $i < strlen($s); $i+=2) { # $i=2 to skip salt $result .= chr(text_decrypt_symbol($s, $i) ^ $enc++); if ($enc > 255) $enc = 0; } return $result; } # # Recursively deletes category with all its contents # function func_rm_dir_files ($path) { $dir = opendir ($path); while ($file = readdir ($dir)) { if (($file == ".") or ($file == "..")) continue; if (filetype ("$path/$file") == "dir") { func_rm_dir_files ("$path/$file"); rmdir ("$path/$file"); } else { unlink ("$path/$file"); } } } function func_rm_dir ($path) { func_rm_dir_files ($path); rmdir ($path); } # # Delete product from products table + all associated information # $productid - product's id # function func_delete_product($productid) { global $sql_tbl; db_query("delete from $sql_tbl[pricing] where productid='$productid'"); db_query("delete from $sql_tbl[product_links] where productid1='$productid' or productid2='$productid'"); db_query("delete from $sql_tbl[featured_products] where productid='$productid'"); db_query("delete from $sql_tbl[products] where productid='$productid'"); db_query("delete from $sql_tbl[delivery] where productid='$productid'"); db_query("delete from $sql_tbl[images] where productid='$productid'"); db_query("delete from $sql_tbl[thumbnails] where productid='$productid'"); db_query("delete from $sql_tbl[product_options] where productid='$productid'"); db_query("DELETE FROM $sql_tbl[product_options_ex] WHERE productid='$productid'"); db_query("DELETE FROM $sql_tbl[product_options_js] WHERE productid='$productid'"); db_query("DELETE FROM $sql_tbl[product_votes] WHERE productid='$productid'"); db_query("DELETE FROM $sql_tbl[product_reviews] WHERE productid='$productid'"); db_query("DELETE FROM $sql_tbl[products_lng] WHERE productid='$productid'"); db_query("DELETE FROM $sql_tbl[subscriptions] tbl[stats_customers_products] where productid='$productid'"); db_query("DELETE FROM $sql_tbl[wishlist] where productid='$productid'"); db_query("DELETE FROM $sql_tbl[product_bookmarks] where productid='$productid'"); } # # Delete profile from customers table + all associated information # function func_delete_profile($user,$usertype) { global $files_dir_name, $single_mode, $sql_tbl; if($usertype=="P" && !$single_mode) { # If user is provider delete some associated info to keep DB integrity # Delete products # $products = func_query("SELECT productid FROM $sql_tbl[products] WHERE provider='$user'"); if (!empty($products)) foreach($products as $product) func_delete_product($product["productid"]); # # Delete Shipping, Discounts, Coupons, States/Tax, Countries/Tax # db_query("delete from $sql_tbl[shipping_rates] where provider='$user'"); db_query("delete from $sql_tbl[discounts] where provider='$user'"); db_query("delete from $sql_tbl[discount_coupons] where provider='$user'"); db_query("delete from $sql_tbl[state_tax] where provider='$user'"); db_query("delete from $sql_tbl[country_tax] where provider='$user'"); # # Delete provider's file dir # @func_rm_dir ("$files_dir_name/$user"); } # # If it is partner, then remove all his information # if ($usertype == "B") { db_query ("DELETE FROM $sql_tbl[partner_clicks] WHERE login='$user'"); db_query ("DELETE FROM $sql_tbl[partner_commitions] WHERE login='$user'"); db_query ("DELETE FROM $sql_tbl[partner_payment] WHERE login='$user'"); db_query ("DELETE FROM $sql_tbl[partner_views] WHERE login='$user'"); } db_query("DELETE FROM $sql_tbl[customers] WHERE login='$user' AND usertype='$usertype'"); } # # Get information associated with user # function func_userinfo($user,$usertype) { global $sql_tbl; $userinfo = func_query_first("SELECT $sql_tbl[customers].*, $sql_tbl[countries].country FROM $sql_tbl[customers], $sql_tbl[countries] WHERE $sql_tbl[customers].login='$user' AND $sql_tbl[customers].usertype='$usertype' AND $sql_tbl[countries].code=$sql_tbl[customers].b_country"); $userinfo["passwd1"] = stripslashes(text_decrypt($userinfo["password"])); $userinfo["passwd2"] = stripslashes(text_decrypt($userinfo["password"])); $userinfo["password"] = stripslashes(text_decrypt($userinfo["password"])); $userinfo["card_number"] = text_decrypt($userinfo["card_number"]); $userinfo["b_statename"]= array_pop(func_query_first("SELECT $sql_tbl[states].state FROM $sql_tbl[customers], $sql_tbl[states] WHERE $sql_tbl[states].code='$userinfo[b_state]'")); $userinfo["b_countryname"]= array_pop(func_query_first("SELECT $sql_tbl[countries].country FROM $sql_tbl[customers], $sql_tbl[countries] WHERE $sql_tbl[countries].code='$userinfo[b_country]'")); $userinfo["s_statename"]= array_pop(func_query_first("SELECT $sql_tbl[states].state FROM $sql_tbl[customers], $sql_tbl[states] WHERE $sql_tbl[states].code='$userinfo[s_state]'")); $userinfo["s_countryname"]= array_pop(func_query_first("SELECT $sql_tbl[countries].country FROM $sql_tbl[customers], $sql_tbl[countries] WHERE $sql_tbl[countries].code='$userinfo[s_country]'")); $email = $userinfo["email"]; if(func_query_first("SELECT email FROM $sql_tbl[maillist] WHERE email='$email'")) $userinfo["newsletter"]="Y"; return $userinfo; } # # Convert price to "XXXXX.XX" format # function price_format($price) { if (strstr($price,".")) { $ttt = 0.00000001; $price = round($price+$ttt,2); $price.="00"; $price = ereg_replace("(\...).*$","\\1",$price); } else $price.=".00"; return $price; } function func_get_products_providers ($products) { $products_providers = array (); foreach ($products as $product) { if (!in_array ($product["provider"], $products_providers)) { $products_providers [] = $product["provider"]; } } return $products_providers; } function func_get_products_by_provider ($products, $provider) { global $single_mode; $result = array (); if ($single_mode) { $result = $products; } else { foreach ($products as $product) { if ($product["provider"] == $provider) $result[] = $product; } } return $result; } # # This function do real shipping calcs # function func_real_shipping($delivery) { global $intershipper_rates, $sql_tbl; $shipping_codes = func_query_first("select code, subcode from $sql_tbl[shipping] where shippingid='$delivery'"); if ($intershipper_rates) { foreach($intershipper_rates as $rate) if ($rate["methodid"]==$shipping_codes["subcode"]) return $rate["rate"]; } else return "0.00"; } # # This function calculates costs of contents of shopping cart # function func_calculate($cart, $products, $login, $login_type) { global $single_mode; if ($single_mode) { $return = array (); $result = func_calculate_single ($cart, $products, $login, $login_type); $return = $result; $return ["orders"] = array (); $return ["orders"][0] = $result; $return ["orders"][0]["provider"] = $products[0]["provider"]; } else { $products_providers = func_get_products_providers ($products); $return = array (); $return["orders"] = array (); $key = 0; foreach ($products_providers as $provider_for) { $_products = func_get_products_by_provider ($products, $provider_for); $result = func_calculate_single ($cart, $_products, $login, $login_type); $return ["total_cost"] += $result ["total_cost"]; $return ["shipping_cost"] += $result ["shipping_cost"]; $return ["tax_cost"] += $result ["tax_cost"]; $return ["discount"] += $result ["discount"]; if ($result["coupon"]) { $return ["coupon"] = $result ["coupon"]; } $return ["coupon_discount"] += $result ["coupon_discount"]; $return ["sub_total"] += $result ["sub_total"]; $return ["total_vat"] += $result ["total_vat"]; $return ["orders"][$key] = $result; $return ["orders"][$key]["provider"] = $provider_for; $key ++; } if ($cart["giftcerts"]) { $_products = array (); $result = func_calculate_single ($cart, $_products, $login, $login_type); $return ["total_cost"] += $result ["total_cost"]; $return ["shipping_cost"] += $result ["shipping_cost"]; $return ["tax_cost"] += $result ["tax_cost"]; $return ["discount"] += $result ["discount"]; $return ["sub_total"] += $result ["sub_total"]; $return ["total_vat"] += $result ["total_vat"]; $return ["coupon_discount"] += $result ["coupon_discount"]; $return ["orders"][$key] = $result; $return ["orders"][$key]["provider"] = ""; #$provider_for; $key++; } } return $return; } # # Calculate total products price # 1) calculate total sum, # 2) a) total = total - discount # b) total = total - coupon_discount # 3) calculate shipping # 4) calculate tax # 5) total_cost = total + shipping + tax # 6) total_cost = total_cost + giftcerts_cost # function func_calculate_single($cart, $products, $login, $login_type) { global $single_mode; global $active_modules, $config, $sql_tbl; if (!$products) $provider_for = ""; else $provider_for = $products[0]["provider"]; $delivery = $cart["shippingid"]; $giftcerts = $cart["giftcerts"]; $discount_coupon = $cart["discount_coupon"]; $provider_condition=($single_mode?"":"and provider='$provider_for'"); if(!empty($login)) $customer_info = func_userinfo($login,$login_type); $total=0; $sub_total=0; $total_weight=0; $total_items=0; $avail_discount_total=0; $total_weight_shipping = 0; $total_items_shipping = 0; $total_shipping = 0; $total_vat = 0; $avail_discount_total=0; $discount=0; $giftcert_cost = 0; if ($cart["applied_giftcerts"]) { foreach($cart["applied_giftcerts"] as $k=>$v) $giftcert_cost += $v["giftcert_cost"]; } foreach($products as $product) { if ($product["discount_avail"]=='Y') $avail_discount_total+=$product["price"]*$product["amount"]; $total+=$product["price"]*$product["amount"]; $total_weight+=$product["weight"]*$product["amount"]; $total_vat+=$product["price"]*$product["amount"]*$product["vat"]/100; if ($product["distribution"]=="") $total_items+=$product["amount"]; elseif ($total_items==0) $total_items+=$product["amount"]; if ($product["free_shipping"] != "Y") { $total_shipping += $product["price"]*$product["amount"]; $total_weight_shipping += $product["weight"]*$product["amount"]; if ($product["distribution"]=="") $total_items_shipping += $product["amount"]; } } $sub_total = $total; # # Deduct discount # $discount_info = func_query_first("select * from $sql_tbl[discounts] where minprice<='$avail_discount_total' $provider_condition and membership='$customer_info[membership]' order by minprice desc"); $discountall_info = func_query_first("select * from $sql_tbl[discounts] where minprice<='$avail_discount_total' $provider_condition and membership='' order by minprice desc"); if ($discount_info["discount_type"]=="absolute") $discount += $discount_info["discount"]; elseif ($discount_info["discount_type"]=="percent") $discount += $avail_discount_total*$discount_info["discount"]/100; elseif ($discountall_info["discount_type"]=="absolute") $discount += $discountall_info["discount"]; elseif ($discountall_info["discount_type"]=="percent") $discount += $avail_discount_total*$discountall_info["discount"]/100; $total = $total-$discount; $total_shipping -= $discount; if ($total_shipping < 0) $total_shipping = 0; # # Deduct discount by discount coupon # $coupon_discount=0; $coupon_total = 0; $coupon_amount = 0; $discount_coupon_data = func_query_first("select * from $sql_tbl[discount_coupons] where coupon='$discount_coupon' $provider_condition"); if (($discount_coupon_data["productid"]>0) and (($discount_coupon_data["coupon_type"]=="absolute") or ($discount_coupon_data["coupon_type"]=="percent"))) { foreach($products as $product) { if ($product["productid"] == $discount_coupon_data["productid"]) { $coupon_total += $product["price"]*$product["amount"]; $coupon_amount += $product["amount"]; } } if ($discount_coupon_data["coupon_type"]=="absolute") { $coupon_discount = $coupon_amount*$discount_coupon_data["discount"]; } else { $coupon_discount = $coupon_total*$discount_coupon_data["discount"]/100; } } elseif (($discount_coupon_data["categoryid"]>0) and (($discount_coupon_data["coupon_type"]=="absolute") or ($discount_coupon_data["coupon_type"]=="percent"))) { foreach ($products as $product) { if ($product["categoryid"] == $discount_coupon_data["categoryid"]) { $coupon_total += $product["price"]*$product["amount"]; $coupon_amount += $product["amount"]; } } if ($discount_coupon_data["coupon_type"]=="absolute") { $coupon_discount = $coupon_amount*$discount_coupon_data["discount"]; } else { $coupon_discount = $coupon_total*$discount_coupon_data["discount"]/100; } } else { if ($discount_coupon_data["coupon_type"]=="absolute") $coupon_discount = $discount_coupon_data["discount"]; elseif ($discount_coupon_data["coupon_type"]=="percent") $coupon_discount = $total*$discount_coupon_data["discount"]/100; } if ((!$single_mode) and (($discount_coupon_data["provider"] != $provider_for) or (!$products))) $discount_coupon = ""; $total = $total-$coupon_discount; $total_shipping -= $coupon_discount; if ($total_shipping<0) $total_shipping = 0; # # Calculate shipping cost # # Shipping also calculated based on zones # # Advanced shipping formula: # AMOUNT = amount of ordered products # SUM = total sum of order # TOTAL_WEIGHT = total weight of products # # SHIPPING = rate+TOTAL_WEIGHT*weight_rate+AMOUNT*item_rate+SUM*rate_p/100 # $shipping_cost = 0; $shipping_freight = 0; # # Zones code # $calculate_enable_flag = true; if (!$login && $config["General"]["apply_default_country"]!="Y") $calculate_enable_flag = false; else { if (!$login && $config["General"]["apply_default_country"]=="Y") { $customer_info[s_country] = $config["General"]["default_country"]; } } if($calculate_enable_flag) { $customer_zone = array_pop(func_query_first("select zoneid from $sql_tbl[country_zones] where code='$customer_info[s_country]' $provider_condition")); if ($customer_info["s_country"]==$config["Company"]["location_country"]) { $customer_zone_tmp = array_pop(func_query_first("select zoneid from $sql_tbl[state_zones] where code='$customer_info[s_state]' $provider_condition")); if($customer_zone_tmp) $customer_zone=$customer_zone_tmp; } } if(!$customer_zone) $customer_zone=0; # # if $products is empty then shipping and tax are alwayz zero # if ($total_items_shipping && $calculate_enable_flag) { $shipping = func_query("select * from $sql_tbl[shipping_rates] where shippingid='$delivery' $provider_condition and zoneid='$customer_zone' and maxtotal>=$total_shipping and maxweight>=$total_weight_shipping and type='D' order by maxtotal, maxweight"); if($shipping) $shipping_cost = $shipping[0]["rate"]+$total_weight_shipping*$shipping[0]["weight_rate"]+$total_items_shipping*$shipping[0]["item_rate"]+$total_shipping*$shipping[0]["rate_p"]/100; } $free_shipping=1; $is_distribution=1; foreach($products as $product){ $shipping_freight += $product["shipping_freight"]*$product["amount"]; if ($product["free_shipping"] != "Y" and $product["distribution"] == "") $free_shipping=0; if ($product["distribution"] == "") $is_distribution=0; } # # Realtime shipping rates # $result = func_query_first ("SELECT * FROM $sql_tbl[shipping] WHERE shippingid='$delivery' AND code!=''"); if($config["Shipping"]["realtime_shipping"]=="Y" and $result and $free_shipping==0 and $is_distribution==0) { $shipping_cost = func_real_shipping($delivery); $shipping_rt = func_query("select * from $sql_tbl[shipping_rates] where shippingid='$delivery' $provider_condition and zoneid='$customer_zone' and maxtotal>=$total_shipping and maxweight>=$total_weight_shipping and type='R' order by maxtotal, maxweight"); if($shipping_rt) $shipping_cost += $shipping_rt[0]["rate"]+$total_weight_shipping*$shipping_rt[0]["weight_rate"]+$total_items_shipping*$shipping_rt[0]["item_rate"]+$total_shipping*$shipping_rt[0]["rate_p"]/100; } if ($discount_coupon_data["coupon_type"]=='free_ship') { if (($single_mode) or ($provider_for == $discount_coupon_data["provider"])) { $coupon_discount = $shipping_cost; $total -= $coupon_discount; } } $shipping_cost += $shipping_freight; # # Calculate tax cost # SUM = total sum of order # # TAX = country_tax_flat + SUM*country_tax_percent/100 + state_tax_flat + SUM*state_tax_percent/100; # $tax_cost = 0; if ((!empty($login) || $calculate_enable_flag) && ($active_modules["Tax_Zones"])) { include "../modules/Tax_Zones/calc_tax.php"; } if ((!empty($login) || $calculate_enable_flag) && $total_items) { $country_tax = array(); $state_tax = array(); $country_tax = func_query_first("select $sql_tbl[country_tax].* from $sql_tbl[country_tax], $sql_tbl[countries] where $sql_tbl[country_tax].code='$customer_info[s_country]' $provider_condition and $sql_tbl[country_tax].code=$sql_tbl[countries].code"); if ($customer_info["s_country"]==$config["Company"]["location_country"]) { if ($customer_info["s_state"]) $state_tax = func_query_first("select $sql_tbl[state_tax].* from $sql_tbl[states], $sql_tbl[state_tax] where $sql_tbl[states].code=$sql_tbl[state_tax].code $provider_condition and $sql_tbl[state_tax].code='".$customer_info["s_state"]."'"); if ($customer_info["s_zipcode"]) $zipcode_tax = func_query_first("select sum(tax_percent) as tax_percent, sum(tax_flat) as tax_flat from $sql_tbl[zipcode_tax] where '".addslashes($customer_info[s_zipcode])."' like zipcode_mask"); } $tax_cost += $country_tax["tax_flat"]+$total*$country_tax["tax_percent"]/100+$state_tax["tax_flat"]+$total*$state_tax["tax_percent"]/100; $tax_cost += $zipcode_tax["tax_flat"]+$total*$zipcode_tax["tax_percent"]/100; } # # Calculate Gift Certificates cost (purchased giftcerts) # $giftcerts_cost=0; if ((($single_mode) or (!$provider_for)) and ($giftcerts)) foreach($giftcerts as $giftcert) $giftcerts_cost+=$giftcert["amount"]; $sub_total = $sub_total+$giftcerts_cost; # # Calculate total # $total+=$shipping_cost+$tax_cost+$giftcerts_cost; # # Recalculating applied gift certificates # if ($cart["applied_giftcerts"]) { $gc_payed_sum = 0; $applied_giftcerts = array(); foreach($cart["applied_giftcerts"] as $k=>$v) { if (($gc_payed_sum + $v["giftcert_cost"]) <= $total) { $gc_payed_sum += $v["giftcert_cost"]; $applied_giftcerts[] = $v; continue; } else db_query("UPDATE $sql_tbl[giftcerts] SET status='A' WHERE gcid='$v[giftcert_id]'"); } $giftcert_cost = $gc_payed_sum; } if ($total>=$giftcert_cost) $giftcert_discount = $giftcert_cost; else $giftcert_discount = $giftcert_cost - $total; $total = $total - $giftcert_discount; return array("total_cost"=>price_format($total), "shipping_cost"=>price_format($shipping_cost), "tax_cost"=>price_format($tax_cost), "discount"=>price_format($discount), "coupon"=>$discount_coupon, "coupon_discount"=>price_format($coupon_discount), "sub_total"=>price_format($sub_total), "total_vat"=>price_format($total_vat), "giftcert_discount"=>price_format($giftcert_discount), "applied_giftcerts"=>$applied_giftcerts); } # # Search for products in products database # function func_search_products($query, $membership,$first=0,$count_all=-1,$get_all=0, $add="") { global $current_area; global $store_language, $sql_tbl; global $config; if ($current_area == "C") { $membership_condition = " AND ($sql_tbl[categories].membership='$membership' OR $sql_tbl[categories].membership='') "; } else { $membership_condition = ""; } $tail = ""; $result = array(); if($count_all != -1) { if($first > $count_all) return $result; if(!$get_all) { $count_all_max = $config["General"]["products_per_page"]*$config["General"]["max_nav_pages"]; if($count_all > $count_all_max) $count_all = $count_all_max; $count = $config["General"]["products_per_page"]; if(($first+$count)>$count_all) $count = $count_all - $first; } else { $count = $count_all - $first; } $tail = " limit ".$count_all; $query .= " group by $sql_tbl[products].productid "; } if($count_all == 0 or $count_all < -1) return $result; $search_query = "select $sql_tbl[products].*, $sql_tbl[categories].category, min($sql_tbl[pricing].price) as price from $sql_tbl[products], $sql_tbl[pricing], $sql_tbl[categories] where $sql_tbl[pricing].productid=$sql_tbl[products].productid and $sql_tbl[pricing].quantity=1 and $sql_tbl[products].categoryid=$sql_tbl[categories].categoryid $membership_condition and ($sql_tbl[pricing].membership='$membership' or $sql_tbl[pricing].membership='') and ".$query." ".$add; //.$tail $result_p = func_query ($search_query);//." LIMIT 300" # sorting by "orderby" field if($result_p) { if($count_all!=-1) { $productorderbys = array(); foreach($result_p as $result_line) $productorderbys[]=$result_line["orderby"]; array_multisort($result_p,($config["General"]["product_order_reversed"]=="Y"?SORT_DESC:SORT_ASC),SORT_STRING, $productorderbys,($config["General"]["product_order_reversed"]=="Y"?SORT_DESC:SORT_ASC),SORT_NUMERIC); for($i=$first; $i < $first+$count; $i++) $result[]=$result_p[$i]; } else { $i = 0; foreach($result_p as $key => $value) $result[] = $result_p[$key]; } } if ($result and $current_area=="C") { foreach ($result as $key=>$value) { $int_res = func_query_first ("SELECT * FROM $sql_tbl[products_lng] WHERE code='$store_language' AND productid='$value[productid]'"); if ($int_res[descr]) $result[$key][descr] = str_replace("\n","
", stripslashes($int_res[descr])); if ($int_res[full_descr]) $result[$key][full_descr] = str_replace("\n","
", stripslashes($int_res[full_descr])); } } return $result; } # # Delete category recursively and all subcategories and products # function func_delete_category($cat) { global $sql_tbl; $cat_name = array_pop(func_query_first("select category from $sql_tbl[categories] where categoryid='$cat'")); $cat_name = addslashes($cat_name); # # Delete products from subcategories # $prods = func_query("select productid from $sql_tbl[products], $sql_tbl[categories] where ($sql_tbl[categories].category='$cat_name' or $sql_tbl[categories].category like '$cat_name/%') and $sql_tbl[products].categoryid=$sql_tbl[categories].categoryid"); if($prods) while(list($key,$prod)=each($prods)) func_delete_product($prod["productid"]); # # Delete subcategories # $subcats = func_query("select categoryid from $sql_tbl[categories] where category like '$cat_name/%' or category='$cat_name'"); while(list($key,$subcat)=each($subcats)) { $cat_id=$subcat["categoryid"]; db_query("delete from $sql_tbl[categories] where categoryid='$cat_id'"); } # # Delete associated data # db_query("delete from $sql_tbl[icons] where categoryid='$cat'"); db_query("delete from $sql_tbl[featured_products] where categoryid='$cat'"); } # # Count products in category # function func_products_count($cat) { global $sql_tbl; $cat_name = array_pop(func_query_first("select category from $sql_tbl[categories] where categoryid='$cat'")); $cat_name = addslashes($cat_name); # # Select products from subcategories # $prods = func_query("select count(productid) from $sql_tbl[products], $sql_tbl[categories]