Parent Directory
|
Revision Log
timezone support
1 ################################################################################ 2 # WeBWorK Online Homework Delivery System 3 # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ 4 # $CVSHeader: webwork2/lib/WeBWorK/ContentGenerator/Instructor/UsersAssignedToSet.pm,v 1.12 2004/06/17 14:35:05 toenail 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::UsersAssignedToSet; 18 use base qw(WeBWorK::ContentGenerator::Instructor); 19 20 =head1 NAME 21 22 WeBWorK::ContentGenerator::Instructor::UsersAssignedToSet - List and edit the 23 users to which sets are assigned. 24 25 =cut 26 27 use strict; 28 use warnings; 29 use CGI qw(); 30 31 sub initialize { 32 my ($self) = @_; 33 my $r = $self->r; 34 my $urlpath = $r->urlpath; 35 my $authz = $r->authz; 36 my $db = $r->db; 37 my $setID = $urlpath->arg("setID"); 38 my $user = $r->param('user'); 39 40 # Check permissions 41 return unless $authz->hasPermissions($user, "access_instructor_tools"); 42 return unless $authz->hasPermissions($user, "assign_problem_sets"); 43 44 my @users = $db->listUsers; 45 my %selectedUsers = map {$_ => 1} $r->param('selected'); 46 47 my $doAssignToSelected = 0; 48 49 # get the global user, if there is one 50 my $globalUserID = ""; 51 $globalUserID = $db->{set}->{params}->{globalUserID} 52 if ref $db->{set} eq "WeBWorK::DB::Schema::GlobalTableEmulator"; 53 54 if (defined $r->param('assignToAll')) { 55 $WeBWorK::timer->continue("assignSetToAllUsers($setID)") if defined $WeBWorK::timer; 56 $self->addmessage(CGI::div({class=>'ResultsWithoutError'}, "Problems have been assigned to all current users.")); 57 $self->assignSetToAllUsers($setID); 58 $WeBWorK::timer->continue("done assignSetToAllUsers($setID)") if defined $WeBWorK::timer; 59 } elsif (defined $r->param('unassignFromAll') and defined($r->param('unassignFromAllSafety')) and $r->param('unassignFromAllSafety')==1) { 60 %selectedUsers = ( $globalUserID => 1 ); 61 $self->addmessage(CGI::div({class=>'ResultsWithoutError'}, "Problems for all students have been unassigned.")); 62 $doAssignToSelected = 1; 63 } elsif (defined $r->param('assignToSelected')) { 64 $self->addmessage(CGI::div({class=>'ResultsWithoutError'}, "Problems for selected students have been reassigned.")); 65 $doAssignToSelected = 1; 66 } else { 67 # no action taken 68 $self->addmessage(CGI::div({class=>'ResultsWithError'}, "No action taken")); 69 } 70 71 if ($doAssignToSelected) { 72 my $setRecord = $db->getGlobalSet($setID); #checked 73 die "Unable to get global set record for $setID " unless $setRecord; 74 75 foreach my $selectedUser (@users) { 76 if (exists $selectedUsers{$selectedUser}) { 77 $WeBWorK::timer->continue("assignSetToUser($selectedUser, ...)") if defined $WeBWorK::timer; 78 $self->assignSetToUser($selectedUser, $setRecord); 79 $WeBWorK::timer->continue("done assignSetToUser($selectedUser, ...)") if defined $WeBWorK::timer; 80 } else { 81 next if $selectedUser eq $globalUserID; 82 $db->deleteUserSet($selectedUser, $setID); 83 } 84 } 85 } 86 } 87 88 sub getSetName { 89 my ($self, $pathSetName) = @_; 90 if (ref $pathSetName eq "HASH") { 91 $pathSetName = undef; 92 } 93 return $pathSetName; 94 } 95 96 97 sub body { 98 my ($self) = @_; 99 my $r = $self->r; 100 my $urlpath = $r->urlpath; 101 my $db = $r->db; 102 my $ce = $r->ce; 103 my $authz = $r->authz; 104 my $webworkRoot = $ce->{webworkURLs}->{root}; 105 my $courseName = $urlpath->arg("courseID"); 106 my $setID = $urlpath->arg("setID"); 107 my $user = $r->param('user'); 108 109 return CGI::div({class=>"ResultsWithError"}, CGI::p("You are not authorized to acces the Instructor tools.")) 110 unless $authz->hasPermissions($user, "access_instructor_tools"); 111 112 return CGI::div({class=>"ResultsWithError"}, CGI::p("You are not authorized to assign problem sets.")) 113 unless $authz->hasPermissions($user, "assign_problem_sets"); 114 115 my @users = $db->listUsers; 116 print CGI::start_form({method=>"post", action => $self->systemLink( $urlpath, authen=>0) }); 117 118 print CGI::p( 119 CGI::submit({name=>"assignToAll", value => "Assign to All Current Users"}), CGI::i("This action can take a long time if there are many students.") 120 ), 121 CGI::div({-style=>"color:red"}, "Do not uncheck students, unless you know what you are doing.",CGI::br(), 122 "There is NO undo for unassigning students. "), 123 CGI::p("When you unassign 124 by unchecking a student's name, you destroy all 125 of the data for problem set $setID for this student. You will then need to 126 reassign the set to these students and they will receive new versions of the problems. 127 Make sure this is what you want to do before unchecking students." 128 ); 129 130 print CGI::start_table({}); 131 # get user records 132 my @userRecords = (); 133 foreach my $currentUser ( @users) { 134 my $userObj = $db->getUser($currentUser); #checked 135 die "Unable to find user object for $currentUser. " unless $userObj; 136 push (@userRecords, $userObj ); 137 } 138 @userRecords = sort { ( lc($a->section) cmp lc($b->section) ) || 139 ( lc($a->last_name) cmp lc($b->last_name )) } @userRecords; 140 141 # get the global user, if there is one 142 my $globalUserID = ""; 143 $globalUserID = $db->{set}->{params}->{globalUserID} 144 if ref $db->{set} eq "WeBWorK::DB::Schema::GlobalTableEmulator"; 145 146 foreach my $userRecord (@userRecords) { 147 148 my $statusClass = $ce->{siteDefaults}->{status}->{$userRecord->{status}} || ""; 149 150 my $user = $userRecord->user_id; 151 my $userSetRecord = $db->getUserSet($user, $setID); #checked 152 # don't need to check here, undefined values are handled below 153 #die "Unable to find record for user $user and set $setID " unless $userSetRecord; 154 my $prettyName = $userRecord->last_name 155 . ", " 156 . $userRecord->first_name; 157 my $dueDate = $userSetRecord->due_date if ref($userSetRecord); 158 my $prettyDate = ($dueDate)? '(' . $self->formatDateTime($dueDate) . ') ' : ''; 159 print CGI::Tr({}, 160 CGI::td({}, [ 161 ($user eq $globalUserID 162 ? "" # no checkbox for global user! 163 : CGI::checkbox({ 164 type=>"checkbox", 165 name=>"selected", 166 checked=>( 167 defined($userSetRecord) # && $statusClass ne "Drop" 168 ? "on" 169 : "" 170 ), 171 value=>$user, 172 label=>"", 173 }) 174 ), 175 CGI::div({class=>$statusClass}, $user), 176 "($prettyName)", " ", $userRecord->section, " ", 177 ( 178 defined $userSetRecord 179 ? $prettyDate . CGI::a( 180 {href=>$self->systemLink($urlpath->new(type =>'instructor_set_detail', 181 args =>{courseID => $courseName, 182 setID => $setID 183 }), 184 params =>{editForUser=> $user} 185 )}, 186 "Edit data for $user" 187 ) 188 : () 189 ), 190 ]) 191 ); 192 } 193 print CGI::end_table(); 194 print $self->hidden_authen_fields; 195 print CGI::submit({name=>"assignToSelected", value=>"Save"}); 196 print CGI::p( CGI::hr(), 197 CGI::div( {class=>'ResultsWithError'}, 198 "There is NO undo for this function. 199 Do not use it unless you know what you are doing! When you unassign 200 a student using this button, or by unchecking their name, you destroy all 201 of the data for problem set $setID for this student.", 202 CGI::br(), 203 CGI::submit({name=>"unassignFromAll", value=>"Unassign from All Users"}), 204 CGI::radio_group(-name=>"unassignFromAllSafety", -values=>[0,1], -default=>0, -labels=>{0=>'Read only', 1=>'Allow unassign'}), 205 206 ), 207 208 209 CGI::hr(), 210 ); 211 print CGI::end_form(); 212 213 return ""; 214 } 215 216 1;
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |