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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : malsyned 831 ################################################################################
2 :     # WeBWorK mod_perl (c) 2000-2002 WeBWorK Project
3 :     # $Id$
4 :     ################################################################################
5 :    
6 :     package WeBWorK::ContentGenerator::Instructor::Index;
7 :     use base qw(WeBWorK::ContentGenerator::Instructor);
8 :    
9 :     =head1 NAME
10 :    
11 :     WeBWorK::ContentGenerator::Instructor::Index - Menu interface to the Instructor pages
12 :    
13 :     =cut
14 :    
15 :     use strict;
16 :     use warnings;
17 : gage 1579 use Apache::Constants qw(:common REDIRECT DONE);
18 : malsyned 831 use CGI qw();
19 : gage 1579 sub pre_header_initialize {
20 :     my ($self, $setName, $problemNumber) = @_;
21 :     my $r = $self->{r};
22 :     my $ce = $self->{ce};
23 :     my $db = $self->{db};
24 :     my $authz = $self->{authz};
25 :     my $userName = $r->param('user');
26 :     my $effectiveUserName = $r->param('effectiveUser');
27 :     my $key = $r->param('key');
28 :     my $user = $db->getUser($userName);
29 :     my $effectiveUser = $db->getUser($effectiveUserName);
30 :     my $permissionLevel = $db->getPermissionLevel($userName)->permission();
31 :     unless ($authz->hasPermissions($userName, "modify_student_data")) {
32 :     $self->{submitError} = "You are not authorized to modify student data";
33 :     return;
34 :     }
35 :     my @submit_actions = qw(student-dates act-as-student edit-set-dates reset-password assign-passwords
36 :     set-stats drop-students edit-students-sets edit-sets student-stats edit-class-data
37 :     add-students send-email);
38 :     foreach my $act (@submit_actions) {
39 :     $self->{current_action } .= "The action <$act> "". $r->param($act) . "" was requested"
40 :     if defined($r->param($act));
41 :     }
42 :     $self->{selected_sets} = "Set(s) chosen: " . join(" ", $r->param("setList"));
43 :     $self->{selected_users} = "Student(s) chosen: " .join(" ", $r->param("classList")) ;
44 :     # Redirect actions
45 :     defined($r->param('student-dates')) && do {
46 :     #FIXME will only do one student and one set at a time
47 :     # it would be good to be able to do many sets for many student
48 :     # this would require a separate module
49 :     my $root = $ce->{webworkURLs}->{root};
50 :     my $courseName = $ce->{courseName};
51 :     my @userList = $r->param("classList");
52 :     # can only become the first user listed.
53 :     my $student = shift @userList;
54 :     my @setList = $r->param("setList");
55 :     # can only become the first user listed.
56 :     my $setName = shift @setList;
57 :     my $uri="$root/$courseName/instructor/sets/$setName/?editForUser=$student&".$self->url_authen_args;
58 :     warn "redirect to $uri";
59 :     $r->header_out(Location => $uri);
60 :     $self->{noContent} = 1; # forces redirect
61 :     return;
62 :     };
63 :     defined($r->param('act-as-student')) && do {
64 :     # fix url and redirect
65 :     my @userList = $r->param("classList");
66 :     # can only become the first user listed.
67 :     my $effectiveUser = shift @userList;
68 :     my @setList = $r->param("setList");
69 :     my $setName = shift @setList;
70 :     my $root = $ce->{webworkURLs}->{root};
71 :     my $courseName = $ce->{courseName};
72 : sh002i 1566
73 : gage 1579 my $uri="$root/$courseName/$setName/?effectiveUser=$effectiveUser&".$self->url_authen_args;
74 :     #FIXME does the display mode need to be defined?
75 :     #FIXME url_authen_args also includes an effective user, so the new one must come first.
76 :     # even that might not work with every browser since there are two effective User assignments.
77 :     $r->header_out(Location => $uri);
78 :     $self->{noContent} = 1; # forces redirect
79 :     return;
80 :     };
81 :     defined($r->param('edit-set-dates')) && do {
82 :     #FIXME this should be replaced by redirecting to a module where you can edit
83 :     # dates for several sets at once
84 :     my $root = $ce->{webworkURLs}->{root};
85 :     my $courseName = $ce->{courseName};
86 :     my @setList = $r->param("setList");
87 :     # can only become the first user listed.
88 :     my $setName = shift @setList;
89 :     my $uri="$root/$courseName/instructor/sets/$setName/?".$self->url_authen_args;
90 :     warn "redirect to $uri";
91 :     $r->header_out(Location => $uri);
92 :     $self->{noContent} = 1; # forces redirect
93 :     return;
94 :     };
95 :     defined($r->param('reset-password')) && do {
96 :     # FIXME this should allow me to assign studentID to a number of students
97 :     # requires a new module
98 :     my @userList = $r->param("classList");
99 :     # can only become the first user listed.
100 :     my $effectiveUser = shift @userList;
101 :     my @setList = $r->param("setList");
102 :     my $setName = shift @setList;
103 :     my $root = $ce->{webworkURLs}->{root};
104 :     my $courseName = $ce->{courseName};
105 :    
106 :     my $uri="$root/$courseName/options/?effectiveUser=$effectiveUser&".$self->url_authen_args;
107 :     #FIXME does the display mode need to be defined?
108 :     #FIXME url_authen_args also includes an effective user, so the new one must come first.
109 :     # even that might not work with every browser since there are two effective User assignments.
110 :     $r->header_out(Location => $uri);
111 :     $self->{noContent} = 1; # forces redirect
112 :     return;
113 :     };
114 :     defined($r->param('assign-passwords')) && do {
115 :     my @userList = $r->param("classList");
116 :     # can only become the first user listed.
117 :     my $effectiveUser = shift @userList;
118 :     my @setList = $r->param("setList");
119 :     my $setName = shift @setList;
120 :     my $root = $ce->{webworkURLs}->{root};
121 :     my $courseName = $ce->{courseName};
122 :    
123 :     my $uri="$root/$courseName/options/?effectiveUser=$effectiveUser&".$self->url_authen_args;
124 :     #FIXME does the display mode need to be defined?
125 :     #FIXME url_authen_args also includes an effective user, so the new one must come first.
126 :     # even that might not work with every browser since there are two effective User assignments.
127 :     $r->header_out(Location => $uri);
128 :     $self->{noContent} = 1; # forces redirect
129 :     return;
130 :     };
131 :     defined($r->param('set-stats')) && do {
132 :     my $root = $ce->{webworkURLs}->{root};
133 :     my $courseName = $ce->{courseName};
134 :     my @setList = $r->param("setList");
135 :     # can only become the first user listed.
136 :     my $setName = shift @setList;
137 :     my $uri="$root/$courseName/instructor/stats/set/$setName?".$self->url_authen_args;
138 :     warn "redirect to $uri";
139 :     $r->header_out(Location => $uri);
140 :     $self->{noContent} = 1; # forces redirect
141 :     return;
142 :     };
143 :     defined($r->param('drop-students')) && do {
144 :     #FIXME this operation should be made faster
145 :     my $root = $ce->{webworkURLs}->{root};
146 :     my $courseName = $ce->{courseName};
147 :     my @setList = $r->param("setList");
148 :     # can only become the first user listed.
149 :     my $setName = shift @setList;
150 :     my $uri="$root/$courseName/instructor/users/?".$self->url_authen_args;
151 :     warn "redirect to $uri";
152 :     $r->header_out(Location => $uri);
153 :     $self->{noContent} = 1; # forces redirect
154 :     return;
155 :     };
156 :     defined($r->param('edit-students-sets')) && do {
157 :     my $root = $ce->{webworkURLs}->{root};
158 :     my $courseName = $ce->{courseName};
159 :     my @userList = $r->param("classList");
160 :     # can only become the first user listed.
161 :     my $student = shift @userList;
162 :     my @setList = $r->param("setList");
163 :     # can only become the first user listed.
164 :     my $setName = shift @setList;
165 :     my $uri="$root/$courseName/instructor/sets/$setName/?editForUser=$student&".$self->url_authen_args;
166 :     warn "redirect to $uri";
167 :     $r->header_out(Location => $uri);
168 :     $self->{noContent} = 1; # forces redirect
169 :     return;
170 :     };
171 :     defined($r->param('edit-sets')) && do {
172 :     my $root = $ce->{webworkURLs}->{root};
173 :     my $courseName = $ce->{courseName};
174 :     my @setList = $r->param("setList");
175 :     # can only become the first user listed.
176 :     my $setName = shift @setList;
177 :     my $uri="$root/$courseName/instructor/sets/$setName/?".$self->url_authen_args;
178 :     warn "redirect to $uri";
179 :     $r->header_out(Location => $uri);
180 :     $self->{noContent} = 1; # forces redirect
181 :     return;
182 :     };
183 :     defined($r->param('student-stats')) && do {
184 :     my $root = $ce->{webworkURLs}->{root};
185 :     my $courseName = $ce->{courseName};
186 :     my @userList = $r->param("classList");
187 :     # can only become the first user listed.
188 :     my $studentName = shift @userList;
189 :     my $uri="$root/$courseName/instructor/stats/student/$studentName?".$self->url_authen_args;
190 :     warn "redirect to $uri";
191 :     $r->header_out(Location => $uri);
192 :     $self->{noContent} = 1; # forces redirect
193 :     return;
194 :     };
195 :     defined($r->param('edit-class-data')) && do {
196 :     my $root = $ce->{webworkURLs}->{root};
197 :     my $courseName = $ce->{courseName};
198 :     my @setList = $r->param("setList");
199 :     # can only become the first user listed.
200 :     my $setName = shift @setList;
201 :     my $uri="$root/$courseName/instructor/users/?".$self->url_authen_args;
202 :     warn "redirect to $uri";
203 :     $r->header_out(Location => $uri);
204 :     $self->{noContent} = 1; # forces redirect
205 :     return;
206 :     };
207 :     defined($r->param('add-students')) && do {
208 :     my $root = $ce->{webworkURLs}->{root};
209 :     my $courseName = $ce->{courseName};
210 :    
211 :     my $uri="$root/$courseName/instructor/add_users/?".$self->url_authen_args;
212 :     $r->header_out(Location => $uri);
213 :     $self->{noContent} = 1; # forces redirect
214 :     return;
215 :     };
216 :     defined($r->param('send-email')) && do {
217 :     my $root = $ce->{webworkURLs}->{root};
218 :     my $courseName = $ce->{courseName};
219 :    
220 :     my $uri="$root/$courseName/instructor/send_mail/?".$self->url_authen_args;
221 :     $r->header_out(Location => $uri);
222 :     $self->{noContent} = 1; # forces redirect
223 :     return;
224 :     };
225 :    
226 :    
227 :    
228 :     # unless (substr($current_uri,-1) eq '/') {
229 :     # $r->header_out(Location => "$current_uri/" . ($args ? "?$args" : ""));
230 :     # return REDIRECT;
231 :     # # *** any post data gets lost here -- fix that.
232 :     # # (actually, it's not a problem, since all URLs generated
233 :     # # from within the system have trailing slashes, and we don't
234 :     # # need POST data from outside the system anyway!)
235 :     # }
236 :    
237 :     }
238 :     # override contentGenerator header routine for now
239 :     # FIXME
240 :     sub header {
241 :     my $self = shift;
242 :     return REDIRECT if $self->{noContent};
243 :     my $r = $self->{r};
244 :     $r->content_type('text/html');
245 :     $r->send_http_header();
246 :     return OK;
247 :     }
248 : gage 1486 sub initialize {
249 :     my ($self) = @_;
250 :     my $r = $self->{r};
251 :     my $db = $self->{db};
252 :     my $ce = $self->{ce};
253 :     my $authz = $self->{authz};
254 :     my $user = $r->param('user');
255 : malsyned 831
256 : gage 1486 unless ($authz->hasPermissions($user, "modify_student_data")) {
257 :     $self->{submitError} = "You are not authorized to modify student data";
258 :     return;
259 :     }
260 :    
261 : gage 1579 #############################################################################################
262 :     # gather database data
263 :     #############################################################################################
264 :     # FIXME this might be better done in body? We don't always need all of this data. or do we?
265 :     # Obtaining the list of users
266 :     my @userNames = $db->listUsers;
267 :     my @user_records = $db->getUsers(@userNames);
268 :    
269 :     # store data
270 :     $self->{ra_users} = \@userNames;
271 :     $self->{ra_user_records} = \@user_records;
272 :    
273 :     # Obtaining list of sets:
274 :     my @setNames = $db->listGlobalSets();
275 :     my @set_records = ();
276 :     @set_records = $db->getMergedSets(map {[$user,$_]} @setNames);
277 :     # foreach my $name (@setNames) {
278 :     # my $set_record;
279 :     # $set_record = $db->getMergedSet($user,$name,) ;
280 :     #
281 :     # #warn "Adding set $name", ref($set_record);
282 :     # push @set_records, $set_record;
283 :     # }
284 :    
285 :    
286 :     # store data
287 :     $self->{ra_sets} = \@setNames;
288 :     $self->{ra_set_records} = \@set_records;
289 :    
290 : gage 1486 }
291 : gage 1295 sub path {
292 : gage 1579 my $self = shift;
293 :     my $args = $_[-1];
294 :    
295 : gage 1295 my $ce = $self->{ce};
296 :     my $root = $ce->{webworkURLs}->{root};
297 :     my $courseName = $ce->{courseName};
298 :     return $self->pathMacro($args,
299 : gage 1579 "Home" => "$root",
300 :     $courseName => "$root/$courseName",
301 :     'instructor' => '',
302 : gage 1295 );
303 :     }
304 :    
305 : malsyned 831 sub title {
306 :     my $self = shift;
307 : gage 1579 return "Instructor tools for ".$self->{ce}->{courseName};
308 : malsyned 831 }
309 :    
310 :     sub body {
311 :     my $self = shift;
312 : malsyned 834 my $r = $self->{r};
313 :     my $ce = $self->{ce};
314 : malsyned 1017 my $db = $self->{db};
315 :     my $authz = $self->{authz};
316 : malsyned 834 my $courseName = $ce->{courseName};
317 :     my $authen_args = $self->url_authen_args();
318 : malsyned 1017 my $user = $r->param('user');
319 : malsyned 834 my $prof_url = $ce->{webworkURLs}->{oldProf};
320 :     my $full_url = "$prof_url?course=$courseName&$authen_args";
321 : malsyned 996 my $userEditorURL = "users/?" . $self->url_args;
322 : malsyned 998 my $problemSetEditorURL = "sets/?" . $self->url_args;
323 : gage 1433 my $statsURL = "stats/?" . $self->url_args;
324 :     my $emailURL = "send_mail/?" . $self->url_args;
325 : gage 1023 ################### debug code
326 : gage 1579 # my $permissonLevel = $self->{db}->getPermissionLevel($user)->permission();
327 :     #
328 :     # my $courseEnvironmentLevels = $self->{ce}->{permissionLevels};
329 :     # return CGI::em(" user $permissonLevel permlevels ".join("<>",%$courseEnvironmentLevels));
330 : gage 1023 ################### debug code
331 : gage 1579 return CGI::em('You are not authorized to access the Instructor tools.') unless $authz->hasPermissions($user, 'access_instructor_tools');
332 :     my $actionURL= $r->uri;
333 : gage 1433 return join("",
334 : gage 1579 #defined($self->{current_action}) ? CGI::h4($self->{current_action}) :'' ,
335 :     #defined($self->{selected_users}) ? CGI::p($self->{selected_users}) : '',
336 :     #defined($self->{selected_sets}) ? CGI::p($self->{selected_sets}) : '',
337 :     CGI::a({href=>$full_url},"Link to WeBWorK 1.9 Instructor tools"),
338 :     CGI::start_form(-method=>"POST", -action=>$actionURL),"\n",
339 :     $self->hidden_authen_fields,"\n",
340 :     CGI::start_table({-border=>2,-cellpadding=>5}),
341 :     CGI::Tr({ -align=>'center'},
342 :     CGI::td({colspan=>2},[
343 :     CGI::input({type=>'submit',value=>'Add students...',name=>'add-students'}),
344 :     CGI::input({type=>'submit',value=>'Send email...',name=>'send-email'}),
345 :     ]
346 : gage 1433 ),
347 : gage 1579
348 :    
349 :     ),
350 :     CGI::Tr({ -align=>'center'},
351 :     CGI::td({colspan=>1},[
352 : gage 1433
353 : gage 1579 CGI::input({type=>'submit',value=>'Reset password',name=>'reset-password'}),
354 :     CGI::input({type=>'submit',value=>'Assign passwords...',name=>'assign-passwords'}),
355 :     CGI::input({type=>'submit',value=>'View set statistics...',name=>'set-stats'}),
356 :     CGI::input({type=>'submit',value=>'Edit set(s) dates...',name=>'edit-set-dates'})
357 :     ]
358 :     )
359 :    
360 :     ),
361 :     CGI::Tr({ -align=>'center'},
362 :     CGI::td({colspan=>1},[
363 :     CGI::input({type=>'submit',value=>'View student statistics...',name=>'student-stats'}),
364 :     CGI::input({type=>'submit',value=>'Edit class data for students...',name=>'edit-class-data'}),
365 :     CGI::input({type=>'submit',value=>'Edit set(s) data...',name=>'edit-sets'}),
366 :     '&nbsp;'
367 :     ]
368 : sh002i 1566 ),
369 : gage 1433 ),
370 : gage 1579
371 :    
372 : gage 1433 CGI::Tr({ -align=>'center'},
373 : gage 1579 CGI::td({colspan=>2},[
374 :     $self->popup_user_form,
375 :     $self->popup_set_form,
376 :     ]
377 :     )
378 :    
379 : gage 1433 ),
380 :     CGI::Tr({ -align=>'center'},
381 : gage 1579 CGI::td({colspan=>1},[
382 :    
383 :     CGI::input({type=>'submit',value=>'Edit student(s)/set(s) dates',name=>'student-dates'}),
384 :     CGI::input({type=>'submit',value=>'Act as student in set...',name=>'act-as-student'}),
385 :     ]
386 :     ),
387 :     CGI::td({colspan=>2},
388 :     CGI::input({type=>'submit',value=>'Edit student(s) data for set(s)...',name=>'edit-students-sets'}),
389 :    
390 :     )
391 :    
392 : gage 1433 ),
393 : gage 1579
394 :     CGI::Tr({ -align=>'center'},
395 :     CGI::td({colspan=>2},[
396 :     CGI::input({type=>'submit',value=>'Drop student(s)',name=>'drop-students'}),
397 :     '&nbsp;'
398 :     ]
399 :     ),
400 :    
401 : gage 1433
402 : gage 1579 ),
403 :    
404 : gage 1433 CGI::end_table(),
405 : gage 1579 CGI::end_form(),
406 :     # CGI::hr(),
407 :     # CGI::p( defined($self->{studentEntryReport}) ? $self->{studentEntryReport}:''
408 :     # ),
409 :     #
410 :     # $self->addStudentForm,
411 : gage 1433 );
412 : malsyned 831 }
413 : gage 1486 sub addStudentForm {
414 :     my $self = shift;
415 :     my $r = $self->{r};
416 :    
417 :     # Add a student form
418 : gage 1579 join( "",
419 : gage 1486 CGI::p("Add new students"),
420 :     CGI::start_form({method=>"post", action=>$r->uri()}),
421 :     $self->hidden_authen_fields(),
422 :     CGI::start_table({border=>'1', cellpadding=>'2'}),
423 :     CGI::Tr({},
424 :     CGI::th({},
425 :     ['Last Name', 'First Name', 'Student ID', 'Login Name', 'Email Address', 'Section','Recitation', 'Comment']
426 :     )
427 :     ),
428 :     CGI::Tr({},
429 :     CGI::td({},
430 :     [ CGI::input({name=>'last_name'}),
431 :     CGI::input({name=>'first_name'}),
432 :     CGI::input({name=>'student_id',size=>'16'}),
433 :     CGI::input({name=>'new_user_id',size=>'10'}),
434 :     CGI::input({name=>'email_address'}),
435 :     CGI::input({name=>'section',size=>'10'}),
436 :     CGI::input({name=>'recitation',size=>'10'}),
437 :     CGI::input({name=>'comment'}),
438 :    
439 :    
440 :     ]
441 :     )
442 :     ),
443 :     CGI::end_table(),
444 :     CGI::submit({name=>"addStudent", value=>"Add Student"}),
445 :     CGI::end_form(),
446 :     );
447 : gage 1579
448 :    
449 :    
450 :    
451 :    
452 :    
453 : gage 1486 }
454 : gage 1579 sub popup_user_form {
455 :     my $self = shift;
456 :     my $r = $self->{r};
457 :     my $authz = $self->{authz};
458 :     my $user = $r->param('user');
459 :     my $db = $self->{db};
460 :     my $ce = $self->{ce};
461 :     my $root = $ce->{webworkURLs}->{root};
462 :     my $courseName = $ce->{courseName};
463 : sh002i 1566
464 : gage 1579 # return CGI::em("You are not authorized to access the Instructor tools.") unless $authz->hasPermissions($user, "access_instructor_tools");
465 :    
466 :     # This code will require changing if the permission and user tables ever have different keys.
467 :     my @users = ();
468 :     my $ra_user_records = $self->{ra_user_records};
469 :     my %classlistLabels = ();# %$hr_classlistLabels;
470 :     my @user_records = sort { ( lc($a->section) cmp lc($b->section) ) ||
471 :     ( lc($a->last_name) cmp lc($b->last_name )) } @{$ra_user_records};
472 :     foreach my $ur (@{user_records}) {
473 :     $classlistLabels{$ur->user_id} = $ur->last_name. ', '. $ur->first_name.' - '.$ur->section.' '.$ur->user_id;
474 :     push(@users, $ur->user_id);
475 :     }
476 :     return CGI::popup_menu(-name=>'classList',
477 :     -values=>\@users,
478 :     -labels=>\%classlistLabels,
479 :     -size => 10,
480 :     -multiple => 1,
481 :     -default=>$user
482 :     ),
483 :    
484 :    
485 :     }
486 :     sub popup_set_form {
487 :     my $self = shift;
488 :     my $r = $self->{r};
489 :     my $authz = $self->{authz};
490 :     my $user = $r->param('user');
491 :     my $db = $self->{db};
492 :     my $ce = $self->{ce};
493 :     my $root = $ce->{webworkURLs}->{root};
494 :     my $courseName = $ce->{courseName};
495 :    
496 :     # return CGI::em("You are not authorized to access the Instructor tools.") unless $authz->hasPermissions($user, "access_instructor_tools");
497 :    
498 :     # This code will require changing if the permission and user tables ever have different keys.
499 :     my @setNames = ();
500 :     my $ra_set_records = $self->{ra_set_records};
501 :     my %setLabels = ();# %$hr_classlistLabels;
502 :     my @set_records = sort {$a->set_id cmp $b->set_id } @{$ra_set_records};
503 :     foreach my $sr (@set_records) {
504 :     $setLabels{$sr->set_id} = $sr->set_id;
505 :     push(@setNames, $sr->set_id); # reorder sets
506 :     }
507 :     return CGI::popup_menu(-name=>'setList',
508 :     -values=>\@setNames,
509 :     -labels=>\%setLabels,
510 :     -size => 10,
511 :     -multiple => 1,
512 :     #-default=>$user
513 :     ),
514 :    
515 :    
516 :     }
517 : malsyned 831 1;
518 :    
519 :     __END__
520 :    
521 :     =head1 AUTHOR
522 :    
523 :     Written by Dennis Lambe Jr., malsyned (at) math.rochester.edu
524 :    
525 :     =cut

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9