<?php
  /**************************************************************************\
  * phpGroupWare - attachedFiles                                             *
  * http://www.phpgroupware.org                                              *
  * This file is written by Lars Piepho <lpiepho@probusiness.de>             *
  * Copyright (C) 2003 probusiness AG (Lars Piepho)                          *
  *                                                                          *
  * --------------------------------------------                             *
  *  This program is free software; you can redistribute it and/or modify it *
  *  under the terms of the GNU General Public License as published by the   *
  *  Free Software Foundation; either version 2 of the License, or (at your  *
  *  option) any later version.                                              *
  \**************************************************************************/

	/* $Id: class.attachedFiles.inc.php 14268 2004-01-20 05:03:42Z jengo $ */

	
	class attachedFiles
	{

		var $public_functions = array(
			'show_file' => True
		);
		var $file;
		var $vfs;

		function attachedFiles()
		{		
		 $this->file = $_REQUEST['file'];
		 		  
		 $GLOBALS['phpgw_info']['flags'] = array
		(
			'currentapp'	=> 'tts',
			'noheader'	=> True,
			'nofooter'	=> True,
			'enable_vfs_class'	=> True,
			'enable_browser_class'	=> True
		);
		
		$this->vfs = CreateObject('phpgwapi.vfs');
		
		}

		function show_file()
		{			
			$ls_array = $this->vfs->ls(array (
			'string'	=> $this->file,
			'relatives'	=> array (RELATIVE_ALL),
			'checksubdirs'	=> False,
			'nofiles'	=> True));

			if ($ls_array[0]['mime_type'])
			{
				$mime_type = $ls_array[0]['mime_type'];
			}
			elseif ($GLOBALS['settings']['viewtextplain'])
			{
				$mime_type = 'text/plain';
			}
			$filename = basename($this->file);
			header('Content-type: ' . $mime_type);
			header('Content-Disposition: attachment; filename=' . $filename);
			echo $this->vfs->read (array (
					'string'	=> $this->file,
					'relatives'	=> array (RELATIVE_NONE)));
			$GLOBALS['phpgw']->common->phpgw_exit ();
		}
		
	}
?>
