<?php
/**
* @version 1.0.0
* @package RSFiles! 1.0.0
* @copyright (C) 2009 www.rsjoomla.com
* @license GPL, http://www.gnu.org/copyleft/gpl.html
*/

defined('_JEXEC') or die();
 
jimport( 'joomla.application.component.model' );

class rsfilesModelRsfiles extends JModel
{
	var $_query;
	var $_data;
	var $_total=null;
	var $_pagination=null;
	var $_folder=null;
	
	
	function __construct()
	{
		global $mainframe;
		parent::__construct();		
		if (is_dir(JRequest::getVar('folder')))
		{
			$this->_folder = JRequest::getVar('folder');
			if (substr($this->_folder, -1) == DS)
				$this->_folder = substr($this->_folder, 0, -1);
		}
		else
			$this->_folder = JPATH_SITE;
	}
	
	function getFolders()
	{
		$folders = array();
		
		$all_folders = JFolder::folders($this->_folder);
		foreach ($all_folders as $folder)
		{
			$element = new stdClass();
			$element->name = $folder;
			$element->fullpath = urlencode($this->_folder.DS.$folder);
			$folders[] = $element;
		}
		
		return $folders;
	}
	
	
	function getElements()
	{		
		$elements = explode(DS, $this->_folder);
		$navigation_path = '';
		
		if(!empty($elements))
			foreach($elements as $i=>$element)
			{
				$navigation_path .= $element;
				$newelement = new stdClass();
				$newelement->name = $element;
				$newelement->fullpath = urlencode($navigation_path);
				$elements[$i] = $newelement;
				$navigation_path .= DS;
			}
		
		return $elements;
	}
	
	function getCurrent()
	{
		return $this->_folder;
	}
	
	function getPrevious()
	{
		$elements = explode(DS, $this->_folder);
		if (count($elements) > 1)
			array_pop($elements);
		return urlencode(implode(DS, $elements));
	}	
}