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

sakharuk lon-capa-cvs@mail.lon-capa.org
Mon, 09 Sep 2002 20:20:40 -0000


sakharuk		Mon Sep  9 16:20:40 2002 EDT

  Modified files:              
    /loncom/interface	lonprintout.pm 
  Log:
  Added menu for selection of problems to print.
  
  
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.57 loncom/interface/lonprintout.pm:1.58
--- loncom/interface/lonprintout.pm:1.57	Mon Sep  9 15:27:42 2002
+++ loncom/interface/lonprintout.pm	Mon Sep  9 16:20:40 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.57 2002/09/09 19:27:42 sakharuk Exp $
+# $Id: lonprintout.pm,v 1.58 2002/09/09 20:20:40 sakharuk Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -118,6 +118,77 @@
 }
 
 
+sub problem_choice_menu {
+    my $r = shift;
+    my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'});
+    $subdirtoprint =~ s/\/[^\/]+$//;
+    my @list_of_files = ();
+    if ($ENV{'request.role'}=~m/^au\./ or $ENV{'request.role'}=~m/^ca\./) {
+	$subdirtoprint =~ s/^[^~]*~(\w+)\//\/home\/$1\/public_html\//;
+    } else {
+	$subdirtoprint =~ s/.*(\/res\/)/$1/;
+    }
+    my @content_directory = ();
+    if ($ENV{'request.role'}=~m/^au\./ or $ENV{'request.role'}=~m/^ca\./) {
+	@content_directory = &Apache::lonnet::dirlist($subdirtoprint,$ENV{'user.domain'}, $ENV{'user.name'},'');
+    } else {
+	@content_directory = &Apache::lonnet::dirlist($subdirtoprint);
+    }
+    for (my $iy=0;$iy<=$#content_directory;$iy++) {
+	my @tempo_array = split(/&/,$content_directory[$iy]);
+	if ($tempo_array[0] =~ m/^[^\.]+\.(problem|exam|quiz|assess|survey|form|library)$/) {
+	    push(@list_of_files,$tempo_array[0]);
+	}
+    }
+    $subdirtoprint =~ s/\/$//;
+    for (my $i=0;$i<=$#list_of_files;$i++) {
+	$list_of_files[$i] = $subdirtoprint.'/'.$list_of_files[$i];
+    }
+    $r->print(<<ENDMENUOUT1);
+<input type="hidden" name="url" value="$ENV{'form.url'}">
+<input type="hidden" name="choice" value="$ENV{'form.choice'}">
+<input type="hidden" name="layout" value="$ENV{'form.layout'}">
+<input type="hidden" name="numberofcolumns" value="$ENV{'form.numberofcolumns'}">
+<h1>Mark problems which you want to print</h1>
+<script>
+    function checkall() {
+	for (i=0; i<document.forms.printform.elements.length; i++) {
+            if 
+          (document.forms.printform.elements[i].name.indexOf('whattoprint')==0) {
+	      document.forms.printform.elements[i].checked=true;
+            }
+        }
+    }
+
+
+    function uncheckall() {
+	for (i=0; i<document.forms.printform.elements.length; i++) {
+            if 
+          (document.forms.printform.elements[i].name.indexOf('whattoprint')==0) {
+	      document.forms.printform.elements[i].checked=false;
+            }
+        }
+    }
+</script>
+<input type=button onClick="checkall()" value="Check for All">&nbsp;
+<input type=button onClick="uncheckall()" value="Check for None">
+<p>
+ENDMENUOUT1
+    my $i;
+    foreach my $file (@list_of_files) {
+	$r->print('<br /><input type=checkbox name="whattoprint'.$i.'" value="'.$file.'"> '.
+                  $file);
+	$i++;
+    }
+    $r->print(<<ENDMENUOUT2);
+<br />
+<input type="hidden" name="numberofproblems" value="$i">
+<input type="hidden" name="phase" value="three">
+<input type="submit" value="Submit">
+ENDMENUOUT2
+}
+
+
 sub additional_class_menu {
     my $r = shift;
     $r->print(<<ENDMENUOUT1);
@@ -133,7 +204,6 @@
 		   $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
     my $now=time;
     $r->print(<<ENDDISHEADER);
-<input type=hidden name=sendmode value=group>
 <script>
     function checkall() {
 	for (i=0; i<document.forms.printform.elements.length; i++) {
@@ -206,12 +276,16 @@
     for (my $i=0; $i<$ENV{'form.numberofstudents'};$i++) {
 	$what_to_print .= '<input type="hidden" name="whomtoprint'.$i.'" value="'.$ENV{'form.whomtoprint'.$i}.'">';
     }
+    for (my $i=0; $i<$ENV{'form.numberofproblems'};$i++) {
+	$what_to_print .= '<input type="hidden" name="whattoprint'.$i.'" value="'.$ENV{'form.whattoprint'.$i}.'">';
+    }
     $r->print(<<ENDMENUOUT);
     $what_to_print
 <input type="hidden" name="url" value="$ENV{'form.url'}">
 <input type="hidden" name="choice" value="$ENV{'form.choice'}">
 <input type="hidden" name="layout" value="$ENV{'form.layout'}">
 <input type="hidden" name="numberofstudents" value="$ENV{'form.numberofstudents'}">
+<input type="hidden" name="numberofproblems" value="$ENV{'form.numberofproblems'}">
 <input type="hidden" name="numberofcolumns" value="$ENV{'form.numberofcolumns'}">
 Define page layout parameters: <br />
 <b>Width</b>: <input type="text" name="width" width="8" value="9cm"> <br />
@@ -397,48 +471,30 @@
 	    $current_output =~ s/\\begin{document}/\\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent\\fbox{\\textbf{$fullname}}\\hskip 1\.4in } \\vskip 5 mm /;
 	    $result .= $current_output;
 	}
-
 	$result = &additional_cleanup($result);
-
-
-
-
-
-
     } elsif ($choice eq 'Subdirectory print') {      
-	my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'});
-	$subdirtoprint =~ s/\/[^\/]+$//;
-	my @list_of_files = ();
-	if ($ENV{'request.role'}=~m/^au\./ or $ENV{'request.role'}=~m/^ca\./) {
-	    $subdirtoprint =~ s/^[^~]*~(\w+)\//\/home\/$1\/public_html\//;
-	} else {
-	    $subdirtoprint =~ s/.*(\/res\/)/$1/;
-	}
-	my @content_directory = ();
-	if ($ENV{'request.role'}=~m/^au\./ or $ENV{'request.role'}=~m/^ca\./) {
-	    @content_directory = &Apache::lonnet::dirlist($subdirtoprint,$ENV{'user.domain'}, $ENV{'user.name'},'');
-	} else {
-	    @content_directory = &Apache::lonnet::dirlist($subdirtoprint);
-	}
-	for (my $iy=0;$iy<=$#content_directory;$iy++) {
-	    my @tempo_array = split(/&/,$content_directory[$iy]);
-	    if ($tempo_array[0] =~ m/^[^\.]+\.(problem|exam|quiz|assess|survey|form|library)$/) {
-		push(@list_of_files,$tempo_array[0]);
+    #prints selected problems from the subdirectory 
+        my @list_of_files = ();
+	for (my $i=0; $i<$ENV{'form.numberofproblems'};$i++) {
+	    if ($ENV{'form.whattoprint'.$i}=~/^\//) {
+#		$result.= $ENV{'form.whattoprint'.$i}.' FFF ';
+		push @list_of_files,$ENV{'form.whattoprint'.$i};
 	    }
 	}
-	$subdirtoprint =~ s/\/$//;
 	for (my $i=0;$i<=$#list_of_files;$i++) {
-	    my $urlp = $subdirtoprint.'/'.$list_of_files[$i];
-	    my %moreenv;
-	    $moreenv{'form.grade_target'}='tex';
-	    &Apache::lonnet::appenv(%moreenv);
-	    if ($ENV{'request.role'}=~m/^au\./ or $ENV{'request.role'}=~m/^ca\./) { 
-		$urlp =~ s/\/home\/([^\/]*)\/public_html/\/~$1/; 
-	    }
-	    my $texversion=&Apache::lonnet::ssi($urlp);
-	    &Apache::lonnet::delenv('form.grade_target');
-	    $texversion =~ s/(\\begin{document})/$1 {\\tiny\\begin{verbatim}$urlp\\end{verbatim}}/;
-	    $result .= $texversion;   
+	    my $urlp = $list_of_files[$i];
+	    if ($urlp=~/\//) {
+		my %moreenv;
+		$moreenv{'form.grade_target'}='tex';
+		&Apache::lonnet::appenv(%moreenv);
+		if ($ENV{'request.role'}=~m/^au\./ or $ENV{'request.role'}=~m/^ca\./) { 
+		    $urlp =~ s/\/home\/([^\/]*)\/public_html/\/~$1/; 
+		}
+		my $texversion=&Apache::lonnet::ssi($urlp);
+		&Apache::lonnet::delenv('form.grade_target');
+		$texversion =~ s/(\\begin{document})/$1 {\\tiny\\begin{verbatim}$urlp\\end{verbatim}}/;
+		$result .= $texversion;
+	    }   
 	}
 	$result = &additional_cleanup($result);
 	
@@ -939,6 +995,8 @@
      if ($ENV{'form.phase'} eq 'two') {
 	 if($ENV{'form.choice'} eq 'All class print') {
 	     &additional_class_menu($r);
+	 } elsif($ENV{'form.choice'} eq 'Subdirectory print') {
+	     &problem_choice_menu($r);
 	 } else {
 	     $ENV{'form.phase'} = 'three';
 	 }