/** * Recursive algorithm to restrict all sub_categories of a specified category to a specified product_type */ function zen_restrict_sub_categories($zf_cat_id, $zf_type) { global $db; $zp_sql = "select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int) $zf_cat_id . "'"; $zq_sub_cats = $db->Execute($zp_sql); while (!$zq_sub_cats->EOF) { $zp_sql = "select * from " . TABLE_PRODUCT_TYPES_TO_CATEGORY . "\n where category_id = '" . (int) $zq_sub_cats->fields['categories_id'] . "'\n and product_type_id = '" . (int) $zf_type . "'"; $zq_type_to_cat = $db->Execute($zp_sql); if ($zq_type_to_cat->RecordCount() < 1) { $za_insert_sql_data = array('category_id' => (int) $zq_sub_cats->fields['categories_id'], 'product_type_id' => (int) $zf_type); zen_db_perform(TABLE_PRODUCT_TYPES_TO_CATEGORY, $za_insert_sql_data); } zen_restrict_sub_categories($zq_sub_cats->fields['categories_id'], $zf_type); $zq_sub_cats->MoveNext(); } }
$sql = "select * from " . TABLE_PRODUCT_TYPES_TO_CATEGORY . "\n where category_id = '" . zen_db_prepare_input($_POST['categories_id']) . "'\n and product_type_id = '" . zen_db_prepare_input($_POST['restrict_type']) . "'"; $type_to_cat = $db->Execute($sql); if ($type_to_cat->RecordCount() < 1) { //@@TODO find all sub-categories and restrict them as well. $insert_sql_data = array('category_id' => zen_db_prepare_input($_POST['categories_id']), 'product_type_id' => zen_db_prepare_input($_POST['restrict_type'])); zen_db_perform(TABLE_PRODUCT_TYPES_TO_CATEGORY, $insert_sql_data); /* // moved below so evaluated separately from current category if (isset($_POST['add_type_all'])) { zen_restrict_sub_categories($_POST['categories_id'], $_POST['restrict_type']); } */ } // add product type restrictions to subcategories if not already set if (isset($_POST['add_type_all'])) { zen_restrict_sub_categories($_POST['categories_id'], $_POST['restrict_type']); } $action = "edit"; zen_redirect(zen_href_link(FILENAME_CATEGORIES, 'action=edit_category&cPath=' . $cPath . '&cID=' . zen_db_prepare_input($_POST['categories_id']))); } if (isset($_POST['categories_id'])) { $categories_id = zen_db_prepare_input($_POST['categories_id']); } $sort_order = zen_db_prepare_input($_POST['sort_order']); $sql_data_array = array('sort_order' => (int) $sort_order); if ($action == 'insert_category') { $insert_sql_data = array('parent_id' => $current_category_id, 'date_added' => 'now()'); $sql_data_array = array_merge($sql_data_array, $insert_sql_data); zen_db_perform(TABLE_CATEGORIES, $sql_data_array); $categories_id = zen_db_insert_id(); // check if [arent is restricted
function zen_restrict_sub_categories($zf_cat_id, $zf_type) { global $gBitDb; $zp_sql = "SELECT `categories_id` FROM " . TABLE_CATEGORIES . " WHERE `parent_id` = '" . $zf_cat_id . "'"; $zq_sub_cats = $gBitDb->Execute($zp_sql); while (!$zq_sub_cats->EOF) { $zp_sql = "SELECT * FROM " . TABLE_PRODUCT_TYPES_TO_CATEGORY . "\n\t\t\t\t\t\t\t\t\t\t\t\t WHERE `category_id` = '" . $zq_sub_cats->fields['categories_id'] . "'\n\t\t\t\t\t\t\t\t\t\t\t\t and `product_type_id` = '" . $zf_type . "'"; $zq_type_to_cat = $gBitDb->Execute($zp_sql); if ($zq_type_to_cat->RecordCount() < 1) { $za_insert_sql_data = array('category_id' => $zq_sub_cats->fields['categories_id'], 'product_type_id' => $zf_type); $gBitDb->associateInsert(TABLE_PRODUCT_TYPES_TO_CATEGORY, $za_insert_sql_data); } zen_restrict_sub_categories($zq_sub_cats->fields['categories_id'], $zf_type); $zq_sub_cats->MoveNext(); } }