<?php

/* $Id: portal_functions.php 56 2009-02-23 20:59:59Z kremer $ */

include_once "portal_settings.php";


/** LVZ 2011_10_11
 * Storing LOGIN messages
 * @param $dbgmsg debug message
 */
 /*
function catch_user_abort () {
   if (connection_aborted ())
      error_log ("Script $GLOBALS[SCRIPT_NAME] on server " .
         "$GLOBALS[SERVER_NAME] was aborted by the user.");
}


register_shutdown_function ('catch_user_abort');
*/


/** LVZ 2011_10_11

 * Storing LOGIN messages
 * @param $dbgmsg debug message
 */
function portal_login ( $dbgmsg ) {
  $dt = datetime();
  


  $bt = debug_backtrace();
  // get file, line where call to caller of caller was made
  $file = $bt[0]['file'];
  $line = $bt[0]['line'];
       
 // $dbgmsg = $dbgmsg ." in ". $file ." at ". $line;


  $date = substr ( $dt, 0, 0 - strlen ( strrchr ( $dt, "_" ) ) );
  //$dbgmsg = $dt." (".$_SERVER['REMOTE_USER']."): ".$dbgmsg;
   
  
//LVZ 2013-06-18 : added remote ip address of client
   $dbgmsg = $dt." (".$_SERVER['REMOTE_USER']."): ".$_SERVER['REMOTE_ADDR'];
   
  $login = $_SERVER['REMOTE_USER'];

  shell_exec ( "echo '$dbgmsg' >> /var/www/html/xadesweb/protected/log/login_php_".$date.".log" );
  
//LVZ 2014-07-11 : added first occurence to be looged in portal_inkind.log
$filename = "/var/www/html/xadesweb/protected/log/login_php_".$date.".log";
$searchfor = " (".$_SERVER['REMOTE_USER'].")";

$file = file_get_contents($filename);


$list_expert = array('velez','caccia','rizzo', 'lanz', 'cruellas');
	
	if( ! in_array($login,$list_expert)){     
		$occurence_string = 0;
		$occurence_string = substr_count($file, $searchfor);
			if ($occurence_string == 1 ) {
			
					
			//$company = get_company_name ( $login, $db_server, $db_username, $db_password, $db_dbname, $debug );
			//dbgmsg = $company.'___'.$dbgmsg;
			shell_exec ( "echo '$dbgmsg' >> /var/www/html/xadesweb/protected/log/inkind/inkind_php_".$date.".log" );
			}
	}
	
	
	
}


/**
 * Storing debug messages
 * @param $dbgmsg debug message
 */
function portal_debug ( $dbgmsg ) {
  $dt = datetime();

  $date = substr ( $dt, 0, 0 - strlen ( strrchr ( $dt, "_" ) ) );
  $dbgmsg = $dt." (".$_SERVER['REMOTE_USER'].": ".$_SERVER['REMOTE_ADDR']."): ".$dbgmsg;

//  shell_exec ( "echo '$dbgmsg' >> $debug_file" );
  shell_exec ( "echo '$dbgmsg' >> /var/www/html/xadesweb/protected/log/debug_php_".$date.".log" );
}


/**
 * Error handling/notification funtion
 * @param $errmsg error message to be sent out
 */
function portal_error ( $errmsg ) {
  portal_debug ( "ERROR: $errmsg" );

  $recipient = "xades3_admin@list.etsi.org";
  $subject = "ASiC Portal Problem";
  $headers = "From: ASiC Plugtest Portal <xades3_admin@list.etsi.org>";

  $body = "User: ".$_SERVER['REMOTE_USER']."\n";
  $body = $body."Error message: ".$errmsg;

  mail ( $recipient, $subject, $body , $headers );

  exit ( $errmsg );
}


/**
 * Connects to the database
 * @param $p_db_server MySQL server name
 * @param $p_db_username username to log in to the DB server
 * @param $p_db_password password for the DB server
 * @param $p_db_dbname DB name on the server
 * @param $debug controls the printing of debug messages
 * @return int mysql_errno()
 */
