рок для подкатегорий $y = ceil(count($cats)/$x); $res = array(); $k = 0; for ($i = 0; $i < $x; $i++) { $res[$i] = array(); for ($j = 0; $j < $y; $j++) { if (isset($cats[$k])) { $res[$i][$j] = $cats[$k]; $k++; } } } $cat_arr['child'] = $res; } return $cat_arr; } function catGetCategoryCListMin() { return _recursiveGetCategoryCList( 1, 0, null, 'NUM', false, false); } // ***************************************************************************** // Purpose gets product count in category // Inputs // Remarks this function does not keep in mind subcategories // Returns nothing function catGetCategoryProductCount( $categoryID, $cprod = false ) { if (!$categoryID) return 0; $res = 0; $sql = " select count(*) FROM ".PRODUCTS_TABLE." WHERE categoryID=".(int)$categoryID."".($cprod?" AND enabled>0":""); $q = db_query($sql); $t = db_fetch_row($q); $res += $t[0]; if($cprod) $sql = " select COUNT(*) FROM ".PRODUCTS_TABLE." AS prot LEFT JOIN ".CATEGORIY_PRODUCT_TABLE." AS catprot ON prot.productID=catprot.productID WHERE catprot.categoryID=".(int)$categoryID." AND prot.enabled>0 "; else $sql = " select count(*) from ".CATEGORIY_PRODUCT_TABLE. " where categoryID=".(int)$categoryID ; $q1 = db_query($sql); $row = db_fetch_row($q1); $res += $row[0]; return $res; } function update_sCount($parent) { global $fc, $mc; $rcat = array_keys ($mc, (int)$parent); $crcat = count($rcat); for ($i=0; $i<$crcat; $i++) { $rowsub = $fc[(int)$rcat[$i]]; $countsub = count(array_keys ($mc, (int)$rowsub["categoryID"])); db_query("UPDATE ".CATEGORIES_TABLE. " SET subcount=".(int)$countsub." ". " WHERE categoryID=".(int)$rcat[$i]); $rowsubExist = ( $countsub != 0 ); if ( $rowsubExist ) update_sCount($rowsub["categoryID"]); } } function update_pCount($parent) { update_sCount($parent); $q = db_query("select categoryID FROM ".CATEGORIES_TABLE. " WHERE categoryID>1 AND parent=".(int)$parent); $cnt = array(); $cnt["admin_count"] = 0; $cnt["customer_count"] = 0; // process subcategories while( $row=db_fetch_row($q) ) { $t = update_pCount( $row["categoryID"] ); $cnt["admin_count"] += $t["admin_count"]; $cnt["customer_count"] += $t["customer_count"]; } // to administrator $q = db_query("select count(*) FROM ".PRODUCTS_TABLE. " WHERE categoryID=".(int)$parent); $t = db_fetch_row($q); $cnt["admin_count"] += $t[0]; $q1 = db_query("select count(*) from ".CATEGORIY_PRODUCT_TABLE. " where categoryID=".(int)$parent); $row = db_fetch_row($q1); $cnt["admin_count"] += $row[0]; // to customer $q = db_query("select count(*) FROM ".PRODUCTS_TABLE. " WHERE enabled=1 AND categoryID=".(int)$parent); $t = db_fetch_row($q); $cnt["customer_count"] += $t[0]; $q1 = db_query("select productID, categoryID from ".CATEGORIY_PRODUCT_TABLE. " where categoryID=".(int)$parent); while( $row = db_fetch_row($q1) ) { $q2 = db_query("select productID from ".PRODUCTS_TABLE. " where enabled=1 AND productID=".(int)$row["productID"]); if ( db_fetch_row($q2) ) $cnt["customer_count"] ++; } db_query("UPDATE ".CATEGORIES_TABLE. " SET products_count=".(int)$cnt["customer_count"].", products_count_admin=". (int)$cnt["admin_count"]." WHERE categoryID=".(int)$parent); return $cnt; } function update_psCount($parent) { global $fc, $mc; $q = db_query("select categoryID, name, products_count, ". "products_count_admin, parent, picture, subcount FROM ". CATEGORIES_TABLE. " ORDER BY sort_order, name"); $fc = array(); //parents $mc = array(); //parents while ($row = db_fetch_row($q)) { $fc[(int)$row["categoryID"]] = $row; $mc[(int)$row["categoryID"]] = (int)$row["parent"]; } update_pCount($parent); } // ***************************************************************************** // Purpose get subcategories by category id // Inputs $categoryID // parent category ID // Remarks get current category's subcategories IDs (of all levels!) // Returns array of category ID function catGetSubCategories( $categoryID ) { $q = db_query("select categoryID from ".CATEGORIES_TABLE." where parent=".(int)$categoryID); $r = array(); while ($row = db_fetch_row($q)) { $a = catGetSubCategories($row[0]); $c_a = count($a); for ($i=0;$i<$c_a;$i++) $r[] = $a[$i]; $r[] = $row[0]; } return $r; } // ***************************************************************************** // Purpose get subcategories by category id // Inputs $categoryID // parent category ID // Remarks get current category's subcategories IDs (of all levels!) // Returns array of category ID function catGetSubCategoriesSingleLayer( $categoryID ) { $q = db_query("select categoryID, name, products_count FROM ". CATEGORIES_TABLE." WHERE parent=".(int)$categoryID." order by sort_order, name"); $result = array(); while ($row = db_fetch_row($q)) $result[] = $row; return $result; } // ***************************************************************************** // Purpose get category by id // Inputs $categoryID // - category ID // Remarks // Returns function catGetCategoryById($categoryID) { $sql_query = "SELECT cat.categoryID, cat.name, cat.parent, cat.products_count, cat.picture, cat.products_count_admin, cat.sort_order, cat.viewed_times, cat.allow_products_comparison, cat.allow_products_search, cat.show_subcategories_products, tpl_id, UID, typ, REPLACE(REPLACE(tpl.description,'{city}',cat.cat_h1), '{year}', YEAR(CURDATE())) as description, REPLACE(tpl.meta_description,'{city}',cat.name)as meta_description, REPLACE(tpl.meta_keywords,'{city}',cat.name) as meta_keywords, REPLACE(tpl.title,'{city}',cat.name) as title, REPLACE(tpl.cat_h1,'{city}',cat.cat_h1) as cat_h1, REPLACE(tpl.cat_h2_c,'{city}',cat.cat_h1) as cat_h2_c, REPLACE(tpl.cat_h2_o,'{city}',cat.cat_h1) as cat_h2_o, REPLACE(tpl.cat_h2_r,'{city}',cat.cat_h1) as cat_h2_r, level FROM ".CATEGORIES_TABLE." cat LEFT JOIN ".CATEGORIES_TPL_TABLE." tpl ON(cat.tpl_id = tpl.id) WHERE categoryID=".$categoryID; $q = db_query($sql_query); $catrow = db_fetch_row($q); if($catrow==false) { $sql_query = 'SELECT * FROM '.CATEGORIES_TABLE.' WHERE categoryID='.$categoryID; $catrow = db_fetch_row($q); } $catrow["name"] = ToText($catrow["name"]); $catrow["meta_description"] = ToText($catrow["meta_description"]); $catrow["meta_keywords"] = ToText($catrow["meta_keywords"]); $catrow["title"] = ToText($catrow["title"]); $catrow["cat_h1"] = ToText($catrow["cat_h1"]); $catrow["cat_h2_c"] = ToText($catrow["cat_h2_c"]); $catrow["cat_h2_o"] = ToText($catrow["cat_h2_o"]); $catrow["cat_h2_r"] = ToText($catrow["cat_h2_r"]); return $catrow; } // ***************************************************************************** // Purpose gets category META information in HTML form // Inputs $categoryID // - category ID // Remarks // Returns function catGetMetaTags($categoryID) { $q = db_query( "select meta_description, meta_keywords from ". CATEGORIES_TABLE." where categoryID=".(int)$categoryID ); $row = db_fetch_row($q); $res = ""; if ( $row["meta_description"] != "" ) $res .= "\n"; if ( $row["meta_keywords"] != "" ) $res .= "\n"; return $res; } // ***************************************************************************** // Purpose adds product to appended category // Inputs // Remarks this function uses CATEGORIY_PRODUCT_TABLE table in data base instead of // PRODUCTS_TABLE.categoryID. In CATEGORIY_PRODUCT_TABLE saves appended // categories // Returns array of item // "categoryID" // "category_name" function catGetAppendedCategoriesToProduct( $productID ) { $q = db_query( "select ".CATEGORIES_TABLE.".categoryID as categoryID, name as category_name ". " from ".CATEGORIY_PRODUCT_TABLE.", ".CATEGORIES_TABLE." ". " where ".CATEGORIY_PRODUCT_TABLE.".categoryID = ".CATEGORIES_TABLE.".categoryID ". " AND productID = ".(int)$productID ); $data = array(); while( $row = db_fetch_row( $q ) ){ $wayadd = ''; $way = catCalculatePathToCategoryA($row["categoryID"]); $cway = count($way); for ($i=$cway-1; $i>=0; $i--){ if($way[$i]['categoryID']!=1) $wayadd .= $way[$i]['name'].' / '; } $row["category_way"]=$wayadd."".$row["category_name"].""; $data[] = $row; } return $data; } // ***************************************************************************** // Purpose adds product to appended category // Inputs // Remarks this function uses CATEGORIY_PRODUCT_TABLE table in data base instead of // PRODUCTS_TABLE.categoryID. In CATEGORIY_PRODUCT_TABLE saves appended // categories // Returns true if success, false otherwise function catAddProductIntoAppendedCategory($productID, $categoryID) { $q = db_query("select count(*) from ".CATEGORIY_PRODUCT_TABLE. " where productID=".(int)$productID." AND categoryID=".(int)$categoryID); $row = db_fetch_row( $q ); $qh = db_query( "select categoryID from ".PRODUCTS_TABLE. " where productID=".(int)$productID); $rowh = db_fetch_row( $qh ); $basic_categoryID = $rowh["categoryID"]; if ( !$row[0] && $basic_categoryID != $categoryID ) { db_query("insert into ".CATEGORIY_PRODUCT_TABLE. "( productID, categoryID ) ". "values( ".(int)$productID.", ".(int)$categoryID." )" ); return true; } else return false; } // ***************************************************************************** // Purpose removes product to appended category // Inputs // Remarks this function uses CATEGORIY_PRODUCT_TABLE table in data base instead of // PRODUCTS_TABLE.categoryID. In CATEGORIY_PRODUCT_TABLE saves appended // categories // Returns nothing function catRemoveProductFromAppendedCategory($productID, $categoryID) { db_query("delete from ".CATEGORIY_PRODUCT_TABLE. " where productID = ".(int)$productID." AND categoryID = ".(int)$categoryID); } // ***************************************************************************** // Purpose calculate a path to the category ( $categoryID ) // Inputs // Remarks // Returns path to category function catCalculatePathToCategory( $categoryID ) { if (!$categoryID) return NULL; $path = array(); $q = db_query("select count(*) from ".CATEGORIES_TABLE. " where categoryID=".(int)$categoryID); $row = db_fetch_row($q); if ( $row[0] == 0 ) return $path; do { $q = db_query("select categoryID, parent, cat_h1 as name, UID FROM ". CATEGORIES_TABLE." WHERE categoryID=".(int)$categoryID); $row = db_fetch_row($q); $path[] = $row; //if ($row["parent"] == $row["categoryID"]) break; $categoryID = $row["parent"]; } while ( $categoryID ); //now reverse $path $path = array_reverse($path); return $path; } // ***************************************************************************** // Purpose calculate a path to the category ( $categoryID ) // Inputs // Remarks // Returns path to category function catCalculatePathToCategoryA( $categoryID ) { if (!$categoryID) return NULL; $path = array(); $q = db_query("select count(*) from ".CATEGORIES_TABLE. " where categoryID=".(int)$categoryID); $row = db_fetch_row($q); if ( $row[0] == 0 ) return $path; $curr = $categoryID; do { $q = db_query("select categoryID, parent, name FROM ". CATEGORIES_TABLE." WHERE categoryID=".(int)$categoryID); $row = db_fetch_row($q); if($categoryID != $curr) $path[] = $row; if ( $categoryID == 1 ) break; $categoryID = $row["parent"]; } while ( 1 ); //now reverse $path $path = array_reverse($path); return $path; } function _deleteSubCategories( $parent ) { $q1 = db_query("select picture FROM ".CATEGORIES_TABLE." WHERE categoryID=".(int)$parent); $r = db_fetch_row($q1); if ($r["picture"] && file_exists("data/category/".$r["picture"])) unlink("data/category/".$r["picture"]); $q = db_query("select categoryID FROM ".CATEGORIES_TABLE." WHERE parent=".(int)$parent); while ($row = db_fetch_row($q)){ $qp = db_query("select productID FROM ".PRODUCTS_TABLE." where categoryID=".(int)$row["categoryID"] ); while ( $picture = db_fetch_row($qp) ) { DeleteThreePictures2($picture["productID"]); } db_query("delete FROM ".PRODUCTS_TABLE." WHERE categoryID=".(int)$row["categoryID"]); _deleteSubCategories( $row["categoryID"] ); } db_query("delete FROM ".CATEGORIES_TABLE." WHERE parent=".(int)$parent); } // ***************************************************************************** // Purpose deletes category // Inputs // $categoryID - ID of category to be deleted // Remarks delete also all subcategories, all prodoctes remove into root // Returns nothing function catDeleteCategory( $categoryID ) { _deleteSubCategories( $categoryID ); $q=db_query("select productID FROM ".PRODUCTS_TABLE." where categoryID=".(int)$categoryID ); if ( $picture=db_fetch_row($q) ) { DeleteThreePictures2($picture["productID"]); } db_query("delete FROM ".PRODUCTS_TABLE." WHERE categoryID=".(int)$categoryID); db_query("delete FROM ".CATEGORIES_TABLE." WHERE parent=".(int)$categoryID); $q = db_query("select picture FROM ".CATEGORIES_TABLE." WHERE categoryID=".(int)$categoryID); $r = db_fetch_row($q); if ($r["picture"] && file_exists("data/category/".$r["picture"])) unlink("data/category/".$r["picture"]); db_query("delete FROM ".CATEGORIES_TABLE." WHERE categoryID=".(int)$categoryID); } ?>ERROR: Couldn't find language file!