| … | |
… | |
| 16 | use base qw(WeBWorK::ContentGenerator); |
16 | use base qw(WeBWorK::ContentGenerator); |
| 17 | use Apache::Constants qw(:common); |
17 | use Apache::Constants qw(:common); |
| 18 | use CGI qw(); |
18 | use CGI qw(); |
| 19 | use WeBWorK::ContentGenerator; |
19 | use WeBWorK::ContentGenerator; |
| 20 | use WeBWorK::DB::WW; |
20 | use WeBWorK::DB::WW; |
|
|
21 | use WeBWorK::DB::Auth; |
| 21 | use WeBWorK::Utils qw(readFile formatDateTime); |
22 | use WeBWorK::Utils qw(readFile formatDateTime); |
| 22 | |
23 | |
| 23 | sub initialize { |
24 | sub initialize { |
| 24 | my $self = shift; |
25 | my $self = shift; |
| 25 | my $courseEnvironment = $self->{courseEnvironment}; |
26 | my $courseEnvironment = $self->{courseEnvironment}; |
| 26 | |
27 | |
| 27 | # Open a database connection that we can use for the rest of |
28 | # Open a database connection that we can use for the rest of |
| 28 | # the content generation. |
29 | # the content generation. |
| 29 | |
30 | |
| 30 | my $wwdb = new WeBWorK::DB::WW $courseEnvironment; |
31 | $self->{wwdb} = new WeBWorK::DB::WW $courseEnvironment; |
| 31 | $self->{wwdb} = $wwdb; |
32 | $self->{authdb} = new WeBWorK::DB::Auth $courseEnvironment; |
| 32 | } |
33 | } |
| 33 | |
34 | |
| 34 | sub path { |
35 | sub path { |
| 35 | my ($self, $args) = @_; |
36 | my ($self, $args) = @_; |
| 36 | |
37 | |
| … | |
… | |
| 56 | my $courseEnvironment = $self->{courseEnvironment}; |
57 | my $courseEnvironment = $self->{courseEnvironment}; |
| 57 | my $user = $r->param("user"); |
58 | my $user = $r->param("user"); |
| 58 | my $effectiveUser = $r->param("effectiveUser"); |
59 | my $effectiveUser = $r->param("effectiveUser"); |
| 59 | my $sort = $r->param("sort") || "status"; |
60 | my $sort = $r->param("sort") || "status"; |
| 60 | my $wwdb = $self->{wwdb}; |
61 | my $wwdb = $self->{wwdb}; |
|
|
62 | my $authdb = $self->{authdb}; |
|
|
63 | my $permissionLevel = $authdb->getPermissions($user); |
| 61 | |
64 | |
| 62 | if (defined $courseEnvironment->{courseFiles}->{motd} |
65 | if (defined $courseEnvironment->{courseFiles}->{motd} |
| 63 | and $courseEnvironment->{courseFiles}->{motd}) { |
66 | and $courseEnvironment->{courseFiles}->{motd}) { |
| 64 | my $motd = eval { readFile($courseEnvironment->{courseFiles}->{motd}) }; |
67 | my $motd = eval { readFile($courseEnvironment->{courseFiles}->{motd}) }; |
| 65 | $@ or print $motd; |
68 | $@ or print $motd; |
| 66 | } |
69 | } |
| 67 | |
70 | |
| 68 | $sort = "status" unless $sort eq "status" or $sort eq "name"; |
71 | $sort = "status" unless $sort eq "status" or $sort eq "name"; |
| 69 | my $baseURL = $r->uri . "?" . $self->url_authen_args(); |
72 | my $baseURL = $r->uri . "?" . $self->url_authen_args(); |
| 70 | my $nameHeader = ($sort eq "name") ? "Name" : CGI::a({-href=>"$baseURL&sort=name"}, "Name"); |
73 | my $nameHeader = ($sort eq "name") ? CGI::u("Name") : CGI::a({-href=>"$baseURL&sort=name"}, "Name"); |
| 71 | my $statusHeader = ($sort eq "status") ? "Status" : CGI::a({-href=>"$baseURL&sort=status"}, "Status"); |
74 | my $statusHeader = ($sort eq "status") ? CGI::u("Status") : CGI::a({-href=>"$baseURL&sort=status"}, "Status"); |
| 72 | |
75 | |
| 73 | print CGI::startform(-method=>"POST", -action=>$r->uri."hardcopy/"); |
76 | print CGI::startform(-method=>"POST", -action=>$r->uri."hardcopy/"); |
| 74 | print $self->hidden_authen_fields; |
77 | print $self->hidden_authen_fields; |
| 75 | print CGI::start_table(); |
78 | print CGI::start_table(); |
| 76 | print CGI::Tr( |
79 | print CGI::Tr( |
| 77 | CGI::th("Sel."), |
80 | CGI::th("Sel."), |
| 78 | CGI::th($nameHeader), |
81 | CGI::th($nameHeader), |
| 79 | CGI::th($statusHeader), |
82 | CGI::th($statusHeader), |
| 80 | CGI::th("Hardcopy"), |
83 | #CGI::th("Hardcopy"), |
| 81 | ); |
84 | ); |
| 82 | |
85 | |
| 83 | my @sets; |
86 | my @sets; |
| 84 | push @sets, $wwdb->getSet($effectiveUser, $_) foreach ($wwdb->getSets($effectiveUser)); |
87 | push @sets, $wwdb->getSet($effectiveUser, $_) foreach ($wwdb->getSets($effectiveUser)); |
| 85 | @sets = sort byname @sets if $sort eq "name"; |
88 | @sets = sort byname @sets if $sort eq "name"; |
| 86 | @sets = sort byduedate @sets if $sort eq "status"; |
89 | @sets = sort byduedate @sets if $sort eq "status"; |
| 87 | foreach my $set (@sets) { |
90 | foreach my $set (@sets) { |
| 88 | print $self->setListRow($set); |
91 | print $self->setListRow($set, ($permissionLevel > 0)); |
| 89 | } |
92 | } |
| 90 | |
93 | |
| 91 | print CGI::end_table(); |
94 | print CGI::end_table(); |
|
|
95 | my $pl = ($permissionLevel > 0 ? "s" : ""); |
| 92 | print CGI::p(CGI::submit("hardcopy", "Download Harcopy for Selected Sets")); |
96 | print CGI::p(CGI::submit("hardcopy", "Download Harcopy for Selected Set$pl")); |
| 93 | print CGI::endform(); |
97 | print CGI::endform(); |
| 94 | |
98 | |
| 95 | # feedback form |
99 | # feedback form |
| 96 | my $ce = $self->{courseEnvironment}; |
100 | my $ce = $self->{courseEnvironment}; |
| 97 | my $root = $ce->{webworkURLs}->{root}; |
101 | my $root = $ce->{webworkURLs}->{root}; |
| … | |
… | |
| 107 | CGI::endform(); |
111 | CGI::endform(); |
| 108 | |
112 | |
| 109 | return ""; |
113 | return ""; |
| 110 | } |
114 | } |
| 111 | |
115 | |
| 112 | sub setListRow($$) { |
116 | sub setListRow($$$) { |
| 113 | my $self = shift; |
117 | my ($self, $set, $multiSet) = @_; |
| 114 | my $set = shift; |
|
|
| 115 | |
118 | |
| 116 | my $name = $set->id; |
119 | my $name = $set->id; |
| 117 | |
120 | |
| 118 | my $interactiveURL = "$name/?" . $self->url_authen_args; |
121 | my $interactiveURL = "$name/?" . $self->url_authen_args; |
| 119 | my $hardcopyURL = "hardcopy/$name/?" . $self->url_authen_args; |
122 | #my $hardcopyURL = "hardcopy/$name/?" . $self->url_authen_args; |
| 120 | |
123 | |
| 121 | my $openDate = formatDateTime($set->open_date); |
124 | my $openDate = formatDateTime($set->open_date); |
| 122 | my $dueDate = formatDateTime($set->due_date); |
125 | my $dueDate = formatDateTime($set->due_date); |
| 123 | my $answerDate = formatDateTime($set->answer_date); |
126 | my $answerDate = formatDateTime($set->answer_date); |
| 124 | |
127 | |
| 125 | my $checkbox = CGI::checkbox(-name=>"set", -value=>$set->id, -label=>""); |
128 | #my $checkbox = CGI::checkbox(-name=>"hcSet", -value=>$set->id, -label=>""); |
|
|
129 | |
|
|
130 | my $control = ""; |
|
|
131 | if ($multiSet) { |
|
|
132 | $control = CGI::checkbox( |
|
|
133 | -name=>"hcSet", |
|
|
134 | -value=>$name, |
|
|
135 | -label=>"", |
|
|
136 | ); |
|
|
137 | } else { |
|
|
138 | $control = CGI::radio_group( |
|
|
139 | -name=>"hcSet", |
|
|
140 | -values=>[$name], |
|
|
141 | -default=>"-", |
|
|
142 | -labels=>{$name => ""}, |
|
|
143 | ); |
|
|
144 | } |
|
|
145 | |
| 126 | my $interactive = CGI::a({-href=>$interactiveURL}, $name); |
146 | my $interactive = CGI::a({-href=>$interactiveURL}, $name); |
| 127 | my $hardcopy = CGI::a({-href=>$hardcopyURL}, "download"); |
147 | #my $hardcopy = CGI::a({-href=>$hardcopyURL}, "download"); |
| 128 | |
148 | |
| 129 | my $status; |
149 | my $status; |
| 130 | if (time < $set->open_date) { |
150 | if (time < $set->open_date) { |
| 131 | $status = "opens at $openDate"; |
151 | $status = "opens at $openDate"; |
| 132 | $checkbox = ""; |
152 | $control = ""; |
| 133 | $interactive = $name; |
153 | $interactive = $name; |
| 134 | $hardcopy = ""; |
154 | #$hardcopy = ""; |
| 135 | } elsif (time < $set->due_date) { |
155 | } elsif (time < $set->due_date) { |
| 136 | $status = "open, due at $dueDate"; |
156 | $status = "open, due at $dueDate"; |
| 137 | } elsif (time < $set->answer_date) { |
157 | } elsif (time < $set->answer_date) { |
| 138 | $status = "closed, answers at $answerDate"; |
158 | $status = "closed, answers at $answerDate"; |
| 139 | } else { |
159 | } else { |
| 140 | $status = "closed, answers available"; |
160 | $status = "closed, answers available"; |
| 141 | } |
161 | } |
| 142 | |
162 | |
| 143 | return CGI::Tr(CGI::td([ |
163 | return CGI::Tr(CGI::td([ |
| 144 | $checkbox, |
164 | $control, |
| 145 | $interactive, |
165 | $interactive, |
| 146 | $status, |
166 | $status, |
| 147 | $hardcopy, |
167 | #$hardcopy, |
| 148 | ])); |
168 | ])); |
| 149 | } |
169 | } |
| 150 | |
170 | |
| 151 | sub byname { $a->id cmp $b->id; } |
171 | sub byname { $a->id cmp $b->id; } |
| 152 | sub byduedate { $a->due_date <=> $b->due_date; } |
172 | sub byduedate { $a->due_date <=> $b->due_date; } |