<?php
if(!defined('DIR'))
{
	define('DIR','dir');
}

using('System.Web.UI.HtmlControls.Helper');
/**
 * DirectoryBrowser
 *
 * @date 21.03.2007
 * @name LoginBox
 * @author Margo Poolak <margo 'dot' poolak 'at' mail 'dot' ee>
 * @copyright Copyright &copy;2006 Margo Poolak. All Rights Reserved.
 * @version 2.0
 * @package System.Web.UI.WebControls
 * @category 
 * 
 * This is UI directory browser
 */
class DirectoryBrowser extends Page
{
	private $_ctrl_dir;
	private $_dir_path;
	/*
	*
	*/
	public function onInit()
	{
		$this->setMasterPage('DefaultMasterPage');
		$this->setPath(dirname(__FILE__));
		$this->_dir_path = $this->Request->getGet(DIR,realpath(__FILE__.'/../'));
		$this->_ctrl_dir = new CtrlDir($this->_dir_path);
	}
	/*
	*
	*/
	public function onLoad()
	{
		$this->set('files',$this->_ctrl_dir->toArray());
		$this->set('realpath',$this->_ctrl_dir->getRealPath());
		$this->set('path',$this->_ctrl_dir->getPath());
	}
	/*
	*
	*/
	public function setDirPath($path)
	{
		$this->_dir_path = $path;
	}
	/*
	*
	*/
	public function export($file)
	{
		$this->onInit();
		$file = $this->_ctrl_dir->convertPath($file);
		$this->Response->export($file);
	}
	/*
	*
	*/
	public function import($file)
	{
	
	}
	/*
	*
	*/
	public function sort($field,$order='asc')
	{
		$this->onInit();
		$this->_ctrl_dir->sort($field,$order);
		$this->display();
	}
}
?>