Index: /gsdl/trunk/bin/script/gti.pl
===================================================================
--- /gsdl/trunk/bin/script/gti.pl	(revision 14257)
+++ /gsdl/trunk/bin/script/gti.pl	(revision 14258)
@@ -39,5 +39,6 @@
 
 
-my $anonymous_cvs_root = ":pserver:cvs_anon\@cvs.scms.waikato.ac.nz:2402/usr/local/global-cvs/gsdl-src";
+#my $anonymous_cvs_root = ":pserver:cvs_anon\@cvs.scms.waikato.ac.nz:2402/usr/local/global-cvs/gsdl-src";
+#my $anonymous_svn_root = "http://http://svn.greenstone.org/gsdl/trunk/";
 my $gsdl_root_directory = "$ENV{'GSDLHOME'}";
 my $gti_log_file = &util::filename_cat($gsdl_root_directory, "etc", "gti.log");
@@ -79,9 +80,13 @@
 	# 'target_file' => "gsdl-documentation/tutorials/xml-source/tutorial_{target_language_code}.xml" },
 
-      # Greenstone.org
+      # new Greenstone.org
       { 'key' => "greenorg",
-	'file_type' => "macrofile",
-	'source_file' => "greenorg/macros/english.dm",
-	'target_file' => "greenorg/macros/{iso_639_1_target_language_name}.dm" }
+        'file_type' => "resource_bundle",
+        'source_file' => "greenstoneorg/website/classes/Gsc.properties",
+        'target_file' => "greenstoneorg/website/classes/Gsc_{iso_639_1_target_language_name}.properties" 
+	# 'file_type' => "macrofile",
+	# 'source_file' => "greenorg/macros/english.dm",
+	# 'target_file' => "greenorg/macros/{iso_639_1_target_language_name}.dm" 
+      }
     ];
 
@@ -111,8 +116,8 @@
     }
     if ($gti_command =~ /^get-first-n-chunks-requiring-work$/i) {
-	print &get_first_n_chunks_requiring_work(@gti_command_arguments);
+	print &get_first_n_chunks_requiring_work(@gti_command_arguments);        
     }
     if ($gti_command =~ /^get-language-status$/i) {
-	print &get_language_status(@gti_command_arguments);
+	print &get_language_status(@gti_command_arguments);       
     }
     if ($gti_command =~ /^search-chunks$/i) {
@@ -248,5 +253,5 @@
     my @source_file_lines = &read_file_lines($source_file_path);
     my %source_file_key_to_line_mapping = &build_key_to_line_mapping(\@source_file_lines, $translation_file_type);
-
+    
     my $target_file_path = &util::filename_cat($gsdl_root_directory, $target_file);
     my @target_file_lines = &read_file_lines($target_file_path);
@@ -299,7 +304,11 @@
 	my $source_file_chunk_date = $source_file_key_to_last_update_date_mapping{$chunk_key};
 	my $source_file_chunk_text = &make_text_xml_safe($source_file_key_to_text_mapping{$chunk_key});
-
+	
+	if(!defined $source_file_chunk_date){
+		$source_file_chunk_date = "";
+	}
+	
 	$xml_response .= "    <Chunk key=\"" . &make_text_xml_safe($chunk_key) . "\">\n";
-	$xml_response .= "      <SourceFileText date=\"$source_file_chunk_date\">$source_file_chunk_text</SourceFileText>\n";
+	$xml_response .= "      <SourceFileText date=\"$source_file_chunk_date\">$source_file_chunk_text</SourceFileText>\n";	
 	$xml_response .= "      <TargetFileText></TargetFileText>\n";
 	$xml_response .= "    </Chunk>\n";
@@ -325,6 +334,10 @@
 	my $target_file_chunk_date = $target_file_key_to_last_update_date_mapping{$chunk_key};
 	my $target_file_chunk_text = &make_text_xml_safe($target_file_key_to_text_mapping{$chunk_key});
-
-	$xml_response .= "    <Chunk key=\"" . &make_text_xml_safe($chunk_key) . "\">\n";
+	
+	if(!defined $source_file_chunk_date){
+		$source_file_chunk_date = "";
+	}
+
+	$xml_response .= "    <Chunk key=\"" . &make_text_xml_safe($chunk_key) . "\">\n";	
 	$xml_response .= "      <SourceFileText date=\"$source_file_chunk_date\">$source_file_chunk_text</SourceFileText>\n";
 	$xml_response .= "      <TargetFileText date=\"$target_file_chunk_date\">$target_file_chunk_text</TargetFileText>\n";
@@ -636,5 +649,6 @@
     # The "2>/dev/null" is very important! If it is missing this will never return when run from the receptionist
     # unless ($translation_file_is_not_in_cvs) {
-	my $source_file_cvs_status = `cd $gsdl_root_directory; cvs -d $anonymous_cvs_root update $source_file 2>/dev/null`;
+	#my $source_file_cvs_status = `cd $gsdl_root_directory; cvs -d $anonymous_cvs_root update $source_file 2>/dev/null`;
+        my $source_file_cvs_status = `cd $gsdl_root_directory; svn status $source_file 2>/dev/null`;
 	if ($source_file_cvs_status =~ /^C /) {
 	    &throw_fatal_error("Source file $source_file_path conflicts with the repository.");
@@ -753,9 +767,10 @@
 	my $chunk_cvs_date = $key_to_cvs_date_mapping{$chunk_key};
 	$key_to_last_update_date_mapping{$chunk_key} = $chunk_cvs_date;
-
+                
 	# If a comment date exists and it is after the CVS date, use that instead
+        # need to convert the comment date format to SVN format
 	my $chunk_gti_comment = $key_to_gti_comment_mapping{$chunk_key};
 	if (defined($chunk_gti_comment) && $chunk_gti_comment =~ /(\d?\d-\D\D\D-\d\d\d\d)/) {
-	    my $chunk_comment_date = $1;
+	    my $chunk_comment_date = $1;            
 	    if ((!defined($chunk_cvs_date) || &is_date_after($chunk_comment_date, $chunk_cvs_date))) {
 		$key_to_last_update_date_mapping{$chunk_key} = $chunk_comment_date;
@@ -774,5 +789,8 @@
     # Use CVS to annotate each line of the file with the date it was last edited
     # The "2>/dev/null" is very important! If it is missing this will never return when run from the receptionist
-    my $cvs_annotated_file = `cd $gsdl_root_directory; cvs -d $anonymous_cvs_root annotate -F $filename 2>/dev/null`;
+    # my $cvs_annotated_file = `cd $gsdl_root_directory; cvs -d $anonymous_cvs_root annotate -F $filename 2>/dev/null`;    
+    # my $cvs_annotated_file = `cd $gsdl_root_directory; export PATH=.:/research/lh92/programs/subversion/bin; svn annotate -v --force $filename`;
+    my $cvs_annotated_file = `cd $gsdl_root_directory; svn annotate -v $filename`;
+    
     my @cvs_annotated_file_lines = split(/\n/, $cvs_annotated_file);
 
@@ -780,22 +798,31 @@
     foreach my $cvs_annotated_file_line (@cvs_annotated_file_lines) {
 	# Extract the date from the CVS annotation at the front
-	$cvs_annotated_file_line =~ s/^\S+\s+\(\S+\s+(\S+)\):\s//;
-	push(@cvs_annotated_file_lines_date, $1);
-    }
-
+        # cvs format : 07-Jun-02
+        # svn format : 2007-07-16
+	# $cvs_annotated_file_line =~ s/^\S+\s+\(\S+\s+(\S+)\):\s//;
+        $cvs_annotated_file_line =~ s/^\s+\S+\s+\S+\s(\S+)//; 
+        
+        push(@cvs_annotated_file_lines_date, $1);
+        
+        # trim extra date information in svn annotation format
+        # 15:42:49 +1200 (Wed, 21 Jun 2006)
+        $cvs_annotated_file_line =~ s/^\s+\S+\s\S+\s\((.+?)\)\s//; 
+    }    
+    
     # Build a key to line mapping for the CVS annotated file, for matching the chunk key to the CVS date
     my %key_to_line_mapping = &build_key_to_line_mapping(\@cvs_annotated_file_lines, $translation_file_type);
-
+        
     my %key_to_cvs_date_mapping = ();
     foreach my $chunk_key (keys(%key_to_line_mapping)) {
  	my $chunk_starting_line = (split(/-/, $key_to_line_mapping{$chunk_key}))[0];
  	my $chunk_finishing_line = (split(/-/, $key_to_line_mapping{$chunk_key}))[1];
-
+                
  	# Find the date this chunk was last edited, from the CVS annotation
- 	my $chunk_date = $cvs_annotated_file_lines_date[$chunk_starting_line];
+ 	my $chunk_date = $cvs_annotated_file_lines_date[$chunk_starting_line];        
  	for (my $l = ($chunk_starting_line + 1); $l <= $chunk_finishing_line; $l++) {
  	    if (&is_date_after($cvs_annotated_file_lines_date[$l], $chunk_date)) {
  		# This part of the chunk has been updated more recently
  		$chunk_date = $cvs_annotated_file_lines_date[$l];
+ 		
  	    }
  	}
@@ -861,5 +888,8 @@
 	my $source_chunk_last_update_date = $source_file_key_to_last_update_date_mapping->{$chunk_key};
  	my $target_chunk_last_update_date = $target_file_key_to_last_update_date_mapping->{$chunk_key};
-	if (defined($target_chunk_last_update_date) && &is_date_after($source_chunk_last_update_date, $target_chunk_last_update_date)) {
+        
+        # print "key: $chunk_key\nsource date : $source_chunk_last_update_date\ntarget date : $target_chunk_last_update_date\nafter? ". &is_date_after($source_chunk_last_update_date, $target_chunk_last_update_date) . "\n\n";        
+                	
+        if (defined($target_chunk_last_update_date) && &is_date_after($source_chunk_last_update_date, $target_chunk_last_update_date)) {
 	    # &log_message("Chunk with key $chunk_key needs updating.");
 	    push(@target_file_keys_requiring_updating, $chunk_key);
@@ -903,5 +933,5 @@
 
 # Returns 1 if $date1 is after $date2, 0 otherwise
-sub is_date_after
+sub is_date_after_cvs
 {
     my ($date1, $date2) = @_;
@@ -909,4 +939,8 @@
 		  "Jul", 7, "Aug", 8, "Sep", 9, "Oct", 10, "Nov", 11, "Dec", 12);
 
+	if(!defined $date1) {
+		return 1;
+	}
+
     my @date1parts = split(/-/, $date1);
     my @date2parts = split(/-/, $date2);
@@ -915,9 +949,9 @@
     my $year1 = $date1parts[2];
     if ($year1 < 80) {
-	$year1 += 2000;
+		$year1 += 2000;
     }
     my $year2 = $date2parts[2];
     if ($year2 < 80) {
-	$year2 += 2000;
+		$year2 += 2000;
     }
 
@@ -939,4 +973,54 @@
     }
 
+    return 0;
+}
+
+sub is_date_after
+{
+    my ($date1, $date2) = @_;
+    
+    if(!defined $date1) {
+      return 1;
+    }
+    if(!defined $date2) {
+      return 0;
+    }
+    
+    # 16-Aug-2006
+    if($date1=~ /(\d+?)-(\S\S\S)-(\d\d\d\d)/){
+       my %months = ("Jan", "01", "Feb", "02", "Mar", "03", "Apr",  "04", "May",  "05", "Jun",  "06",
+		  "Jul", "07", "Aug", "08", "Sep", "09", "Oct", "10", "Nov", "11", "Dec", "12");
+       $date1=$3 . "-" . $months{$2} . "-" . $1;
+       # print "** converted date1: $date1\n";
+    }
+    if($date2=~ /(\d+?)-(\S\S\S)-(\d\d\d\d)/){
+       my %months = ("Jan", "01", "Feb", "02", "Mar", "03", "Apr",  "04", "May",  "05", "Jun",  "06",
+		  "Jul", "07", "Aug", "08", "Sep", "09", "Oct", "10", "Nov", "11", "Dec", "12");
+       $date2=$3 . "-" . $months{$2} . "-" . $1;
+       # print "** converted date2: $date2\n";
+    }
+    
+    
+    # 2006-08-16
+    my @date1parts = split(/-/, $date1);
+    my @date2parts = split(/-/, $date2);
+    
+    # Compare year
+    if ($date1parts[0] > $date2parts[0]) {
+	return 1;
+    }
+    elsif ($date1parts[0] == $date2parts[0]) {
+	# Year is the same, so compare month
+	if ($date1parts[1] > $date2parts[1]) {
+	    return 1;
+	}
+	elsif ($date1parts[1] == $date2parts[1]) {
+	    # Month is the same, so compare day
+	    if ($date1parts[2] > $date2parts[2]) {
+		return 1;
+	    }
+	}
+    }    
+    
     return 0;
 }
