Parent Directory
|
Revision Log
Additionaly tweaks to fail gracefully
1 ################################################################################ 2 # WeBWorK Online Homework Delivery System 3 # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ 4 # $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/Index.pm,v 1.36 2004/05/24 01:27:48 mschmitt Exp $ 5 # 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 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. 10 # 11 # This program is distributed in the hope that it will be useful, but WITHOUT 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 # FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the 14 # Artistic License for more details. 15 ################################################################################ 16 17 package WeBWorK::ContentGenerator::Instructor::Index; 18 use base qw(WeBWorK::ContentGenerator::Instructor); 19 20 =head1 NAME 21 22 WeBWorK::ContentGenerator::Instructor::Index - Menu interface to the Instructor 23 pages 24 25 =cut 26 27 use strict; 28 use warnings; 29 use Apache::Constants qw(:response); 30 use CGI qw(); 31 use WeBWorK::HTML::ScrollingRecordList qw/scrollingRecordList/; 32 #use WeBWorK::Utils::FilterRecords qw/getFiltersForClass/; 33 34 use constant E_NO_USERS => "Please do not select any users."; 35 use constant E_NO_SETS => "Please do not select any sets."; 36 use constant E_MAX_ONE_USER => "Please select at most one user."; 37 use constant E_MAX_ONE_SET => "Please select at most one set."; 38 use constant E_ONE_USER => "Please select exactly one user."; 39 use constant E_ONE_SET => "Please select exactly one set."; 40 use constant E_MIN_ONE_USER => "Please select at least one user."; 41 use constant E_MIN_ONE_SET => "Please select at least one set."; 42 43 sub pre_header_initialize { 44 my ($self) = @_; 45 my $r = $self->r; 46 my $ce = $r->ce; 47 my $db = $r->db; 48 my $authz = $r->authz; 49 my $urlpath = $r->urlpath; 50 51 unless ($authz->hasPermissions($r->param("user"), "modify_student_data")) { 52 $self->addmessage("You are not authorized to modify student data"); 53 return; 54 } 55 56 my $courseID = $urlpath->arg("courseID"); 57 my $userID = $r->param("user"); 58 my $eUserID = $r->param("effectiveUser"); 59 60 my @selectedUserIDs = $r->param("selected_users"); 61 my @selectedSetIDs = $r->param("selected_sets"); 62 63 my $nusers = @selectedUserIDs; 64 my $nsets = @selectedSetIDs; 65 66 my $firstUserID = $nusers ? $selectedUserIDs[0] : ""; 67 my $firstSetID = $nsets ? $selectedSetIDs[0] : ""; 68 69 # these will be used to construct a new URL 70 my $module; 71 my %args = ( courseID => $courseID ); 72 my %params; 73 74 my $pfx = "WeBWorK::ContentGenerator"; 75 my $ipfx = "WeBWorK::ContentGenerator::Instructor"; 76 77 my @error; 78 79 # depending on which button was pushed, fill values in for URL construction 80 81 defined param $r "sets_assigned_to_user" and do { 82 if ($nusers == 1) { 83 $module = "${ipfx}::SetsAssignedToUser"; 84 $args{userID} = $firstUserID; 85 } else { 86 push @error, E_ONE_USER; 87 } 88 }; 89 90 defined param $r "users_assigned_to_set" and do { 91 if ($nsets == 1) { 92 $module = "${ipfx}::UsersAssignedToSet"; 93 $args{setID} = $firstSetID; 94 } else { 95 push @error, E_ONE_SET; 96 } 97 }; 98 99 defined param $r "edit_users" and do { 100 if ($nusers >= 1) { 101 $module = "${ipfx}::UserList"; 102 $params{visible_users} = \@selectedUserIDs; 103 $params{editMode} = 1; 104 } else { 105 push @error, E_MIN_ONE_USER; 106 } 107 }; 108 109 defined param $r "edit_sets" and do { 110 if ($nsets == 1) { 111 $module = "${ipfx}::ProblemSetEditor"; 112 $args{setID} = $firstSetID; 113 } else { 114 push @error, E_ONE_SET; 115 116 } 117 }; 118 119 defined param $r "user_stats" and do { 120 if ($nusers == 1) { 121 $module = "${ipfx}::Stats"; 122 $args{statType} = "student"; # FIXME: fix URLPath -- i shouldn't have to type this! 123 $args{userID} = $firstUserID; 124 } else { 125 push @error, E_ONE_USER; 126 } 127 }; 128 129 defined param $r "set_stats" and do { 130 if ($nsets == 1) { 131 $module = "${ipfx}::Stats"; 132 $args{statType} = "set"; # FIXME: fix URLPath -- i shouldn't have to type this! 133 $args{setID} = $firstSetID; 134 } else { 135 push @error, E_ONE_SET; 136 } 137 }; 138 139 defined param $r "user_options" and do { 140 if ($nusers == 1) { 141 $module = "${pfx}::Options"; 142 $params{effectiveUser} = $firstUserID; 143 } else { 144 push @error, E_ONE_USER; 145 } 146 }; 147 148 defined param $r "score_sets" and do { 149 if ($nsets >= 1) { 150 $module = "${ipfx}::Scoring"; 151 $params{selectedSet} = \@selectedSetIDs; 152 $params{scoreSelected} = 1; 153 } else { 154 push @error, E_MIN_ONE_SET; 155 } 156 }; 157 158 defined param $r "act_as_user" and do { 159 if ($nusers == 1 and $nsets <= 1) { 160 if ($nsets) { 161 $module = "${pfx}::ProblemSet"; 162 $args{setID} = $firstSetID; 163 } else { 164 $module = "${pfx}::ProblemSets"; 165 } 166 $params{effectiveUser} = $firstUserID; 167 } else { 168 push @error, E_ONE_USER unless $nusers == 1; 169 push @error, E_MAX_ONE_SET unless $nsets <= 1; 170 } 171 }; 172 173 defined param $r "edit_set_for_user" and do { 174 if ($nusers == 1 and $nsets == 1) { 175 $module = "${ipfx}::ProblemSetEditor"; 176 $args{setID} = $firstSetID; 177 $params{editForUser} = $firstUserID; 178 } else { 179 push @error, E_ONE_USER unless $nusers == 1; 180 push @error, E_ONE_SET unless $nsets == 1; 181 182 } 183 }; 184 185 # handle errors, redirect to target page 186 187 if (@error) { 188 $self->addmessage(CGI::div({class=>"ResultsWithError"}, 189 CGI::p("Your request could not be fulfilled. Please correct the following errors and try again:"), 190 CGI::ul(CGI::li(\@error)), 191 )); 192 193 } elsif ($module) { 194 my $page = $urlpath->newFromModule($module, %args); 195 my $url = $self->systemLink($page, params => \%params); 196 $self->reply_with_redirect($url); 197 } 198 } 199 200 sub body { 201 my ($self) = @_; 202 my $r = $self->r; 203 my $db = $r->db; 204 my $ce = $r->ce; 205 my $authz = $r->authz; 206 207 return CGI::em("You are not authorized to access the Instructor tools.") 208 unless $authz->hasPermissions($r->param("user"), "access_instructor_tools"); 209 210 print CGI::p("Use the interface below to quickly access commonly-used 211 instructor tools, or select a tool from the list to the left."); 212 213 print CGI::p("Select user(s) and/or set(s) below and click the action button 214 of your choice."); 215 216 my @userIDs = $db->listUsers; 217 my @Users = $db->getUsers(@userIDs); 218 219 ## Mark's Edits for filtering 220 my @myUsers; 221 my $user = $r->param("user"); 222 223 my (@viewable_sections,@viewable_recitations); 224 225 if (defined @{$ce->{viewable_sections}->{$user}}) 226 {@viewable_sections = @{$ce->{viewable_sections}->{$user}};} 227 if (defined @{$ce->{viewable_recitations}->{$user}}) 228 {@viewable_recitations = @{$ce->{viewable_recitations}->{$user}};} 229 230 if (@viewable_sections or @viewable_recitations){ 231 foreach my $student (@Users){ 232 my $keep = 0; 233 foreach my $sec (@viewable_sections){ 234 if ($student->section() eq $sec){$keep = 1;} 235 } 236 foreach my $rec (@viewable_recitations){ 237 if ($student->recitation() eq $rec){$keep = 1;} 238 } 239 if ($keep) {push @myUsers, $student;} 240 } 241 @Users = @myUsers; 242 } 243 ## End Mark's Edits 244 245 my @globalSetIDs = $db->listGlobalSets; 246 my @GlobalSets = $db->getGlobalSets(@globalSetIDs); 247 248 my @selected_users = $r->param("selected_users"); 249 my @selected_sets = $r->param("selected_sets"); 250 251 my $scrolling_user_list = scrollingRecordList({ 252 name => "selected_users", 253 request => $r, 254 default_sort => "lnfn", 255 default_format => "lnfn_uid", 256 default_filters => ["all"], 257 size => 10, 258 multiple => 1, 259 }, @Users); 260 261 my $scrolling_set_list = scrollingRecordList({ 262 name => "selected_sets", 263 request => $r, 264 default_sort => "set_id", 265 default_format => "set_id", 266 default_filters => ["all"], 267 size => 10, 268 multiple => 1, 269 }, @GlobalSets); 270 271 print CGI::start_form({method=>"get", action=>$r->uri()}); 272 print $self->hidden_authen_fields(); 273 274 print CGI::table({class=>"FormLayout"}, 275 CGI::Tr( 276 CGI::th("Users"), 277 CGI::th("Sets"), 278 ), 279 CGI::Tr( 280 CGI::td({style=>"width:50%"}, $scrolling_user_list), 281 CGI::td({style=>"width:50%"}, $scrolling_set_list), 282 ), 283 CGI::Tr({class=>"ButtonRow"}, [ 284 CGI::td([ 285 CGI::submit("sets_assigned_to_user", "View/edit")." all sets for one <b>user</b>", 286 CGI::submit("users_assigned_to_set", "View/edit")." all users for one <b>set</b>", 287 ]), 288 CGI::td([ 289 CGI::submit("edit_users", "Edit"). " selected <b>users</b>", 290 CGI::submit("edit_sets", "Edit"). " one <b>set</b>", 291 ]), 292 CGI::td([ 293 CGI::submit("user_stats", "View stats"). " for one <b>user</b>", 294 CGI::submit("set_stats", "View stats"). " for one <b>set</b>", 295 ]), 296 CGI::td([ 297 CGI::submit("user_options", "Change password")." for one <b>user</b>", 298 CGI::submit("score_sets", "Score"). " selected <b>sets</b>", 299 ]), 300 ]), 301 CGI::Tr({class=>"ButtonRowCenter"}, [ 302 CGI::td({colspan=>2,style=>'text-align:center'}, 303 CGI::submit("act_as_user", "Act as")." one <b>user</b> (on one <b>set</b>)", 304 ), 305 CGI::td({colspan=>2,style=>'text-align:center'}, 306 CGI::submit("edit_set_for_user", "Edit"). " one <b>set</b> for one <b>user</b>", 307 ), 308 ]), 309 ); 310 311 print CGI::end_form(); 312 313 return ""; 314 } 315 316 1; 317 318 __END__ 319 320 =head1 AUTHOR 321 322 Written by Dennis Lambe Jr., malsyned (at) math.rochester.edu. 323 324 =cut
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |