[LON-CAPA-cvs] cvs: loncom(bz2851) /interface lonprintout.pm
foxr
foxr@source.lon-capa.org
Tue, 25 Aug 2009 10:57:19 -0000
This is a MIME encoded message
--foxr1251197839
Content-Type: text/plain
foxr Tue Aug 25 10:57:19 2009 EDT
Modified files: (Branch: bz2851)
/loncom/interface lonprintout.pm
Log:
- On the way to allowing print pages in courses to print pages
for selected students.
- Factor out student chooser from the inline helper generating code so
it can be re-used for the course/folder and page printing code.
--foxr1251197839
Content-Type: text/plain
Content-Disposition: attachment; filename="foxr-20090825105719.txt"
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.560.2.1 loncom/interface/lonprintout.pm:1.560.2.2
--- loncom/interface/lonprintout.pm:1.560.2.1 Mon Aug 17 10:48:28 2009
+++ loncom/interface/lonprintout.pm Tue Aug 25 10:57:18 2009
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Printout
#
-# $Id: lonprintout.pm,v 1.560.2.1 2009/08/17 10:48:28 foxr Exp $
+# $Id: lonprintout.pm,v 1.560.2.2 2009/08/25 10:57:18 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -26,7 +26,6 @@
#
#
package Apache::lonprintout;
-
use strict;
use Apache::Constants qw(:common :http);
use Apache::lonxml;
@@ -74,6 +73,46 @@
my $font_size = 'normalsize'; # Default is normalsize...
+#---------------------------- Helper helpers. -------------------------
+
+# Returns the text needd for a student chooser.
+# that text must still be parsed by the helper xml parser.
+# Parameters:
+# this_state - State name of the chooser.
+# sort_choice - variable to hold the sorting choice.
+# variable - Name of variable to hold students.
+# next_state - State after chooser.
+
+
+sub generate_student_chooser {
+ my ($this_state,
+ $sort_choice,
+ $variable,
+ $next_state) = @_;
+
+ my $result = <<CHOOSE_STUDENTS;
+ <state name="$this_state" title="Select Students and Resources">
+ <message><b>Select sorting order of printout</b> </message>
+
+ <choices variable="$sort_choice">
+ <choice computer='0'>Sort by section then student</choice>
+ <choice computer='1'>Sort by students across sections.</choice>
+ </choices>
+
+ <message><br /><hr /><br /> </message>
+ <student multichoice='1'
+ variable="$variable"
+ nextstate="$next_state"
+ coursepersonnel="1" />
+ </state>
+
+CHOOSE_STUDENTS
+
+ return $result;
+}
+
+#-----------------------------------------------------------------------
+
# Fetch the contents of a resource, uninterpreted.
# This is used here to fetch a latex file to be included
@@ -1343,7 +1382,7 @@
if ($mode ne '') {$mode='\\'.$mode}
- my $result.= &print_latex_header($mode);
+ my $result = &print_latex_header($mode);
if ($currentURL=~m|^(/adm/wrapper/)?ext/|) {
$currentURL=~s|^(/adm/wrapper/)?ext/|http://|;
my $title=&Apache::lonnet::gettitle($symb);
@@ -1413,9 +1452,6 @@
my $texversion = &ssi_with_retries($urlp, $ssi_retry_count, %form);
- # There seems to be an extraneous \vskip 1mm \\\\ :
-
- $texversion =~ s/^\\vskip 1mm \\\\\\\\//;
# current document with answers.. no need to encap in minipage
# since there's only one answer.
@@ -1438,7 +1474,7 @@
if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
$texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
} else {
- $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
+ $texversion= &print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
if ($helper->{'VARS'}->{'construction'} ne '1') {
my $title = &Apache::lonnet::gettitle($helper->{'VARS'}->{'symb'});
$title = &Apache::lonxml::latex_special_symbols($title);
@@ -1473,6 +1509,14 @@
$texversion=~s/(\\addcontentsline\{toc\}\{subsection\}\{[^\}]*\})/$1 URL: \\verb|$currentURL| \\strut\\\\\\strut /;
}
+ $texversion = &latex_header_footer_remove($texversion);
+
+ # the first remaining line is a comment from londefdef the second
+ # line seems to be an extraneous \vskip 1mm \\\\ :
+ # (imperfect removal from header_footer_remove?
+
+ $texversion =~ s/\\vskip 1mm \\\\\\\\//;
+
$result .= $texversion;
if ($currentURL=~m/\.page\s*$/) {
($result,$numberofcolumns) = &page_cleanup($result);
@@ -1560,7 +1604,7 @@
# A reference to a page break hash.
#
#
-#use Data::Dumper;
+use Data::Dumper;
#sub dump_helper_vars {
# my ($helper) = @_;
# my $helpervars = Dumper($helper->{'VARS'});
@@ -2018,7 +2062,7 @@
$result.="\\newpage\n";
}
}
- my ($sequence,$middle_thingy,$urlp)=&Apache::lonnet::decode_symb($master_seq[$i]);
+ my ($sequence,$middle_thingy,$urlp)=&Apache::lonnet::decode_symb($master_seq[$i]);
$urlp=&Apache::lonnet::clutter($urlp);
$form{'symb'}=$master_seq[$i];
@@ -2033,6 +2077,10 @@
&Apache::lonnet::logthis("Problem");
$resources_printed .= $urlp.':';
&Apache::lonxml::remember_problem_counter();
+ &Apache::lonnet::logthis("Fetching tex for $urlp");
+ my $debug = Dumper(%form);
+ &Apache::lonnet::logthis("Form: $debug");
+
$texversion.=&ssi_with_retries($urlp, $ssi_retry_count, %form);
&Apache::lonnet::logthis("texversion so far: $texversion");
if ($urlp=~/\.page$/) {
@@ -3007,38 +3055,38 @@
"<option text='".&mt('Start new page<br />before selected').
"' variable='FINISHPAGE' />";
}
- # some debugging:
- {
+
+ # If not construction space user can print the components of a page:
+
+ my $page_ispage;
+ my $page_title;
+ if (!$helper->{VARS}->{'construction'}) {
my $varspostdata = $helper->{VARS}->{'postdata'};
my $varsassignment = $helper->{VARS}->{'assignment'};
- my $debugnavmap = Apache::lonnavmaps::navmap->new();
- my @dbgresources = $debugnavmap->retrieveResources($url);
- if(defined($dbgresources[0])) {
- my $debugispage = $dbgresources[0]->is_page();
- my $debugtitle = $dbgresources[0]->title();
- my $resourcesymb = $dbgresources[0]->symb();
+ my $page_navmap = Apache::lonnavmaps::navmap->new();
+ my @page_resources = $page_navmap->retrieveResources($url);
+ if(defined($page_resources[0])) {
+ $page_ispage = $page_resources[0]->is_page();
+ $page_title = $page_resources[0]->title();
+ my $resourcesymb = $page_resources[0]->symb();
my ($pagemap, $pageid, $pageurl) = &Apache::lonnet::decode_symb($symb);
- &Apache::lonnet::logthis("post: $varspostdata ass: $varsassignment is page: $debugispage");
- if ($debugispage) {
+ if ($page_ispage) {
push @{$printChoices},
- [&mt('Selected [_1]Problems[_2] from page [_3]', '<b>', '</b>', '<b><i>'.$debugtitle.'</i></b>'),
+ [&mt('Selected [_1]Problems[_2] from page [_3]', '<b>', '</b>', '<b><i>'.$page_title.'</i></b>'),
'map_problems_in_page',
'CHOOSE_PROBLEMS_PAGE'];
push @{$printChoices},
- [&mt('Selected [_1]Resources[_2] from page [_3]', '<b>', '</b>', '<b><i>'.$debugtitle.'</i></b>'),
+ [&mt('Selected [_1]Resources[_2] from page [_3]', '<b>', '</b>', '<b><i>'.$page_title.'</i></b>'),
'map_resources_in_page',
'CHOOSE_RESOURCES_PAGE'];
}
- &Apache::lonnet::logthis("Pushing problems/resources from folder. $debugtitle");
- &Apache::lonnet::logthis("Map url: $url");
- &Apache::lonnet::logthis("Decoded symb: pagemap $pagemap id: $pageid url: $pageurl");
my $helperFragment = <<HELPERFRAGMENT;
<state name="CHOOSE_PROBLEMS_PAGE" title="Select Problem(s) to print">
<resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1"
closeallpages="1">
<nextstate>PAGESIZE</nextstate>
<filterfunc>return $isProblem;</filterfunc>
- <mapurl>$pagemap</mapurl>
+ <mapurl>$url</mapurl>
<valuefunc>return $symbFilter;</valuefunc>
$start_new_option
</resource>
@@ -3103,8 +3151,9 @@
# If the user has pfo (print for others) allow them to print all
# problems and resources in the entire course, optionally for selected students
+ my $post_data = $helper->{VARS}->{'postdata'};
if ($perm{'pfo'} && !$is_published &&
- ($helper->{VARS}->{'postdata'}=~/\/res\// || $helper->{VARS}->{'postdata'}=~/\/(syllabus|smppg|aboutme|bulletinboard)$/)) {
+ ($post_data=~/\/res\// || $post_data =~/\/(syllabus|smppg|aboutme|bulletinboard)$/)) {
push @{$printChoices}, [&mtn('Selected <b>Problems</b> from <b>entire course</b>'), 'all_problems', 'ALL_PROBLEMS'];
push @{$printChoices}, [&mtn('Selected <b>Resources</b> from <b>entire course</b>'), 'all_resources', 'ALL_RESOURCES'];
@@ -3152,8 +3201,24 @@
ALL_PROBLEMS
if ($helper->{VARS}->{'assignment'}) {
- push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from folder [_3] for [_4]selected people[_5]','<b>','</b>','<b><i>'.$sequenceTitle.'</i></b>','<b>','</b>'), 'problems_for_students', 'CHOOSE_STUDENTS'];
- push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from folder [_3] for [_4]CODEd assignments[_5]','<b>','</b>','<b><i>'.$sequenceTitle.'</i></b>','<b>','</b>'), 'problems_for_anon', 'CHOOSE_ANON1'];
+
+ # If we were looking at a page, allow a selection of problems from the page
+ # either for selected students or for coded assignments.
+
+ if ($page_ispage) {
+ push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from page [_3] for [_4]selected people[_5]',
+ '<b>', '</b>', '<b><i>'.$page_title.'</i></b>', '<b>', '</b>'),
+ 'problems_for_students', 'CHOOSE_STUDENTS'];
+ push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from page [_3] for [_4]CODEd assignments[_5]',
+ '<b>', '</b>', '<b><i>'.$page_title.'</i></b>', '<b>', '</b>'),
+ 'problems_for_anon', 'CHOOSE_ANON1'];
+ }
+ push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from folder [_3] for [_4]selected people[_5]',
+ '<b>','</b>','<b><i>'.$sequenceTitle.'</i></b>','<b>','</b>'),
+ 'problems_for_students', 'CHOOSE_STUDENTS'];
+ push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from folder [_3] for [_4]CODEd assignments[_5]',
+ '<b>','</b>','<b><i>'.$sequenceTitle.'</i></b>','<b>','</b>'),
+ 'problems_for_anon', 'CHOOSE_ANON1'];
}
my $randomly_ordered_warning =
@@ -3202,20 +3267,30 @@
</state>
RESOURCE_SELECTOR
- &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_STUDENTS);
- <state name="CHOOSE_STUDENTS" title="Select Students and Resources">
- <message><b>Select sorting order of printout</b> </message>
- <choices variable='student_sort'>
+# Generate student choosers.
- <choice computer='0'>Sort by section then student</choice>
- <choice computer='1'>Sort by students across sections.</choice>
- </choices>
- <message><br /><hr /><br /> </message>
- <student multichoice='1' variable="STUDENTS" nextstate="SELECT_PROBLEMS" coursepersonnel="1"/>
- </state>
- $resource_selector
-CHOOSE_STUDENTS
+
+# &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_STUDENTS);
+# <state name="CHOOSE_STUDENTS" title="Select Students and Resources">
+# <message><b>Select sorting order of printout</b> </message>
+# <choices variable='student_sort'>
+#
+#
+# <choice computer='0'>Sort by section then student</choice>
+# <choice computer='1'>Sort by students across sections.</choice>
+# </choices>
+# <message><br /><hr /><br /> </message>
+# <student multichoice='1' variable="STUDENTS" nextstate="SELECT_PROBLEMS" coursepersonnel="1"/>
+# </state>
+ &Apache::lonxml::xmlparse($r, 'helper',
+ &generate_student_chooser('CHOOSE_STUDENTS',
+ 'student_sort',
+ 'STUDENTS',
+ 'SELECT_PROBLEMS'));
+ &Apache::lonxml::xmlparse($r, 'helper', $resource_selector);
+# $resource_selector
+# CHOOSE_STUDENTS
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
--foxr1251197839--