[system] / trunk / webwork2 / lib / WeBWorK / ContentGenerator / Instructor / Assigner.pm Repository:
ViewVC logotype

Annotation of /trunk/webwork2/lib/WeBWorK/ContentGenerator/Instructor/Assigner.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3377 - (view) (download) (as text)

1 : sh002i 1663 ################################################################################
2 :     # WeBWorK Online Homework Delivery System
3 :     # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/
4 : glarose 3377 # $CVSHeader: webwork2/lib/WeBWorK/ContentGenerator/Instructor/Assigner.pm,v 1.27 2004/12/20 16:21:50 gage 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 :     ################################################################################
16 :    
17 : malsyned 1174 package WeBWorK::ContentGenerator::Instructor::Assigner;
18 :     use base qw(WeBWorK::ContentGenerator::Instructor);
19 :    
20 :     =head1 NAME
21 :    
22 : dpvc 3358 WeBWorK::ContentGenerator::Instructor::Assigner - Assign homework sets to users.
23 : malsyned 1174
24 :     =cut
25 :    
26 :     use strict;
27 :     use warnings;
28 :     use CGI qw();
29 : sh002i 1825 use WeBWorK::HTML::ScrollingRecordList qw/scrollingRecordList/;
30 : malsyned 1174
31 : toenail 2302 sub initialize {
32 :     my ($self) = @_;
33 :     my $r = $self->r;
34 :     my $authz = $r->authz;
35 :    
36 :     my $user = $r->param('user');
37 :    
38 :     # Check permissions
39 :     return unless ($authz->hasPermissions($user, "access_instructor_tools"));
40 :     return unless ($authz->hasPermissions($user, "assign_problem_sets"));
41 :     }
42 :    
43 : malsyned 1174 sub body {
44 : sh002i 1825 my ($self) = @_;
45 : sh002i 1916 my $r = $self->r;
46 :     my $db = $r->db;
47 :     my $authz = $r->authz;
48 : mschmitt 2196 my $ce = $r->ce;
49 : gage 3051
50 :     my $user = $r->param('user');
51 :    
52 : toenail 2302 # Check permissions
53 :     return CGI::div({class=>"ResultsWithError"}, "You are not authorized to access the Instructor tools.")
54 : gage 3051 unless $authz->hasPermissions($user, "access_instructor_tools");
55 : sh002i 1916
56 : sh002i 3357 return CGI::div({class=>"ResultsWithError"}, "You are not authorized to assign homework sets.")
57 : gage 3051 unless $authz->hasPermissions($user, "assign_problem_sets");
58 : toenail 2302
59 :    
60 : toenail 2584 print CGI::p("Select one or more sets and one or more users below to assign/unassign"
61 :     . " each selected set to/from all selected users.");
62 : sh002i 1681
63 : sh002i 1825 my @userIDs = $db->listUsers;
64 :     my @Users = $db->getUsers(@userIDs);
65 : mschmitt 2196 ## Mark's Edits for filtering
66 :     my @myUsers;
67 : gage 3057
68 : sh002i 1825
69 : mschmitt 2196 my (@viewable_sections, @viewable_recitations);
70 :    
71 :     if (defined @{$ce->{viewable_sections}->{$user}})
72 :     {@viewable_sections = @{$ce->{viewable_sections}->{$user}};}
73 :     if (defined @{$ce->{viewable_recitations}->{$user}})
74 :     {@viewable_recitations = @{$ce->{viewable_recitations}->{$user}};}
75 : mschmitt 2198 if (@viewable_sections or @viewable_recitations){
76 :     foreach my $student (@Users){
77 :     my $keep = 0;
78 :     foreach my $sec (@viewable_sections){
79 :     if ($student->section() eq $sec){$keep = 1;}
80 :     }
81 :     foreach my $rec (@viewable_recitations){
82 :     if ($student->section() eq $rec){$keep = 1;}
83 :     }
84 :     if ($keep) {push @myUsers, $student;}
85 : mschmitt 2196 }
86 : mschmitt 2198 @Users = @myUsers;
87 : mschmitt 2196 }
88 :     ## End Mark's Edits
89 :    
90 :    
91 : sh002i 1828 my @globalSetIDs = $db->listGlobalSets;
92 :     my @GlobalSets = $db->getGlobalSets(@globalSetIDs);
93 :    
94 :     my @selected_users = $r->param("selected_users");
95 :     my @selected_sets = $r->param("selected_sets");
96 :    
97 : toenail 2584 if (defined $r->param("assign") || defined $r->param("assign")) {
98 : sh002i 1828 if (@selected_users && @selected_sets) {
99 : toenail 2584 my @results;
100 :     $self->assignSetsToUsers(\@selected_sets, \@selected_users) if defined $r->param("assign");
101 :     $self->unassignSetsFromUsers(\@selected_sets, \@selected_users) if defined $r->param("unassign");
102 : sh002i 1828
103 :     if (@results) {
104 :     print CGI::div({class=>"ResultsWithError"},
105 :     CGI::p("The following error(s) occured while assigning:"),
106 :     CGI::ul(CGI::li(\@results)),
107 :     );
108 :     } else {
109 :     print CGI::div({class=>"ResultsWithoutError"},
110 :     CGI::p("All assignments were made successfully."),
111 :     );
112 :     }
113 :     } else {
114 :     print CGI::div({class=>"ResultsWithError"},
115 :     @selected_users ? () : CGI::p("You must select one or more users below."),
116 :     @selected_sets ? () : CGI::p("You must select one or more sets below."),
117 :     );
118 :     }
119 :     }
120 :    
121 : sh002i 1825 my $scrolling_user_list = scrollingRecordList({
122 : toenail 2584 name => "selected_users",
123 :     request => $r,
124 :     default_sort => "lnfn",
125 :     default_format => "lnfn_uid",
126 :     default_filters => ["all"],
127 :     size => 20,
128 :     multiple => 1,
129 :     }, @Users);
130 : sh002i 1825
131 :     my $scrolling_set_list = scrollingRecordList({
132 :     name => "selected_sets",
133 :     request => $r,
134 :     default_sort => "set_id",
135 :     default_format => "set_id",
136 : mschmitt 2196 default_filters => ["all"],
137 : sh002i 1825 size => 20,
138 :     multiple => 1,
139 :     }, @GlobalSets);
140 :    
141 :     print CGI::start_form({method=>"post", action=>$r->uri()});
142 :     print $self->hidden_authen_fields();
143 :    
144 : sh002i 1904 print CGI::table({class=>"FormLayout"},
145 :     CGI::Tr(
146 :     CGI::th("Users"),
147 :     CGI::th("Sets"),
148 :     ),
149 :     CGI::Tr(
150 :     CGI::td($scrolling_user_list),
151 :     CGI::td($scrolling_set_list),
152 :     ),
153 :     CGI::Tr(
154 : sh002i 1944 CGI::td({colspan=>2, class=>"ButtonRow"},
155 : sh002i 1904 CGI::submit(
156 :     -name => "assign",
157 :     -value => "Assign selected sets to selected users",
158 : sh002i 1825 ),
159 :     ),
160 :     ),
161 : toenail 2584 CGI::Tr(
162 :     CGI::td({colspan=>2, class=>"ButtonRow"},
163 :     CGI::submit(
164 :     -name => "unassign",
165 :     -value => "Unassign selected sets from selected users",
166 :     ),
167 :     ),
168 :     ),
169 : sh002i 1825 );
170 : toenail 2584
171 : sh002i 1825
172 : toenail 2584 print CGI::div({-style=>"color:red"}, "Do not unassign students unless you know what you are doing.", CGI::br(),
173 :     "There is NO undo for unassigning students. ");
174 :    
175 :     print CGI::p("When you unassign a student's name, you destroy all
176 : sh002i 3357 of the data for that homework set for that student. You will then need to
177 : toenail 2584 reassign the set(s) to these students and they will receive new versions of the problems.
178 :     Make sure this is what you want to do before unassigning students."
179 :     );
180 :    
181 : sh002i 1825 print CGI::end_form();
182 :    
183 : malsyned 1174 return "";
184 :     }
185 :    
186 :     1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9