<?php
     function getMainSubCategories($parentId = null, $recursionLevel = 1){
    	if(is_null($parentId)){
    		$parentId = Mage::app()->getStore()->getRootCategoryId();
    	}
		$category = Mage::getModel('catalog/category');
    	$mainSubCategories = $category->getCategories($parentId, $recursionLevel, true, true, true);
		return $mainSubCategories;
    }
    function getProductCollection()
    {
    	$categoryId = Mage::app()->getRequest()->getParam('catid');
    	if(empty($categoryId)){
    		$categoryId = Mage::app()->getRequest()->getPost('catid');
    	}

    	if($categoryId){
    		$category = Mage::getModel('catalog/category')->load($categoryId);
    	} else {
    		return array();
    	}
    	if(!$category->getId()){
    		return array();
    	}
    	$storeId = Mage::app()->getStore()->getId();

    	$productCollection = $category->getProductCollection();
        $productCollection	->addMinimalPrice()
							->addFinalPrice()
							->addTaxPercents()
				            ->addAttributeToSelect(array('product_url','name','price','description','manufacturer','image','model'));

       	Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($productCollection);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($productCollection);
        $productCollection->addUrlRewrite($category->getId());

        return $productCollection;
    }

    function getSubcategories($category){

		$baseUrl = Mage::getBaseUrl();
		$realBaseUrl = str_replace("xmlcatslist.php/", "catfeed/", $baseUrl);

		 $subCategories = getSubCategories1($category->getId());
		 $categoryCount = count($subCategories);
		 $str= "";
         if($categoryCount){
			$str = "<ul class='tree'>";
        	 $j = 1;
			foreach($subCategories as $subCategory):
				$last = "";
				if($j == $categoryCount){
					$last = "class = 'last'";
				}
				$str.= "<li $last >";
				$str.= "<a href='".$realBaseUrl."xmlproduct.php?catid=".$subCategory->getId()."'>".Mage::helper('core')->__("%s", $subCategory->getName())."</a>";
				$str.= getSubcategories($subCategory);
			 	$str.= "</li>";
			 	$j++;
        	endforeach;

        	$str.= "</ul>";
         }
         return $str;
    }
     function getSubCategories1($parentId = null, $recursionLevel = 1){
    	//Mage::log("From Ajax Presentation: ".$parentId);
		$category = Mage::getModel('catalog/category');
    	$mainSubCategories = $category->getCategories($parentId, $recursionLevel, true, true, true);
		return $mainSubCategories;
    }
     function getMainCategory(){

    	$parentId = $this->getRequest()->getParam('category_id');
		$category = Mage::getModel('catalog/category')->load($parentId);
		return $category;
    }
?>