0
votes

There is this extension for Joomla called Jreviews. It has a module which lists the section and categories of Joomla in a tree structure. I wanted to convert it into a double drop down.

I got one script from that makes the section and categories of a Joomla website in a double drop down. I just had to modify its resultant URL, to match it with Jreviews tree structure URL and I would be done.

In the script, there's this piece of code that I discovered:

var iCatID = document.getElementById('catselect_cat').value;
var iSecID = document.getElementById('catselect_sec').value;
if (iCatID != 0)
      **window.location= jsLiveSite+'index.php?option=com_content&view=category&layout=blog&id='+iCatID+'&Itemid='+iItemID;**
else
    alert('Please select a section and a category');

In this piece of code, if I could replace the bold line with Jreviews directory module url's I would get the required result. In my site, the Jreviews directory has URL's for categories like this:

http://www.yoursite.com/component/jreviews/jreviews_directory_name/section_name/category_name_alias/

Is there a way to store the section name and category alias in a variable when we have their ids?

I'll post the whole drop down script which goes like this:

defined('_JEXEC') or die('Restricted access'); global $mainframe; $database = & JFactory::getDBO(); $itemid = trim($params->get('linkmenu'));

// select the published sections $query = "SELECT s.id, s.title FROM #__sections AS s WHERE s.published=1";

$database->setQuery($query); $sections = $database->loadObjectList();

$query = "SELECT c.id, c.title, c.section FROM #__categories AS c " ."WHERE c.published=1";

$database->setQuery($query ); $categories = $database->loadObjectList();

// Generate javascript functions and varaibles echo (" var jsCat = [];

jsCat=[");
foreach ($categories as $item)
{
    echo("[".$item->id.",\"".$item->title."\",\"".$item->section."\"],");
}

echo("[0,\"Select Category\",\"0\"]]; \n

var iItemID="); echo($itemid); echo(" var jsLiveSite='"); echo(JURI::base()); echo("'; \n

function jsRemoveAll(cControl) { var cCat = document.getElementById(cControl);

for( var i=(cCat.options.length - 1); i >=0 ; i--)
{
    cCat.remove(i);
}

}

function jsOnSecSelect() { jsRemoveAll('catselect_cat');

var cSec = document.getElementById('catselect_sec');
var cCat = document.getElementById('catselect_cat');

var iSecID = cSec.options[cSec.selectedIndex].value;

for (var i=0; i<jsCat.length; i++)
{
    if (jsCat[i][2] == iSecID)
    {
        var cOpt = document.createElement(\"option\");
        cOpt.value = jsCat[i][0];
        cOpt.text = jsCat[i][1];
        cOpt.secID  = jsCat[i][2];
        cCat.options.add(cOpt);
    }
}

}

function jsOnFormSubmit() {

var iCatID = document.getElementById('catselect_cat').value;
var iSecID = document.getElementById('catselect_sec').value;
if (iCatID != 0)
    window.location= jsLiveSite+'index.php?option=com_content&view=category&layout=blog&id='+iCatID+'&Itemid='+iItemID;
else
    alert('Please select a section and a category');

} ");

echo(""); //Generate form echo("

Select Section"); foreach ($sections as $item) { echo("id."'>".$item->title." \n" ); } echo(" \n Select Category \n \n

");

?>

1

1 Answers

0
votes

From what you have posted, you are looking in the wrong place. The code you posted is simply taking values from a form (most likely) and using them to create the URL. At this point in the code it is unlikely that any other information related to the Section or Category is available. Your best bet is to find the code that creates the form. Then it is a matter of slightly altering the query or even just changing what fields you use to create the forms. We would need to see the code that creates the drop downs to give you a more specific answer.