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 advsearch2($option) { global $savantConf, $Itemid, $mtconf; $database =& JFactory::getDBO(); $document =& JFactory::getDocument(); require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'mfields.class.php'; require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'mAdvancedSearch.class.php'; $document->setTitle(JText::_('Advanced search results')); # Load up search ID if available $search_id = JRequest::getInt('search_id', 0); if ($search_id > 0) { $database->setQuery('SELECT search_text FROM #__mt_searchlog WHERE search_id = ' . $database->quote($search_id)); $post = unserialize($database->loadResult()); } else { $post = JRequest::get('post'); } # Load all published CORE & custom fields $database->setQuery("SELECT cf.*, '0' AS link_id, '' AS value, '0' AS attachment, ft.ft_class FROM #__mt_customfields AS cf " . "\nLEFT JOIN #__mt_fieldtypes AS ft ON ft.field_type=cf.field_type" . "\nWHERE cf.published='1' ORDER BY ordering ASC"); $fields = new mFields($database->loadObjectList()); $searchParams = $fields->loadSearchParams($post); $advsearch = new mAdvancedSearch($database); if (intval($post['searchcondition']) == 2) { $advsearch->useAndOperator(); } else { $advsearch->useOrOperator(); } # Search Category $search_cat = intval($post['cat_id']); $only_subcats_sql = ''; if ($search_cat > 0 && is_int($search_cat)) { $mtCats = new mtCats($database); $subcats = $mtCats->getSubCats_Recursive($search_cat, true); $subcats[] = $search_cat; if (!empty($subcats)) { $advsearch->limitToCategory($subcats); } } $fields->resetPointer(); while ($fields->hasNext()) { $field = $fields->getField(); $searchFields = $field->getSearchFields(); if (isset($searchFields[0]) && isset($searchParams[$searchFields[0]]) && $searchParams[$searchFields[0]] != '') { foreach ($searchFields as $searchField) { $searchFieldValues[] = $searchParams[$searchField]; } if (!empty($searchFieldValues) && $searchFieldValues[0] != '') { if (is_array($searchFieldValues[0]) && empty($searchFieldValues[0][0])) { // Do nothing } else { $tmp_where_cond = call_user_func_array(array($field, 'getWhereCondition'), $searchFieldValues); if (!is_null($tmp_where_cond)) { $advsearch->addCondition($field, $searchFieldValues); } } } unset($searchFieldValues); } $fields->next(); } $limit = JRequest::getInt('limit', $mtconf->get('fe_num_of_searchresults'), 'get'); $limitstart = JRequest::getInt('limitstart', 0, 'get'); if ($limitstart < 0) { $limitstart = 0; } $advsearch->search(1, 1); // Total Results $total = $advsearch->getTotal(); if ($search_id <= 0 && $total > 0) { # Store search for later retrieval. if ($search_id < 1) { $database->setQuery("INSERT INTO #__mt_searchlog (search_text) VALUES ('" . serialize($post) . "')"); if (!$database->query()) { echo $database->getErrorMsg(); } } # Get the above search ID $database->setQuery("SELECT search_id FROM #__mt_searchlog WHERE search_text ='" . serialize($post) . "'"); $database->query(); $search_id = $database->loadResult(); $document->addCustomTag('<meta http-equiv="Refresh" content="1; URL=' . JRoute::_("index.php?option=com_mtree&task=advsearch2&search_id={$search_id}&Itemid={$Itemid}") . '">'); # Savant template $savant = new Savant2($savantConf); $savant->assign('redirect_url', JRoute::_("index.php?option=com_mtree&task=advsearch2&search_id={$search_id}&Itemid={$Itemid}")); $savant->display('page_advSearchRedirect.tpl.php'); } else { $links = $advsearch->loadResultList($limitstart, $limit); # Page Navigation jimport('joomla.html.pagination'); $pageNav = new JPagination($total, $limitstart, $limit); # Pathway $pathWay = new mtPathWay(); # Savant template $savant = new Savant2($savantConf); assignCommonListlinksVar($savant, $links, $pathWay, $pageNav); $savant->assign('search_id', $search_id); $savant->display('page_advSearchResults.tpl.php'); } }
function getSubCats_Recursive($cat_id, $published_only = true) { $database =& JFactory::getDBO(); $mtCats = new mtCats($database); if ($cat_id > 0) { $subcats = $mtCats->getSubCats_Recursive($cat_id, $published_only); } $subcats[] = $cat_id; return $subcats; }