Parent Directory
|
Revision Log
This module is a candidate to replace the Index.pm page and module. The displayed "control panel" is set up. Only the "become student" control works right at the moment. You can access it by replacing instructor by instructor2 in the url for the instructor index page. --Mike
1 ################################################################################ 2 # WeBWorK mod_perl (c) 2000-2002 WeBWorK Project 3 # $Id$ 4 ################################################################################ 5 6 package WeBWorK::ContentGenerator::Instructor::Index2; 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 use Apache::Constants qw(:common REDIRECT DONE); 18 use CGI qw(); 19 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('act-as-student')) && do { 46 # fix url and redirect 47 my @userList = $r->param("classList"); 48 # can only become the first user listed. 49 my $effectiveUser = shift @userList; 50 my @setList = $r->param("setList"); 51 my $setName = shift @setList; 52 my $root = $ce->{webworkURLs}->{root}; 53 my $courseName = $ce->{courseName}; 54 55 my $uri="$root/$courseName/$setName/?effectiveUser=$effectiveUser&".$self->url_authen_args; 56 #FIXME does the display mode need to be defined? 57 #FIXME url_authen_args also includes an effective user, so the new one must come first. 58 # even that might not work with every browser since there are two effective User assignments. 59 $r->header_out(Location => $uri); 60 $self->{noContent} = 1; # forces redirect 61 #return REDIRECT; 62 }; 63 64 # unless (substr($current_uri,-1) eq '/') { 65 # $r->header_out(Location => "$current_uri/" . ($args ? "?$args" : "")); 66 # return REDIRECT; 67 # # *** any post data gets lost here -- fix that. 68 # # (actually, it's not a problem, since all URLs generated 69 # # from within the system have trailing slashes, and we don't 70 # # need POST data from outside the system anyway!) 71 # } 72 73 } 74 # override contentGenerator header routine for now 75 # FIXME 76 sub header { 77 my $self = shift; 78 return REDIRECT if $self->{noContent}; 79 my $r = $self->{r}; 80 $r->content_type('text/html'); 81 $r->send_http_header(); 82 return OK; 83 } 84 sub initialize { 85 my ($self) = @_; 86 my $r = $self->{r}; 87 my $db = $self->{db}; 88 my $ce = $self->{ce}; 89 my $authz = $self->{authz}; 90 my $user = $r->param('user'); 91 92 unless ($authz->hasPermissions($user, "modify_student_data")) { 93 $self->{submitError} = "You are not authorized to modify student data"; 94 return; 95 } 96 97 ############################################################################################# 98 # gather database data 99 ############################################################################################# 100 # FIXME this might be better done in body? We don't always need all of this data. or do we? 101 # Obtaining the list of users 102 my @userNames = $db->listUsers; 103 my @user_records = $db->getUsers(@userNames); 104 105 # store data 106 $self->{ra_users} = \@userNames; 107 $self->{ra_user_records} = \@user_records; 108 109 # Obtaining list of sets: 110 my @setNames = $db->listGlobalSets(); 111 my @set_records = (); 112 @set_records = $db->getMergedSets(map {[$user,$_]} @setNames); 113 # foreach my $name (@setNames) { 114 # my $set_record; 115 # $set_record = $db->getMergedSet($user,$name,) ; 116 # 117 # #warn "Adding set $name", ref($set_record); 118 # push @set_records, $set_record; 119 # } 120 121 122 # store data 123 $self->{ra_sets} = \@setNames; 124 $self->{ra_set_records} = \@set_records; 125 126 } 127 sub path { 128 my $self = shift; 129 my $args = $_[-1]; 130 131 my $ce = $self->{ce}; 132 my $root = $ce->{webworkURLs}->{root}; 133 my $courseName = $ce->{courseName}; 134 return $self->pathMacro($args, 135 "Home" => "$root", 136 $courseName => "$root/$courseName", 137 'instructor' => '', 138 ); 139 } 140 141 sub title { 142 my $self = shift; 143 return "Instructor tools for ".$self->{ce}->{courseName}; 144 } 145 146 sub body { 147 my $self = shift; 148 my $r = $self->{r}; 149 my $ce = $self->{ce}; 150 my $db = $self->{db}; 151 my $authz = $self->{authz}; 152 my $courseName = $ce->{courseName}; 153 my $authen_args = $self->url_authen_args(); 154 my $user = $r->param('user'); 155 my $prof_url = $ce->{webworkURLs}->{oldProf}; 156 my $full_url = "$prof_url?course=$courseName&$authen_args"; 157 my $userEditorURL = "users/?" . $self->url_args; 158 my $problemSetEditorURL = "sets/?" . $self->url_args; 159 my $statsURL = "stats/?" . $self->url_args; 160 my $emailURL = "send_mail/?" . $self->url_args; 161 ################### debug code 162 # my $permissonLevel = $self->{db}->getPermissionLevel($user)->permission(); 163 # 164 # my $courseEnvironmentLevels = $self->{ce}->{permissionLevels}; 165 # return CGI::em(" user $permissonLevel permlevels ".join("<>",%$courseEnvironmentLevels)); 166 ################### debug code 167 return CGI::em('You are not authorized to access the Instructor tools.') unless $authz->hasPermissions($user, 'access_instructor_tools'); 168 my $actionURL= $r->uri; 169 return join("", 170 defined($self->{current_action}) ? CGI::h4($self->{current_action}) :'' , 171 defined($self->{selected_users}) ? CGI::p($self->{selected_users}) : '', 172 defined($self->{selected_sets}) ? CGI::p($self->{selected_sets}) : '', 173 CGI::start_form(-method=>"POST", -action=>$actionURL),"\n", 174 $self->hidden_authen_fields,"\n", 175 CGI::start_table({-border=>2,-cellpadding=>5}), 176 CGI::Tr({ -align=>'center'}, 177 CGI::td({colspan=>2},[ 178 CGI::input({type=>'submit',value=>'Add students...',name=>'add-students'}), 179 CGI::input({type=>'submit',value=>'Send email...',name=>'send-email'}), 180 ] 181 ), 182 183 184 ), 185 CGI::Tr({ -align=>'center'}, 186 CGI::td({colspan=>1},[ 187 188 CGI::input({type=>'submit',value=>'Reset password',name=>'reset-password'}), 189 CGI::input({type=>'submit',value=>'Assign passwords...',name=>'assign-passwords'}), 190 CGI::input({type=>'submit',value=>'View set statistics...',name=>'set-stats'}), 191 CGI::input({type=>'submit',value=>'Edit set(s) dates...',name=>'edit-set-dates'}) 192 ] 193 ) 194 195 ), 196 CGI::Tr({ -align=>'center'}, 197 CGI::td({colspan=>1},[ 198 CGI::input({type=>'submit',value=>'View student statistics...',name=>'student-stats'}), 199 CGI::input({type=>'submit',value=>'Edit class data for students...',name=>'edit-class-data'}), 200 CGI::input({type=>'submit',value=>'Edit set(s) data...',name=>'edit-sets'}), 201 ' ' 202 ] 203 ), 204 ), 205 206 207 CGI::Tr({ -align=>'center'}, 208 CGI::td({colspan=>2},[ 209 $self->popup_user_form, 210 $self->popup_set_form, 211 ] 212 ) 213 214 ), 215 CGI::Tr({ -align=>'center'}, 216 CGI::td({colspan=>1},[ 217 218 CGI::input({type=>'submit',value=>'Edit student(s)/set(s) dates',name=>'student-dates'}), 219 CGI::input({type=>'submit',value=>'Act as student in set...',name=>'act-as-student'}), 220 ] 221 ), 222 CGI::td({colspan=>2}, 223 CGI::input({type=>'submit',value=>'Edit student(s) data for set(s)...',name=>'edit-students-sets'}), 224 225 ) 226 227 ), 228 229 CGI::Tr({ -align=>'center'}, 230 CGI::td({colspan=>2},[ 231 CGI::input({type=>'submit',value=>'Drop student(s)',name=>'drop-students'}), 232 ' ' 233 ] 234 ), 235 236 237 ), 238 239 CGI::end_table(), 240 CGI::end_form(), 241 # CGI::hr(), 242 # CGI::p( defined($self->{studentEntryReport}) ? $self->{studentEntryReport}:'' 243 # ), 244 # 245 # $self->addStudentForm, 246 ); 247 } 248 sub addStudentForm { 249 my $self = shift; 250 my $r = $self->{r}; 251 252 # Add a student form 253 join( "", 254 CGI::p("Add new students"), 255 CGI::start_form({method=>"post", action=>$r->uri()}), 256 $self->hidden_authen_fields(), 257 CGI::start_table({border=>'1', cellpadding=>'2'}), 258 CGI::Tr({}, 259 CGI::th({}, 260 ['Last Name', 'First Name', 'Student ID', 'Login Name', 'Email Address', 'Section','Recitation', 'Comment'] 261 ) 262 ), 263 CGI::Tr({}, 264 CGI::td({}, 265 [ CGI::input({name=>'last_name'}), 266 CGI::input({name=>'first_name'}), 267 CGI::input({name=>'student_id',size=>'16'}), 268 CGI::input({name=>'new_user_id',size=>'10'}), 269 CGI::input({name=>'email_address'}), 270 CGI::input({name=>'section',size=>'10'}), 271 CGI::input({name=>'recitation',size=>'10'}), 272 CGI::input({name=>'comment'}), 273 274 275 ] 276 ) 277 ), 278 CGI::end_table(), 279 CGI::submit({name=>"addStudent", value=>"Add Student"}), 280 CGI::end_form(), 281 ); 282 283 284 285 286 287 288 } 289 sub popup_user_form { 290 my $self = shift; 291 my $r = $self->{r}; 292 my $authz = $self->{authz}; 293 my $user = $r->param('user'); 294 my $db = $self->{db}; 295 my $ce = $self->{ce}; 296 my $root = $ce->{webworkURLs}->{root}; 297 my $courseName = $ce->{courseName}; 298 299 # return CGI::em("You are not authorized to access the Instructor tools.") unless $authz->hasPermissions($user, "access_instructor_tools"); 300 301 # This code will require changing if the permission and user tables ever have different keys. 302 my @users = (); 303 my $ra_user_records = $self->{ra_user_records}; 304 my %classlistLabels = ();# %$hr_classlistLabels; 305 my @user_records = sort { ( lc($a->section) cmp lc($b->section) ) || 306 ( lc($a->last_name) cmp lc($b->last_name )) } @{$ra_user_records}; 307 foreach my $ur (@{user_records}) { 308 $classlistLabels{$ur->user_id} = $ur->last_name. ', '. $ur->first_name.' - '.$ur->section.' '.$ur->user_id; 309 push(@users, $ur->user_id); 310 } 311 return CGI::popup_menu(-name=>'classList', 312 -values=>\@users, 313 -labels=>\%classlistLabels, 314 -size => 10, 315 -multiple => 1, 316 -default=>$user 317 ), 318 319 320 } 321 sub popup_set_form { 322 my $self = shift; 323 my $r = $self->{r}; 324 my $authz = $self->{authz}; 325 my $user = $r->param('user'); 326 my $db = $self->{db}; 327 my $ce = $self->{ce}; 328 my $root = $ce->{webworkURLs}->{root}; 329 my $courseName = $ce->{courseName}; 330 331 # return CGI::em("You are not authorized to access the Instructor tools.") unless $authz->hasPermissions($user, "access_instructor_tools"); 332 333 # This code will require changing if the permission and user tables ever have different keys. 334 my @setNames = (); 335 my $ra_set_records = $self->{ra_set_records}; 336 my %setLabels = ();# %$hr_classlistLabels; 337 my @set_records = sort {$a->set_id cmp $b->set_id } @{$ra_set_records}; 338 foreach my $sr (@set_records) { 339 $setLabels{$sr->set_id} = $sr->set_id; 340 push(@setNames, $sr->set_id); # reorder sets 341 } 342 return CGI::popup_menu(-name=>'setList', 343 -values=>\@setNames, 344 -labels=>\%setLabels, 345 -size => 10, 346 -multiple => 1, 347 #-default=>$user 348 ), 349 350 351 } 352 1; 353 354 __END__ 355 356 =head1 AUTHOR 357 358 Written by Dennis Lambe Jr., malsyned (at) math.rochester.edu 359 360 =cut
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |