_:n23fcd63c62e9415c8f29b83dd37ab358xb33
<http://schema.org/text>
"I'm having to pot my code in seperate replies as its too long for an all in one hit...\n \n \n \n\n\nif (isset($HTTP_POST_VARS['categories_id'])) {\n\t  $categories_id = tep_db_prepare_input($HTTP_POST_VARS['categories_id']);\n\t  $categories = tep_get_category_tree($categories_id, '', '0', '', true);\n\t  $products = array();\n\t  $products_delete = array();\n\t  for ($i=0, $n=sizeof($categories); $i&lt;$n; $i++) {\n\t    $product_ids_query = tep_db_query(\"select products_id from \" . TABLE_PRODUCTS_TO_CATEGORIES . \" where categories_id = '\" . (int)$categories[$i]['id'] . \"'\");\n\t    while ($product_ids = tep_db_fetch_array($product_ids_query)) {\n\t\t  $products[$product_ids['products_id']]['categories'][] = $categories[$i]['id'];\n\t    }\n\t  }\n\t  reset($products);\n\t  while (list($key, $value) = each($products)) {\n\t    $category_ids = '';\n\t    for ($i=0, $n=sizeof($value['categories']); $i&lt;$n; $i++) {\n\t\t  $category_ids .= \"'\" . (int)$value['categories'][$i] . \"', \";\n\t    }\n\t    $category_ids = substr($category_ids, 0, -2);\n\t    $check_query = tep_db_query(\"select count(*) as total from \" . TABLE_PRODUCTS_TO_CATEGORIES . \" where products_id = '\" . (int)$key . \"' and categories_id not in (\" . $category_ids . \")\");\n\t    $check = tep_db_fetch_array($check_query);\n\t    if ($check['total'] &lt; '1') {\n\t\t  $products_delete[$key] = $key;\n\t    }\n\t  }\n// removing categories can be a lengthy process\n\t  tep_set_time_limit(0);\n\t  for ($i=0, $n=sizeof($categories); $i&lt;$n; $i++) {\n\t    tep_remove_category($categories[$i]['id']);\n\t  }\n\t  reset($products_delete);\n\t  while (list($key) = each($products_delete)) {\n\t    tep_remove_product($key);\n\t  }\n    }\n    if (USE_CACHE == 'true') {\n\t  tep_reset_cache_block('categories');\n\t  tep_reset_cache_block('also_purchased');\n    }\n    tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath));\n    break;\n  case 'delete_product_confirm':\n    if (isset($HTTP_POST_VARS['products_id']) &amp;&amp; isset($HTTP_POST_VARS['product_categories']) &amp;&amp; is_array($HTTP_POST_VARS['product_categories'])) {\n\t  $product_id = tep_db_prepare_input($HTTP_POST_VARS['products_id']);\n\t  $product_categories = $HTTP_POST_VARS['product_categories'];\n\t  // BOF Separate Pricing Per Customer\n\t  tep_db_query(\"delete from \" . TABLE_PRODUCTS_GROUPS . \" where products_id = '\" . tep_db_input($product_id) . \"' \");\n\t  // EOF Separate Pricing Per Customer\n\t  for ($i=0, $n=sizeof($product_categories); $i&lt;$n; $i++) {\n\t    tep_db_query(\"delete from \" . TABLE_PRODUCTS_TO_CATEGORIES . \" where products_id = '\" . (int)$product_id . \"' and categories_id = '\" . (int)$product_categories[$i] . \"'\");\n\t  }\n   // BOF QPBPP for SPPC\n\t    tep_db_query(\"delete from \" . TABLE_PRODUCTS_PRICE_BREAK . \" where products_id = '\" . (int)$product_id . \"'\");\n// EOF QPBPP for SPPC\n\n\t  $product_categories_query = tep_db_query(\"select count(*) as total from \" . TABLE_PRODUCTS_TO_CATEGORIES . \" where products_id = '\" . (int)$product_id . \"'\");\n\t  $product_categories = tep_db_fetch_array($product_categories_query);\n\t  if ($product_categories['total'] == '0') {\n\t    tep_remove_product($product_id);\n\t  }\n    }\n    if (USE_CACHE == 'true') {\n\t  tep_reset_cache_block('categories');\n\t  tep_reset_cache_block('also_purchased');\n    }\n    tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath));\n    break;\n  case 'move_category_confirm':\n    if (isset($HTTP_POST_VARS['categories_id']) &amp;&amp; ($HTTP_POST_VARS['categories_id'] != $HTTP_POST_VARS['move_to_category_id'])) {\n\t  $categories_id = tep_db_prepare_input($HTTP_POST_VARS['categories_id']);\n\t  $new_parent_id = tep_db_prepare_input($HTTP_POST_VARS['move_to_category_id']);\n\t  $path = explode('_', tep_get_generated_category_path_ids($new_parent_id));\n\t  if (in_array($categories_id, $path)) {\n\t    $messageStack-&gt;add_session(ERROR_CANNOT_MOVE_CATEGORY_TO_PARENT, 'error');\n\t    tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&amp;cID=' . $categories_id));\n\t  } else {\n\t    tep_db_query(\"update \" . TABLE_CATEGORIES . \" set parent_id = '\" . (int)$new_parent_id . \"', last_modified = now() where categories_id = '\" . (int)$categories_id . \"'\");\n\t    if (USE_CACHE == 'true') {\n\t\t  tep_reset_cache_block('categories');\n\t\t  tep_reset_cache_block('also_purchased');\n\t    }\n\n\n\n"
<https://forums.oscommerce.com/topic/53436-seperate-pricing-per-customer-v35/?page=235&tab=comments#comment-1620780>