Parent Directory
|
Revision Log
Revision 1920 - (view) (download) (as text)
| 1 : | malsyned | 831 | ################################################################################ |
| 2 : | sh002i | 1663 | # WeBWorK Online Homework Delivery System |
| 3 : | # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ | ||
| 4 : | sh002i | 1920 | # $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/Index.pm,v 1.30 2004/03/04 21:05:58 sh002i Exp $ |
| 5 : | sh002i | 1663 | # |
| 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 : | malsyned | 831 | ################################################################################ |
| 16 : | |||
| 17 : | package WeBWorK::ContentGenerator::Instructor::Index; | ||
| 18 : | use base qw(WeBWorK::ContentGenerator::Instructor); | ||
| 19 : | |||
| 20 : | =head1 NAME | ||
| 21 : | |||
| 22 : | sh002i | 1920 | WeBWorK::ContentGenerator::Instructor::Index - Menu interface to the Instructor |
| 23 : | pages | ||
| 24 : | malsyned | 831 | |
| 25 : | =cut | ||
| 26 : | |||
| 27 : | use strict; | ||
| 28 : | use warnings; | ||
| 29 : | sh002i | 1920 | use Apache::Constants qw(:response); |
| 30 : | malsyned | 831 | use CGI qw(); |
| 31 : | sh002i | 1920 | use WeBWorK::HTML::ScrollingRecordList qw/scrollingRecordList/; |
| 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 : | |||
| 42 : | gage | 1579 | sub pre_header_initialize { |
| 43 : | sh002i | 1841 | my ($self) = @_; |
| 44 : | sh002i | 1920 | my $r = $self->r; |
| 45 : | my $ce = $r->ce; | ||
| 46 : | my $db = $r->db; | ||
| 47 : | my $authz = $r->authz; | ||
| 48 : | my $urlpath = $r->urlpath; | ||
| 49 : | gage | 1667 | |
| 50 : | sh002i | 1920 | unless ($authz->hasPermissions($r->param("user"), "modify_student_data")) { |
| 51 : | gage | 1579 | $self->{submitError} = "You are not authorized to modify student data"; |
| 52 : | return; | ||
| 53 : | } | ||
| 54 : | sh002i | 1920 | |
| 55 : | my $courseID = $urlpath->arg("courseID"); | ||
| 56 : | my $userID = $r->param("user"); | ||
| 57 : | my $eUserID = $r->param("effectiveUser"); | ||
| 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}::SetsAssignedToUser"; | ||
| 83 : | $args{userID} = $firstUserID; | ||
| 84 : | } else { | ||
| 85 : | push @error, E_ONE_USER; | ||
| 86 : | } | ||
| 87 : | gage | 1579 | }; |
| 88 : | sh002i | 1920 | |
| 89 : | defined param $r "users_assigned_to_set" and do { | ||
| 90 : | if ($nsets == 1) { | ||
| 91 : | $module = "${ipfx}::UsersAssignedToSet"; | ||
| 92 : | $args{setID} = $firstSetID; | ||
| 93 : | } else { | ||
| 94 : | push @error, E_ONE_SET; | ||
| 95 : | } | ||
| 96 : | gage | 1579 | }; |
| 97 : | sh002i | 1920 | |
| 98 : | defined param $r "edit_users" and do { | ||
| 99 : | if ($nusers >= 1) { | ||
| 100 : | $module = "${ipfx}::UserList"; | ||
| 101 : | $params{visible_users} = \@selectedUserIDs; | ||
| 102 : | $params{editMode} = 1; | ||
| 103 : | } else { | ||
| 104 : | push @error, E_MIN_ONE_USER; | ||
| 105 : | } | ||
| 106 : | gage | 1579 | }; |
| 107 : | |||
| 108 : | sh002i | 1920 | defined param $r "edit_sets" and do { |
| 109 : | if ($nsets == 1) { | ||
| 110 : | $module = "${ipfx}::ProblemSetEditor"; | ||
| 111 : | $args{setID} = $firstSetID; | ||
| 112 : | } else { | ||
| 113 : | push @error, E_ONE_SET; | ||
| 114 : | |||
| 115 : | } | ||
| 116 : | }; | ||
| 117 : | gage | 1579 | |
| 118 : | sh002i | 1920 | defined param $r "user_stats" and do { |
| 119 : | if ($nusers == 1) { | ||
| 120 : | $module = "${ipfx}::Stats"; | ||
| 121 : | $args{statType} = "student"; # FIXME: fix URLPath -- i shouldn't have to type this! | ||
| 122 : | $args{userID} = $firstUserID; | ||
| 123 : | } else { | ||
| 124 : | push @error, E_ONE_USER; | ||
| 125 : | } | ||
| 126 : | }; | ||
| 127 : | |||
| 128 : | defined param $r "set_stats" and do { | ||
| 129 : | if ($nsets == 1) { | ||
| 130 : | $module = "${ipfx}::Stats"; | ||
| 131 : | $args{statType} = "set"; # FIXME: fix URLPath -- i shouldn't have to type this! | ||
| 132 : | $args{setID} = $firstSetID; | ||
| 133 : | } else { | ||
| 134 : | push @error, E_ONE_SET; | ||
| 135 : | } | ||
| 136 : | }; | ||
| 137 : | |||
| 138 : | defined param $r "user_options" and do { | ||
| 139 : | if ($nusers == 1) { | ||
| 140 : | $module = "${pfx}::Options"; | ||
| 141 : | $params{effectiveUser} = $firstUserID; | ||
| 142 : | } else { | ||
| 143 : | push @error, E_ONE_USER; | ||
| 144 : | } | ||
| 145 : | }; | ||
| 146 : | |||
| 147 : | defined param $r "score_sets" and do { | ||
| 148 : | if ($nsets >= 1) { | ||
| 149 : | $module = "${ipfx}::Scoring"; | ||
| 150 : | $params{selectedSet} = \@selectedSetIDs; | ||
| 151 : | $params{scoreSelected} = 1; | ||
| 152 : | } else { | ||
| 153 : | push @error, E_MIN_ONE_SET; | ||
| 154 : | } | ||
| 155 : | }; | ||
| 156 : | |||
| 157 : | defined param $r "act_as_user" and do { | ||
| 158 : | if ($nusers == 1 and $nsets <= 1) { | ||
| 159 : | if ($nsets) { | ||
| 160 : | $module = "${pfx}::ProblemSet"; | ||
| 161 : | $args{setID} = $firstSetID; | ||
| 162 : | } else { | ||
| 163 : | $module = "${pfx}::ProblemSets"; | ||
| 164 : | } | ||
| 165 : | $params{effectiveUser} = $firstUserID; | ||
| 166 : | } else { | ||
| 167 : | push @error, E_ONE_USER unless $nusers == 1; | ||
| 168 : | push @error, E_MAX_ONE_SET unless $nsets <= 1; | ||
| 169 : | } | ||
| 170 : | }; | ||
| 171 : | |||
| 172 : | defined param $r "edit_set_for_user" and do { | ||
| 173 : | if ($nusers == 1 and $nsets == 1) { | ||
| 174 : | $module = "${ipfx}::ProblemSetEditor"; | ||
| 175 : | $args{setID} = $firstSetID; | ||
| 176 : | $params{editForUser} = $firstUserID; | ||
| 177 : | } else { | ||
| 178 : | push @error, E_ONE_USER unless $nusers == 1; | ||
| 179 : | push @error, E_ONE_SET unless $nsets == 1; | ||
| 180 : | |||
| 181 : | } | ||
| 182 : | }; | ||
| 183 : | |||
| 184 : | # handle errors, redirect to target page | ||
| 185 : | |||
| 186 : | if (@error) { | ||
| 187 : | $self->{error} = \@error; | ||
| 188 : | } elsif ($module) { | ||
| 189 : | my $page = $urlpath->newFromModule($module, %args); | ||
| 190 : | my $url = $self->systemLink($page, params => \%params); | ||
| 191 : | $self->reply_with_redirect($url); | ||
| 192 : | } | ||
| 193 : | gage | 1295 | } |
| 194 : | |||
| 195 : | malsyned | 831 | sub body { |
| 196 : | sh002i | 1920 | my ($self) = @_; |
| 197 : | my $r = $self->r; | ||
| 198 : | my $db = $r->db; | ||
| 199 : | my $authz = $r->authz; | ||
| 200 : | sh002i | 1681 | |
| 201 : | sh002i | 1920 | return CGI::em("You are not authorized to access the Instructor tools.") |
| 202 : | unless $authz->hasPermissions($r->param("user"), "access_instructor_tools"); | ||
| 203 : | sh002i | 1681 | |
| 204 : | sh002i | 1920 | print CGI::p("Use the interface below to quickly access commonly-used |
| 205 : | instructor tools, or select a tool from the list to the left."); | ||
| 206 : | sh002i | 1681 | |
| 207 : | sh002i | 1920 | print CGI::p("Select user(s) and/or set(s) below and click the action button |
| 208 : | of your choice."); | ||
| 209 : | gage | 1766 | |
| 210 : | sh002i | 1920 | if ($self->{error}) { |
| 211 : | my @errors = @{ $self->{error} }; | ||
| 212 : | print CGI::div({class=>"ResultsWithError"}, | ||
| 213 : | CGI::p("Your request could not be fulfilled. Please correct the following errors and try again:"), | ||
| 214 : | CGI::ul(CGI::li(\@errors)), | ||
| 215 : | ); | ||
| 216 : | } | ||
| 217 : | |||
| 218 : | my @userIDs = $db->listUsers; | ||
| 219 : | my @Users = $db->getUsers(@userIDs); | ||
| 220 : | |||
| 221 : | my @globalSetIDs = $db->listGlobalSets; | ||
| 222 : | my @GlobalSets = $db->getGlobalSets(@globalSetIDs); | ||
| 223 : | |||
| 224 : | my @selected_users = $r->param("selected_users"); | ||
| 225 : | my @selected_sets = $r->param("selected_sets"); | ||
| 226 : | |||
| 227 : | my $scrolling_user_list = scrollingRecordList({ | ||
| 228 : | name => "selected_users", | ||
| 229 : | request => $r, | ||
| 230 : | default_sort => "lnfn", | ||
| 231 : | default_format => "lnfn_uid", | ||
| 232 : | size => 10, | ||
| 233 : | multiple => 1, | ||
| 234 : | }, @Users); | ||
| 235 : | |||
| 236 : | my $scrolling_set_list = scrollingRecordList({ | ||
| 237 : | name => "selected_sets", | ||
| 238 : | request => $r, | ||
| 239 : | default_sort => "set_id", | ||
| 240 : | default_format => "set_id", | ||
| 241 : | size => 10, | ||
| 242 : | multiple => 1, | ||
| 243 : | }, @GlobalSets); | ||
| 244 : | |||
| 245 : | print CGI::start_form({method=>"get", action=>$r->uri()}); | ||
| 246 : | print $self->hidden_authen_fields(); | ||
| 247 : | |||
| 248 : | print CGI::table({class=>"FormLayout"}, | ||
| 249 : | CGI::Tr( | ||
| 250 : | CGI::th("Users"), | ||
| 251 : | CGI::th("Sets"), | ||
| 252 : | gage | 1579 | ), |
| 253 : | sh002i | 1920 | CGI::Tr( |
| 254 : | CGI::td({style=>"width:50%"}, $scrolling_user_list), | ||
| 255 : | CGI::td({style=>"width:50%"}, $scrolling_set_list), | ||
| 256 : | gage | 1579 | ), |
| 257 : | sh002i | 1920 | CGI::Tr({class=>"ButtonRow"}, [ |
| 258 : | gage | 1766 | CGI::td([ |
| 259 : | sh002i | 1920 | CGI::submit("sets_assigned_to_user", "View/edit assigned sets for selected user"), |
| 260 : | CGI::submit("users_assigned_to_set", "View/edit assigned users for selected set"), | ||
| 261 : | gage | 1766 | ]), |
| 262 : | sh002i | 1920 | CGI::td([ |
| 263 : | CGI::submit("edit_users", "Edit selected users"), | ||
| 264 : | CGI::submit("edit_sets", "Edit selected set"), | ||
| 265 : | ]), | ||
| 266 : | CGI::td([ | ||
| 267 : | CGI::submit("user_stats", "View stats for selected user"), | ||
| 268 : | CGI::submit("set_stats", "View stats for selected set"), | ||
| 269 : | ]), | ||
| 270 : | CGI::td([ | ||
| 271 : | CGI::submit("user_options", "Change selected user's password"), | ||
| 272 : | CGI::submit("score_sets", "Score selected sets"), | ||
| 273 : | ]), | ||
| 274 : | CGI::td({colspan=>2}, | ||
| 275 : | CGI::submit("act_as_user", "Act as selected user (optionally viewing selected set)"), | ||
| 276 : | gage | 1766 | ), |
| 277 : | sh002i | 1920 | CGI::td({colspan=>2}, |
| 278 : | CGI::submit("edit_set_for_user", "Edit properties of selected set for selected user"), | ||
| 279 : | gage | 1766 | ), |
| 280 : | sh002i | 1920 | ]), |
| 281 : | gage | 1766 | ); |
| 282 : | gage | 1486 | |
| 283 : | sh002i | 1920 | print CGI::end_form(); |
| 284 : | gage | 1579 | |
| 285 : | sh002i | 1920 | return ""; |
| 286 : | gage | 1579 | } |
| 287 : | |||
| 288 : | malsyned | 831 | 1; |
| 289 : | |||
| 290 : | __END__ | ||
| 291 : | |||
| 292 : | =head1 AUTHOR | ||
| 293 : | |||
| 294 : | sh002i | 1920 | Written by Dennis Lambe Jr., malsyned (at) math.rochester.edu. |
| 295 : | malsyned | 831 | |
| 296 : | =cut |
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |