dolibarr/htdocs/document.php

91 lines
2.7 KiB
PHP
Raw Normal View History

2004-10-20 23:06:45 +02:00
<?php
2004-07-12 11:46:13 +02:00
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
2004-07-12 11:46:13 +02:00
*
* 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.
*
* 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see http://www.gnu.org/
*
* $Id$
* $Source$
*
*/
/**
\file htdocs/document.php
\brief Wrapper permettant le t<EFBFBD>l<EFBFBD>chargement de fichier de donn<EFBFBD>es Dolibarr
L'appel ancienne m<EFBFBD>thode (non s<EFBFBD>curis<EFBFBD>e) est document.php?file=pathcompletdufichier
L'appel nouvelle m<EFBFBD>thode (s<EFBFBD>curis<EFBFBD>e) est document.php?file=pathrelatifdufichier&type=typefichier
\version $Revision$
*/
require_once("main.inc.php");
// C'est un wrapper, donc header vierge
function llxHeader() { }
2004-07-12 11:46:13 +02:00
$original_file = urldecode($_GET["file"]);
$modulepart = urldecode($_GET["modulepart"]);
$type = urldecode($_GET["type"]);
2004-07-12 11:46:13 +02:00
$accessallowed=0;
if ($modulepart)
{
// On fait une v<>rification des droits et on d<>finit le r<>pertoire concern<72>
if ($modulepart == 'facture_paiement')
{
$user->getrights('facture');
if ($user->rights->facture->lire)
{
$accessallowed=1;
}
$original_file=$conf->compta->dir_output.'/'.$original_file;
}
}
else
{
// A terme, on ne doit rien pouvoir t<>l<EFBFBD>charger via document.php sans fournir type
// car c'est grace au type qu'on v<>rifie que les droits et qu'on d<>finit le r<>pertoire racine des fichiers
// \todo Corriger ce trou de s<>curit<69> pour ne plus permettre l'utilisation via un nom de fichier complet et sans test de droits
// Pour l'instant, autorise la passage
$accessallowed=1;
}
2004-07-12 11:46:13 +02:00
// Limite acc<63>s si droits non corrects
if (! $accessallowed) { accessforbidden(); }
$filename = basename($original_file);
if (! file_exists($original_file)) { dolibarr_print_error(0,$langs->trans("FileDoesNotExist",$original_file)); exit; }
// Les drois sont ok et fichier trouv<75>
if ($type)
{
header('Content-type: '.$type);
}
else
{
header('Content-type: application/pdf');
}
2004-07-12 11:46:13 +02:00
header('Content-Disposition: attachment; filename="'.$filename.'"');
readfile($original_file);
2004-07-12 11:46:13 +02:00
?>