function copyCats2($cat_id, $option) { global $mainframe; $database =& JFactory::getDBO(); $new_cat_parent_id = JRequest::getInt('new_cat_parent', '', 'post'); $copy_subcats = JRequest::getInt('copy_subcats', 1, 'post'); $copy_relcats = JRequest::getInt('copy_relcats', 0, 'post'); $copy_listings = JRequest::getInt('copy_listings', 1, 'post'); $copy_reviews = JRequest::getInt('copy_reviews', 0, 'post'); $reset_hits = JRequest::getInt('reset_hits', 1, 'post'); $reset_rating = JRequest::getInt('reset_rating', 1, 'post'); $total_cats = 0; $total_links = 0; $row = new mtCats($database); if (count($cat_id) > 0) { foreach ($cat_id as $id) { $database->setQuery('SELECT cat_id, lft, rgt FROM #__mt_cats WHERE cat_id = ' . $database->quote($new_cat_parent_id)); $new_cat_parent = $database->loadObject(); $copied_cat_ids = $row->copyCategory($id, $new_cat_parent->cat_id, $copy_subcats, $copy_relcats, $copy_listings, $copy_reviews, $reset_hits, $reset_rating, null); // Retrieve category's count $database->setQuery('SELECT cat_cats, cat_links FROM #__mt_cats WHERE cat_id = ' . $database->quote($id) . ' LIMIT 1'); $total = $database->loadObject(); $total_cats++; $total_cats += $total->cat_cats; $total_links += $total->cat_links; //print_r( $copied_cat_ids ); // Update all category's lft and rgt to the right of this new node to accommodate new categories $database->setQuery("UPDATE #__mt_cats SET lft = lft+" . 2 * count($copied_cat_ids) . " WHERE lft >= {$new_cat_parent->rgt} AND cat_id NOT IN (" . implode(",", $copied_cat_ids) . ")"); $database->query(); $database->setQuery("UPDATE #__mt_cats SET rgt = rgt+" . 2 * count($copied_cat_ids) . " WHERE rgt >= {$new_cat_parent->rgt} AND cat_id NOT IN (" . implode(",", $copied_cat_ids) . ")"); $database->query(); } // End foreach } // End if smartCountUpdate($new_cat_parent_id, $total_links, $total_cats); $mainframe->redirect("index2.php?option={$option}&task=listcats&cat_id={$new_cat_parent->cat_id}"); }