[LON-CAPA-cvs] cvs: loncom /interface lonprintout.pm

sakharuk lon-capa-cvs@mail.lon-capa.org
Fri, 07 Feb 2003 19:47:48 -0000


This is a MIME encoded message

--sakharuk1044647268
Content-Type: text/plain

sakharuk		Fri Feb  7 14:47:48 2003 EDT

  Modified files:              
    /loncom/interface	lonprintout.pm 
  Log:
  1. Bug 1224 (Prints incorrect problem) is fixed. Changes were done in subroutine coming_from_hash.
  2. Only one subroutine working with "big" hash is left which made code more clean and self-consistent. 
  3. Option "printing assignment for selected students" is restored for the courses created with DOCS. 
  
  
--sakharuk1044647268
Content-Type: text/plain
Content-Disposition: attachment; filename="sakharuk-20030207144748.txt"

Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.111 loncom/interface/lonprintout.pm:1.112
--- loncom/interface/lonprintout.pm:1.111	Tue Feb  4 17:22:07 2003
+++ loncom/interface/lonprintout.pm	Fri Feb  7 14:47:48 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.111 2003/02/04 22:22:07 sakharuk Exp $
+# $Id: lonprintout.pm,v 1.112 2003/02/07 19:47:48 sakharuk Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -144,6 +144,7 @@
                                            </select> 
    </td>
  </tr>
+
 </table>
 </br> 
 <input type="submit" value="Submit your choice">
@@ -158,9 +159,13 @@
     my @sequence = split('___',$symbolic);
     if ($sequence[0]=~/^uploaded/) {$primary_sequence = '/'.$sequence[0];} 
       else {$primary_sequence = '/res/'.$sequence[0];} 
-    my @master_seq = &coming_from_hash($primary_sequence,$sequence[0]);
-    my @titles_master_seq = &titles_coming_from_hash($primary_sequence,$sequence[0]);
-    foreach my $entity (@titles_master_seq) {$entity=~/^(.*)&&/; $entity=$1}
+    my @master_seq = &coming_from_hash($primary_sequence);
+    my @titles_master_seq = (); 
+    for (my $i=0;$i<=$#master_seq;$i++) {
+	my ($path,$title,$symb) = split /&&/,$master_seq[$i];
+	$master_seq[$i] = $path.'&&'.$symb;
+        push @titles_master_seq,  $title;
+    }
     my @master_seq_view = @master_seq;
     if ($ENV{'user.adv'}) {
       for (my $i=0;$i<=$#master_seq_view;$i++) {
@@ -183,8 +188,7 @@
 <script>
     function checkall() {
 	for (i=0; i<document.forms.printform.elements.length; i++) {
-            if 
-          (document.forms.printform.elements[i].name.indexOf('whatfile')==0) {
+            if (document.forms.printform.elements[i].name.indexOf('whatfile')==0) {
 	      document.forms.printform.elements[i].checked=true;
             }
         }
@@ -198,6 +202,7 @@
         }
     }
 </script>
+<b>DDD=$#titles_master_seq</b> $titles_master_seq[0]<br />
 <input type=button onClick="checkall()" value="Check All">&nbsp;
 <input type=button onClick="uncheckall()" value="Uncheck">&nbsp;
 <input type="submit" value="Submit">
@@ -549,7 +554,11 @@
 	} else {
 	    $main_seq = '/res/'.$ENV{'request.course.uri'};
 	}
-	my @file_seq = &coming_from_hash_whole($main_seq);
+	my @file_seq = &coming_from_hash($main_seq);
+	for (my $i=0;$i<=$#file_seq;$i++) {
+	    my ($path,$title,$symb) = split /&&/,$file_seq[$i];
+	    $file_seq[$i] = $path.'&&'.$symb;
+	}
 	my $flag_latex_header_remove = 'NO';
         #-- produce an output string
 	for (my $i=0;$i<=$#file_seq;$i++) {
@@ -586,8 +595,14 @@
 	#where is the primary sequence containing current resource (the same for all students)?
 	my $symbolic = &Apache::lonnet::symbread($ENV{'form.url'});
 	my @sequence = split('___',$symbolic);
-	my $primary_sequence = '/res/'.$sequence[0]; 	
-	my @master_seq = &coming_from_hash($primary_sequence,$sequence[0]); 
+	my $primary_sequence;
+	if ($sequence[0]=~/^uploaded/) {$primary_sequence = '/'.$sequence[0];} 
+          else {$primary_sequence = '/res/'.$sequence[0];}  	
+	my @master_seq = &coming_from_hash($primary_sequence); 
+	for (my $i=0;$i<=$#master_seq;$i++) {
+	    my ($path,$title,$symb) = split /&&/,$master_seq[$i];
+	    $master_seq[$i] = $path.'&&'.$symb;
+	}
         #loop over students
 	my $flag_latex_header_remove = 'NO'; 
 	my %moreenv;
@@ -617,7 +632,7 @@
 	    }
 	    if ($current_output=~/\\documentclass/) {
 		my $courseidinfo = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
-		$current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm}\\usepackage{fancyhdr}\\pagestyle{fancy}\\rhead{}\\chead{}\\lhead{$courseidinfo \\hfill \\thepage \\\\ \\textit{$assignment}}  \\begin{document}\\noindent\\textit{\\textbf{$fullname}}\\vskip 3 mm /;
+		$current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm}\\usepackage{fancyhdr}\\pagestyle{fancy}\\rhead{}\\chead{}\\lhead{$courseidinfo \\hfill \\thepage \\\\ \\textit{$assignment}} \\begin{document}\\noindent\\textit{\\textbf{$fullname}}\\vskip 3 mm /;
 	    } else {
 		my $blanspages = '';
 		for (my $j=0;$j<$ENV{'form.addedpages'};$j++) {$blanspages.='\clearpage\strut\clearpage';}
@@ -712,7 +727,7 @@
 }
 
 
-sub coming_from_hash_whole {
+sub coming_from_hash {
 
     my $mainsequence = shift;
     my @resourcelist = ();
@@ -722,12 +737,12 @@
     my $current_resource = $mapstart;
     while ($current_resource ne $mapfinish) {
 	if ($hash{'src_'.$current_resource}=~/\.sequence$/) {
-	    push @resourcelist,&coming_from_hash_whole($hash{'src_'.$current_resource});
+	    push @resourcelist,&coming_from_hash($hash{'src_'.$current_resource});
 	} else {
 	    my $presymb; 
 	    if ($mainsequence =~ /\/res\/(.*)$/) {$presymb = $1;} 
               elsif ($mainsequence =~ /\/?(uploaded\/(.*))$/) {$presymb = $1;} 
-	    my $rid = $hash{'ids_'.$hash{'src_'.$current_resource}};
+	    my $rid = $current_resource;
 	    if ($rid=~/,/) {
 		my @rid = split /,/, $rid;
 		foreach my $rid_element (@rid) {
@@ -742,18 +757,18 @@
 	    }
 	    $hash{'src_'.$current_resource} =~ m/\/res\/(.*)$/;
 	    my $symb = $presymb.'___'.$rid.'___'.$1;	    
-	    push @resourcelist,$hash{'src_'.$current_resource}.'&&'.$symb;
+	    push @resourcelist,$hash{'src_'.$current_resource}.'&&'.$hash{'title_'.$current_resource}.'&&'.$symb;
 	}
 	$current_resource = $hash{'goesto_'.$hash{'to_'.$current_resource}};
     } 
     #needs if final resource in the map (type="finish") contains something
 	if ($hash{'src_'.$current_resource}=~/\.sequence$/) {
-	    push @resourcelist,&coming_from_hash_whole($hash{'src_'.$current_resource});
+	    push @resourcelist,&coming_from_hash($hash{'src_'.$current_resource});
 	} else {
 	    my $presymb; 
 	    if ($mainsequence =~ /\/res\/(.*)$/) {$presymb = $1;} 
               elsif ($mainsequence =~ /\/?(uploaded\/(.*))$/) {$presymb = $1;} 
-	    my $rid = $hash{'ids_'.$hash{'src_'.$current_resource}};
+	    my $rid = $current_resource;
 	    if ($rid=~/,/) {
 		my @rid = split /,/, $rid;
 		foreach my $rid_element (@rid) {
@@ -768,139 +783,12 @@
 	    }
 	    $hash{'src_'.$current_resource} =~ m/\/res\/(.*)$/;
 	    my $symb = $presymb.'___'.$rid.'___'.$1;	    
-	    push @resourcelist,$hash{'src_'.$current_resource}.'&&'.$symb;
-	}
-	$current_resource = $hash{'goesto_'.$hash{'to_'.$current_resource}};
-    return @resourcelist;
-}
-
-
-sub coming_from_hash {
-
-    my ($mainsequence,$symb) = @_;
-    my @resourcelist = ();
-    my $mapid = $hash{'map_pc_'.$mainsequence};
-    my $mapstart = $hash{'map_start_'.$mainsequence};
-    my $mapfinish = $hash{'map_finish_'.$mainsequence};
-    my ($presymb);
-    if ($symb) {
-	($presymb)=split(/___/,$symb);
-    } else {
-	$presymb=$mainsequence;
-	$presymb=~s|^/res/||;
-    }
-    $presymb = $presymb.'___';
-    my $current_resource = $mapstart;
-    while ($current_resource ne $mapfinish) {
-	if (not $hash{'src_'.$current_resource}=~/\.sequence$/) {
-	    my $rid = $hash{'ids_'.$hash{'src_'.$current_resource}};
-            if ($rid=~/,/) {
-		my @rid = split /,/, $rid;
-		foreach my $rid_element (@rid) {
-		    if ($rid_element =~ m/^$mapid\.(\d*)/) {
-			$rid = $1; 
-			last;
-		    }
-		}
-	    } else {
-		$rid =~ m/^$mapid\.(\d*)/;
-                $rid = $1;  
-	    }
-	    $hash{'src_'.$current_resource} =~ m/\/res\/(.*)$/;
-	    $symb = $presymb.$rid.'___'.$1;
-	    push @resourcelist,$hash{'src_'.$current_resource}.'&&'.$symb;
-	} else {
-	    push @resourcelist,&coming_from_hash($hash{'src_'.$current_resource});
+	    push @resourcelist,$hash{'src_'.$current_resource}.'&&'.$hash{'title_'.$current_resource}.'&&'.$symb;
 	}
 	$current_resource = $hash{'goesto_'.$hash{'to_'.$current_resource}};
-    }
-    #needs if final resource in the map (type="finish") contains something
-    if (not $hash{'src_'.$current_resource}=~/\.sequence$/) {
-		    my $rid = $hash{'ids_'.$hash{'src_'.$current_resource}};
-            if ($rid=~/,/) {
-		my @rid = split /,/, $rid;
-		foreach my $rid_element (@rid) {
-		    if ($rid_element =~ m/^$mapid\.(\d*)/) {
-			$rid = $1; 
-			last;
-		    }
-		}
-	    } else {
-		$rid =~ m/^$mapid\.(\d*)/;
-                $rid = $1;  
-	    }
-	    $hash{'src_'.$current_resource} =~ m/\/res\/(.*)$/;
-	    $symb = $presymb.$rid.'___'.$1;
-	push @resourcelist,$hash{'src_'.$current_resource}.'&&'.$symb;
-    } else {
-	push @resourcelist,&coming_from_hash($hash{'src_'.$current_resource});
-    }
     return @resourcelist;
 }
 
-
-sub titles_coming_from_hash {
-
-    my ($mainsequence,$symb) = @_;
-    my @resourcelist = ();
-    my $mapid = $hash{'map_pc_'.$mainsequence};
-    my $mapstart = $hash{'map_start_'.$mainsequence};
-    my $mapfinish = $hash{'map_finish_'.$mainsequence};
-    my ($presymb);
-    if ($symb) {
-	($presymb)=split(/___/,$symb);
-    } else {
-	$presymb=$mainsequence;
-	$presymb=~s|^/res/||;
-    }
-    $presymb = $presymb.'___';
-    my $current_resource = $mapstart;
-    while ($current_resource ne $mapfinish) {
-	if (not $hash{'src_'.$current_resource}=~/\.sequence$/) {
-	    my $rid = $hash{'ids_'.$hash{'src_'.$current_resource}};
-            if ($rid=~/,/) {
-		my @rid = split /,/, $rid;
-		foreach my $rid_element (@rid) {
-		    if ($rid_element =~ m/^$mapid\.(\d*)/) {
-			$rid = $1; 
-			last;
-		    }
-		}
-	    } else {
-		$rid =~ m/^$mapid\.(\d*)/;
-                $rid = $1;  
-	    }
-	    $hash{'src_'.$current_resource} =~ m/\/res\/(.*)$/;
-	    $symb = $presymb.$rid.'___'.$1;
-	    push @resourcelist,$hash{'title_'.$current_resource}.'&&'.$symb;
-	} else {
-	    push @resourcelist,&titles_coming_from_hash($hash{'src_'.$current_resource});
-	}
-	$current_resource = $hash{'goesto_'.$hash{'to_'.$current_resource}};
-    }
-    #needs if final resource in the map (type="finish") contains something
-    if (not $hash{'src_'.$current_resource}=~/\.sequence$/) {
-		    my $rid = $hash{'ids_'.$hash{'src_'.$current_resource}};
-            if ($rid=~/,/) {
-		my @rid = split /,/, $rid;
-		foreach my $rid_element (@rid) {
-		    if ($rid_element =~ m/^$mapid\.(\d*)/) {
-			$rid = $1; 
-			last;
-		    }
-		}
-	    } else {
-		$rid =~ m/^$mapid\.(\d*)/;
-                $rid = $1;  
-	    }
-	    $hash{'src_'.$current_resource} =~ m/\/res\/(.*)$/;
-	    $symb = $presymb.$rid.'___'.$1;
-	push @resourcelist,$hash{'title_'.$current_resource}.'&&'.$symb;
-    } else {
-	push @resourcelist,&titles_coming_from_hash($hash{'src_'.$current_resource});
-    }
-    return @resourcelist;
-}
 
 sub latex_header_footer_remove {
     my $text = shift;

--sakharuk1044647268--