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

sakharuk lon-capa-cvs@mail.lon-capa.org
Thu, 05 Sep 2002 15:51:07 -0000


sakharuk		Thu Sep  5 11:51:07 2002 EDT

  Modified files:              
    /loncom/interface	lonprintout.pm 
  Log:
  Prints assignment for a group of student. Needs some additional 
  work: 1. Info about course; 2. Printing every students on the new page/sheet; ...
  
  
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.53 loncom/interface/lonprintout.pm:1.54
--- loncom/interface/lonprintout.pm:1.53	Tue Sep  3 23:59:20 2002
+++ loncom/interface/lonprintout.pm	Thu Sep  5 11:51:07 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.53 2002/09/04 03:59:20 albertel Exp $
+# $Id: lonprintout.pm,v 1.54 2002/09/05 15:51:07 sakharuk Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -43,11 +43,13 @@
 use Apache::Constants qw(:common :http);
 use Apache::lonxml;
 use Apache::lonnet;
+use Apache::loncommon;
 use Apache::inputtags;
+use Apache::loncoursedata;
+use Apache::grades;
 use Apache::edit;
 use Apache::File();
 use POSIX qw(strftime);
-use Apache::loncoursedata;
 
 
 sub headerform {
@@ -83,7 +85,7 @@
     }
     if ($ENV{'request.role'}=~m/^cc\./ or $ENV{'request.role'}=~m/^in\./ or $ENV{'request.role'}=~m/^ta\./) { 
 	$r->print(<<ENDMENUOUT6);
-  <input type="radio" name="choice" value="All class print">  Print assignment for students in class<br />
+  <input type="radio" name="choice" value="All class print">  Print assignment (all problems from the primary sequence) for group of students<br />
 ENDMENUOUT6
     }
       my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'});
@@ -135,23 +137,27 @@
 ENDMENUOUT1
     my $c = $r->connection;    
     my %cache;
-    my $courseID=$ENV{'request.course.id'};
-    my $classlist=&Apache::loncoursedata::DownloadClasslist($courseID,
-                                                $cache{'ClasslistTimestamp'},
-                                                $c);
-    foreach (keys(%$classlist)) {
-        if(/^(con_lost|error|no_such_host)/i) {
-            untie(%cache);
-            return "Error getting student data.";
-        }
+    my $courseID = $ENV{'request.course.id'};
+    my $classlist = &Apache::loncoursedata::DownloadClasslist($courseID,$cache{'ClasslistTimestamp'},$c);
+    &Apache::loncoursedata::ProcessClasslist(\%cache,$classlist,$courseID,$c);    
+    my @all_students = split(':::',$cache{'NamesOfStudents'});
+    my @active_students = ();
+    foreach my $student (@all_students) {
+	if ($cache{$student.':Status'} eq 'Active') {
+	    push @active_students,$student;
+	}
     }
-    my $classlistaa = '';
-    foreach my $st (keys(%$classlist)) {
-	$classlistaa .= ' SSS '.$st.' => '.$$classlist{$st}.' FFF '."\r\n";
+    my $what_to_print = '<table border="1">';    
+    my $i = 0;
+    foreach my $student (@active_students) {
+	$what_to_print .= '<tr><td><input type="checkbox" name="whomtoprint'.$i.'" value="'.$student.'">'.$cache{$student.':fullname'}.'</td></tr>';
+#	$what_to_print .= '<tr><td><input type="checkbox" name="whomtoprint'.$i.'" value="'.$cache{$student.':fullname'}.'">'.$cache{$student.':fullname'}.'</td></tr>';
+	$i++;
     }
-
+    $what_to_print .= '</table>';
     $r->print(<<ENDMENUOUT2);
-    $classlistaa <br />
+    $what_to_print <br />
+<input type="hidden" name="numberofstudents" value="$i">
 <input type="hidden" name="phase" value="three">
 <input type="submit" value="Submit">
 ENDMENUOUT2
@@ -160,10 +166,16 @@
 
 sub additional_print_menu { 
     my $r = shift;
+    my $what_to_print = '';
+    for (my $i=0; $i<$ENV{'form.numberofstudents'};$i++) {
+	$what_to_print .= '<input type="hidden" name="whomtoprint'.$i.'" value="'.$ENV{'form.whomtoprint'.$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="numberofcolumns" value="$ENV{'form.numberofcolumns'}">
 Enter width of the page: <input type="text" name="width" width="10" value="9cm"> <br />
 <input type="hidden" name="phase" value="four">
@@ -309,6 +321,48 @@
 	}	    
 	$result = &additional_cleanup($result);
     } elsif ($choice eq 'All class print') { 
+    #-- prints assignments for whole class or for selected students  
+        my (@students,@st_output) = ((),());
+	for (my $i=0; $i<$ENV{'form.numberofstudents'};$i++) {
+	    if ($ENV{'form.whomtoprint'.$i}=~/:/) {
+		push @students,$ENV{'form.whomtoprint'.$i};
+	    }
+	}
+	#where is the primary sequence containing current resource (the same for all students)?
+	my $symbolic = &Apache::lonnet::symbread($ENV{'form.url'});
+	$symbolic =~ m/([^_]+)_/;
+	my $primary_sequence = '/res/'.$1;
+	#opens and analyses the primary sequence file, produces the array of resources
+	my $sequence_file=&Apache::lonnet::filelocation("",$primary_sequence);
+	my $sequencefilecontents=&Apache::lonnet::getfile($sequence_file);
+	my @master_seq = &content_map($sequencefilecontents);
+        #loop over students
+	foreach my $person (@students) {
+	    my $current_output = ''; 
+	    my ($username,$userdomain) = split /:/,$person;
+	    my $fullname = &Apache::grades::get_fullname($username,$userdomain);
+            #goes through all resources, checks if they are available for current student, and produces output 
+	    foreach my $curres (@master_seq)  {
+		$curres =~ s/^"//;
+		$curres =~ s/"$//;
+                if ($curres=~/\w+/) {
+		    my $symb = &Apache::lonnet::symbread($curres);
+		    my ($map,$id,$res_url) = split(/___/,$symb);
+		    if (&Apache::lonnet::allowed('bre',$res_url)) {
+			my $rendered = &Apache::loncommon::get_student_view($symb,$username,$userdomain,
+                                                                        $ENV{'request.course.id'},'tex');
+			$current_output .= $rendered;
+		    }
+		}
+	    }
+	    $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);
+
+
+