function moveCats2($cat_id, $option) { global $mainframe; $database =& JFactory::getDBO(); $new_cat_parent_id = JRequest::getInt('new_cat_parent', '', 'post'); if ($new_cat_parent_id == 0) { $database->setQuery("SELECT cat_id, lft, rgt FROM #__mt_cats WHERE cat_parent = -1"); $new_cat_parent = $database->loadObject(); } else { $database->setQuery('SELECT cat_id, lft, rgt FROM #__mt_cats WHERE cat_id = ' . $database->quote($new_cat_parent_id)); $new_cat_parent = $database->loadObject(); } if (in_array($new_cat_parent_id, $cat_id)) { $mainframe->redirect("index2.php?option={$option}", JText::_('You can not move categories in to itself.')); return; } $row = new mtCats($database); # Loop every moving categories if (count($cat_id) > 0) { $total_cats = 0; $total_links = 0; foreach ($cat_id as $id) { $row->load($id); $total_cats++; $total_cats += $row->cat_cats; $total_links += $row->cat_links; # Assign new cat_parent $old_cat_parent = $row->cat_parent; if ($new_cat_parent_id == 0) { $row->cat_parent = 0; } else { $row->cat_parent = $new_cat_parent->cat_id; } if (!$row->store()) { echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n"; exit; } $inc = $new_cat_parent->rgt - $row->lft; $original_row_lft = $row->lft; $original_row_rgt = $row->rgt; $subcats = $row->getSubCats_Recursive($id); # Categories are moved to the right if ($row->rgt < $new_cat_parent->rgt) { # (1) 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($subcats) . " WHERE lft >= {$new_cat_parent->rgt}"); $database->query(); $database->setQuery("UPDATE #__mt_cats SET rgt = rgt+" . 2 * count($subcats) . " WHERE rgt >= {$new_cat_parent->rgt}"); $database->query(); # (2) Update lft & rgt values of moving categories $database->setQuery("UPDATE #__mt_cats SET lft = lft + {$inc}, rgt = rgt + {$inc} WHERE lft >= {$row->lft} AND rgt <= {$row->rgt}"); $database->query(); # (3) Finally, update all lft & rgt from the old node $database->setQuery("UPDATE #__mt_cats SET lft = lft-" . 2 * count($subcats) . " WHERE lft >= {$original_row_lft}"); $database->query(); $database->setQuery("UPDATE #__mt_cats SET rgt = rgt-" . 2 * count($subcats) . " WHERE rgt >= {$original_row_rgt}"); $database->query(); # Categories are moved to the left } else { # (1) 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($subcats) . " WHERE lft >= {$new_cat_parent->rgt}"); $database->query(); $database->setQuery("UPDATE #__mt_cats SET rgt = rgt+" . 2 * count($subcats) . " WHERE rgt >= {$new_cat_parent->rgt}"); $database->query(); # (2) Update lft & rgt values of moving categories $database->setQuery("UPDATE #__mt_cats SET lft = lft +({$inc} - " . 2 * count($subcats) . "), rgt = rgt +({$inc} - " . 2 * count($subcats) . ") WHERE lft >= ({$row->lft} + " . 2 * count($subcats) . ") AND rgt <= ({$row->rgt} + " . 2 * count($subcats) . ")"); $database->query(); # (3) Finally, update all lft & rgt from the old node $database->setQuery("UPDATE #__mt_cats SET lft = lft-" . 2 * count($subcats) . " WHERE lft >= {$original_row_lft} + " . 2 * count($subcats)); $database->query(); $database->setQuery("UPDATE #__mt_cats SET rgt = rgt-" . 2 * count($subcats) . " WHERE rgt >= {$original_row_rgt} + " . 2 * count($subcats)); $database->query(); } } // End foreach smartCountUpdate_catMove($old_cat_parent, $new_cat_parent->cat_id, $total_links, $total_cats); } // End if $mainframe->redirect("index2.php?option={$option}&task=listcats&cat_id={$row->cat_parent}"); }
function addcategory2($option) { global $Itemid, $mtconf, $mainframe; // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); $database =& JFactory::getDBO(); $my =& JFactory::getUser(); $jdate = JFactory::getDate(); $now = $jdate->toMySQL(); # Get cat_parent $cat_parent = JRequest::getInt('cat_parent', 0); # Check if any malicious user is trying to submit link if ($mtconf->get('user_addcategory') == 1 && $my->id <= 0) { echo _NOT_EXIST; } else { # Allowed $post = JRequest::get('post'); $row = new mtCats($database); if (!$row->bind($post)) { echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n"; exit; } $isNew = $row->cat_id < 1; # Assignment for new record if ($isNew) { $jdate = JFactory::getDate(); $row->cat_created = $now; // Required approval if ($mtconf->get('needapproval_addcategory')) { $row->cat_approved = '0'; } else { $row->cat_approved = 1; $row->cat_published = 1; $cache =& JFactory::getCache('com_mtree'); $cache->clean(); } } else { # Assignment for exsiting record $row->cat_modified = $now; } # OK. Store new category into database if (!$row->store()) { echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n"; exit; } if ($isNew && !$mtconf->get('needapproval_addcategory')) { $row->updateLftRgt(); $row->updateCatCount(1); } $mainframe->redirect(JRoute::_("index.php?option={$option}&task=listcats&cat_id={$cat_parent}&Itemid={$Itemid}"), $mtconf->get('needapproval_addcategory') ? JText::_('Category will be reviewed') : JText::_('Category have been added')); } }
function addcategory2( $option ) { global $Itemid, $mtconf; $app = JFactory::getApplication('site'); // Check for request forgeries JRequest::checkToken() or jexit( 'Invalid Token' ); $database =& JFactory::getDBO(); $my =& JFactory::getUser(); $jdate = JFactory::getDate(); $now = $jdate->toMySQL(); # Get cat_parent $cat_parent = JRequest::getInt('cat_parent', 0); # Check if any malicious user is trying to submit link if ( $mtconf->get('user_addcategory') == 1 && $my->id <= 0 ) { echo JText::_( 'NOT_EXIST' ); } elseif( $mtconf->get('user_addcategory') == '-1' ) { # Add category is disabled JError::raiseError(404, JText::_('Resource Not Found')); } else { # Allowed $post = JRequest::get( 'post' ); $row = new mtCats( $database ); if (!$row->bind( $post )) { echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; exit(); } $isNew = $row->cat_id < 1; # Assignment for new record if ($isNew) { $jdate = JFactory::getDate(); $row->cat_created = $now; $row->alias = JFilterOutput::stringURLSafe($row->cat_name); // Required approval if ( $mtconf->get('needapproval_addcategory') ) { $row->cat_approved = '0'; } else { $row->cat_approved = 1; $row->cat_published = 1; $cache = &JFactory::getCache('com_mtree'); $cache->clean(); } } else { # Assignment for exsiting record $row->cat_modified = $now; } # OK. Store new category into database if (!$row->store()) { echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; exit(); } if ( $isNew && !$mtconf->get('needapproval_addcategory')) { $row->updateLftRgt(); $row->updateCatCount( 1 ); } $app->redirect( JRoute::_("index.php?option=$option&task=listcats&cat_id=$cat_parent&Itemid=$Itemid"), ( ($mtconf->get('needapproval_addcategory')) ? JText::_( 'Category will be reviewed' ) : JText::_( 'Category have been added' )) ); } }