[system] / branches / rel-2-1-patches / webwork2 / lib / WeBWorK / ContentGenerator / Instructor / AddUsers.pm Repository:
ViewVC logotype

Annotation of /branches/rel-2-1-patches/webwork2/lib/WeBWorK/ContentGenerator/Instructor/AddUsers.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2086 - (view) (download) (as text)
Original Path: trunk/webwork2/lib/WeBWorK/ContentGenerator/Instructor/AddUsers.pm

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9