<?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( 'Restricted access' ); 
jimport( 'joomla.application.component.view');
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.path');

class rsfilesViewFiles extends JView
{
	function display($tpl = null)
	{		
		global $mainframe;
		$db = JFactory::getDBO();
		$this->assignRef('db',$db);
		$user = JFactory::getUser();
		$this->assignRef('user',$user);
		$rsfilesConfig = RsfilesHelper::getConfig();
		$this->assignRef('rsfilesConfig',$rsfilesConfig);
		
		//approved extensions for previewing 
		$extensions = explode(',',$rsfilesConfig['preview_files']);
		
		//get the itemid
		$Itemid = JRequest::getVar('Itemid','','request');
		$itemid = ($Itemid == '') ? '' : '&Itemid='.$Itemid;
		$this->assignRef('itemid',$itemid);
		
		JHTML::_('behavior.modal');
		
		$layout=JRequest::getVar('layout','','request');
		switch($layout)
		{
			default:
			case 'files':
			case 'timeperiod':
			{
				$cfolder = JRequest::getVar('folder');
				$previous = $this->get('previous');
				$current = $this->get('Current');
				
				//check for publishing permission
				if (!empty($cfolder))
				{
					$db->setQuery("SELECT published FROM #__rsfiles_files WHERE FilePath = '".$db->getEscaped($rsfilesConfig['download_folder'].DS.urldecode($cfolder))."' ");
					$published = $db->loadResult();
					$published = $published != '' ? $published : 1;
					
					if (!$published) $mainframe->redirect(JRoute::_('index.php?option=com_rsfiles&view=files'.$itemid,false));
				}
				
				
				
				$link = 'index.php?option=com_rsfiles&view=files';
				if ($layout == 'timeperiod')
				$link = 'index.php?option=com_rsfiles&view=files&layout=timeperiod';

				$fileLayout = $this->get('FileLayout');
				$maintenance = $this->get('PermissionMaintenance');
				$canview = $this->get('PermissionView');
				$parts = $this->get('Paths');
				
				
				if(!$canview) $mainframe->redirect(JRoute::_('index.php?option=com_rsfiles&view=files'.$itemid,false));
				
				$layouts = array();	
				
				//set pathway
				$pathway =& $mainframe->getPathway();
				$pathway->addItem(JText::_('RSFL_FILES'), '');
				
				
				//if the users get outs of the root 
				if (strpos(realpath($current), $rsfilesConfig['download_folder']) !== 0) $mainframe->redirect(JRoute::_('index.php?option=com_rsfiles&view=files'.$itemid,false));
				if (!is_dir(realpath($rsfilesConfig['download_folder'].DS.$cfolder))) $mainframe->redirect(JRoute::_('index.php?option=com_rsfiles&view=files'.$itemid,false));
				
				$allfiles = $this->get('FolderFiles');
				$pagination = $this->get('Pagination');
				
				//add alternate feed link
				if($rsfilesConfig['enable_rss'] == 1)
				{
					$document =& JFactory::getDocument();
					$flink	= '&format=feed&limitstart=';
					$attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');
					$document->addHeadLink(JRoute::_($flink.'&type=rss'), 'alternate', 'rel', $attribs);
					$attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0');
					$document->addHeadLink(JRoute::_($flink.'&type=atom'), 'alternate', 'rel', $attribs);
				}
				
				foreach($allfiles as $obj)
				{		
					
					$name = ($obj->type == 'folder') ? '<a href="'.JRoute::_($link.'&folder='.$obj->fullpath.$itemid,false).'">'.$obj->name.'</a>' : '<a href="'.JRoute::_('index.php?option=com_rsfiles&view=files&layout=download&path='.$obj->fullpath.$itemid,false).'">'.$obj->name.'</a>';
					
					
					if($obj->type == 'folder')
					{
						$bad = array('{FileName}','{FileDescription}','{FileHits}','{FileThumb}','{FileLicense}','{RealFileName}','{FileVersion}','{FileSize}','{FileType}','{FileUploader}','{DateAdded}','{FileModified}','{FileChecksum}','{Download}','{View}','{Details}','{fullpath}');
						$good	= array($name,$obj->description,$obj->hits.' '.JText::_('RSFL_HITS'),$obj->thumb,''); 
					}
					
					if($obj->type == 'file')
					{
						//set the download view link
						$download = '<a class="button" href="'.JRoute::_('index.php?option=com_rsfiles&view=files&layout=download&path='.$obj->fullpath.$itemid,false).'">'.JText::_('RSFL_DOWNLOAD').'</a>&nbsp;';
						
						//set the preview link if the file extension is in the $rsfilesConfig['preview_files']
						if(in_array(JFile::getExt($obj->fullpath),$extensions))
						$view = '<a class="button modal" rel="{handler: \'iframe\', size: {x: 660, y: 475}}" href="'.JRoute::_('index.php?option=com_rsfiles&view=files&layout=view&tmpl=component&path='.$obj->fullpath.$itemid,false).'">'.JText::_('RSFL_VIEW').'</a>&nbsp;';
						else $view = '';
						
						//set the details view
						$details = '<a class="button" href="'.JRoute::_('index.php?option=com_rsfiles&view=files&layout=details&path='.$obj->fullpath.$itemid,false).'">'.JText::_('RSFL_DETAILS').'</a>&nbsp;';
						
						$bad = array('{FileName}','{FileDescription}','{FileLicense}','{RealFileName}','{FileVersion}','{FileSize}','{FileType}','{FileUploader}','{DateAdded}','{FileHits}','{FileModified}','{FileChecksum}','{FileThumb}','{Download}','{View}','{Details}','{fullpath}');
						
						$good	= array($name,$obj->filedescription,$obj->filelicense,$obj->filename,$obj->fileversion,$obj->size,$obj->filetype,$obj->owner,$obj->dateadded,($obj->hits == 0) ? JText::_('RSFL_NO_HITS') : $obj->hits.' '.JText::_('RSFL_HITS'),$obj->lastmodified,$obj->checksum,$obj->thumb,$download,$view,$details,$rsfilesConfig['download_folder'].DS.$obj->fullpath); 
					}
					
					$layouts[] = str_replace($bad,$good,$fileLayout);
				}
				
				
				$this->assignRef('link', $link);
				$this->assignRef('previous', $previous);
				$this->assignRef('current', $current);
				$this->assignRef('currentfolder', $this->get('CurrentFolder'));
				$this->assignRef('fileheader', $this->get('FilesHeader'));
				$this->assignRef('pagination', $pagination);
				$this->assignRef('layouts', $layouts);
				$this->assignRef('maintenance', $maintenance);
				$this->assignRef('parts', $parts);
			
			} break;
			
			case 'view':
			
				$this->get('Preview');
				exit;
			break;
			
			case 'edit':
				//set pathway
				$pathway =& $mainframe->getPathway();
				$pathway->addItem(JText::_('RSFL_FILES_EDIT'), '');
				
				$path = JRequest::getVar('path');
				$current = $this->get('Current');
				$maintenance = $this->get('PermissionMaintenance');
				$file = $this->get('FileInfo');
				
				
				//if the users get outs of the root 
				if (strpos(realpath($current.DS.$path), $rsfilesConfig['download_folder']) !== 0) $mainframe->redirect(JRoute::_('index.php?option=com_rsfiles&view=files'.$itemid,false));
				//check to see if the user has permissions to upload
				if(!$maintenance) $mainframe->redirect(JRoute::_('index.php?option=com_rsfiles&view=files'.$itemid,false),JText::_('RSFL_EDIT_DENIED'));
				
				$download_method = array();
				
				$download_method[] = JHTML::_('select.option', 0, JText::_('RSFL_DOWNLOAD_NORMAL'));
				$download_method[] = JHTML::_('select.option', 1, JText::_('RSFL_DOWNLOAD_EMAIL'));
				$lists['downloads'] = JHTML::_('select.genericlist', $download_method, 'DownloadMethod', '', 'value', 'text', $file->DownloadMethod);
				
				$db->setQuery("SELECT IdLicense,LicenseName FROM #__rsfiles_licenses WHERE published = 1");
				$lics= array();
				$lics[] = JHTML::_('select.option', 0, JText::_('RSFL_LICENSE_SELECT'));
				foreach ($db->loadObjectList() as $license)
					$lics[] = JHTML::_('select.option', $license->IdLicense, $license->LicenseName);
					
				$lists['licenses'] = JHTML::_('select.genericlist', $lics, 'IdLicense', '', 'value', 'text', $file->IdLicense);
				
				
				$this->assignRef('editor', JFactory::getEditor());
				$this->assignRef('currentpath', $this->get('CurrentPath'));
				$this->assignRef('file', $file);
				$this->assignRef('lists', $lists);
				$this->assignRef('path', $path);
			break;
			
			case 'report':
				JRequest::setVar('tmpl','component');
				$path = JRequest::getVar('path');
				
				$this->assignRef('path',$path);
				
			break;
			
			
			case 'download':
			{
				//set pathway
				$pathway =& $mainframe->getPathway();
				$pathway->addItem(JText::_('RSFL_FILES_DOWNLOAD'), '');
				$layout = $this->get('DownloadLayout');
				$file = $this->get('FileDetails');
				$mirrors = $this->get('Mirrors');
				$screenshots = $this->get('Screenshots');
				$current = $this->get('Current');
				$path = JRequest::getVar('path');
				$maintenance = $this->get('PermissionMaintenance');
				$candownload = $this->get('PermissionDownload');
				$canview = $this->get('PermissionView');
				
				//check for publishing permission
				$published = 1;
				$parts = explode(DS,urldecode($path));

				if (!empty($parts))
				foreach ($parts as $i => $part)
				{
					$db->setQuery("SELECT published FROM #__rsfiles_files WHERE FilePath = '".$db->getEscaped($rsfilesConfig['download_folder'].DS.implode(DS,$parts))."' ");
					if ($db->loadResult() == 0) $published = 0;
					array_pop($parts);
				}
				
				if (!$published) $mainframe->redirect(JRoute::_('index.php?option=com_rsfiles&view=files'.$itemid,false));
				
				if(!$canview) $mainframe->redirect(JRoute::_('index.php?option=com_rsfiles&view=files'.$itemid,false));
				
				//if the users get outs of the root 
				if (strpos(realpath($current.DS.$path), $rsfilesConfig['download_folder']) !== 0) $mainframe->redirect(JRoute::_('index.php?option=com_rsfiles&view=files'.$itemid,false));
				
				$ext = end(explode(DS,$path));
				if(JFile::stripExt($ext) == '') $mainframe->redirect(JRoute::_('index.php?option=com_rsfiles&view=files'.$itemid,false));
				
				//placheholders
				$fname = empty($file->FileName) ? JFile::getName($path) : $file->FileName;
				$filedescription = empty($file->FileDescription) ? JText::_('RSFL_NO_DESCRIPTION') : $file->FileDescription;
				$filelicense = (empty($file->IdLicense) || $file->IdLicense == 0) ? JText::_('RSFL_NO_LICENSE') : '<a href="'.JRoute::_('index.php?option=com_rsfiles&view=files&layout=license&cid='.$file->IdLicense.$itemid,false).'">'.$file->LicenseName.'</a>';
				$filename = JFile::getName($path);
				$fileversion = empty($file->FileVersion) ? '' : $file->FileVersion;
				$filesize = RsfilesHelper::formatBytes(filesize($current.DS.$path));
				$filetype = JFile::getExt($path).' ('.JText::_('RSFL_MIMETYPE').' '.RsfilesHelper::mimetype(strtolower(JFile::getExt($path))).')';
				$owner = (empty($file->username) || $file->username == 0) ? JText::_('RSFL_GUEST') : $file->username;
				$dateadded = empty($file->DateAdded) ? date($rsfilesConfig['global_date'],filemtime($current.DS.$path)) : date($rsfilesConfig['global_date'],$file->DateAdded);
				$hits = (empty($file->hits) || ($file->hits == 0 && $file->FileStatistics == 0)) ? JText::_('RSFL_NO_HITS') : $file->hits.' '.JText::_('RSFL_HITS');
				$lastmodified = date($rsfilesConfig['global_date'],filemtime($current.DS.$path));
				$checksum = empty($file->hash) ? JText::_('RSFL_NO_CHECKSUM') : $file->hash;
				$thumb = empty($file->FileThumb) ? '' : '<img src="'.JURI::root().'components/com_rsfiles/images/thumbs/files/'.$file->FileThumb.'" />' ;
				$fullpath = $rsfilesConfig['download_folder'].DS.$path;
				
				$screenshot = '';
				//add the placeholders to the layout
				if(!empty($screenshots))
				{
					$screenshot .= '<div class="rsfl_screenshots">';
					foreach($screenshots as $image)
						$screenshot .= '<a class="modal" href="'.JURI::root().'components/com_rsfiles/images/screenshots/'.$image->Path.'"><img src="'.JURI::root().'components/com_rsfiles/images/screenshots/'.$image->Path.'" width="110" height="110" /></a>';
					
					$screenshot .= '</div>';
				}
				
				$mirror = '';
				if(!empty($mirrors))
				{
					$mirror .='<div class="rsfl_mirrors">';
					$mirror .= '<br/>'.JText::_('RSFL_MIRROR_DETAIL').'<br/>';
					$mirror .= '<table>';
					foreach($mirrors as $link)
						$mirror .= '<tr><td><a target="_blank" href="'.$link->MirrorURL.'"><img src="'.JURI::root().'components/com_rsfiles/images/icons/download-mirror.gif" alt="'.JText::_('RSM_MIRROR_ALT').'" />'.JText::_('RSFL_EXTERNAL_MIRROR').' '.$link->MirrorName.'</a></td></tr>';
					
					$mirror .='</table>';
					$mirror .='</div>';
				}
				
				$file->DownloadMethod = empty($file->DownloadMethod) ? 0 : $file->DownloadMethod ;
				
				$dlink = ($file->DownloadMethod == 0) ? ((empty($file->IdLicense) || $file->IdLicense == 0) ? JRoute::_('index.php?option=com_rsfiles&task=download&path='.urlencode($path).$itemid,false) : JRoute::_('index.php?option=com_rsfiles&view=files&layout=agreement&tmpl=component&cid='.$file->IdLicense.'&path='.urlencode($path).$itemid,false) ) : JRoute::_('index.php?option=com_rsfiles&view=files&layout=emaildownload&tmpl=component&path='.urlencode($path).$itemid,false);
				$rel = ($file->DownloadMethod == 0) ? ((empty($file->IdLicense) || $file->IdLicense == 0) ? '' : 'rel="{handler: \'iframe\', size: {x: 800, y: 600}}"' ) : 'rel="{size: {x: 600, y: 170}}"' ;
				$enablemodal = ($file->DownloadMethod == 0) ? ((empty($file->IdLicense) || $file->IdLicense == 0) ? '' : ' modal' ) : ' modal' ;
				
				if($candownload)
				$download = '<a class="rsfl_download_btn'.$enablemodal.'" '.$rel.' href="'.$dlink.'"><img src="'.JURI::root().'components/com_rsfiles/images/icons/download-big.png" alt="'.JText::_('RSM_DOWNLOAD_ALT').'" />'.JText::_('RSFL_DOWNLOAD_FILE').'</a>'.$mirror;
				else $download = JText::_('RSFL_PERMISSION_DENIED');
				
				$bad = array('{FileName}','{FileDescription}','{FileLicense}','{RealFileName}','{FileVersion}','{FileSize}','{FileType}','{FileUploader}','{DateAdded}','{FileHits}','{FileModified}','{FileChecksum}','{FileThumb}','{screenshots}','{maindownload}','{fullpath}');
				$good = array($fname,$filedescription,$filelicense,$filename,$fileversion,$filesize,$filetype,$owner,$dateadded,$hits,$lastmodified,$checksum,$thumb,$screenshot,$download,$fullpath);
				
				//replace placheholders
				$layout = str_replace($bad,$good,$layout);
				
				$this->assignRef('layout',$layout);
				$this->assignRef('currentpath', $this->get('CurrentPath'));
				$this->assignRef('previous', $this->get('PreviousPath'));
				$this->assignRef('maintenance', $maintenance);
				$this->assignRef('candownload', $candownload);
				
			} break;
			
			case 'details':
			{
				//set pathway
				$pathway =& $mainframe->getPathway();
				$pathway->addItem(JText::_('RSFL_FILES_DETAILS'), '');
				$layout = $this->get('DetailsLayout');
				$file = $this->get('FileDetails');
				$path = JRequest::getVar('path');
				$current = $this->get('Current');
				$maintenance = $this->get('PermissionMaintenance');
				$canview = $this->get('PermissionView');
				
				
				//check for publishing permission
				$published = 1;
				$parts = explode(DS,urldecode($path));

				if (!empty($parts))
				foreach ($parts as $i => $part)
				{	
					$db->setQuery("SELECT published FROM #__rsfiles_files WHERE FilePath = '".$db->getEscaped($rsfilesConfig['download_folder'].DS.implode(DS,$parts))."' ");
					if ($db->loadResult() == 0) $published = 0;
					array_pop($parts);
				}
				
				if (!$published) $mainframe->redirect(JRoute::_('index.php?option=com_rsfiles&view=files'.$itemid,false));
				
				
				//if the users get outs of the root 
				if (strpos(realpath($current.DS.$path), $rsfilesConfig['download_folder']) !== 0) $mainframe->redirect(JRoute::_('index.php?option=com_rsfiles&view=files'.$itemid,false));
				
				//check for view permissions
				if(!$canview) $mainframe->redirect(JRoute::_('index.php?option=com_rsfiles&view=files'.$itemid,false));
				
				$ext = end(explode(DS,$path));
				if(JFile::stripExt($ext) == '') $mainframe->redirect(JRoute::_('index.php?option=com_rsfiles&view=files'.$itemid,false));
				
				//placeholders
				$fname = empty($file->FileName) ? JFile::getName($path) : $file->FileName;
				$filedescription = empty($file->FileDescription) ? JText::_('RSFL_NO_DESCRIPTION') : $file->FileDescription;
				$filelicense = (empty($file->IdLicense) || $file->IdLicense == 0) ? JText::_('RSFL_NO_LICENSE') : '<a href="'.JRoute::_('index.php?option=com_rsfiles&view=files&layout=license&cid='.$file->IdLicense.$itemid,false).'">'.$file->LicenseName.'</a>';
				$filename = JFile::getName($path);
				$fileversion = empty($file->FileVersion) ? '' : $file->FileVersion;
				$filesize = RsfilesHelper::formatBytes(filesize($current.DS.$path));
				$filetype = JFile::getExt($path).' ('.JText::_('RSFL_MIMETYPE').' '.RsfilesHelper::mimetype(strtolower(JFile::getExt($path))).')';
				$owner = empty($file->username) ? JText::_('RSFL_GUEST') : $file->username;
				$dateadded = empty($file->DateAdded) ? date($rsfilesConfig['global_date'],filemtime($current.DS.$path)) : date($rsfilesConfig['global_date'],$file->DateAdded);
				$hits = (empty($file->hits) || ($file->hits == 0 && $file->FileStatistics == 0)) ? JText::_('RSFL_NO_HITS') : $file->hits.' '.JText::_('RSFL_HITS');
				$lastmodified = date($rsfilesConfig['global_date'],filemtime($current.DS.$path));
				$checksum = empty($file->hash) ? JText::_('RSFL_NO_CHECKSUM') : $file->hash;
				$thumb = empty($file->FileThumb) ? '' : '<img src="'.JURI::root().'components/com_rsfiles/images/thumbs/files/'.$file->FileThumb.'" />' ;
				$fullpath = $rsfilesConfig['download_folder'].DS.$path;
				
				
				$bad = array('{FileName}','{FileDescription}','{FileLicense}','{RealFileName}','{FileVersion}','{FileSize}','{FileType}','{FileUploader}','{DateAdded}','{FileHits}','{FileModified}','{FileChecksum}','{FileThumb}','{fullpath}');
				$good = array($fname,$filedescription,$filelicense,$filename,$fileversion,$filesize,$filetype,$owner,$dateadded,$hits,$lastmodified,$checksum,$thumb,$fullpath);
				
				//replace placeholders
				$layout = str_replace($bad,$good,$layout);
				
				$this->assignRef('layout',$layout);
				$this->assignRef('maintenance',$maintenance);
				$this->assignRef('currentpath', $this->get('CurrentPath'));
				$this->assignRef('previous', $this->get('PreviousPath'));
				
			} break;
			
			case 'upload':
			{
				//set pathway
				$pathway =& $mainframe->getPathway();
				$pathway->addItem(JText::_('RSFL_FILES_UPLOAD'), '');
				$maintenance = $this->get('PermissionMaintenance');
				$doc = JFactory::getDocument();
				
				//check to see if the upload is enable
				if($rsfilesConfig['enable_upload'] == 0) $mainframe->redirect(JRoute::_('index.php?option=com_rsfiles&view=files'.$itemid,false),JText::_('RSFL_UPLOAD_DENIED'));
				//check to see if the user has permissions to upload
				if(!$maintenance) $mainframe->redirect(JRoute::_('index.php?option=com_rsfiles&view=files'.$itemid,false),JText::_('RSFL_UPLOAD_DENIED'));
				
				if($rsfilesConfig['enable_flash_upload'] == 1)
				{
					$doc->addScript(JURI::root().'components/com_rsfiles/assets/uploader/swfupload.js');
					$doc->addScript(JURI::root().'components/com_rsfiles/assets/uploader/js/swfupload.queue.js');
					$doc->addScript(JURI::root().'components/com_rsfiles/assets/uploader/js/fileprogress.js');
					$doc->addScript(JURI::root().'components/com_rsfiles/assets/uploader/js/handlers.js');
					$doc->addStyleSheet(JURI::root().'components/com_rsfiles/assets/uploader/default.css');
					
					$extensions = str_replace("\r",'',$rsfilesConfig['allowed_files']);
					$extensions = explode("\n",$extensions);
					$newExtensions = array();
					foreach($extensions as $extension)
						$newExtensions[] = '*.'.$extension;
					$this->assignRef('extensions',implode(';',$newExtensions));
				}
				
				$folder = str_replace('&folder=','',$this->get('CurrentFolder'));
				
				$ext = end(explode(DS,$folder));
				if(JFile::stripExt($ext) == '') $mainframe->redirect(JRoute::_('index.php?option=com_rsfiles&view=files'.$itemid,false));
				
				$this->assignRef('currentfolder', $folder);
				
			} break;
			
			case 'newfolder':
				$folder = str_replace('&folder=','',$this->get('CurrentFolder'));
				$maintenance = $this->get('PermissionMaintenance');
				
				//check to see if the user has permissions to create a new folder
				if(!$maintenance) $mainframe->redirect(JRoute::_('index.php?option=com_rsfiles&view=files'.$itemid,false));
				
				$ext = end(explode(DS,$folder));
				if(JFile::stripExt($ext) == '') $mainframe->redirect(JRoute::_('index.php?option=com_rsfiles&view=files'.$itemid,false));
				
				$this->assignRef('currentfolder', $folder);
			break;
			
			case 'license':
			{
				//set pathway
				$pathway =& $mainframe->getPathway();
				$pathway->addItem(JText::_('RSFL_FILES_LICENSE'), '');
				
				$this->assignRef('license',$this->get('License'));
				
			} break;
			
			case 'search':
			{
				//set pathway
				$pathway =& $mainframe->getPathway();
				$pathway->addItem(JText::_('RSFL_FILES_SEARCH'), '');
				
				if($rsfilesConfig['show_search'] == 0) $mainframe->redirect(JRoute::_('index.php?option=com_rsfiles&view=files'.$itemid,false));
				
				$layouts = array();
				$fileLayout = $this->get('FileLayout');
				$files = $this->get('Results');
				$link = 'index.php?option=com_rsfiles&view=files';
				
				
				if(!empty($files))
				foreach($files as $obj)
				{
					
					$name = ($obj->type == 'folder') ? '<a href="'.JRoute::_($link.'&folder='.$obj->fullpath.$itemid,false).'">'.$obj->name.'</a>' : '<a href="'.JRoute::_('index.php?option=com_rsfiles&view=files&layout=download&path='.$obj->fullpath.$itemid,false).'">'.$obj->name.'</a>';
					
					if($obj->type == 'folder')
					{
						$bad = array('{FileName}','{FileDescription}','{FileHits}','{FileThumb}','{FileLicense}','{RealFileName}','{FileVersion}','{FileSize}','{FileType}','{FileUploader}','{DateAdded}','{FileModified}','{FileChecksum}','{Download}','{View}','{Details}');
						$good	= array($name,$obj->description,$obj->hits.' '.JText::_('RSFL_HITS'),$obj->thumb,''); 
					}
					
					if($obj->type == 'file')
					{
						//set the download view link
						$download = '<a class="button" href="'.JRoute::_('index.php?option=com_rsfiles&view=files&layout=download&path='.$obj->fullpath.$itemid,false).'">'.JText::_('RSFL_DOWNLOAD').'</a>&nbsp;';
						
						//set the preview link if the file extension is in the $rsfilesConfig['preview_files']
						if(in_array(JFile::getExt($obj->fullpath),$extensions))
						$view = '<a class="button modal" rel="{handler: \'iframe\', size: {x: 660, y: 475}}" href="'.JRoute::_('index.php?option=com_rsfiles&view=files&layout=view&tmpl=component&format=raw&path='.$obj->fullpath.$itemid,false).'">'.JText::_('RSFL_VIEW').'</a>&nbsp;';
						else $view = '';
						
						//set the details view
						$details = '<a class="button" href="'.JRoute::_('index.php?option=com_rsfiles&view=files&layout=details&path='.$obj->fullpath.$itemid,false).'">'.JText::_('RSFL_DETAILS').'</a>&nbsp;';
						
						$bad = array('{FileName}','{FileDescription}','{FileLicense}','{RealFileName}','{FileVersion}','{FileSize}','{FileType}','{FileUploader}','{DateAdded}','{FileHits}','{FileModified}','{FileChecksum}','{FileThumb}','{Download}','{View}','{Details}');
						
						$good	= array($name,$obj->description,$obj->filelicense,$obj->filename,$obj->fileversion,$obj->size,$obj->filetype,$obj->owner,$obj->dateadded,($obj->hits == 0) ? JText::_('RSFL_NO_HITS') : $obj->hits.' '.JText::_('RSFL_HITS'),$obj->lastmodified,$obj->checksum,$obj->thumb,$download,$view,$details); 
					}
					
					$layouts[] = str_replace($bad,$good,$fileLayout);
				}
				
				
				$order = array();
				$order[] = JHTML::_('select.option', 'name', JText::_('RSFL_ORDER_NAME') );
				$order[] = JHTML::_('select.option', 'date', JText::_('RSFL_ORDER_DATE') );
				$order[] = JHTML::_('select.option', 'hits', JText::_('RSFL_ORDER_HITS') );
				$lists['ordering'] = JHTML::_('select.genericlist', $order, 'rsfl_ordering', 'size="1" class="inputbox"', 'value', 'text',JRequest::getVar('rsfl_ordering'));
				
				$way = array();
				$way[] = JHTML::_('select.option', 'ASC', JText::_('RSFL_ORDER_ASC') );
				$way[] = JHTML::_('select.option', 'DESC', JText::_('RSFL_ORDER_DESC') );
				$lists['ordering_way'] = JHTML::_('select.genericlist', $way, 'rsfl_ordering_direction', 'size="1" class="inputbox"', 'value', 'text',JRequest::getVar('rsfl_ordering_direction'));
			
				$this->assignRef('layouts',$layouts);
				$this->assignRef('lists',$lists);
				$this->assignRef('fileheader', $this->get('FilesHeader'));
				
			} break;
			
			case 'emaildownload':
			{
				
			} break;
			
			case 'agreement':
			{
				$path = JRequest::getVar('path');
				$file = JFile::getName(JRequest::getVar('path'));
				$this->assignRef('path',$path);
				$this->assignRef('file',$file);
				$this->assignRef('license',$this->get('License'));
				
			} break;
			
			case 'bookmarks':
			{
				$doc = JFactory::getDocument();
				$doc->addScript(JURI::root(true).'/includes/js/joomla.javascript.js');
				
				$data = $this->get('Bookmarks');
				
				$this->assignRef('data',$data);
			} break;
		}
		parent::display($tpl);
	}
}