<?PHP
/************************************************************************/
/* NPDS V Image list for Extend HTML Editor .                           */
/*                                                                      */
/* This version name NPDS Copyright (c) 2001-2005 by Philippe Brunier   */
/*                                                                      */
/* 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.       */
/************************************************************************/
   $editor_mark=true;
   include("../grab_globals.php");
   include("../config.php");
   include("../modules/upload/upload.conf.php");
   include ("../lib/multi-langue.php");
   include_once("../modules/upload/lang/upload.lang-$language.php");

function Access_Error () {
  if (file_exists("../meta/meta.php"))
     include ("../meta/meta.php");
  echo "<title>NPDS</title></head><body bgcolor=\"white\"><br /><p align=\"center\"><span style=\"font-size: 14px; font-family: Arial; font-weight: bold; color: red;\">";
  echo "Access Denied / Acc&egrave;s Refus&eacute;";
  if (cur_charset=="utf-8") echo" / &#x901A;&#x5165;&#x88AB;&#x5426;&#x8BA4;";
  echo "</span>";
  echo "<br /><br /><span style=\"font-size: 12px; font-family: Arial; font-weight: bold; color: black;\">NPDS - Portal System";
  echo "</span></p></body></html>";
  die();
}
function filtre_module($strtmp) {
   if (strstr($strtmp,"..") || stristr($strtmp,"script") || stristr($strtmp,"cookie") || stristr($strtmp,"iframe") || stristr($strtmp,"applet") || stristr($strtmp,"object") || stristr($strtmp,"meta")) {
      Access_Error();
   } else {
      if ($strtmp!="") {
         return (true);
      } else {
         return (false);
      }
   }
}

function verifsize ($size) { // By snipe 2003
   global $width_max, $height_max;
   if ($width_max==0) $width_max=50;
   if ($height_max==0) $height_max=50;

   $width=$size[0];
   $height=$size[1];

   if ($width > $width_max) {
      $imageProp = ($width_max * 100) / $width;
      $height = ceil(($height * $imageProp) / 100);
      $width = $width_max;
   }
   if ($height > $height_max) {
      $imageProp = ($height_max * 100) / $height;
      $width = ceil(($width * $imageProp) / 100);
      $height = $height_max;
   }
   return ("width=\"$width\" height=\"$height\"");
}

   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 "<title>NPDS - ".upload_translate("Images & Documents")."</title>";
   if ($user) {
      $userX = base64_decode($user);
      $cookie = explode(":", $userX);
      if (trim($cookie[1])!="") {
         $uname=$cookie[1];
         if (!$autorise_upload_p) {
            Access_Error();
         }
      } else {
         Access_Error();
      }
   } else {
      Access_Error();
   }
   echo "</head>\n<body topmargin=\"2\" leftmargin=\"0\" rightmargin=\"0\">";
   echo "<table border=\"0\" width=\"100%\"><tr align=\"left\">";
   echo "<td width=\"100%\"><span class=\"ROUGE\">$uname</span> : ".upload_translate("Ces Images et ces Documents sont rattachés à votre compte.")."</td>";
   echo "</tr></table>";
   echo "<hr noshade>";

   if (is_dir("../users_private/".$uname)) {
      $directory="/users_private/".$uname."/";
      if ($op!="") {
         if (filtre_module($op) and is_dir("../users_private/".$uname."/".$op)) {
            $directory="/users_private/".$uname."/".$op."/";
         } else {
            Access_Error();
         }
      }
   } else {
      Access_Error();
   }

   $handle=opendir("..".$directory);
   while ($file = readdir($handle)) $filelist[] = $file;
   asort($filelist);
   $ibid=2;
   echo "<table border=\"0\" width=\"100%\"><tr align=\"center\">";
   while (list ($key, $file) = each ($filelist)) {
     if (ereg(".gif|.jpg|.png",$file)) {
        $size=verifsize(@getImageSize("..".$directory.$file));
        echo "<td><img src=\"".$url_upload.$racine.$directory.$file."\" $size border=\"0\" hspace=\"2\" vspace=\"2\" align=\"middle\" alt=\"$file\" /></td>";
        if ($ibid>=$ed_nb_images) {
           echo "</tr><tr>";
           $ibid=1;
        } else {
           $ibid++;
        }
     }
   }
   closedir($handle);
   unset ($filelist);
   echo "</tr></table>";
   echo "<hr noshade>";
   // directory upload standard for document
   $handle=opendir("..".$directory);
   $tab_dir=array();
   while ($file = readdir($handle)) $filelist[] = $file;
   asort($filelist);
   while (list ($key, $file) = each ($filelist)) {
      if (!ereg("index.html|!mime|!divers|\.\.|.gif|.jpg|.png|mns",$file)) {
         if (is_dir("..".$directory.$file)) {
            if ($file!=".")
               $tab_dir[]="..".$directory.$file;
            $file=".";
         }
         if ($file!=".") {
            switch(substr($file,strlen($file)-3)) {
               case "doc":
               case "dot":
                  $typeM="!mime/word.gif";
                  break;
               case "xls":
               case "xla":
               case "xlt":
               case "xll":
                  $typeM="!mime/xls.gif";
                  break;
               case ".gz":
               case "tgz":
                  $typeM="!mime/gzip.gif";
                  break;
               case "zip":
               case "rar":
               case "ace":
                  $typeM="!mime/zip.gif";
                  break;
               case "pdf":
                  $typeM="!mime/pdf.gif";
                  break;
               case "txt":
                  $typeM="!mime/txt.gif";
                  break;
               case "mp3":
               case "wav":
               case "avi":
               case "mov":
                  $typeM="!mime/mp3.gif";
                  break;
               case "html":
               case "htm":
                  $typeM="!mime/html.gif";
                  break;
               case "exe":
               case "com":
               case "dll":
               case "ocx":
               case "drv":
               case "vbx":
                  $typeM="!mime/exe.gif";
                  break;
               default:
                  $typeM="!mime/unknown.gif";
                  break;
            }
            echo "&nbsp;-:[ $file : <a href=\"".$url_upload.$racine.$directory.$file."\"><img src=\"".$url_upload.$rep_upload.$typeM."\" border=\"0\" hspace=\"2\" vspace=\"2\" align=\"middle\" alt=\"$file\" /></a>&nbsp;&nbsp;] <br />";
         }
      }
   }
   closedir($handle);
   unset ($filelist);

   // Direcxtory
   if (count($tab_dir)>0) {
      echo "<hr noshade>";
      while (list ($key, $dir) = each ($tab_dir)) {
         echo "&nbsp;<a href=\"upload_list_p.php?op=".basename($dir)."\">".basename($dir)."</a><br />";
      }
   }
   if ($op!="") {
      echo "&nbsp;<a href=\"upload_list_p.php\"><img src=\"".$url_upload.$racine."/images/admin/filemanager/parent.gif\" alt=\"\" border=\"0\" /></a>\n";
   }
   echo "</body></html>";
?>