function connectDB ( $p_db_server, $p_db_username, $p_db_password, $p_db_dbname, $debug ) {
  $connectionId = mysql_connect ( $p_db_server, $p_db_username, $p_db_password );
  if ( $debug ) {
    portal_debug ( "INFO: connectDB(): mysql_connect()" );
    portal_debug ( "INFO: connectDB(): connectionId = $connectionId" );
    portal_debug ( "INFO: connectDB(): mysql_errno = ".mysql_errno()."" );
    portal_debug ( "INFO: connectDB(): mysql_error = ".mysql_error()."" );
  }

  if ( mysql_errno() ) {
    exit ( "connectDB(): ".mysql_error() );
  }

  mysql_select_db ( $p_db_dbname, $connectionId );
  if ( $debug ) {
    portal_debug ( "INFO: connectDB(): mysql_select_db()" );
    portal_debug ( "INFO: connectDB(): mysql_errno = ".mysql_errno()."" );
    portal_debug ( "INFO: connectDB(): mysql_error = ".mysql_error()."" );
  }

  if ( mysql_errno() ) {
    exit ( "connectDB(): ".mysql_error() );
  } else {
    return $connectionId;
  }
}


/**
 * Gets the company name for a given user
 * @return string containing the company name
 */
function get_company_name ( $user, $db_server, $db_username, $db_password, $db_dbname, $debug ) {
  if ( $debug ) {
    portal_debug ( "INFO: get_company_name(): user = $user" );
  }

  // Connect to DB
  $dblink = connectDB ( $db_server, $db_username, $db_password, $db_dbname, $debug );

  $fields = mysql_fetch_row ( mysql_query ( "SELECT company FROM tb_login WHERE username = '$user'" ) );
  $company_name = $fields[0];
  $company = strtoupper ( $company_name );

  mysql_close ( $dblink );

  if ( $debug ) {
    portal_debug ( "INFO: get_company_name(): company name = $company" );
  }

  return $company;
}


/**
 * Gets the actual date and time
 * @return string containing the actual date and time in yyyymmdd_hhmm format.
 */
function datetime() {
  $today = getdate();
  $year = $today['year'];
  $month = $today['mon'];
  $day = $today['mday'];
  $hours = $today['hours'];
  $min = $today['minutes'];
  $sec = $today['seconds'];

  if (strlen($sec) == 1) $sec = "0".$sec;
  if (strlen($min) == 1) $min = "0".$min;
  if (strlen($hours) == 1) $hours= "0".$hours;
  if (strlen($day) == 1) $day = "0".$day;
  if (strlen($month) == 1) $month = "0".$month;

  $t = $year.$month.$day."_".$hours.$min.$sec ;

  return $t;
}


/**
 * Select the directories that starts with $dirname
 * @param $path path to the extracted zipfile
 * @param $dirname collect dirs that start with this string
 * @param $debug controls the printing of debug messages
 * @return boolean|string[] including the directories starting with $dirname
 */
function select_dir ( $path, $dirname, $debug ) {
  if ( $debug ) {
    portal_debug ( "INFO: check_dir(): path = $path" );
    portal_debug ( "INFO: check_dir(): dirname = $dirname" );
  }

  if ( ! ( $dir = opendir ( $path ) ) )
  {
    portal_debug ( "ERROR: select_dir(): Unable to open $path" );
    exit ( "select_dir(): Unable to open $path" );
  }

  $dirarray = array();
  while ( ( $file = readdir ( $dir ) ) !== false ) {
    if ( ( $file != "." ) && ( $file != ".." ) ) {
      if ( is_dir ( $path.'/'.$file ) ) {
        //Test of directory begin with $dirname
        if ( ereg ( "^$dirname", $file ) ) {
          $dirarray[]= $file;
        }
      }
    }
  }

  closedir ( $dir );

  return $dirarray;
}


/**
 * Check if the dir in @param2 exists in @param1
 * @param $tcdir path to the testcases directory
 * @param $newdir directory name in the uploaded file
 * @param $path_filter filter string used to trim the beginning of the path
 * @param $company_name name of the user's company
 * @param $debug controls the printing of debug messages
 * @return boolean true if the dir in the uploaded file is a valid testcase dir
 */
function check_dir ( $tcdir, $newdir, $path_filter, $company_name, $debug ) {
  $newdir_dir = substr ( $newdir, strrpos ( $newdir, $path_filter ) );

  if ( $debug ) {
    portal_debug ( "INFO: check_dir(): tcdir = $tcdir" );
    portal_debug ( "INFO: check_dir(): newdir = $newdir" );
    portal_debug ( "INFO: check_dir(): newdir_dir = $newdir_dir" );
  }

  if ( ! ( $dir = opendir ( $tcdir ) ) )
  {
    portal_debug ( "ERROR: check_dir(): Unable to open $tcdir" );
    exit ( "check_dir(): Unable to open $tcdir" );
  }

  $dirfound = false;
  while ( ( $file = readdir ( $dir ) ) !== false ) {
    if ( ( $file != "." ) && ( $file != ".." ) ) {
      // Check if $file is a dir
      if ( is_dir ( $tcdir.'/'.$file ) ) {
        // Check if the current dir is a valid testcase dir
		
		
		
		
        if ( $file == $newdir_dir ) {
          if ( $debug ) {
            portal_debug ( "INFO: check_dir(): $newdir_dir is a valid testcase directory ($tcdir/$file)" );
          }
          // Check if company folders exist at both locations
          if ( is_dir ( $tcdir."/".$file."/".$company_name ) ) {
            if ( $debug ) {
              portal_debug ( "INFO: check_dir(): Company dir exists in testcase folder: $tcdir/$file/$company_name" );
            }
            if ( is_dir ( $newdir."/".$company_name ) ) {
              if ( $debug ) {
                portal_debug ( "INFO: check_dir(): Company dir exists in uploaded zip file: $newdir/$company_name" );
              }
              $dirfound = true;
            }
          }
        }
      }
    }
  }

  closedir ( $dir );

  return $dirfound;
}


/**
 * Compare the content of two directories. Copy the files if they are new.
 * If a file already exists in $dstdir, compare them and only copy the file
 * if they differ. In thata case the verification reports are deleted.
 * @param $srcdir source directory (uploaded file content)
 * @param $dstdir destination directory (testcases directory)
 * @param $newfile_list list of new files in the uploaded zip
 * @param $oldfile_list list of old verification report files
 * @param $path_filter filter string used to trim the beginning of the path
 * @param $debug controls the printing of debug messages
 * @return boolean true if the copy was successful
 */
function compare_and_copy_files ( $srcdir, $dstdir, &$newfile_list, &$oldfile_list, $path_filter, $debug ) {
  if ( $debug ) {
    portal_debug ( "INFO: compare_and_copy_files(): srcdir = $srcdir" );
    portal_debug ( "INFO: compare_and_copy_files(): dstdir = $dstdir" );
  }

  if ( ! ( $dir = opendir ( $srcdir ) ) )
  {
    portal_debug ( "ERROR: compare_and_copy_files(): Unable to open $srcdir" );
    exit ( "compare_and_copy_files(): Unable to open $srcdir" );
  }

  while ( ( $file = readdir ( $dir ) ) !== false ) {
    if ( ( $file != "." ) && ( $file != ".." ) ) {
      // Check if $file is a regular file
      if ( is_file ( $srcdir.'/'.$file ) ) {
        if ( $debug ) {
          portal_debug ( "INFO: compare_and_copy_files(): $srcdir/$file is a regular file" );
        }

        // Check if the file exists in $dstdir
        if ( ! stat ( $dstdir."/".$file ) ) { // it doesn't exist, ready to copy
          if ( $debug ) {
            portal_debug ( "INFO: compare_and_copy_files(): $dstdir/$file does not exist, copy the new file" );
          }

          $newfile_list = $newfile_list.substr ( $srcdir, strrpos ( $srcdir, $path_filter ) )."/$file\n";

          if ( ! copy ( $srcdir."/".$file, $dstdir."/".$file ) ) {
            portal_debug ( "ERROR: compare_and_copy_files(): Unable to copy $srcdir/$file to $dstdir/$file" );
            closedir ( $dir );
            return false;
          }
        } else { // the file exists in both dirs, need to compare
          if ( $debug ) {
            portal_debug ( "INFO: compare_and_copy_files(): $dstdir/$file already exists, need to compare the files" );
          }

          $cmd = "diff --brief \"$srcdir/$file\" \"$dstdir/$file\"";
          exec ( $cmd, $output, $retval );

          if ( $debug ) {
            portal_debug ( "INFO: compare_and_copy_files(): shell command to compare the files: $cmd" );
          }

          if ( $retval != 0 ) { // the files are different
            if ( $debug ) {
              portal_debug ( "INFO: compare_and_copy_files(): $srcdir/$file and $dstdir/$file are different, the old file is overwritten" );
            }

            $newfile_list = $newfile_list.substr ( $srcdir, strrpos ( $srcdir, $path_filter ) )."/$file\n";

            if ( ! copy ( $srcdir."/".$file, $dstdir."/".$file ) ) {
              portal_debug ( "ERROR: compare_and_copy_files(): Unable to copy $srcdir/$file to $dstdir/$file" );
              closedir ( $dir );
              return false;
            }

            // Delete verification reports
            if ( ! delete_verification_reports ( $dstdir, $file, $oldfile_list, $path_filter, $debug ) ) {
              portal_debug ( "ERROR: compare_and_copy_files(): Unable to delete all verification reports for $file" );
              closedir ( $dir );
              return false;
            }
          } else { // the files are the same, no need to copy
            if ( $debug ) {
              portal_debug ( "INFO: compare_and_copy_files(): $srcdir/$file and $dstdir/$file are the same, no need to copy" );
            }
          }
        }
      }
    }
  }

  closedir ( $dir );
  return true;
}


/**
 * Delete verification reports for $file in the parent of $dir
 * @param $dstdir dir where the company folders can be found
 * @param $sigfile original signature file
 * @param $oldfile_list list of old verification report files
 * @param $path_filter filter string used to trim the beginning of the path
 * @param $debug controls the printing of debug messages
 * @return boolean true if the delete was successful
 */
function delete_verification_reports ( $dstdir, $sigfile, &$oldfile_list, $path_filter, $debug ) {
  $scandir = substr ( $dstdir, 0, 0 - strlen ( strrchr ( $dstdir, "/" ) ) );
  $company = substr ( $dstdir, strlen ( $scandir ) + 1 );
  $sigfile_ext = pathinfo ( $sigfile, PATHINFO_EXTENSION );
  $sigfile_noext = basename ( $sigfile, ".".$sigfile_ext );
  $report_file = "Verification_of_$company"."_$sigfile_noext.xml";

  if ( $debug ) {
    portal_debug ( "INFO: delete_verification_reports(): dstdir = $dstdir" );
    portal_debug ( "INFO: delete_verification_reports(): sigfile = $sigfile" );
    portal_debug ( "INFO: delete_verification_reports(): sigfile_ext = $sigfile_ext" );
    portal_debug ( "INFO: delete_verification_reports(): sigfile_noext = $sigfile_noext" );
    portal_debug ( "INFO: delete_verification_reports(): scandir = $scandir" );
    portal_debug ( "INFO: delete_verification_reports(): company = $company" );
    portal_debug ( "INFO: delete_verification_reports(): report_file = $report_file" );
  }

  if ( ! ( $dir = opendir ( $scandir ) ) )
  {
    portal_debug ( "ERROR: delete_verification_reports(): Unable to open $scandir" );
    exit ( "delete_verification_reports(): Unable to open $scandir" );
  }

  while ( ( $file = readdir ( $dir ) ) !== false ) {
    if ( ( $file != "." ) && ( $file != ".." ) && ( $file != $company ) ) {
      if ( is_dir ( $scandir."/".$file ) )
      {
        if ( stat ( $scandir."/".$file."/".$report_file ) ) {
          if ( $debug ) {
            portal_debug ( "INFO: delete_verification_reports(): Deleting $scandir/$file/$report_file" );
          }

          $oldfile_list = $oldfile_list.substr ( $scandir."/".$file, strrpos ( $scandir."/".$file, $path_filter ) )."/$report_file\n";

          if ( ! unlink ( $scandir."/".$file."/".$report_file ) ) {
            portal_debug ( "ERROR: delete_verification_reports(): Unable to delete verification report $report_file in $scandir/$file" );
            closedir ( $dir );
            return false;
          }
        } else if ( $debug ) {
          portal_debug ( "INFO: delete_verification_reports(): $scandir/$file/$report_file doesn't exist, no need to delete" );
        }
      }
    }
  }

  closedir ( $dir );
  return true;
}


/**
 * Delete a directory
 * @param $dir dir to be deleted
 * @param $dir_too whether to delete the directory itself (true) or just the content (false)
 * @param $debug controls the printing of debug messages
 * @return boolean true if the delete was successful
 */
