[system] / branches / rel-2-1-patches / webwork-modperl / lib / WeBWorK / ContentGenerator.pm Repository:
ViewVC logotype

Diff of /branches/rel-2-1-patches/webwork-modperl/lib/WeBWorK/ContentGenerator.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 3136 Revision 3137
1################################################################################ 1################################################################################
2# WeBWorK Online Homework Delivery System 2# WeBWorK Online Homework Delivery System
3# Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ 3# Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/
4# $CVSHeader: webwork2/lib/WeBWorK/ContentGenerator.pm,v 1.123.2.1 2005/01/07 20:17:20 sh002i Exp $ 4# $CVSHeader: webwork2/lib/WeBWorK/ContentGenerator.pm,v 1.123.2.2 2005/01/28 00:35:29 sh002i Exp $
5# 5#
6# This program is free software; you can redistribute it and/or modify it under 6# This program is free software; you can redistribute it and/or modify it under
7# the terms of either: (a) the GNU General Public License as published by the 7# the terms of either: (a) the GNU General Public License as published by the
8# Free Software Foundation; either version 2, or (at your option) any later 8# Free Software Foundation; either version 2, or (at your option) any later
9# version, or (b) the "Artistic License" which comes with this package. 9# version, or (b) the "Artistic License" which comes with this package.
47use Carp; 47use Carp;
48use CGI::Pretty qw(*ul *li escapeHTML); 48use CGI::Pretty qw(*ul *li escapeHTML);
49use Date::Format; 49use Date::Format;
50use URI::Escape; 50use URI::Escape;
51use WeBWorK::Template qw(template); 51use WeBWorK::Template qw(template);
52use WeBWorK::PG;
52 53
53############################################################################### 54###############################################################################
54 55
55=head1 CONSTRUCTOR 56=head1 CONSTRUCTOR
56 57
292 293
293Must be called before the message() template escape is invoked. 294Must be called before the message() template escape is invoked.
294 295
295=cut 296=cut
296 297
297# FIXME: we should probably 298
298 299
299sub addmessage { 300sub addmessage {
300 my ($self, $message) = @_; 301 my ($self, $message) = @_;
301 $self->{status_message} .= $message; 302 $self->{status_message} .= $message;
302} 303}
485 486
486 # only users with appropriate permissions can report bugs 487 # only users with appropriate permissions can report bugs
487 if ($authz->hasPermissions($user, "report_bugs")) { 488 if ($authz->hasPermissions($user, "report_bugs")) {
488 print CGI::p(CGI::a({style=>"font-size:larger", href=>$ce->{webworkURLs}{bugReporter}}, "Report bugs")),CGI::hr(); 489 print CGI::p(CGI::a({style=>"font-size:larger", href=>$ce->{webworkURLs}{bugReporter}}, "Report bugs")),CGI::hr();
489 } 490 }
490 491 my %displayOptions = (displayMode => $self->{displayMode},
492 showOldAnswers => $self->{will}->{showOldAnswers}
493 );
491 print CGI::start_ul({class=>"LinksMenu"}); 494 print CGI::start_ul({class=>"LinksMenu"});
492 print CGI::li(CGI::span({style=>"font-size:larger"}, 495 print CGI::li(CGI::span({style=>"font-size:larger"},
493 CGI::a({href=>$self->systemLink($sets)}, sp2nbsp("Homework Sets")))); 496 CGI::a({href=>$self->systemLink($sets,
497 params=>{ %displayOptions,}
498 )}, sp2nbsp("Homework Sets")))
499 );
494 500
495 if ($authz->hasPermissions($user, "change_password") or $authz->hasPermissions($user, "change_email_address")) { 501 if ($authz->hasPermissions($user, "change_password") or $authz->hasPermissions($user, "change_email_address")) {
496 print CGI::li(CGI::a({href=>$self->systemLink($options)}, sp2nbsp($options->name))); 502 print CGI::li(CGI::a({href=>$self->systemLink($options,
503 params=>{ %displayOptions,}
504 )
505 }, sp2nbsp($options->name))
506 );
497 } 507 }
498 508
499 print CGI::li(CGI::a({href=>$self->systemLink($grades)}, sp2nbsp($grades->name))); 509 print CGI::li(CGI::a({href=>$self->systemLink($grades,
510 params=>{ %displayOptions,}
511 )}, sp2nbsp($grades->name)));
500 print CGI::li(CGI::a({href=>$self->systemLink($logout)}, sp2nbsp($logout->name))); 512 print CGI::li(CGI::a({href=>$self->systemLink($logout)}, sp2nbsp($logout->name)));
501 513
502 if ($authz->hasPermissions($user, "access_instructor_tools")) { 514 if ($authz->hasPermissions($user, "access_instructor_tools")) {
503 my $ipfx = "${pfx}Instructor::"; 515 my $ipfx = "${pfx}Instructor::";
504 516
532 my $userProgress = $urlpath->newFromModule("${ipfx}StudentProgress", %args, statType => "student", userID => $userID); 544 my $userProgress = $urlpath->newFromModule("${ipfx}StudentProgress", %args, statType => "student", userID => $userID);
533 my $setProgress = $urlpath->newFromModule("${ipfx}StudentProgress", %args, statType => "set", setID => $setID); 545 my $setProgress = $urlpath->newFromModule("${ipfx}StudentProgress", %args, statType => "set", setID => $setID);
534 546
535 547
536 my $fileMgr = $urlpath->newFromModule("${ipfx}FileManager", %args); 548 my $fileMgr = $urlpath->newFromModule("${ipfx}FileManager", %args);
537 my $fileXfer = $urlpath->newFromModule("${ipfx}FileXfer", %args); 549 #my $fileXfer = $urlpath->newFromModule("${ipfx}FileXfer", %args);
538 550
539 print CGI::hr(); 551 print CGI::hr();
540 print CGI::start_li(); 552 print CGI::start_li();
541 print CGI::span({style=>"font-size:larger"}, 553 print CGI::span({style=>"font-size:larger"},
542 CGI::a({href=>$self->systemLink($instr)}, space2nbsp($instr->name)) 554 CGI::a({href=>$self->systemLink($instr,params=>{ %displayOptions,})}, space2nbsp($instr->name))
543 ); 555 );
544 print CGI::start_ul(); 556 print CGI::start_ul();
545 #print CGI::li(CGI::a({href=>$self->systemLink($addUsers)}, sp2nbsp($addUsers->name))) if $authz->hasPermissions($user, "modify_student_data");
546 print CGI::li(CGI::a({href=>$self->systemLink($userList)}, sp2nbsp($userList->name))); 557 print CGI::li(CGI::a({href=>$self->systemLink($userList,params=>{ %displayOptions,})}, sp2nbsp($userList->name)));
547 print CGI::start_li(); 558 print CGI::start_li();
548 print CGI::a({href=>$self->systemLink($setList)}, sp2nbsp($setList->name)); 559 print CGI::a({href=>$self->systemLink($setList,params=>{ %displayOptions,})}, sp2nbsp($setList->name));
549 if (defined $setID and $setID ne "") { 560 if (defined $setID and $setID ne "") {
550 print CGI::start_ul(); 561 print CGI::start_ul();
551 print CGI::start_li(); 562 print CGI::start_li();
552 print CGI::a({href=>$self->systemLink($setDetail)}, $setID); 563 print CGI::a({href=>$self->systemLink($setDetail,params=>{ %displayOptions,})}, $setID);
553 if (defined $problemID and $problemID ne "") { 564 if (defined $problemID and $problemID ne "") {
554 print CGI::ul( 565 print CGI::ul(
555 CGI::li(CGI::a({href=>$self->systemLink($problemEditor)}, $problemID)) 566 CGI::li(CGI::a({href=>$self->systemLink($problemEditor,params=>{ %displayOptions,})}, $problemID))
556 ); 567 );
557 } 568 }
558 print CGI::end_li(); 569 print CGI::end_li();
559 print CGI::end_ul(); 570 print CGI::end_ul();
560 } 571 }
561 print CGI::end_li(); 572 print CGI::end_li();
562 print CGI::li(CGI::a({href=>$self->systemLink($maker)}, sp2nbsp($maker->name))) if $authz->hasPermissions($user, "modify_problem_sets"); 573 print CGI::li(CGI::a({href=>$self->systemLink($maker,params=>{ %displayOptions,})}, sp2nbsp($maker->name))) if $authz->hasPermissions($user, "modify_problem_sets");
563 print CGI::li(CGI::a({href=>$self->systemLink($assigner)}, sp2nbsp($assigner->name))) if $authz->hasPermissions($user, "assign_problem_sets"); 574 print CGI::li(CGI::a({href=>$self->systemLink($assigner,params=>{ %displayOptions,})}, sp2nbsp($assigner->name))) if $authz->hasPermissions($user, "assign_problem_sets");
564 575
565 print CGI::li(CGI::a({href=>$self->systemLink($stats)}, sp2nbsp($stats->name))); 576 print CGI::li(CGI::a({href=>$self->systemLink($stats,params=>{ %displayOptions,})}, sp2nbsp($stats->name)));
566 577
567 ## Added Link for Student Progress 578 ## Added Link for Student Progress
568 print CGI::li(CGI::a({href=>$self->systemLink($progress)}, sp2nbsp($progress->name))); 579 print CGI::li(CGI::a({href=>$self->systemLink($progress,params=>{ %displayOptions,})}, sp2nbsp($progress->name)));
569 print CGI::start_li(); 580 print CGI::start_li();
570 if (defined $userID and $userID ne "") { 581 if (defined $userID and $userID ne "") {
571 print CGI::ul( 582 print CGI::ul(
572 CGI::li(CGI::a({href=>$self->systemLink($userProgress)}, $userID)) 583 CGI::li(CGI::a({href=>$self->systemLink($userProgress,params=>{ %displayOptions,})}, $userID))
573 ); 584 );
574 } 585 }
575 if (defined $setID and $setID ne "") { 586 if (defined $setID and $setID ne "") {
576 print CGI::ul( 587 print CGI::ul(
577 CGI::li(CGI::a({href=>$self->systemLink($setProgress)}, space2nbsp($setID))) 588 CGI::li(CGI::a({href=>$self->systemLink($setProgress,params=>{ %displayOptions,})}, space2nbsp($setID)))
578 ); 589 );
579 } 590 }
580 print CGI::end_li(); 591 print CGI::end_li();
581 592
582 print CGI::li(CGI::a({href=>$self->systemLink($scoring)}, sp2nbsp($scoring->name))) if $authz->hasPermissions($user, "score_sets"); 593 print CGI::li(CGI::a({href=>$self->systemLink($scoring,params=>{ %displayOptions,})}, sp2nbsp($scoring->name))) if $authz->hasPermissions($user, "score_sets");
583 print CGI::li(CGI::a({href=>$self->systemLink($mail)}, sp2nbsp($mail->name))) if $authz->hasPermissions($user, "send_mail"); 594 print CGI::li(CGI::a({href=>$self->systemLink($mail,params=>{ %displayOptions,})}, sp2nbsp($mail->name))) if $authz->hasPermissions($user, "send_mail");
584 print CGI::li(CGI::a({href=>$self->systemLink($fileMgr)}, sp2nbsp($fileMgr->name))); 595 print CGI::li(CGI::a({href=>$self->systemLink($fileMgr,params=>{ %displayOptions,})}, sp2nbsp($fileMgr->name)));
585 print CGI::li(CGI::a({href=>$self->systemLink($fileXfer)}, sp2nbsp($fileXfer->name))); 596 #print CGI::li(CGI::a({href=>$self->systemLink($fileXfer)}, sp2nbsp($fileXfer->name)));
586 print CGI::li( $self->helpMacro('instructor_links')); 597 print CGI::li( $self->helpMacro('instructor_links'));
587 print CGI::end_ul(); 598 print CGI::end_ul();
588 599
589 } 600 }
590 601
662 673
663#sub nav { } 674#sub nav { }
664 675
665=item options() 676=item options()
666 677
667Not defined in this package.
668 678
669Print an auxiliary options form, related to the content displayed in the 679Print an auxiliary options form, related to the content displayed in the
670C<body>. 680C<body>.
681
682=cut
683
684sub options {
685 my ($self) = @_;
686
687 return "" if $self->{invalidProblem};
688 my $sourceFilePathfield = '';
689 if($self->r->param("sourceFilePath")) {
690 $sourceFilePathfield = CGI::hidden(-name => "sourceFilePath",
691 -value => $self->r->param("sourceFilePath"));
692 }
693
694 my $r = $self->{r};
695 my $ce = $self->{ce};
696 # insure that certain defaults are defined
697 $self->{must} = {} unless defined $self->{must};
698 $self->{can} = {} unless defined $self->{can};
699 $self->{will} = {} unless defined $self->{will};
700
701 # displayMode
702 my $displayMode = $r->param("displayMode") || $ce->{pg}->{options}->{displayMode};
703 $self->{displayMode} = $displayMode unless defined $self->{displayMode};
704
705 # showOldAnswers
706 my $want_to_showOldAnswers = defined($r->param("showOldAnswers")) ?
707 $r->param("showOldAnswers") : $ce->{pg}->{options}->{showOldAnswers};
708 $self->{can}->{showOldAnswers} = 1;
709 $self->{will}->{showOldAnswers} = $self->{can}->{showOldAnswers} && $want_to_showOldAnswers;
710
711 return join("",
712 CGI::start_form("POST", $self->{r}->uri),
713 $self->hidden_authen_fields,
714 $sourceFilePathfield,
715 CGI::hr(),
716 CGI::start_div({class=>"viewOptions"}),
717 $self->viewOptions(),
718 CGI::end_div(),
719 CGI::end_form()
720 );
721}
722
723sub viewOptions {
724 my ($self) = @_;
725 my $ce = $self->r->ce;
726
727 # don't show options if we don't have anything to show
728 return if $self->{invalidSet} or $self->{invalidProblem};
729 #return unless $self->{isOpen};
730
731 my $displayMode = $self->{displayMode};
732 my %must = %{ $self->{must} };
733 my %can = %{ $self->{can} };
734 my %will = %{ $self->{will} };
735
736 my $optionLine;
737 $can{showOldAnswers} and $optionLine .= join "",
738 "Show&nbsp;saved&nbsp;answers?".CGI::br(),
739 CGI::radio_group(
740 -name => "showOldAnswers",
741 -values => [1,0],
742 -default => $will{showOldAnswers},
743 -labels => {
744 0 => 'No',
745 1 => 'Yes',
746 },
747 ), .CGI::br();
748
749 $optionLine and $optionLine .= join "", CGI::br();
750
751 my %display_modes = %{WeBWorK::PG::DISPLAY_MODES()};
752 my @active_modes = grep { exists $display_modes{$_} }
753 @{$ce->{pg}->{displayModes}};
754 my $modeLine = (scalar(@active_modes) > 1) ?
755 "View&nbsp;equations&nbsp;as:&nbsp;&nbsp;&nbsp;&nbsp;".CGI::br().
756 CGI::radio_group(
757 -name => "displayMode",
758 -values => \@active_modes,
759 -default => $displayMode,
760 -linebreak=>'true',
761 -labels => {
762 plainText => "plain",
763 formattedText => "formatted",
764 images => "images",
765 jsMath => "jsMath",
766 asciimath => "asciimath",
767 },
768 ). CGI::br().CGI::hr() : '';
769
770 return CGI::div({-style=>"border: thin groove; padding: 1ex; margin: 2ex align: left"},
771 $modeLine,
772 $optionLine,
773 CGI::submit(-name=>"redisplay", -label=>"Apply Options"),
774 );
775}
671 776
672=item path($args) 777=item path($args)
673 778
674Defined in this package. 779Defined in this package.
675 780
776sub message { 881sub message {
777 my ($self) = @_; 882 my ($self) = @_;
778 883
779 print "\n<!-- BEGIN " . __PACKAGE__ . "::message -->\n"; 884 print "\n<!-- BEGIN " . __PACKAGE__ . "::message -->\n";
780 print $self->{status_message} if exists $self->{status_message}; 885 print $self->{status_message} if exists $self->{status_message};
886
781 print "<!-- END " . __PACKAGE__ . "::message -->\n"; 887 print "<!-- END " . __PACKAGE__ . "::message -->\n";
782 888
783 return ""; 889 return "";
784} 890}
785 891
837 943
838sub help { 944sub help {
839 my $self = shift; 945 my $self = shift;
840 my $args = shift; 946 my $args = shift;
841 my $name = $args->{name}; 947 my $name = $args->{name};
842 948
843 # old naming scheme 949 # old naming scheme
844 #$name = lc($self->r->urlpath->name) unless defined($name); 950 #$name = lc($self->r->urlpath->name) unless defined($name);
845 #$name =~ s/\s/_/g; 951 #$name =~ s/\s/_/g;
846 952
847 $name = $self->r->urlpath->module unless defined($name); 953 $name = $self->r->urlpath->module unless defined($name);
848 $name =~ s/WeBWorK::ContentGenerator:://; 954 $name =~ s/WeBWorK::ContentGenerator:://;
849 $name =~ s/://g; 955 $name =~ s/://g;
850 956
851 $self->helpMacro($name); 957 $self->helpMacro($name);
958}
959
960=item url($args)
961
962Defined in this package.
963
964Returns the specified URL from either %webworkURLs or %courseURLs in the course
965environment. $args is a reference to a hash containing the following fields:
966
967 type => type of URL: webwork|course
968 name => name of URL (key in URL hash)
969
970=cut
971
972sub url {
973 my ($self, $args) = @_;
974 my $ce = $self->r->ce;
975 my $type = $args->{type};
976 my $name = $args->{name};
977
978 if ($type eq "webwork") {
979 return $ce->{webworkURLs}->{$name};
980 } elsif ($type eq "course") {
981 return $ce->{courseURLs}->{$name};
982 } else {
983 warn __PACKAGE__."::url: unrecognized type '$type'.\n";
984 }
852} 985}
853 986
854=back 987=back
855 988
856=cut 989=cut
1262 my ($self) = @_; 1395 my ($self) = @_;
1263 1396
1264 return $self->url_args("user", "effectiveUser", "key"); 1397 return $self->url_args("user", "effectiveUser", "key");
1265} 1398}
1266 1399
1400=item url_display_args()
1401
1402Use url_args to return a URL query string for request fields used in
1403authentication.
1404
1405=cut
1406
1407sub url_display_args {
1408 my ($self) = @_;
1409
1410 return $self->url_args("displayMode", "showOldAnswer");
1411}
1412
1267=item print_form_data($begin, $middle, $end, $omit) 1413=item print_form_data($begin, $middle, $end, $omit)
1268 1414
1269Return a string containing every request field not matched by the quoted reguar 1415Return a string containing every request field not matched by the quoted reguar
1270expression $omit, placing $begin before each field name, $middle between each 1416expression $omit, placing $begin before each field name, $middle between each
1271field name and its value, and $end after each value. Values are taken from the 1417field name and its value, and $end after each value. Values are taken from the
1377 } 1523 }
1378 } elsif (defined $r->param($name)) { 1524 } elsif (defined $r->param($name)) {
1379 @values = $r->param($name); 1525 @values = $r->param($name);
1380 } 1526 }
1381 #FIXME -- evntually we'd like to catch where this happens 1527 #FIXME -- evntually we'd like to catch where this happens
1382 croak "internal error -- user has been multiply defined!" if $name eq 'user' and @values >1; 1528 if ($name eq 'user' and @values >1 ) {
1529 warn "internal error -- user has been multiply defined! You may need to logout and log back in to correct this.";
1530 my $user = $r->param("user");
1531 $r->param(user => $user);
1532 @values = ($user);
1533 warn "requesting page is ", $r->headers_in->{'Referer'};
1534 warn "Parameters are ", join("|",$r->param());
1535
1536 }
1537
1383 if (@values) { 1538 if (@values) {
1384 if ($first) { 1539 if ($first) {
1385 $url .= "?"; 1540 $url .= "?";
1386 $first = 0; 1541 $first = 0;
1387 } else { 1542 } else {
1485 my ($self, $warnings) = @_; 1640 my ($self, $warnings) = @_;
1486 my $r = $self->{r}; 1641 my $r = $self->{r};
1487 1642
1488 my @warnings = split m/\n+/, $warnings; 1643 my @warnings = split m/\n+/, $warnings;
1489 foreach my $warning (@warnings) { 1644 foreach my $warning (@warnings) {
1490 $warning = escapeHTML($warning); 1645 #$warning = escapeHTML($warning); # this would prevent using tables in output from answer evaluators
1491 $warning = CGI::li(CGI::code($warning)); 1646 $warning = CGI::li(CGI::code($warning));
1492 } 1647 }
1493 $warnings = join("", @warnings); 1648 $warnings = join("", @warnings);
1494 1649
1495 my $time = time2str("%a %b %d %H:%M:%S %Y", time); 1650 my $time = time2str("%a %b %d %H:%M:%S %Y", time);

Legend:
Removed from v.3136  
changed lines
  Added in v.3137

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9