<?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 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>";
   echo "</head>\n<body topmargin=\"2\" leftmargin=\"0\" rightmargin=\"0\">";
   echo "<table border=\"0\" width=\"100%\"><tr align=\"left\">";
   if ($op=="img") {
      echo "<td width=\"90%\">".upload_translate("Ces Images sont disponibles sur votre site")."</td>";
   } else {
      echo "<td width=\"90%\">".upload_translate("Ces Documents sont disponibles sur votre site")."</td>";
   }
   echo "<td><a href=\"javascript:void(0);\" onClick=\"window.open('editor_images/help_img-doc-$language.htm', 'winhelpI', 'width=640, height=350, resizable=yes');\"><img src=\"editor_images/help.gif\" border=\"0\" hspace=\"2\" vspace=\"0\" align=\"middle\" alt=\"Aide / Help\" /></a></td>";
   echo "</tr></table>";
   echo "<hr noshade>";
   if ($op=="img") {
      if ((substr($ed_profil,0,1)=="1") and ($action=="!divers")) {
         // directory !divers
         $directory=str_replace($racine,"",$rep_upload."!divers");
         $handle=opendir("..".$directory);
         while ($file = readdir($handle)) $filelist[] = $file;
         asort($filelist);
         $ibid=2;
         echo "<table border=\"0\" width=\"100%\"><tr align=\"center\">";
         echo "<td>[!divers]</td>";
         while (list ($key, $file) = each ($filelist)) {
            if (ereg(".gif|.jpg|.png",$file)) {
               $size=verifsize(@getImageSize("..".$directory."/".$file));
               echo "<td><img src=\"".$url_upload.$rep_upload."!divers/".$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>";
      } else {
         echo "<table border=\"0\" width=\"100%\"><tr align=\"left\">";
         echo "<td>[&nbsp;<a href=\"upload_list.php?op=img&amp;action=!divers\" class=\"NOIR\">!divers</a>&nbsp;]</td>";
         echo "</tr></table>";
         echo "<hr noshade>";
      }

      // directory !mime
      if ((substr($ed_profil,1,1)=="1") and ($action=="!mime")) {
         $directory=str_replace($racine,"",$rep_upload."!mime");
         $handle=opendir("..".$directory);
         while ($file = readdir($handle)) $filelist[] = $file;
         asort($filelist);
         $ibid=2;
         echo "<table border=\"0\" width=\"100%\"><tr align=\"center\">";
         echo "<td>[!mime]</td>";
         while (list ($key, $file) = each ($filelist)) {
            if (ereg(".gif|.jpg|.png",$file)) {
               $size=verifsize(@getImageSize("..".$directory."/".$file));
               echo "<td><img src=\"".$url_upload.$rep_upload."!mime/".$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>";
      } else {
         echo "<table border=\"0\" width=\"100%\"><tr align=\"left\">";
         echo "<td>[&nbsp;<a href=\"upload_list.php?op=img&amp;action=!mime\" class=\"NOIR\">!mime</a>&nbsp;]</td>";
         echo "</tr></table>";
         echo "<hr noshade>";
      }
      if ((substr($ed_profil,2,1)=="1") and ($action=="standard")) {
         // directory upload standard for images
         echo "<p align=\"center\">";
         $directory=str_replace($racine,"",$rep_upload);
         $handle=opendir("..".$directory);
         while ($file = readdir($handle)) $filelist[] = $file;
         asort($filelist);
         $ibid=2;
         while (list ($key, $file) = each ($filelist)) {
            if (ereg(".gif|.jpg|.png",$file)) {
               $size=verifsize(@getImageSize("..".$directory."/".$file));
               echo "<img src=\"".$url_upload.$rep_upload.$file."\" $size border=\"0\" hspace=\"2\" vspace=\"2\" align=\"middle\" alt=\"$file\" />";
               if ($ibid>=$ed_nb_images) {
                  echo "<br />";
                  $ibid=1;
               } else {
                  $ibid++;
               }
            }
         }
         echo "</p>";
         closedir($handle);
         unset ($filelist);
      } else {
         echo "<table border=\"0\" width=\"100%\"><tr align=\"left\">";
         echo "<td>[&nbsp;<a href=\"upload_list.php?op=img&amp;action=standard\" class=\"NOIR\">".upload_translate("Télécharg.")."</a>&nbsp;]</td>";
         echo "</tr></table>";
         echo "<hr noshade>";
      }
   } else {
      if (substr($ed_profil,3,1)=="1") {
         // directory upload standard for document
         $directory=str_replace($racine,"",$rep_upload);
         $handle=opendir("..".$directory);
         while ($file = readdir($handle)) $filelist[] = $file;
         asort($filelist);
         while (list ($key, $file) = each ($filelist)) {
            if (!ereg("index.html|!mime|!divers|\.\.|.gif|.jpg|.png",$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.$rep_upload.$file."\"><img src=\"".$url_upload.$rep_upload.$typeM."\" border=\"0\" hspace=\"2\" vspace=\"2\" align=\"middle\" alt=\"$file\" /></a>&nbsp;&nbsp;] <br />";
               }
            }
         }
         closedir($handle);
      }
   }
   echo "</body></html>";
?>