function delete_dir_content ( $dir, $dir_too, $debug ) {
  if ( $debug ) {
    portal_debug ( "INFO: delete_dir_content(): dir = $dir" );
    portal_debug ( "INFO: delete_dir_content(): dir_too = $dir_too" );
  }

  if ( ! chdir ( $dir ) ) {
    portal_debug ( "ERROR: delete_dir_content(): Unable to change to $dir" );
    return false;
  }

  $cmd = "rm -rf *";
  exec ( $cmd, $output, $retval );

  if ( $retval != 0 ) {
    portal_debug ( "ERROR: delete_dir_content(): Unable to delete the content of $dir" );
    return false;
  }

  if ( $dir_too ) {
    if ( ! rmdir ( $dir ) ) {
      portal_debug ( "ERROR: delete_dir_content(): Unable to delete $dir" );
      return false;
    }
  }

  return true;
}





function clean_dir_content ( $dir, $dir_too, $debug ) {
  if ( $debug ) {
    portal_debug ( "INFO: clean_dir_content(): dir = $dir" );
    portal_debug ( "INFO: clean_dir_content(): dir_too = $dir_too" );
  }

  if ( ! chdir ( $dir ) ) {
    portal_debug ( "ERROR: delete_dir_content(): Unable to change to $dir" );
    return false;
  }

$cmd = "rm -rf *";
exec ( $cmd, $output, $retval );

  if ( $retval != 0 ) {
    portal_debug ( "ERROR: delete_dir_content(): Unable to delete the content of $dir" );
    return false;
  }

  if ( $dir_too ) {
    if ( ! rmdir ( $dir ) ) {
      portal_debug ( "ERROR: delete_dir_content(): Unable to delete $dir" );
      return false;
    }
  }


  return true;
}






/**
 * Creates a zip file
 * @param $filename name of the zip file
 * @param $srcdir dir whose content will be compressed
 * @param $dstdir dir where to put the zip file
 * @param $include filemask to include files
 * @param $exclude filemask to exculde files
 * @param $debug controls the printing of debug messages
 * @return boolean true if the delete was successful
 */
function create_zipfile ( $filename, $srcdir, $dstdir, $include, $exclude, $debug ) {
  if ( $debug ) {
    portal_debug ( "INFO: create_zipfile(): filename = $filename" );
    portal_debug ( "INFO: create_zipfile(): srcdir = $srcdir" );
    portal_debug ( "INFO: create_zipfile(): dstdir = $dstdir" );
    portal_debug ( "INFO: create_zipfile(): include = $include" );
    portal_debug ( "INFO: create_zipfile(): exclude = $exclude" );
  }

  if ( ! chdir ( $srcdir ) ) {
    portal_debug ( "ERROR: create_zipfile(): Unable to change to source dir: $srcdir" );
    return false;
  }

  $cmd = "/usr/bin/zip -r $dstdir/$filename $include -x $exclude";
  if ( $debug ) {
    portal_debug ( "INFO: create_zipfile(): Creating new zip file $dstdir/$filename" );
    portal_debug ( "INFO: create_zipfile(): zip command: $cmd" );
  }
  exec ( $cmd, $output, $retval );
  if ( $retval != 0 ) {
    portal_debug ( "ERROR: create_zipfile(): Couldn't create new download file '$dstdir/$filename'" );
    return false;
  }

  return true;
}


/**
 * Put the name, modification time and size of a file into an array
 * @param $entry parent dir name
 * @param $base original file/dir name
 * @return array including name, modification time and size of a file/dir into an array
 */
function addScheme ( $entry, $base ) {
  $tab['name'] = $entry;
  $tab['date'] = filemtime ( $base );
  $tab['size'] = filesize ( $base );

  return $tab;
}


/**
 * Sort data in array by name
 * @param $a array1
 * @param $b array2
 * @return unknown_type
 */
function cmp_name ( $a, $b ) {
  global $asc;
  if ( $a['name'] == $b['name'] ) return 0;
  if ( $asc == 'a' ) {
    return ( $a['name'] < $b['name'] ) ? -1 : 1;
  } else {
    return ( $a['name'] > $b['name'] ) ? -1 : 1;
  }
}


/**
 * Sort data in array by last modification time.
 * @param $a array1
 * @param $b array2
 * @return unknown_type
 */
function cmp_date ( $a, $b ) {
  global $asc;
  if ( $a['date'] == $b['date'] ) return cmp_name ( $a, $b );
  if ( $asc == 'a' ) {
    return ( $a['date'] < $b['date'] ) ? -1 : 1;
  } else {
    return ( $a['date'] > $b['date'] ) ? -1 : 1;
  }
}


/**
 * Format the filesize
 * @param $s filesize
 * @return string formatted string
 */
function formatSize ( $s ) {
  $u = array ( 'bytes', 'KB', 'MB', 'GB', 'TB' );
  $i = 0;
  $m = 0;

  while( $s >= 1 ) {
    $m = $s;
    $s /= 1024;
    $i++;
  }
  if ( ! $i ) $i = 1;
  $d = explode ( ".", $m );

  if ( $d[0] != $m ) {
    $m = number_format ( $m, 2, ",", " " );
  }

  return $m." ".$u[$i-1];
}


/**
 * List and display folders only
 * @param $base_dir path to the current directory
 * @param $root_dir path to the root directory
 * @param $testcases_dir path to the testcases directory (relative to base_dir)
 * @param $rel_dir path from the base directory
 * @param $indent_level indentation level for subdirectories
 * @param $debug controls the printing of debug messages
 * @return unknown_type
 */
function list_subdirs ( $base_dir, $root_dir, $testcases_dir, $rel_dir, $indent_level, $debug )
{
  if ( $dir = opendir ( $base_dir ) )
  {
    // Select dirs in target directory
    $dirlist = array();
    while ( ( $file = readdir ( $dir ) ) !== false ) {
      if ( ( is_dir ( $base_dir."/".$file ) ) && ( $file != "." ) && ( $file != ".." ) && ( $file != ".svn" ) ) {
        $dirlist[] = $file;
      }
    }

    sort ( $dirlist );

    foreach ( $dirlist as $el )
    {
      /* chemin relatif à la racine */
      $file = $base_dir."/".$el;
      /* marge gauche */
      for ( $i = 1; $i <= ( 4 * $indent_level ); $i++ ) {
        echo "&nbsp;";
      }
      //      echo "Compare '$file' and '$root_dir$testcases_dir/$rel_dir'\n";
      /* l'entrée est-elle le dossier courant */
      if ( $file == $root_dir.$testcases_dir."/".$rel_dir ) {
        echo "<img src='/common/images/dir-open.gif' />&nbsp;$el<br>\n";
      } else {
        echo "<img src='/common/images/dir-close.gif' />&nbsp;<a href='".substr ( $file, strrpos ( $file, $testcases_dir ) )."'>$el</a><br>";
      }
      /* l'entrée est-elle dans la branche dont le dossier courant est la feuille */
      if ( strstr ( $root_dir.$testcases_dir."/".$rel_dir, $file ) ) {
        //        echo "list_subdir elott\n";
        list_subdirs ( $file, $root_dir, $testcases_dir, $rel_dir, $indent_level + 1, $debug );
      }
    }
    closedir ( $dir );
  } else {
    portal_debug ( "ERROR: list_subdirs(): Unable to open dir $base_dir/$rel_dir" );
    exit ( "list_subdirs(): Unable to open dir $base_dir/$rel_dir<br>" );
  }
}


/**
 * List and display files only
 * @param $base_dir path to the current directory
 * @param $testcases_dir path to the testcases directory (relative to base_dir)
 * @param $rel_dir path from the base directory
 * @param $debug controls the printing of debug messages
 * @return unknown_type
 */
function list_files ( $base_dir, $testcases_dir, $rel_dir, $debug )
{
  if ( $dir = opendir ( $base_dir."/".$rel_dir ) ) {
    $tab_file = array();

    while ( ( $file = readdir ( $dir ) ) !== false ) {
      if ( ( is_file ( $base_dir."/".$rel_dir."/".$file ) && ( $file != "index.php" ) ) ) {
        $tab_file[] = addScheme ( $file, $base_dir."/".$rel_dir."/".$file );
      }
    }

    sort ( $tab_file );

    echo "<table>";

    foreach ( $tab_file as $elem )
    {
      $e = $elem['name'];
      $d = $elem['date'];
      $size = formatSize ( $elem['size'] );
      $file = $e;

      echo "<tr>";
      echo "<td>";
      echo "<img src='/common/images/file-none.gif' />&nbsp; <a target='_blank' href='$testcases_dir/$rel_dir/$file'>$e</a><br>";
      echo "</td>";
      echo "<td>";
      echo "</td>";
      echo "<td>";
      echo "$size<br>";
      echo "</td>";
      echo "<td>";
      echo "</td>";
      echo "<td>";
      echo "</td>";
      echo "<td>";
      echo date("F d Y H:i:s", "$d");
      echo "</td>";
      echo "</tr>";
    }
    echo "</table>";

    closedir ( $dir );
  }
}




?>
