<?PHP
/************************************************************************/
/* DUNE by NPDS                                                         */
/*                                                                      */
/* NPDS Copyright (c) 2001-2007 by Philippe Brunier                     */
/*                                                                      */
/* Upload / meta fonction and automation for NPDS .                     */
/*                                                                      */
/* 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.       */
/************************************************************************/
/* Copyright Snipe 2003                                                 */
/************************************************************************/
if (!eregi("modules.php", $PHP_SELF)) { die(); }

/*****************************************************/
/* Include et definition                             */
/*****************************************************/
   include_once("modules/upload/lang/upload.lang-$language.php");
   include_once("modules/upload/include_minisite/upload.conf.minisite.php");
   $userinfo=getusrinfo($user);
   if (!$userinfo[mns]) {Access_error();}
   include_once("modules/upload/include_minisite/upload.func.minisite.php");
   include_once("lib/file.class.php");

/*****************************************************/
/* Entete                                            */
/*****************************************************/
   ob_start();
   $Titlesitename=$uname;
   include("meta/meta.php");
   // CSS externalisation
   if ($url_upload_css) {
      $url_upload_cssX=str_replace("style.css","$language-style.css",$url_upload_css);
      if (is_readable($url_upload.$url_upload_cssX))
         $url_upload_css=$url_upload_cssX;
      print ("<link href=\"".$url_upload.$url_upload_css."\" title=\"default\" rel=\"stylesheet\" type=\"text/css\" media=\"all\" />\n");
   }
   echo "</head>\n<body>";

if ($actiontype) {
   switch ($actiontype) {
      case 'delete' : deleteUserAttachmentsfile($del_att); break;
      case 'upload' : $thanks_msg=minisite_upload(); break;
   }
}
   // gestion du quota de place d'un post
   $actu_size=getUserAttachmentsSize();
   if (($MAX_FILE_SIZE_TOTAL - $actu_size)<$MAX_FILE_SIZE) {
      $MAX_FILE_SIZE = $MAX_FILE_SIZE_TOTAL - $actu_size;
   }

include("modules/upload/include/minigfsb.php");

/*****************************************************/
/* Upload du fichier                                 */
/*****************************************************/
function minisite_upload() {
   global $apli, $pcfile, $pcfile_size, $pcfile_name, $pcfile_type, $att_count, $att_size, $total_att_count, $total_att_size;
   global $MAX_FILE_SIZE, $MAX_FILE_SIZE_TOTAL, $mimetypes, $mimetype_default, $rep_upload_minisite, $actu_size;

   include "modules/upload/include/fileupload.php";

   // gestion du quota de place d'un post
   $actu_size=getUserAttachmentsSize();
   if (($MAX_FILE_SIZE_TOTAL - $actu_size)<$MAX_FILE_SIZE) {
      $MAX_FILE_SIZE = $MAX_FILE_SIZE_TOTAL - $actu_size;
   }

   // Récupération des valeurs de PCFILE
   global $HTTP_POST_FILES, $_FILES;
   if (!empty($HTTP_POST_FILES))
       $fic=$HTTP_POST_FILES;
   else
       $fic=$_FILES;
   $pcfile_name = $fic['pcfile']['name'];
   $pcfile_type = $fic['pcfile']['type'];
   $pcfile_size = $fic['pcfile']['size'];
   $pcfile = $fic['pcfile']['tmp_name'];

   $fu = new FileUpload;
   $fu->init ($rep_upload_minisite,"",$apli);

   $att_count = 0;
   $att_size = 0;
   $total_att_count = 0;
   $total_att_size = 0;

   $attachments = $fu->getUploadedFiles("","");
   if (is_array ($attachments) ) {
      $att_count = $attachments["att_count"];
      $att_size = $attachments["att_size"];
      if (is_array($pcfile_name)) {
         reset ($pcfile_name);
         $names = implode (", ", $pcfile_name);
         $pcfile_name = $names;
      }
      $pcfile_size = $att_size;
      $thanks_msg .= str_replace ('{NAME}', $pcfile_name, str_replace('{SIZE}', $pcfile_size, upload_translate("<center><b>Fichier {NAME} bien recu ({SIZE} octets transférés)</b></center>")));
      $total_att_count += $att_count;
      $total_att_size += $att_size;
   }
   return ($thanks_msg);
}
?>