Parent Directory
|
Revision Log
Revision 1368 -
(view)
(download)
(as text)
Original Path: trunk/webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/SendMail.pm
| 1 : | gage | 1368 | package WeBWorK::ContentGenerator::Instructor::SendMail; |
| 2 : | use base qw(WeBWorK::ContentGenerator::Instructor); | ||
| 3 : | |||
| 4 : | =head1 NAME | ||
| 5 : | |||
| 6 : | WeBWorK::ContentGenerator::Instructor::SendMail - Entry point for User-specific data editing | ||
| 7 : | |||
| 8 : | =cut | ||
| 9 : | |||
| 10 : | use strict; | ||
| 11 : | use warnings; | ||
| 12 : | use CGI qw(); | ||
| 13 : | |||
| 14 : | sub initialize { | ||
| 15 : | my ($self) = @_; | ||
| 16 : | my $r = $self->{r}; | ||
| 17 : | my $db = $self->{db}; | ||
| 18 : | my $ce = $self->{ce}; | ||
| 19 : | my $authz = $self->{authz}; | ||
| 20 : | my $user = $r->param('user'); | ||
| 21 : | |||
| 22 : | unless ($authz->hasPermissions($user, "send_mail")) { | ||
| 23 : | $self->{submitError} = "You are not authorized to send mail to students."; | ||
| 24 : | return; | ||
| 25 : | } | ||
| 26 : | |||
| 27 : | # if (defined($r->param('save_classlist'))) { | ||
| 28 : | # my @userList = $db->listUsers; | ||
| 29 : | # foreach my $user (@userList) { | ||
| 30 : | # my $userRecord = $db->getUser($user); | ||
| 31 : | # my $permissionLevelRecord = $db->getPermissionLevel($user); | ||
| 32 : | # foreach my $field ($userRecord->NONKEYFIELDS()) { | ||
| 33 : | # my $paramName = "user.${user}.${field}"; | ||
| 34 : | # if (defined($r->param($paramName))) { | ||
| 35 : | # $userRecord->$field($r->param($paramName)); | ||
| 36 : | # } | ||
| 37 : | # } | ||
| 38 : | # foreach my $field ($permissionLevelRecord->NONKEYFIELDS()) { | ||
| 39 : | # my $paramName = "permission.${user}.${field}"; | ||
| 40 : | # if (defined($r->param($paramName))) { | ||
| 41 : | # $permissionLevelRecord->$field($r->param($paramName)); | ||
| 42 : | # } | ||
| 43 : | # } | ||
| 44 : | # $db->putUser($userRecord); | ||
| 45 : | # $db->putPermissionLevel($permissionLevelRecord); | ||
| 46 : | # } | ||
| 47 : | # foreach my $userID ($r->param('deleteUser')) { | ||
| 48 : | # $db->deleteUser($userID); | ||
| 49 : | # } | ||
| 50 : | # } elsif (defined($r->param('addStudent'))) { | ||
| 51 : | # my $newUser = $db->newUser; | ||
| 52 : | # my $newPermissionLevel = $db->newPermissionLevel; | ||
| 53 : | # my $newPassword = $db->newPassword; | ||
| 54 : | # $newUser->user_id($r->param('newUserID')); | ||
| 55 : | # $newPermissionLevel->user_id($r->param('newUserID')); | ||
| 56 : | # $newPassword->user_id($r->param('newUserID')); | ||
| 57 : | # $newUser->status('C'); | ||
| 58 : | # $newPermissionLevel->permission(0); | ||
| 59 : | # $db->addUser($newUser); | ||
| 60 : | # $db->addPermissionLevel($newPermissionLevel); | ||
| 61 : | # $db->addPassword($newPassword); | ||
| 62 : | # } | ||
| 63 : | } | ||
| 64 : | |||
| 65 : | sub fieldEditHTML { | ||
| 66 : | my ($self, $fieldName, $value, $properties) = @_; | ||
| 67 : | my $size = $properties->{size}; | ||
| 68 : | my $type = $properties->{type}; | ||
| 69 : | my $access = $properties->{access}; | ||
| 70 : | my $items = $properties->{items}; | ||
| 71 : | my $synonyms = $properties->{synonyms}; | ||
| 72 : | |||
| 73 : | |||
| 74 : | if ($access eq "readonly") { | ||
| 75 : | return $value; | ||
| 76 : | } | ||
| 77 : | if ($type eq "number" or $type eq "text") { | ||
| 78 : | return CGI::input({type=>"text", name=>$fieldName, value=>$value, size=>$size}); | ||
| 79 : | } | ||
| 80 : | if ($type eq "enumerable") { | ||
| 81 : | my $matched = undef; # Whether a synonym match has occurred | ||
| 82 : | |||
| 83 : | # Process synonyms for enumerable objects | ||
| 84 : | foreach my $synonym (keys %$synonyms) { | ||
| 85 : | if ($synonym ne "*" and $value =~ m/$synonym/) { | ||
| 86 : | $value = $synonyms->{$synonym}; | ||
| 87 : | $matched = 1; | ||
| 88 : | } | ||
| 89 : | } | ||
| 90 : | if (!$matched and exists $synonyms->{"*"}) { | ||
| 91 : | $value = $synonyms->{"*"}; | ||
| 92 : | } | ||
| 93 : | return CGI::popup_menu({ | ||
| 94 : | name => $fieldName, | ||
| 95 : | values => [keys %$items], | ||
| 96 : | default => $value, | ||
| 97 : | labels => $items, | ||
| 98 : | }); | ||
| 99 : | } | ||
| 100 : | } | ||
| 101 : | |||
| 102 : | sub title { | ||
| 103 : | my $self = shift; | ||
| 104 : | return 'Send mail to ' .$self->{ce}->{courseName}; | ||
| 105 : | } | ||
| 106 : | |||
| 107 : | sub path { | ||
| 108 : | my $self = shift; | ||
| 109 : | my $args = $_[-1]; | ||
| 110 : | |||
| 111 : | my $ce = $self->{ce}; | ||
| 112 : | my $root = $ce->{webworkURLs}->{root}; | ||
| 113 : | my $courseName = $ce->{courseName}; | ||
| 114 : | return $self->pathMacro($args, | ||
| 115 : | "Home" => "$root", | ||
| 116 : | $courseName => "$root/$courseName", | ||
| 117 : | 'instructor' => "$root/$courseName/instructor", | ||
| 118 : | "Send Mail to: $courseName" => '', | ||
| 119 : | ); | ||
| 120 : | } | ||
| 121 : | |||
| 122 : | sub body { | ||
| 123 : | my ($self, $setID) = @_; | ||
| 124 : | my $r = $self->{r}; | ||
| 125 : | my $authz = $self->{authz}; | ||
| 126 : | my $user = $r->param('user'); | ||
| 127 : | my $db = $self->{db}; | ||
| 128 : | my $ce = $self->{ce}; | ||
| 129 : | my $root = $ce->{webworkURLs}->{root}; | ||
| 130 : | my $courseName = $ce->{courseName}; | ||
| 131 : | |||
| 132 : | return CGI::em("You are not authorized to access the Instructor tools.") unless $authz->hasPermissions($user, "access_instructor_tools"); | ||
| 133 : | |||
| 134 : | my $userTemplate = $db->newUser; | ||
| 135 : | my $permissionLevelTemplate = $db->newPermissionLevel; | ||
| 136 : | |||
| 137 : | # This code will require changing if the permission and user tables ever have different keys. | ||
| 138 : | my @users = $db->listUsers; | ||
| 139 : | |||
| 140 : | # This table can be consulted when display-ready forms of field names are needed. | ||
| 141 : | my %prettyFieldNames = map {$_ => $_} ($userTemplate->FIELDS(), $permissionLevelTemplate->FIELDS()); | ||
| 142 : | @prettyFieldNames{qw( | ||
| 143 : | user_id | ||
| 144 : | first_name | ||
| 145 : | last_name | ||
| 146 : | email_address | ||
| 147 : | student_id | ||
| 148 : | status | ||
| 149 : | section | ||
| 150 : | recitation | ||
| 151 : | comment | ||
| 152 : | permission | ||
| 153 : | )} = ( | ||
| 154 : | "User ID", | ||
| 155 : | "First Name", | ||
| 156 : | "Last Name", | ||
| 157 : | "E-mail", | ||
| 158 : | "Student ID", | ||
| 159 : | "Status", | ||
| 160 : | "Section", | ||
| 161 : | "Recitation", | ||
| 162 : | "Comment", | ||
| 163 : | "Perm. Level" | ||
| 164 : | ); | ||
| 165 : | |||
| 166 : | my %fieldProperties = ( | ||
| 167 : | user_id => { | ||
| 168 : | type => "text", | ||
| 169 : | size => 8, | ||
| 170 : | access => "readonly", | ||
| 171 : | }, | ||
| 172 : | first_name => { | ||
| 173 : | type => "text", | ||
| 174 : | size => 10, | ||
| 175 : | access => "readwrite", | ||
| 176 : | }, | ||
| 177 : | last_name => { | ||
| 178 : | type => "text", | ||
| 179 : | size => 10, | ||
| 180 : | access => "readwrite", | ||
| 181 : | }, | ||
| 182 : | email_address => { | ||
| 183 : | type => "text", | ||
| 184 : | size => 20, | ||
| 185 : | access => "readwrite", | ||
| 186 : | }, | ||
| 187 : | student_id => { | ||
| 188 : | type => "text", | ||
| 189 : | size => 11, | ||
| 190 : | access => "readwrite", | ||
| 191 : | }, | ||
| 192 : | status => { | ||
| 193 : | type => "enumerable", | ||
| 194 : | size => 4, | ||
| 195 : | access => "readwrite", | ||
| 196 : | items => { | ||
| 197 : | "C" => "Enrolled", | ||
| 198 : | "D" => "Drop", | ||
| 199 : | "A" => "Audit", | ||
| 200 : | }, | ||
| 201 : | synonyms => { | ||
| 202 : | qr/^[ce]/i => "C", | ||
| 203 : | qr/^[dw]/i => "D", | ||
| 204 : | qr/^a/i => "A", | ||
| 205 : | "*" => "C", | ||
| 206 : | } | ||
| 207 : | }, | ||
| 208 : | section => { | ||
| 209 : | type => "text", | ||
| 210 : | size => 4, | ||
| 211 : | access => "readwrite", | ||
| 212 : | }, | ||
| 213 : | recitation => { | ||
| 214 : | type => "text", | ||
| 215 : | size => 4, | ||
| 216 : | access => "readwrite", | ||
| 217 : | }, | ||
| 218 : | comment => { | ||
| 219 : | type => "text", | ||
| 220 : | size => 20, | ||
| 221 : | access => "readwrite", | ||
| 222 : | }, | ||
| 223 : | permission => { | ||
| 224 : | type => "number", | ||
| 225 : | size => 2, | ||
| 226 : | access => "readwrite", | ||
| 227 : | } | ||
| 228 : | ); | ||
| 229 : | |||
| 230 : | print CGI::start_form({method=>"post", action=>$r->uri()}); | ||
| 231 : | |||
| 232 : | ############################################################################################################## | ||
| 233 : | |||
| 234 : | # my ($ar_sortedNames, $hr_classlistLabels) = getClasslistFilesAndLabels($course); | ||
| 235 : | # my @sortedNames = @$ar_sortedNames; | ||
| 236 : | my %classlistLabels = ();# %$hr_classlistLabels; | ||
| 237 : | unshift(@users, "None"); | ||
| 238 : | $classlistLabels{None} = 'None'; | ||
| 239 : | my ($from,$subject,$replyTo,$text,$columns,$rows,$messageFileName); #FIXME | ||
| 240 : | $rows = 20; $columns=120; $messageFileName=''; | ||
| 241 : | #create list of sudents | ||
| 242 : | # show professors's name and email address | ||
| 243 : | # show replyTo field and From field | ||
| 244 : | print CGI::start_table({-border=>'2', -cellpadding=>'4'}); | ||
| 245 : | print CGI::Tr({-align=>'RIGHT',-valign=>'VCENTER'}, | ||
| 246 : | CGI::td("\n", CGI::p( CGI::b('From: '), CGI::textfield(-name=>"from", -size=>40, -value=>$from, -override=>1), ), | ||
| 247 : | "\n", CGI::p( CGI::b('Reply-To: '), CGI::textfield(-name=>"replyTo", -size=>40, -value=>$replyTo, -override=>1), ), | ||
| 248 : | "\n", CGI::p( CGI::b('Subject: '), CGI::textfield(-name=>'subject', -default=>$subject, -size=>40, -override=>1), ), | ||
| 249 : | ), | ||
| 250 : | CGI::td( | ||
| 251 : | 'Select recipients'.CGI::br(). | ||
| 252 : | CGI::popup_menu(-name=>'classList', | ||
| 253 : | -values=>\@users, | ||
| 254 : | -labels=>\%classlistLabels, | ||
| 255 : | -size => 10, | ||
| 256 : | -multiple => 1, | ||
| 257 : | -default=>'None' | ||
| 258 : | ) | ||
| 259 : | ), | ||
| 260 : | CGI::td( | ||
| 261 : | #show available macros | ||
| 262 : | CGI::popup_menu( | ||
| 263 : | -name=>'dummyName', | ||
| 264 : | -values=>['', '$SID', '$FN', '$LN', '$SECTION', '$RECITATION','$STATUS', '$EMAIL', '$LOGIN', '$COL[3]', '$COL[-1]'], | ||
| 265 : | -labels=>{''=>'These macros can be used to insert student specific data:', | ||
| 266 : | '$SID'=>'$SID - Student ID', | ||
| 267 : | '$FN'=>'$FN - First name', | ||
| 268 : | '$LN'=>'$LN - Last name', | ||
| 269 : | '$SECTION'=>'$SECTION - Student\'s Section', | ||
| 270 : | '$RECITATION'=>'$RECITATION - Student\'s Recitation', | ||
| 271 : | '$STATUS'=>'$STATUS - C, Audit, Drop, etc.', | ||
| 272 : | '$EMAIL'=>'$EMAIL - Email address', | ||
| 273 : | '$LOGIN'=>'$LOGIN - Login', | ||
| 274 : | '$COL[3]'=>'$COL[3] - Third column in merge file', | ||
| 275 : | '$COL[-1]'=>'$COL[-1] - Last column in merge file' | ||
| 276 : | } | ||
| 277 : | ), "\n", | ||
| 278 : | ), | ||
| 279 : | |||
| 280 : | ); | ||
| 281 : | print CGI::end_table(); | ||
| 282 : | #create a textbox with the subject and a textarea with the message | ||
| 283 : | |||
| 284 : | #print actual body of message | ||
| 285 : | print CGI::p( | ||
| 286 : | CGI::submit(-name=>'action', -value=>'Revert to original and Resize message window'), | ||
| 287 : | " Rows: ", CGI::textfield(-name=>'rows', -size=>3, -value=>$rows), | ||
| 288 : | " Columns: ", CGI::textfield(-name=>'columns', -size=>3, -value=>$columns),CGI::br(), | ||
| 289 : | "If you resize the message window, you will lose all unsaved changes." | ||
| 290 : | ); | ||
| 291 : | |||
| 292 : | print "\n", CGI::p( CGI::textarea(-name=>'body', -default=>$text, -rows=>$rows, -columns=>$columns, -override=>1) | ||
| 293 : | ); | ||
| 294 : | #create all necessary action buttons | ||
| 295 : | print CGI::p(CGI::submit(-name=>'action', -value=>'Open'), "\n", | ||
| 296 : | CGI::textfield(-name=>'savefilename', -size => 20, -value=> "$messageFileName", -override=>1), ' ', | ||
| 297 : | CGI::submit(-name=>'action', -value=>'Save'), " \n", | ||
| 298 : | CGI::submit(-name=>'action', -value=>'Save as'), " \n", | ||
| 299 : | CGI::submit(-name=>'action', -value=>'Save as Default'), | ||
| 300 : | CGI::submit(-name=>'action', -value=>'Send Email'), "\n", CGI::br(), | ||
| 301 : | 'For "Save As" choose a new filename.', | ||
| 302 : | ); | ||
| 303 : | |||
| 304 : | ############################################################################################################## | ||
| 305 : | # Table headings, prettied-up | ||
| 306 : | # print CGI::start_table({}); | ||
| 307 : | # print CGI::Tr({}, | ||
| 308 : | # CGI::th({}, [ | ||
| 309 : | # "Delete?", | ||
| 310 : | # map {$prettyFieldNames{$_}} ( | ||
| 311 : | # $userTemplate->KEYFIELDS(), | ||
| 312 : | # $userTemplate->NONKEYFIELDS(), | ||
| 313 : | # $permissionLevelTemplate->NONKEYFIELDS(), | ||
| 314 : | # ) | ||
| 315 : | # ]) | ||
| 316 : | # ); | ||
| 317 : | # | ||
| 318 : | # foreach my $currentUser (@users) { | ||
| 319 : | # my $userRecord = $db->getUser($currentUser); | ||
| 320 : | # my $permissionLevel = $db->getPermissionLevel($currentUser); | ||
| 321 : | # unless (defined $permissionLevel) { | ||
| 322 : | # warn "No permissionLevel record for user $currentUser" ; | ||
| 323 : | # next; | ||
| 324 : | # } | ||
| 325 : | # | ||
| 326 : | # # A concise way of printing a row containing a cell for each field, editable unless it's a key | ||
| 327 : | # print CGI::Tr({}, | ||
| 328 : | # CGI::td({}, [ | ||
| 329 : | # CGI::input({type=>"checkbox", name=>"deleteUser", value=>$currentUser}), | ||
| 330 : | # ( | ||
| 331 : | # map { | ||
| 332 : | # my $changeEUserURL = "$root/$courseName?user=".$r->param("user")."&effectiveUser=".$userRecord->user_id()."&key=".$r->param("key"); | ||
| 333 : | # CGI::a({href=>$changeEUserURL}, $userRecord->$_) | ||
| 334 : | # } $userRecord->KEYFIELDS | ||
| 335 : | # ), | ||
| 336 : | # (map { | ||
| 337 : | # # CGI::input({type=>"text", size=>"8", name=> "user.".$userRecord->user_id().".".$_, value=>$userRecord->$_}) | ||
| 338 : | # $self->fieldEditHTML("user.".$userRecord->user_id().".".$_, $userRecord->$_, $fieldProperties{$_}); | ||
| 339 : | # } $userRecord->NONKEYFIELDS()), | ||
| 340 : | # (map { | ||
| 341 : | # # CGI::input({type=>"text", size=>"8", name => "permission.".$permissionLevel->user_id().".".$_, value=>$permissionLevel->$_}) | ||
| 342 : | # $self->fieldEditHTML("permission.".$permissionLevel->user_id().".".$_, $permissionLevel->$_, $fieldProperties{$_}); | ||
| 343 : | # } $permissionLevel->NONKEYFIELDS()), | ||
| 344 : | # ]) | ||
| 345 : | # ); | ||
| 346 : | # } | ||
| 347 : | # | ||
| 348 : | # print CGI::end_table(); | ||
| 349 : | print $self->hidden_authen_fields(); | ||
| 350 : | print CGI::submit({name=>"save_classlist", value=>"Save Changes to Users"}); | ||
| 351 : | print CGI::end_form(); | ||
| 352 : | |||
| 353 : | # Add a student form | ||
| 354 : | # print CGI::start_form({method=>"post", action=>$r->uri()}); | ||
| 355 : | # print $self->hidden_authen_fields(); | ||
| 356 : | # print "User ID:"; | ||
| 357 : | # print CGI::input({type=>"text", name=>"newUserID", value=>"", size=>"20"}); | ||
| 358 : | # print CGI::submit({name=>"addStudent", value=>"Add Student"}); | ||
| 359 : | # print CGI::end_form(); | ||
| 360 : | |||
| 361 : | return ""; | ||
| 362 : | } | ||
| 363 : | |||
| 364 : | 1; |
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |