[system] / trunk / webwork2 / lib / WeBWorK / ContentGenerator / ProblemSets.pm Repository:
ViewVC logotype

Annotation of /trunk/webwork2/lib/WeBWorK/ContentGenerator/ProblemSets.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 809 - (view) (download) (as text)

1 : sh002i 455 ################################################################################
2 : sh002i 494 # WeBWorK mod_perl (c) 2000-2002 WeBWorK Project
3 : sh002i 455 # $Id$
4 :     ################################################################################
5 :    
6 : malsyned 353 package WeBWorK::ContentGenerator::ProblemSets;
7 :    
8 : sh002i 455 =head1 NAME
9 :    
10 :     WeBWorK::ContentGenerator::ProblemSets - Display a list of built problem sets.
11 :    
12 :     =cut
13 :    
14 : malsyned 441 use strict;
15 :     use warnings;
16 : sh002i 455 use base qw(WeBWorK::ContentGenerator);
17 : sh002i 449 use Apache::Constants qw(:common);
18 :     use CGI qw();
19 : malsyned 353 use WeBWorK::ContentGenerator;
20 : malsyned 441 use WeBWorK::DB::WW;
21 : sh002i 737 use WeBWorK::DB::Auth;
22 : sh002i 701 use WeBWorK::Utils qw(readFile formatDateTime);
23 : malsyned 353
24 : malsyned 441 sub initialize {
25 :     my $self = shift;
26 : sh002i 809 my $courseEnvironment = $self->{ce};
27 : malsyned 441
28 :     # Open a database connection that we can use for the rest of
29 :     # the content generation.
30 :    
31 : sh002i 737 $self->{wwdb} = new WeBWorK::DB::WW $courseEnvironment;
32 :     $self->{authdb} = new WeBWorK::DB::Auth $courseEnvironment;
33 : malsyned 441 }
34 :    
35 : sh002i 469 sub path {
36 :     my ($self, $args) = @_;
37 :    
38 : sh002i 809 my $ce = $self->{ce};
39 : sh002i 469 my $root = $ce->{webworkURLs}->{root};
40 :     my $courseName = $ce->{courseName};
41 :     return $self->pathMacro($args,
42 :     "Home" => "$root",
43 :     $courseName => "",
44 :     );
45 :     }
46 :    
47 : malsyned 353 sub title {
48 :     my $self = shift;
49 : sh002i 809 my $courseEnvironment = $self->{ce};
50 : sh002i 469
51 :     return $courseEnvironment->{courseName};
52 : malsyned 353 }
53 :    
54 :     sub body {
55 :     my $self = shift;
56 :     my $r = $self->{r};
57 : sh002i 809 my $courseEnvironment = $self->{ce};
58 : sh002i 683 my $user = $r->param("user");
59 : malsyned 720 my $effectiveUser = $r->param("effectiveUser");
60 : sh002i 692 my $sort = $r->param("sort") || "status";
61 : malsyned 441 my $wwdb = $self->{wwdb};
62 : sh002i 737 my $authdb = $self->{authdb};
63 :     my $permissionLevel = $authdb->getPermissions($user);
64 : malsyned 353
65 : sh002i 721 if (defined $courseEnvironment->{courseFiles}->{motd}
66 :     and $courseEnvironment->{courseFiles}->{motd}) {
67 :     my $motd = eval { readFile($courseEnvironment->{courseFiles}->{motd}) };
68 :     $@ or print $motd;
69 :     }
70 : sh002i 701
71 : sh002i 683 $sort = "status" unless $sort eq "status" or $sort eq "name";
72 :     my $baseURL = $r->uri . "?" . $self->url_authen_args();
73 : sh002i 737 my $nameHeader = ($sort eq "name") ? CGI::u("Name") : CGI::a({-href=>"$baseURL&sort=name"}, "Name");
74 :     my $statusHeader = ($sort eq "status") ? CGI::u("Status") : CGI::a({-href=>"$baseURL&sort=status"}, "Status");
75 : sh002i 683
76 : sh002i 640 print CGI::startform(-method=>"POST", -action=>$r->uri."hardcopy/");
77 :     print $self->hidden_authen_fields;
78 : sh002i 449 print CGI::start_table();
79 :     print CGI::Tr(
80 : sh002i 469 CGI::th("Sel."),
81 : sh002i 683 CGI::th($nameHeader),
82 :     CGI::th($statusHeader),
83 : sh002i 737 #CGI::th("Hardcopy"),
84 : sh002i 449 );
85 :    
86 : sh002i 469 my @sets;
87 : malsyned 720 push @sets, $wwdb->getSet($effectiveUser, $_) foreach ($wwdb->getSets($effectiveUser));
88 : sh002i 683 @sets = sort byname @sets if $sort eq "name";
89 :     @sets = sort byduedate @sets if $sort eq "status";
90 :     foreach my $set (@sets) {
91 : sh002i 739 print $self->setListRow($set, ($permissionLevel > 0),
92 :     ($permissionLevel > 0));
93 : sh002i 449 }
94 : malsyned 441
95 : sh002i 449 print CGI::end_table();
96 : sh002i 737 my $pl = ($permissionLevel > 0 ? "s" : "");
97 :     print CGI::p(CGI::submit("hardcopy", "Download Harcopy for Selected Set$pl"));
98 : sh002i 449 print CGI::endform();
99 : malsyned 441
100 : sh002i 669 # feedback form
101 : sh002i 809 my $ce = $self->{ce};
102 : sh002i 669 my $root = $ce->{webworkURLs}->{root};
103 :     my $courseName = $ce->{courseName};
104 :     my $feedbackURL = "$root/$courseName/feedback/";
105 :     print
106 :     CGI::startform("POST", $feedbackURL),
107 :     $self->hidden_authen_fields,
108 :     CGI::hidden("module", __PACKAGE__),
109 :     CGI::p({-align=>"right"},
110 :     CGI::submit(-name=>"feedbackForm", -label=>"Send Feedback")
111 :     ),
112 :     CGI::endform();
113 :    
114 : sh002i 449 return "";
115 : malsyned 353 }
116 :    
117 : sh002i 737 sub setListRow($$$) {
118 : sh002i 739 my ($self, $set, $multiSet, $preOpenSets) = @_;
119 : sh002i 449
120 :     my $name = $set->id;
121 :    
122 : sh002i 555 my $interactiveURL = "$name/?" . $self->url_authen_args;
123 : sh002i 737 #my $hardcopyURL = "hardcopy/$name/?" . $self->url_authen_args;
124 : sh002i 469
125 : sh002i 449 my $openDate = formatDateTime($set->open_date);
126 :     my $dueDate = formatDateTime($set->due_date);
127 :     my $answerDate = formatDateTime($set->answer_date);
128 :    
129 : sh002i 737 #my $checkbox = CGI::checkbox(-name=>"hcSet", -value=>$set->id, -label=>"");
130 :    
131 :     my $control = "";
132 :     if ($multiSet) {
133 :     $control = CGI::checkbox(
134 :     -name=>"hcSet",
135 :     -value=>$name,
136 :     -label=>"",
137 :     );
138 :     } else {
139 :     $control = CGI::radio_group(
140 :     -name=>"hcSet",
141 :     -values=>[$name],
142 :     -default=>"-",
143 :     -labels=>{$name => ""},
144 :     );
145 :     }
146 :    
147 : sh002i 469 my $interactive = CGI::a({-href=>$interactiveURL}, $name);
148 : sh002i 737 #my $hardcopy = CGI::a({-href=>$hardcopyURL}, "download");
149 : sh002i 449
150 :     my $status;
151 :     if (time < $set->open_date) {
152 :     $status = "opens at $openDate";
153 : sh002i 739 $control = "" unless $preOpenSets;
154 :     $interactive = $name unless $preOpenSets;
155 : sh002i 737 #$hardcopy = "";
156 : sh002i 449 } elsif (time < $set->due_date) {
157 :     $status = "open, due at $dueDate";
158 :     } elsif (time < $set->answer_date) {
159 :     $status = "closed, answers at $answerDate";
160 :     } else {
161 :     $status = "closed, answers available";
162 :     }
163 :    
164 :     return CGI::Tr(CGI::td([
165 : sh002i 737 $control,
166 : sh002i 469 $interactive,
167 : sh002i 449 $status,
168 : sh002i 737 #$hardcopy,
169 : sh002i 449 ]));
170 :     }
171 :    
172 : sh002i 683 sub byname { $a->id cmp $b->id; }
173 :     sub byduedate { $a->due_date <=> $b->due_date; }
174 :    
175 : malsyned 353 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9