<?PHP
/************************************************************************/
/* NPDS V : Net Portal Dynamic System .                                 */
/* ===========================                                          */
/*                                                                      */
/* This version name NPDS Copyright (c) 2001-2004 by Philippe Brunier   */
/*                                                                      */
/* =========================                                            */
/* Snipe 2003                                                           */
/*                                                                      */
/* 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.       */
/************************************************************************/
include ("mainfile.php");

switch($apli) {
   case "forum_npds":
      $userX=base64_decode($user);
      $userdata=explode(":", $userX);
      $marqueurM=substr($userdata[2],8,6);
   case "minisite":
   case "getfile":
      $att_name=StripSlashes(str_replace("\"","",rawurldecode($att_name)));
      if ((eregi("(^[0-9a-z_\.-])",$att_name) or ($Mmod==$marqueurM)) and !stristr($att_name,".*://") and !stristr($att_name,"..") and !stristr($att_name,"../") and !stristr($att_name, "script") and !stristr($att_name, "cookie") and !stristr($att_name, "iframe") and  !stristr($att_name, "applet") and !stristr($att_name, "object") and !stristr($att_name, "meta")) {
         if (eregi("(^[0-9a-z_\.-])",$att_id) and !stristr($att_id,".*://") and !stristr($att_id,"..") and !stristr($att_id,"../") and !stristr($att_id, "script") and !stristr($att_id, "cookie") and !stristr($att_id, "iframe") and  !stristr($att_id, "applet") and !stristr($att_id, "object") and !stristr($att_id, "meta")) {
            $fic="";
            switch($apli) {
               // Forum
               case "forum_npds":
                  $fic="modules/upload/upload_forum/$att_id.$apli.$att_name";
                  break;
               // MiniSite
               case "minisite":
                  $fic="users_private/$att_id/mns/$att_name";
                  break;
               // Application générique : la présence de getfile.conf.php est nécessaire
               case "getfile":
                  if (file_exists("$att_id/getfile.conf.php") or file_exists("$att_id/.getfile.conf.php"))
                     $fic="$att_id/$att_name";
                  else
                     header("location: index.php");
                  break;
            }
            include ("modules/upload/lang/upload.lang-$language.php");
            include ("modules/upload/include/mimetypes.php");
            $suffix=strtoLower(substr(strrchr( $att_name, '.' ),1));
            list ($type, $garbage) = split(';',$type);      // strip "; name=.... " (Opera6)
            if (isset($mimetypes[$suffix]) ) {
               $type=$mimetypes[$suffix];
            } elseif ( empty($type) || ($type=='application/octet-stream') ) {
               $type=$mimetype_default;
            }
            $att_type = $type;
            $att_size = @filesize ($fic);
            if (file_exists ($fic)) {
               if ($apli=="forum_npds") {
                  include ("auth.php");
                  $sql="UPDATE $upload_table SET compteur = compteur+1 WHERE att_id = '$att_id'";
                  @mysql_query($sql);
               }
               // Output file to the browser
               header('Expires: Thu, 01 Jan 1970 00:00:01 GMT');
               header('Cache-Control: no-store, no-cache, must-revalidate');
               header('Pragma: no-cache');
               if ($att_type=="application/x-shockwave-flash") {
                  header("Content-type: application/x-shockwave-flash");
               } else {
                  header("Content-Type: $att_type; name=\"".basename($att_name)."\"");
               }
               header ("Content-length: $att_size");
               if (strstr($HTTP_USER_AGENT,"MSIE 5") && !strstr($HTTP_USER_AGENT,"Opera")) {
                  header("Content-Disposition: filename=\"".basename($att_name)."\"");
               } else {
                  header ("Content-Disposition: attachment; filename=\"".basename($att_name)."\"");
               }
               readFile ($fic);
            } else {
               header("location: index.php");
            }
         } else {
            header("location: index.php");
         }
      } else {
         header("location: index.php");
      }
      break;

   default:
      header("location: index.php");
      break;
}
?>