Parent Directory
|
Revision Log
Apache2 compatibility for HTTP constants. (This may very well be broken, but I wanted to get it comitted before bed.)
1 ################################################################################ 2 # WeBWorK Online Homework Delivery System 3 # Copyright © 2000-2006 The WeBWorK Project, http://openwebwork.sf.net/ 4 # $CVSHeader: webwork2/lib/WeBWorK/ContentGenerator/Instructor/Index.pm,v 1.53 2006/07/08 14:07:34 gage 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 CGI qw(-nosticky ); 30 use WeBWorK::HTML::ScrollingRecordList qw/scrollingRecordList/; 31 #use WeBWorK::Utils::FilterRecords qw/getFiltersForClass/; 32 33 use constant E_NO_USERS => "Please do not select any users."; 34 use constant E_NO_SETS => "Please do not select any sets."; 35 use constant E_MAX_ONE_USER => "Please select at most one user."; 36 use constant E_MAX_ONE_SET => "Please select at most one set."; 37 use constant E_ONE_USER => "Please select exactly one user."; 38 use constant E_ONE_SET => "Please select exactly one set."; 39 use constant E_MIN_ONE_USER => "Please select at least one user."; 40 use constant E_MIN_ONE_SET => "Please select at least one set."; 41 use constant E_SET_NAME => "Please specify a homework set name."; 42 use constant E_BAD_NAME => "Please use only letter, digits, -, _ and . in your set name."; 43 44 sub pre_header_initialize { 45 my ($self) = @_; 46 my $r = $self->r; 47 my $ce = $r->ce; 48 my $db = $r->db; 49 my $authz = $r->authz; 50 my $urlpath = $r->urlpath; 51 52 my $courseID = $urlpath->arg("courseID"); 53 my $userID = $r->param("user"); 54 my $eUserID = $r->param("effectiveUser"); 55 $self->{courseName} = $courseID; 56 # Check permissions 57 return unless ($authz->hasPermissions($userID, "access_instructor_tools")); 58 59 my @selectedUserIDs = $r->param("selected_users"); 60 my @selectedSetIDs = $r->param("selected_sets"); 61 62 my $nusers = @selectedUserIDs; 63 my $nsets = @selectedSetIDs; 64 65 my $firstUserID = $nusers ? $selectedUserIDs[0] : ""; 66 my $firstSetID = $nsets ? $selectedSetIDs[0] : ""; 67 68 # these will be used to construct a new URL 69 my $module; 70 my %args = ( courseID => $courseID ); 71 my %params; 72 73 my $pfx = "WeBWorK::ContentGenerator"; 74 my $ipfx = "WeBWorK::ContentGenerator::Instructor"; 75 76 my @error; 77 78 # depending on which button was pushed, fill values in for URL construction 79 80 defined param $r "sets_assigned_to_user" and do { 81 if ($nusers == 1) { 82 $module = "${ipfx}::UserDetail"; 83 $args{userID} = $firstUserID; 84 $params{fromTools} = 1; 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 $params{fromTools} = 1; 95 } else { 96 push @error, E_ONE_SET; 97 } 98 }; 99 100 defined param $r "edit_users" and do { 101 if ($nusers >= 1) { 102 $module = "${ipfx}::UserList"; 103 $params{visible_users} = \@selectedUserIDs; 104 $params{editMode} = 1; 105 } else { 106 push @error, E_MIN_ONE_USER; 107 } 108 }; 109 110 defined param $r "edit_sets" and do { 111 if ($nsets == 1) { 112 $module = "${ipfx}::ProblemSetDetail"; 113 $args{setID} = $firstSetID; 114 } else { 115 push @error, E_ONE_SET; 116 117 } 118 }; 119 120 defined param $r "prob_lib" and do { 121 if ($nsets == 1) { 122 $module = "${ipfx}::SetMaker"; 123 $params{local_sets} = $firstSetID; 124 } elsif ($nsets == 0) { 125 $module = "${ipfx}::SetMaker"; 126 } else { 127 push @error, E_ONE_SET; 128 129 } 130 }; 131 132 defined param $r "user_stats" and do { 133 if ($nusers == 1) { 134 $module = "${ipfx}::Stats"; 135 $args{statType} = "student"; # FIXME: fix URLPath -- i shouldn't have to type this! 136 $args{userID} = $firstUserID; 137 } else { 138 push @error, E_ONE_USER; 139 } 140 }; 141 142 defined param $r "set_stats" and do { 143 if ($nsets == 1) { 144 $module = "${ipfx}::Stats"; 145 $args{statType} = "set"; # FIXME: fix URLPath -- i shouldn't have to type this! 146 $args{setID} = $firstSetID; 147 } else { 148 push @error, E_ONE_SET; 149 } 150 }; 151 152 defined param $r "user_progress" and do { 153 if ($nusers == 1) { 154 $module = "${ipfx}::StudentProgress"; 155 $args{statType} = "student"; # FIXME: fix URLPath -- i shouldn't have to type this! 156 $args{userID} = $firstUserID; 157 } else { 158 push @error, E_ONE_USER; 159 } 160 }; 161 162 defined param $r "set_progress" and do { 163 if ($nsets == 1) { 164 $module = "${ipfx}::StudentProgress"; 165 $args{statType} = "set"; # FIXME: fix URLPath -- i shouldn't have to type this! 166 $args{setID} = $firstSetID; 167 } else { 168 push @error, E_ONE_SET; 169 } 170 }; 171 172 defined param $r "user_options" and do { 173 if ($nusers == 1) { 174 $module = "${pfx}::Options"; 175 $params{effectiveUser} = $firstUserID; 176 } else { 177 push @error, E_ONE_USER; 178 } 179 }; 180 181 defined param $r "score_sets" and do { 182 if ($nsets >= 1) { 183 $module = "${ipfx}::Scoring"; 184 $params{selectedSet} = \@selectedSetIDs; 185 $params{scoreSelected} = 1; 186 } else { 187 push @error, E_MIN_ONE_SET; 188 } 189 }; 190 191 defined param $r "assign_users" and do { 192 if ($nusers >= 1 and $nsets >= 1) { 193 $module = "${ipfx}::Assigner"; 194 $params{selected_users} = \@selectedUserIDs; 195 $params{selected_sets} = \@selectedSetIDs; 196 $params{assign} = "Assign selected sets to selected users"; 197 } else { 198 push @error, E_MIN_ONE_USER unless $nusers >= 1; 199 push @error, E_MIN_ONE_SET unless $nsets >= 1; 200 } 201 }; 202 203 defined param $r "act_as_user" and do { 204 if ($nusers == 1 and $nsets <= 1) { 205 if ($nsets) { 206 $module = "${pfx}::ProblemSet"; 207 $args{setID} = $firstSetID; 208 } else { 209 $module = "${pfx}::ProblemSets"; 210 } 211 $params{effectiveUser} = $firstUserID; 212 } else { 213 push @error, E_ONE_USER unless $nusers == 1; 214 push @error, E_MAX_ONE_SET unless $nsets <= 1; 215 } 216 }; 217 218 defined param $r "edit_set_for_users" and do { 219 if ($nusers >= 1 and $nsets == 1) { 220 $module = "${ipfx}::ProblemSetDetail"; 221 $args{setID} = $firstSetID; 222 $params{editForUser} = \@selectedUserIDs; 223 } else { 224 push @error, E_MIN_ONE_USER unless $nusers >= 1; 225 push @error, E_ONE_SET unless $nsets == 1; 226 227 } 228 }; 229 230 defined param $r "create_set" and do { 231 my $setname = $r->param("new_set_name"); 232 if ($setname && $setname ne 'Name for new set here') { 233 if ($setname =~ /^[\w.-]*$/) { 234 $module = "${ipfx}::SetMaker"; 235 $params{new_local_set} = "Create a New Set in this Course"; 236 $params{new_set_name} = $setname; 237 $params{selfassign} = 1; 238 } else { 239 push @error, E_BAD_NAME; 240 } 241 } else { 242 push @error, E_SET_NAME; 243 } 244 }; 245 246 defined param $r "add_users" and do { 247 $module = "${ipfx}::AddUsers"; 248 }; 249 250 defined param $r "email_users" and do { 251 $module = "${ipfx}::SendMail"; 252 }; 253 254 defined param $r "transfer_files" and do { 255 $module = "${ipfx}::FileManager"; 256 }; 257 258 push @error, "You are not allowed to act as a student." 259 if (defined param $r "act_as_user" and not $authz->hasPermissions($userID, "become_student")); 260 push @error, "You are not allowed to modify homework sets." 261 if ((defined param $r "edit_sets" or defined param $r "edit_set_for_users") and not $authz->hasPermissions($userID, "modify_problem_sets")); 262 push @error, "You are not allowed to assign homework sets." 263 if ((defined param $r "sets_assigned_to_user" or defined param $r "users_assigned_to_set") and not $authz->hasPermissions($userID, "assign_problem_sets")); 264 push @error, "You are not allowed to modify student data." 265 if ((defined param $r "edit_users" or defined param $r "user_options" or defined param $r "user_options") and not $authz->hasPermissions($userID, "modify_student_data")); 266 push @error, "You are not allowed to score sets." 267 if (defined param $r "score_sets" and not $authz->hasPermissions($userID, "score_sets")); 268 269 # handle errors, redirect to target page 270 if (@error) { 271 $self->addbadmessage(CGI::p(join(CGI::br(),@error))); 272 273 } elsif ($module) { 274 my $page = $urlpath->newFromModule($module, %args); 275 my $url = $self->systemLink($page, params => \%params); 276 $self->reply_with_redirect($url); 277 } 278 } 279 280 sub body { 281 my ($self) = @_; 282 my $r = $self->r; 283 my $db = $r->db; 284 my $ce = $r->ce; 285 my $authz = $r->authz; 286 my $courseName = $self->{courseName}; 287 my $user = $r->param("user"); 288 289 return CGI::div({class=>"ResultsWithError"}, "You are not authorized to access the Instructor tools.") 290 unless $authz->hasPermissions($user, "access_instructor_tools"); 291 292 print CGI::p("Use the interface below to quickly access commonly-used 293 instructor tools, or select a tool from the list to the left.", CGI::br(), 294 "Select user(s) and/or set(s) below and click the action button 295 of your choice."); 296 297 my @userIDs = $db->listUsers; 298 my @Users = $db->getUsers(@userIDs); 299 300 ## Mark's Edits for filtering 301 my @myUsers; 302 303 my (@viewable_sections,@viewable_recitations); 304 305 if (defined @{$ce->{viewable_sections}->{$user}}) 306 {@viewable_sections = @{$ce->{viewable_sections}->{$user}};} 307 if (defined @{$ce->{viewable_recitations}->{$user}}) 308 {@viewable_recitations = @{$ce->{viewable_recitations}->{$user}};} 309 310 if (@viewable_sections or @viewable_recitations){ 311 foreach my $student (@Users){ 312 my $keep = 0; 313 foreach my $sec (@viewable_sections){ 314 if ($student->section() eq $sec){$keep = 1;} 315 } 316 foreach my $rec (@viewable_recitations){ 317 if ($student->recitation() eq $rec){$keep = 1;} 318 } 319 if ($keep) {push @myUsers, $student;} 320 } 321 @Users = @myUsers; 322 } 323 ## End Mark's Edits 324 325 my @globalSetIDs = $db->listGlobalSets; 326 my @GlobalSets = $db->getGlobalSets(@globalSetIDs); 327 328 my @selected_users = $r->param("selected_users"); 329 my @selected_sets = $r->param("selected_sets"); 330 331 my $scrolling_user_list = scrollingRecordList({ 332 name => "selected_users", 333 request => $r, 334 default_sort => "lnfn", 335 default_format => "lnfn_uid", 336 default_filters => ["all"], 337 size => 10, 338 multiple => 1, 339 }, @Users); 340 341 my $scrolling_set_list = scrollingRecordList({ 342 name => "selected_sets", 343 request => $r, 344 default_sort => "set_id", 345 default_format => "set_id", 346 default_filters => ["all"], 347 size => 10, 348 multiple => 1, 349 }, @GlobalSets); 350 351 print CGI::start_form({method=>"get", action=>$r->uri()}); 352 print $self->hidden_authen_fields(); 353 354 print CGI::table({class=>"FormLayout"}, 355 CGI::Tr( 356 CGI::th("Users"), 357 CGI::th("Sets"), 358 ), 359 CGI::Tr( 360 CGI::td({style=>"width:50%"}, $scrolling_user_list), 361 CGI::td({style=>"width:50%"}, $scrolling_set_list), 362 ), 363 CGI::Tr({class=>"ButtonRow"}, [ 364 CGI::td([ 365 CGI::submit("sets_assigned_to_user", "View/edit")." all sets for one <b>user</b>(set dates, scores)", 366 CGI::submit("users_assigned_to_set", "View/edit")." all users for one <b>set</b>", 367 ]), 368 CGI::td([ 369 CGI::submit("edit_users", "Edit"). " class list data for selected <b>users</b>", 370 CGI::submit("edit_sets", "Edit"). " one <b>set</b>" . " ". 371 "or ".CGI::submit("prob_lib","add problems")." to one <b>set</b>", 372 ]), 373 CGI::td([ 374 CGI::submit("user_stats", "Statistics")." or ". 375 CGI::submit("user_progress", "progress")." for one <b>user</b>", 376 CGI::submit("set_stats", "Statistics")." or ". 377 CGI::submit("set_progress", "progress")." for one <b>set</b>", 378 ]), 379 CGI::td([ 380 CGI::submit("user_options", "Change password")." for one <b>user</b>", 381 CGI::submit("score_sets", "Score"). " selected <b>sets</b>", 382 ]), 383 CGI::td([ 384 CGI::submit("add_users", "Add")." new users", 385 CGI::submit("create_set", "Create"). " new set: ". 386 CGI::textfield(-name=>"new_set_name", 387 -default=>"Name for new set here", 388 -override=>1, -size=>20), 389 ]), 390 ]), 391 CGI::Tr({class=>"ButtonRowCenter"}, 392 CGI::td({-colspan=>2, align=>"center"}, 393 CGI::table({-border=>0, align=>"center"}, 394 CGI::Tr({-align=>"left"}, [ 395 CGI::td({-height=>2}), 396 CGI::td(CGI::submit("assign_users", "Assign")." selected <b>users</b> to selected <b>sets</b>"), 397 CGI::td(CGI::submit("act_as_user", "Act as")." one <b>user</b> (on one <b>set</b>)"), 398 CGI::td(CGI::submit("edit_set_for_users", "Edit"). " one <b>set</b> for <b>users</b>"), 399 CGI::td({-height=>4}), 400 CGI::td(CGI::submit("email_users", "Email"). " your students"), 401 ($authz->hasPermissions($user, "manage_course_files") 402 ? CGI::td(CGI::submit("transfer_files", "Transfer"). " course files") 403 : () 404 ), 405 ]) 406 ) 407 ) 408 ), 409 ); 410 411 print CGI::end_form(); 412 413 return ""; 414 } 415 416 1; 417 418 __END__ 419 420 =head1 AUTHOR 421 422 Written by Dennis Lambe Jr., malsyned (at) math.rochester.edu. 423 424 =cut
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |