Location: PHPKode > scripts > phpShowtime > phpshowtime/index.php
<? /* 
       ---------------------------------------------------------
       ---          phpShowtime by KYBERNETIKA GmbH          ---
       ---         http://phpShowtime.kybernetika.de         ---
       ---                Release 09.10.2006                 ---
       ---------------------------------------------------------
   */  

   header ("Content-Type: text/html; charset=UTF-8");

   include "config.php";
//   $dictionary = "";
//   load_dictionary_sk();
   
   if (file_exists($resources."/colors/".$color_theme_file)){
     include $resources."/colors/".$color_theme_file;  
   } else {
     include $resources."/colors/colors_default.php";
   }
      
   // Do not change these parameters
   $recreate_thumbnails_dirs       = FALSE;         // Thumbnails for directories will be recreated on every request
   $recreate_thumbnails_images     = FALSE;         // Thumbnails for images will be recreated on every request
   $folder_caption_height_prozent  = 0.15;          // 15%
   $folder_footer_height_prozent   = 0.05;          // 05%
   $square_thumbnails              = FALSE;
   $properties                     = "";
   $allowed_thumbnail_size[0]      = 100;
   $allowed_thumbnail_size[1]      = 200;
   $allowed_thumbnail_size[2]      = 300;
   $allowed_thumbnail_size_default = 200;
   $caption_font_size              = 8;
   $corners_created                = TRUE;
   //Search is temporary switched off
   $_POST['s'] =                     "";
   $_REQUEST['s'] =                  "";
   if ($album_root=="") {
      $album_root=substr($_SERVER["PHP_SELF"],0,strrpos($_SERVER["PHP_SELF"],"/")+1);
   }
   $album_root_path=properpath($_SERVER["DOCUMENT_ROOT"]."/".$album_root);
//   info();
   $request_raw = (isset($_REQUEST['r'])) ? $_REQUEST['r'] : "";
   $message=(isset($_REQUEST['m'])) ? trim($_REQUEST['m']) : "";
   $request=$request_raw;
   if ($request=="") {
      $cmd="i";
      $request="/";
   } else {
      if (substr($request,0,1)=="/") {
         $cmd="i";
      } else {
         $cmd    =substr($request,0,1);
         $request=substr($request,strpos($request,0,"/")+1);
      }
   }

   $form_submitted=(isset($_POST['c'])) ? $_POST['c'] : "";
   if ($form_submitted==1){

      $search_string =$_POST['s'];
      $password_raw  =$_POST['a'];
      if (!empty($_COOKIE["a"]))
        $password_dummy=str_repeat("*", strlen($_COOKIE["a"]));
      else
        $password_dummy="";
        
      if ($password_raw=="") {
         setcookie("a",FALSE,time()-3600);
         $password="";
      }
      if ($password_raw!="" && $password_raw!=$password_dummy) {
         setcookie("a",$password_raw,time()+60*60*24); // one day
         $password=$password_raw;
      }
      if ($password_raw!="" && $password_raw==$password_dummy) {
         $password=$_COOKIE["a"];
      }

      if ($search_string=="" && $password!="" && $immediate_search) {
         $search_string=$password;
      }
      if ($search_string=="" && $password=="") {
         $cmd="i";
         $request="";
      }
      if ($search_string!="") {
         $cmd="k";
      }
   
   } else {
      $password=(isset($_COOKIE["a"])) ? $_COOKIE["a"] : "";
   }

   $quality=(isset($_GET['q'])) ? $_GET['q'] : "";
   if ($quality) {
         setcookie("q",$quality,time()+60*60*24*30*12);
   } else {
      $quality=(isset($_COOKIE["q"])) ? $_COOKIE["q"] : "";
   }
   switch (strtoupper($quality)) {
      case "L":
      case "LOW":
         $quality="LOW";
         break;
      case "L":
      case "HIGH":
         $quality="HIGH";
         break;

      default:
         $quality=$default_image_quality;
         break;
   }

   $thumbnail_size=(isset($_GET['t'])) ? $_GET['t'] : "";
   $thumbnail_size_cookie=(isset($_COOKIE["ts"])) ? $_COOKIE["ts"] : "";
      
   if (!$thumbnail_size) {
      $thumbnail_size=(isset($_POST['t'])) ? $_POST['t'] : "";
   }
   
   switch ($thumbnail_size) {
      case $allowed_thumbnail_size[0]:
      case $allowed_thumbnail_size[1]:
      case $allowed_thumbnail_size[2]:
         break;
      default:
         $thumbnail_size=$thumbnail_size_cookie;
         switch ($thumbnail_size) {
            case $allowed_thumbnail_size[0]:
            case $allowed_thumbnail_size[1]:
            case $allowed_thumbnail_size[2]:
               break;
            default:
               $thumbnail_size = $allowed_thumbnail_size_default;
         }
   }
   
   switch ($thumbnail_size) {
      case $allowed_thumbnail_size[0]:
         $caption_font_size=10;
         $properties_font_size=9;
         break;
      case $allowed_thumbnail_size[1]:
         $caption_font_size=12;
         $properties_font_size=11;
         break;
      case $allowed_thumbnail_size[2]:
         $caption_font_size=14;
         $properties_font_size=12;
         break;
   }
   
   if ($thumbnail_size!=$thumbnail_size_cookie) {
      setcookie("ts",$thumbnail_size,time()+60*60*24*31*12); // one year
   }
//   echo "thumbnail_size:$thumbnail_size";   
//   info();
   
   switch ($cmd) {
      case "c": // Delete image
         deleteImage();
         break;
      case "e": // Fileinfo Editor
         if (htmlHeader())
            htmlEditor();
         htmlFooter();
         break;
      case "g": // Generate all thumbnails
         htmlHeader();
         htmlComplett();
         htmlFooterSignature();
         htmlFooter();
         break;
      case "h": // Thumbnail
         makeImageAsDirectoryThumbnail();
         break;
      case "i": // Index
         if (htmlHeader()){
            htmlIndex();
            htmlFooterSignature();
         }
         htmlFooter();
         break;
      case "k": // Keyword lookup
         htmlHeader();
         htmlSearch();
         htmlFooterSignature();
         htmlFooter();
         break;
      case "m": // Mail directory
         htmlHeader();
         htmlMailer();
         htmlFooter();
         break;
      case "o": // color themes
         echo "<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=setup_frame.php?r=i".urlencode($request)."\">";
         break;
      case "p": // Picture
         if ($quality=="LOW") {
            sendImageLowQuality();
         } else {
            sendImageFile($album_root_path.$request);
         }
         break;
      case "q": // Save changes from editor to filename
         saveEditor();
         break;
      case "r": // Keyword rebuild
         break;
      case "s": // Slide
         if ($message) {
         	submitMessage();
         }
         $margin=0;
         htmlHeader();
         htmlSlide();
         htmlFooter();
         break;
      case "t": // Thumbnail
         getThumbnail($request);
         break;
      case "u": // upload a file
         uploadImage();
         break;
      default:
         htmlHeader();
         echo "Command not supported!";
         htmlFooterSignature();
         htmlFooter();
         break;
   }
   exit;

function deleteImage(){

  global $password;
  global $master_password;
  global $album_root_path;
  global $request;
  
  if ($password!=$master_password){
    echo t("Access denied")."!<br>";
    return;
  }
  
  $file = properPath($album_root_path."/".$request);
  if (file_exists($file))
    unlink($file);
  $newpath = substr($request,0,strrpos($request, "/")); 
  echo "<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=".$_SERVER["SCRIPT_NAME"]."?r=i".urlencode($newpath)."\">";
  //echo "New target is $newpath";
  exit;

}

function makeImageAsDirectoryThumbnail(){
  
  global $password;
  global $master_password;
  global $request;
  global $album_root_path;
  global $properties;
  
  if ($password!=$master_password) {
    echo t("Access denied")."!<br>";
    return;
  }
  
  $directory=substr($request,0,strrpos($request,"/"));
  deleteThumbnailDirectory($directory);
  
  getProperties($album_root_path.$directory,TRUE);
  $properties[$album_root_path.$directory]["THUMBNAIL"]=$request;
  
  $new_content = getPropertyFileContent($album_root_path.$directory);
  $property_filename=getPropertyFilename($album_root_path.$directory);
  if (file_exists($property_filename)) {
    unlink($property_filename);
  }
  if (function_exists("file_put_contents")){
     file_put_contents($property_filename,$new_content);
  } else {
     $fileHandler = fopen ($property_filename, "w");
     fwrite ($fileHandler, $new_content);
     fclose ($fileHandler);
  }
  
  echo "<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=".$_SERVER["SCRIPT_NAME"]."?r=i".urlencode($directory)."\">";

}

function submitMessage(){

   global $message;
   global $request;
   global $album_root_path;

   // exit if no message
   if ($message=="") return;
   
   $property_filename = getPropertyFilename($album_root_path."/".$request);
   $lines = getPropertyFileContent($album_root_path."/".$request);

   // prevent writing same message twice
   $pos = strpos($lines,":  ".$message."\n");
   if ($pos>0) return;

   $lines = $lines."\n"."Comment:       ".date("j. M. Y").":  ".$message."\n";
          
   if (file_exists($property_filename)) {
      unlink($property_filename);
   }
   
   if (function_exists("file_put_contents")){
      file_put_contents($property_filename,$lines);
   } else {
      $fileHandler = fopen ($property_filename, "w");
      fwrite ($fileHandler, $lines);
      fclose ($fileHandler);
   }

   global $email_coments_to;
   global $email_from;
   if ($email_coments_to!=""){
      
      $lines="New comment on picture in your phpShowtime gallery:\n"
            ."\n"
            ."http://".$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"]."?r=s".urlencode($request)."\n"
            ."\n"
            .$lines;
      $headers = "From: $email_from \r\n" .
                 "Reply-To: $email_from \r\n" .
                 "X-Mailer: PHP/".phpversion();
      mail($email_coments_to,"phpShowtime: New comment on picture",$lines,$headers);
   }
   
}

function htmlSearch(){

   global $app_path;
   global $album_root_path;
   global $search_string;
   
   $file_index=scanKeywords($album_root_path);

   foreach ($file_index as $file => $keywords) {
      foreach ($keywords as $keyw_nr => $keyword) {
         if (!is_numeric($keyword) && $keyword!="") {
            $keyword_index[strtoupper($keyword)][]=$file;
         }
      }
   }
   unset($file_index);
   
   foreach ($keyword_index as $keyword => $file) {
      $keyword_index[$keyword]=array_unique ($file);
   }

   $search_string_upper=strtoupper($search_string);

   //root folder
   htmlThumbnailDirectory("");
   
   //Login-Search form
   htmlLoginTable("");
   
   echo "<hr>";
   
   if ($keyword_index[$search_string_upper]){

      //Show directories
      $dir_counter_with_access=0;
      foreach ($keyword_index[$search_string_upper] as $keyword => $file) {
         if (is_dir($file)){
            getProperties($file);
            if (checkAccess($file)) {
               $dir_counter_with_access++;
               $dir_url="/".str_replace($album_root_path,"",$file);
               htmlThumbnailDirectory($dir_url);
            }
         } 
      }
      if ($dir_counter_with_access>0) echo "<hr>\n";         

      //Show files
      $img_counter_with_access=0;
      foreach ($keyword_index[$search_string_upper] as $keyword => $file) {
         if (!is_dir($file)){
            getProperties($file);
            if (checkAccess($file)) {
               $img_counter_with_access++;
               $file_url="/".str_replace($album_root_path,"",$file);
               htmlThumbnailPicture($file_url);
            }
         }
      }
      if ($img_counter_with_access>0) echo "<hr>\n";         

   }

   if ($dir_counter_with_access+$img_counter_with_access==0){
      echo "<center><b>No relevant file was found.</b></center><hr>";
   }

}

function htmlAdminTools(){

   global $password;
   global $master_password;
   global $thumbnail_size;
   global $allowed_thumbnail_size;
   global $frame_width;
   global $frame_gap;

   // Only for Admins
   if ($password!=$master_password) return;

   switch ($thumbnail_size) {
      case $allowed_thumbnail_size[0]:
         $font_size=9;
         $tab_width=2*$thumbnail_size;
         break;
      case $allowed_thumbnail_size[1]:
         $font_size=11;
         $tab_width=$thumbnail_size;
         break;
      case $allowed_thumbnail_size[2]:
         $font_size=14;
         $tab_width=$thumbnail_size;
         break;
      default:
         $font_size=14;
         $tab_width=$thumbnail_size;
         break;
   }
   $selected[$thumbnail_size]=" selected";
   $table_height=$thumbnail_size*0.95;
?>
   <form method="post" action="<?=$_SERVER['SCRIPT_NAME']?>" name=myAdminForm id=myAdminForm>
      <select name=r style="font-size:<?=$font_size?>;" onChange="myAdminForm.submit()">
         <option selected value=""><?=t("Admin toolbox")?></option>
         <option value="d"><?=t("Thumbnail clean-up")?></option>
         <option value="g"><?=t("Generate all thumbnails")?></option>
      </select>
   </form>
<?
}

function htmlLoginTable(){

   global $search_string;
   global $form_submitted;
   global $password;
   global $thumbnail_size;
   global $allowed_thumbnail_size;
   global $frame_width;
   global $frame_gap;

   $password_dummy=str_repeat("*", strlen($password));
   
   if ($form_submitted==1){
      if ($password==$search_string) {
         if (!$_REQUEST['s']){
             $search_string="";
         }
      }
   }
   switch ($thumbnail_size) {
      case $allowed_thumbnail_size[0]:
         $font_size=9;
         $tab_width=2*$thumbnail_size;
         break;
      case $allowed_thumbnail_size[1]:
         $font_size=11;
         $tab_width=$thumbnail_size;
         break;
      case $allowed_thumbnail_size[2]:
         $font_size=14;
         $tab_width=$thumbnail_size;
         break;
      default:
         $font_size=14;
         $tab_width=$thumbnail_size;
         break;
   }
   $selected[$thumbnail_size]=" selected";
   $table_height=$thumbnail_size*0.95;
?>
<table style="display:inline; height:<?=$table_height?>px;">
  <tr>
    <td>
        <table style="height:<?=$table_height?>px;">
          <tr style="height:40%;"><td>&nbsp;</td></tr>
          <form method="post" action="<?=$_SERVER['SCRIPT_NAME']?>" name=myForm>
          <tr>
            <td style="font-size:<?=$font_size?>; text-align:right;"><?=t("Password")?>:</td>
            <td><input type=password name="a" value="<?=$password_dummy?>" style="width: 100px; text-align: center;"></td>
<!--          <tr style="width:10%;">
            <td style="font-size:<?=$font_size?>; text-align:right;"><?=t("Search")?>:</td>
            <td><input type="text" name="s" style="text-align:center;width: 100px;" value="<?=$search_string?>"></td>
          </tr>
//-->          <tr>
            <td style="font-size:<?=$font_size?>;">&nbsp;</td>
            <td><input type=hidden name="c" value="1"><input type="submit" value="<?=t("Submit")?>" style="width: 100px; font-size: <?=$font_size?>;"></td>
          </tr>
          </form>
          <tr style="height:40%;"><td>&nbsp;</td></tr>
        </table>
    </td>
  </tr>
</table><?
}

function imageColorAllocateHex(&$image,$string) {
   if (substr ($string,0,1)=="#") $string = substr ($string,1);

   if (strlen($string)==6) {
      sscanf($string, "%2x%2x%2x", $red, $green, $blue);
      $color=ImageColorAllocate($image,$red,$green,$blue);
      return $color;
   } else {
      $color=ImageColorAllocate($image,255,255,255);
      return $color;
   }
}

function createCorners(){
	
   global $html_color_direcory_front;
   global $html_color_direcory_back;
   global $thumbnail_size;
   global $app_path;
   global $corners_created;
   global $allowed_thumbnail_size;
   global $resources;
   
   if (function_exists("imagegif")){ 
      $filename_extension="gif";
   } else {
      $filename_extension="png";
   }

   $filename_lr=$app_path.$resources."/corners/".$thumbnail_size."_".substr($html_color_direcory_front,1)."_lr.".$filename_extension;
   $filename_ll=$app_path.$resources."/corners/".$thumbnail_size."_".substr($html_color_direcory_front,1)."_ll.".$filename_extension;
   $filename_tr=$app_path.$resources."/corners/".$thumbnail_size."_".substr($html_color_direcory_back,1)."_tr.".$filename_extension;
   $filename_tl=$app_path.$resources."/corners/".$thumbnail_size."_".substr($html_color_direcory_front,1)."_tl.".$filename_extension;
   $filename_mm=$app_path.$resources."/corners/".$thumbnail_size."_".substr($html_color_direcory_front,1)."_".substr($html_color_direcory_back,1)."_mm.".$filename_extension;
   
   if (file_exists($filename_lr)) unlink ($filename_lr);
   if (file_exists($filename_ll)) unlink ($filename_ll);
   if (file_exists($filename_tr)) unlink ($filename_tr);
   if (file_exists($filename_tl)) unlink ($filename_tl);
   if (file_exists($filename_mm)) unlink ($filename_mm);

//   echo "Creating corners for thumbnail size ".$thumbnail_size;
   switch ($thumbnail_size){
     case $allowed_thumbnail_size[0]:
       $side=$thumbnail_size*0.12;
       break;
       
     case $allowed_thumbnail_size[1]:
       $side=$thumbnail_size*0.07;
       break;
     case $allowed_thumbnail_size[2]:
       $side=$thumbnail_size*0.06;
       break;
   }
   
   
   $img_tl = ImageCreateTrueColor($side, $side);
   $img_color_front       = imageColorAllocateHex($img_tl, $html_color_direcory_front);
   $img_color_background  = ImageColorAt         ($img_tl, 1, 1);
   ImageArc ( $img_tl, $side-1, $side-1, $side*2-1, $side*2-1, 0, 360, $img_color_front );
   ImageFill( $img_tl, $side-1, $side-1, $img_color_front);
   ImageColorTransparent ($img_tl, $img_color_background);
   ImageTrueColorToPalette ($img_tl, TRUE, 255);
   
   $img_tr = ImageCreateTrueColor($side, $side);
   $img_color_back        = imageColorAllocateHex($img_tr, $html_color_direcory_back);
   $img_color_background  = ImageColorAt         ($img_tr, 1, 1);
   ImageArc ( $img_tr, 0, $side-1, $side*2-1, $side*2-1, 0, 360, $img_color_back );
   ImageFill( $img_tr, 0, $side-1, $img_color_back);
   ImageColorTransparent ($img_tr, $img_color_background);
   ImageTrueColorToPalette ($img_tr, TRUE, 255);

   $img_lr = ImageCreateTrueColor($side, $side);
   $img_color_front       = imageColorAllocateHex($img_lr, $html_color_direcory_front);
   $img_color_background  = ImageColorAt         ($img_lr, 1, 1);
   ImageArc ( $img_lr, 0, 0, $side*2-1, $side*2-1, 0, 360, $img_color_front );
   ImageFill( $img_lr, 0, 0, $img_color_front);
   ImageColorTransparent ($img_lr, $img_color_background);
   ImageTrueColorToPalette ($img_lr, TRUE, 255);

   $img_ll = ImageCreateTrueColor($side, $side);
   $img_color_front       = imageColorAllocateHex($img_ll, $html_color_direcory_front);
   $img_color_background  = ImageColorAt         ($img_ll, 1, 1);
   ImageArc ( $img_ll, $side-1, 0, $side*2-1, $side*2-1, 0, 360, $img_color_front );
   ImageFill( $img_ll, $side-1, 0, $img_color_front);
   ImageColorTransparent ($img_ll, $img_color_background);
   ImageTrueColorToPalette ($img_ll, TRUE, 255);

   $img_mm = imagecreatetruecolor($side, $side*2);
   $img_color_front = imageColorAllocateHex($img_mm, $html_color_direcory_front);
   $img_color_back  = imageColorAllocateHex($img_mm, $html_color_direcory_back);
   ImageArc ( $img_mm, $side-1, $side-1, $side*2-2, $side*2-2, 180, 270, $img_color_back );
   ImageArc ( $img_mm, 0      , $side*2-1, $side*2-2, $side*2-2, 0, 360, $img_color_front );
   ImageFill( $img_mm, $side-1, $side-1, $img_color_back);
   ImageFill( $img_mm, 0      , $side*2-1, $img_color_front);
   $img_color_background=ImageColorAt($img_mm, 0, 0);
   ImageColorTransparent($img_mm, $img_color_background);
   imagetruecolortopalette ($img_mm, TRUE, 255);
   
   if ($filename_extension=="gif"){ 
      imagegif($img_lr, $filename_lr);
      imagegif($img_ll, $filename_ll);
      imagegif($img_tr, $filename_tr);
      imagegif($img_tl, $filename_tl);
      imagegif($img_mm, $filename_mm);
   } else {
      imagepng($img_lr, $filename_lr);
      imagepng($img_ll, $filename_ll);
      imagepng($img_tr, $filename_tr);
      imagepng($img_tl, $filename_tl);
      imagepng($img_mm, $filename_mm);
   }

   imagedestroy ($img_lr);
   imagedestroy ($img_ll);
   imagedestroy ($img_tr);
   imagedestroy ($img_tl);
   imagedestroy ($img_mm);
   $corners_created = TRUE;
}

function htmlThumbnailDirectory($dir_url, $edit_modus=TRUE){

   global $thumbnail_size;
   global $password;
   global $master_password;
   global $properties;
   global $caption_font_size;
   global $html_color_direcory_front;
   global $html_color_direcory_back;
   global $html_color_backgroud;
   global $app_path;
   global $corners_created;
   global $album_title;
   global $resources;
   global $folder_caption_height_prozent;
   global $folder_footer_height_prozent;
   global $album_root_path;
   
   $dir_url=properPath($dir_url);

   if (function_exists("imagegif")){ 
      $filename_extension="gif";
   } else {
      $filename_extension="png";
   }
   
   $filename_tl  =$resources."/corners/".$thumbnail_size."_".substr($html_color_direcory_front,1)."_tl.".$filename_extension;
   $filename_tr  =$resources."/corners/".$thumbnail_size."_".substr($html_color_direcory_back,1)."_tr.".$filename_extension;
   $filename_ll  =$resources."/corners/".$thumbnail_size."_".substr($html_color_direcory_front,1)."_ll.".$filename_extension;
   $filename_lr  =$resources."/corners/".$thumbnail_size."_".substr($html_color_direcory_front,1)."_lr.".$filename_extension;
   $filename_mm  =$resources."/corners/".$thumbnail_size."_".substr($html_color_direcory_front,1)."_".substr($html_color_direcory_back,1)."_mm.".$filename_extension;
   $filename_img =$_SERVER["SCRIPT_NAME"]."?t=".$thumbnail_size."&amp;r=t".urlencode($dir_url);
   $link_img     =$_SERVER["SCRIPT_NAME"]."?r=i".urlencode($dir_url);
   $link_prop    =$_SERVER["SCRIPT_NAME"]."?r=e".urlencode($dir_url);
   $link_mail    =$_SERVER["SCRIPT_NAME"]."?r=m".urlencode($dir_url);
   if (!file_exists($app_path.$filename_tl) || $corners_created==FALSE ) createCorners();

   $path = $album_root_path.$dir_url;
   $path = properPath($path);
   //echo "<pre>$properties</pre>";
   $style="";
   if (isset($properties[$path])) {
     $style="border:red solid 1px;";
   }
   if (!isset($properties[$path]['CAPTION'])) {
      $caption=substr($dir_url,strrpos($dir_url,"/")+1);
      $caption=utf8_encode($caption);
      if (is_numeric(substr($caption,0,2)) && substr($caption,2,1)==" ") $caption=substr($caption,3);
      if ($caption=="") $caption=$album_title;
   } else {
      $caption=$properties[$path]['CAPTION'];
   }
   $caption=str_replace(" ","&nbsp;",$caption);
   $thumbnail_w=$thumbnail_size;
   $thumbnail_h=$thumbnail_size*(1-$folder_caption_height_prozent-$folder_footer_height_prozent);
   
?>
<table style="display:inline;">
  <tr>
    <td>
        <table>
        	<tr>
        		<td colspan=2></td>
        		<td rowspan=2 valign=bottom><img alt="" src="<?=$filename_mm?>"></td>
        		<td class="bg" rowspan=2><?=$caption?></td>
        		<td valign=bottom><img alt="" src="<?=$filename_tr?>"></td>
        	</tr>
        	<tr>
        		<td valign=bottom><img alt="" src="<?=$filename_tl?>"></td>
        		<td class="fg_c"></td>
        		<td class="bg"></td>
        	</tr>
        	<tr>
        		<td colspan=5 class="fg_c">
        			<a href="<?=$link_img?>"><img alt="" src="<?=$filename_img?>" height="<?=$thumbnail_h?>" width="<?=$thumbnail_w?>"></a>
        		</td>
        	</tr>
        	<tr>
        		<td valign=top><img alt="" src="<?=$filename_ll?>"></td>
        		<td class="fg_l" colspan=3>
<?    if ($password==$master_password && !empty($properties[$path]["PASSWORD"])) 
        echo "<img src='".$resources."/key.gif' title='".t("Restricted access").": ".implode(", ",$properties[$path]["PASSWORD"])."'>&nbsp;";
  		if ($password==$master_password && $edit_modus){
?>            <a href="<?=$link_mail?>" class="p"><img src="<?=$resources?>/email.gif" alt="E-Mail" title="Send link to your friend using E-Mail"></a>&nbsp;
              <a href="<?=$link_prop?>" class="p"><img src="<?=$resources?>/properties.gif" alt="Properties" title="Edit Properties for this directory (caption, keywords, passwords...)" style="<?=$style?>"</a>
<?		} 
?>          </td> 
        		<td valign=top><img alt="" src="<?=$filename_lr?>"></td>
        	</tr>
        </table>
    </td>
  </tr>
</table>&nbsp;
<?
}

function htmlThumbnailPicture($file_url, $edit_modus=TRUE){

   global $password;
   global $master_password;
   global $thumbnail_size;
   global $properties;
   global $frame_width;
   global $frame_gap;
   global $caption_font_size;
   global $show_captions;
   global $show_filename_if_no_caption;
   global $resources;
   global $album_root_path;
   
   $link_slide    =$_SERVER["SCRIPT_NAME"]."?t=".$thumbnail_size."&amp;r=s".urlencode($file_url);
   $link_thumbnail=$_SERVER["SCRIPT_NAME"]."?t=".$thumbnail_size."&amp;r=t".urlencode($file_url);
   $link_prop     =$_SERVER["SCRIPT_NAME"]."?r=e".urlencode($file_url);
   $link_mail     =$_SERVER["SCRIPT_NAME"]."?r=m".urlencode($file_url);
   $link_thmb     =$_SERVER["SCRIPT_NAME"]."?r=h".urlencode($file_url);

   $path = $album_root_path.$file_url;
   $path = properPath($path);
   $style="";
   if (isset($properties[$path])) {
     $style="border:red solid 1px;";
   }
   if (!isset($properties[$path]['CAPTION'])) {
      $caption="";
      if($show_filename_if_no_caption){
         $caption=substr($file_url,strrpos($file_url,"/")+1);
         if (is_numeric(substr($caption,0,2)) && substr($caption,2,1)==" ") $caption=substr($caption,3);
      }
   } else {
      $caption=$properties[$path]['CAPTION'];
   }
   if ($caption!="") {
      $title=" title=\"".$caption."\""
            ." alt=\"".$caption."\"";
   } else {
      $fileInfo = pathinfo($file_url);
      $title=" title=\"".$fileInfo["basename"]."\""
            ." alt=\"".$fileInfo["basename"]."\"";
   }
   $caption=str_replace(" ","&nbsp;",$caption);
   $caption_height = 0;
   if ($show_captions) {
      $caption_height = 2.1*$caption_font_size;
   }
   if ($password==$master_password && $edit_modus) {
      $caption_height = $caption_height + 2.1*$caption_font_size;
   }
   $table_height=$thumbnail_size+2*$frame_width+2*$frame_gap+$caption_height+3;
?>
<table style="display:inline;">
  <tr>
    <td class="t">
      <table style="height:<?=$table_height?>">
        <tr>
          <td>
            <a href="<?=$link_slide?>">
              <img class="t" src="<?=$link_thumbnail?>"<?=$title?>>
            </a>
          </td>
        </tr>
<?      if ($show_captions) {?>
        <tr>
          <td class="c"><?=$caption?><br>&nbsp;</td>
        </tr>
<?      }
        if ($password==$master_password && $edit_modus){?>
        <tr>
          <td class="p">
<?      if (!empty($properties[$path]["PASSWORD"])) 
           echo "<img src='".$resources."/key.gif' title='".t("Restricted access").": ".implode(", ",$properties[$path]["PASSWORD"])."'>&nbsp;";
?>          <a class="p" href="<?=$link_thmb?>"><img src="<?=$resources?>/directory.gif" alt="Thumbnail" title="Make this image a thumbnail for whole directory"></a>&nbsp;
            <a class="p" href="<?=$link_mail?>"><img src="<?=$resources?>/email.gif" alt="E-Mail" title="Send link to your friend using E-Mail"></a>&nbsp;
            <a class="p" href="<?=$link_prop?>"><img src="<?=$resources?>/properties.gif" alt="Properties" title="Edit Properties for this image (caption, keywords, passwords...)" style="<?=$style?>"></a>&nbsp;&nbsp;
          </td>
        </tr>
<?      }?>
      </table>
    </td>
  </tr>
</table>&nbsp;
<?
}

function scanKeywords($dirName){

   $d = dir($dirName);
   while($entry = $d->read()) {
      switch ($entry){
         case ".":
         case "..":
            // forget them
            break;
         default:
            $path = properPath($dirName.$entry);
            if (is_dir($path)) {
               getProperties($path);
               $raw=$entry;
               $raw=str_replace(","," ",$raw);
               $raw=str_replace("_"," ",$raw);
               $raw=str_replace("."," ",$raw);
               $directory_keywords_1=explode(" ",$raw);
               $directory_keywords_1=array_merge($directory_keywords_1, $properties[$path]['KEYWORDS']);
               $directory_keywords_1=array_merge($directory_keywords_1, $properties[$path]['CAPTION']);
               $file_index[$path."/"]=$directory_keywords_1;
               $subdirectory_index=scanKeywords($path."/");
               $file_index = array_merge($file_index, $subdirectory_index); 
            } else {
               switch (strtolower(getExtension($entry))){
                  case "gif":
                  case "jpg":
                  case "jpeg":
                  case "png":
                     getProperties($path);
                     if (is_array($properties[$path]['KEYWORDS'])) {
                        $file_index[$path]=$properties[$dirName.$entry]['KEYWORDS'];
                     }
                     break;
                  default:
                     // forget this file
               }
           }
       }
   }
   $d->close();
  // echoo ($file_index,"file_index;");
   return $file_index;
}

function scanFilesystem($dirName){
	
   global $property_file_extension;
   
   $d = dir($dirName);
   while($entry = $d -> read()) {
      switch ($entry){
         case ".":
         case "..":
            // forget them
            $entry=false;
            break;
         default:
            $path=properPath($dirName."/".$entry);
            if (is_dir($path)) {
               $filesystem_index[] = array($path,"D");            //Directory
               $subdirectory_index = scanFilesystem($path."/");
               $filesystem_index   = array_merge($filesystem_index, $subdirectory_index); 
            } else {
               switch (strtolower(getExtension($entry))){
                  case "gif":
                  case "jpg":
                  case "jpeg":
                  case "png":
                      $filesystem_index[]=array($path,"I"); //Image
                     break;
                  case $property_file_extension:
                     $filesystem_index[]=array($path,"T");      //Text File
                  default:
                     // forget this file
               }
            }
      }
   }
   $d->close();
   //echoo ($filesystem_index,"filesystem_index for ".$dirName);
   if (isset($filesystem_index))
     return $filesystem_index;
   
}

function sendImageLowQuality(){

   global $album_root_path;
   global $request;

   $image_orig=getImage($album_root_path.$request);
   $last_modif_time = getLastModifiedTime($album_root_path.$request);
   $orig_w=imagesx($image_orig);
   $orig_h=imagesy($image_orig);
   if ($orig_w<=640 && $orig_h<640){
      $target_h=$orig_h;
      $target_w=$orig_w;
   } else {
      if ($orig_w>$orig_h){
         $target_w=640;
         $target_h=$target_w/($orig_w/$orig_h);
      } else {
         $target_h=640;
         $target_w=$target_h*($orig_w/$orig_h);
      }
   }
   $image_targ = imagecreatetruecolor($target_w,$target_h);
   imagecopyresampled ($image_targ, $image_orig, 0, 0, 0, 0, $target_w, $target_h, $orig_w, $orig_h);
   $html_color_text =  imagecolorallocate ($image_targ, 233, 14, 91); 
   imagestring ($image_targ, 5, $target_w-12, $target_h-18,  "L", $html_color_text); 
   $file=basename("resized_".substr($request,strrpos($request,"/")+1));
   sendImage($image_targ,$file,$last_modif_time);
}
   
function getThumbnail($image_filename){
   global $album_root_path;
   
   if (!file_exists($album_root_path.$image_filename)) {
     sendErrorImage("File does not exist");
   }
   if (is_dir($album_root_path.$image_filename)){
      createThumbnailDirectory($image_filename);
   } else {
      createThumbnailPicture($album_root_path."/".$image_filename);
   }

} 

function sendErrorImage($message){

   global $thumbnail_size;
   $image = imageCreateTrueColor ($thumbnail_size, $thumbnail_size);
   $html_color_text =  imageColorAllocate ($image, 233, 14, 91); 
   imagestring ($image, 1, 30, $thumbnail_size/2,  t($message)."!", $html_color_text);
   sendImage($image,"Error.jpg");
   
}

function getThumbnailFilename($image_filename){

   global $thumbnail_size;
   global $resources;
   global $album_root_path;
   
   $fileInfo = pathinfo($image_filename);
   $fileInfo["extension"]= isset($fileInfo["extension"]) ? $fileInfo["extension"] : "";
   if ($fileInfo["extension"]=="gif" AND !function_exists("imagegif"))
      $thmb_extension="gif";
   else 
      $thmb_extension="jpg";
   
   $basename=ereg_replace(".$","",basename($image_filename,$fileInfo["extension"]));
   $thmb_path=substr($fileInfo["dirname"],strlen($album_root_path));
   $thmb_path=properPath($album_root_path."/".$resources."/thumbnails/".$thumbnail_size."/".$thmb_path);
   $thmb_filename=properPath($thmb_path."/".$basename.".".$thmb_extension);

   return(array ("thmb_extension"=>$thmb_extension
                ,"thmb_path"=>$thmb_path
                ,"thmb_filename"=>$thmb_filename
                ));
}

function createThumbnailPicture($image_filename){

   global $thumbnail_size;
   global $recreate_thumbnails_images;
   global $album_root_path;
   
   extract(getThumbnailFilename($image_filename));
  // echo "$thmb_filename";
   
   if (file_exists($thmb_filename)) {
      if ($recreate_thumbnails_images) {
         unlink ($thmb_filename);
      } else {
         sendImageFile($thmb_filename);
         exit;
      }
   }

   global $square_thumbnails;
   global $html_color_backgroud;
	
   $src_img = getImage($image_filename);
   
   $orig_w=imagesx($src_img);
   $orig_h=imagesy($src_img);
   if ($orig_h<$thumbnail_size || $orig_w<$thumbnail_size) {
      if ($orig_h<$thumbnail_size && $orig_w<$thumbnail_size) {
         // the original image is smaller than the thumbnail,
         // no conversion and thumbnail necessary, send original file
         sendImageFile($image_filename);
         exit;
      } elseif ($orig_h>$thumbnail_size) {
         $thmb_h=$thumbnail_size;
         $thmb_w=$thumbnail_size/($orig_h/$orig_w);
      } elseif ($orig_w>$thumbnail_size) {
         $thmb_w=$thumbnail_size;
         $thmb_h=$thumbnail_size*($orig_h/$orig_w);
      } else {
         $thmb_h=$orig_h;
         $thmb_w=$orig_w;
      }
      $offset_x=($thumbnail_size-$thmb_w)/2;
      $offset_y=($thumbnail_size-$thmb_h)/2;
   } else {
      if ($orig_h>$orig_w) {
         $thmb_h=$thumbnail_size;
         $thmb_w=$thumbnail_size/($orig_h/$orig_w);
         $offset_x=($thumbnail_size-$thmb_w)/2;
         $offset_y=0;
      } else {
         $thmb_h=$thumbnail_size*($orig_h/$orig_w);
         $thmb_w=$thumbnail_size;
         $offset_x=0;
         $offset_y=($thumbnail_size-$thmb_h)/2;
      }   
   }
   //echo "OR:W*H=$orig_w*$orig_h<br>TH:W*H=$thmb_w*$thmb_h<br>";

   if($square_thumbnails) {
      $thumbnail_size_w=$thumbnail_size;
      $thumbnail_size_h=$thumbnail_size;
   } else {
      $thumbnail_size_w=$thmb_w;
      $thumbnail_size_h=$thmb_h;
      $offset_x=0;
      $offset_y=0;
   }
   $thmb_img = imageCreateTrueColor($thumbnail_size_w,$thumbnail_size_h);
   if($square_thumbnails) {
   	$color = imageColorAllocateHex($thmb_img, $html_color_backgroud);
      imagefill ( $thmb_img, 0, 0, $color );
   }
   
   imageCopyResampled ($thmb_img, $src_img, $offset_x, $offset_y, 0, 0, $thmb_w, $thmb_h, $orig_w, $orig_h);

   mkpath($thmb_path);
   if ($thmb_extension=="gif") {
      imagegif($thmb_img,$thmb_filename);
   } else {
      imagejpeg($thmb_img,$thmb_filename);
   }
   imageDestroy ($src_img);
   imageDestroy ($thmb_img);
   sendImageFile($thmb_filename);
   
}

function createThumbnailDirectory($directory_path)
{
   global $thumbnail_size;
   global $properties;
   global $request;
   global $recreate_thumbnails_dirs;
   global $resources;
   global $date_of_last_theme_change;
   global $album_root_path;
   
   //Clean up the current filename
   $directory_path=properPath($directory_path);
   
   //Create filename of the thumbnail
   $thmb_path=substr($directory_path,0,strrpos($directory_path,"/"));
   $thmb_base=substr($directory_path,strrpos($directory_path,"/")+1);
   
   if ($request!=""){
     $thmb_filename=$album_root_path."/".$resources."/thumbnails/".$thumbnail_size.$thmb_path."/".$thmb_base.".png";
   } else {
     $thmb_filename=$album_root_path."/".$resources."/thumbnails/".$thumbnail_size."_root.png";
   }
   
   if (file_exists($thmb_filename)) {
     if ($recreate_thumbnails_dirs) {
       unlink ($thmb_filename);
     } else {
       if (date('Y-m-d H:i:s',filemtime($thmb_filename))<$date_of_last_theme_change) {
         unlink ($thmb_filename);
       } else {
         sendImageFile($thmb_filename);
       }
     }
   }

   global $folder_caption_height_prozent;
   global $folder_footer_height_prozent;
   global $html_color_direcory_front;
   global $html_color_direcory_back;
   global $html_color_backgroud;

   $thumbnail_w=$thumbnail_size;
   $thumbnail_h=$thumbnail_size*(1-$folder_caption_height_prozent-$folder_footer_height_prozent);
   $border=$thumbnail_w*$folder_footer_height_prozent/2;
   $thmb_img = ImageCreateTrueColor($thumbnail_w, $thumbnail_h);
   $folder_color_backgroud  = imageColorAllocateHex($thmb_img, $html_color_direcory_front);
   imagefill($thmb_img,0,0, $folder_color_backgroud);
   ImageColorTransparent($thmb_img, $folder_color_backgroud);
	
	 // Is there a special image that should be used as thu8mbnail for this directory?
   getProperties($album_root_path.$directory_path, TRUE);
   if (isset($properties[properPath($album_root_path."/".$directory_path)]["THUMBNAIL"])){
      $dir_thmb_file=utf8_decode(properPath($album_root_path.$properties[properPath($album_root_path.$directory_path)]["THUMBNAIL"]));
      if (file_exists($dir_thmb_file)) {
        $src_img = getImage($dir_thmb_file);
        $orig_w=imagesx($src_img);
        $orig_h=imagesy($src_img);
        if ($orig_h/$orig_w>$thumbnail_h/$thumbnail_w) {
          // Vertical thumbnail
          $thmb_h=$thumbnail_h;
          $thmb_w=$thmb_h*($orig_w/$orig_h);
        } else {
          // Horizontal thumbnail
          $thmb_w=$thumbnail_w;
          $thmb_h=$thmb_w*($orig_h/$orig_w);
        } 
        $thmb_x=($thumbnail_w-$thmb_w)/2;
        $thmb_y=($thumbnail_h-$thmb_h)/2;
     //   echo "$thumbnail_h thumbnail_h<br>$thumbnail_w thumbnail_w<br>$thmb_h thmb_h<br>$thmb_w thmb_w<br>$thmb_x thmb_x<br>$thmb_y thmb_y<br>"; 
        imageCopyResampled($thmb_img,$src_img,$thmb_x,$thmb_y,0,0,$thmb_w,$thmb_h,$orig_w,$orig_h);
        imagepng($thmb_img,$thmb_filename);
        imagedestroy($src_img);
        imagedestroy($thmb_img);
        sendImageFile($thmb_filename);
        return;
      }
    }

    $images=getArrayWithImages($album_root_path.$directory_path);
    
    if (count($images)==0) {
       //there are no images in the directory
       $thmb_filename=$album_root_path."/".$resources."/thumbnails/".$thumbnail_size."_empty.png";

       if (!file_exists($thmb_filename)) {
         mkpath($album_root_path."/".$resources."/thumbnails/");
         imagepng($thmb_img,$thmb_filename);
       } else {
         if ($recreate_thumbnails_dirs || (date('Y-m-d H:i:s',filemtime($thmb_filename))<$date_of_last_theme_change)) {
           unlink ($thmb_filename);
           imagepng($thmb_img,$thmb_filename);
         }
       }
       sendImageFile($thmb_filename);
       return;
    }
    
    //get four horizontal images
    for ($img_counter=0;$img_counter<count($images);$img_counter++) {
       if (round($images[$img_counter][2])>round($images[$img_counter][3],2)){
          $used_images[]=$images[$img_counter];
          if (count($used_images)>=4) $img_counter=count($used_images)+1;
       }
    }

    //get four vertical images
    if (count($used_images)<4){
       unset($used_images);
       for ($img_counter=0;$img_counter<count($images);$img_counter++) {
       if (round($images[$img_counter][2])<round($images[$img_counter][3],2)){
             $used_images[]=$images[$img_counter];
             if (count($used_images)>=4) $img_counter=count($used_images)+1;
          }
       }
    }

    //get first four images
    if (count($used_images)<4){
       unset($used_images);
       for ($img_counter=0;$img_counter<count($images);$img_counter++) {
          $used_images[]=$images[$img_counter];
          if (count($used_images)>=4) $img_counter=count($used_images)+1;
       }
    }
    
//    echo "directory_path:$directory_path<br>thmb_filename:   $thmb_filename<br>thmb_base:  $thmb_base-------<br>";
    
    //generate the thumbnail
    for ($img_counter=0;$img_counter<count($used_images);$img_counter++) {
       $subimage_filename=$album_root_path.$directory_path.$thumbnail_size."/".getFilenameWithoutExtension($used_images[$img_counter][0]).".jpg";
       if (!file_exists($subimage_filename)) {
          $subimage_filename = $album_root_path.$directory_path."/".$used_images[$img_counter][0];
       }
      // echoo ($subimage_filename,"subimage_filename");
       $src_img = getImage($subimage_filename);
       $orig_w=imagesx($src_img);
       $orig_h=imagesy($src_img);
       if ($orig_h/$orig_w>$thumbnail_h/$thumbnail_w) {
         // Vertical thumbnail
         $thmb_h=($thumbnail_h-$border)/2;
         $thmb_w=$thmb_h*($orig_w/$orig_h);
       } else {
         // Horizontal thumbnail
         $thmb_w=($thumbnail_w-$border)/2;
         $thmb_h=$thmb_w*($orig_h/$orig_w);
       } 
       switch ($img_counter) {
          case 0:
             $offset_x=$thumbnail_w/2-$thmb_w-$border*.5;
             $offset_y=$thumbnail_h/2-$thmb_h-$border*.5;
             break;
          case 1:
             $offset_x=$thumbnail_w/2+$border*.5;
             $offset_y=$thumbnail_h/2-$thmb_h-$border*.5;
             break;
          case 2:
             $offset_x=$thumbnail_w/2-$thmb_w-$border*.5;
             $offset_y=$thumbnail_h/2+$border*.5;
             break;
          case 3:
             $offset_x=$thumbnail_w/2+$border*.5;
             $offset_y=$thumbnail_h/2+$border*.5;
             $img_counter=count($used_images)+1;
             break;
          default:
             $offset_x=-1;
             $offset_y=-1;
             break;
       }
       imageCopyResampled($thmb_img,$src_img,$offset_x,$offset_y,0,0,$thmb_w,$thmb_h,$orig_w,$orig_h);
    } 

   // save the image
   imagepng($thmb_img,$thmb_filename);
   imagedestroy($thmb_img);
   imagedestroy($src_img);
   
   // return the filename of the thumbail
   sendImageFile($thmb_filename);
}

function getProperties($path, $this_file_only=FALSE){

  global $properties;
  
  $path = properPath($path);

  //Have properties for this path been read before?
  if (isset($properties[$path])) return;  
  
  // If the path you are looking for does not exist, forget it completely
  if (!file_exists($path)) return;
   
  $property_filename=getPropertyFilename($path);
  if (is_dir($path)) {
    $property_file['dir']=$property_filename;
    $properties[$path]["TYPE"]="DIRECTORY";
  } else {
    $property_file['file']=$property_filename;
    if ($this_file_only == FALSE) {
       $slash=strrpos($property_file['file'],"/");
       $property_file['dir']=getPropertyFilename(substr($path,0,strrpos($path,"/")));
    }
  }

  foreach ($property_file as $key => $property_filename) {
    while (strpos($property_filename,"//")>0) {
      $property_filename=str_replace("//","/",$property_filename);
    }
      if (file_exists($property_filename)) {
         $lines = file ($property_filename); 
         foreach ($lines as $line_num => $line) { 
            if (substr($line,0,1)!="#") {
               $int_space = strpos($line," ");
               $int_equal = strpos($line,"=");
               $int_tab   = strpos($line,"\t");
               $int_colon = strpos($line,":");
   
               $start=strlen($line)+1;
               if ($int_space && $int_space < $start ) $start=$int_space;
               if ($int_equal && $int_equal < $start ) $start=$int_equal;
               if ($int_tab   && $int_tab   < $start ) $start=$int_tab;
               if ($int_colon && $int_colon < $start ) $start=$int_colon;
               
               if ($start<strlen($line)+1) {
                  $current_property=strtoupper(substr($line,0,$start));
                  $current_value=trim(substr($line,$start+1));
                  if (trim($current_value)!=""){
                     // Only to catch if thew people use different spellings
                     switch ($current_property){
                        case "COMMENT":
                          $current_property="COMMENTS";
                          break;
                        case "KEYWORD":
                          $current_property="KEYWORDS";
                          break;
                        case "PASSWORDS":
                          $current_property="PASSWORD";
                          break;
                        case "SHOW_CAPTIONS":
                        case "SHOWCAPTIONS":
                        case "CAPTIONS":
                          $current_property="SHOW_CAPTIONS";
                          break;
                      }
                      
                      if (isset($property_file['file']) && $key=="dir") {
                        switch ($current_property){
                          case "PASSWORD":
                            $wordlist=explode(" ",$current_value);
                            //var_dump($properties);
                            $properties[$path][$current_property]=array_merge((isset($properties[$path][$current_property]) ? $properties[$path][$current_property] : Array()) ,$wordlist);
                            break;
                       }
                     } else {
                        switch ($current_property){
                        	
                           // These parameters are space separated
                           case "KEYWORDS":
                           case "PASSWORD":
                              $wordlist=explode(" ",$current_value);
                              $properties[$path][$current_property]=array_merge((isset($properties[$path][$current_property]) ? $properties[$path][$current_property] : Array()) ,$wordlist);
                              break;
                           
                           //This parameters have to be put into an array
                           case "COMMENTS":
                              $properties[$path][$current_property][]=$current_value;
                              break;
                              
                           //These are True/False parameters
                           case "SHOW_CAPTIONS":
                           case "UPLOAD":
                              switch (strtoupper($current_value)) {
                              case "TRUE":
                              case "YES":
                              case "1":
                              case "-1":
                              case "-1":
                                $properties[$path][$current_property]=TRUE;
                                break;
                              default:
                              //  $properties[$path][$current_property]=FALSE;
                              }
                              break;
                              
                           // Defaultly one value per parameter (for example caption)
                           default:
                              $properties[$path][$current_property]=$current_value;
                        }
                     }
                  }
               }
            }
         }
      }
   }
}

function htmlHeader() {

   global $html_color_backgroud;
   global $html_color_text;

   global $html_color_img_backgroud;
   global $html_color_img_frame;
   global $html_color_img_caption;

   global $html_color_direcory_front;
   global $html_color_direcory_back;
   global $html_color_direcory_back_text;

   global $html_color_direcory_front_text;
   global $html_color_text_properties;
   global $thumbnail_size;
   global $cmd;
   global $frame_width;
   global $frame_gap;
   global $caption_font_size;
   global $properties_font_size;
   global $album_title;
   
   $on_load="";
   $overflow="";
   if ($cmd=="s") {
      $on_load=" onLoad=jsGetImage()";
      $overflow=" overflow:hidden;";
      $margin=0;
   } else {
      $margin=10;
   }
?>
<html>
<head>
  <title><?=htmlentities($album_title)?></title>
	<meta http-equiv='content-type' content='text/html; charset=UTF-8'>
	<style TYPE='text/css' media='screen'>
		body      <?//  0 ?>  {font-family:verdana; background-color:<?=$html_color_backgroud?>; color:<?=$html_color_text?>; margin:<?=$margin?>;<?=$overflow?>}
		a         <?//  1 ?>  {color:<?=$html_color_text?>;}
		a.p       <?//  2 ?>  {color:<?=$html_color_text_properties?>;}
		a:link    <?//  3 ?>  {color:<?=$html_color_text?>; text-decoration:none; background-color:transparent;}
		a:visited <?//  4 ?>  {color:<?=$html_color_text?>; text-decoration:none; background-color:transparent;}
		a:hover   <?//  5 ?>  {color:<?=$html_color_backgroud?>; text-decoration:none; background-color:<?=$html_color_text?>;}
		img       <?//  6 ?>  {border:none; font-size:9px;}
		img.t     <?//  7 ?>  {margin:<?=$frame_gap?>; border:solid; border-color:<?=$html_color_img_frame?>; border-width:<?=$frame_width?>px;}
		td        <?//  8 ?>  {border:solid black 0px; padding:0px; color:<?=$html_color_text?>; text-align:center; vertical-align:middle;}
		table     <?//  9 ?>  {width:<?=($thumbnail_size+2*$frame_width+2*$frame_gap)?>px; border-collapse:collapse; margin:0px;}
		td.fg_c   <?// 10 ?>  {width:<?=($thumbnail_size+2*$frame_width+2*$frame_gap)?>px; background-color:<?=$html_color_direcory_front?>; color:<?=$html_color_direcory_front_text?>; font-size:<?=$caption_font_size?>; text-align:center;}
		td.c      <?// 11 ?>  {font-size:<?=$caption_font_size?>; margin-bottom:<?=$frame_gap?>; font-weight:normal; color:<?=$html_color_img_caption?>;}
		td.p      <?// 12 ?>  {text-align:right; font-size:<?=($properties_font_size)?>; font-weight:bold; color:<?=$html_color_text_properties?>;}
		td.t      <?// 13 ?>  {background-color:<?=$html_color_img_backgroud?>; color:<?=$html_color_img_caption?>;}
		td.m      <?// 14 ?>  {vertical-align:top; text-align:left; font-weight:bold;  font-size:<?=($properties_font_size)?>;}
		td.fg_l   <?// 15 ?>  {text-align:right; font-size:<?=$properties_font_size?>; font-weight:bold; width:<?=($thumbnail_size+2*$frame_width+2*$frame_gap)?>px; background-color:<?=$html_color_direcory_front?>; color:<?=$html_color_text_properties?>;}
		td.bg     <?// 16 ?>  {background-color:<?=$html_color_direcory_back?>; color:<?=$html_color_direcory_back_text?>; text-align:right; font-size:<?=$caption_font_size?>; font-weight:bold;}
	</style>
</head>
<body<?=$on_load?>>
<?
   if (function_exists('ImageCreateTrueColor')) {
     // OK
   } else {
      echo "<center><h1>phpShowtime critical problem<br><br>";
      if (!function_exists('ImageCreateTrueColor')) echo "Extension PHP_GD2.DLL is missing<br>";
//      if (!function_exists('exif_read_data'))       echo "Extension PHP_EXIF.DLL is missing<br>";
      echo "<br>Please modify your PHP.INI</h1></center>";
      return false;
   }
   return TRUE;
}

function validateEmail($email){
  if(eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $email)) {
    return TRUE;
  } else {
    return FALSE;
  }
}

function htmlMailer() {
   
   global $password;
   global $master_password;
   
   if ($password!=$master_password) {
      echo t("Access denied")."!<br>";
      return;
   }

   global $request;
   global $album_root_path;
   global $properties;
   global $adresbook_filename;
   global $show_captions;
   $show_captions = FALSE;
   
   if (file_exists($adresbook_filename)) {
     $addressbook = file ($adresbook_filename);
     foreach ($addressbook as $line_num => $address) {
       $addressbook[$line_num]=trim($address);
     }
   } else {
     $addressbook = array();
   }
   $previous_recipients_string = (empty($_REQUEST["p"]) ? "" : $_REQUEST["p"]);
   if ($previous_recipients_string!="") {
     $previous_recipients = explode(",",$previous_recipients_string);
     foreach ($previous_recipients as $line_num => $address) {
       if (trim($address)!=""){
         $previous_recipients_new[]=trim($address);
       }
     }
     $previous_recipients=$previous_recipients_new;
   } else {
     $previous_recipients = array();    
   }
   $error_recipients = array();
   $new_recipients = array();
   
   $path = properPath($album_root_path.$request);
   getProperties($path);
   $body=(empty($_REQUEST["body"]) ? "" : $_REQUEST["body"]);
   $subject=(empty($_REQUEST["s"]) ? t("New pictures") : $_REQUEST["s"]);
   if ($body==""){
      if (is_dir($path)) {
        $link="http://".$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"]."?r=i".urlencode($request);
        $link_cancel=$link;
      } else {
        $link="http://".$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"]."?r=s".urlencode($request);
        $link_cancel="?r=i".urlencode(substr($request,0,strrpos($request,"/")));
      }
      $body = "Hi!\n"
            . "\n"
            . "I have put new pictures online:\n"
            . $link."\n"
            . "\n"
            . "Have fun!\n"
            . "\n"
            . "MickeyMiner"; 
   }

   $r = (empty($_REQUEST["c"]) ? "" : $_REQUEST["c"]);
   if ($r=="s") { 
      $number_of_mails=$_REQUEST["n"];
      for ($i = 0; $i < $number_of_mails; $i++) {
        $email=trim($_REQUEST["adr_".$i]);
        if ($email!=""){
          if (validateEmail($email)) {
            if ($_REQUEST["send_".$i]){
              $new_recipients[] = $email;
            } else {
              $addressbook[] = $email;
            }
          } else {
            $error_recipients[]=$email;
          }
        }
      }

      if (count($new_recipients)>0) {
        global $email_from;
        global $email_bcc;
        $previous_recipients_string .= ",".implode(",",$new_recipients);
        $headers = "From: $email_from \r\n" .
                   "Reply-To: $email_from \r\n" .
                   "X-Mailer: PHP/".phpversion()." \r\n" .
                   "Bcc: $email_bcc";
    
          // this part is sending emails
          foreach ($new_recipients as $nr => $recipient){
             //echo "mailing to ".$recipient."<br>";
             if (!mail($recipient, $subject, $body, $headers)){
                $error_recipients[]=$recipient;
             };
          }
          

      }
      
      $addressbook=array_merge($addressbook,$previous_recipients,$new_recipients);
      if (count($addressbook)>0) {
        $addressbook=my_array_unique($addressbook);
        $fileHandler = fopen ($adresbook_filename, "w");
        foreach ($addressbook as $line_num => $address) {
          fwrite ($fileHandler, $address."\n");
        }
        fclose ($fileHandler);
      }
   }
   
   $addressbook_complett=array_merge($addressbook,$error_recipients);
   $addressbook_complett=my_array_unique($addressbook_complett);
   if (count($addressbook_complett)>0) 
    sort($addressbook_complett);
   
   // minimum of 10 input fields
   do { 
      $addressbook_complett[]="";
   } while (count($addressbook_complett)<10); 
 
?>
  <form method="post" action="<?=$_SERVER['SCRIPT_NAME']?>">
  <table border=0>
    <tr>
      <td class='m'><?=t("To")?>:&nbsp;&nbsp;</td>
      <td style="text-align:left; vertical-align:top;" >
        <table>
<? 
   foreach ($addressbook_complett as $line_num => $address) { 
      $address = trim($address);
      $mail_sent="";
      if (in_array($address, $new_recipients)) { 
        $mail_sent=" &lt;-- OK (".t("last mailing").")";
      }elseif (in_array($address, $previous_recipients)) { 
        $mail_sent=" &lt;-- OK";
      }elseif (in_array($address, $error_recipients)) {
        $mail_sent=" ".t("ERROR");
      }
      $checked="";
      echo "<tr><td nowrap style='text-align:left;'><input size='40' name='adr_".$line_num."' value='".$address."'>&nbsp;<input type=checkbox ".$checked." name='send_".$line_num."'>&nbsp; ".$mail_sent."</td></tr>";
   }
?>      </table>    
      </td>
      <td class='m' style='text-align:right;'>
<?       if (is_dir($path)) {
            htmlThumbnailDirectory($request,FALSE);
         } else {
            htmlThumbnailPicture($request,FALSE);
         }
?>    </td>
    </tr>
    <tr>
      <td class='m'><?=t("Subject")?>:&nbsp;&nbsp;</td>
      <td colspan=2><input type="text" name="s" value="<?=$subject?>" style="width:800"></td>
    </tr>
    <tr>
      <td class='m'><?=t("Body")?>:&nbsp;&nbsp;</td>
      <td colspan=2><textarea name="body" style="height:400; width:800"><?=$body;?></textarea></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td style="text-align:left;" colspan=2>
        <input type="submit" style="width:100px" value="<?=t("Send")?>">
        <input type="hidden" name="n" value="<?=count($addressbook_complett)?>">
        <input type="hidden" name="c" value="s">
        <input type="hidden" name="p" value="<?=$previous_recipients_string?>">
        <input type="hidden" name="r" value="m<?=($request)?>">
        <a href="<?=$link_cancel?>"><input type="button"  style="width:100px" value="<?=t("Cancel")?>/<?=t("Return")?>"></a>
      </td>
    </tr>
  </table>
  </form>
<?
}
function my_array_unique($somearray){
  $tmparr = array_unique($somearray);
  $newarr = Array();
  $i=0;
  foreach ($tmparr as $v) { 
    $newarr[$i] = $v;
    $i++;
  }
  return $newarr;
}

function htmlFooter() {
   echo "</body>";
   echo "</html>";
}

function htmlFooterSignature() {
	
	global $allowed_thumbnail_size;
	global $html_color_img_frame;
	global $html_color_text;
	global $request;
	global $resources;
   global $password;
   global $master_password;
   global $email_from;
	
?>	<table style="text-align:right; width:100%;">
		<tr style="text-align:left; font-size:8pt; font-weight:bold;">
			<td style="text-align:left; font-size:8pt; font-weight:bold;" nowrap><?=t("Thumbnail size")?>:</td>
			<td><a title="Small Thumbnails"  href="<?=$_SERVER["SCRIPT_NAME"]."?t=".$allowed_thumbnail_size[0]."&amp;r=i".urlencode($request)?>"><img class="t" src="<?=$resources?>/blue.gif" alt="Small Thumbnails"  style="height:15; width:15; border: 2px; margin:2;"></a></td>
			<td><a title="Middle Thumbnails" href="<?=$_SERVER["SCRIPT_NAME"]."?t=".$allowed_thumbnail_size[1]."&amp;r=i".urlencode($request)?>"><img class="t" src="<?=$resources?>/blue.gif" alt="Middle Thumbnails" style="height:20; width:20; border: 2px; margin:2;"></a></td>
			<td><a title="Large Thumbnails"  href="<?=$_SERVER["SCRIPT_NAME"]."?t=".$allowed_thumbnail_size[2]."&amp;r=i".urlencode($request)?>"><img class="t" src="<?=$resources?>/blue.gif" alt="Large Thumbnails"  style="height:25; width:25; border: 2px; margin:2;"></a></td>
<?  if ($password==$master_password ){
?>     <td nowrap>&nbsp;&nbsp;
          <form method="post" action="<?=$_SERVER['SCRIPT_NAME']?>" name=myAdminForm id=myAdminForm>
             &nbsp;&nbsp;<select name=r style="font-size:8pt;" onChange="myAdminForm.submit()">
                <option selected value=""><?=t("Admin toolbox")?></option>
                <option value="g"><?=t("Generate all thumbnails")?></option>
                <option value="o"><?=t("Color themes")?></option>
             </select>
          </form>
       </td>
<?     if ($request==""){
         //who is using phpShowtime? no abuse... maximum of 1 update notification in 3 months
         // include "http://phpShowtime.kybernetika.de/showtime.php?e=".urlencode($email_from);
       }
    }
?>			<td width="100%">&nbsp;</td>
			<td style="text-align:center; width:100%;">
				<a href="http://phpShowtime.kybernetika.de/" style="font-size:11pt; font-weight:bold; text-decoration: none;">phpShowtime</a>
				<br>
				<a href="http://www.kybernetika.de/" title="KYBERNETIKA GmbH" style="font-size:6pt;"><img src="http://www.kybernetika.de/images/kyb.gif" width="125" height="15" alt="KYBERNETIKA GmbH"></a>
			</td>
		</tr>
	</table>
<?
}

function echoo($var,$varname=""){
  
   // Only show the variable in a readable form
   echo "<pre><hr>";
   echo "Variable name: $varname<br>";
   print_r ($var);
   echo "<hr></pre>";
}

function properPath($path){
  
  $path = ereg_replace('[\/]{1,}',"/", $path);
  $path = ereg_replace('[/]$',"", $path);
  return $path;
  
}

function checkAccess($filename){

   global $password;
   global $master_password;
   
   //The Master has always right
   if ($password==$master_password) return TRUE;

   $filename = properPath($filename);
   global $properties;

   //Is the current password in the list of passwords for this file?
   if (isset($properties[$filename]['PASSWORD'])){
      $access_granted=in_array($password,$properties[$filename]['PASSWORD']);
   } else {
      // no password set. default ist TRUE
      $access_granted=TRUE;
   }
   return $access_granted;
}

function htmlIndex(){

   global $album_root_path;
   global $request;
   global $properties;
   global $html_color_text;
   global $resources;
   global $show_captions;
   global $show_captions_default;

   if(substr($request,0,1)=="/") {
      $requested_dir=substr($request,1);
   } else {
      $requested_dir=$request;
   }

   //root folder
   getProperties($album_root_path);
   htmlThumbnailDirectory("");
   
   //Login-Search form
   if(!$requested_dir){
      htmlLoginTable("");
   }
      
   // Path from root to current directory
   unset ($directories);
   $directories = explode("/", $requested_dir);
   if (is_array($directories)){
      $dir_url="/";
      foreach ($directories as $dir_counter=>$directory) {
         if ($directory) {
            $path=$album_root_path.$dir_url.$directory;
            $path = properPath($path);
            getProperties($path);
            if (checkAccess($path)) {
               htmlThumbnailDirectory($dir_url.$directory);
            }
            $dir_url.=$directory."/";
         }
      }
   }
   echo "<hr>";

   // Directories of the requested folder
   if (file_exists($album_root_path."/".$requested_dir)) {
      unset ($directories);
      $d = dir($album_root_path."/".$requested_dir);
      while (FALSE !== ($entry = $d->read())) { 
        switch ($entry) {
        case ".":
        case "..":
        case $resources:
           break;
        default:
          if (is_dir($album_root_path."/".$request."/".$entry)){
            $directories[]=$entry;
          }
        }
      } 
      $d->close();
      if (isset($directories)){
         sort ( $directories );
         $dir_counter_with_access=0;
         foreach ($directories as $dir_counter=>$directory) {
            $path=properPath($album_root_path."/".$request."/".$directory);
            getProperties($path);
            if (checkAccess($path)) {
               $dir_counter_with_access++;
               htmlThumbnailDirectory($request."/".$directory);
            }
         }
         if ($dir_counter_with_access>0) echo "<hr>\n";
      }
   }
   
   // Images
   $path_dir = properPath($album_root_path."/".$requested_dir);
   $images=getArrayWithImages($path_dir);
   $show_captions=(isset($properties[$path_dir]["SHOW_CAPTIONS"]) ? $properties[$path_dir]["SHOW_CAPTIONS"] : $show_captions_default);

   if (is_array($images)){
      $img_counter_with_access=0;
      foreach ($images as $img_counter=>$image) {
         $path=properPath($path_dir."/".$image[0]);
         getProperties($path);
         if (checkAccess($path)) {
            htmlThumbnailPicture($request."/".$image[0]);
            $img_counter_with_access++;
         }
      }
      if ($img_counter_with_access>0) echo "<hr>";
   }

   $path=properPath($album_root_path."/".$requested_dir);
   getProperties($path);
   
   if (isset($properties[$path]['UPLOAD']) && $properties[$path]['UPLOAD']==TRUE) {
      global $allowed_thumbnail_size;
?>	<center>
		<form method="post" enctype="multipart/form-data" action="<?=$_SERVER['SCRIPT_NAME']?>">
			<input type="file" value="<?=t("Image file")?>" name="image">
			<input type="submit" value="<?=t("Upload")?>">
			<input type="hidden" name="r" value="u<?=$request?>">
			<input type="hidden" name="MAX_FILE_SIZE" value="512000">
		</form>
	</center>
	<hr>
<?
   }
}

function htmlComplett(){

   global $album_root_path;
   global $app_path;
   global $password;
   global $master_password;
   global $properties;
   global $resources;
	global $thumbnail_size;
	
   if ($password!=$master_password){
      echo t("Access denied")."!<br>";
      return;
   }

   $filesystem=scanFilesystem($album_root_path);

  //  echo $resources;
  //   echoo ($filesystem);
   //exit;
   
   //root folder
   htmlThumbnailDirectory("");
   
   //Login-Search form
   htmlLoginTable("");
   
   $r=properPath($album_root_path."/".$resources);
   $t=properPath($album_root_path."/".$resources."/thumbnails/");
   $thumbnail_counter=0;
   $new_thumbnails_in_directory_counter=0;
   $limit = 100;
   echo "<hr>";
   
   // Loop through filesystem
   ob_start();
   foreach ($filesystem as $entry_counter => $entry) {
      if (substr($entry[0],0,strlen($r))!=$r){
         // these are the real directories with images
         $resource = "/".str_replace($album_root_path,"",$entry[0]);
         if ($entry[1]=="D") {
            if ($new_thumbnails_in_directory_counter==0){
               ob_end_clean();
            } else {
               if ($thumbnail_counter==0) echo t("Only newly generated thumbnails are shown!<hr>");
               ob_flush();
            }
            ob_start();
            echo "<br>\n";
            htmlThumbnailDirectory($resource);
            $new_thumbnails_in_directory_counter=0;
         } elseif ($entry[1]=="I") {
            extract(getThumbnailFilename($entry[0]));
            $show_thumbnail=false;
            if (!file_exists($thmb_filename)){
               // image must be larger than the thumbnail size!
               list($width, $height, $type, $attr) = getimagesize($entry[0]);
               if ($width>$thumbnail_size and $height>$thumbnail_size){
                 $show_thumbnail=true;
               }
            } else {
              if (filemtime($entry[0])>filemtime($thmb_filename)){
                 deleteThumbnailImage($entry[0]);
                 $show_thumbnail=true;
              }
            }
            if ($show_thumbnail){
               $new_thumbnails_in_directory_counter++;
               htmlThumbnailPicture($resource);
               $thumbnail_counter++;
            }
         }
      } else {
        // deleting old/uncesessary thumbnails
        if (substr($entry[0],0,strlen($t))==$t AND strlen($entry[0])>strlen($t)+4){
          // these are thumbnails
          $image = properPath($album_root_path."/".substr($entry[0], strpos($entry[0],"/",strlen($t)+1)));
          if (file_exists($image)){
            // ok, forget it. there is an belonging image
          } else {
            // maybe there is an GIF image?
            $image_gif = substr($image,0,strrpos($image,".")).".gif";
            $image_png = substr($image,0,strrpos($image,".")).".png";
            $image_dir = substr($image,0,strrpos($image,"."));
            if (file_exists($image_gif) OR file_exists($image_png) OR is_dir($image_dir)){
               // ok, forget it. there is an belonging image
            } else {
              unlink($entry[0]);
            }
          }
        }
      }
      
      if ($thumbnail_counter>$limit){
        echo "<hr>Limit of $limit thumbnails per page was reached.<br>".
             "Please wait until loading of this page finishes, and reload this page again.<br>".
             "Another $limit thumbnails will be pre-generated and saved.<hr>";
        break;
      }
   }
   if ($new_thumbnails_in_directory_counter==0){
      ob_end_clean();
   } else {
      ob_flush();
   }
   if ($thumbnail_counter<$limit) {
      if ( $thumbnail_counter>0 ) echo "<hr>When the pages finishes loading, ";
      echo t("All thumbnails with size $thumbnail_size are generated!<hr>");
   }

}

function uploadImage(){

   global $album_root_path;
   global $request;
   global $_FILES;
   
   switch ($_FILES['image']['type']){
      case "image/jpeg":
      case "image/pjpeg":
      case "image/gif":
      case "image/png":
         //OK
         break;
      default:
      echo "<META HTTP-EQUIV=Refresh CONTENT=\"10; URL=".$_SERVER["SCRIPT_NAME"]."?r=i".urlencode($request)."\">";
      htmlHeader();
?><table style="width:100%; height:100%;">
    <tr>
      <td align='center' valign='middle'>This type of file is not supported!<br>
        <br>
        <a href="<?=$_SERVER["SCRIPT_NAME"]."?r=i".urlencode($request)?>">Return</a>
        <br>Your type: <?=$_FILES['image']['type']?>
      </td>
    </tr>
  </table>
<?    htmlFooter();
      return;
   }
   
   $uploadfile= $album_root_path.$request."/".basename($_FILES['image']['name']);

   if (file_exists($uploadfile)){
      unlink ($uploadfile);
   }
   
   if (!move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile)) { 
      echo "<META HTTP-EQUIV=Refresh CONTENT=\"5; URL=".$_SERVER["SCRIPT_NAME"]."?r=i".$request."\">";
      htmlHeader();
      echo "<table width='100%' height='100%'>\n<tr>\n<td align='center' valign='middle'>\n";
      echo "Your file could not be uploaded!"; 
      echo "<br><br>";
      echo "<a href=\"".$_SERVER["SCRIPT_NAME"]."?r=i".urlencode($request)."\">Return</a>";
      echo "</td>\n</tr>\n</table>";
      htmlFooter();
      return;
   } 

   deleteThumbnailDirectory($request);
   deleteThumbnailImage($uploadfile);

   echo "<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=".$_SERVER["SCRIPT_NAME"]."?r=i".$request."\">";
   return;

}

function deleteThumbnailImage($image_filename){
   
   global $allowed_thumbnail_size;
   
   $fileInfo = pathinfo($image_filename);
   $thmb_path=$fileInfo["dirname"];
   foreach ($allowed_thumbnail_size as $thumbnail_size) {
      $thmb_filename=$thmb_path."/".$allowed_thumbnail_size."/".getFilenameWithoutExtension($image_filename).".jpg";
      if (file_exists($thmb_filename)) {
         unlink ($thmb_filename);
      }
   }
   
}

function deleteThumbnailDirectory($request){
   
   global $allowed_thumbnail_size;
   global $resources;
   global $album_root_path;
   
   foreach ($allowed_thumbnail_size as $thumbnail_size) {
      if ($request==""){
        $thmb_filename=properPath($album_root_path."/".$resources."/thumbnails/".$thumbnail_size."_root.png");
      } else {
        $thmb_filename=properPath($album_root_path."/".$resources."/thumbnails/".$thumbnail_size."/".$request.".png");
      }
      $thmb_filename=utf8_decode($thmb_filename);
      if (file_exists($thmb_filename)) {
         unlink ($thmb_filename);
      }
   }
}

function getArrayWithImages($path){

   global $properties;

   if (!file_exists($path)) {
      return;
   }
   
   $counter=0;
    foreach (glob($path."/"."*.*") as $img_path) {
       $entry=substr($img_path,strlen($path)+1);
       if (!is_dir($img_path)){
           if (!is_dir($path.getFilenameWithoutExtension($entry))){
             switch (strtolower(getExtension($entry))) {
             case "png":
             case "gif":
             case "jpg":
                getProperties($img_path,TRUE);
                if (checkAccess($img_path)){
                   $images[$counter][0]=$entry;
                   $images[$counter][1]=getEXIF($path."/".$entry);
                   list($images[$counter][2],$images[$counter][3])=getimagesize($path."/".$entry);
                   $images[$counter][4]=(isset($properties[$img_path]['COMMENTS'])) ? $properties[$img_path]['COMMENTS'] : "";
                   $counter++;
                }
             }
          }
       }
    } 
    if (isset($images)){
       sort ( $images );
       return $images;
    }
}

function info(){
   
   global $album_root, $request, $album_root_path, $cmd, $request_raw, $password;
   global $password_raw, $search_string, $password_dummy, $form_submitted;
   
   echo "<hr><pre>";
   echo "form_submitted:   ".$form_submitted ."\n";
   echo "password:         ".$password       ."\n";
   echo "password_raw:     ".$password_raw   ."\n";
   echo "password_dummy:   ".$password_dummy ."\n";
   echo "search_string:    ".$search_string  ."\n";
   echo "request_raw:      ".$request_raw    ."\n";
   echo "request:          ".$request        ."\n";
   echo "cmd:              ".$cmd            ."\n";
   echo "album_root:       ".$album_root     ."\n";
   echo "album_root_path:  ".$album_root_path."\n";
   echo "$"."_REQUEST:     ";
   print_r ($_REQUEST);
   echo "</pre><hr>";
   flush();
}

function getFilenameWithoutExtension($file){
  $fileInfo = pathinfo($file);
  $name=$fileInfo["basename"];
  $name=substr($name,0,strpos($name,"."));
  return $name;
}

function getExtension($file){

  $fileInfo  = pathinfo($file);
  $extension = $fileInfo["extension"];
  return $extension;
}

function getLastModifiedTime($filename){
   $last_modif_time  = filemtime($filename);
   if (!$last_modif_time) {
      $last_modif_time  = filectime($filename);
   }
   $last_modif_time=gmdate("D, d M Y H:i:s A", $last_modif_time);
   return $last_modif_time;
}

function sendImageFile($image_filename){

   $image_filename=properPath($image_filename);
//   echoo ($image_filename);
   
   if (!file_exists($image_filename)) {
      sendErrorImage ("File does not exist");
   } else {
      getProperties($image_filename);
      if (!checkAccess($image_filename)) {
         sendErrorImage ("Access denied");
      }
   }
   
   $last_modif_time = getLastModifiedTime($image_filename);
   $last_modif_cache = "";
   if (function_exists("apache_request_headers")){
      $headers = apache_request_headers(); 
      foreach ($headers as $header => $value) { 
         if ($header=="If-Modified-Since"){
            $last_modif_cache = $value;
            break;
         }
      } 
   } else {
      global $_SERVER;
      $last_modif_cache = strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]);
   }
   
   $x=0;
   if ($x==1){
      echo "<pre>";
      echo "filename: ".$image_filename."<br>";
      echo "last modified: ".$last_modif_time."<br>";
      echo "client value:".$last_modif_cache."<br>";
      if (function_exists("apache_request_headers")){
         echo "<hr><br>";
         $headers = apache_request_headers(); 
         foreach ($headers as $header => $value) { 
           echo "$header: $value\n";
         }
      } 
      echo "<hr><br>";
      if ($last_modif_cache == $last_modif_time) {
         echo "--- GO FROM CACHE ---";
      } else {
         echo "--- LOAD NEW FILE ---";
      }
      echo "<hr><br>";
      print_r($_SERVER);
      echo "</pre>";
   }   
   
   if ($last_modif_cache == $last_modif_time) {
      header("HTTP/1.0 304 Not Modified");
      ob_end_clean();
      exit;
   } 
   
   $image_type=strtolower(getExtension($image_filename));
   switch ($image_type) {
     case "jpg":
       $image_type="jpeg";
       break;
   }
   //echo $image_filename;
   header("Content-Type: image/".$image_type);
   header("Content-Disposition: inline; filename=".basename($image_filename));
   header("Last-Modified: ".$last_modif_time);
   
   if (function_exists("virtual")){
      if (glob($image_filename[0]!="")) {
         $image_filename=str_replace($_SERVER['DOCUMENT_ROOT'],"",$image_filename);
         
         virtual($image_filename);
         exit;
      }
   }
   
   switch ($image_type) {
   case "png":
      $image=imagecreatefrompng($image_filename);
      imagepng($image);
      exit;
   case "gif":
      $image=imagecreatefromgif($image_filename);
      if (imagetypes() & IMG_GIF) {
        imagegif($image);
      } else {
        imagepng($image);
      }
      exit;
   case "jpg":
   case "jpeg":
      $image=imagecreatefromjpeg($image_filename);
      imagejpeg($image);
      exit;
   default:
      return false;
   }

}

function sendImage($image,$image_filename,$last_modif_time=""){

   if ($image){
      $image_type=strtolower(getExtension($image_filename));
      switch ($image_type) {
         case "jpg":
         case "jpeg":
            $image_type="jpeg";
            break;
         default:
            if (function_exists("imagegif") && $image_type=="gif"){ 
               $image_type="gif";
            } else {
               $image_type="png";
            }
      }
      $file=basename($image_filename);
      header("Content-Type: image/$image_type");
      header("Content-Disposition: inline; filename=$file");
      if ($last_modif_time!="") {
         header("Last-Modified: $last_modif_time");
      }
      switch ($image_type) {
         case "gif":
            imagegif($image);
            break;
         case "png":
            imagepng($image);
            break;
         default:
            imagejpeg($image);
      }
      ImageDestroy($image);
   }
   exit;
}

function getImage($image_filename){
   
   switch (strtolower(getExtension($image_filename))) {
      case "png":
         $image=@imagecreatefrompng($image_filename);
         break;
      case "gif":
         $image=@imagecreatefromgif($image_filename);
         break;
      case "jpg":
      case "jpeg":
         $image=@imagecreatefromjpeg($image_filename);
         break;
      default:
         return false;
   }
   return $image;

}

function getEXIF($filename){

   switch (strtolower(substr($filename,strrpos($filename,".")+1))){
      case "jpg":
      case "jpeg":
      case "tiff":
         //OK
         break;
      default:
         return "";
   }
   
   if (!function_exists('exif_read_data'))
     return "Extension PHP_EXIF.DLL is missing. Please modify your PHP.INI";
     
   $exif = exif_read_data ($filename,0,true); 
   foreach($exif as $key=>$section) { 
      foreach($section as $name=>$val) { 
         switch ("$key.$name") {
            case "IFD0.Make":
            case "IFD0.Model":
            case "EXIF.ExposureTime":
            case "EXIF.ShutterSpeedValue":
            case "EXIF.ISOSpeedRatings":
            case "EXIF.DateTimeOriginal":
            case "EXIF.MaxApertureValue":
            case "EXIF.ApertureValue":
            case "EXIF.Flash":
            case "EXIF.FocalLength":
            case "COMPUTED.ApertureFNumber":
            case "COMPUTED.ExposureTime":
               $buffer[$key.".".$name]=$val;
         }
      } 
   }
//   echoo ($exif,$filename);
   
   $exif ="";
   if (isset($buffer)){
     if (strstr($buffer['IFD0.Model'],$buffer['IFD0.Make'])) {
        $exif.="         Camera: ".gtrim($buffer['IFD0.Model'])."<br>";
     } else {
        $exif.="         Camera: ".gtrim($buffer['IFD0.Make']." ".$buffer['IFD0.Model'])."<br>";
     }
     $exif.="           Date: ".(isset($buffer['EXIF.DateTimeOriginal'])    ?      $buffer['EXIF.DateTimeOriginal'] : "")."<br>";
     $exif.="            ISO: ".(isset($buffer['EXIF.ISOSpeedRatings'])     ?      $buffer['EXIF.ISOSpeedRatings'] : "")."<br>";
     $exif.="  Exposure time: ".(isset($buffer['EXIF.ExposureTime'])        ?      $buffer['EXIF.ExposureTime'] : "").
                                (isset($buffer['COMPUTED.ExposureTime'])    ? "  ".$buffer['COMPUTED.ExposureTime'] : "")."<br>";
     $exif.="       Aperture: ".(isset($buffer['EXIF.MaxApertureValue'])    ?      $buffer['EXIF.MaxApertureValue'] : "") 
                               .(isset($buffer['EXIF.ApertureValue'])       ? "  ".$buffer['EXIF.ApertureValue'] : "")
                               .(isset($buffer['COMPUTED.ApertureFNumber']) ? "  ".$buffer['COMPUTED.ApertureFNumber'] : "")
                               ."<br>";
     $exif.="   Focal length: ".$buffer['EXIF.FocalLength']."<br>";
     if ($buffer['EXIF.Flash']==1) {
        $flash="Yes";
     } else {
        $flash="No";
     }
     $exif.="          Flash: ".$flash;
   }
   return $exif;
}

function gtrim($str){
   $str=trim(ereg_replace (' +', ' ', $str));
   return $str;
}

function getPropertyFilename($path){

   global $property_file_extension;
   global $album_root_path;
   global $resources;
   
   $path = properPath($path);
   
   if (is_dir($path)) {
      //echo "$path<hr>$album_root_path";
      if ($path."/"==$album_root_path) {
        $property_filename=$path."/".$resources."/root.".$property_file_extension;      
      } else {
        $property_filename=$path.".".$property_file_extension;
      }
   } else {
      $property_filename=substr($path,0,strrpos($path,".")).".".$property_file_extension;
   }
   return properPath($property_filename);
   
}

function getPropertyFileContent( $path ){

  global $properties;
  
  $path = properPath($path);
  getProperties($path, TRUE);
	
  $caption=(empty($properties[$path]["CAPTION"]) ? "" : $properties[$path]["CAPTION"]);
  $thumbnail=(empty($properties[$path]["THUMBNAIL"]) ? "" : $properties[$path]["THUMBNAIL"]);
  $type=(empty($properties[$path]["TYPE"]) ? "" : $properties[$path]["TYPE"]);
		
  $lines="Caption:       ".$caption."\n"
	      ."Passwords:     ";
  if (!empty($properties[$path]["PASSWORD"])) $lines .= implode($properties[$path]["PASSWORD"]," ");
  $lines .= "\nKeywords:      ";
  if (!empty($properties[$path]["KEYWORDS"])) $lines .= implode($properties[$path]["KEYWORDS"]," ");
  $lines .= "\n";
  if ($type=="DIRECTORY") {
	
    // these are defaults
    if (!empty($properties[$path]["SHOW_CAPTIONS"])) {$properties[$path]["SHOW_CAPTIONS"]="1";} else {$properties[$path]["SHOW_CAPTIONS"]="0";}
    if (!empty($properties[$path]["UPLOAD"])) {$properties[$path]["UPLOAD"]="1";} else {$properties[$path]["UPLOAD"]="0";}

    $lines .="Thumbnail:     ".$thumbnail."\n"
	        ."ShowCaptions:  ".$properties[$path]["SHOW_CAPTIONS"]."\n"
	        ."Upload:        ".$properties[$path]["UPLOAD"]."\n";
	}
	if (!empty($properties[$path]["COMMENTS"])) {
  	  foreach($properties[$path]["COMMENTS"] as $key=>$comment) { 
  	    $lines .= "Comment:       ".$comment."\n";
  	  }
   }

	return $lines;
   
}

function htmlEditor(){
   
   global $password;
   global $master_password;
   
   if ($password!=$master_password) {
      echo t("Access denied")."!<br>";
      return;
   }

   global $request;
   global $album_root_path;
   global $properties;
   global $show_captions;
   $show_captions = FALSE;
   
   $path = properPath($album_root_path.$request);
   $request = properPath($request);
   if (is_dir($path)) {
      $type="Directory: ";
      $filetype="DIRECTORY";
      htmlThumbnailDirectory($request,FALSE);
      $href_cancel="?r=i".urlencode($request);
      $href_delete="?r=c".urlencode($request);
   } else {
      $type="Image file: ";
      $filetype="FILE";
      htmlThumbnailPicture($request,FALSE);
      $href_cancel="?r=i".urlencode(substr($request,0,strrpos($request,"/")));
      $href_delete="?r=c".urlencode($request);
   }
   $lines = getPropertyFileContent($path);

?>
<form method="post" action="<?=$_SERVER['SCRIPT_NAME']?>">
  <pre><?=$type." ".utf8_encode($request)?></pre>
  <textarea name="con" style="height:400; width:800"><?=$lines;?></textarea><br>&nbsp;<br>
  <input type="submit" value="Submit">
  <input type="hidden" name="f" value="<?=utf8_encode($request)?>">
  <input type="hidden" name="r" value="q">
  <a href="<?=$href_cancel?>"><input type="button" value="Cancel"></a>
<?if (!is_dir($path)){?>
  <a href="<?=$href_delete?>" onclick="return confirm('Do you really want to delete this image?')"><input type="button" value="Delete"></a>
<?}?>
</form>
<?
}

function saveEditor(){

   global $password;
   global $master_password;
   global $request;
   global $album_root_path;
   
   if ($password!=$master_password) {
      echo t("Access denied")."!<br>";
      return;
   }

   $new_content=$_POST['con'];
   $request=$_POST['f'];

   if (substr($request,-1)=="/") $request=substr($request,0,strlen($request)-1);
   //echo properPath($album_root_path.$request)."<hr>";
   if (is_dir(properPath(utf8_decode($album_root_path.$request)))) {
      $type="Directory: ";
      $directory_path=properPath(utf8_decode($album_root_path.$request));
      $property_filename=getPropertyFilename($directory_path);
      $thmb_path=substr($directory_path,0,strrpos($directory_path,"/"));
      $thmb_base=substr($directory_path,strrpos($directory_path,"/")+1);
      deleteThumbnailDirectory($request);
      $forward_link=$request;
   } else {
      $type="Image file: ";
      $property_filename=getPropertyFilename($album_root_path.$request);
      $forward_link=substr($request,0,strrpos($request,"/"));
   }
   
   if (file_exists($property_filename)) {
      unlink($property_filename);
   }
   
   if ($new_content) {
      if (function_exists("file_put_contents")){
         file_put_contents($property_filename,$new_content);
      } else {
         $fileHandler = fopen ($property_filename, "w");
         fwrite ($fileHandler, $new_content);
         fclose ($fileHandler);
      }
   }
   //echo $type."\n<br>".$property_filename."\n<br>".$forward_link."\n<br>"."<a href=\"".$_SERVER["SCRIPT_NAME"]."?r=i".urlencode($forward_link)."\">xx</a>";
   echo "<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=".$_SERVER["SCRIPT_NAME"]."?r=i".$forward_link."\">";
   return;
}

function htmlSlide(){

   global $request;
   global $album_root_path;
   global $quality;
   global $slideshow_interval;
   global $frame_width_slide;
   global $frame_gap_slide;
   global $frame_gap;
   global $html_color_img_frame;
   global $request_raw;
   global $message;
   global $resources;
   
   if ($message!="") {
      $default_message_style="inline";
   } else {
      $default_message_style="none";
   }
   $dir=substr($request,0,strrpos($request,"/"));
   $dir_url=str_replace("//","/",$dir);
   $img_name=substr($request,strrpos($request,"/")+1);
   $images=getArrayWithImages($album_root_path.$dir);
   for ($img_counter=0;$img_counter<count($images);$img_counter++) {
      if ($images[$img_counter][0]==$img_name) {
         $current_image_nr=$img_counter;
         break;
      }
   }
?>
<script type="text/javascript">
   var current_nr=<?=$current_image_nr?>;
   var next_nr=<?=$current_image_nr+1?>;
   var total_nr=<?=count($images)?>;
   var ss=new Array();
   var si=new Array();
   var se=new Array();
   var so=new Array();
   var sw=new Array();
   var sh=new Array();
   var sc=new Array();
   var path_a="<?=$_SERVER["SCRIPT_NAME"]?>?r=";
   var path_b="<?=urlencode($dir_url)?>";
   var t=0;
   var timer_interval=<?= ($slideshow_interval*1000) ?>;
   var cur_res="<?=$quality?>";
   var quality_parameter="&q="+cur_res;
   var message="";
   var comments="";
<?   for ($img_counter=0;$img_counter<count($images);$img_counter++) {
      echo "   ss[$img_counter]=\"".urlencode(utf8_encode($images[$img_counter][0]))."\";";
      echo "   se[$img_counter]=\"".$images[$img_counter][1]."\";";
      echo "   sw[$img_counter]=\"".$images[$img_counter][2]."\";";
      echo "   sh[$img_counter]=\"".$images[$img_counter][3]."\";";
      $comments="";
      if (is_array($images[$img_counter][4])) {
         $comments=implode("<br>",$images[$img_counter][4]);
         $comments=str_replace("\"","&quot;",$comments);
      }
      echo "   sc[$img_counter]=\"".$comments."\";\n";
   }
?>   function jsGetImage() {
      if (si[current_nr]) {
         jsShowImage(message);
      } else {
         si[current_nr]=new Image();
         si[current_nr].src=path_a+"p"+path_b+"/"+ss[current_nr]+quality_parameter;
         si[current_nr].onLoad = jsShowImage(message);
         message=message+"Load("+current_nr+"), ";
      }
   }

   function jsDisplayButtons(status){
      document.b_previous.style.display=status;
      document.b_next.style.display=status;
      document.b_index.style.display=status;
      document.b_slideshow.style.display=status;
      document.b_exif.style.display=status;
      document.b_comments.style.display=status;
      document.b_res_high.style.display=status;
      document.b_res_low.style.display=status;
      document.b_res_full.style.display=status;
   }

   function jsMyClearTimeout(){
      message=message+("clearing timer: "+t+", ");
      clearTimeout(t);
      t=0;
      jsDisplayButtons("inline");
   }
   
   function jsSlideShowStart(){
      current_nr=current_nr-1;
      jsSlideShow();
   }
   
   function jsSlideShow(){
      if (t) jsMyClearTimeout();
      jsDisplayButtons("none");
      jsNextImage();
      t=setTimeout("jsSlideShow()",timer_interval);
   }
   
   function jsPreviousImage(){
      if (t) jsMyClearTimeout()
      else {
         current_nr-=1;
         if (current_nr<0) current_nr=<?=count($images)-1?>;
         next_nr=current_nr-1;
         if (next_nr<0) next_nr=<?=count($images)-1?>;
      }
      jsGetImage();
   }
   
   function jsNextImage(){
      if (t) jsMyClearTimeout()
      else {
         current_nr+=1;
         if (current_nr><?=count($images)-1?>) current_nr=0;
         next_nr=current_nr+1;
         if (next_nr><?=count($images)-1?>) next_nr=0;
      }
      jsGetImage();
   }

   function jsShowImage(message) {
   
      document.slide.src=si[current_nr].src;

      var aspect=sw[current_nr]/sh[current_nr];
      if (aspect<document.body.clientWidth/document.body.clientHeight) {
         var slH = document.body.clientHeight-<?=($frame_width_slide*2+$frame_gap_slide)?>;
         var slW = slH*aspect;
      } else {
         var slW = document.body.clientWidth-<?=($frame_width_slide*2+$frame_gap_slide)?>;
         var slH = slW/aspect;
      }

      var slT = (document.body.clientHeight-slH-<?=($frame_width_slide*2+$frame_gap_slide)?>)/2;
      var slL = (document.body.clientWidth-slW-<?=($frame_width_slide*2+$frame_gap_slide)?>)/2;

      document.slide.style.height = slH;
      document.slide.style.width  = slW;
      document.slide.style.top    = slT;
      document.slide.style.left   = slL;
      
      jsShowResButtons();
      document.all['a_res_full'].href=path_a+"p"+path_b+"/"+ss[current_nr]+"&q=HIGH";

      if (t>0) {
         clearTimeout(t);
         t=setTimeout("jsSlideShow()",timer_interval);
      }

      if (!si[next_nr]) {
         si[next_nr]=new Image();
         si[next_nr].src=path_a+"p"+path_b+"/"+ss[next_nr]+quality_parameter;
         message=message+"Pre-Load("+next_nr+"), ";
      }
         
      message=message+"Img ("+current_nr+"), ";
      message=message+"W*H:"+sw[current_nr]+"*"+sh[current_nr]+", ";
      message=message+"screen W*H:"+document.body.clientWidth+"*"+document.body.clientHeight+" t:"+t;
      document.getElementById('msg').value=message;
      message="";

      comments=sc[current_nr];
      comments=jsReplace(comments,"<br>","\n");
      comments=jsReplace(comments,"&quot;","\"");
      document.getElementById('comments').value=comments;
      if (comments!="") {
      	document.b_comments.src="<?=$resources?>/comment.gif";
      } else {
          document.b_comments.src="<?=$resources?>/comment_no.gif";
      }

      jsFreeMemory(4);

      var exif = se[current_nr];
      exif=jsReplace(exif,"<br>","\n");
      document.getElementById('exif').value=exif;
      if (exif!="") {
      	document.b_exif.src="<?=$resources?>/exif.gif";
      } else {
          document.b_exif.src="<?=$resources?>/exif_no.gif";
      }

      document.getElementById('r').value="s"+"<?=$dir?>/"+ss[current_nr];

   }
   
   function jsFreeMemory(){
      for (var i = 0; i < si.length; i++) {
         if (i<current_nr-3 || i>current_nr+3) {
            if (si[i]) {
               si[i] = null;
   }   }   }   }
   
   function jsShowEXIF(){
      if (document.getElementById('exif').style.display=="none") {
         document.getElementById('exif').style.display="inline";
      } else {
         document.getElementById('exif').style.display="none";
      }
   }
   
   function jsReplace(string,what,by) {
      var strLength = string.length, txtLength = what.length;
      if ((strLength == 0) || (txtLength == 0)) return string;
      
      var i = string.indexOf(what);
      if ((!i) && (what != string.substring(0,txtLength))) return string;
      if (i == -1) return string;
      
      var newstr = string.substring(0,i) + by;
      
      if (i+txtLength < strLength)
        newstr += jsReplace(string.substring(i+txtLength,strLength),what,by);
      
      return newstr;
   }
   
   function jsSwitchRes(){
      if (cur_res=="HIGH") cur_res="LOW"
      else cur_res="HIGH";
      for (var i = 0; i < si.length; i++) {
         si[i] = null;
      }
      quality_parameter="&q="+cur_res;
      jsGetImage();
   }

   function jsShowResButtons(){
      if (cur_res=="HIGH"){
         document.b_res_high.src="<?=$resources?>/res_high_off.gif";
         document.b_res_low.src="<?=$resources?>/res_low.gif";
      } else {
         document.b_res_high.src="<?=$resources?>/res_high.gif";
         document.b_res_low.src="<?=$resources?>/res_low_off.gif";
      }
   }
   
   function jsShowComments(){
      if (document.getElementById('divComment').style.display=="none") {
         document.getElementById('divComment').style.display="inline";
      } else {
         document.getElementById('divComment').style.display="none";
      }
   }
   
</script>
<div style="z-index: 1; position: absolute; width: 100%; height:100%;">
   <table style="height:100%;width:100%;">
      <tr>
         <td width=1%><a style="cursor: pointer;" onclick="jsPreviousImage()"><img name="b_previous"  src="<?=$resources?>/back.gif"      title="Previous image" alt="Previous image"></a>&nbsp;</td>
         <td width=1%><a style="cursor: pointer;" href="<?=$_SERVER["SCRIPT_NAME"]."?r=i".urlencode($dir)?>"><img name="b_index" src="<?=$resources?>/index.gif" title="Index" alt="Index"></a>&nbsp;</td>
         <td width=1%><a style="cursor: pointer;" onclick="jsNextImage()"><img name="b_next"      src="<?=$resources?>/forward.gif"   title="Next image"     alt="Next image"></a>&nbsp;</td>
         <td width=1%><a style="cursor: pointer;" onclick="jsSlideShowStart()"><img name="b_slideshow" src="<?=$resources?>/slideshow.gif" title="Slideshow"      alt="Slideshow"></a>&nbsp;</td>
         <td width=1%><a style="cursor: pointer;" onclick="jsShowComments()"><img name='b_comments' src='<?=$resources?>/comment.gif' title='Show comments' alt='Comments'></a>&nbsp;</td>
         <td width=1%><a style="cursor: pointer;" onclick="jsShowEXIF()"><img name='b_exif' src='<?=$resources?>/exif.gif' title='EXIF info' alt='EXIF'></a>&nbsp;</td>
         <td>&nbsp;</td>
         <td width=47% onclick="jsNextImage()"><input type=hidden id=msg style="width: 100%;">&nbsp;</td>
         <td width=1%><a style="cursor: pointer;" onclick="jsSwitchRes()"><img name='b_res_high' src='<?=$resources?>/res_high.gif' title='High resolution (Quality)' alt='Quality'></a>&nbsp;</td>
         <td width=1%><a style="cursor: pointer;" onclick="jsSwitchRes()" ><img name='b_res_low' src='<?=$resources?>/res_low.gif' title='Low resolution (Speed)' alt='Speed'></a>&nbsp;</td>
         <td width=1%><a style="cursor: pointer;" target="_blank" name='a_res_full'><img name='b_res_full' src='<?=$resources?>/res_full.gif' title='Full size image (100%)' alt='100%'></a>&nbsp;</td>
      </tr>
      <tr style="height:80%;">
         <td onclick="jsPreviousImage()" width="50%" colspan="7">&nbsp;</td>
         <td onclick="jsNextImage()" width="50%" colspan="4">&nbsp;</td>
      </tr>
      <tr style="height:240;">
         <td style="width:50%;" colspan="7">
         	<div id=divComment style="display:<?=$default_message_style?>; align: left;">
              <textarea id="comments" READONLY rows=7 cols=80 style="width: 80%; background: transparent; border: none; font-family:Tahoma; font-size:14pt; font-weight:bold; background-color:lightgray; filter:alpha(opacity=60); opacity: 0.6; moz-opacity:0.6;">
              </textarea><br>
              New comment:<br>
              <form method="get" action="<?=$_SERVER['SCRIPT_NAME']?>">
                <input type=text   size=80 style="width: 80%; font-family:Courier New; font-size:10pt; filter:alpha(opacity=60); opacity: 0.6; moz-opacity:0.6;" id=m name=m>
                <input type=hidden size=80 style="width: 80%; font-family:Courier New; font-size:10pt;" id=r name=r>
                <br>
                <input type=submit value="Submit">
              </form>
         </div>
         </td>
         <td onclick="jsShowEXIF()" width="50%" align="right" colspan="4">
            <textarea id="exif" READONLY rows=7 cols=46 style="display:none; background: white; vertical-align: bottom; border:none; overflow:hidden; text-align:left; font-family:Courier New; color:blue; font-weight:bold; font-size:10pt; filter:alpha(opacity=60); opacity: 0.6; moz-opacity:0.6;">
            </textarea>&nbsp;
         </td>
      </tr>
   </table>
</div>
<div style="z-index: 0; height:100%; width:100%; text-align: center; vertical-align: middle; ">
   <font style="font-size:20pt;">
      <img src="<?=$resources?>/blue.gif" name="slide" style="position:absolute; margin: 10; vertical-align: middle; border: solid <?=$html_color_img_frame?> <?=$frame_width_slide."px"?>" alt="Your image is being loaded!">
   </font>
</div>

<?
}

function load_dictionary_sk(){

  global $dictionary;

  $dictionary['SK']["Password"]                 = "Heslo";
  $dictionary['SK']["Search"]                   = "Hladaj";
  $dictionary['SK']["Thumbnail size"]           = "Velkost obrazkov";
  $dictionary['SK']["Color themes"]             = "Farebne variacie";
  $dictionary['SK']["Access denied"]            = "Pristup zamietnuty";
  $dictionary['SK']["Subject"]                  = "Predmet";
  $dictionary['SK']["To"]                       = "Adresati";
  $dictionary['SK']["Body"]                     = "Telo";
  $dictionary['SK']["File does not exist"]      = "Subor neexistuje";
  $dictionary['SK']["Submit"]                   = "Odosli";
  $dictionary['SK']["Upload"]                   = "Posli subor";
  $dictionary['SK']["New pictures"]             = "Nove obrazky";
  
}

function t($original){

  return $original;
  
  global $dictionary;  
  $translation=$dictionary['SK'][$original];
  if ($translation=="") $translation=$original;
  return $translation; 
}

function mkpath($path)
   {
     $dirs=array();
     $path=preg_replace('/(\/){2,}|(\\\){1,}/','/',$path); //only forward-slash
     $dirs=explode("/",$path);
     $path="";
     foreach ($dirs as $element)
         {
           $path.=$element."/";
           if(!is_dir($path))
             {
             if(!mkdir($path)){ echo "something was wrong at : ".$path; return 0; }
             }         
         }
     return true;
   }
?>
Return current item: phpShowtime