| … | |
… | |
| 21 | |
21 | |
| 22 | unless ($authz->hasPermissions($user, "send_mail")) { |
22 | unless ($authz->hasPermissions($user, "send_mail")) { |
| 23 | $self->{submitError} = "You are not authorized to send mail to students."; |
23 | $self->{submitError} = "You are not authorized to send mail to students."; |
| 24 | return; |
24 | return; |
| 25 | } |
25 | } |
|
|
26 | ############################################################################################# |
|
|
27 | # gather directory data |
|
|
28 | ############################################################################################# |
|
|
29 | my $emailDirectory = $ce->{courseDirs}->{email}; |
|
|
30 | my $scoringDirectory = $ce->{courseDirs}->{scoring}; |
|
|
31 | my $templateDirectory = $ce->{courseDirs}->{templates}; |
| 26 | |
32 | |
| 27 | # if (defined($r->param('save_classlist'))) { |
33 | my $action = $r->param('action'); |
| 28 | # my @userList = $db->listUsers; |
34 | my $openfilename = $r->param('openfilename'); |
| 29 | # foreach my $user (@userList) { |
35 | my $savefilename = $r->param('savefilename'); |
| 30 | # my $userRecord = $db->getUser($user); |
36 | #FIXME get these values |
| 31 | # my $permissionLevelRecord = $db->getPermissionLevel($user); |
37 | my $default_msg = 'default.msg'; |
| 32 | # foreach my $field ($userRecord->NONKEYFIELDS()) { |
38 | my $old_default_msg = 'old_default.msg'; |
| 33 | # my $paramName = "user.${user}.${field}"; |
39 | my $defaultFrom = 'FIXME from'; |
| 34 | # if (defined($r->param($paramName))) { |
40 | my $defaultReply = 'FIXME reply'; |
| 35 | # $userRecord->$field($r->param($paramName)); |
41 | ############################################################################################# |
|
|
42 | # Get directory file name |
|
|
43 | ############################################################################################# |
|
|
44 | |
|
|
45 | #make sure message file was submitted and exists |
|
|
46 | my $messageFileName; |
|
|
47 | if (defined($openfilename) && -e "${emailDirectory}$openfilename") { |
|
|
48 | if ( -R "${emailDirectory}$openfilename") { |
|
|
49 | $messageFileName = $openfilename; |
|
|
50 | } else { |
|
|
51 | warn "The file ${emailDirectory}$openfilename is not readable by the webserver. |
|
|
52 | Check that it's permissions are set correctly."; |
|
|
53 | } |
|
|
54 | } else { |
|
|
55 | $messageFileName = $default_msg; |
|
|
56 | } |
|
|
57 | |
|
|
58 | $self->{messageFileName}=$messageFileName; |
|
|
59 | |
|
|
60 | # make sure that the file path is legal (lies below inside the email directory |
|
|
61 | if (defined($savefilename) && ($savefilename =~ /^[~.]/ or $savefilename =~ /\.\./ ) ){ |
|
|
62 | $self->fatal_error("For security reasons, you cannot save a message", |
|
|
63 | "in any directory higher than the email directory.", |
|
|
64 | "Please specify a file name to save under."); |
|
|
65 | } |
|
|
66 | |
|
|
67 | ############################################################################################# |
|
|
68 | # if no form is submitted gather data from default message file and return |
|
|
69 | ############################################################################################# |
|
|
70 | |
|
|
71 | unless (defined($action) ){ |
|
|
72 | ############################################################################################# |
|
|
73 | #get message from given messageFileName |
|
|
74 | ############################################################################################# |
|
|
75 | my ($text, @text); |
|
|
76 | my $header = ''; |
|
|
77 | my ($subject, $from, $replyTo); |
|
|
78 | if (-e "$emailDirectory/$messageFileName") { |
|
|
79 | open FILE, "$emailDirectory/$messageFileName" || $self->fatal_error("Can't open $emailDirectory/$messageFileName"); |
|
|
80 | while ($header !~ s/Message:\s*$//m) { |
|
|
81 | $header .= <FILE>; |
|
|
82 | } |
|
|
83 | $text = join( '', <FILE>); |
|
|
84 | $text .= "from $emailDirectory/$messageFileName"; |
|
|
85 | $header =~ /^From:\s(.*)$/m; |
|
|
86 | $from = $1 or $from = $defaultFrom; #given email address or default feedback address |
|
|
87 | $header =~ /^Reply-To:\s(.*)$/m; |
|
|
88 | $replyTo = $1 or $replyTo = $defaultReply; |
|
|
89 | $header =~ /^Subject:\s(.*)$/m; |
|
|
90 | $subject = $1; |
|
|
91 | |
|
|
92 | } else { |
|
|
93 | $from = $defaultFrom; |
|
|
94 | $replyTo = $defaultReply; |
|
|
95 | $text = "FIXME file $emailDirectory/$messageFileName doesn't exist"; |
|
|
96 | $subject = "FIXME default subject"; |
|
|
97 | } |
|
|
98 | ############################################################################################# |
|
|
99 | # store info for body subroutine |
|
|
100 | ############################################################################################# |
|
|
101 | $self->{openfilename }= $openfilename; |
|
|
102 | $self->{savefilename }= $savefilename; |
|
|
103 | $self->{from} = $from; |
|
|
104 | $self->{replyTo} = $replyTo; |
|
|
105 | $self->{subject} = $subject; |
|
|
106 | $self->{r_text} = \$text; |
|
|
107 | $self->{rows} = (defined($r->param('rows'))) ? $r->param('rows') : $ce->{mail}->{editor_window_rows}; |
|
|
108 | $self->{columns} = (defined($r->param('columns'))) ? $r->param('columns') : $ce->{mail}->{editor_window_columns}; |
|
|
109 | $self->{default_msg} = $default_msg; |
|
|
110 | $self->{old_default_msg} = $old_default_msg; |
|
|
111 | |
|
|
112 | return ''; |
|
|
113 | } |
|
|
114 | |
|
|
115 | |
|
|
116 | |
|
|
117 | |
|
|
118 | |
|
|
119 | ############################################################################################# |
|
|
120 | # If form is submitted deal with filled out forms |
|
|
121 | # and various actions resulting from different buttons |
|
|
122 | ############################################################################################# |
|
|
123 | |
|
|
124 | my $from = $r->param('from'); |
|
|
125 | my $to = $r->param('To'); |
|
|
126 | my $replyTo = $r->param('replyTo'); |
|
|
127 | my $subject = $r->param('subject'); |
|
|
128 | my $body = $r->param('body'); |
|
|
129 | |
|
|
130 | |
|
|
131 | |
|
|
132 | # script action |
|
|
133 | my $script_action = ''; |
|
|
134 | # user_errors |
|
|
135 | # save |
|
|
136 | # save as |
|
|
137 | # save as default |
|
|
138 | # send mail |
|
|
139 | # set defaults |
|
|
140 | |
|
|
141 | |
|
|
142 | |
|
|
143 | #if Save button was clicked |
|
|
144 | if (( $r->param('action') eq 'Save') && defined($r->param('body')) && defined($r->param('savefilename'))) { |
|
|
145 | |
|
|
146 | my $temp_body = $body; |
|
|
147 | $temp_body =~ s/\r\n/\n/g; |
|
|
148 | $temp_body = "From: " . $from . "\n" . |
|
|
149 | "Reply-To: " . $replyTo . "\n" . |
|
|
150 | "Subject: " . $subject . "\n" . |
|
|
151 | "Message: \n" . $temp_body; |
|
|
152 | |
|
|
153 | saveProblem($temp_body, $savefilename); |
|
|
154 | $messageFileName = $savefilename; |
|
|
155 | |
|
|
156 | #if Save As button was clicked |
|
|
157 | } elsif (( $r->param('action') eq 'Save as') && defined($r->param('body')) && defined($r->param('savefilename'))) { |
|
|
158 | |
|
|
159 | $messageFileName = $savefilename; |
|
|
160 | |
|
|
161 | if ($messageFileName =~ /^[~.]/ || $messageFileName =~ /\.\./) { |
|
|
162 | $self->fatal_error("For security reasons, you cannot specify a merge file from a directory higher than the email directory (you can't use ../blah/blah). Please specify a different file or move the needed file to the email directory"); |
|
|
163 | } |
|
|
164 | |
|
|
165 | |
|
|
166 | my $temp_body = $body; |
|
|
167 | $temp_body =~ s/\r\n/\n/g; |
|
|
168 | $temp_body = join("", |
|
|
169 | "From: $from \nReply-To: $replyTo)\n" , |
|
|
170 | "Subject: $subject\n" , |
|
|
171 | "Message: \n $temp_body"); |
|
|
172 | |
|
|
173 | saveNewProblem($temp_body, $messageFileName); |
|
|
174 | |
|
|
175 | #if Save As Default button was clicked |
|
|
176 | } elsif (( $r->param('action') eq 'Save as Default') && defined($r->param('body'))) { |
|
|
177 | |
|
|
178 | my $temp_body; |
|
|
179 | $temp_body = $r->param('body'); |
|
|
180 | $temp_body =~ s/\r\n/\n/g; |
|
|
181 | |
|
|
182 | #get default.msg and back it up in default.old.msg |
|
|
183 | open DEFAULT, "$emailDirectory/$default_msg"; |
|
|
184 | $temp_body = <DEFAULT>; |
|
|
185 | close DEFAULT; |
|
|
186 | |
|
|
187 | if ( -e "$emailDirectory/$old_default_msg") { |
|
|
188 | # saveProblem($temp_body, $old_default_msg); |
|
|
189 | } else { |
|
|
190 | # saveNewProblem($temp_body, $old_default_msg); |
|
|
191 | } |
|
|
192 | |
|
|
193 | #save new default message as default.msg |
|
|
194 | $temp_body = $body; |
|
|
195 | $temp_body =~ s/\r\n/\n/g; |
|
|
196 | $temp_body = join("", |
|
|
197 | "From: $from \nReply-To: $replyTo)\n" , |
|
|
198 | "Subject: $subject\n" , |
|
|
199 | "Message: \n $temp_body"); |
|
|
200 | |
|
|
201 | # saveProblem($temp_body, $default_msg); |
|
|
202 | $messageFileName = $default_msg; |
|
|
203 | |
|
|
204 | #if Send Email button was clicked |
|
|
205 | } elsif ( $r->param('action') eq 'Send Email' ) { |
|
|
206 | |
|
|
207 | my @studentID = (); |
|
|
208 | |
|
|
209 | if ($r->param('To') eq 'classList' && defined($r->param('classList')) && $r->param('classList') ne 'None') { |
|
|
210 | # my $classlist = $r->param('classList'); |
|
|
211 | # my $classListFile = "$templateDirectory$classlist"; |
|
|
212 | # my @classList = (); |
|
|
213 | # #FIXME checkClasslistFile($Global::noOfFieldsInClasslist,$classListFile); |
|
|
214 | # open(FILE, "$classListFile") || die "can't open $classListFile"; |
|
|
215 | # @classList=<FILE>; |
|
|
216 | # close(FILE); |
|
|
217 | # |
|
|
218 | # foreach (@classList) { ## read through classlist and send e-mail |
|
|
219 | # ## message to all active students |
|
|
220 | # unless ($_ =~ /\S/) {next;} ## skip blank lines |
|
|
221 | # chomp; |
|
|
222 | # my @classListRecord=&getRecord($_); |
|
|
223 | # my ($studentID, $lastName, $firstName, $status, $comment, $section, $recitation, $email_address, $login_name) |
|
|
224 | # = @classListRecord; |
|
|
225 | # unless (&dropStatus($status)) { |
|
|
226 | # push (@studentID, $studentID); |
|
|
227 | # $fn{$studentID} = $firstName; |
|
|
228 | # $ln{$studentID} = $lastName; |
|
|
229 | # $section{$studentID} = $section; |
|
|
230 | # $recitation{$studentID} = $recitation; |
|
|
231 | # $status{$studentID} = $status; |
|
|
232 | # $email{$studentID} = $email_address; |
|
|
233 | # $login{$studentID} = $login_name; |
|
|
234 | # } |
| 36 | # } |
235 | # } |
|
|
236 | } elsif ($r->param('To') eq 'studentID' && defined($r->param('studentID'))) { |
|
|
237 | @studentID = $r->param('studentID'); |
|
|
238 | my ($studentID, $login_name); |
|
|
239 | # |
|
|
240 | # foreach $studentID (@studentID) { |
|
|
241 | # $login_name = $studentID_LoginName_Hash{$studentID}; |
|
|
242 | # &attachCLRecord($login_name); |
|
|
243 | # $fn{$studentID} = CL_getStudentFirstName($login_name); |
|
|
244 | # $ln{$studentID} = CL_getStudentLastName($login_name); |
|
|
245 | # $section{$studentID} = CL_getClassSection($login_name); |
|
|
246 | # $recitation{$studentID} = CL_getClassRecitation($login_name); |
|
|
247 | # $status{$studentID} = CL_getStudentStatus($login_name); |
|
|
248 | # $email{$studentID} = CL_getStudentEmailAddress($login_name); |
|
|
249 | # $login{$studentID} = $login_name; |
|
|
250 | # } |
|
|
251 | |
|
|
252 | } elsif ($r->param('To') eq 'all_students') { |
|
|
253 | @studentID = (); |
|
|
254 | my ($studentID, $login_name, $status); |
|
|
255 | |
|
|
256 | # foreach $login_name (@availableStudents) { |
|
|
257 | # &attachCLRecord($login_name); |
|
|
258 | # $status = CL_getStudentStatus($login_name); |
|
|
259 | # next if &dropStatus($status); |
|
|
260 | # $studentID = CL_getStudentID($login_name); |
|
|
261 | # push(@studentID,$studentID); |
|
|
262 | # |
|
|
263 | # $fn{$studentID} = CL_getStudentFirstName($login_name); |
|
|
264 | # $ln{$studentID} = CL_getStudentLastName($login_name); |
|
|
265 | # $section{$studentID} = CL_getClassSection($login_name); |
|
|
266 | # $recitation{$studentID} = CL_getClassRecitation($login_name); |
|
|
267 | # $status{$studentID} = CL_getStudentStatus($login_name); |
|
|
268 | # $email{$studentID} = CL_getStudentEmailAddress($login_name); |
|
|
269 | # $login{$studentID} = $login_name; |
|
|
270 | # } |
|
|
271 | } else { |
|
|
272 | $self->fatal_error('You didn\'t select any recipients. Make sure you select either all student in the course, individual students or a whole classlist.'); |
|
|
273 | } |
|
|
274 | |
|
|
275 | my $mergeFile = ''; |
|
|
276 | |
|
|
277 | #the radio button named 'merge' determines whether to take the selected mergefile |
|
|
278 | #or one that was typed in. A error message is given if select one and use the other |
|
|
279 | $mergeFile = $scoringDirectory . $r->param('mergeFiles') |
|
|
280 | if ($r->param('merge') eq 'mergeFiles' && defined($r->param('mergeFiles')) && $r->param('mergeFiles') ne 'None'); |
|
|
281 | |
|
|
282 | $mergeFile = $templateDirectory . $r->param('mergeFile') |
|
|
283 | if ($r->param('merge') eq 'mergeFile' && defined($r->param('mergeFile')) && $r->param('mergeFile') !~ m|/$|); #does not end in a / |
|
|
284 | |
|
|
285 | if ($mergeFile =~ /^[~.]/ || $mergeFile =~ /\.\./) { |
|
|
286 | $self->fatal_error("For security reasons, you cannot specify a merge file from a directory higher than the email directory. Please specify a different file or move the needed file to the email directory"); |
|
|
287 | } |
|
|
288 | if ($r->param('body') =~ /(\$COL\[.*?\])/ && !(-e $mergeFile)) { |
|
|
289 | $self->fatal_error("In order to use the \$COL[] you must specify a merge file. The file you specified does not exist. Also, make sure you selected the right checkbox."); |
|
|
290 | } |
|
|
291 | |
|
|
292 | |
|
|
293 | my %mergeAArray = (); |
|
|
294 | # unless ($mergeFile eq '') {%mergeAArray = &delim2aa($mergeFile);} |
|
|
295 | # |
|
|
296 | $self->fatal_error('You didn\'t enter any message.') if ($r->param('body') eq ''); |
|
|
297 | # |
|
|
298 | # foreach my $studentID (@studentID) { |
|
|
299 | # @COL =(); |
|
|
300 | # $SID = $studentID; |
|
|
301 | # $LN = defined $ln{$studentID} ? $ln{$studentID} :''; |
|
|
302 | # $FN = defined $fn{$studentID} ? $fn{$studentID} :''; |
|
|
303 | # $SECTION = defined $section{$studentID} ? $section{$studentID} :''; |
|
|
304 | # $RECITATION = defined $recitation{$studentID} ? $recitation{$studentID} :''; |
|
|
305 | # $EMAIL = defined $email{$studentID} ? $email{$studentID} :''; |
|
|
306 | # $STATUS =defined $status{$studentID} ? $status{$studentID} :''; |
|
|
307 | # $LOGIN = $login{$studentID}; |
|
|
308 | # |
|
|
309 | # next if ($LOGIN =~ /^$practiceUser/); ## skip practice users |
|
|
310 | # |
|
|
311 | # if ($timeout_attempts >= $max_timeout_attempts) { ## have attemped to connect to smtp server |
|
|
312 | # ## the max allowed times. Now just collect |
|
|
313 | # ## data on emails not sent and exit |
|
|
314 | # ++$emails_not_sent; |
|
|
315 | # &log_error(\@exceeded_max_timeout,$FN,$LN,$EMAIL); |
|
|
316 | # next; |
|
|
317 | # } |
|
|
318 | # |
|
|
319 | # unless ((defined $mergeAArray{$studentID}) or ($mergeFile eq '')) { |
|
|
320 | # if ($cgi->param('no_record')) { |
|
|
321 | # ++$emails_not_sent; |
|
|
322 | # &log_error(\@no_record,$FN,$LN,$EMAIL); |
|
|
323 | # next; |
|
|
324 | # } |
|
|
325 | # } |
|
|
326 | |
|
|
327 | # my ($dbString, @dbArray); |
|
|
328 | # if (defined $mergeAArray{$SID}) { |
|
|
329 | # $dbString = $mergeAArray{$SID}; ## get sid record from merge file |
|
|
330 | # @dbArray = &getRecord($dbString); |
|
|
331 | # unshift(@dbArray,$SID); |
|
|
332 | # unshift(@dbArray,""); ## note COL[1] is the first column |
|
|
333 | # @COL= @dbArray; ## put merge fields in COL array |
|
|
334 | # $endCol = @COL; ## \endCol-1 gives last field, etc |
|
|
335 | # } |
|
|
336 | # my $smtp; |
|
|
337 | # if ($smtp = Net::SMTP->new($Global::smtpServer, Timeout => $timeout_sec)) {} else { |
|
|
338 | # # &internal_error("Couldn't contact SMTP server."); |
|
|
339 | # ++$emails_not_sent; |
|
|
340 | # &log_error(\@timeout_problem,$FN,$LN,$EMAIL); |
|
|
341 | # ++$timeout_attempts; |
|
|
342 | # next; |
|
|
343 | # } |
|
|
344 | # |
|
|
345 | # $smtp->mail($smtpSender); |
|
|
346 | # |
|
|
347 | # if ( $smtp->recipient($EMAIL)) { # this one's okay, keep going |
|
|
348 | # if ( $smtp->data("To: $EMAIL\n" . output() ) ) { |
|
|
349 | # ++$emails_sent; |
|
|
350 | # } else { |
|
|
351 | # ++$emails_not_sent; |
|
|
352 | # &log_error(\@unknown_problem,$FN,$LN,$EMAIL); |
|
|
353 | # next; |
|
|
354 | # } |
|
|
355 | # # &internal_error("Unknown problem sending message data to SMTP server."); |
|
|
356 | # } else { # we have a problem with this address |
|
|
357 | # $smtp->reset; |
|
|
358 | # #&internal_error("SMTP server doesn't like this address: <$EMAIL>."); |
|
|
359 | # ++$emails_not_sent; |
|
|
360 | # &log_error(\@bad_email_addresses,$FN,$LN,$EMAIL); |
|
|
361 | # } |
|
|
362 | # $smtp->quit; |
| 37 | # } |
363 | # } |
| 38 | # foreach my $field ($permissionLevelRecord->NONKEYFIELDS()) { |
364 | # &success; |
| 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 | # } |
365 | } |
| 47 | # foreach my $userID ($r->param('deleteUser')) { |
366 | |
| 48 | # $db->deleteUser($userID); |
367 | |
| 49 | # } |
368 | |
| 50 | # } elsif (defined($r->param('addStudent'))) { |
369 | |
| 51 | # my $newUser = $db->newUser; |
370 | } #end initialize |
| 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 | |
371 | |
| 65 | sub fieldEditHTML { |
372 | sub fieldEditHTML { |
| 66 | my ($self, $fieldName, $value, $properties) = @_; |
373 | my ($self, $fieldName, $value, $properties) = @_; |
| 67 | my $size = $properties->{size}; |
374 | my $size = $properties->{size}; |
| 68 | my $type = $properties->{type}; |
375 | my $type = $properties->{type}; |
| … | |
… | |
| 136 | |
443 | |
| 137 | # This code will require changing if the permission and user tables ever have different keys. |
444 | # This code will require changing if the permission and user tables ever have different keys. |
| 138 | my @users = $db->listUsers; |
445 | my @users = $db->listUsers; |
| 139 | |
446 | |
| 140 | # This table can be consulted when display-ready forms of field names are needed. |
447 | # This table can be consulted when display-ready forms of field names are needed. |
| 141 | my %prettyFieldNames = map {$_ => $_} ($userTemplate->FIELDS(), $permissionLevelTemplate->FIELDS()); |
448 | # my %prettyFieldNames = map {$_ => $_} ($userTemplate->FIELDS(), $permissionLevelTemplate->FIELDS()); |
| 142 | @prettyFieldNames{qw( |
449 | # @prettyFieldNames{qw( |
| 143 | user_id |
450 | # user_id |
| 144 | first_name |
451 | # first_name |
| 145 | last_name |
452 | # last_name |
| 146 | email_address |
453 | # email_address |
| 147 | student_id |
454 | # student_id |
| 148 | status |
455 | # status |
| 149 | section |
456 | # section |
| 150 | recitation |
457 | # recitation |
| 151 | comment |
458 | # comment |
| 152 | permission |
459 | # permission |
| 153 | )} = ( |
460 | # )} = ( |
| 154 | "User ID", |
461 | # "User ID", |
| 155 | "First Name", |
462 | # "First Name", |
| 156 | "Last Name", |
463 | # "Last Name", |
| 157 | "E-mail", |
464 | # "E-mail", |
| 158 | "Student ID", |
465 | # "Student ID", |
| 159 | "Status", |
466 | # "Status", |
| 160 | "Section", |
467 | # "Section", |
| 161 | "Recitation", |
468 | # "Recitation", |
| 162 | "Comment", |
469 | # "Comment", |
| 163 | "Perm. Level" |
470 | # "Perm. Level" |
| 164 | ); |
471 | # ); |
| 165 | |
472 | |
| 166 | my %fieldProperties = ( |
473 | # my %fieldProperties = ( |
| 167 | user_id => { |
474 | # user_id => { |
| 168 | type => "text", |
475 | # type => "text", |
| 169 | size => 8, |
476 | # size => 8, |
| 170 | access => "readonly", |
477 | # access => "readonly", |
| 171 | }, |
478 | # }, |
| 172 | first_name => { |
479 | # first_name => { |
| 173 | type => "text", |
480 | # type => "text", |
| 174 | size => 10, |
481 | # size => 10, |
| 175 | access => "readwrite", |
482 | # access => "readwrite", |
| 176 | }, |
483 | # }, |
| 177 | last_name => { |
484 | # last_name => { |
| 178 | type => "text", |
485 | # type => "text", |
| 179 | size => 10, |
486 | # size => 10, |
| 180 | access => "readwrite", |
487 | # access => "readwrite", |
| 181 | }, |
488 | # }, |
| 182 | email_address => { |
489 | # email_address => { |
| 183 | type => "text", |
490 | # type => "text", |
| 184 | size => 20, |
491 | # size => 20, |
| 185 | access => "readwrite", |
492 | # access => "readwrite", |
| 186 | }, |
493 | # }, |
| 187 | student_id => { |
494 | # student_id => { |
| 188 | type => "text", |
495 | # type => "text", |
| 189 | size => 11, |
496 | # size => 11, |
| 190 | access => "readwrite", |
497 | # access => "readwrite", |
| 191 | }, |
498 | # }, |
| 192 | status => { |
499 | # status => { |
| 193 | type => "enumerable", |
500 | # type => "enumerable", |
| 194 | size => 4, |
501 | # size => 4, |
| 195 | access => "readwrite", |
502 | # access => "readwrite", |
| 196 | items => { |
503 | # items => { |
| 197 | "C" => "Enrolled", |
504 | # "C" => "Enrolled", |
| 198 | "D" => "Drop", |
505 | # "D" => "Drop", |
| 199 | "A" => "Audit", |
506 | # "A" => "Audit", |
| 200 | }, |
507 | # }, |
| 201 | synonyms => { |
508 | # synonyms => { |
| 202 | qr/^[ce]/i => "C", |
509 | # qr/^[ce]/i => "C", |
| 203 | qr/^[dw]/i => "D", |
510 | # qr/^[dw]/i => "D", |
| 204 | qr/^a/i => "A", |
511 | # qr/^a/i => "A", |
| 205 | "*" => "C", |
512 | # "*" => "C", |
| 206 | } |
513 | # } |
| 207 | }, |
514 | # }, |
| 208 | section => { |
515 | # section => { |
| 209 | type => "text", |
516 | # type => "text", |
| 210 | size => 4, |
517 | # size => 4, |
| 211 | access => "readwrite", |
518 | # access => "readwrite", |
| 212 | }, |
519 | # }, |
| 213 | recitation => { |
520 | # recitation => { |
| 214 | type => "text", |
521 | # type => "text", |
| 215 | size => 4, |
522 | # size => 4, |
| 216 | access => "readwrite", |
523 | # access => "readwrite", |
| 217 | }, |
524 | # }, |
| 218 | comment => { |
525 | # comment => { |
| 219 | type => "text", |
526 | # type => "text", |
| 220 | size => 20, |
527 | # size => 20, |
| 221 | access => "readwrite", |
528 | # access => "readwrite", |
| 222 | }, |
529 | # }, |
| 223 | permission => { |
530 | # permission => { |
| 224 | type => "number", |
531 | # type => "number", |
| 225 | size => 2, |
532 | # size => 2, |
| 226 | access => "readwrite", |
533 | # access => "readwrite", |
| 227 | } |
534 | # } |
| 228 | ); |
535 | # ); |
| 229 | |
536 | |
| 230 | print CGI::start_form({method=>"post", action=>$r->uri()}); |
537 | |
| 231 | |
538 | |
| 232 | ############################################################################################################## |
539 | ############################################################################################################## |
| 233 | |
540 | |
| 234 | # my ($ar_sortedNames, $hr_classlistLabels) = getClasslistFilesAndLabels($course); |
541 | # my ($ar_sortedNames, $hr_classlistLabels) = getClasslistFilesAndLabels($course); |
| 235 | # my @sortedNames = @$ar_sortedNames; |
542 | # my @sortedNames = @$ar_sortedNames; |
| 236 | my %classlistLabels = ();# %$hr_classlistLabels; |
543 | my %classlistLabels = ();# %$hr_classlistLabels; |
| 237 | unshift(@users, "None"); |
544 | unshift(@users, "Yourself"); |
| 238 | $classlistLabels{None} = 'None'; |
545 | $classlistLabels{None} = 'Yourself'; |
| 239 | my ($from,$subject,$replyTo,$text,$columns,$rows,$messageFileName); #FIXME |
546 | my $from = $self->{from}; |
| 240 | $rows = 20; $columns=120; $messageFileName=''; |
547 | my $subject = $self->{subject}; |
|
|
548 | my $replyTo = $self->{replyTo}; |
|
|
549 | my $columns = $self->{columns}; |
|
|
550 | my $rows = $self->{rows}; |
|
|
551 | my $text = defined($self->{r_text}) ? ${ $self->{r_text} }: 'FIXME'; |
|
|
552 | my $messageFileName = $self->{messageFileName}; |
|
|
553 | |
|
|
554 | CGI::popup_menu(-name=>'classList', |
|
|
555 | -values=>\@users, |
|
|
556 | -labels=>\%classlistLabels, |
|
|
557 | -size => 10, |
|
|
558 | -multiple => 1, |
|
|
559 | -default=>'Yourself' |
|
|
560 | ); |
|
|
561 | print CGI::start_form({method=>"post", action=>$r->uri()}); |
| 241 | #create list of sudents |
562 | #create list of sudents |
| 242 | # show professors's name and email address |
563 | # show professors's name and email address |
| 243 | # show replyTo field and From field |
564 | # show replyTo field and From field |
| 244 | print CGI::start_table({-border=>'2', -cellpadding=>'4'}); |
565 | print CGI::start_table({-border=>'2', -cellpadding=>'4'}); |
| 245 | print CGI::Tr({-align=>'RIGHT',-valign=>'VCENTER'}, |
566 | print CGI::Tr({-align=>'left',-valign=>'VCENTER'}, |
| 246 | CGI::td("\n", CGI::p( CGI::b('From: '), CGI::textfield(-name=>"from", -size=>40, -value=>$from, -override=>1), ), |
567 | CGI::td("\n", CGI::p( CGI::b('From: '), CGI::br(), CGI::textfield(-name=>"from", -size=>30, -value=>$from, -override=>1), ), |
| 247 | "\n", CGI::p( CGI::b('Reply-To: '), CGI::textfield(-name=>"replyTo", -size=>40, -value=>$replyTo, -override=>1), ), |
568 | "\n", CGI::p( CGI::b('Reply-To: '), CGI::br(), CGI::textfield(-name=>"replyTo", -size=>30, -value=>$replyTo, -override=>1), ), |
| 248 | "\n", CGI::p( CGI::b('Subject: '), CGI::textfield(-name=>'subject', -default=>$subject, -size=>40, -override=>1), ), |
569 | "\n", CGI::p( CGI::b('Subject: '), CGI::br(), CGI::textarea(-name=>'subject', -default=>$subject, -rows=>2,-columns=>30, -override=>1), ), |
| 249 | ), |
570 | ), |
| 250 | CGI::td( |
571 | CGI::td({-align=>'left'}, |
| 251 | 'Select recipients'.CGI::br(). |
572 | CGI::radio_group(-name=>'radio', -values=>['all_students','studentID'], |
|
|
573 | -labels=>{all_students=>'All active students',studentID => 'Select recipients'}, |
|
|
574 | -default=>'studentID', |
|
|
575 | -linebreak=>1), |
|
|
576 | CGI::br(), |
| 252 | CGI::popup_menu(-name=>'classList', |
577 | CGI::popup_menu(-name=>'classList', |
| 253 | -values=>\@users, |
578 | -values=>\@users, |
| 254 | -labels=>\%classlistLabels, |
579 | -labels=>\%classlistLabels, |
| 255 | -size => 10, |
580 | -size => 10, |
| 256 | -multiple => 1, |
581 | -multiple => 1, |
| 257 | -default=>'None' |
582 | -default=>'Yourself' |
|
|
583 | ), |
|
|
584 | |
| 258 | ) |
585 | |
| 259 | ), |
586 | ), |
| 260 | CGI::td( |
587 | CGI::td({align=>'left'}, |
|
|
588 | CGI::submit(-name=>'preview', -value=>'Preview')," email to ", |
|
|
589 | CGI::popup_menu(-name=>'classList', |
|
|
590 | -values=>\@users, |
|
|
591 | -labels=>\%classlistLabels, |
|
|
592 | -default=>'Yourself' |
|
|
593 | ), |
|
|
594 | CGI::br(),CGI::br(), |
|
|
595 | CGI::submit(-name=>'action', -value=>'Revert to original and Resize message window'),CGI::br(), |
|
|
596 | " Rows: ", CGI::textfield(-name=>'rows', -size=>3, -value=>$rows), |
|
|
597 | " Columns: ", CGI::textfield(-name=>'columns', -size=>3, -value=>$columns), |
|
|
598 | CGI::br(), |
|
|
599 | "If you resize the message window,",CGI::br(),"you will lose all unsaved changes.", |
|
|
600 | CGI::br(),CGI::br(), |
| 261 | #show available macros |
601 | #show available macros |
| 262 | CGI::popup_menu( |
602 | CGI::popup_menu( |
| 263 | -name=>'dummyName', |
603 | -name=>'dummyName', |
| 264 | -values=>['', '$SID', '$FN', '$LN', '$SECTION', '$RECITATION','$STATUS', '$EMAIL', '$LOGIN', '$COL[3]', '$COL[-1]'], |
604 | -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:', |
605 | -labels=>{''=>'list of insertable macros', |
| 266 | '$SID'=>'$SID - Student ID', |
606 | '$SID'=>'$SID - Student ID', |
| 267 | '$FN'=>'$FN - First name', |
607 | '$FN'=>'$FN - First name', |
| 268 | '$LN'=>'$LN - Last name', |
608 | '$LN'=>'$LN - Last name', |
| 269 | '$SECTION'=>'$SECTION - Student\'s Section', |
609 | '$SECTION'=>'$SECTION - Student\'s Section', |
| 270 | '$RECITATION'=>'$RECITATION - Student\'s Recitation', |
610 | '$RECITATION'=>'$RECITATION', |
| 271 | '$STATUS'=>'$STATUS - C, Audit, Drop, etc.', |
611 | '$STATUS'=>'$STATUS - C, Audit, Drop, etc.', |
| 272 | '$EMAIL'=>'$EMAIL - Email address', |
612 | '$EMAIL'=>'$EMAIL - Email address', |
| 273 | '$LOGIN'=>'$LOGIN - Login', |
613 | '$LOGIN'=>'$LOGIN - Login', |
| 274 | '$COL[3]'=>'$COL[3] - Third column in merge file', |
614 | '$COL[3]'=>'$COL[3] - 3rd column in merge file', |
| 275 | '$COL[-1]'=>'$COL[-1] - Last column in merge file' |
615 | '$COL[-1]'=>'$COL[-1] - Last column' |
| 276 | } |
616 | } |
| 277 | ), "\n", |
617 | ), "\n", |
| 278 | ), |
618 | ), |
| 279 | |
619 | |
| 280 | ); |
620 | ); |
| 281 | print CGI::end_table(); |
621 | print CGI::end_table(); |
| 282 | #create a textbox with the subject and a textarea with the message |
622 | #create a textbox with the subject and a textarea with the message |
| 283 | |
623 | |
| 284 | #print actual body of message |
624 | #print actual body of message |
| 285 | print CGI::p( |
625 | |
| 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 | |
626 | |
| 292 | print "\n", CGI::p( CGI::textarea(-name=>'body', -default=>$text, -rows=>$rows, -columns=>$columns, -override=>1) |
627 | print "\n", CGI::p( CGI::textarea(-name=>'body', -default=>$text, -rows=>$rows, -columns=>$columns, -override=>1)); |
| 293 | ); |
|
|
| 294 | #create all necessary action buttons |
628 | #create all necessary action buttons |
| 295 | print CGI::p(CGI::submit(-name=>'action', -value=>'Open'), "\n", |
629 | print CGI::p(CGI::submit(-name=>'action', -value=>'Open'), "\n", |
| 296 | CGI::textfield(-name=>'savefilename', -size => 20, -value=> "$messageFileName", -override=>1), ' ', |
630 | CGI::textfield(-name=>'savefilename', -size => 20, -value=> "$messageFileName", -override=>1), ' ', |
| 297 | CGI::submit(-name=>'action', -value=>'Save'), " \n", |
631 | CGI::submit(-name=>'action', -value=>'Save'), " \n", |
| 298 | CGI::submit(-name=>'action', -value=>'Save as'), " \n", |
632 | CGI::submit(-name=>'action', -value=>'Save as'), " \n", |
| … | |
… | |
| 300 | CGI::submit(-name=>'action', -value=>'Send Email'), "\n", CGI::br(), |
634 | CGI::submit(-name=>'action', -value=>'Send Email'), "\n", CGI::br(), |
| 301 | 'For "Save As" choose a new filename.', |
635 | 'For "Save As" choose a new filename.', |
| 302 | ); |
636 | ); |
| 303 | |
637 | |
| 304 | ############################################################################################################## |
638 | ############################################################################################################## |
| 305 | # Table headings, prettied-up |
639 | |
| 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(); |
640 | print $self->hidden_authen_fields(); |
| 350 | print CGI::submit({name=>"save_classlist", value=>"Save Changes to Users"}); |
641 | print CGI::submit({name=>"save_classlist", value=>"Save Changes to Users"}); |
| 351 | print CGI::end_form(); |
642 | 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 ""; |
643 | return ""; |
| 362 | } |
644 | } |
| 363 | |
645 | |
|
|
646 | ############################################################################## |
|
|
647 | # Utility methods |
|
|
648 | ############################################################################## |
|
|
649 | sub fatal_error { |
|
|
650 | my $self = shift; |
|
|
651 | my $msg = join " ", @_; |
|
|
652 | # $cgi->start_html('-title' => 'User error'), |
|
|
653 | # $cgi->h1('User error'), |
|
|
654 | # $cgi->p, |
|
|
655 | # $cgi->b(HTML::Entities::encode($msg)), |
|
|
656 | # $cgi->p, |
|
|
657 | # "Please hit the "<B>Back</B>" button on your browser to ", |
|
|
658 | # "try again, or notify ", $cgi->br, |
|
|
659 | # "<", $cgi->a({href=>"mailto:$Global::webmaster"}, $Global::webmaster), "> ", |
|
|
660 | # "if you believe this message is in error.", |
|
|
661 | # $cgi->end_html; |
|
|
662 | $self->{submitError}= CGI::b(HTML::Entities::encode($msg)). |
|
|
663 | qq{"Please hit the "<B>Back</B>" button on your browser to |
|
|
664 | try again, or notify your web master |
|
|
665 | if you believe this message is in error. |
|
|
666 | }; |
|
|
667 | return; |
|
|
668 | } |
|
|
669 | |
| 364 | 1; |
670 | 1; |