function remove_categories($category_id)
 {
     $categories = xtc_get_category_tree($category_id, '', '0', '', true);
     $products = array();
     $products_delete = array();
     for ($i = 0, $n = sizeof($categories); $i < $n; $i++) {
         $product_ids_query = xtc_db_query("SELECT products_id\n                                                     FROM " . TABLE_PRODUCTS_TO_CATEGORIES . "\n                                                     WHERE categories_id = '" . $categories[$i]['id'] . "'");
         while ($product_ids = xtc_db_fetch_array($product_ids_query)) {
             $products[$product_ids['products_id']]['categories'][] = $categories[$i]['id'];
         }
     }
     reset($products);
     while (list($key, $value) = each($products)) {
         $category_ids = '';
         for ($i = 0, $n = sizeof($value['categories']); $i < $n; $i++) {
             $category_ids .= '\'' . $value['categories'][$i] . '\', ';
         }
         $category_ids = substr($category_ids, 0, -2);
         $check_query = xtc_db_query("SELECT COUNT(*) AS total\n                                                 FROM " . TABLE_PRODUCTS_TO_CATEGORIES . "\n                                                 WHERE products_id = '" . $key . "'\n                                                 AND categories_id NOT IN (" . $category_ids . ")");
         $check = xtc_db_fetch_array($check_query);
         if ($check['total'] < '1') {
             $products_delete[$key] = $key;
         }
     }
     // Removing categories can be a lengthy process
     @xtc_set_time_limit(0);
     for ($i = 0, $n = sizeof($categories); $i < $n; $i++) {
         $this->remove_category($categories[$i]['id']);
     }
     reset($products_delete);
     while (list($key) = each($products_delete)) {
         $this->remove_product($key);
     }
 }
 function make_categorie_tree()
 {
     $categories = xtc_get_category_tree();
     foreach ($categories as $i => $cat) {
         if ($i == 0) {
             continue;
         }
         // ignore "top" categorie
         $count = substr_count($cat['text'], '&nbsp;');
         $categories[$i]['text'] = str_replace('&nbsp;', '', $cat['text']);
         $last[$count] = $cat['id'];
         $last_inx[$count] = $i;
         $cat_id = $cat['id'];
         $parent_id = $count > 0 ? $last[$count - 3] : 0;
         $categories[$i]['parent_id'] = $parent_id;
         $categories[$i]['parent_index'] = $count > 0 ? $last_inx[$count - 3] : 0;
     }
     $this->categorie_tree = $categories;
 }
             if (is_array($_POST['multi_products'])) {
                 $cat_tree = xtc_get_category_tree('0', '', '0');
             } else {
                 $cat_tree = xtc_get_category_tree();
             }
             $tree = '';
             for ($i = 0; $n = sizeof($cat_tree), $i < $n; $i++) {
                 $tree .= '<input type="checkbox" name="dest_cat_ids[]" value="' . $cat_tree[$i]['id'] . '"><font size="1">' . $cat_tree[$i]['text'] . '</font><br />';
             }
             $contents[] = array('text' => $tree . '<br /><hr noshade>');
             $contents[] = array('text' => '<b>' . TEXT_SINGLECOPY . '</b><br />' . TEXT_SINGLECOPY_DESC);
         }
         if (is_array($_POST['multi_products'])) {
             $category_tree = xtc_get_category_tree('0', '', '0');
         } else {
             $category_tree = xtc_get_category_tree();
         }
         $contents[] = array('text' => '<br />' . TEXT_SINGLECOPY_CATEGORY . '<br />' . xtc_draw_pull_down_menu('dest_category_id', $category_tree, $current_category_id) . '<br /><hr noshade>');
         $contents[] = array('text' => '<strong>' . TEXT_HOW_TO_COPY . '</strong><br />' . xtc_draw_radio_field('copy_as', 'link', true) . ' ' . TEXT_COPY_AS_LINK . '<br />' . xtc_draw_radio_field('copy_as', 'duplicate') . ' ' . TEXT_COPY_AS_DUPLICATE . '<br /><hr noshade>');
         $contents[] = array('text' => '<br />' . TEXT_HOW_TO_LINK . '<br />' . '<input type="checkbox" name="link_to_product" value="link_to_product" checked="checked"><font size="1">' . TEXT_HOW_TO_LINK_INFO . '</font><br /><hr noshade>');
         $contents[] = array('text' => '<strong>' . TEXT_ATTRIBUTE_COPY . '</strong><br />' . '<input type="checkbox" name="attr_copy" value="attr_copy"><font size="1">' . TEXT_ATTRIBUTE_COPY_INFO . '</font><br /><hr noshade>');
         $contents[] = array('align' => 'center', 'text' => '<input class="btn btn-default" type="submit" name="multi_copy_confirm" value="' . BUTTON_COPY . '"> <a class="btn btn-default" href="' . xtc_href_link(FILENAME_CATEGORIES, xtc_get_all_get_params(array('cPath', 'action', 'pID', 'cID')) . 'cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&cID=' . $cInfo->categories_id) . '">' . BUTTON_CANCEL . '</a>');
         //close multi-action form
         $contents[] = array('text' => '</form>');
     }
     // multi_copy confirm ENDS
     break;
 default:
     if ($rows > 0) {
         if (isset($cInfo) && is_object($cInfo)) {
             // category info box contents
/**
 * xtc_get_category_tree()
 *
 * @param string $parent_id
 * @param string $spacing
 * @param string $exclude
 * @param string $category_tree_array
 * @param bool $include_itself
 * @return
 */
function xtc_get_category_tree($parent_id = '0', $spacing = '', $exclude = '', $category_tree_array = '', $include_itself = false)
{
    if (!is_array($category_tree_array)) {
        $category_tree_array = array();
    }
    if (sizeof($category_tree_array) < 1 && $exclude != '0') {
        $category_tree_array[] = array('id' => '0', 'text' => TEXT_TOP);
    }
    if ($include_itself) {
        $category_query = xtc_db_query("select cd.categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " cd where cd.language_id = '" . (int) $_SESSION['languages_id'] . "' and cd.categories_id = '" . $parent_id . "'");
        $category = xtc_db_fetch_array($category_query);
        $category_tree_array[] = array('id' => $parent_id, 'text' => $category['categories_name']);
    }
    $categories_query = xtc_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = cd.categories_id and cd.language_id = '" . (int) $_SESSION['languages_id'] . "' and c.parent_id = '" . $parent_id . "' order by c.sort_order, cd.categories_name");
    while ($categories = xtc_db_fetch_array($categories_query)) {
        if ($exclude != $categories['categories_id']) {
            $category_tree_array[] = array('id' => $categories['categories_id'], 'text' => $spacing . $categories['categories_name']);
        }
        $category_tree_array = xtc_get_category_tree($categories['categories_id'], $spacing . '&nbsp;&nbsp;&nbsp;', $exclude, $category_tree_array);
    }
    return $category_tree_array;
}