<?php
$myEnv["module"] = "files";
$myEnv["output"] = "html";
$myEnv["translate"] = true;
$myEnv["stdsmenu"] = false;

session_cache_limiter('public');
include("../../config.inc.php");
include(INCLUDEPATH ."container.inc.php");

if(($row = $conn->GetRow(getRightsQuery($_GET['id']))) === false)
     exit(showSQLerror(getRightsQuery($_GET['id']), $conn->ErrorMsg(), __LINE__, __FILE__));

if (($res['owner'] == $_SESSION['MGW']->userid) || checkForFileRight((int)$_GET['id'])){
    header("Content-Type: ".$row['mime_type']);
    header("Content-Length: ".$row['size']);

    if(isset($_GET['dl']) && (int)$_GET['dl'] === 1){
	if (strstr($_SERVER["HTTP_USER_AGENT"], "MSIE"))
	    header('Content-Disposition: filename="'.$row['name'].'"');
	else
	    header('Content-Disposition: attachment; filename="'.$row['name'].'"');
    }

    readfile(STORE_FOLDER.$row['resides_in'].'-'.$row['name']);
} else {
    $smarty->assign("errorheader",Lang::getLanguageString("permerror"));
    $smarty->assign("permerror",Lang::getLanguageString("permerrormsg"));
    $smarty->display($appconf["gentemplates"] ."/perm_errors.tpl");
    die();
}
?>