Parent Directory
|
Revision Log
preliminary web-based course creation support try it -- create a course called "admin" the usual way and then visit it in your browser.
1 ################################################################################ 2 # WeBWorK Online Homework Delivery System 3 # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ 4 # $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/AddUsers.pm,v 1.11 2004/03/28 03:25:47 gage 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::AddUsers; 18 use base qw(WeBWorK::ContentGenerator::Instructor); 19 20 =head1 NAME 21 22 WeBWorK::ContentGenerator::Instructor::AddUsers - Menu interface for adding users 23 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 $db = $r->db; 35 my $ce = $r->ce; 36 my $authz = $r->authz; 37 38 my $user = $r->param('user'); 39 40 unless ($authz->hasPermissions($user, "modify_student_data")) { 41 $self->{submitError} = "You are not authorized to modify student data"; 42 return; 43 } 44 45 if (defined($r->param('addStudents'))) { 46 my @userIDs; 47 my $numberOfStudents = $r->param('number_of_students'); 48 warn "Internal error -- the number of students to be added has not been included" unless defined $numberOfStudents; 49 foreach my $i (1..$numberOfStudents) { 50 my $new_user_id = $r->param("new_user_id_$i"); 51 next unless defined($new_user_id) and $new_user_id; 52 push @userIDs, $new_user_id; 53 54 my $newUser = $db->newUser; 55 my $newPermissionLevel = $db->newPermissionLevel; 56 my $newPassword = $db->newPassword; 57 $newUser->user_id($new_user_id); 58 $newPermissionLevel->user_id($new_user_id); 59 $newPassword->user_id($new_user_id); 60 $newUser->last_name($r->param("last_name_$i")); 61 $newUser->first_name($r->param("first_name_$i")); 62 $newUser->student_id($r->param("student_id_$i")); 63 $newUser->email_address($r->param("email_address_$i")); 64 $newUser->section($r->param("section_$i")); 65 $newUser->recitation($r->param("recitation_$i")); 66 $newUser->comment($r->param("comment_$i")); 67 $newUser->status('C'); 68 $newPermissionLevel->permission(0); 69 #FIXME handle errors if user exists already 70 eval { $db->addUser($newUser) }; 71 if ($@) { 72 my $addError = $@; 73 $self->{studentEntryReport} .= join("", 74 CGI::b("Failed to enter student: "), $newUser->last_name, ", ",$newUser->first_name, 75 CGI::b(", login/studentID: "), $newUser->user_id, "/",$newUser->student_id, 76 CGI::b(", email: "), $newUser->email_address, 77 CGI::b(", section: "), $newUser->section, 78 CGI::br(), CGI::b("Error message: "), $addError, 79 CGI::hr(),CGI::br(), 80 ); 81 } else { 82 $db->addPermissionLevel($newPermissionLevel); 83 $db->addPassword($newPassword); 84 $self->{studentEntryReport} .= join("", 85 CGI::b("Entered student: "), $newUser->last_name, ", ",$newUser->first_name, 86 CGI::b(", login/studentID: "), $newUser->user_id, "/",$newUser->student_id, 87 CGI::b(", email: "), $newUser->email_address, 88 CGI::b(", section: "), $newUser->section,CGI::hr(),CGI::br(), 89 90 ); 91 } 92 } 93 if (defined $r->param("assignSets")) { 94 my @setIDs = $r->param("assignSets"); 95 if (@setIDs) { 96 $self->assignSetsToUsers(\@setIDs, \@userIDs); 97 } 98 } 99 } 100 } 101 102 sub body { 103 my ($self) = @_; 104 my $r = $self->r; 105 my $ce = $r->ce; 106 my $db = $r->db; 107 my $authz = $r->authz; 108 109 my $courseName = $r->urlpath->arg("courseID"); 110 my $authen_args = $self->url_authen_args(); 111 my $user = $r->param('user'); 112 113 ################### debug code 114 #my $permissonLevel = $self->{db}->getPermissionLevel($user)->permission(); #checked 115 #my $courseEnvironmentLevels = $self->{ce}->{permissionLevels}; 116 #return CGI::em(" user $permissonLevel permlevels ".join("<>",%$courseEnvironmentLevels)); 117 ################### debug code 118 119 return CGI::em('You are not authorized to access the Instructor tools.') 120 unless $authz->hasPermissions($user, 'access_instructor_tools'); 121 122 return join("", 123 124 CGI::hr(), 125 CGI::p( 126 defined($self->{studentEntryReport}) 127 ? $self->{studentEntryReport} 128 : '' 129 ), 130 CGI::p("Enter information below for students you wish to add. Each student's password will initially be set to their student ID."), 131 $self->addStudentForm, 132 ); 133 } 134 135 sub addStudentForm { 136 my $self = shift; 137 my $r = $self->r; 138 my $db = $r->db; 139 my $ce = $r->ce; 140 my $numberOfStudents = $r->param("number_of_students") || 5; 141 142 143 144 # Add a student form 145 146 my @entryLines = (); 147 foreach my $i (1..$numberOfStudents) { 148 push( @entryLines, 149 CGI::Tr({}, 150 CGI::td({}, 151 [ CGI::input({name=>"last_name_$i"}), 152 CGI::input({name=>"first_name_$i"}), 153 CGI::input({name=>"student_id_$i",size=>"16"}), 154 CGI::input({name=>"new_user_id_$i",size=>"10"}), 155 CGI::input({name=>"email_address_$i"}), 156 CGI::input({name=>"section_$i",size=>"10"}), 157 CGI::input({name=>"recitation_$i",size=>"10"}), 158 CGI::input({name=>"comment_$i"}), 159 ] 160 ) 161 ),"\n", 162 ); 163 } 164 165 return join("", 166 CGI::start_form({method=>"post", action=>$r->uri(),name=>"add_users"}), 167 $self->hidden_authen_fields(),"\n", 168 CGI::submit(-name=>"Create", -value=>"Create")," ","\n", 169 CGI::input({type=>'text', name=>'number_of_students', value=>$numberOfStudents,size => 3}), " entry rows. ","\n", 170 CGI::end_form(),"\n", 171 CGI::hr(), 172 173 CGI::start_form({method=>"post", action=>$r->uri()}), 174 $self->hidden_authen_fields(), 175 CGI::input({type=>'hidden', name => "number_of_students", value => $numberOfStudents}), 176 CGI::start_table({border=>'1', cellpadding=>'2'}), 177 CGI::Tr({}, 178 CGI::th({}, 179 ['Last Name', 'First Name', 'Student ID', 'Login Name', 'Email Address', 'Section','Recitation', 'Comment'] 180 ) 181 ), 182 @entryLines, 183 CGI::end_table(), 184 185 186 187 CGI::p("Select sets below to assign them to the newly-created users."), 188 CGI::popup_menu( 189 -name => "assignSets", 190 -values => [ $db->listGlobalSets ], 191 -size => 10, 192 -multiple => "multiple", 193 ), 194 CGI::p( 195 CGI::submit({name=>"addStudents", value=>"Add Students"}), 196 ), 197 CGI::end_form(), 198 199 #qq{ <div style="color:red"> After entering new students you will still 200 #need to assign sets to them. This is done from the "set list" page. <br> 201 #Click on the entry "xx users" in 202 #the "assigned to" column at the far right. <br> Then click either "assign to all" 203 #or check individual users and click "save" at the bottom. </div> 204 #Soon ( real soon -- honest!!! :-) ) you will also be able to assign sets to the students as they are entered from this page. } 205 ); 206 } 207 208 1; 209 210 __END__ 211 212 =head1 AUTHOR 213 214 Written by Dennis Lambe Jr., malsyned (at) math.rochester.edu 215 216 =cut
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |