Parent Directory
|
Revision Log
CAUTION. Major update!!! Modifications made up until the release of 2.0 on July 16, 2004 on the 2.0 branch have been incorporated into version 2.1 alpha 1. A moderate amount of testing has been done. It will take some time to reconfigure your global.conf file once you update to this version.
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/AddUsers.pm,v 1.15 2004/06/14 18:04:33 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::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 use WeBWorK::Utils qw/cryptPassword/; 31 32 sub initialize { 33 my ($self) = @_; 34 my $r = $self->r; 35 my $db = $r->db; 36 my $ce = $r->ce; 37 my $authz = $r->authz; 38 39 my $user = $r->param('user'); 40 41 # Check permissions 42 return unless ($authz->hasPermissions($user, "access_instructor_tools")); 43 return unless ($authz->hasPermissions($user, "modify_student_data")); 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 my $new_password = cryptPassword($r->param("student_id_$i")); 52 next unless defined($new_user_id) and $new_user_id; 53 push @userIDs, $new_user_id; 54 55 my $newUser = $db->newUser; 56 my $newPermissionLevel = $db->newPermissionLevel; 57 my $newPassword = $db->newPassword; 58 $newUser->user_id($new_user_id); 59 $newPermissionLevel->user_id($new_user_id); 60 $newPassword->user_id($new_user_id); 61 $newPassword->password($new_password); 62 $newUser->last_name($r->param("last_name_$i")); 63 $newUser->first_name($r->param("first_name_$i")); 64 $newUser->student_id($r->param("student_id_$i")); 65 $newUser->email_address($r->param("email_address_$i")); 66 $newUser->section($r->param("section_$i")); 67 $newUser->recitation($r->param("recitation_$i")); 68 $newUser->comment($r->param("comment_$i")); 69 $newUser->status('C'); 70 $newPermissionLevel->permission(0); 71 #FIXME handle errors if user exists already 72 eval { $db->addUser($newUser) }; 73 if ($@) { 74 my $addError = $@; 75 $self->{studentEntryReport} .= join("", 76 CGI::b("Failed to enter student: "), $newUser->last_name, ", ",$newUser->first_name, 77 CGI::b(", login/studentID: "), $newUser->user_id, "/",$newUser->student_id, 78 CGI::b(", email: "), $newUser->email_address, 79 CGI::b(", section: "), $newUser->section, 80 CGI::br(), CGI::b("Error message: "), $addError, 81 CGI::hr(),CGI::br(), 82 ); 83 } else { 84 $db->addPermissionLevel($newPermissionLevel); 85 $db->addPassword($newPassword); 86 $self->{studentEntryReport} .= join("", 87 CGI::b("Entered student: "), $newUser->last_name, ", ",$newUser->first_name, 88 CGI::b(", login/studentID: "), $newUser->user_id, "/",$newUser->student_id, 89 CGI::b(", email: "), $newUser->email_address, 90 CGI::b(", section: "), $newUser->section,CGI::hr(),CGI::br(), 91 92 ); 93 } 94 } 95 if (defined $r->param("assignSets")) { 96 my @setIDs = $r->param("assignSets"); 97 if (@setIDs) { 98 $self->assignSetsToUsers(\@setIDs, \@userIDs); 99 } 100 } 101 } 102 } 103 104 sub body { 105 my ($self) = @_; 106 my $r = $self->r; 107 my $ce = $r->ce; 108 my $db = $r->db; 109 my $authz = $r->authz; 110 111 my $courseName = $r->urlpath->arg("courseID"); 112 my $authen_args = $self->url_authen_args(); 113 my $user = $r->param('user'); 114 115 # Check permissions 116 return CGI::div({class=>"ResultsWithError"}, "You are not authorized to access the Instructor tools.") 117 unless $authz->hasPermissions($r->param("user"), "access_instructor_tools"); 118 119 return CGI::div({class=>"ResultsWithError"}, "You are not authorized to modify student data.") 120 unless $authz->hasPermissions($r->param("user"), "modify_student_data"); 121 122 123 return join("", 124 125 CGI::hr(), 126 CGI::p( 127 defined($self->{studentEntryReport}) 128 ? $self->{studentEntryReport} 129 : '' 130 ), 131 CGI::p("Enter information below for students you wish to add. Each student's password will initially be set to their student ID."), 132 $self->addStudentForm, 133 ); 134 } 135 136 sub addStudentForm { 137 my $self = shift; 138 my $r = $self->r; 139 my $db = $r->db; 140 my $ce = $r->ce; 141 my $numberOfStudents = $r->param("number_of_students") || 5; 142 143 144 145 # Add a student form 146 147 my @entryLines = (); 148 foreach my $i (1..$numberOfStudents) { 149 push( @entryLines, 150 CGI::Tr({}, 151 CGI::td({}, 152 [ CGI::input({name=>"last_name_$i"}), 153 CGI::input({name=>"first_name_$i"}), 154 CGI::input({name=>"student_id_$i",size=>"16"}), 155 CGI::input({name=>"new_user_id_$i",size=>"10"}), 156 CGI::input({name=>"email_address_$i"}), 157 CGI::input({name=>"section_$i",size=>"10"}), 158 CGI::input({name=>"recitation_$i",size=>"10"}), 159 CGI::input({name=>"comment_$i"}), 160 ] 161 ) 162 ),"\n", 163 ); 164 } 165 166 return join("", 167 CGI::start_form({method=>"post", action=>$r->uri(),name=>"add_users"}), 168 $self->hidden_authen_fields(),"\n", 169 CGI::submit(-name=>"Create", -value=>"Create")," ","\n", 170 CGI::input({type=>'text', name=>'number_of_students', value=>$numberOfStudents,size => 3}), " entry rows. ","\n", 171 CGI::end_form(),"\n", 172 CGI::hr(), 173 174 CGI::start_form({method=>"post", action=>$r->uri()}), 175 $self->hidden_authen_fields(), 176 CGI::input({type=>'hidden', name => "number_of_students", value => $numberOfStudents}), 177 CGI::start_table({border=>'1', cellpadding=>'2'}), 178 CGI::Tr({}, 179 CGI::th({}, 180 ['Last Name', 'First Name', 'Student ID', 'Login Name', 'Email Address', 'Section','Recitation', 'Comment'] 181 ) 182 ), 183 @entryLines, 184 CGI::end_table(), 185 186 187 188 CGI::p("Select sets below to assign them to the newly-created users."), 189 CGI::popup_menu( 190 -name => "assignSets", 191 -values => [ $db->listGlobalSets ], 192 -size => 10, 193 -multiple => "multiple", 194 ), 195 CGI::p( 196 CGI::submit({name=>"addStudents", value=>"Add Students"}), 197 ), 198 CGI::end_form(), 199 200 #qq{ <div style="color:red"> After entering new students you will still 201 #need to assign sets to them. This is done from the "set list" page. <br> 202 #Click on the entry "xx users" in 203 #the "assigned to" column at the far right. <br> Then click either "assign to all" 204 #or check individual users and click "save" at the bottom. </div> 205 #Soon ( real soon -- honest!!! :-) ) you will also be able to assign sets to the students as they are entered from this page. } 206 ); 207 } 208 209 1; 210 211 __END__ 212 213 =head1 AUTHOR 214 215 Written by Dennis Lambe Jr., malsyned (at) math.rochester.edu 216 217 =cut
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |