<?php

// -----------------------------------------------------------------------
// This file is part of aroundme
// 
// Copyright (C) 2003, 2005 Barnraiser
// http://www.barnraiser.org/
// info@barnraiser.org
// 
// 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, or (at your option) any
// later version.
// 
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with program; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
// -----------------------------------------------------------------------

include "inc/header_group.inc.php";



$file->user_id = $me['user_id'];

//images
$image_type_ids[] = $c_node['file']['mime'][1]['suffix']; //jpg
$image_type_ids[] = $c_node['file']['mime'][2]['suffix']; //png
$image_type_ids[] = $c_node['file']['mime'][3]['suffix']; //gif


if (isset($_REQUEST['file_id'])) {
	$file_id = $_REQUEST['file_id'];
	$file->file_id = $file_id;
	$output_file = $file->getFileRecord();
	
	if (isset($output_file)) {
		//either send it to the template (image) or open the file
	
		foreach($image_type_ids as $ft): 
			if ($output_file['file_suffix'] == $ft) {
				$output_image = $output_file;
			}
		endforeach;
		
		if ($output_file['file_suffix'] == $c_node['file']['mime'][6]['suffix']) { //shockwave
		    header("Content-type: " . $c_node['file']['mime'][6]['mime']);
		}
		
		if ($output_file['file_suffix'] == $c_node['file']['mime'][4]['suffix']) { //pdf
		   header("Content-type: " . $c_node['file']['mime'][4]['mime']);
		}
		
		if ($output_file['file_suffix'] == $c_node['file']['mime'][5]['suffix']) { //plain txt
		   header("Content-type: " . $c_node['file']['mime'][5]['mime']);
		}
	
		if (empty($output_image)) {
		    readfile($c_node['dir']['asset_path'] . $output_file['file']);
			exit;
		}
	}
}


$file->thumb = $c_node['file']['image']['thumb'][2]['name'];
$file->orderby = "file_title";

$output_files = $file->getFiles();



//get images out of files output
if (isset($output_files)) {
	foreach($output_files as $key => $i): 
		foreach($image_type_ids as $ft): 
			if ($i['file_suffix'] == $ft) {
				$output_images[] = $output_files[$key];
				unset($output_files[$key]);
			}
		endforeach;
	endforeach;
}



//move to template
if (!empty($output_group)) {
    $body->set('group', $output_group);
}

if (!empty($output_files)) {
    $body->set('files', $output_files);
}

if (!empty($output_images)) {
    $body->set('images', $output_images);
}

if (!empty($output_image)) {
    $body->set('image', $output_image);
}

if (!empty($image_type_ids)) {
    $body->set('image_type_ids', $image_type_ids);
}

if (isset($display)) {
    $body->set('display', $display);
}

include "inc/footer.inc.php";

?>
