#!/usr/bin/perl -w
use strict;
no strict "vars";
#
#  To move files tested by translators into the appropriate public locations.
#
#  Version of 2007 Mar 14 pm 4:49
#
#  'cron' will run this program every 5 minutes, and this program will find any
#   files that translators have named in the 'makepublic' directory.  Files in that 
#   location are expected to have a first line that starts with the person's transcode
#   followed by the pathname elements to describe where the the file will go
#   in the destination language's tree of pages/files.
#
# TREAT THIS HASH TABLE AS AN IMPORTANT SECRET!:
%destlang = (
	"Gk2006BC" => "GreekL",
	"tr73m03k" => "chinEse",
	"trAM19V8" => "spanishSA",
);

#
@args = ("date");
system(@args) == 0
  or die "system @args failed: $?";
#
#Identify the files in 1 test area:
@args = ("ls", "-al", "/home/darwind/public_html/tr73m03k/makepublic");  
system(@args) == 0
  or die "system @args failed: $?";

#foreach $key (%destlang) {
	
	#Move the files to the correct language:
	#@args = ("mv", "/home/darwind/public_html/tr73m03k/makepublic/*",     
	#               "/home/darwind/public_html/chinEse/makepublic"); 
				   
	@args = ("ls", "/home/darwind/public_html/tr73m03k/makepublic");    
	@filestomove = `(@args)`;

    foreach $fileN (@filestomove) {
	open(FILEN, "/home/darwind/public_html/tr73m03k/makepublic/$fileN") 
	  or die "Can't open /home/darwind/public_html/tr73m03k/makepublic/$fileN\n";
	while ($lineread = <FILEN>) {
		#$line = <FILEN> ;  #Read 1st line only
		#print "First line of $fileN is $line\n";
		if ($INPUT_LINE_NUMBER == 1) {
		  print "First line of $fileN is $lineread\n";
		};
		if ($INPUT_LINE_NUMBER == 2) {
		  print "Copying rest of $fileN to targetofmove/$fileN\n";
		  open(FILEN, ">>", "/home/darwind/public_html/tr73m03k/targetofmove/$fileN") 
			or die "Can't open /home/darwind/public_html/tr73m03k/targetofmove/$fileN\n";
		};
		if ($INPUT_LINE_NUMBER >= 2) {
		  print FILEN "$lineread";
		};
  	};
    };
#};  # End of all transcoded languages
